static void worldsens_add_rdv(ws_time clock, int priority) {
    ws_rdv_t *rdv;
    if ((rdv = (ws_rdv_t *) mem_fs_alloc(mem_ws_rdv)) == NULL) {
        return;
    }
    rdv->clock    = clock;
    rdv->priority = priority;
    sodas_insert(ws_rdvs, rdv, rdv);
}
/* ************************************************** */
void scheduler_add_event(event_t *event) {
    event->id = event_id++;
    sodas_insert(scheduler, event, event);
    dbg.c_events++;
}
Example #3
0
/* ************************************************** */
int init(call_t *c, void *params) {
    struct _env_data *entitydata = malloc(sizeof(struct _env_data));
    char *filepath = "collection_ctrl.data";
    int line;
    struct _collec_event *event;
    param_t *param;
    char str[128];
    char event_str[30];
    FILE *file;

    /* We use a sorted list for the events (sorted by time) */
    entitydata->events = sodas_create(event_compare);

    /* Get parameters from the configuration file */
    das_init_traverse(params);
    while ((param = (param_t *) das_traverse(params)) != NULL) {
        if (!strcmp(param->key, "file")) {
            filepath = param->value;            
        }
    }

    /* Open the data collection scheme file */
    if ((file = fopen(filepath, "r")) == NULL) {
        DBG("ERROR: cannot open file %s in init()\n", filepath);
        goto error;
    }

    /* Save the events in a data structure */
    /* Structure of the file is:
     * <time> <node id> <event type> <value>
     */
    fseek(file, 0L, SEEK_SET);
    line = 1;
    while (fgets(str, 128, file) != NULL) {
        event = malloc(sizeof(struct _collec_event));
        memset(event_str, 0, sizeof(event_str));

        if (event == NULL) {
            DBG("ERROR: malloc failed\n");
            goto error;
        }

        if (str[0] == '#' || str[0] == '\n') {
            /* Line is a comment or an empty line */
            line++;
            continue;
        }

        if (sscanf(str, "%"PRId64" %d %s %d\n", 
                   &event->time, &event->node_id,
                   event_str, &event->event_value) != 4) {
            DBG("ERROR: cannot read event in file %s, line %d\n", 
                    filepath, line);
            free(event);
            goto error;
        }

        if (!strncmp(event_str, "APP_TIME_DRV", sizeof(event_str))) {
            event->event_type = APP_TIME_DRV;
        } else if (!strncmp(event_str, "APP_EVENT_DRV", sizeof(event_str))) {
            event->event_type = APP_EVENT_DRV;
        } else if (!strncmp(event_str, "APP_QUERY_DRV", sizeof(event_str))) {
            event->event_type = APP_QUERY_DRV;
        } else if (!strncmp(event_str, "APP_PAYLOAD_SIZE", sizeof(event_str))) {
            event->event_type = APP_PAYLOAD_SIZE;
        } else if (!strncmp(event_str, "ENV_EVENT", sizeof(event_str))) {
            event->event_type = ENV_EVENT;
        } else if (!strncmp(event_str, "QUERY_MSG", sizeof(event_str))) {
            event->event_type = QUERY_MSG;
        } else if (!strncmp(event_str, "CHANGE_APP_DST", sizeof(event_str))) {
            event->event_type = CHANGE_APP_DST;
        } else {
            DBG("ERROR: event type %s unknown in file %s, line %d\n", 
                    event_str, filepath, line);
            free(event);
            goto error;
        }
            
        //DBG("EVENT: %"PRId64" %d %d %d\n", 
        //    event->time, event->node_id, 
        //    event->event_type, event->event_value);

        if (event->node_id >= get_node_count()) {
            DBG("ERROR: node id %d (line %d) does not exist, "
                "skipping this event \n", event->node_id, line);
            free(event);
        } else {
            /* Insert the event in the sorted data structure */
            sodas_insert(entitydata->events, &event->time, event);
        }

        line++;
    }

    /* Close the opened file */
    fclose(file);

    set_entity_private_data(c, entitydata);
    return 0;

error:
    free(entitydata);
    return -1;
}