src/server/daemon/event.c

changeset 415
d938228c382e
parent 256
19259b6c5cf7
child 440
d77b8f3e14e2
equal deleted inserted replaced
414:99a34860c105 415:d938228c382e
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include <ucx/map.h> 29 #include <cx/hash_map.h>
30 #include "../util/atomic.h" 30 #include "../util/atomic.h"
31 31
32 #include "event.h" 32 #include "event.h"
33 33
34 UcxMap *event_handler_map = NULL; 34 CxMap *event_handler_map = NULL;
35 int numevhandlers = 0; 35 int numevhandlers = 0;
36 36
37 EVHandler *default_event_handler = NULL; 37 EVHandler *default_event_handler = NULL;
38 38
39 EVHandler *last_handler_c = NULL; 39 EVHandler *last_handler_c = NULL;
40 40
41 int create_event_handler(EventHandlerConfig *cfg) { 41 int create_event_handler(EventHandlerConfig *cfg) {
42 if(event_handler_map == NULL) { 42 if(event_handler_map == NULL) {
43 event_handler_map = ucx_map_new(16); 43 event_handler_map = cxHashMapCreate(cxDefaultAllocator, 16);
44 } 44 }
45 45
46 CxHashKey key = cx_hash_key_bytes((const unsigned char*)cfg->name.ptr, cfg->name.length);
47
46 /* if the event handler already exists, we don't modify it */ 48 /* if the event handler already exists, we don't modify it */
47 if(ucx_map_sstr_get(event_handler_map, cfg->name)) { 49 if(cxMapGet(event_handler_map, key)) {
48 /* TODO: log message */ 50 /* TODO: log message */
49 /* TODO: set reload status */ 51 /* TODO: set reload status */
50 return 1; 52 return 1;
51 } 53 }
52 54
62 /* TODO: log warning */ 64 /* TODO: log warning */
63 } 65 }
64 default_event_handler = e; 66 default_event_handler = e;
65 } 67 }
66 68
67 int ret = ucx_map_sstr_put(event_handler_map, cfg->name, e); 69 int ret = cxMapPut(event_handler_map, key, e);
68 if(ret == 0) { 70 if(ret == 0) {
69 last_handler_c = e; 71 last_handler_c = e;
70 numevhandlers++; 72 numevhandlers++;
71 } 73 }
72 74
86 return 0; 88 return 0;
87 } 89 }
88 } 90 }
89 91
90 EventHandlerConfig cfg; 92 EventHandlerConfig cfg;
91 cfg.name = SC("default"); 93 cfg.name = cx_str("default");
92 cfg.nthreads = 1; 94 cfg.nthreads = 1;
93 cfg.isdefault = 1; 95 cfg.isdefault = 1;
94 96
95 return create_event_handler(&cfg); 97 return create_event_handler(&cfg);
96 } 98 }
98 100
99 EVHandler* get_default_event_handler() { 101 EVHandler* get_default_event_handler() {
100 return default_event_handler; 102 return default_event_handler;
101 } 103 }
102 104
103 EVHandler* get_event_handler(char *name) { 105 EVHandler* get_event_handler(const char *name) {
104 return ucx_map_cstr_get(event_handler_map, name); 106 return cxMapGet(event_handler_map, cx_hash_key_str(name));
105 } 107 }
106 108
107 EventHandler* ev_instance(EVHandler *ev) { 109 EventHandler* ev_instance(EVHandler *ev) {
108 int nev = ev->numins; 110 int nev = ev->numins;
109 if(nev == 1) { 111 if(nev == 1) {

mercurial