- Refactored hdb callbacks

SKIPPED:
	psi/julcho.c
This commit is contained in:
koennecke
2008-03-10 11:06:07 +00:00
parent 6b10e0a4e9
commit f512f47b02
14 changed files with 1440 additions and 829 deletions

View File

@@ -24,6 +24,8 @@
* Added treeChange callback, Mark Koennecke, November 2006
*
* Added support for properties, Mark Koennecke, January 2007
*
* Refactored callback handling, Markus Zolliker, Mark Koennecke, March 2008
*/
#ifndef HIPADABA
#define HIPADABA
@@ -40,11 +42,6 @@
#define HIPFLOATVARAR 6
#define HIPOBJ 7
#define HIPFUNC 8
/* -------- callback types */
#define HCBSET 0
#define HCBUPDATE 1
#define HCBREAD 2
#define HCBTREE 3
/*--------- error codes */
#define HDBTYPEMISMATCH -7701
#define HDBLENGTHMISMATCH -7702
@@ -68,29 +65,87 @@ typedef struct __hipadaba {
struct __hipadaba *mama;
struct __hipadaba *child;
struct __hipadaba *next;
struct __hdbcallback *writeCallbacks;
struct __hdbcallback *updateCallbacks;
struct __hdbcallback *readCallbacks;
struct __hdbcallback *treeChangeCallbacks;
struct __hdbcallback *callBackChain;
char *name;
hdbValue value;
int protected;
pStringDict properties;
}Hdb, *pHdb;
/*-------------- return values for callback functions -------------------------*/
typedef enum {hdbContinue,
hdbAbort,
hdbKill } hdbCallbackReturn;
/*======================== Messages ===========================================*/
typedef struct __hdbMessage {
char *type;
} hdbMessage, *pHdbMessage;
/*-----------------------------------------------------------------------------*/
typedef struct {
char *type;
hdbValue *v;
void *callData;
}hdbDataMessage, *pHdbDataMessage;
/*-------------------------------------------------------------------------------*/
typedef int (*hdbCallbackFunction)(void *userData, void *callData,
pHdb currentNode, hdbValue v);
typedef struct {
char *type;
void *callData;
}hdbTreeChangeMessage, *pHdbTreeChangeMessage;
/*-------------------------------------------------------------------------------*/
typedef hdbCallbackReturn (*hdbCallbackFunction)(pHdb currentNode,
void *userData,
pHdbMessage message);
typedef void (*killUserData)(void *data);
/*-------------------------------------------------------------------------------*/
typedef struct __hdbcallback {
void *userData;
killUserData killFunc;
hdbCallbackFunction userCallback;
int id;
void *internalID;
int killFlag;
struct __hdbcallback *next;
struct __hdbcallback *previous;
}hdbCallback, *pHdbCallback;
/*--------------- another message: must be here for seqeunce --------------------*/
typedef struct {
char *type;
hdbCallbackFunction testFunc;
void *testPtr;
void *result;
}hdbDataSearch, *pHdbDataSearch;
/*============= Message Test Functions ==========================================*/
/**
* Test a message if it is a set message
* @param toTest The message to test.
* @return NULL if the message is no set message or a message pointer if it is.
*/
pHdbDataMessage GetHdbSetMessage(pHdbMessage toTest);
/**
* Test a message if it is a set message
* @param toTest The message to test.
* @return NULL if the message is no set message or a message pointer if it is.
*/
pHdbDataMessage GetHdbGetMessage(pHdbMessage toTest);
/**
* Test a message if it is a update message
* @param toTest The message to test.
* @return NULL if the message is no update message or a message pointer if
* it is.
*/
pHdbDataMessage GetHdbUpdateMessage(pHdbMessage toTest);
/**
* Test a message if it is a tree change message
* @param toTest The message to test.
* @return NULL if the message is no tree change message or a message
* pointer if it is.
*/
pHdbTreeChangeMessage GetHdbTreeChangeMessage(pHdbMessage toTest);
/**
* Test a message if it is a data search message
* @param toTest The message to test.
* @return NULL if the message is no data search message or a message
* pointer if it is.
*/
pHdbDataSearch GetHdbDataSearchMessage(pHdbMessage toTest);
/*======================== Function protoypes: hdbData ========================*/
hdbValue makeHdbValue(int datatype, int length);
/**
@@ -231,11 +286,6 @@ char *GetHipadabaPath(pHdb node);
* @param callData User data for the tree change callback
*/
void RemoveHdbNodeFromParent(pHdb node, void *callData);
/**
* delete a callback chain
* @param root The callback chain to delete
*/
void DeleteCallbackChain(pHdbCallback root);
/**
* count the numbers of children in thie Hdb node
* @param node The node to count children for
@@ -249,50 +299,35 @@ int CountHdbChildren(pHdb node);
* @param userData userData to be associated with this callback. Can be NULL.
* @param killFunc A function for freeing the userData. Can be NULL, then it will
* not be invoked
* @param id An ID associated with this callback
* @param internalID Another ID to be associated with this callback. Typically a
* reference to the owner object responsible for deleting the callback.
* @return A new suitabaly initialised callback structure or NULL when required elements
* are missing or there is nor memory.
*/
pHdbCallback MakeHipadabaCallback(hdbCallbackFunction func,
void *userData, killUserData killFunc,
int id, void *internalID);
void *userData, killUserData killFunc);
/**
* add a callback at the end of the callback chain
* @param node The node to which to append the callback
* @param type the type of the callback to append
* @param newCB The callback to append
*/
void AppendHipadabaCallback(pHdb node,int type, pHdbCallback newCB);
void AppendHipadabaCallback(pHdb node,pHdbCallback newCB);
/**
* add a callback at the head of the callback chain
* @param node The node to which to append the callback
* @param type the type of the callback to append
* @param newCB The callback prepend
*/
void PrependHipadabaCallback(pHdb node, int type, pHdbCallback newCB);
/**
* remove recursively all callbacks witch match the id
* @param root The starting node from where to start removing callbacks
* @param id The ID callbacks have to match in order to be removed.
*/
void RemoveHipadabaCallback(pHdb root, int id);
/**
* remove recursively all callbacks witch match the internal id
* @param root The starting node from where to start removing callbacks
* @param internalID The internal ID callbacks have to match in order to be removed.
*/
void InternalRemoveHipadabaCallback(pHdb root, void *internalID);
void PrependHipadabaCallback(pHdb node,pHdbCallback newCB);
/**
* find the callback data
* @param node the node from where callbacks have to be searched
* @param type the type of the callback to be searched
* @param func the function registered with the searched callback
* @param userPtr A pointer to some user data whih the callback
* uses to determine if it is the right one.
* @return the found callback user data or NULL on failure
*/
void *FindHdbCallbackData(pHdb node, int type, hdbCallbackFunction func
, void *internalID);
void *FindHdbCallbackData(pHdb node,hdbCallbackFunction func,
void *userPtr);
/**
* invoke a callback chain.
* @param root The callback chain to invoke
@@ -301,9 +336,19 @@ void *FindHdbCallbackData(pHdb node, int type, hdbCallbackFunction func
* @param v The new value for this callback
* @return 1 on success, 0 on failure
*/
int InvokeCallbackChain(pHdbCallback root, pHdb node,
void *callData, hdbValue v);
int InvokeCallbackChain(pHdb node, pHdbMessage message);
/**
* Deletes a callback chain. This is internal, normal users
* should nto use this function. Or you create a mess!
* @param root The callback chain to remove
*/
void DeleteCallbackChain(pHdbCallback root);
/**
* apply message to the node and all its children
* @param node Th node where to start recursing
* @param message The message to send
*/
void RecurseCallbackChains(pHdb node, pHdbMessage message);
/*============== Parameter Handling ===============================*/
/**
* Set a hipadaba parameter. This is an external set for a parameter. It may cause