configure: Downgrade GNU Make message to a warning
[metze/wireshark/wip.git] / register.c
1 /* register.c
2  * Definitions for protocol registration
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0+
9  */
10
11 #include "register.h"
12 #include "ws_attributes.h"
13
14 #include <glib.h>
15 #include "epan/dissectors/dissectors.h"
16
17 static const char *cur_cb_name = NULL;
18 //static GMutex register_cb_mtx;
19 static GAsyncQueue *register_cb_done_q;
20
21 #define CB_WAIT_TIME (150 * 1000) // microseconds
22
23 static void set_cb_name(const char *proto) {
24     // g_mutex_lock(register_cb_mtx);
25     cur_cb_name = proto;
26     // g_mutex_unlock(register_cb_mtx);
27 }
28
29 static void *
30 register_all_protocols_worker(void *arg _U_)
31 {
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();
35     }
36
37     g_async_queue_push(register_cb_done_q, GINT_TO_POINTER(TRUE));
38     return NULL;
39 }
40
41 void
42 register_all_protocols(register_cb cb, gpointer cb_data)
43 {
44     const char *cb_name;
45     register_cb_done_q = g_async_queue_new();
46     gboolean called_back = FALSE;
47
48 #if GLIB_CHECK_VERSION(2,31,0)
49     g_thread_new("register_all_protocols_worker", &register_all_protocols_worker, NULL);
50 #else
51     g_thread_create(&register_all_protocols_worker, TRUE, FALSE, NULL);
52 #endif
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);
57         if (cb && cb_name) {
58             cb(RA_REGISTER, cb_name, cb_data);
59             called_back = TRUE;
60         }
61     }
62     if (cb && !called_back) {
63             cb(RA_REGISTER, "Registration finished", cb_data);
64     }
65 }
66
67 static void *
68 register_all_protocol_handoffs_worker(void *arg _U_)
69 {
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();
73     }
74
75     g_async_queue_push(register_cb_done_q, GINT_TO_POINTER(TRUE));
76     return NULL;
77 }
78
79 void
80 register_all_protocol_handoffs(register_cb cb, gpointer cb_data)
81 {
82     cur_cb_name = NULL;
83     const char *cb_name;
84     gboolean called_back = FALSE;
85
86 #if GLIB_CHECK_VERSION(2,31,0)
87     g_thread_new("register_all_protocol_handoffs_worker", &register_all_protocol_handoffs_worker, NULL);
88 #else
89     g_thread_create(&register_all_protocol_handoffs_worker, TRUE, FALSE, NULL);
90 #endif
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);
95         if (cb && cb_name) {
96             cb(RA_HANDOFF, cb_name, cb_data);
97             called_back = TRUE;
98         }
99     }
100     if (cb && !called_back) {
101             cb(RA_HANDOFF, "Registration finished", cb_data);
102     }
103
104     g_async_queue_unref(register_cb_done_q);
105 }
106
107 gulong register_count(void)
108 {
109     return dissector_reg_proto_count + dissector_reg_handoff_count;
110 }
111
112 /*
113  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
114  *
115  * Local Variables:
116  * c-basic-offset: 4
117  * tab-width: 8
118  * indent-tabs-mode: nil
119  * End:
120  *
121  * vi: set shiftwidth=4 tabstop=8 expandtab:
122  * :indentSize=4:tabSize=8:noTabs=true:
123  */