FACT++  1.0
int getDeadband ( IssueStruct *  issueParam)

Definition at line 2586 of file feeserver.c.

References createLogMessage(), findIntItem(), findItem(), Memory::free(), Memory::malloc(), and sprintf().

Referenced by command_handler().

2586  {
2587  char* itemName = 0;
2588  int nameLength = 0;
2589  ItemNode* node = 0;
2590  IntItemNode* intNode = 0;
2591  float currentDeadband = 0;
2592  char msg[120];
2593 
2594  if ((*issueParam).size <= 0) {
2595  (*issueParam).size = 0;
2596  createLogMessage(MSG_DEBUG,
2597  "FeeServer command for getting dead band contained invalid parameter.",
2598  0);
2599  return FEE_INVALID_PARAM;
2600  }
2601 
2602  nameLength = (*issueParam).size;
2603  itemName = (char*) malloc(nameLength + 1);
2604  if (itemName == 0) {
2605  (*issueParam).size = 0;
2606  return FEE_INSUFFICIENT_MEMORY;
2607  }
2608 
2609  memcpy(itemName, (*issueParam).command, nameLength);
2610  itemName[nameLength] = 0;
2611 
2612  // search wanted itemNode
2613  node = findItem(itemName);
2614  if (node == 0) {
2615  //check in IntItemList
2616  intNode = findIntItem(itemName);
2617  }
2618  if ((node == 0) && (intNode == 0)) {
2619  // message is NOT sent in findItem() or findIntItem()
2620  msg[sprintf(msg, "Item %s not found in list.", itemName)] = 0;
2621  createLogMessage(MSG_WARNING, msg, 0);
2622 # ifdef __DEBUG
2623  printf("Item %s not found in list.\n", itemName);
2624  fflush(stdout);
2625 # endif
2626 
2627  free(itemName);
2628  (*issueParam).size = 0;
2629  createLogMessage(MSG_DEBUG,
2630  "FeeServer command for getting dead band contained invalid parameter.",
2631  0);
2632  return FEE_INVALID_PARAM;
2633  } else {
2634  (*issueParam).result = (char*) malloc(sizeof(float) + nameLength);
2635  if ((*issueParam).result == 0) {
2636  (*issueParam).size = 0;
2637  return FEE_INSUFFICIENT_MEMORY;
2638  }
2639 
2640  // copy current deadband value to ACK result
2641  if (node != 0) {
2642  currentDeadband = node->threshold * 2.0; // compute deadband
2643  } else {
2644  currentDeadband = intNode->threshold * 2.0; // compute deadband
2645  }
2646 
2647  memcpy((*issueParam).result, &currentDeadband, sizeof(float));
2648  memcpy((*issueParam).result + sizeof(float), itemName, nameLength);
2649  (*issueParam).size = sizeof(float) + nameLength;
2650 # ifdef __DEBUG
2651  printf("Current deadband on item %s is %f.\n", itemName, currentDeadband);
2652  fflush(stdout);
2653 # endif
2654  msg[sprintf(msg, "Current deadband for item %s is %f.", itemName,
2655  currentDeadband)] = 0;
2656  createLogMessage(MSG_DEBUG, msg, 0);
2657  }
2658  free(itemName);
2659  return FEE_OK;
2660 }
Definition: dns.c:26
ItemNode * findItem(char *name)
Definition: feeserver.c:3045
void * malloc()
Definition: EventBuilder.cc:99
void createLogMessage(unsigned int type, char *description, char *origin)
Definition: feeserver.c:1530
void free(void *mem)
IntItemNode * findIntItem(char *name)
Definition: feeserver.c:3378
sprintf(name1,"NewService%d", i)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: