annotate libfdproto/dispatch.c @ 882:ae96ae28f3dd 1.1.5

Limit python version to avoid using python3 (not compatible)
author Sebastien Decugis <sdecugis@freediameter.net>
date Sat, 03 Nov 2012 18:45:41 +0100
parents 4a9f08d6b6ba
children 8d7201a747eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
740
4a9f08d6b6ba Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> *
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
662
2e94ef0515d7 Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 658
diff changeset
5 * Copyright (c) 2011, WIDE Project and NICT *
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
658
f198d16fa7f4 Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 648
diff changeset
36 #include "fdproto-internal.h"
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38 /* The dispatch module in the library is quite simple: callbacks are saved in a global list
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39 * in no particular order. In addition, they are also linked from the dictionary objects they
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40 * refer to. */
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
42 /* Protection for the lists managed in this module. */
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
43 pthread_rwlock_t fd_disp_lock = PTHREAD_RWLOCK_INITIALIZER;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
44
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
45 /* List of all registered handlers -- useful if we want to cleanup properly at some point... */
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
46 static struct fd_list all_handlers = FD_LIST_INITIALIZER( all_handlers );
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
47
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
48 /* List of handlers registered for DISP_HOW_ANY. Other handlers are stored in the dictionary */
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 7
diff changeset
49 static struct fd_list any_handlers = FD_LIST_INITIALIZER( any_handlers );
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
50
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
51 /* The structure to store a callback */
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
52 struct disp_hdl {
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
53 int eyec; /* Eye catcher, DISP_EYEC */
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
54 struct fd_list all; /* link in the all_handlers list */
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
55 struct fd_list parent;/* link in dictionary cb_list or in any_handlers */
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
56 enum disp_how how; /* Copy of registration parameter */
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
57 struct disp_when when; /* Copy of registration parameter */
639
95a784729cac Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 398
diff changeset
58 int (*cb)( struct msg **, struct avp *, struct session *, void *, enum disp_action *); /* The callback itself */
95a784729cac Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 398
diff changeset
59 void *opaque; /* opaque data passed back to the callback */
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
60 };
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
61
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
62 #define DISP_EYEC 0xD15241C1
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
63 #define VALIDATE_HDL( _hdl ) \
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
64 ( ( ( _hdl ) != NULL ) && ( ((struct disp_hdl *)( _hdl ))->eyec == DISP_EYEC ) )
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
65
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
66 /**************************************************************************************/
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
67
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
68 /* Call CBs from a given list (any_handlers if cb_list is NULL) -- must have locked fd_disp_lock before */
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
69 int fd_disp_call_cb_int( struct fd_list * cb_list, struct msg ** msg, struct avp *avp, struct session *sess, enum disp_action *action,
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
70 struct dict_object * obj_app, struct dict_object * obj_cmd, struct dict_object * obj_avp, struct dict_object * obj_enu)
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
71 {
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
72 struct fd_list * senti, *li;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
73 TRACE_ENTRY("%p %p %p %p %p %p %p %p %p", cb_list, msg, avp, sess, action, obj_app, obj_cmd, obj_avp, obj_enu);
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
74 CHECK_PARAMS(msg && action);
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
75
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
76 senti = cb_list;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
77 if (!senti)
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
78 senti = &any_handlers;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
79
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
80 for (li = senti->next; li != senti; li = li->next) {
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
81 struct disp_hdl * hdl = (struct disp_hdl *)(li->o);
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
82
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
83 TRACE_DEBUG(ANNOYING, "when: %p %p %p %p", hdl->when.app, hdl->when.command, hdl->when.avp, hdl->when.value);
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
84
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
85 /* Check this handler matches this message / avp */
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
86 if (hdl->when.app && (hdl->when.app != obj_app))
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
87 continue;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
88 if (hdl->when.command && (hdl->when.command != obj_cmd))
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
89 continue;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
90 if (hdl->when.avp && (hdl->when.avp != obj_avp))
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
91 continue;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
92 if (hdl->when.value && (hdl->when.value != obj_enu))
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
93 continue;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
94
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
95 /* We have a match, the cb must be called. */
639
95a784729cac Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 398
diff changeset
96 CHECK_FCT( (*hdl->cb)(msg, avp, sess, hdl->opaque, action) );
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
97
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
98 if (*action != DISP_ACT_CONT)
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
99 break;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
100
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
101 if ( *msg == NULL )
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
102 break;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
103 }
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
104
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
105 /* We're done on this list */
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
106 return 0;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
107 }
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
108
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
109 /**************************************************************************************/
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
110
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
111 /* Create a new handler and link it */
639
95a784729cac Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 398
diff changeset
112 int fd_disp_register ( int (*cb)( struct msg **, struct avp *, struct session *, void *, enum disp_action *),
95a784729cac Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 398
diff changeset
113 enum disp_how how, struct disp_when * when, void * opaque, struct disp_hdl ** handle )
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
114 {
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
115 struct fd_list * cb_list = NULL;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
116 struct disp_hdl * new;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
117 struct dict_object * type_enum, * type_avp;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
118 struct dictionary * dict = NULL;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
119
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
120 TRACE_ENTRY("%p %d %p %p", cb, how, when, handle);
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
121 CHECK_PARAMS( cb && ( (how == DISP_HOW_ANY) || when ));
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
122
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
123 switch (how) {
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
124 case DISP_HOW_ANY:
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
125 cb_list = &any_handlers;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
126 break;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
127
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
128 case DISP_HOW_APPID:
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
129 CHECK_FCT( fd_dict_disp_cb(DICT_APPLICATION, when->app, &cb_list) );
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
130 break;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
131
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
132 case DISP_HOW_CC:
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
133 CHECK_FCT( fd_dict_disp_cb(DICT_COMMAND, when->command, &cb_list) );
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
134 break;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
135
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
136 case DISP_HOW_AVP_ENUMVAL:
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
137 CHECK_FCT( fd_dict_disp_cb(DICT_ENUMVAL, when->value, &cb_list) ); /* cb_list is then overwriten */
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
138 CHECK_FCT( fd_dict_getdict(when->value, &dict) );
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
139 CHECK_FCT( fd_dict_search(dict, DICT_TYPE, TYPE_OF_ENUMVAL, when->value, &type_enum, EINVAL) );
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
140 case DISP_HOW_AVP:
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
141 CHECK_FCT( fd_dict_disp_cb(DICT_AVP, when->avp, &cb_list) );
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
142 if (dict) {
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
143 CHECK_FCT( fd_dict_search(dict, DICT_TYPE, TYPE_OF_AVP, when->avp, &type_avp, EINVAL) );
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
144 CHECK_PARAMS( type_enum == type_avp );
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
145 }
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
146 break;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
147
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
148 default:
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
149 CHECK_PARAMS(how = 0);
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
150 }
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
151 /* We might further check optional fields, but we trust the caller ^^ */
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
152
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
153 /* Create the new handler */
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
154 CHECK_MALLOC( new = malloc( sizeof(struct disp_hdl) ) );
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
155 memset(new, 0, sizeof(struct disp_hdl));
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
156 new->eyec = DISP_EYEC;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
157 fd_list_init(&new->all, new);
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
158 fd_list_init(&new->parent, new);
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
159 new->how = how;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
160 switch (how) {
398
e93428e7ab31 Fix compilation warning
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 96
diff changeset
161 case DISP_HOW_ANY:
e93428e7ab31 Fix compilation warning
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 96
diff changeset
162 /* there is no "when" in that case */
e93428e7ab31 Fix compilation warning
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 96
diff changeset
163 break;
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
164 case DISP_HOW_AVP_ENUMVAL:
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
165 new->when.value = when->value;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
166 case DISP_HOW_AVP:
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
167 new->when.avp = when->avp;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
168 case DISP_HOW_CC:
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
169 new->when.command = when->command;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
170 case DISP_HOW_APPID:
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
171 new->when.app = when->app;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
172 }
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
173 new->cb = cb;
639
95a784729cac Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 398
diff changeset
174 new->opaque = opaque;
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
175
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
176 /* Now, link this new element in the appropriate lists */
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
177 CHECK_POSIX( pthread_rwlock_wrlock(&fd_disp_lock) );
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
178 fd_list_insert_before(&all_handlers, &new->all);
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
179 fd_list_insert_before(cb_list, &new->parent);
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
180 CHECK_POSIX( pthread_rwlock_unlock(&fd_disp_lock) );
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
181
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
182 /* We're done */
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
183 if (handle)
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
184 *handle = new;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
185
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
186 return 0;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
187 }
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
188
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
189 /* Delete a handler */
639
95a784729cac Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 398
diff changeset
190 int fd_disp_unregister ( struct disp_hdl ** handle, void ** opaque )
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
191 {
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
192 struct disp_hdl * del;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
193 TRACE_ENTRY("%p", handle);
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
194 CHECK_PARAMS( handle && VALIDATE_HDL(*handle) );
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
195 del = *handle;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
196 *handle = NULL;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
197
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
198 CHECK_POSIX( pthread_rwlock_wrlock(&fd_disp_lock) );
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
199 fd_list_unlink(&del->all);
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
200 fd_list_unlink(&del->parent);
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
201 CHECK_POSIX( pthread_rwlock_unlock(&fd_disp_lock) );
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
202
639
95a784729cac Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 398
diff changeset
203 if (opaque)
95a784729cac Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 398
diff changeset
204 *opaque = del->opaque;
95a784729cac Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 398
diff changeset
205
7
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
206 free(del);
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
207 return 0;
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
208 }
e5af94b04946 Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
209
90
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
210 /* Delete all handlers */
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
211 void fd_disp_unregister_all ( void )
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
212 {
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
213 TRACE_ENTRY("");
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
214 while (!FD_IS_LIST_EMPTY(&all_handlers)) {
639
95a784729cac Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 398
diff changeset
215 CHECK_FCT_DO( fd_disp_unregister((void *)&(all_handlers.next->o), NULL), /* continue */ );
90
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
216 }
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
217 return;
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
218 }
"Welcome to our mercurial repository"