2 * Definitions for protocol registration
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0+
12 #include "ws_attributes.h"
15 #include "epan/dissectors/dissectors.h"
17 static const char *cur_cb_name = NULL;
18 //static GMutex register_cb_mtx;
19 static GAsyncQueue *register_cb_done_q;
21 #define CB_WAIT_TIME (150 * 1000) // microseconds
23 static void set_cb_name(const char *proto) {
24 // g_mutex_lock(register_cb_mtx);
26 // g_mutex_unlock(register_cb_mtx);
30 register_all_protocols_worker(void *arg _U_)
32 for (gulong i = 0; i < dissector_reg_proto_count; i++) {
33 set_cb_name(dissector_reg_proto[i].cb_name);
34 dissector_reg_proto[i].cb_func();
37 g_async_queue_push(register_cb_done_q, GINT_TO_POINTER(TRUE));
42 register_all_protocols(register_cb cb, gpointer cb_data)
45 register_cb_done_q = g_async_queue_new();
46 gboolean called_back = FALSE;
48 #if GLIB_CHECK_VERSION(2,31,0)
49 g_thread_new("register_all_protocols_worker", ®ister_all_protocols_worker, NULL);
51 g_thread_create(®ister_all_protocols_worker, TRUE, FALSE, NULL);
53 while (!g_async_queue_timeout_pop(register_cb_done_q, CB_WAIT_TIME)) {
54 // g_mutex_lock(register_cb_mtx);
55 cb_name = cur_cb_name;
56 // g_mutex_unlock(register_cb_mtx);
58 cb(RA_REGISTER, cb_name, cb_data);
62 if (cb && !called_back) {
63 cb(RA_REGISTER, "Registration finished", cb_data);
68 register_all_protocol_handoffs_worker(void *arg _U_)
70 for (gulong i = 0; i < dissector_reg_handoff_count; i++) {
71 set_cb_name(dissector_reg_handoff[i].cb_name);
72 dissector_reg_handoff[i].cb_func();
75 g_async_queue_push(register_cb_done_q, GINT_TO_POINTER(TRUE));
80 register_all_protocol_handoffs(register_cb cb, gpointer cb_data)
84 gboolean called_back = FALSE;
86 #if GLIB_CHECK_VERSION(2,31,0)
87 g_thread_new("register_all_protocol_handoffs_worker", ®ister_all_protocol_handoffs_worker, NULL);
89 g_thread_create(®ister_all_protocol_handoffs_worker, TRUE, FALSE, NULL);
91 while (!g_async_queue_timeout_pop(register_cb_done_q, CB_WAIT_TIME)) {
92 // g_mutex_lock(register_cb_mtx);
93 cb_name = cur_cb_name;
94 // g_mutex_unlock(register_cb_mtx);
96 cb(RA_HANDOFF, cb_name, cb_data);
100 if (cb && !called_back) {
101 cb(RA_HANDOFF, "Registration finished", cb_data);
104 g_async_queue_unref(register_cb_done_q);
107 gulong register_count(void)
109 return dissector_reg_proto_count + dissector_reg_handoff_count;
113 * Editor modelines - http://www.wireshark.org/tools/modelines.html
118 * indent-tabs-mode: nil
121 * vi: set shiftwidth=4 tabstop=8 expandtab:
122 * :indentSize=4:tabSize=8:noTabs=true: