FACT++  1.0
void add_item_node ( unsigned int  _id,
Item *  _item 
)

Definition at line 1464 of file feeserver.c.

References calculateChecksum(), cleanUp(), lastNode, Memory::malloc(), and nodesAmount.

Referenced by publish().

1464  {
1465  //create new node with enough memory
1466  ItemNode* newNode = 0;
1467 
1468  newNode = (ItemNode*) malloc(sizeof(ItemNode));
1469  if (newNode == 0) {
1470  //no memory available!
1471 # ifdef __DEBUG
1472  printf("no memory available while adding itemNode!\n");
1473 # endif
1474  // !!! unable to run FeeServer, write msg in kernel logger !!! (->Tobias)
1475  cleanUp();
1476  exit(201);
1477  }
1478  //initialize "members" of node
1479  newNode->prev = 0;
1480  newNode->next = 0;
1481  newNode->id = _id;
1482  newNode->item = _item;
1483  newNode->lastTransmittedValue = *(_item->location);
1484  //if default deadband is negative -> set threshold 0, otherwise set half of defaultDeadband
1485  newNode->threshold = (_item->defaultDeadband < 0) ? 0.0 : (_item->defaultDeadband / 2);
1486  /*
1487  if(_item->defaultDeadband < 0) {
1488  newNode->threshold = 0.0;
1489  } else {
1490  newNode->threshold = _item->defaultDeadband / 2;
1491  }
1492 */
1493  newNode->locBackup = _item->location;
1494  newNode->checksum = calculateChecksum((unsigned char*) &(_item->location),
1495  sizeof(volatile float*));
1496  newNode->checksumBackup = newNode->checksum;
1497 
1498 #ifdef __DEBUG
1499  // complete debug display of added Item
1500 /*
1501  printf("Item: %d\n", _id);
1502  printf("location: %f, locBackup %f\n", *(_item->location), *(newNode->locBackup));
1503  printf("location addr: %p, locBackup addr %p\n", _item->location, newNode->locBackup);
1504  printf("checksum1: %d, checksum2: %d\n\n", newNode->checksum,
1505  newNode->checksumBackup);
1506 */
1507 #endif
1508 
1509 # ifdef __DEBUG
1510  // short debug display of added Item
1511  printf("init of %s with ID %d: %f\n", newNode->item->name, newNode->id,
1512  newNode->lastTransmittedValue);
1513  fflush(stdout);
1514 # endif
1515 
1516  ++nodesAmount;
1517  //redirect pointers of doubly linked list
1518  if (firstNode != 0) {
1519  lastNode->next = newNode;
1520  newNode->prev = lastNode;
1521  lastNode = newNode;
1522  } else {
1523  firstNode = newNode;
1524  lastNode = newNode;
1525  }
1526 }
unsigned int calculateChecksum(unsigned char *buffer, int size)
Definition: feeserver.c:2372
void cleanUp()
Definition: feeserver.c:3159
void * malloc()
Definition: EventBuilder.cc:99
static ItemNode * firstNode
Definition: feeserver.c:89
static unsigned int nodesAmount
Definition: feeserver.c:139
static ItemNode * lastNode
Definition: feeserver.c:95

+ Here is the call graph for this function:

+ Here is the caller graph for this function: