FACT++  1.0
void monitorValues ( )

Definition at line 1944 of file feeserver.c.

References checkLocation(), createLogMessage(), dis_update_service, firstNode, and sprintf().

Referenced by startMonitorThread().

1944  {
1945  int status = -1;
1946  int nRet;
1947  unsigned long sleepTime = 0;
1948  ItemNode* current = 0;
1949  char msg[120];
1950  unsigned long innerCounter = 0; // used for update check after time interval
1951  unsigned long outerCounter = 0; // used for update check after time interval
1952 
1953  // set flag, that monitor thread has been started
1954  monitorThreadStarted = true;
1955 
1956  // set cancelation type
1957  status = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
1958  if (status != 0) {
1959 # ifdef __DEBUG
1960  printf("Set cancel state error [mon - float]: %d\n", status);
1961  fflush(stdout);
1962 # endif
1963  createLogMessage(MSG_WARNING,
1964  "Unable to configure monitor thread (float) properly. Monitoring is not affected.", 0);
1965  }
1966  status = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
1967  if (status != 0) {
1968 # ifdef __DEBUG
1969  printf("Set cancel type error [mon - float]: %d\n", status);
1970  fflush(stdout);
1971 # endif
1972  createLogMessage(MSG_WARNING,
1973  "Unable to configure monitor thread (float) properly. Monitoring is not affected.", 0);
1974  }
1975 
1976  createLogMessage(MSG_DEBUG, "Started monitor thread for FLOAT values successfully.", 0);
1977 
1978  while (1) {
1979  current = firstNode;
1980  sleepTime = (unsigned long) (updateRate / nodesAmount);
1981  while (current != 0) { // is lastNode->next (end of list)
1982  if (!checkLocation(current)) {
1983  msg[sprintf(msg, "Value of item %s (float) is corrupt, reconstruction failed. Ignoring!",
1984  current->item->name)] = 0;
1985  createLogMessage(MSG_ERROR, msg, 0);
1986  // message and do some stuff (like invalidate value)
1987  // (test, what happens if pointer is redirected ???)
1988  } else {
1989  if ((fabsf((*(current->item->location)) - current->lastTransmittedValue)
1990  >= current->threshold) || (outerCounter ==
1991  (innerCounter * TIME_INTERVAL_MULTIPLIER))) {
1992  nRet = dis_update_service(current->id);
1993  current->lastTransmittedValue = *(current->item->location);
1994 # ifdef __DEBUG
1995  //printf("Updated %d clients for service %s [float]: %f\n", nRet,
1996  // current->item->name, *(current->item->location));
1997  //fflush(stdout);
1998 # endif
1999  }
2000  }
2001 
2002  ++innerCounter;
2003  current = current->next;
2004  usleep(sleepTime * 1000);
2005  // sleeps xy microseconds, needed milliseconds-> "* 1000"
2006  }
2007  // with the check of both counter, each service is at least updated after
2008  // every (deadband updateRate * nodesAmount) seconds
2009  innerCounter = 0;
2010  ++outerCounter;
2011  // after every service in list is updated set counter back to 0
2012  // the TIME_INTERVAL_MULTIPLIER is used to enlarge the time interval of
2013  // the request of services without touching the deadband checker updateRate
2014  if (outerCounter >= (nodesAmount * TIME_INTERVAL_MULTIPLIER)) {
2015  outerCounter = 0;
2016  }
2017  }
2018  // should never be reached !
2019  pthread_exit(0);
2020 }
static unsigned short updateRate
Definition: feeserver.c:196
void createLogMessage(unsigned int type, char *description, char *origin)
Definition: feeserver.c:1530
bool checkLocation(ItemNode *node)
Definition: feeserver.c:2023
static ItemNode * firstNode
Definition: feeserver.c:89
#define dis_update_service
Definition: dis.h:18
static bool monitorThreadStarted
Definition: feeserver.c:147
static unsigned int nodesAmount
Definition: feeserver.c:139
sprintf(name1,"NewService%d", i)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: