Commit 2ef32ad9 authored by Xenofon Foukas's avatar Xenofon Foukas

Added support for turning off periodical timer tasks

parent 3e2adfbc
......@@ -313,19 +313,6 @@ int enb_agent_start(mid_t mod_id, const Enb_properties_array_t* enb_properties){
return -1;
}
//#ifdef TEST_TIMER
long timer_id=0;
enb_agent_timer_args_t timer_args;
memset (&timer_args, 0, sizeof(enb_agent_timer_args_t));
timer_args.mod_id = mod_id;
//timer_args.cc_actions= ENB_AGENT_ACTION_APPLY;
//timer_args.cc_report_flags = PROTOCOL__PRP_CELL_STATS_TYPE__PRCST_NOISE_INTERFERENCE;
//timer_args.ue_actions = ENB_AGENT_ACTION_SEND;
//timer_args.ue_report_flags = PROTOCOL__PRP_UE_STATS_TYPE__PRUST_BSR | PROTOCOL__PRP_UE_STATS_TYPE__PRUST_DL_CQI;
enb_agent_create_timer(1, 0, ENB_AGENT_DEFAULT, mod_id, ENB_AGENT_TIMER_TYPE_PERIODIC, enb_agent_timeout,(void*)&timer_args, &timer_id);
//#endif
//new_thread(send_thread, &shared_ctxt);
//while (1) pause();
......
......@@ -377,6 +377,7 @@ err_code_t enb_agent_create_timer(uint32_t interval_sec,
agent_id_t agent_id,
instance_t instance,
uint32_t timer_type,
xid_t xid,
enb_agent_timer_callback_t cb,
void* timer_args,
long *timer_id){
......@@ -424,7 +425,8 @@ err_code_t enb_agent_create_timer(uint32_t interval_sec,
e->instance = instance;
e->state = ENB_AGENT_TIMER_STATE_ACTIVE;
e->timer_id = *timer_id;
// e->timer_args = timer_args;
e->xid = xid;
e->timer_args = timer_args;
e->cb = cb;
/*element should be a real pointer*/
RB_INSERT(enb_agent_map, &timer_instance.enb_agent_head, e);
......@@ -440,7 +442,8 @@ err_code_t enb_agent_destroy_timer(long timer_id){
struct enb_agent_timer_element_s *e = get_timer_entry(timer_id);
if (e != NULL ) {
RB_REMOVE(enb_agent_map, &timer_instance.enb_agent_head, &e);
RB_REMOVE(enb_agent_map, &timer_instance.enb_agent_head, e);
enb_agent_destroy_progran_message(e->timer_args->msg);
free(e);
}
......@@ -454,13 +457,35 @@ err_code_t enb_agent_destroy_timer(long timer_id){
return TIMER_REMOVED_FAILED ;
}
err_code_t enb_agent_destroy_timer_by_task_id(xid_t xid) {
struct enb_agent_timer_element_s *e = NULL;
long timer_id;
RB_FOREACH(e, enb_agent_map, &timer_instance.enb_agent_head) {
if (e->xid == xid) {
timer_id = e->timer_id;
RB_REMOVE(enb_agent_map, &timer_instance.enb_agent_head, e);
enb_agent_destroy_progran_message(e->timer_args->msg);
free(e);
if (timer_remove(timer_id) < 0 ) {
goto error;
}
}
}
return 0;
error:
LOG_E(ENB_AGENT, "timer can't be removed\n");
return TIMER_REMOVED_FAILED ;
}
err_code_t enb_agent_destroy_timers(void){
struct enb_agent_timer_element_s *e = NULL;
RB_FOREACH(e, enb_agent_map, &timer_instance.enb_agent_head) {
RB_REMOVE(enb_agent_map, &timer_instance.enb_agent_head, e);
timer_remove(e->timer_id);
timer_remove(e->timer_id);
enb_agent_destroy_progran_message(e->timer_args->msg);
free(e);
}
......@@ -468,15 +493,6 @@ err_code_t enb_agent_destroy_timers(void){
}
struct enb_agent_timer_element_s * get_timer_entry(long timer_id) {
struct enb_agent_timer_element_s search;
memset(&search, 0, sizeof(struct enb_agent_timer_element_s));
search.timer_id = timer_id;
return RB_FIND(enb_agent_map, &timer_instance.enb_agent_head, &search);
}
void enb_agent_sleep_until(struct timespec *ts, int delay) {
ts->tv_nsec += delay;
if(ts->tv_nsec >= 1000*1000*1000){
......@@ -493,15 +509,15 @@ void enb_agent_sleep_until(struct timespec *ts, int delay) {
}
*/
/*
err_code_t enb_agent_stop_timer(uint32_t timer_id){
err_code_t enb_agent_stop_timer(long timer_id){
struct enb_agent_timer_element_s *e=NULL;
RB_FOREACH(e, enb_agent_map, &enb_agent_head) {
if (e->timer_id == timer_id)
break;
}
struct enb_agent_timer_element_s search;
memset(&search, 0, sizeof(struct enb_agent_timer_element_s));
search.timer_id = timer_id;
e = RB_FIND(enb_agent_map, &timer_instance.enb_agent_head, &search);
if (e != NULL ) {
e->state = ENB_AGENT_TIMER_STATE_STOPPED;
......@@ -510,9 +526,18 @@ err_code_t enb_agent_stop_timer(uint32_t timer_id){
timer_remove(timer_id);
return 0;
}
struct enb_agent_timer_element_s * get_timer_entry(long timer_id) {
struct enb_agent_timer_element_s search;
memset(&search, 0, sizeof(struct enb_agent_timer_element_s));
search.timer_id = timer_id;
return RB_FIND(enb_agent_map, &timer_instance.enb_agent_head, &search);
}
/*
// this will change the timer_id
err_code_t enb_agent_restart_timer(uint32_t *timer_id){
......
......@@ -70,6 +70,8 @@ typedef int (*enb_agent_message_destruction_callback)(
int enb_agent_serialize_message(Protocol__ProgranMessage *msg, void **buf, int *size);
int enb_agent_deserialize_message(void *data, int size, Protocol__ProgranMessage **msg);
err_code_t enb_agent_destroy_progran_message(Protocol__ProgranMessage *msg);
int prp_create_header(xid_t xid, Protocol__PrpType type, Protocol__PrpHeader **header);
int enb_agent_hello(mid_t mod_id, const void *params, Protocol__ProgranMessage **msg);
......@@ -189,9 +191,11 @@ typedef struct enb_agent_timer_element_s{
uint32_t interval_usec;
long timer_id; /* Timer id returned by the timer API*/
xid_t xid; /*The id of the task as received by the controller
message*/
enb_agent_timer_callback_t cb;
// void* timer_args;
enb_agent_timer_args_t *timer_args;
} enb_agent_timer_element_t;
......@@ -206,12 +210,14 @@ err_code_t enb_agent_create_timer(uint32_t interval_sec,
agent_id_t agent_id,
instance_t instance,
uint32_t timer_type,
xid_t xid,
enb_agent_timer_callback_t cb,
void* timer_args,
long *timer_id);
err_code_t enb_agent_destroy_timers(void);
err_code_t enb_agent_destroy_timer(long timer_id);
err_code_t enb_agent_destroy_timer_by_task_id(xid_t xid);
err_code_t enb_agent_stop_timer(long timer_id);
......@@ -219,8 +225,6 @@ err_code_t enb_agent_restart_timer(long *timer_id);
struct enb_agent_timer_element_s * get_timer_entry(long timer_id);
Protocol__ProgranMessage * enb_agent_process_timeout(long timer_id, void* timer_args);
int enb_agent_compare_timer(struct enb_agent_timer_element_s *a, struct enb_agent_timer_element_s *b);
......
......@@ -54,9 +54,8 @@ enb_agent_message_destruction_callback message_destruction_callback[] = {
enb_agent_destroy_hello,
enb_agent_destroy_echo_request,
enb_agent_destroy_echo_reply,
0, /*No stats request message is created in the agent. No need for a callback*/
enb_agent_mac_destroy_stats_request,
enb_agent_mac_destroy_stats_reply,
};
static const char *enb_agent_direction2String[] = {
......@@ -170,3 +169,7 @@ Protocol__ProgranMessage* enb_agent_process_timeout(long timer_id, void* timer_a
LOG_E(ENB_AGENT, "can't get the timer element\n");
return TIMER_ELEMENT_NOT_FOUND;
}
err_code_t enb_agent_destroy_progran_message(Protocol__ProgranMessage *msg) {
return ((*message_destruction_callback[msg->msg_case-1])(msg));
}
......@@ -71,18 +71,12 @@ int enb_agent_mac_handle_stats(mid_t mod_id, const void *params, Protocol__Progr
switch(stats_req->body_case) {
case PROTOCOL__PRP_STATS_REQUEST__BODY_COMPLETE_STATS_REQUEST: ;
Protocol__PrpCompleteStatsRequest *comp_req = stats_req->complete_stats_request;
/* if (comp_req->report_frequency == PROTOCOL__PRP_STATS_REPORT_FREQ__PRSRF_PERIODICAL) { */
/* //TODO: Must create a periodic report. Implement once the */
/* // timer functionality is supported */
/* *msg = NULL; */
/* return 0; */
/* } else */
if (comp_req->report_frequency == PROTOCOL__PRP_STATS_REPORT_FREQ__PRSRF_CONTINUOUS) {
//TODO: Must create an event based report mechanism
*msg = NULL;
return 0;
} else if (comp_req->report_frequency == PROTOCOL__PRP_STATS_REPORT_FREQ__PRSRF_OFF) {
//TODO: Must implement to deactivate the event based reporting
enb_agent_destroy_timer_by_task_id(xid);
*msg = NULL;
return 0;
} else { //One-off or periodical reporting
......@@ -141,7 +135,7 @@ int enb_agent_mac_handle_stats(mid_t mod_id, const void *params, Protocol__Progr
sec_interval = usec_interval/(1000*1000);
usec_interval = usec_interval%(1000*1000);
}
enb_agent_create_timer(sec_interval, usec_interval, ENB_AGENT_DEFAULT, enb_id, ENB_AGENT_TIMER_TYPE_PERIODIC, enb_agent_handle_timed_task,(void*) timer_args, &timer_id);
enb_agent_create_timer(sec_interval, usec_interval, ENB_AGENT_DEFAULT, enb_id, ENB_AGENT_TIMER_TYPE_PERIODIC, xid, enb_agent_handle_timed_task,(void*) timer_args, &timer_id);
}
}
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment