Beispiel #1
0
static void pushLoopToClients(LOOP_PKT* loopData)
{
    WVIEW_ALARM_CLIENT  *client, *oldClient;
    LOOP_PKT            networkLoop;

    datafeedConvertLOOP_HTON(&networkLoop, loopData);

    // Push to each socket client:
    for (client = (WVIEW_ALARM_CLIENT *) radListGetFirst (&alarmsWork.clientList);
         client != NULL;
         client = (WVIEW_ALARM_CLIENT *) radListGetNext (&alarmsWork.clientList, 
                                                         (NODE_PTR)client))
    {
        // write the frame start so clients may sync to the beginning of each
        // data update
        if (radSocketWriteExact (client->client, 
                                 (void *)DF_LOOP_START_FRAME, 
                                 DF_START_FRAME_LENGTH)
            != DF_START_FRAME_LENGTH)
        {
            // write error, bail on this guy
            radMsgLog (PRI_HIGH, "LOOP: write error to client %s:%d - closing socket...",
                       radSocketGetHost (client->client),
                       radSocketGetPort (client->client));
            statusDecrementStat(ALARM_STATS_CLIENTS);
            radProcessIODeRegisterDescriptorByFd(radSocketGetDescriptor(client->client));
            radSocketDestroy (client->client);
            oldClient = client;
            client = (WVIEW_ALARM_CLIENT *) 
                        radListGetPrevious (&alarmsWork.clientList, (NODE_PTR)client);
            radListRemove (&alarmsWork.clientList, (NODE_PTR)oldClient);
            free (oldClient);
            continue;
        }

        // write out the loop data in network byte order:
        if (radSocketWriteExact(client->client, &networkLoop, sizeof(networkLoop))
            != sizeof(networkLoop))
        {
            // write error, bail on this guy
            radMsgLog (PRI_HIGH, "LOOP: write error to client %s:%d - closing socket...",
                       radSocketGetHost (client->client),
                       radSocketGetPort (client->client));
            statusDecrementStat(ALARM_STATS_CLIENTS);
            radProcessIODeRegisterDescriptorByFd(radSocketGetDescriptor(client->client));
            radSocketDestroy (client->client);
            oldClient = client;
            client = (WVIEW_ALARM_CLIENT *) 
                        radListGetPrevious (&alarmsWork.clientList, (NODE_PTR)client);
            radListRemove (&alarmsWork.clientList, (NODE_PTR)oldClient);
            free (oldClient);
            continue;
        }

        statusIncrementStat(ALARM_STATS_PKTS_SENT);
    }

    return;
}
Beispiel #2
0
static void RemoveClient(RADSOCK_ID clientSock)
{
    WVIEW_ALARM_CLIENT*     node;

    for (node = (WVIEW_ALARM_CLIENT*)radListGetFirst(&alarmsWork.clientList);
         node != NULL;
         node = (WVIEW_ALARM_CLIENT*)radListGetNext(&alarmsWork.clientList, (NODE_PTR)node))
    {
        if (node->client == clientSock)
        {
            // found him!
            statusDecrementStat(ALARM_STATS_CLIENTS);
            radListRemove(&alarmsWork.clientList, (NODE_PTR)node);
            radProcessIODeRegisterDescriptorByFd(radSocketGetDescriptor(node->client));
            radSocketDestroy(node->client);
            free(node);
            return;
        }
    }
}
Beispiel #3
0
void radTimerStop
(
    TIMER_ID        timer
)
{
    if (timer == NULL)
        return;

    radUtilsDisableSignal (SIGALRM);

    if (timer->pending == TRUE)
    {
        timer->pending = FALSE;
        radListRemove (&timerList->pendingList, (NODE_PTR)timer);
    }

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

    radUtilsEnableSignal (SIGALRM);
}
Beispiel #4
0
static void pushArchiveToClients(ARCHIVE_PKT* archive)
{
    WVIEW_ALARM_CLIENT  *client, *oldClient;
    ARCHIVE_PKT         networkArchive;

    datafeedConvertArchive_HTON(&networkArchive, archive);

    // Push to each socket client:
    for (client = (WVIEW_ALARM_CLIENT *) radListGetFirst (&alarmsWork.clientList);
         client != NULL;
         client = (WVIEW_ALARM_CLIENT *) radListGetNext (&alarmsWork.clientList, 
                                                         (NODE_PTR)client))
    {
        // Check for archive sync in progress:
        if (client->syncInProgress)
        {
            continue;
        }

        // Write start frame and archive packet on the socket:
        if (WriteArchiveToClient(client->client, &networkArchive) == ERROR)
        {
            // write error, bail on this guy
            radMsgLog (PRI_HIGH, "ARCHIVE: write error to client %s:%d - closing socket...",
                       radSocketGetHost (client->client),
                       radSocketGetPort (client->client));
            statusDecrementStat(ALARM_STATS_CLIENTS);
            radProcessIODeRegisterDescriptorByFd(radSocketGetDescriptor(client->client));
            radSocketDestroy (client->client);
            oldClient = client;
            client = (WVIEW_ALARM_CLIENT *) 
                        radListGetPrevious (&alarmsWork.clientList, (NODE_PTR)client);
            radListRemove (&alarmsWork.clientList, (NODE_PTR)oldClient);
            free (oldClient);
            continue;
        }
    }

    return;
}
Beispiel #5
0
void raddatabaseRowDescriptionDelete
(
    ROW_ID          row
)
{
    FIELD_ID    field;

    for (field = (FIELD_ID) radListGetFirst (&row->fields);
         field != NULL;
         field = (FIELD_ID) radListGetFirst (&row->fields))
    {
        if ((field->type & FIELD_STRING) || (field->type & FIELD_DATETIME))
        {
            free (field->cvalue);
        }

        radListRemove (&row->fields, (NODE_PTR)field);
        free (field);
    }

    free (row);
}
Beispiel #6
0
//  ... process expired timers
static void processExpiredTimers (void)
{
    register TIMER_ID   timer, prevTimer;
    SYS_CALLBACK_MSG    cbMsg;
    int                 retVal;

    for (timer = (TIMER_ID) radListGetFirst (&timerList->pendingList);
         timer != NULL;
         timer = (TIMER_ID) radListGetNext (&timerList->pendingList, (NODE_PTR)timer))
    {
        if (timer->deltaTime == 0)
        {
            // remove from pending list
            prevTimer = (TIMER_ID) radListGetPrevious (&timerList->pendingList, (NODE_PTR)timer);
            radListRemove (&timerList->pendingList, (NODE_PTR)timer);

            timer->pending = FALSE;

            // send expiry notification
            if (timer->routine != NULL)
            {
                cbMsg.length    = sizeof (cbMsg) - sizeof (cbMsg.length);
                cbMsg.msgType   = 0;
                cbMsg.callback  = timer->routine;
                cbMsg.parm      = timer->parm;
                retVal = write (timerList->notifyFD, &cbMsg, sizeof (cbMsg));
                if (retVal != sizeof (cbMsg))
                {
                    radMsgLog(PRI_HIGH, "processExpiredTimers: write to notify fd failed: %s",
                               strerror (errno));
                }
            }

            timer = prevTimer;
        }
    }

    return;
}
Beispiel #7
0
int raddatabaseRowDescriptionRemoveField
(
    ROW_ID          id,
    const char      *name
)
{
    FIELD_ID        field;

    field = raddatabaseFieldGet (id, name);
    if (field == NULL)
    {
        return ERROR;
    }

    radListRemove (&id->fields, (NODE_PTR)field);
    if (field->type & FIELD_STRING || field->type == FIELD_DATETIME)
    {
        free (field->cvalue);
    }

    free (field);

    return OK;
}