Ejemplo n.º 1
0
/* edit by Ibrahim Amadou <*****@*****.**> */
void *sodas_delete(void *S, void *key) {
    sodas_t *sodas = (sodas_t *) S;
    sodas_elt_t elts, temp;
    int i = 0, p = 0, child;
  
    if(sodas->size == 0) {
      return NULL;
    }

    if(sodas->compare(sodas->elts[1].key, key) == 0) {      
       return sodas_pop(S);
    }else if(sodas->compare(sodas->elts[sodas->size].key, key) == 0) {
      elts.key  = sodas->elts[sodas->size].key;
      elts.data = sodas->elts[sodas->size].data;      
      sodas->size--;      
      return (void *) elts.data;
    }else{
         while(p != 1) {
	   
           for(i = 1; 2*i <= sodas->size; i++) {
                  child = 2*i;
                  if((child != sodas->size) && (sodas->compare(sodas->elts[child].key, key) == 0)) {
		    temp.key  = sodas->elts[i].key;
		    temp.data = sodas->elts[i].data;
		    sodas->elts[i].key = sodas->elts[child].key;
		    sodas->elts[i].data = sodas->elts[child].data; 
		    sodas->elts[child].key = temp.key;
		    sodas->elts[child].data = temp.data;
		    p = i;
		    break;
		  }
		  child++;
		  
		  if(sodas->compare(sodas->elts[child].key, key) == 0) {
		    temp.key  = sodas->elts[i].key;
		    temp.data = sodas->elts[i].data;
		    sodas->elts[i].key = sodas->elts[child].key;
		    sodas->elts[i].data = sodas->elts[child].data; 
		    sodas->elts[child].key = temp.key;
		    sodas->elts[child].data = temp.data;
		    p = i;
		    break;
		  }
           }
           if(p == 1) {
	     return sodas_pop(S);
           }else if(p == 0) {
             p = 1;
           }
	 }
	 return NULL;       
    }
}
void scheduler_clean(void) {
    event_t *event;
    
    if (scheduler == NULL) {
        return;
    }

    while ((event = (event_t *) sodas_pop(scheduler)) != NULL) {
        switch (event->priority) {
        case PRIORITY_RX_END:
            packet_dealloc(event->u.rx.packet);
            break;
        case PRIORITY_RX_BEGIN:
            packet_dealloc(event->u.rx.packet);
            break;
        case PRIORITY_TX_END:
            packet_dealloc(event->u.rx.packet);
            break;
        default:
            break;
        }

        mem_fs_dealloc(mem_event, event);
    }

    sodas_destroy(scheduler);

    worldsens_clean();
}
Ejemplo n.º 3
0
/* ************************************************** */
int event_callback(call_t *c, void *data) {
    struct _env_data *entitydata = get_entity_private_data(c);    
    struct _collec_event *event = (struct _collec_event *) data;
    call_t c0;
    array_t *app_layer = NULL;
    int type, value;

    /* Execute the event using an IOCTL */
    type = event->event_type;
    value = event->event_value;
    c0.node = event->node_id;
    app_layer = get_application_entities(&c0);
    c0.entity = app_layer->elts[0];
    IOCTL(&c0, type, &value, 0);
    DBG("Time %"PRId64", IOCTL for node %d, type %d, value %d\n", 
         event->time, event->node_id, type, value);

    /* Delete the event */
    free(event);

    /* Schedule the next event */
    event = (struct _collec_event *) sodas_pop(entitydata->events);
    if (event == NULL) {
        DBG("No more events in queue\n");
        return 0;
    }

    scheduler_add_callback(event->time, c, event_callback, event);
    return 0;
}
Ejemplo n.º 4
0
int destroy(call_t *c) {
    struct _env_data *entitydata = get_entity_private_data(c);
    struct _collec_event *event;

    /* Free the pending events */
    while ((event = (struct _collec_event *)
                sodas_pop(entitydata->events)) != NULL) {
        free(event);
    }

    /* Free the event list */
    sodas_destroy(entitydata->events);

    free(entitydata);
    return 0;
}
Ejemplo n.º 5
0
/* ************************************************** */
int bootstrap(call_t *c) {
    struct _env_data *entitydata = get_entity_private_data(c);
    struct _collec_event *event = NULL;

    /* Get the first event */
    event = (struct _collec_event *) sodas_pop(entitydata->events);

    if (event == NULL) {
        DBG("ERROR: no events in queue\n");
        return 0;
    }

    /* Schedule the first event */
    scheduler_add_callback(event->time, c, event_callback, event);

    return 0;
}
static void worldsens_clean(void) {
    if (ws_count) {
        wsens_srv_finalize();

	/* free node informations space */
	ws_node_features_t *p_temp = ws_nodes_feat;
	ws_node_features_t *p_free = NULL;
	while(p_temp != NULL) {
	    p_free = p_temp;
	    p_temp = p_temp->next;
	    free(p_free);
	}
	
	/* free rdvs */
	ws_rdv_t *rdv;
	while ((rdv = (ws_rdv_t *) sodas_pop(ws_rdvs)) != NULL) {
	    mem_fs_dealloc(mem_ws_rdv, rdv);
	}
    }
}
static ws_rdv_t *worldsens_rdv_next(void) {
    return (ws_rdv_t *) sodas_pop(ws_rdvs);
}
event_t *scheduler_next(void) {
    return (event_t *) sodas_pop(scheduler);
}