summaryrefslogtreecommitdiffstats
path: root/g2/pointsel.c
blob: 018dc2139e6506725722a56041bace4e6231338e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
/* 
 *------------------------------------------------------------------
 * Copyright (c) 2005-2016 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <ctype.h>
#include <string.h>
#include <gtk/gtk.h>
#include "g2.h"

/*
 * globals
 */
event_def_t g_eventdefs[NEVENTS];

/*
 * locals
 */
static GtkWidget *s_pointselbox;
static FILE *s_hfp;
static FILE *s_elog_hfp;
static int s_basenum;
static GtkWidget *s_event_buttons[NEVENTS];
static int s_min_shown_pointsel;
static int s_max_shown_pointsel;
static GtkWidget *s_allbutton;
static GtkWidget *s_nonebutton;
static GtkWidget *s_pointselbuttons;
static GtkWidget *s_ps_vscroll;
static GtkObject *s_ps_vsadj;
static int g_neventdefs;

enum button_click {
    ALL_BUTTON=1,
    NONE_BUTTON,
};

/*
 * config params
 */
int c_maxpointsel;

/****************************************************************************
* recompute_vscrollbar
****************************************************************************/

static void recompute_ps_vscrollbar (void)
{
    GtkAdjustment *adj;
    ulong limit;

    adj = GTK_ADJUSTMENT(s_ps_vsadj);

#ifdef NOTDEF
    /* This seems like the right calculation, but seems not to work */
    if (g_neventdefs > c_maxpointsel)
        limit = g_neventdefs - c_maxpointsel;
    else
        limit = g_neventdefs;
#else
    limit = g_neventdefs-1;
#endif

    adj->lower = (gfloat)0.00;
    adj->upper = (gfloat)limit;
    adj->value = (gfloat)0.00;
    adj->step_increment = (gfloat)1.00;
    adj->page_increment = (gfloat)(c_maxpointsel / 3);
    adj->page_size = (gfloat)c_maxpointsel;
    gtk_adjustment_changed(adj);
    gtk_adjustment_value_changed(adj);
    gtk_widget_show(s_ps_vscroll);
}

/****************************************************************************
* point_select_callback
****************************************************************************/

static void point_select_callback(GtkToggleButton *item, gpointer data)
{
    int i = (int) (unsigned long long) data;

    g_eventdefs[i].selected = gtk_toggle_button_get_active(
        GTK_TOGGLE_BUTTON(s_event_buttons[i]));
    view1_display_when_idle();
}

/****************************************************************************
* up_button
****************************************************************************/

static void up_button(void)
{
    int i;
    int increment = c_maxpointsel/4;

    if (s_min_shown_pointsel == 0)
        return;

    s_min_shown_pointsel -= increment;

    if (s_min_shown_pointsel < 0)
        s_min_shown_pointsel = 0;

    s_max_shown_pointsel = s_min_shown_pointsel + c_maxpointsel;

    for (i = 0; i < g_neventdefs; i++) {
        if (i >= s_min_shown_pointsel &&
            i <= s_max_shown_pointsel)
            gtk_widget_show(s_event_buttons[i]);
        else
            gtk_widget_hide(s_event_buttons[i]);
    }

}

#ifdef NOTDEF
/****************************************************************************
* down_button
****************************************************************************/

static void down_button(void)
{
    int i;
    int increment = c_maxpointsel/4;

    if (s_max_shown_pointsel == g_neventdefs)
        return;

    s_max_shown_pointsel += increment;

    if (s_max_shown_pointsel >= g_neventdefs)
        s_max_shown_pointsel = (g_neventdefs-1);

    s_min_shown_pointsel = s_max_shown_pointsel - c_maxpointsel;

    if (s_min_shown_pointsel < 0)
        s_min_shown_pointsel = 0;

    for (i = 0; i < g_neventdefs; i++) {
        if (i >= s_min_shown_pointsel &&
            i <= s_max_shown_pointsel)
            gtk_widget_show(s_event_buttons[i]);
        else
            gtk_widget_hide(s_event_buttons[i]);
    }

}
#endif

/****************************************************************************
* button_click_callback
****************************************************************************/

static void button_click_callback(GtkButton *item, gpointer data)
{
    int i;
    enum button_click click = (enum button_click)data;

    switch (click) {
    case ALL_BUTTON:
        for (i = 0; i < g_neventdefs; i++) {
            gtk_toggle_button_set_active (
                GTK_TOGGLE_BUTTON(s_event_buttons[i]), TRUE);
            g_eventdefs[i].selected = TRUE;
        }
        break;

    case NONE_BUTTON:
        for (i = 0; i < g_neventdefs; i++) {
            gtk_toggle_button_set_active (
                GTK_TOGGLE_BUTTON(s_event_buttons[i]), FALSE);
            g_eventdefs[i].selected = FALSE;
        }
        break;
    }
}

/****************************************************************************
* scroll_callback
****************************************************************************/

static void scroll_callback (GtkAdjustment *adj, GtkWidget *notused)
{
    int i;

    s_min_shown_pointsel = (int)adj->value;
    s_max_shown_pointsel = s_min_shown_pointsel + c_maxpointsel;

    for (i = 0; i < g_neventdefs; i++) {
        if (i >= s_min_shown_pointsel &&
            i <= s_max_shown_pointsel)
            gtk_widget_show(s_event_buttons[i]);
        else
            gtk_widget_hide(s_event_buttons[i]);
    }
}

/****************************************************************************
* point_selector_init
****************************************************************************/

void point_selector_init(void)
{

    c_maxpointsel = atol(getprop_default("event_selector_lines", "20"));

    s_pointselbox = gtk_vbox_new(FALSE,5);

    s_pointselbuttons = gtk_hbox_new(FALSE,5);

    s_allbutton = gtk_button_new_with_label("ALL");
    gtk_widget_show(s_allbutton);
    s_nonebutton = gtk_button_new_with_label("NONE");
    gtk_widget_show(s_nonebutton);

    gtk_signal_connect (GTK_OBJECT(s_allbutton), "clicked",
                        GTK_SIGNAL_FUNC(button_click_callback), 
                        (gpointer) ALL_BUTTON);

    gtk_signal_connect (GTK_OBJECT(s_nonebutton), "clicked",
                        GTK_SIGNAL_FUNC(button_click_callback), 
                        (gpointer) NONE_BUTTON);

    gtk_box_pack_start(GTK_BOX(s_pointselbuttons), s_allbutton, FALSE, 
                       FALSE, 0);
    gtk_box_pack_start(GTK_BOX(s_pointselbuttons), s_nonebutton, FALSE, 
                       FALSE, 0);
    
    gtk_widget_show(s_pointselbuttons);
    gtk_widget_ref(s_pointselbuttons); 

    gtk_box_pack_start(GTK_BOX(s_pointselbox), s_pointselbuttons, FALSE, 
                       FALSE, 0);

    gtk_box_pack_end (GTK_BOX(g_mainhbox), s_pointselbox, 
                       FALSE, FALSE, 0);

    s_ps_vsadj = gtk_adjustment_new(0.0 /* initial value */, 
                                    0.0 /* minimum value */,
                                    2000.0 /* maximum value */,
                                    0.1 /* step increment */, 
                                    10.0/* page increment */, 
                                    10.0/* page size */);
    
    s_ps_vscroll = gtk_vscrollbar_new (GTK_ADJUSTMENT(s_ps_vsadj));
    gtk_signal_connect (GTK_OBJECT (s_ps_vsadj), "value-changed",
                        GTK_SIGNAL_FUNC (scroll_callback), 
                        (gpointer)s_ps_vscroll);
    gtk_box_pack_end(GTK_BOX(g_mainhbox), s_ps_vscroll, FALSE, FALSE, 0);
}

/****************************************************************************
* sxerox
****************************************************************************/

char *sxerox (char *s)
{
    char *rv;

    /* Note: g_malloc does or dies... */
    rv = (char *)g_malloc(strlen(s)+1);
    strcpy (rv, s);
    return (rv);
}

/****************************************************************************
* reset_point_selector
****************************************************************************/

static void reset_point_selector(void)
{
    int i;

    gtk_widget_hide(s_pointselbox);
    gtk_widget_hide(s_pointselbuttons);
    gtk_widget_hide(s_ps_vscroll);
    gtk_container_remove(GTK_CONTAINER(s_pointselbox), 
                         s_pointselbuttons);
    
    for (i = 0; i < g_neventdefs; i++) {
        if (s_event_buttons[i]) {
            gtk_container_remove(GTK_CONTAINER(s_pointselbox), 
                                 s_event_buttons[i]);
            s_event_buttons[i] = 0;
        }
    }
}

/****************************************************************************
* create_point_selector
****************************************************************************/

static void create_point_selector(void)
{
    int i;
    char tmpbuf [1024];
    event_def_t *ep;
    GtkWidget *wp;

    for (i = 0; i < g_neventdefs; i++) {
        ep = &g_eventdefs[i];
        sprintf(tmpbuf, "[%lu] %s", ep->event, 
                ep->name ? ep->name : "(none)");
        /* Hack to reduce width of point selectors */
        if (strlen(tmpbuf) > 50) {
            tmpbuf[50] = 0;
        }

        wp = gtk_check_button_new_with_label (tmpbuf);
        s_event_buttons[i] = wp;
        gtk_signal_connect (GTK_OBJECT(wp), "toggled",
                            GTK_SIGNAL_FUNC(point_select_callback), 
                            (gpointer) (unsigned long long) i);
        gtk_toggle_button_set_active (
            GTK_TOGGLE_BUTTON(wp), TRUE);
        gtk_box_pack_start(GTK_BOX(s_pointselbox), wp, FALSE, FALSE, 0);
    }

    /* set up scroll parameters by faking an up-button */
    s_min_shown_pointsel = 1;
    up_button();

    gtk_box_pack_start(GTK_BOX(s_pointselbox), s_pointselbuttons, FALSE, 
                       FALSE, 0);
    gtk_widget_show(s_pointselbuttons);
    gtk_widget_show(s_pointselbox);
    gtk_widget_show(s_ps_vscroll);
}

/****************************************************************************
* remove_all_events
****************************************************************************/

static void remove_all_events(void)
{
    event_def_t *ep;
    int i;

    for (i = 0; i < g_neventdefs; i++) {
        ep = &g_eventdefs[i];
        if (!ep->is_clib) {
            if (ep->name)
                g_free(ep->name);
            if(ep->format)
                g_free(ep->format);
        }
    }
    g_neventdefs = 0;
}

/****************************************************************************
* add_event
****************************************************************************/

static void add_event(ulong event, char *name, char *format)
{
    int i;
    event_def_t *ep;

    if (g_neventdefs >= NEVENTS) {
        g_error("Too many event definitions, increase NEVENTS!");
        /*NOTREACHED*/
    }
        
    /* Simple dup check, probably not needed very often */
    for (i = 0; i < g_neventdefs; i++) {
        if (g_eventdefs[i].event == event) {
            g_warning("Duplicate def event %lu: first definition retained\n",
                      event);
            return;
        }
    }

    ep = &g_eventdefs[g_neventdefs++];

    ep->event = event;
    ep->name = sxerox(name);
    ep->format = sxerox(format);
    ep->selected = TRUE;
}

/****************************************************************************
* add_event_from_cpel_file
****************************************************************************/

void add_event_from_cpel_file(ulong event, char *event_format, 
                              char *datum_format)
{
    event_def_t *ep;

    if (g_neventdefs >= NEVENTS) {
        g_error("Too many event definitions, increase NEVENTS!");
        /*NOTREACHED*/
    }

    ep = &g_eventdefs[g_neventdefs++];

    ep->event = event;
    /*
     * Duplicate the strings for backward compatibility. Otherwise,
     * the g_free above will barf because the name/format strings are
     * actually in mmap'ed memory 
     */
    ep->name = sxerox(event_format);
    ep->format = sxerox(datum_format);
    ep->selected = TRUE;
}

/****************************************************************************
* add_event_from_clib_file
****************************************************************************/

void add_event_from_clib_file(unsigned int event, char *name, 
                              unsigned int vec_index)
{
    event_def_t *ep;

    if (g_neventdefs >= NEVENTS) {
        g_error("Too many event definitions, increase NEVENTS!");
        /*NOTREACHED*/
    }

    ep = &g_eventdefs[g_neventdefs++];

    ep->event = event;

    ep->name = sxerox(name);
    ep->format = (void *)(unsigned long long) vec_index;
    ep->selected = TRUE;
    ep->is_clib = TRUE;
}

/****************************************************************************
* read_header_file - eats header file lines of the form
*
*     #define EVENT_FOO  123	/ * name: %d * /
*
****************************************************************************/

static void read_header_file (void)
{
    char tmpbuf [1024];
    char *name, *format;
    char *cp;
    unsigned long event;
    int ev_num_flag;

    while (fgets (tmpbuf, sizeof (tmpbuf), s_hfp))
    {
        cp = tmpbuf;
        ev_num_flag = 0;

        if (strncmp (cp, "#define", 7))
            continue;

        /* skip #define */
        while (*cp && !(isspace ((int)*cp)))
            cp++;

        if (*cp == 0)
            continue;

        /* skip ws after #define */
        while (*cp && isspace ((int)*cp))
            cp++;
            
        if (*cp == 0)
            continue;

        /* skip symbolic name */
        while (*cp && !(isspace ((int)*cp)))
            cp++;

        if (*cp == 0)
            continue;

        /* skip ws after symbolic name */
        while (*cp && isspace ((int)*cp))
            cp++;
            
        if (*cp == 0)
            continue;

        event = 0;

        if (!strncmp(cp, "EV_NUM", 6)) {
            cp += 6;
            ev_num_flag = 1;

            while (*cp && *cp != '(')
                cp++;
            
            if (*cp == 0)
                continue;

            cp++; 

            while (*cp && isspace ((int)*cp))
                cp++;
            
        } 

        /* eat event code. */
        while (*cp && isdigit ((int)*cp))
        {
            event = event * 10 + (*cp - '0');
            cp++;
        }

        if (*cp == 0)
            continue;

        if (ev_num_flag) {
            while (*cp && *cp != ')')
                cp++;
            if (*cp == 0)
                continue;
            cp++;
            event += s_basenum;
        }

        /* skip ws after event code */
        while (*cp && isspace ((int)*cp))
            cp++;
            
        if (*cp != '/')
            continue;

        cp++;

        if (*cp != '*')
            continue;

        cp++;

        /* skip ws after comment start */
        while (*cp && isspace ((int)*cp))
            cp++;

        if (*cp == 0)
            continue;

        name = cp;

        /* accumulate name */
        while (*cp && *cp != ':' && *cp != '*')
            cp++;

        if (*cp == 0)
            continue;

        *cp++ = 0;
        
        /* skip ws after name: */
        while (*cp && isspace ((int)*cp))
            cp++;
        
        if (*cp == 0 || *cp == '/')
        {
            format = " ";
            goto write_it;
        }

        format = cp;
        
        /* accumulate format string */
        while (*cp && !isspace ((int)*cp))
            cp++;

        *cp = 0;

    write_it:

        add_event (event, name, format);
    }
}

/****************************************************************************
* read_header_files - eats header file lines of the form
*
*     #define FILE1_BASE  100	/ * pointdefs: ../vpn/vpn_points.h * /
*
****************************************************************************/

static boolean read_header_files (void)
{
    char *cp, *name;
    char tmpbuf [1024];
    int basenum;
    boolean rv=FALSE;

    while (fgets (tmpbuf, sizeof (tmpbuf), s_elog_hfp))
    {
        cp = tmpbuf;

        if (strncmp (cp, "#define", 7))
            continue;

        cp += 7;

        /* skip ws after #define */
        while (*cp && isspace ((int)*cp))
            cp++;

        if (*cp == 0)
            continue;

        /* skip EV_COMPxxx_START */
        while (*cp && !isspace((int)*cp))
            cp++;

        if (*cp == 0)
            continue;

        /* skip ws after EV_COMPxxx_START */
        while (*cp && isspace ((int)*cp))
            cp++;
        
        if (*cp == 0)
            continue;
        
        basenum = atol (cp);
        
        /* skip #define */
        while (*cp && (*cp != '/'))
            cp++;

        if (*cp == 0)
            continue;

        cp++;
        if (*cp != '*')
            continue;

        cp++;

        /* skip ws after comment start */
        while (*cp && isspace ((int)*cp))
            cp++;

        if (*cp == 0)
            continue;

        if (strncmp (cp, "pointdefs:", 10))
            continue;

        cp += 10;

        /* skip ws after comment start */
        while (*cp && isspace ((int)*cp))
            cp++;

        name = cp;

        while (*cp && !isspace ((int)*cp))
            cp++;
       
        *cp = 0;

        s_hfp = fopen (name, "rt");

        if (s_hfp == NULL) {
            g_warning ("Couldn't open header file %s\n", name);
            continue;
        }
        rv = TRUE;

        s_basenum = basenum;

        read_header_file();

        fclose (s_hfp);
    }
    return(rv);
}

/****************************************************************************
* event_def_cmp
****************************************************************************/

int event_def_cmp(const void *a1, const void *a2)
{
    event_def_t *e1 = (event_def_t *)a1;
    event_def_t *e2 = (event_def_t *)a2;

    if (e1->event < e2->event)
        return(-1);
    else if (e1->event == e2->event)
        return(0);
    else
        return(1);
}

/****************************************************************************
* sort_event_definitions
****************************************************************************/

void sort_event_definitions(void)
{
    qsort(&g_eventdefs[0], g_neventdefs, sizeof(event_def_t), event_def_cmp);
}

static boolean remove_needed=TRUE;

void finalize_events(void)
{
    sort_event_definitions();
    create_point_selector();
    recompute_ps_vscrollbar();
    view1_display_when_idle();
    remove_needed = TRUE;
}

void initialize_events(void)
{
    if (remove_needed) {
        reset_point_selector();
        remove_all_events();
        remove_needed = FALSE;
    }
}

/****************************************************************************
* read_event_definitions
****************************************************************************/

boolean read_event_definitions (char *filename)
{
    char tmpbuf [128];

    initialize_events();

    s_elog_hfp = fopen (filename, "rt");
    if (s_elog_hfp == NULL) {
        sprintf (tmpbuf, "Couldn't open %s\n", filename);
        infobox ("Open Failed", tmpbuf);
        return(FALSE);
    }
    /* Presume "elog.h".  Note fallthrough... */
    if (read_header_files()) {
        sort_event_definitions();
        create_point_selector();
        recompute_ps_vscrollbar();
        fclose(s_elog_hfp);
        view1_display_when_idle();
        remove_needed = TRUE;
        return(TRUE);
    }
    fclose(s_elog_hfp);

    s_hfp = fopen (filename, "rt");
    if (s_hfp == NULL) {
        sprintf (tmpbuf, "Couldn't open %s\n", filename);
        infobox ("Read Event Definition Failure", tmpbuf);
        return(FALSE);
    }

    read_header_file();

    /* Happens if the user feeds us the wrong file, for example */
    if (g_neventdefs == 0) {
        sprintf (tmpbuf, "No event definitions found in %s\n", filename);
        infobox ("No Event Definitions?", tmpbuf);
        return(FALSE);
    }
    finalize_events();
    return(TRUE);
}

static event_def_t dummy_event;
static char dummy_string[32];

/****************************************************************************
* find_event_definition
* Binary search for first event whose time is >= t
****************************************************************************/

event_def_t *find_event_definition (ulong code)
{
    int index, bottom, top;
    event_def_t *edp;

    if (g_neventdefs == 0)
        goto use_dummy;

    bottom = g_neventdefs-1;
    top = 0;

    while (1) {
	index = (bottom + top) / 2;

        edp = (g_eventdefs + index);
        
        if (edp->event == code)
            return(edp);

        if (top >= bottom) {
        use_dummy:
            edp = &dummy_event;
            edp->selected = TRUE;
            edp->event = code;
            edp->format = "0x%x";
            sprintf (dummy_string, "E%lu", code);
            edp->name = &dummy_string[0];
            return(edp);
        }

        if (edp->event < code)
            top = index + 1;
        else 
            bottom = index - 1;
    }
}

/****************************************************************************
* pointsel_next_snapshot
* Set dialog buttons from snapshot
****************************************************************************/

void pointsel_next_snapshot(void)
{
    int i;
    
    for (i = 0; i < g_neventdefs; i++) {
        gtk_toggle_button_set_active (
            GTK_TOGGLE_BUTTON(s_event_buttons[i]), 
            g_eventdefs[i].selected);
    }
}

/****************************************************************************
* pointsel_about
****************************************************************************/

void pointsel_about (char *tmpbuf)
{
    sprintf (tmpbuf+strlen(tmpbuf), "%d event definitions\n", 
             g_neventdefs);
}
>; } } static u8 session_node_cmp_event (session_fifo_event_t * e, svm_fifo_t * f) { stream_session_t *s; switch (e->event_type) { case FIFO_EVENT_APP_RX: case FIFO_EVENT_APP_TX: case FIFO_EVENT_BUILTIN_RX: if (e->fifo == f) return 1; break; case FIFO_EVENT_DISCONNECT: break; case FIFO_EVENT_RPC: s = session_get_from_handle (e->session_handle); if (!s) { clib_warning ("session has event but doesn't exist!"); break; } if (s->server_rx_fifo == f || s->server_tx_fifo == f) return 1; break; default: break; } return 0; } u8 session_node_lookup_fifo_event (svm_fifo_t * f, session_fifo_event_t * e) { session_manager_main_t *smm = vnet_get_session_manager_main (); svm_queue_t *q; session_fifo_event_t *pending_event_vector, *evt; int i, index, found = 0; i8 *headp; u8 thread_index; ASSERT (e); thread_index = f->master_thread_index; /* * Search evt queue */ q = smm->vpp_event_queues[thread_index]; index = q->head; for (i = 0; i < q->cursize; i++) { headp = (i8 *) (&q->data[0] + q->elsize * index); clib_memcpy (e, headp, q->elsize); found = session_node_cmp_event (e, f); if (found) return 1; if (++index == q->maxsize) index = 0; } /* * Search pending events vector */ pending_event_vector = smm->pending_event_vector[thread_index]; vec_foreach (evt, pending_event_vector) { found = session_node_cmp_event (evt, f); if (found) { clib_memcpy (e, evt, sizeof (*evt)); break; } } return found; } static uword session_queue_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { session_manager_main_t *smm = vnet_get_session_manager_main (); session_fifo_event_t *my_pending_event_vector, *e; session_fifo_event_t *my_fifo_events; u32 n_to_dequeue, n_events; svm_queue_t *q; application_t *app; int n_tx_packets = 0; u32 thread_index = vm->thread_index; int i, rv; f64 now = vlib_time_now (vm); void (*fp) (void *); SESSION_EVT_DBG (SESSION_EVT_POLL_GAP_TRACK, smm, thread_index); /* * Update transport time */ transport_update_time (now, thread_index); /* * Get vpp queue events */ q = smm->vpp_event_queues[thread_index]; if (PREDICT_FALSE (q == 0)) return 0; my_fifo_events = smm->free_event_vector[thread_index]; /* min number of events we can dequeue without blocking */ n_to_dequeue = q->cursize; my_pending_event_vector = smm->pending_event_vector[thread_index]; if (!n_to_dequeue && !vec_len (my_pending_event_vector) && !vec_len (smm->pending_disconnects[thread_index])) return 0; SESSION_EVT_DBG (SESSION_EVT_DEQ_NODE, 0); /* * If we didn't manage to process previous events try going * over them again without dequeuing new ones. */ /* XXX: Block senders to sessions that can't keep up */ if (0 && vec_len (my_pending_event_vector) >= 100) { clib_warning ("too many fifo events unsolved"); goto skip_dequeue; } /* See you in the next life, don't be late */ if (pthread_mutex_trylock (&q->mutex)) return 0; for (i = 0; i < n_to_dequeue; i++) { vec_add2 (my_fifo_events, e, 1); svm_queue_sub_raw (q, (u8 *) e); } /* The other side of the connection is not polling */ if (q->cursize < (q->maxsize / 8)) (void) pthread_cond_broadcast (&q->condvar); pthread_mutex_unlock (&q->mutex); vec_append (my_fifo_events, my_pending_event_vector); vec_append (my_fifo_events, smm->pending_disconnects[thread_index]); _vec_len (my_pending_event_vector) = 0; smm->pending_event_vector[thread_index] = my_pending_event_vector; _vec_len (smm->pending_disconnects[thread_index]) = 0; skip_dequeue: n_events = vec_len (my_fifo_events); for (i = 0; i < n_events; i++) { stream_session_t *s0; /* $$$ prefetch 1 ahead maybe */ session_fifo_event_t *e0; e0 = &my_fifo_events[i]; switch (e0->event_type) { case FIFO_EVENT_APP_TX: if (n_tx_packets == VLIB_FRAME_SIZE) { vec_add1 (smm->pending_event_vector[thread_index], *e0); break; } s0 = session_event_get_session (e0, thread_index); if (PREDICT_FALSE (!s0)) { clib_warning ("It's dead, Jim!"); continue; } /* Spray packets in per session type frames, since they go to * different nodes */ rv = (smm->session_tx_fns[s0->session_type]) (vm, node, e0, s0, &n_tx_packets); /* Out of buffers */ if (PREDICT_FALSE (rv < 0)) { vlib_node_increment_counter (vm, node->node_index, SESSION_QUEUE_ERROR_NO_BUFFER, 1); continue; } break; case FIFO_EVENT_DISCONNECT: /* Make sure stream disconnects run after the pending list is * drained */ s0 = session_get_from_handle (e0->session_handle); if (!e0->postponed) { e0->postponed = 1; vec_add1 (smm->pending_disconnects[thread_index], *e0); continue; } /* If tx queue is still not empty, wait */ if (svm_fifo_max_dequeue (s0->server_tx_fifo)) { vec_add1 (smm->pending_disconnects[thread_index], *e0); continue; } stream_session_disconnect_transport (s0); break; case FIFO_EVENT_BUILTIN_RX: s0 = session_event_get_session (e0, thread_index); if (PREDICT_FALSE (!s0)) continue; svm_fifo_unset_event (s0->server_rx_fifo); app = application_get (s0->app_index); app->cb_fns.builtin_app_rx_callback (s0); break; case FIFO_EVENT_RPC: fp = e0->rpc_args.fp; (*fp) (e0->rpc_args.arg); break; default: clib_warning ("unhandled event type %d", e0->event_type); } } _vec_len (my_fifo_events) = 0; smm->free_event_vector[thread_index] = my_fifo_events; vlib_node_increment_counter (vm, session_queue_node.index, SESSION_QUEUE_ERROR_TX, n_tx_packets); SESSION_EVT_DBG (SESSION_EVT_DISPATCH_END, smm, thread_index); return n_tx_packets; } /* *INDENT-OFF* */ VLIB_REGISTER_NODE (session_queue_node) = { .function = session_queue_node_fn, .name = "session-queue", .format_trace = format_session_queue_trace, .type = VLIB_NODE_TYPE_INPUT, .n_errors = ARRAY_LEN (session_queue_error_strings), .error_strings = session_queue_error_strings, .state = VLIB_NODE_STATE_DISABLED, }; /* *INDENT-ON* */ static clib_error_t * session_queue_exit (vlib_main_t * vm) { if (vec_len (vlib_mains) < 2) return 0; /* * Shut off (especially) worker-thread session nodes. * Otherwise, vpp can crash as the main thread unmaps the * API segment. */ vlib_worker_thread_barrier_sync (vm); session_node_enable_disable (0 /* is_enable */ ); vlib_worker_thread_barrier_release (vm); return 0; } VLIB_MAIN_LOOP_EXIT_FUNCTION (session_queue_exit); static uword session_queue_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) { f64 now, timeout = 1.0; uword *event_data = 0; uword event_type; while (1) { vlib_process_wait_for_event_or_clock (vm, timeout); now = vlib_time_now (vm); event_type = vlib_process_get_events (vm, (uword **) & event_data); switch (event_type) { case SESSION_Q_PROCESS_FLUSH_FRAMES: /* Flush the frames by updating all transports times */ transport_update_time (now, 0); break; case SESSION_Q_PROCESS_STOP: timeout = 100000.0; break; case ~0: /* Timed out. Update time for all transports to trigger all * outstanding retransmits. */ transport_update_time (now, 0); break; } vec_reset_length (event_data); } return 0; } /* *INDENT-OFF* */ VLIB_REGISTER_NODE (session_queue_process_node) = { .function = session_queue_process, .type = VLIB_NODE_TYPE_PROCESS, .name = "session-queue-process", .state = VLIB_NODE_STATE_DISABLED, }; /* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */