// ... create a timer list int radTimerListCreate ( int noTimers, int notifyDescriptor ) { TIMER_ID timer; UCHAR *memory; int i; struct sigaction action; memory = (UCHAR *) malloc (sizeof (*timerList) + (sizeof (*timer) * noTimers)); if (memory == NULL) { return ERROR; } timerList = (TIMER_LIST_ID) memory; memset (timerList, 0, sizeof (*timerList)); // ... Set up the free list of timers timerList->noFreeTimers = noTimers; timerList->notifyFD = notifyDescriptor; radListReset (&timerList->freeList); radListReset (&timerList->pendingList); timer = (TIMER_ID) (timerList + 1); for (i = 0; i < noTimers; i ++) { radListAddToEnd (&timerList->freeList, (NODE_PTR)timer); timer += 1; } // ... catch SIGALRM memset (&action, 0, sizeof (action)); action.sa_handler = timerSignalHandler; if (sigemptyset (&action.sa_mask) == -1) { free (timerList); return ERROR; } if (sigaction (SIGALRM, &action, NULL) == -1) { free (timerList); return ERROR; } return OK; }
WV_ACCUM_ID sensorAccumInit (int minutesInAccumulator) { WV_ACCUM_ID newId; newId = (WV_ACCUM_ID)radBufferGet (sizeof (WV_ACCUM)); if (newId == NULL) { return NULL; } radListReset (&newId->samples); newId->secondsInAccumulator = minutesInAccumulator * 60; newId->sum = 0; return newId; }
/* ... create a row description to use when creating a new table; ... returns ROW_ID or NULL */ ROW_ID raddatabaseRowDescriptionCreate ( void ) { ROW_ID newId; newId = (ROW_ID) malloc (sizeof (*newId)); if (newId == NULL) { radMsgLog(PRI_MEDIUM, "raddatabaseRowDescriptionCreate: malloc failed!"); return NULL; } memset (newId, 0, sizeof (*newId)); radListReset (&newId->fields); return newId; }
int htmlmgrReReadImageFiles ( HTML_MGR_ID id, char *installPath ) { int i, numNodes; char confFilePath[256]; // cleanup the old definitions cleanupForecastRules (id); emptyWorkLists (id); radListReset (&id->imgList); radListReset (&id->templateList); // re-read the built-in generators sprintf (confFilePath, "%s/images.conf", installPath); if (readImageConfFile (id, confFilePath, FALSE) != OK) { return ERROR; } else { numNodes = radListGetNumberOfNodes (&id->imgList); radMsgLog (PRI_STATUS, "htmlmgrReReadImageFiles: %d built-in image definitions added", numNodes); } // re-read the user-defined generators sprintf (confFilePath, "%s/images-user.conf", installPath); i = readImageConfFile (id, confFilePath, TRUE); if (i == ERROR_ABORT) { radMsgLog (PRI_STATUS, "htmlmgrReReadImageFiles: no user image definitions found"); } else if (i == ERROR) { return ERROR; } else { radMsgLog (PRI_STATUS, "htmlmgrReReadImageFiles: %d user image definitions added", radListGetNumberOfNodes (&id->imgList) - numNodes); } // reinitialize our html template list sprintf (confFilePath, "%s/html-templates.conf", installPath); if (readHtmlTemplateFile (id, confFilePath) != OK) { return ERROR; } else { radMsgLog (PRI_STATUS, "htmlmgrReReadImageFiles: %d templates added", radListGetNumberOfNodes (&id->templateList)); } // reinitialize our forecast rule text list sprintf (confFilePath, "%s/forecast.conf", installPath); if (readForecastRuleConfigFile (id, confFilePath) != OK) { radMsgLog (PRI_STATUS, "htmlmgrReReadImageFiles: forecast html tags are disabled - %s not found...", confFilePath); } return OK; }
HTML_MGR_ID htmlmgrInit ( char *installPath, int isMetricUnits, char *imagePath, char *htmlPath, int arcInterval, int isExtendedData, char *name, char *city, char *state, int16_t elevation, int16_t latitude, int16_t longitude, char *mphaseIncrease, char *mphaseDecrease, char *mphaseFull, char *radarURL, char *forecastURL, char *dateFormat, int isDualUnits ) { HTML_MGR_ID newId; int i, numNodes, numImages, numTemplates; char confFilePath[256]; newId = &mgrWork; memset (newId, 0, sizeof (mgrWork)); radListReset (&newId->imgList); radListReset (&newId->templateList); newId->isMetricUnits = isMetricUnits; newId->archiveInterval = arcInterval; newId->isExtendedData = isExtendedData; newId->imagePath = imagePath; newId->htmlPath = htmlPath; newId->stationElevation = elevation; newId->stationLatitude = latitude; newId->stationLongitude = longitude; wvstrncpy (newId->stationName, name, sizeof(newId->stationName)); wvstrncpy (newId->stationCity, city, sizeof(newId->stationCity)); wvstrncpy (newId->stationState, state, sizeof(newId->stationState)); wvstrncpy (newId->mphaseIncrease, mphaseIncrease, sizeof(newId->mphaseIncrease)); wvstrncpy (newId->mphaseDecrease, mphaseDecrease, sizeof(newId->mphaseDecrease)); wvstrncpy (newId->mphaseFull, mphaseFull, sizeof(newId->mphaseFull)); wvstrncpy (newId->radarURL, radarURL, sizeof(newId->radarURL)); wvstrncpy (newId->forecastURL, forecastURL, sizeof(newId->forecastURL)); wvstrncpy (newId->dateFormat, dateFormat, sizeof(newId->dateFormat)); newId->isDualUnits = isDualUnits; // ... initialize the newArchiveMask newId->newArchiveMask = NEW_ARCHIVE_ALL; // ... first, the built-in generators sprintf (confFilePath, "%s/images.conf", installPath); if (readImageConfFile (newId, confFilePath, FALSE) != OK) { return NULL; } else { numNodes = radListGetNumberOfNodes (&newId->imgList); radMsgLog (PRI_STATUS, "htmlmgrInit: %d built-in image definitions added", numNodes); numImages = numNodes; } // ... next, the user-defined generators sprintf (confFilePath, "%s/images-user.conf", installPath); i = readImageConfFile (newId, confFilePath, TRUE); if (i == ERROR_ABORT) { radMsgLog (PRI_STATUS, "htmlmgrInit: no user image definitions found"); } else if (i == ERROR) { return NULL; } else { numImages = radListGetNumberOfNodes (&newId->imgList); radMsgLog (PRI_STATUS, "htmlmgrInit: %d user image definitions added", radListGetNumberOfNodes (&newId->imgList) - numNodes); } // ... now initialize our html template list sprintf (confFilePath, "%s/html-templates.conf", installPath); if (readHtmlTemplateFile (newId, confFilePath) != OK) { return NULL; } else { numTemplates = radListGetNumberOfNodes (&newId->templateList); radMsgLog (PRI_STATUS, "htmlmgrInit: %d templates added", numTemplates); } // ... now initialize our forecast rule text list sprintf (confFilePath, "%s/forecast.conf", installPath); if (readForecastRuleConfigFile (newId, confFilePath) != OK) { radMsgLog (PRI_STATUS, "htmlmgrInit: forecast html tags are disabled - %s not found...", confFilePath); } // ... initialize the sample label array htmlmgrSetSampleLabels(newId); // ... initialize our dial palette to conserve CPU cycles if (htmlGenPngDialInit (newId->imagePath) == ERROR) { radMsgLog (PRI_HIGH, "htmlmgrInit: htmlGenPngDialInit failed!"); return NULL; } statusUpdateStat(HTML_STATS_IMAGES_DEFINED, numImages); statusUpdateStat(HTML_STATS_TEMPLATES_DEFINED, numTemplates); return newId; }
/* ... the main entry point for the alarm process */ int main (int argc, char *argv[]) { void (*alarmHandler)(int); int retVal; FILE *pidfile; WVIEW_ALARM *alarm; int runAsDaemon = TRUE; if (argc > 1) { if (!strcmp(argv[1], "-f")) { runAsDaemon = FALSE; } } memset (&alarmsWork, 0, sizeof (alarmsWork)); radListReset (&alarmsWork.alarmList); radListReset (&alarmsWork.clientList); /* ... initialize some system stuff first */ retVal = alarmsSysInit (&alarmsWork); if (retVal == ERROR) { radMsgLogInit (PROC_NAME_ALARMS, FALSE, TRUE); radMsgLog (PRI_CATASTROPHIC, "wvalarmd sysinit failed!"); radMsgLogExit (); exit (1); } else if (retVal == ERROR_ABORT) { exit (2); } /* ... call the global radlib system init function */ if (radSystemInit (WVIEW_SYSTEM_ID) == ERROR) { radMsgLogInit (PROC_NAME_ALARMS, TRUE, TRUE); radMsgLog (PRI_CATASTROPHIC, "radSystemInit failed!"); radMsgLogExit (); exit (1); } /* ... call the radlib process init function */ if (radProcessInit (PROC_NAME_ALARMS, alarmsWork.fifoFile, PROC_NUM_TIMERS_ALARMS, runAsDaemon, // TRUE for daemon msgHandler, evtHandler, NULL) == ERROR) { printf ("\nradProcessInit failed: %s\n\n", PROC_NAME_ALARMS); radSystemExit (WVIEW_SYSTEM_ID); exit (1); } alarmsWork.myPid = getpid (); pidfile = fopen (alarmsWork.pidFile, "w"); if (pidfile == NULL) { radMsgLog (PRI_CATASTROPHIC, "lock file create failed!"); radProcessExit (); radSystemExit (WVIEW_SYSTEM_ID); exit (1); } fprintf (pidfile, "%d", getpid ()); fclose (pidfile); alarmHandler = radProcessSignalGetHandler (SIGALRM); radProcessSignalCatchAll (defaultSigHandler); radProcessSignalCatch (SIGALRM, alarmHandler); radProcessSignalRelease(SIGABRT); // grab all of our alarm definitions from the config database retVal = readAlarmsConfig (); if (retVal == ERROR_ABORT) { radMsgLog (PRI_HIGH, "ALARM daemon not enabled - exiting..."); alarmsSysExit (&alarmsWork); radProcessExit (); radSystemExit (WVIEW_SYSTEM_ID); exit (0); } else if (retVal < 0) { radMsgLog (PRI_HIGH, "readAlarmsConfig failed - " "is there a problem with the wview config database?"); alarmsSysExit (&alarmsWork); radProcessExit (); radSystemExit (WVIEW_SYSTEM_ID); exit (1); } else { radMsgLog (PRI_STATUS, "alarms: added %d alarm definitions", retVal); } if (statusInit(alarmsWork.statusFile, alarmsStatusLabels) == ERROR) { radMsgLog (PRI_HIGH, "ALARM status init failed - exiting..."); alarmsSysExit (&alarmsWork); radProcessExit (); radSystemExit (WVIEW_SYSTEM_ID); exit (1); } statusUpdate(STATUS_BOOTING); statusUpdateStat(ALARM_STATS_ALARMS, retVal); // wait a bit here before continuing radUtilsSleep (500); // register with the radlib message router if (radMsgRouterInit (WVIEW_RUN_DIR) == ERROR) { statusUpdateMessage("radMsgRouterInit failed!"); radMsgLog (PRI_HIGH, "radMsgRouterInit failed!"); statusUpdate(STATUS_ERROR); alarmsSysExit (&alarmsWork); radProcessExit (); radSystemExit (WVIEW_SYSTEM_ID); exit (1); } // enable message reception from the radlib router for SHUTDOWN msgs radMsgRouterMessageRegister (WVIEW_MSG_TYPE_SHUTDOWN); // wait for the wview daemon to be ready if (waitForWviewDaemon () == ERROR) { radMsgLog (PRI_HIGH, "waitForWviewDaemon failed"); statusUpdate(STATUS_ERROR); radMsgRouterExit (); alarmsSysExit (&alarmsWork); radProcessExit (); radSystemExit (WVIEW_SYSTEM_ID); exit (1); } // finally, initialize our data feed socket alarmsWork.dataFeedServer = radSocketServerCreate(WV_DATAFEED_PORT); if (alarmsWork.dataFeedServer == NULL) { statusUpdateMessage("radSocketServerCreate failed"); radMsgLog (PRI_HIGH, "radSocketServerCreate failed..."); statusUpdate(STATUS_ERROR); radMsgRouterExit (); alarmsSysExit (&alarmsWork); radProcessExit (); radSystemExit (WVIEW_SYSTEM_ID); exit (1); } // add it to our descriptors of interest if (radProcessIORegisterDescriptor(radSocketGetDescriptor(alarmsWork.dataFeedServer), dataFeedAccept, NULL) == ERROR) { statusUpdateMessage("radProcessIORegisterDescriptor server failed"); radMsgLog (PRI_HIGH, "radProcessIORegisterDescriptor failed..."); statusUpdate(STATUS_ERROR); radSocketDestroy (alarmsWork.dataFeedServer); radMsgRouterExit (); alarmsSysExit (&alarmsWork); radProcessExit (); radSystemExit (WVIEW_SYSTEM_ID); exit (1); } // enable message reception from the radlib router for loop data radMsgRouterMessageRegister (WVIEW_MSG_TYPE_LOOP_DATA_SVC); // enable message reception from the radlib router for archive data radMsgRouterMessageRegister (WVIEW_MSG_TYPE_ARCHIVE_DATA); // enable message reception from the radlib router for POLL msgs radMsgRouterMessageRegister (WVIEW_MSG_TYPE_POLL); // enter normal processing alarmsWork.inMainLoop = TRUE; statusUpdate(STATUS_RUNNING); statusUpdateMessage("Normal operation"); radMsgLog (PRI_STATUS, "running..."); // Do we need to trigger a test alarm? if (alarmsWork.doTest) { if (1 <= alarmsWork.doTestNumber && alarmsWork.doTestNumber <= ALARMS_MAX) { // Generate the bad boy: retVal = 1; for (alarm = (WVIEW_ALARM *) radListGetFirst (&alarmsWork.alarmList); retVal <= ALARMS_MAX && alarm != NULL; alarm = (WVIEW_ALARM *) radListGetNext (&alarmsWork.alarmList, (NODE_PTR)alarm)) { if (retVal == alarmsWork.doTestNumber) { // This is the one to test: alarm->triggerValue = -1; // run user script here if (executeScript(alarm) != 0) { radMsgLog (PRI_MEDIUM, "Test Alarm %d: script %s failed", retVal, alarm->scriptToRun); } else { radMsgLog (PRI_MEDIUM, "Test Alarm %d: script %s executed", retVal, alarm->scriptToRun); } retVal = ALARMS_MAX; } retVal ++; } } else { radMsgLog (PRI_MEDIUM, "Test Alarm: bad alarm index %d given!", alarmsWork.doTestNumber); } } while (!alarmsWork.exiting) { // wait on something interesting if (radProcessWait (0) == ERROR) { alarmsWork.exiting = TRUE; } } statusUpdateMessage("exiting normally"); radMsgLog (PRI_STATUS, "exiting normally..."); statusUpdate(STATUS_SHUTDOWN); radSocketDestroy (alarmsWork.dataFeedServer); radMsgRouterExit (); alarmsSysExit (&alarmsWork); radProcessExit (); radSystemExit (WVIEW_SYSTEM_ID); exit (0); }