- introduced FindHdbCallbackData

This commit is contained in:
zolliker
2008-02-13 09:50:06 +00:00
parent 4efc67821d
commit 9eb83d3d3f
2 changed files with 39 additions and 8 deletions

View File

@ -81,15 +81,16 @@ void RemoveHdbNodeFromParent(pHdb node, void *callData){
if(parent != NULL){ if(parent != NULL){
if(parent->child == node){ if(parent->child == node){
parent->child = node->next; parent->child = node->next;
return; } else {
current = parent->child;
while(current->next != node){
current = current->next;
}
current->next = current->next->next;
} }
current = parent->child;
while(current->next != node){
current = current->next;
}
current->next = current->next->next;
InvokeCallbackChain(parent->treeChangeCallbacks, InvokeCallbackChain(parent->treeChangeCallbacks,
parent,callData,parent->value); parent,callData,parent->value);
node->mama = NULL;
} }
} }
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
@ -518,6 +519,7 @@ int compareHdbValue(hdbValue v1, hdbValue v2){
int cloneHdbValue(hdbValue *source, hdbValue *clone){ int cloneHdbValue(hdbValue *source, hdbValue *clone){
memset(clone,0,sizeof(hdbValue)); memset(clone,0,sizeof(hdbValue));
clone->v.text = NULL; /* this sets all pointers in the union to NULL */
clone->dataType = source->dataType; clone->dataType = source->dataType;
return copyHdbValue(source, clone); return copyHdbValue(source, clone);
} }
@ -875,6 +877,25 @@ void InternalRemoveHipadabaCallback(pHdb root, void *internalID){
current = current->next; current = current->next;
} }
} }
/*----------------------------------------------------------------------------*/
void *FindHdbCallbackData(pHdb node, int type, hdbCallbackFunction func
, void *internalID) {
pHdbCallback cb;
switch (type) {
case HCBSET: cb = node->writeCallbacks; break;
case HCBUPDATE: cb = node->updateCallbacks; break;
case HCBREAD: cb = node->readCallbacks; break;
case HCBTREE: cb = node->treeChangeCallbacks; break;
}
while (cb != NULL) {
if (cb->internalID == internalID && cb->userCallback == func) {
return cb->userData;
}
cb = cb->next;
}
return NULL;
}
/*=================== parameter interface ====================================*/ /*=================== parameter interface ====================================*/
static int canCopy(hdbValue *source, hdbValue *target){ static int canCopy(hdbValue *source, hdbValue *target){
if(target->dataType == HIPINTVARAR) { if(target->dataType == HIPINTVARAR) {
@ -1001,11 +1022,12 @@ int NotifyHipadabaPar(pHdb node,void *callData){
int GetHipadabaPar(pHdb node, hdbValue *v, void *callData){ int GetHipadabaPar(pHdb node, hdbValue *v, void *callData){
int status; int status;
v->dataType = node->value.dataType;
v->v.text = NULL; /* this sets all pointers in the union to NULL */
status = InvokeCallbackChain(node->readCallbacks, node, callData, *v); status = InvokeCallbackChain(node->readCallbacks, node, callData, *v);
if(status != 1 ){ if(status != 1 ){
return status; return status;
} }
v->dataType = node->value.dataType;
copyHdbValue(&node->value,v); copyHdbValue(&node->value,v);
return 1; return 1;
} }

View File

@ -284,6 +284,15 @@ void RemoveHipadabaCallback(pHdb root, int id);
* @param internalID The internal ID callbacks have to match in order to be removed. * @param internalID The internal ID callbacks have to match in order to be removed.
*/ */
void InternalRemoveHipadabaCallback(pHdb root, void *internalID); void InternalRemoveHipadabaCallback(pHdb root, void *internalID);
/**
* 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
* @return the found callback user data or NULL on failure
*/
void *FindHdbCallbackData(pHdb node, int type, hdbCallbackFunction func
, void *internalID);
/** /**
* invoke a callback chain. * invoke a callback chain.
* @param root The callback chain to invoke * @param root The callback chain to invoke