1 /*******************************************************************
2 uLan Utilities Library - C library of basic reusable constructions
4 ul_evcbase.h - event connectors
6 (C) Copyright 2001-2003 by Pavel Pisa - Originator
8 The uLan utilities library can be used, copied and modified under
10 - GPL - GNU General Public License
11 - LGPL - GNU Lesser General Public License
12 - MPL - Mozilla Public License
13 - and other licenses added by project originators
14 Code can be modified and re-distributed under any combination
15 of the above listed licenses. If contributor does not agree with
16 some of the licenses, he/she can delete appropriate line.
17 Warning, if you delete all lines, you are not allowed to
18 distribute source code and/or binaries utilizing code.
20 See files COPYING and README for details.
22 *******************************************************************/
29 #include "ul_utdefs.h"
40 typedef int evc_rx_fnc_t(void);
41 typedef int evc_prop_fnc_t(struct evc_link *link, va_list args);
44 * struct evc_link - Event Connector Link
45 * @src: describes source of the event link, contains pointer
46 * to &evc_tx_hub_t and @peers links list
47 * @dst: determines destination of the event, it can be @standalone
48 * rx_fnc() function with with @context or &evc_tx_hub_t
50 * @propagate: pointer to the arguments propagation function,
51 * @refcnt: link reference counter
52 * @recursive: link can propagate could be invoked recursively,
53 * else recursive events are ignored by link
54 * @blocked: event propagation is blocked for the link,
55 * can be used by application
56 * @ready: link is ready and has purpose to live - it connects
58 * @dead: link is dead and cannot propagate events
59 * @delete_pend: link is being deleted, but it is taken simultaneously,
60 * delete has to wait for finish of the propagate and to moving
62 * @malloced: link has been malloced and should be automatically freed
63 * when referenc counts drop to zero
64 * @standalone: link is used for standalone function invocation
65 * @tx_full_hub: @src points to the full hub structure
66 * @rx_full_hub: @dst points to the full hub structure
67 * @taken: link is in middle of the propagation process
69 * The link delivers events from the source to the destination.
70 * The link specific function propagate() is called for each link leading from
71 * the hub activated by evc_tx_hub_emit() and evc_tx_hub_propagate().
72 * The propagate function is responsible for parameters transformation before
73 * invocation of standalone or destination hub rx_fnc() function.
76 typedef struct evc_link {
79 struct evc_tx_hub *hub;
84 struct evc_rx_hub *hub;
92 evc_prop_fnc_t *propagate;
98 unsigned delete_pend:1;
100 unsigned standalone:1;
101 unsigned tx_full_hub:1;
102 unsigned rx_full_hub:1;
107 * struct evc_tx_hub - Event Transmit Hub
108 * @links: list of links outgoing from the hub
110 typedef struct evc_tx_hub {
111 ul_list_head_t links;
115 * struct evc_rx_hub - Event Receiving Hub
116 * @links: list of links incoming to the hub
117 * @rx_fnc: function invoked when event arives
118 * @context: context for rx_fnc()
120 typedef struct evc_rx_hub {
121 ul_list_head_t links;
122 evc_rx_fnc_t *rx_fnc;
126 evc_link_t *evc_link_new(void);
127 evc_link_t *evc_link_new_standalone(evc_rx_fnc_t *rx_fnc, void *context);
128 int evc_link_init(evc_link_t *link);
129 int evc_link_init_standalone(evc_link_t *link, evc_rx_fnc_t *rx_fnc,
131 int evc_link_connect(evc_link_t *link, evc_tx_hub_t *src, evc_rx_hub_t *dst,
132 evc_prop_fnc_t *prop);
133 int evc_link_connect_standalone(evc_link_t *link, evc_tx_hub_t *src,
134 evc_prop_fnc_t *prop);
135 int evc_link_delete(evc_link_t *link);
136 void evc_link_dispose(evc_link_t *link);
138 int evc_tx_hub_init(evc_tx_hub_t *hub);
139 void evc_tx_hub_done(evc_tx_hub_t *hub);
140 void evc_tx_hub_propagate(evc_tx_hub_t *hub, va_list args);
141 void evc_tx_hub_emit(evc_tx_hub_t *hub, ...);
142 int evc_tx_hub_eol_weakptr(evc_tx_hub_t *hub, void **weakptr);
144 int evc_rx_hub_init(evc_rx_hub_t *hub, evc_rx_fnc_t *rx_fnc, void *context);
145 void evc_rx_hub_done(evc_rx_hub_t *hub);
146 void evc_rx_hub_disconnect_all(evc_rx_hub_t *hub);
148 int evc_link_propagate_i_p_l(evc_link_t *link, va_list args);
151 * evc_link_inc_refcnt - Increment Link Reference Count
152 * @link: pointer to link
155 void evc_link_inc_refcnt(evc_link_t *link)
158 if(link->refcnt >= 0) link->refcnt++;
162 * evc_link_dec_refcnt - Decrement Link Reference Count
163 * @link: pointer to link
165 * if the link reference count drops to 0, link is deleted
166 * from hubs by evc_link_dispose() function and if @malloced
167 * is sed, link memory is disposed by free().
168 * Special handlink can be achieved if propagate() returns non-zero
169 * value if called with @ded link.
172 void evc_link_dec_refcnt(evc_link_t *link)
175 if(link->refcnt > 0) link->refcnt--;
176 if(!link->refcnt) evc_link_dispose(link);
184 #endif /* _UL_EVCBASE_H */