FACT++  1.0
void monitorIntValues ( )

Definition at line 3540 of file feeserver.c.

References checkIntLocation(), createLogMessage(), dis_update_service, firstIntNode, and sprintf().

Referenced by startMonitorThread().

3540  {
3541  int status = -1;
3542  int nRet;
3543  unsigned long sleepTime = 0;
3544  IntItemNode* current = 0;
3545  char msg[120];
3546  unsigned long innerCounter = 0; // used for update check after time interval
3547  unsigned long outerCounter = 0; // used for update check after time interval
3548 
3549  // set flag, that monitor thread has been started
3550  intMonitorThreadStarted = true;
3551 
3552  // set cancelation type
3553  status = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
3554  if (status != 0) {
3555 # ifdef __DEBUG
3556  printf("Set cancel state error [mon - int]: %d\n", status);
3557  fflush(stdout);
3558 # endif
3559  createLogMessage(MSG_WARNING,
3560  "Unable to configure monitor thread (int) properly. Monitoring is not affected.", 0);
3561  }
3562  status = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
3563  if (status != 0) {
3564 # ifdef __DEBUG
3565  printf("Set cancel type error [mon - int]: %d\n", status);
3566  fflush(stdout);
3567 # endif
3568  createLogMessage(MSG_WARNING,
3569  "Unable to configure monitor thread (int) properly. Monitoring is not affected.", 0);
3570  }
3571 
3572  createLogMessage(MSG_DEBUG, "Started monitor thread for INT values successfully.", 0);
3573 
3574  while (1) {
3575  current = firstIntNode;
3576  sleepTime = (unsigned long) (updateRate / intNodesAmount);
3577  while (current != 0) { // is lastIntNode->next (end of list)
3578  if (!checkIntLocation(current)) {
3579  msg[sprintf(msg, "Value of item %s (int) is corrupt, reconstruction failed. Ignoring!",
3580  current->intItem->name)] = 0;
3581  createLogMessage(MSG_ERROR, msg, 0);
3582  // message and do some stuff (like invalidate value)
3583  // (test, what happens if pointer is redirected ???)
3584  } else {
3585  if ((abs((*(current->intItem->location)) - current->lastTransmittedIntValue)
3586  >= current->threshold) || (outerCounter ==
3587  (innerCounter * TIME_INTERVAL_MULTIPLIER))) {
3588  nRet = dis_update_service(current->id);
3589  current->lastTransmittedIntValue = *(current->intItem->location);
3590 # ifdef __DEBUG
3591  printf("CE triggered an updated on %d clients for service %s [int]: %d\n",
3592  nRet, current->intItem->name, *(current->intItem->location));
3593  fflush(stdout);
3594 # endif
3595  }
3596  }
3597 
3598  ++innerCounter;
3599  current = current->next;
3600  usleep(sleepTime * 1000);
3601  // sleeps xy microseconds, needed milliseconds-> "* 1000"
3602  }
3603  // with the check of both counter, each service is at least updated after
3604  // every (deadband updateRate * nodesAmount) seconds
3605  innerCounter = 0;
3606  ++outerCounter;
3607  // after every service in list is updated set counter back to 0
3608  // the TIME_INTERVAL_MULTIPLIER is used to enlarge the time interval of
3609  // the request of services without touching the deadband checker updateRate
3610  if (outerCounter >= (intNodesAmount * TIME_INTERVAL_MULTIPLIER)) {
3611  outerCounter = 0;
3612  }
3613  }
3614  // should never be reached !
3615  pthread_exit(0);
3616 }
bool checkIntLocation(IntItemNode *node)
Definition: feeserver.c:3619
static unsigned short updateRate
Definition: feeserver.c:196
static IntItemNode * firstIntNode
Definition: feeserver.c:281
static bool intMonitorThreadStarted
Definition: feeserver.c:307
static unsigned int intNodesAmount
Definition: feeserver.c:293
void createLogMessage(unsigned int type, char *description, char *origin)
Definition: feeserver.c:1530
#define dis_update_service
Definition: dis.h:18
sprintf(name1,"NewService%d", i)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: