예제 #1
0
파일: raddatabase.c 프로젝트: mteel/radlib
/*  ... returns OK or ERROR
*/
int raddatabaseRowDescriptionAddField
(
    ROW_ID          id,
    const char      *name,
    UINT            type,
    int             maxLength
)
{
    FIELD_ID        field;

    field = (FIELD_ID) malloc (sizeof (*field));
    if (field == NULL)
    {
        radMsgLog(PRI_MEDIUM, "raddatabaseRowDescriptionCreate: malloc failed!");
        return ERROR;
    }
    memset (field, 0, sizeof (*field));

    strncpy (field->name, name, DB_FIELD_NAME_MAX-1);
    field->type = type;
    field->cvalLength = maxLength;

    radListAddToEnd (&id->fields, (NODE_PTR)field);
    return OK;
}
예제 #2
0
파일: radtimers.c 프로젝트: mteel/radlib
/*  ... put a timer on the pending list (start it)
*/
void radTimerStart
(
    TIMER_ID        timer,
    ULONG           time
)
{
    if (timer == NULL)
        return;

    radUtilsDisableSignal (SIGALRM);

    // only update the delta times and lastTick before adding the new one
    serviceTimers (FALSE);
        
    timer->deltaTime = time;

    if (timer->pending == FALSE)
    {
        // add to pending list
        timer->pending = TRUE;
        radListAddToEnd (&timerList->pendingList, (NODE_PTR)timer);
    }

    // process timers right here to avoid race conditions, then restart signal
    radUtilsSetIntervalTimer (serviceTimers (TRUE));

    radUtilsEnableSignal (SIGALRM);
    return;
}
예제 #3
0
파일: htmlMgr.c 프로젝트: HEnquist/wview
static int readHtmlTemplateFile (HTML_MGR *mgr, char *filename)
{
    HTML_TMPL       *html;
    FILE            *file;
    char            *token;
    char            temp[HTML_MAX_LINE_LENGTH];

    file = fopen (filename, "r");
    if (file == NULL)
    {
        radMsgLog (PRI_HIGH, "htmlmgrInit: %s does not exist!",
                   filename);
        return ERROR_ABORT;
    }

    while (fgets (temp, HTML_MAX_LINE_LENGTH, file) != NULL)
    {
        if (temp[0] == ' ' || temp[0] == '\n' || temp[0] == '#')
        {
            // comment or whitespace
            continue;
        }

        html = (HTML_TMPL *)malloc (sizeof (*html));
        if (html == NULL)
        {
            for (html = (HTML_TMPL *)radListRemoveFirst (&mgr->templateList);
                 html != NULL;
                 html = (HTML_TMPL *)radListRemoveFirst (&mgr->templateList))
            {
                free (html);
            }

            fclose (file);
            return ERROR;
        }

        // do the template file name
        token = strtok (temp, " \t\n");
        if (token == NULL)
        {
            free (html);
            continue;
        }
        wvstrncpy (html->fname, token, sizeof(html->fname));

        radListAddToEnd (&mgr->templateList, (NODE_PTR)html);
    }

    fclose (file);
    return OK;
}
예제 #4
0
파일: radtimers.c 프로젝트: mteel/radlib
//  ... 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;
}
예제 #5
0
파일: radtimers.c 프로젝트: mteel/radlib
/*  ... Deallocate a timer
*/
void radTimerDelete
(
    TIMER_ID        timer
)
{
    if (timer == NULL)
        return;

    //  ... If timer is on the pending list, remove it
    radTimerStop (timer);

    radListAddToEnd (&timerList->freeList, (NODE_PTR)timer);
    timerList->noFreeTimers += 1;
    return;
}
예제 #6
0
파일: alarms.c 프로젝트: breu/wview
static void dataFeedAccept (int fd, void *userData)
{
    RADSOCK_ID          newConnection;
    WVIEW_ALARM_CLIENT  *client;

    newConnection = radSocketServerAcceptConnection(alarmsWork.dataFeedServer);
    if (newConnection == NULL)
    {
        statusUpdateMessage("dataFeed: accept connection failed!");
        radMsgLog (PRI_MEDIUM, "dataFeed: accept connection failed!");
        return;
    }

    // stick him on the data feed client list
    client = (WVIEW_ALARM_CLIENT *) malloc(sizeof(*client));
    if (client == NULL)
    {
        radMsgLog (PRI_MEDIUM, "dataFeedAccept: malloc failed!");
        radSocketDestroy(newConnection);
        return;
    }
    memset(client, 0, sizeof (*client));

    client->client = newConnection;

    radSocketSetBlocking(client->client, TRUE);

    // add it to our descriptors of interest:
    if (radProcessIORegisterDescriptor(radSocketGetDescriptor(client->client),
                                       ClientDataRX,
                                       (void*)client->client)
        == ERROR)
    {
        statusUpdateMessage("dataFeedAccept: register descriptor failed!");
        radMsgLog (PRI_MEDIUM, "dataFeedAccept: register descriptor failed!");
        radSocketDestroy(client->client);
        return;
    }

    radListAddToEnd(&alarmsWork.clientList, (NODE_PTR)client);

    statusIncrementStat(ALARM_STATS_CLIENTS);
    radMsgLog (PRI_STATUS, "dataFeed: client %s:%d accepted...",
               radSocketGetHost (client->client),
               radSocketGetPort (client->client));

    return;
}
예제 #7
0
파일: htmlMgr.c 프로젝트: HEnquist/wview
static int readImageConfFile (HTML_MGR *mgr, char *filename, int isUser)
{
    HTML_IMG        *img;
    FILE            *file;
    int             i, done;
    char            *token;
    char            temp[1536];

    file = fopen (filename, "r");
    if (file == NULL)
    {
        radMsgLog (PRI_HIGH, "htmlmgrInit: %s does not exist!",
                   filename);
        return ERROR_ABORT;
    }

    while (fgets (temp, 1536, file) != NULL)
    {
        if (temp[0] == ' ' || temp[0] == '\n' || temp[0] == '#')
        {
            // comment or whitespace
            continue;
        }

        token = strtok (temp, " \t");
        if (token == NULL)
        {
            continue;
        }

        img = (HTML_IMG *)malloc (sizeof (*img));
        if (img == NULL)
        {
            for (img = (HTML_IMG *)radListRemoveFirst (&mgr->imgList);
                    img != NULL;
                    img = (HTML_IMG *)radListRemoveFirst (&mgr->imgList))
            {
                free (img);
            }

            fclose (file);
            return ERROR;
        }
        memset (img, 0, sizeof (*img));

        img->mgrWork    = mgr;
        
        
        //  ... if legacy image type is found, skip it
        if (!strncmp (token, "IMG_TYPE_", 9))
        {
            // get the next token
            token = strtok (NULL, " \t");
            if (token == NULL)
            {
                free (img);
                goto line_loop_end;
            }
        }

        //  ... do the file name
        wvstrncpy (img->fname, token, sizeof(img->fname));

        //  ... now the label
        token = strtok (NULL, " \t");
        if (token == NULL)
        {
            free (img);
            goto line_loop_end;
        }
        if (token[strlen(token)-1] == '"')
        {
            // we're done!
            strncpy (img->title, &token[1], strlen(token)-2);   // lose quotes
        }
        else
        {
            done = FALSE;
            wvstrncpy (img->title, &token[1], sizeof(img->title));
            while (!done)
            {
                token = strtok (NULL, " ");
                if (token == NULL)
                {
                    free(img);
                    goto line_loop_end;
                }
                else
                {
                    if (token[strlen(token)-1] == '"')
                    {
                        done = TRUE;
                        token[strlen(token)-1] = 0;
                    }
                    strcat (img->title, " ");
                    strcat (img->title, token);
                }
            }
        }

        //  ... now the units label (no spaces allowed)
        token = strtok (NULL, " \t");
        if (token == NULL)
        {
            free (img);
            goto line_loop_end;
        }
        wvstrncpy (img->units, token, sizeof(img->units));

        //  ... now the decimal places
        token = strtok (NULL, " \t");
        if (token == NULL)
        {
            free (img);
            goto line_loop_end;
        }
        img->decimalPlaces = atoi (token);

        //  ... finally, the generator index
        token = strtok (NULL, " \t\n");
        if (token == NULL)
        {
            free (img);
            goto line_loop_end;
        }
        i = atoi (token);
        if (isUser)
        {
            img->generator = user_generators[i];
        }
        else
        {
            img->generator = images_generators[i];
        }

        radListAddToEnd (&mgr->imgList, (NODE_PTR)img);

// Loop end label:
line_loop_end:
        continue;
    }

    fclose (file);
    return OK;
}
예제 #8
0
파일: alarms.c 프로젝트: breu/wview
static int readAlarmsConfig (void)
{
    WVIEW_ALARM     *alarm;
    int             i, numAlarms = 0;
    int             iValue;
    char            type[_MAX_PATH];
    int             boolMAX;
    double          thresh;
    int             abate;
    char            exec[_MAX_PATH];
    char            conftype[64];
    const char*     temp;

    if (wvconfigInit(FALSE) == ERROR)
    {
        radMsgLog (PRI_CATASTROPHIC, "wvconfigInit failed!");
        return ERROR;
    }

    // Is the alarms daemon enabled?
    iValue = wvconfigGetBooleanValue(configItem_ENABLE_ALARMS);
    if (iValue == ERROR || iValue == 0)
    {
        wvconfigExit ();
        return ERROR_ABORT;
    }

    // set the wview verbosity setting
    if (wvutilsSetVerbosity (WV_VERBOSE_WVALARMD) == ERROR)
    {
        radMsgLog (PRI_CATASTROPHIC, "wvutilsSetVerbosity failed!");
        wvconfigExit ();
        return ERROR_ABORT;
    }

    // get the metric units flag:
    iValue = wvconfigGetBooleanValue(configItem_ALARMS_STATION_METRIC);
    if (iValue == ERROR)
    {
        alarmsWork.isMetric = 0;
    }
    else
    {
        alarmsWork.isMetric = iValue;
    }

    // get the do test flag:
    iValue = wvconfigGetBooleanValue(configItem_ALARMS_DO_TEST);
    if (iValue <= 0)
    {
        alarmsWork.doTest = FALSE;
    }
    else
    {
        alarmsWork.doTest = TRUE;
        alarmsWork.doTestNumber = wvconfigGetINTValue(configItem_ALARMS_DO_TEST_NUMBER);
    }

    for (i = 1; i <= ALARMS_MAX; i ++)
    {
        sprintf (conftype, "ALARMS_%1.1d_TYPE", i);
        temp = wvconfigGetStringValue(conftype);
        if (temp == NULL)
        {
            // No type defined - continue:
            continue;
        }
        wvstrncpy(type, temp, _MAX_PATH);

        sprintf (conftype, "ALARMS_%1.1d_MAX", i);
        boolMAX = wvconfigGetBooleanValue(conftype);
        if (boolMAX == ERROR)
        {
            continue;
        }

        sprintf (conftype, "ALARMS_%1.1d_THRESHOLD", i);
        thresh = wvconfigGetDOUBLEValue(conftype);

        sprintf (conftype, "ALARMS_%1.1d_ABATEMENT", i);
        abate = wvconfigGetINTValue(conftype);

        sprintf (conftype, "ALARMS_%1.1d_EXECUTE", i);
        temp = wvconfigGetStringValue(conftype);
        if (temp == NULL)
        {
            // No type defined - continue:
            continue;
        }
        wvstrncpy(exec, temp, _MAX_PATH);

        alarm = (WVIEW_ALARM *) malloc (sizeof (*alarm));
        if (alarm == NULL)
        {
            for (alarm = (WVIEW_ALARM *)radListRemoveFirst (&alarmsWork.alarmList);
                 alarm != NULL;
                 alarm = (WVIEW_ALARM *)radListRemoveFirst (&alarmsWork.alarmList))
            {
                free (alarm);
            }

            return ERROR;
        }
        memset (alarm, 0, sizeof (*alarm));


        // get the type
        if (!strcmp (type, "Barometer"))
        {
            alarm->type = Barometer;
        }
        else if (!strcmp (type, "InsideTemp"))
        {
            alarm->type = InsideTemp;
        }
        else if (!strcmp (type, "InsideHumidity"))
        {
            alarm->type = InsideHumidity;
        }
        else if (!strcmp (type, "OutsideTemp"))
        {
            alarm->type = OutsideTemp;
        }
        else if (!strcmp (type, "WindSpeed"))
        {
            alarm->type = WindSpeed;
        }
        else if (!strcmp (type, "TenMinuteAvgWindSpeed"))
        {
            alarm->type = TenMinuteAvgWindSpeed;
        }
        else if (!strcmp (type, "WindDirection"))
        {
            alarm->type = WindDirection;
        }
        else if (!strcmp (type, "OutsideHumidity"))
        {
            alarm->type = OutsideHumidity;
        }
        else if (!strcmp (type, "RainRate"))
        {
            alarm->type = RainRate;
        }
        else if (!strcmp (type, "StormRain"))
        {
            alarm->type = StormRain;
        }
        else if (!strcmp (type, "DayRain"))
        {
            alarm->type = DayRain;
        }
        else if (!strcmp (type, "MonthRain"))
        {
            alarm->type = MonthRain;
        }
        else if (!strcmp (type, "YearRain"))
        {
            alarm->type = YearRain;
        }
        else if (!strcmp (type, "TxBatteryStatus"))
        {
            alarm->type = TxBatteryStatus;
        }
        else if (!strcmp (type, "ConsoleBatteryVoltage"))
        {
            alarm->type = ConsoleBatteryVoltage;
        }
        else if (!strcmp (type, "DewPoint"))
        {
            alarm->type = DewPoint;
        }
        else if (!strcmp (type, "WindChill"))
        {
            alarm->type = WindChill;
        }
        else if (!strcmp (type, "HeatIndex"))
        {
            alarm->type = HeatIndex;
        }
        else if (!strcmp (type, "Radiation"))
        {
            alarm->type = Radiation;
        }
        else if (!strcmp (type, "UV"))
        {
            alarm->type = UV;
        }
        else if (!strcmp (type, "ET"))
        {
            alarm->type = ET;
        }
        else if (!strcmp (type, "ExtraTemp1"))
        {
            alarm->type = ExtraTemp1;
        }
        else if (!strcmp (type, "ExtraTemp2"))
        {
            alarm->type = ExtraTemp2;
        }
        else if (!strcmp (type, "ExtraTemp3"))
        {
            alarm->type = ExtraTemp3;
        }
        else if (!strcmp (type, "SoilTemp1"))
        {
            alarm->type = SoilTemp1;
        }
        else if (!strcmp (type, "SoilTemp2"))
        {
            alarm->type = SoilTemp2;
        }
        else if (!strcmp (type, "SoilTemp3"))
        {
            alarm->type = SoilTemp3;
        }
        else if (!strcmp (type, "SoilTemp4"))
        {
            alarm->type = SoilTemp4;
        }
        else if (!strcmp (type, "LeafTemp1"))
        {
            alarm->type = LeafTemp1;
        }
        else if (!strcmp (type, "LeafTemp2"))
        {
            alarm->type = LeafTemp2;
        }
        else if (!strcmp (type, "ExtraHumid1"))
        {
            alarm->type = ExtraHumid1;
        }
        else if (!strcmp (type, "ExtraHumid2"))
        {
            alarm->type = ExtraHumid2;
        }
        else if (!strcmp (type, "Wxt510Hail"))
        {
            alarm->type = Wxt510Hail;
        }
        else if (!strcmp (type, "Wxt510Hailrate"))
        {
            alarm->type = Wxt510Hailrate;
        }
        else if (!strcmp (type, "Wxt510HeatingTemp"))
        {
            alarm->type = Wxt510HeatingTemp;
        }
        else if (!strcmp (type, "Wxt510HeatingVoltage"))
        {
            alarm->type = Wxt510HeatingVoltage;
        }
        else if (!strcmp (type, "Wxt510SupplyVoltage"))
        {
            alarm->type = Wxt510SupplyVoltage;
        }
        else if (!strcmp (type, "Wxt510ReferenceVoltage"))
        {
            alarm->type = Wxt510ReferenceVoltage;
        }
        else
        {
            free (alarm);
            radMsgLog (PRI_MEDIUM, "invalid alarm type %s - skipping...",
                       type);
            continue;
        }

        //  do the max/min flag
        alarm->isMax = boolMAX;

        //  now the bounding value
        alarm->bound = (float)thresh;

        //  now the abatement seconds
        alarm->abateSecs = abate;

        //  finally, the alarm script
        wvstrncpy (alarm->scriptToRun, exec, WVIEW_ALARM_SCRIPT_LENGTH);

        radListAddToEnd (&alarmsWork.alarmList, (NODE_PTR)alarm);
    }

    wvconfigExit ();
    return (radListGetNumberOfNodes (&alarmsWork.alarmList));
}