- Added a SICS to Hipadaba adapter

- Added a separate polling module to SICS
This commit is contained in:
koennecke
2006-12-07 14:04:17 +00:00
parent 5b727dc784
commit 78fce0127d
32 changed files with 1899 additions and 183 deletions

97
polldriv.c Normal file
View File

@ -0,0 +1,97 @@
/**
* This is the sister module to sicspoll which defines the drivers for the
* various modes of polling SICS objects.
*
* copyright: see file COPYRIGHT
*
* Mark Koennecke, November-December 2006
*/
#include <stdlib.h>
#include <assert.h>
#include <sics.h>
#include <splitter.h>
#include "polldriv.h"
#include "splitter.h"
#include "sicshipadaba.h"
/*================ actual driver implementation =========================*/
static int timeDue(struct __POLLDRIV *self, time_t now, SConnection *pCon){
if(now > self->nextPoll){
return 1;
} else {
return 0;
}
}
/*------------------ HDB Driver -----------------------------------------*/
static int pollHdb(struct __POLLDRIV *self, SConnection *pCon){
hdbValue old, newVal;
pHdb node = NULL;
memset(&old,0,sizeof(hdbValue));
memset(&newVal,0,sizeof(hdbValue));
node = (pHdb)self->objPointer;
assert(node != NULL);
old = node->value;
self->nextPoll = time(NULL) + self->pollIntervall;
if(GetHipadabaPar(node, &newVal, pCon) == 1){
if(!compareHdbValue(old,newVal)){
UpdateHipadabaPar(node,newVal,pCon);
}
return 1;
} else {
return 0;
}
}
/*-----------------------------------------------------------------------*/
static pPollDriv makeHdbDriver(SConnection *pCon, char *objectIdentifier,
int argc, char *argv[]){
pHdb root = NULL, node = NULL;
pPollDriv pNew = NULL;
root = GetHipadabaRoot();
assert(root != NULL);
node = GetHipadabaNode(root,objectIdentifier);
if(node == NULL){
SCWrite(pCon,"ERROR: object to poll not found",eError);
return 0;
}
pNew = malloc(sizeof(PollDriv));
if(pNew == NULL){
return NULL;
}
memset(pNew,0,sizeof(PollDriv));
pNew->objectIdentifier = strdup(objectIdentifier);
pNew->objPointer = node;
pNew->isDue = timeDue;
pNew->poll = pollHdb;
if(argc > 0){
pNew->pollIntervall = atoi(argv[0]);
} else {
pNew->pollIntervall = 10;
}
return pNew;
}
/*================ external interface ====================================*/
pPollDriv makePollDriver(SConnection *pCon, char *driver,
char *objectIdentifier, int argc, char *argv[]){
strtolower(driver);
if(strcmp(driver,"hdb") == 0) {
return makeHdbDriver(pCon,objectIdentifier, argc, argv);
} else {
SCWrite(pCon,"ERROR: polling driver type unknown",eError);
return NULL;
}
}
/*------------------------------------------------------------------------*/
void deletePollDriv(pPollDriv self){
if(self->objectIdentifier != NULL){
free(self->objectIdentifier);
}
free(self);
}