CallbackMessage

Search SINQ Wiki:
SINQ LIN

SINQ Wiki
- Main Page
- Search SINQ Wiki
- Sample Environment
- Probenumg. Intern
- Troubleshooting SICS

This Page
- Page Info
- Printer Friendly

Referenced by
...nobody

Wiki Info
- Unused pages
- Undefined pages
- RecentChanges
- Page Index
- System Info
- JSPWiki Docu
- SandBox
- OneMinuteWiki
- Create a New Page




JSPWiki v2.0.52


This is version 2. It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]


General Callback Message Concept

A callback message has the form

  typedef struct {
    char *class;
    /* ... message data ... */
  } <message class>;
where class must be the first element and point to a static variable.

In our example we have a module nodehandling.

Extract from nodehandling.h:

  typedef struct {
    char *class;
    SConnection *pCon;
    Hdb *node;
    ValueStruct *value;
  } SetCallbackMsg;

  SetCallbackMsg *SetClassCast(void *msg);

SetClassCast returns the message if it is a SetCallbackMsg or NULL otherwise.

Extract from nodehandling.c:

  static char *setCallbackClass="set callback";

  SetCallbackMsg *SetClassCast(void *msg) {
    if (SetCallbackMsg *)msg)->class == SetCallbackClass) {
      return msg;
    }
    return NULL;
  }

  ...

  /* calling the callback */

  SetCallbackMsg setMsg={setCallbackClass};
  
  setMsg.pCon = pCon;
  setMsg.node = node;
  setMsg.value = value;
  CallCallback(callbacklist, &setMsg);

Extract from a module implementing a callback:

  int MySetCallback(Hdb *node, void *msg, void *data) {
    SetCallbackMsg *setMsg = SetClassCast(msg);
  
    if (! setMsg) return 0; /* not handled */
  
    /* do the set */
  
    return 1;
  }

  ...

  void KillMyData(MyData *data) {
    /* free resources */
  }
  ...

  MyData *data;
  Callback *cb;

  cb = MakeCallback(MySetCallback, data, (KillFunc)KillMyData);
  AppendCallback(node, cb);



This particular version was published on 29-Feb-2008 10:25:16 UTC by MarkusZolliker.