This source file includes following definitions.
- mc_event_init
- mc_event_deinit
- mc_event_mass_add
- mc_event_present
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 #include <config.h>
28
29 #include "lib/global.h"
30 #include "lib/util.h"
31 #include "lib/event.h"
32
33 #include "internal.h"
34
35
36
37
38
39
40
41
42
43 GTree *mc_event_grouplist = NULL;
44
45
46
47
48
49
50 gboolean
51 mc_event_init (GError **mcerror)
52 {
53 mc_return_val_if_error (mcerror, FALSE);
54
55 if (mc_event_grouplist != NULL)
56 {
57 mc_propagate_error (mcerror, 0, "%s", _("Event system already initialized"));
58 return FALSE;
59 }
60
61 mc_event_grouplist =
62 g_tree_new_full ((GCompareDataFunc) g_ascii_strcasecmp,
63 NULL, (GDestroyNotify) g_free, (GDestroyNotify) g_tree_destroy);
64
65 if (mc_event_grouplist == NULL)
66 {
67 mc_propagate_error (mcerror, 0, "%s", _("Failed to initialize event system"));
68 return FALSE;
69 }
70
71 return TRUE;
72 }
73
74
75
76 gboolean
77 mc_event_deinit (GError **mcerror)
78 {
79 mc_return_val_if_error (mcerror, FALSE);
80
81 if (mc_event_grouplist == NULL)
82 {
83 mc_propagate_error (mcerror, 0, "%s", _("Event system not initialized"));
84 return FALSE;
85 }
86
87 g_tree_destroy (mc_event_grouplist);
88 mc_event_grouplist = NULL;
89 return TRUE;
90 }
91
92
93
94 gboolean
95 mc_event_mass_add (const event_init_t *events, GError **mcerror)
96 {
97 size_t array_index;
98
99 mc_return_val_if_error (mcerror, FALSE);
100
101 for (array_index = 0; events[array_index].event_group_name != NULL; array_index++)
102 {
103 if (!mc_event_add (events[array_index].event_group_name,
104 events[array_index].event_name,
105 events[array_index].cb, events[array_index].init_data, mcerror))
106 {
107 return FALSE;
108 }
109 }
110 return TRUE;
111 }
112
113
114
115 gboolean
116 mc_event_present (const gchar *event_group_name, const gchar *event_name)
117 {
118 GTree *event_group;
119 GPtrArray *callbacks;
120
121 if (mc_event_grouplist == NULL || event_group_name == NULL || event_name == NULL)
122 return FALSE;
123
124 event_group = mc_event_get_event_group_by_name (event_group_name, FALSE, NULL);
125 if (event_group == NULL)
126 return FALSE;
127
128 callbacks = mc_event_get_event_by_name (event_group, event_name, FALSE, NULL);
129 if (callbacks == NULL)
130 return FALSE;
131
132 return TRUE;
133 }
134
135