- Added a SICS to Hipadaba adapter
- Added a separate polling module to SICS
This commit is contained in:
88
polldriv.tc
Normal file
88
polldriv.tc
Normal file
@ -0,0 +1,88 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
<%! source sicstemplates.tcl %>
|
||||
<% stdIncludes %>
|
||||
#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;
|
||||
}
|
||||
<%newStruc PollDriv 5 %>
|
||||
|
||||
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);
|
||||
}
|
Reference in New Issue
Block a user