/* * enable() method * * enable <node> * */ int baselineEnable(nbCELL context,void *skillHandle,BTree *tree){ int remaining; time_t utime; if(tree->options&BTREE_OPTION_TRACE) nbLogMsg(context,0,'T',"baselineEnable() called for baseline %s",tree->directory); tree->synapse=nbSynapseOpen(context,skillHandle,tree,NULL,treeAlarm); treeLoad(context,skillHandle,tree); // load baseline // set timer time(&utime); remaining=tree->interval-utime%tree->interval; nbSynapseSetTimer(context,tree->synapse,remaining); nbLogMsg(context,0,'I',"Enabled baseline %s",tree->directory); nbLogFlush(context); return(0); }
/* * enable() method * * enable <node> * */ static int auditEnable(nbCELL context,void *skillHandle,nbAudit *audit){ if(audit->trace) nbLogMsg(context,0,'T',"auditEnable() called %s using",audit->fileName,audit->translatorName); if((audit->file=fopen(audit->fileName,"r"))==NULL){ nbLogMsg(context,0,'E',"Unable to open audit file \"%s\".",audit->fileName); return(1); } if((fseek(audit->file,0,SEEK_END))!=0){ nbLogMsg(context,0,'L',"Failed fseek on \"%s\" - errno=%d.",audit->fileName,errno); fclose(audit->file); audit->file=NULL; return(1); } audit->pos=ftell(audit->file); if(fclose(audit->file)!=0) nbLogMsg(context,0,'L',"File close failed - errno=%d %s",errno,strerror(errno)); audit->file=NULL; audit->synapseCell=nbSynapseOpen(context,skillHandle,audit,audit->scheduleCell,auditAlarm); nbLogMsg(context,0,'I',"Enabled audit of %s using %s",audit->fileName,audit->translatorName); nbLogFlush(context); return(0); }
int main( int argc, char *argv[] ) { nbCELL context; nbCELL xCell; nbCELL synapseAlertCell; nbCELL synapseAlarmCell; int i; context = nbStart( argc, argv ); TEST( "Testing a synapse alert - response to cell change" ); nbCmd( context, "define x cell a + b;", NB_CMDOPT_ECHO ); nbCmd( context, "show a,b,x;", NB_CMDOPT_ECHO ); nbCmd( context, "assert a=13,b=100;", NB_CMDOPT_ECHO ); nbCmd( context, "show a,b,x;", NB_CMDOPT_ECHO ); showTermValue( context, "x" ); xCell = nbTermLocate( context, "x" ); if( xCell == NULL ) { nbLogMsg( context, 0, 'E', "Unable to local x cell" ); return( 1 ); } synapseAlertCell = nbSynapseOpen( context, NULL, NULL, xCell, myAlert ); nbCmd( context, "show a,b,x;", NB_CMDOPT_ECHO ); nbCmd( context, "assert a=14;", NB_CMDOPT_ECHO ); nbCmd( context, "show a,b,x;", NB_CMDOPT_ECHO ); TEST( "Testing synapse alert on time condition along with a synapse alarm" ); nbCmd( context, "assert x==~(4s);", NB_CMDOPT_ECHO ); synapseAlarmCell = nbSynapseOpen( context, NULL, NULL, NULL, myAlarm ); nbSynapseSetTimer( context, synapseAlarmCell, 3 ); // because we have not called nbServe yet, we need to tell the rule engine about advancing time for(i=0;i<20;i++) { sleep(1); nbClockAlert(); // WARNING: This function is deprecated and will be replaced in 0.9.04 } TEST( "Testing a synapse alert and alarm with the rule engine in control of time" ); nbCmd( context, "define EndIt when(~(10s)):stop;", NB_CMDOPT_ECHO ); nbSynapseSetTimer( context, synapseAlarmCell, 5 ); char *argvServe[2]={"eSynapse","-s"}; nbServe( context, 2, argvServe ); nbSynapseClose( context, synapseAlertCell ); // release the synapse nbSynapseClose( context, synapseAlarmCell ); // release the synapse return ( nbStop( context ) ); }