6 * (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include <epan/funnel.h>
18 #include <wsutil/glib-compat.h>
20 typedef struct _funnel_menu_t
{
22 register_stat_group_t group
;
23 funnel_menu_callback callback
;
24 gpointer callback_data
;
25 funnel_menu_callback_data_free callback_data_free
;
27 struct _funnel_menu_t
* next
;
30 /* XXX This assumes one main window and one capture file. */
31 static const funnel_ops_t
* ops
= NULL
;
32 static funnel_menu_t
* registered_menus
= NULL
;
33 static funnel_menu_t
* added_menus
= NULL
;
34 static funnel_menu_t
* removed_menus
= NULL
;
35 static gboolean menus_registered
= FALSE
;
37 const funnel_ops_t
* funnel_get_funnel_ops(void) { return ops
; }
38 void funnel_set_funnel_ops(const funnel_ops_t
* o
) { ops
= o
; }
40 static void funnel_insert_menu (funnel_menu_t
** menu_list
, funnel_menu_t
*menu
)
46 for (c
= *menu_list
; c
->next
; c
= c
->next
);
51 static void funnel_remove_menu (funnel_menu_t
** menu_list
, funnel_menu_t
*menu
)
53 funnel_menu_t
*m
= *menu_list
, *p
= NULL
;
56 if (m
->callback
== menu
->callback
) {
63 if (m
->callback_data_free
) {
64 m
->callback_data_free(m
->callback_data
);
79 static void funnel_clear_menu (funnel_menu_t
** menu_list
)
92 void funnel_register_menu(const char *name
,
93 register_stat_group_t group
,
94 funnel_menu_callback callback
,
95 gpointer callback_data
,
96 funnel_menu_callback_data_free callback_data_free
,
99 funnel_menu_t
* m
= g_new(funnel_menu_t
, 1);
100 m
->name
= g_strdup(name
);
102 m
->callback
= callback
;
103 m
->callback_data
= callback_data
;
104 m
->callback_data_free
= callback_data_free
;
108 funnel_insert_menu(®istered_menus
, m
);
109 if (menus_registered
) {
110 funnel_menu_t
* m_r
= (funnel_menu_t
*)g_memdup2(m
, sizeof *m
);
111 m_r
->name
= g_strdup(name
);
112 funnel_insert_menu(&added_menus
, m_r
);
116 void funnel_deregister_menus(funnel_menu_callback callback
)
118 funnel_menu_t
* m
= g_new0(funnel_menu_t
, 1);
119 m
->callback
= callback
;
121 funnel_remove_menu(®istered_menus
, m
);
122 funnel_insert_menu(&removed_menus
, m
);
125 void funnel_register_all_menus(funnel_registration_cb_t r_cb
)
128 for (c
= registered_menus
; c
; c
= c
->next
) {
129 r_cb(c
->name
,c
->group
,c
->callback
,c
->callback_data
,c
->retap
);
131 menus_registered
= TRUE
;
134 void funnel_reload_menus(funnel_deregistration_cb_t d_cb
,
135 funnel_registration_cb_t r_cb
)
138 for (c
= removed_menus
; c
; c
= c
->next
) {
141 for (c
= added_menus
; c
; c
= c
->next
) {
142 r_cb(c
->name
,c
->group
,c
->callback
,c
->callback_data
,c
->retap
);
145 funnel_clear_menu(&removed_menus
);
146 funnel_clear_menu(&added_menus
);
149 void funnel_cleanup(void)
151 funnel_clear_menu(®istered_menus
);
155 * Editor modelines - https://www.wireshark.org/tools/modelines.html
160 * indent-tabs-mode: nil
163 * vi: set shiftwidth=4 tabstop=8 expandtab:
164 * :indentSize=4:tabSize=8:noTabs=true: