FACT++  1.0
int setDeadband ( IssueStruct *  issueParam)

Definition at line 2494 of file feeserver.c.

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

Referenced by command_handler().

2494  {
2495  char* itemName = 0;
2496  float newDeadband = 0;
2497  int nameLength = 0;
2498  ItemNode* node = 0;
2499  IntItemNode* intNode = 0;
2500  char msg[100];
2501  unsigned int count = 0;
2502 
2503  if ((*issueParam).size <= sizeof(newDeadband)) {
2504  (*issueParam).size = 0;
2505  createLogMessage(MSG_DEBUG,
2506  "FeeServer command for setting dead band contained invalid parameter.",
2507  0);
2508  return FEE_INVALID_PARAM;
2509  }
2510 
2511  nameLength = (*issueParam).size - sizeof(newDeadband);
2512 
2513  if (nameLength <= 0) {
2514  (*issueParam).size = 0;
2515  createLogMessage(MSG_DEBUG,
2516  "FeeServer command for setting dead band contained no service name.",
2517  0);
2518  return FEE_INVALID_PARAM;
2519  }
2520 
2521  itemName = (char*) malloc(nameLength + 1);
2522  if (itemName == 0) {
2523  (*issueParam).size = 0;
2524  return FEE_INSUFFICIENT_MEMORY;
2525  }
2526 
2527  memcpy(&newDeadband, (*issueParam).command, sizeof(newDeadband));
2528  memcpy(itemName, (*issueParam).command + sizeof(newDeadband), nameLength);
2529  itemName[nameLength] = 0;
2530 
2531  if (itemName[0] != '*') {
2532  // search wanted itemNode
2533  node = findItem(itemName);
2534  if (node == 0) {
2535  //check in IntItemList
2536  intNode = findIntItem(itemName);
2537  }
2538  if ((node == 0) && (intNode == 0)) {
2539  // message is NOT sent in findItem() or findIntItem()
2540  msg[sprintf(msg, "Item %s not found in list.", itemName)] = 0;
2541  createLogMessage(MSG_WARNING, msg, 0);
2542 # ifdef __DEBUG
2543  printf("Item %s not found in list.\n", itemName);
2544  fflush(stdout);
2545 # endif
2546 
2547  free(itemName);
2548  (*issueParam).size = 0;
2549  createLogMessage(MSG_DEBUG,
2550  "FeeServer command for setting dead band contained invalid parameter.",
2551  0);
2552  return FEE_INVALID_PARAM;
2553  } else {
2554  // set new threshold ( = dead band / 2)
2555  if (node != 0) {
2556  node->threshold = newDeadband / 2;
2557  } else {
2558  intNode->threshold = newDeadband / 2;
2559  }
2560 # ifdef __DEBUG
2561  printf("Set deadband on item %s to %f.\n", itemName, newDeadband);
2562  fflush(stdout);
2563 # endif
2564  msg[sprintf(msg, "New dead band (%f) is set for item %s.",
2565  newDeadband, itemName)] = 0;
2566  createLogMessage(MSG_INFO, msg, 0);
2567  }
2568  } else {
2569  // set now for all wanted value the new deadband
2570  count = setDeadbandBroadcast(itemName, newDeadband);
2571 
2572 # ifdef __DEBUG
2573  printf("Set deadband for %d items (%s) to %f.\n", count, itemName, newDeadband);
2574  fflush(stdout);
2575 # endif
2576  msg[sprintf(msg, "New dead band (%f) is set for %d items (%s).",
2577  newDeadband, count, itemName)] = 0;
2578  createLogMessage(MSG_INFO, msg, 0);
2579  }
2580 
2581  free(itemName);
2582  (*issueParam).size = 0;
2583  return FEE_OK;
2584 }
Definition: dns.c:26
ItemNode * findItem(char *name)
Definition: feeserver.c:3045
unsigned int setDeadbandBroadcast(char *name, float newDeadbandBC)
Definition: feeserver.c:2858
void * malloc()
Definition: EventBuilder.cc:99
void createLogMessage(unsigned int type, char *description, char *origin)
Definition: feeserver.c:1530
int count
Definition: db_dim_server.c:18
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: