FACT++  1.0
int start ( int  initState)

Definition at line 1740 of file feeserver.c.

References ack_service(), cleanUp(), command_handler(), createHeader(), createLogMessage(), dis_add_cmnd, dis_add_service, dis_remove_service, dis_start_serving, Memory::free(), Memory::malloc(), provideUpdateRate(), sprintf(), startLogWatchDogThread(), and startMonitorThread().

Referenced by EventBuilderWrapper::applyCalib(), DrsCalibrate::ApplyCh(), Compress(), createBenchmark(), Decompress(), FactGui::DisplayEventData(), initialize(), main(), UIConnector::on_autoScaleColor_clicked(), Queue< pair< Time, GUI_STAT > >::Queue(), AutoScheduler< T >::Schedule(), MyTimer::timerHandler(), Tools::Trim(), FitsFile::WriteData(), DataWriteFits2::WriteFooter(), DataWriteFits::WriteFooter(), and FitsFile::WriteKeyNT().

1740  {
1741  int nRet = FEE_UNKNOWN_RETVAL;
1742  char* serviceName = 0;
1743  char* messageName = 0;
1744  char* commandName = 0;
1745  char msgStructure[50];
1746 
1747  if (state == COLLECTING) {
1748  //----- add service for acknowledge -----
1749  serviceName = (char*) malloc(serverNameLength + 13);
1750  if (serviceName == 0) {
1751  //no memory available!
1752 # ifdef __DEBUG
1753  printf("no memory available while trying to create ACK channel!\n");
1754  fflush(stdout);
1755 # endif
1756  // !!! unable to run FeeServer, write msg in kernel logger !!! (-> Tobias)
1757  cleanUp();
1758  exit(201);
1759  }
1760  // compose ACK channel name and terminate with '\0'
1761  serviceName[sprintf(serviceName, "%s_Acknowledge", serverName)] = 0;
1762  if (cmndACK != 0) {
1763  free(cmndACK);
1764  cmndACK = 0;
1765  }
1766  // take created header
1767  cmndACK = createHeader(0, initState, false, false, 0);
1768  cmndACKSize = HEADER_SIZE;
1769  // add ACK channel as service to DIM
1770  serviceACKID = dis_add_service(serviceName, "C", 0, 0, &ack_service,
1771  ACK_SERVICE_TAG);
1772  free(serviceName);
1773 
1774  //----- add message service -----
1775  messageName = (char*) malloc(serverNameLength + 9);
1776  if (messageName == 0) {
1777  //no memory available!
1778 # ifdef __DEBUG
1779  printf("no memory available while trying to create message channel!\n");
1780  fflush(stdout);
1781 # endif
1782  // !!! unable to run FeeServer, write msg in kernel logger !!! (->Tobias)
1783  cleanUp();
1784  exit(201);
1785  }
1786  // compose message channel name and terminate with '\0'
1787  messageName[sprintf(messageName, "%s_Message", serverName)] = 0;
1788  // compose message structure
1789  msgStructure[sprintf(msgStructure, "I:1;C:%d;C:%d;C:%d;C:%d",
1790  MSG_DETECTOR_SIZE, MSG_SOURCE_SIZE, MSG_DESCRIPTION_SIZE,
1791  MSG_DATE_SIZE)] = 0;
1792  // add message channel as service to DIM
1793  messageServiceID = dis_add_service(messageName, msgStructure, (int*) &message,
1794  sizeof(unsigned int) + MSG_DETECTOR_SIZE + MSG_SOURCE_SIZE +
1795  MSG_DESCRIPTION_SIZE + MSG_DATE_SIZE, 0, 0);
1796  free(messageName);
1797 
1798  //----- before start serving we add the only command handled by the server -----
1799  commandName = (char*) malloc(serverNameLength + 9);
1800  if (commandName == 0) {
1801  //no memory available!
1802 # ifdef __DEBUG
1803  printf("no memory available while trying to create CMD channel!\n");
1804  fflush(stdout);
1805 # endif
1806  // !!! unable to run FeeServer, write msg in kernel logger !!! (->Tobias)
1807  cleanUp();
1808  exit(201);
1809  }
1810  // compose Command channel name and terminate with '\0'
1811  commandName[sprintf(commandName, "%s_Command", serverName)] = 0;
1812  // add CMD channel as command to DIM, no tag needed,
1813  // only one command possible
1814  commandID = dis_add_cmnd(commandName, "C", &command_handler, 0);
1815  free(commandName);
1816 
1817  //-- now start serving --
1818  if (dis_start_serving(serverName) == 1) {
1819  // if start server was successful
1820  if (initState == FEE_OK) {
1821  state = RUNNING;
1822  // start monitoring thread now
1823  nRet = startMonitorThread();
1824  if (nRet != FEE_OK) {
1825 # ifdef __DEBUG
1826  printf("Could NOT start monitor thread, error: %d\n", nRet);
1827  fflush(stdout);
1828 # endif
1829  createLogMessage(MSG_ERROR,
1830  "Unable to start monitor thread on FeeServer.", 0);
1831  return nRet;
1832  }
1833  // inform CE about update rate
1835  createLogMessage(MSG_INFO,
1836  "FeeServer started correctly, including monitor thread.", 0);
1837  nRet = FEE_OK;
1838  } else {
1839  state = ERROR_STATE;
1840  createLogMessage(MSG_ERROR,
1841  "Initialisation of ControlEngine failed. FeeServer is running in ERROR state (without CE).",
1842  0);
1843  // starting itself worked, so nRet is OK
1844  nRet = FEE_OK;
1845  }
1846  // start "relicated log messages" watchdog now
1847  nRet = startLogWatchDogThread();
1848  if (nRet != FEE_OK) {
1849 # ifdef __DEBUG
1850  printf("Could NOT start log watch dog thread, error: %d; FeeServer will run without it.\n",
1851  nRet);
1852  fflush(stdout);
1853 # endif
1854  createLogMessage(MSG_WARNING,
1855  "Can not start LogWatchDog thread (filters replicated MSGs). Uncritical error - running without it.",
1856  0);
1857  }
1858  } else {
1859  // starting server was not successful, so remove added core - services
1860  // so they can be added again by next start() - call
1862  free(cmndACK);
1863  cmndACK = 0;
1864  cmndACKSize = 0;
1867  nRet = FEE_FAILED;
1868  }
1869  return nRet;
1870  }
1871  //server is already running
1872  return FEE_OK;
1873 }
#define dis_remove_service
Definition: dis.h:19
static MessageStruct message
Definition: feeserver.c:101
void cleanUp()
Definition: feeserver.c:3159
void command_handler(int *tag, char *address, int *size)
Definition: feeserver.c:829
char * createHeader(unsigned int id, short errorCode, bool huffmanFlag, bool checksumFlag, int checksum)
Definition: feeserver.c:2315
void * malloc()
Definition: EventBuilder.cc:99
static unsigned int serviceACKID
Definition: feeserver.c:153
static int serverNameLength
Definition: feeserver.c:189
void createLogMessage(unsigned int type, char *description, char *origin)
Definition: feeserver.c:1530
#define dis_add_cmnd
Definition: dis.h:13
void ack_service(int *tag, char **address, int *size)
Definition: feeserver.c:1312
int startLogWatchDogThread()
Definition: feeserver.c:2079
#define dis_start_serving
Definition: dis.h:8
static char * cmndACK
Definition: feeserver.c:171
static char * serverName
Definition: feeserver.c:183
void provideUpdateRate()
Definition: feeserver.c:2848
void free(void *mem)
int startMonitorThread()
Definition: feeserver.c:1878
static int cmndACKSize
Definition: feeserver.c:177
#define dis_add_service
Definition: dis.h:12
static unsigned int commandID
Definition: feeserver.c:165
sprintf(name1,"NewService%d", i)
static unsigned int messageServiceID
Definition: feeserver.c:159

+ Here is the call graph for this function:

+ Here is the caller graph for this function: