FACT++  1.0
int publish ( Item *  item)

Definition at line 1396 of file feeserver.c.

References add_item_node(), dis_add_service, findCharItem(), findIntItem(), findItem(), Memory::free(), id, Memory::malloc(), and sprintf().

Referenced by publishFloat().

1396  {
1397  unsigned int id;
1398  char* serviceName = 0;
1399 
1400  // check for right state
1401  if (state != COLLECTING) {
1402  return FEE_WRONG_STATE;
1403  }
1404 
1405  // Testing for NULL - Pointer
1406  // !! Attention: if pointer is not initialized and also NOT set to NULL, this won't help !!
1407  if (item == 0) {
1408 # ifdef __DEBUG
1409  printf("Bad item, not published\n");
1410  fflush(stdout);
1411 # endif
1412  return FEE_NULLPOINTER;
1413  }
1414  if (item->name == 0 || item->location == 0) {
1415 # ifdef __DEBUG
1416  printf("Bad item, not published\n");
1417  fflush(stdout);
1418 # endif
1419  return FEE_NULLPOINTER;
1420  }
1421 
1422  // Check name for duplicate here (float)
1423  if (findItem(item->name) != 0) {
1424 # ifdef __DEBUG
1425  printf("Item name already published (float), new float item discarded.\n");
1426  fflush(stdout);
1427 # endif
1428  return FEE_ITEM_NAME_EXISTS;
1429  }
1430  // Check in INT list
1431  if (findIntItem(item->name) != 0) {
1432 # ifdef __DEBUG
1433  printf("Item name already published (int), float item discarded.\n");
1434  fflush(stdout);
1435 # endif
1436  return FEE_ITEM_NAME_EXISTS;
1437  }
1438  // Check in Char service list
1439  if (findCharItem(item->name) != 0) {
1440 # ifdef __DEBUG
1441  printf("Item name already published in char list, float item discarded.\n");
1442  fflush(stdout);
1443 # endif
1444  return FEE_ITEM_NAME_EXISTS;
1445  }
1446 
1447  // -- add item as service --
1448  serviceName = (char*) malloc(serverNameLength + strlen(item->name) + 2);
1449  if (serviceName == 0) {
1450  return FEE_INSUFFICIENT_MEMORY;
1451  }
1452  // terminate string with '\0'
1453  serviceName[sprintf(serviceName, "%s_%s", serverName, item->name)] = 0;
1454  id = dis_add_service(serviceName, "F", (int*) item->location,
1455  sizeof(float), 0, 0);
1456  free(serviceName);
1457  add_item_node(id, item);
1458 
1459  return FEE_OK;
1460 }
ItemNode * findItem(char *name)
Definition: feeserver.c:3045
void add_item_node(unsigned int _id, Item *_item)
Definition: feeserver.c:1464
Definition: did.h:42
CharItemNode * findCharItem(char *name)
Definition: feeserver.c:4107
void * malloc()
Definition: EventBuilder.cc:99
char id[4]
Definition: FITS.h:71
static int serverNameLength
Definition: feeserver.c:189
char name[132]
Definition: did.h:46
static char * serverName
Definition: feeserver.c:183
void free(void *mem)
#define dis_add_service
Definition: dis.h:12
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: