- Adapted indenation to new agreed upon system

- Added support for second generation scriptcontext based counter
This commit is contained in:
koennecke
2009-02-13 09:00:03 +00:00
parent a3dcad2bfa
commit 91d4af0541
405 changed files with 88101 additions and 88173 deletions

View File

@ -16,138 +16,155 @@
#include "macro.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;
}
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);
}
ReleaseHdbValue(&newVal);
return 1;
} else {
return 0;
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);
}
ReleaseHdbValue(&newVal);
return 1;
} else {
return 0;
}
}
/*-----------------------------------------------------------------------*/
static pPollDriv makeHdbDriver(SConnection *pCon, char *objectIdentifier,
int argc, char *argv[]){
pHdb node = NULL;
pPollDriv pNew = NULL;
node = FindHdbNode(NULL,objectIdentifier,pCon);
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));
static pPollDriv makeHdbDriver(SConnection * pCon, char *objectIdentifier,
int argc, char *argv[])
{
pHdb node = NULL;
pPollDriv pNew = NULL;
pNew->objectIdentifier = strdup(objectIdentifier);
pNew->objPointer = node;
pNew->isDue = timeDue;
pNew->poll = pollHdb;
node = FindHdbNode(NULL, objectIdentifier, pCon);
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));
if(argc > 0){
pNew->pollIntervall = atoi(argv[0]);
} else {
pNew->pollIntervall = 10;
}
return pNew;
}
/*==================== script poll driver ========================*/
static int pollScript(struct __POLLDRIV *self, SConnection *pCon){
int status;
Tcl_Interp *pTcl = InterpGetTcl(pServ->pSics);
self->nextPoll = time(NULL) + self->pollIntervall;
MacroPush(pCon);
status = Tcl_Eval(pTcl,(char *)self->objPointer);
MacroPop();
if(status == 0){
return 1;
} else {
return 0;
}
}
/*-----------------------------------------------------------------------*/
static void killScriptObj(void *data){
if(data != NULL){
free(data);
}
}
/*-----------------------------------------------------------------------*/
static pPollDriv makeScriptDriver(SConnection *pCon, char *objectIdentifier,
int argc, char *argv[]){
pPollDriv pNew = NULL;
char scriptBuffer[512];
if(argc < 2){
SCWrite(pCon,
"ERROR: need intervall and script parameter for script polling driver", eError);
return NULL;
}
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]);
memset(scriptBuffer,0,512);
Arg2Text(argc-1, &argv[1],scriptBuffer,511);
pNew->objectIdentifier = strdup(objectIdentifier);
pNew->objPointer = strdup(scriptBuffer);
pNew->isDue = timeDue;
pNew->poll = pollScript;
pNew->killObjPointer = killScriptObj;
} else {
pNew->pollIntervall = 10;
}
return pNew;
}
/*==================== script poll driver ========================*/
static int pollScript(struct __POLLDRIV *self, SConnection * pCon)
{
int status;
Tcl_Interp *pTcl = InterpGetTcl(pServ->pSics);
self->nextPoll = time(NULL) + self->pollIntervall;
MacroPush(pCon);
status = Tcl_Eval(pTcl, (char *) self->objPointer);
MacroPop();
if (status == 0) {
return 1;
} else {
return 0;
}
}
/*-----------------------------------------------------------------------*/
static void killScriptObj(void *data)
{
if (data != NULL) {
free(data);
}
}
/*-----------------------------------------------------------------------*/
static pPollDriv makeScriptDriver(SConnection * pCon,
char *objectIdentifier, int argc,
char *argv[])
{
pPollDriv pNew = NULL;
char scriptBuffer[512];
if (argc < 2) {
SCWrite(pCon,
"ERROR: need intervall and script parameter for script polling driver",
eError);
return NULL;
}
pNew = malloc(sizeof(PollDriv));
if (pNew == NULL) {
return NULL;
}
memset(pNew, 0, sizeof(PollDriv));
pNew->pollIntervall = atoi(argv[0]);
memset(scriptBuffer, 0, 512);
Arg2Text(argc - 1, &argv[1], scriptBuffer, 511);
pNew->objectIdentifier = strdup(objectIdentifier);
pNew->objPointer = strdup(scriptBuffer);
pNew->isDue = timeDue;
pNew->poll = pollScript;
pNew->killObjPointer = killScriptObj;
return pNew;
}
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 if(strcmp(driver,"script") == 0){
return makeScriptDriver(pCon,objectIdentifier, argc, argv);
} else {
SCWrite(pCon,"ERROR: polling driver type unknown",eError);
return NULL;
}
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 if (strcmp(driver, "script") == 0) {
return makeScriptDriver(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);
}
if(self->objPointer != NULL && self->killObjPointer != NULL){
self->killObjPointer(self->objPointer);
}
free(self);
void deletePollDriv(pPollDriv self)
{
if (self->objectIdentifier != NULL) {
free(self->objectIdentifier);
}
if (self->objPointer != NULL && self->killObjPointer != NULL) {
self->killObjPointer(self->objPointer);
}
free(self);
}