Line 12 was replaced by lines 12-23 |
- In our example we have a module ''nodehandling''. |
+ Given the following functions dealing with callbacks: |
+ {{{ |
+ typedef void KillFunc(void *); |
+ typedef int CallbackFunction(Hdb *node, void *msg, void *data); |
+ typedef struct Callback Callback; |
+ |
+ InvokeCallback(Hdb *node, void *msg); |
+ Callback *MakeCallback(CallbackFunction *cbFunc, void *data, KillFunc *killFunc); |
+ AppendCallback(Hdb *node, Callback *cb); |
+ PrependCallback(Hdb *node, Callback *cb); |
+ }}} |
+ The callbacks are stored as one list per node. |
Line 14 was replaced by line 25 |
- Extract from nodehandling.h: |
+ Extract from (sics)hipadaba.h: |
Removed line 19 |
- Hdb *node; |
Line 23 was replaced by line 33 |
- SetCallbackMsg *SetClassCast(void *msg); |
+ SetCallbackMsg *SetCallbackCast(void *msg); |
Line 26 was replaced by lines 36-38 |
- SetClassCast returns the message if it is a SetCallbackMsg or NULL otherwise. |
+ The members of callback message contain the additional arguments needed for the handling of |
+ the callback. SetCallbackCast reveals if an anonymous message is a SetCallbackMsg. It returns |
+ NULL otherwise. |
Line 28 was replaced by line 40 |
- Extract from nodehandling.c: |
+ Extract from (sics)hipadaba.c: |
Lines 32-33 were replaced by lines 44-45 |
- SetCallbackMsg *SetClassCast(void *msg) { |
- if (SetCallbackMsg *)msg)->class == SetCallbackClass) { |
+ SetCallbackMsg *SetCallbackCast(void *msg) { |
+ if (((SetCallbackMsg *)msg)->class == setCallbackClass) { |
Removed line 46 |
- setMsg.node = node; |
Line 48 was replaced by line 59 |
- CallCallback(callbacklist, &setMsg); |
+ InvokeCallback(node, &setMsg); |
At line 50 added 4 lines. |
+ The text content of setCallbackClass is not very important, it may be used |
+ for logging purposes. The check for a particular class is done by comparing |
+ the pointers, not the contents. |
+ |
Lines 54-55 were replaced by lines 69-71 |
- SetCallbackMsg *setMsg = SetClassCast(msg); |
- |
+ SetCallbackMsg *setMsg = SetCallbackCast(msg); |
+ MyData *mydata; |
+ |
Line 57 was replaced by lines 73-74 |
- |
+ |
+ mydata = data; |
Line 73 was replaced by line 90 |
- cb = MakeCallback(MySetCallback, data, (KillFunc)KillMyData); |
+ cb = MakeCallback(MySetCallback, data, (KillFunc *)KillMyData); |
At line 76 added 33 lines. |
+ An implementation may use the same callback function for handling different |
+ callback messages, with the same user data: |
+ {{{ |
+ int CombinedCallback(Hdb *node, void *msg, void *data) { |
+ SetCallbackMsg *setMsg; |
+ UpdateCallbackMsg *updateMsg; |
+ MyData *mydata = data; |
+ |
+ setMsg = SetCallbackCast(msg); |
+ if (setMsg) { |
+ /* handle setMsg */ |
+ return 1; |
+ } |
+ |
+ updateMsg= UpdateCallbackCast(msg); |
+ if (updateMsg) { |
+ /* handle updateMsg */ |
+ return 1; |
+ } |
+ |
+ return 0; /* not handled */ |
+ } |
+ }}} |
+ |
+ For the implementation of Hipadaba at least the following callbacks have |
+ to be implemented: |
+ |
+ * SetCallback |
+ * ReadCallback |
+ * UpdateCallback |
+ * KillForIDCallback |
+ * KillForInternalIDCallback |
+ |