int main() { // expected: no warnings or errors in this code add_values(4); add_values(4, 1); add_values(4, 1, 2); }
int up_arrow(int **tbl, int len) { int i; int j; int cpt; cpt = 0; while (cpt < len) { i = cpt; while (i < ((len - 1) * len) + cpt) { j = i + len; while (j <= cpt + ((len - 1) * len)) { if (add_values(tbl, i, j)) break ; j += len; } i += len; } cpt++; } align_up(tbl, len); return (0); }
int down_arrow(int **tbl, int len) { int i; int j; int cpt; cpt = 0; while (cpt < len) { i = (len * (len - 1)) + cpt; while (i > cpt) { j = i - len; while (j >= cpt) { if (add_values(tbl, i, j)) break ; j -= len; } i -= len; } cpt++; } align_down(tbl, len); return (0); }
static value_object eval_aux(expr* node) { if (node == NULL) return make_null(); if (node->type == EXP_ASSIGN) return assign_value(node->left, node->right); value_object left = eval_aux(node->left); value_object right = eval_aux(node->right); switch (node->type) { case EXP_PLUS: return add_values(left, right); case EXP_MINUS: return sub_values(left, right); case EXP_TIMES: return mul_values(left, right); case EXP_DIV: return div_values(left, right); case EXP_INT: return make_int(atoi(node->text)); case EXP_FLOAT: return make_float(to_float64(node->text)); case EXP_NATIVE: return make_native(atof(node->text)); case EXP_CALL: return eval_function(node->text, node->args); case EXP_ID: return get_variable_value(node->text); case EXP_UNMINUS: return negate_value(left); } }
void add_macro(char *pString, macro_list **ppList) { macro_list *pEntry = NULL; int iLength = 0; if(pString == NULL || *pString == '\0' || ppList == NULL) { return; } /* Allocate a new list entry for the macro. */ pEntry = (macro_list *)malloc(sizeof(macro_list)); memset(pEntry, 0, sizeof(macro_list)); /* Very first part of the string is the macro name. * How long is it? */ iLength = macro_length(pString); pEntry->m_pMacro = (char *)malloc(iLength + 1); memset(pEntry->m_pMacro, 0, iLength + 1); strncpy(pEntry->m_pMacro, pString, iLength); /* Skip to the values. * These are always on the right side of an '=' */ pString = strchr(pString, '='); if(pString) { pString++; } add_values(pString, &(pEntry->m_pValue)); /* Add the macro to the end of the macro list. */ while(*ppList) { ppList = &((*ppList)->m_pNext); } *ppList = pEntry; }
void Graph::add_values(int row, int n, double* x, double* y) { for (int i = 0; i < n; i++) add_values(row, x[i], y[i]); }
void Graph::add_values(int row, int n, double2* xy) { for (int i = 0; i < n; i++) add_values(row, xy[i][0], xy[i][1]); }
//___________________________________________________________________________________________ void KVIntegerList::Add(Int_t val, Int_t freq) { //Ajout de "freq" fois la valeur val add_values(val, freq); }
static int8_t module(void *state, Message *msg) { app_state_t *s = (app_state_t *) state; MsgParam *p = (MsgParam*)(msg->data); /** * Switch to the correct message handler */ switch (msg->type){ case MSG_INIT: { DEBUG("RATS: node %d initializing\n", ker_id()); s->pid = msg->did; s->ts_list = NULL; s->ts_packet.type = NORMAL_PACKET; //Notify neighbors that RATS is starting (in case node rebooted while it was //synchronizing with another node post_net(s->pid, s->pid, MSG_INVALIDATE_ENTRY, 0, NULL, 0, BCAST_ADDRESS); return SOS_OK; } case MSG_RATS_CLIENT_START: { MsgParam *p = (MsgParam *)msg->data; DEBUG("RATS: Received MSG_RATS_CLIENT_START for node %d\n", p->word); uint8_t request_status = add_request(s, p->word, p->byte); //If a new request was created, then send packet to parent if(request_status != NO_REQUEST_CREATED) { DEBUG("RATS: Transmitting request to node %d\n", p->word); LED_DBG(LED_RED_TOGGLE); //If the current node is the parent of the target node, then the target node will //reply by informing the parent, who will add the target to its list of children. post_net(s->pid, s->pid, MSG_RATS_SERVER_START, 0, NULL, 0, p->word); } else { //Request already exists DEBUG("RATS: Request already exists\n"); } //If this was the first request that was created, we need to start the panic timer if(request_status == CREATED_FIRST_REQUEST) { DEBUG("RATS: PANIC_TIMER started\n"); #ifdef USE_PANIC_PACKETS sys_timer_start(PANIC_TIMER, MIN_SAMPLING_PERIOD*1024, TIMER_REPEAT); #endif //USE_PANIC_PACKETS } return SOS_OK; } case MSG_RATS_SERVER_START: { timesync_t * temp_ts_ptr = get_timesync_ptr(s, msg->saddr); DEBUG("RATS: Received request from node %d\n", msg->saddr); if(temp_ts_ptr == NULL) { DEBUG("RATS: Starting timesync with node %d\n", msg->saddr); LED_DBG(LED_RED_TOGGLE); //If request is coming from node, with whom the node is not synchronizing, then //synchronization is starting sys_timer_stop(TRANSMIT_TIMER); sys_timer_stop(VALIDATION_TIMER); s->ts_packet.transmission_period = INITIAL_TRANSMISSION_PERIOD; s->ts_packet.min_period_node_id = msg->saddr; s->transmit_timer_counter = 1; //s->ts_packet.transmission_period/INITIAL_TRANSMISSION_PERIOD; s->validation_timer_counter = 5; //s->transmit_timer_counter + 4; s->validation_timer_retransmissions = TOTAL_VALIDATION_RETRANSMISSIONS; sys_timer_start(TRANSMIT_TIMER, MIN_SAMPLING_PERIOD*1024, TIMER_REPEAT); sys_timer_start(VALIDATION_TIMER, MIN_SAMPLING_PERIOD*1024, TIMER_REPEAT); } return SOS_OK; } case MSG_RATS_GET_TIME: { //If the module passed a NULL pointer or if the data size is wrong, then discard if( (msg->data == NULL) #ifndef PC_PLATFORM || (msg->len != sizeof(rats_t) ) #endif //PC_PLATFORM ) { DEBUG("RATS: Invalid data received in MSG_RATS_GET_TIME\n"); break; } rats_t * rats_ptr = (rats_t *)sys_msg_take_data(msg); DEBUG("RATS: Received MSG_RATS_GET_TIME (mod_id=%d node=%d)\n", rats_ptr->mod_id, msg->saddr); if(rats_ptr->source_node_id == ker_id()) { timesync_t * temp_ts_ptr = get_timesync_ptr(s, rats_ptr->target_node_id); if(temp_ts_ptr == NULL) { DEBUG("RATS: Target node %d is not time synced\n", rats_ptr->target_node_id); sys_free(rats_ptr); break; } else { DEBUG("RATS: Calculating time for target node %d locally\n", rats_ptr->target_node_id); if(temp_ts_ptr->packet_count < BUFFER_SIZE) // learning state { rats_ptr->time_at_target_node = 0; rats_ptr->error = 0; } else { rats_ptr->time_at_target_node = convert_from_mine_to_parent_time(rats_ptr->time_at_source_node, rats_ptr->target_node_id); rats_ptr->error = getError(&temp_ts_ptr->timestamps[0], &temp_ts_ptr->my_time[0], BUFFER_SIZE, temp_ts_ptr->window_size, BUFFER_SIZE - temp_ts_ptr->window_size, &temp_ts_ptr->a, &temp_ts_ptr->b, temp_ts_ptr->sampling_period, FALSE); } } } else if (rats_ptr->target_node_id == ker_id()) { timesync_t * temp_ts_ptr = get_timesync_ptr(s, rats_ptr->source_node_id); if(temp_ts_ptr == NULL) { DEBUG("RATS: Source node %d is not time synced\n", rats_ptr->source_node_id); sys_free(rats_ptr); break; } else { DEBUG("RATS: Calculating time for source node %d locally\n", rats_ptr->source_node_id); if(temp_ts_ptr->packet_count < BUFFER_SIZE) // learning state { rats_ptr->time_at_target_node = 0; rats_ptr->error = 0; } else { rats_ptr->time_at_target_node = convert_from_parent_to_my_time(rats_ptr->time_at_source_node, rats_ptr->source_node_id); rats_ptr->error = getError(&temp_ts_ptr->timestamps[0], &temp_ts_ptr->my_time[0], BUFFER_SIZE, temp_ts_ptr->window_size, BUFFER_SIZE - temp_ts_ptr->window_size, &temp_ts_ptr->a, &temp_ts_ptr->b, temp_ts_ptr->sampling_period, TRUE); } } } else { DEBUG("RATS: Invalid request (source = %d, target - %d)\n", rats_ptr->source_node_id, rats_ptr->target_node_id); sys_free(rats_ptr); break; } DEBUG("RATS: Sending reply to module %d\n", rats_ptr->mod_id); post_long(rats_ptr->mod_id, s->pid, rats_ptr->msg_type, sizeof(rats_t), rats_ptr, SOS_MSG_RELEASE); break; } case MSG_RATS_CLIENT_STOP: { MsgParam *p = (MsgParam *)msg->data; uint16_t node_id = p->word; //First we need to remove node from list of parents /* Select node at head of list */ timesync_t * ts_list_ptr = s->ts_list; timesync_t * ts_delete_list_ptr; timesync_t * ts_previous_list_ptr = s->ts_list; /* Loop until we've reached the end of the list */ while( ts_list_ptr != NULL ) { if(ts_list_ptr->node_id == node_id) { if(--ts_list_ptr->ref_counter > 0) return SOS_OK; DEBUG("RATS: Removing node %d from list of parents. Sending MSG_RATS_SERVER_STOP.\n", node_id); post_net(s->pid, s->pid, MSG_RATS_SERVER_STOP, 0, NULL, 0, node_id); /* Found the item to be deleted, re-link the list around it */ if( ts_list_ptr == s->ts_list ) /* We're deleting the head */ s->ts_list = ts_list_ptr->next; else ts_previous_list_ptr->next = ts_list_ptr->next; ts_delete_list_ptr = ts_list_ptr; ts_list_ptr = ts_list_ptr->next; /* Free the node */ sys_free( ts_delete_list_ptr ); //If the parent list is empty, then we're stopping the panic timer if(s->ts_list == NULL) { DEBUG("RATS: Parent list is empty. Stopping panic timer\n"); #ifdef USE_PANIC_PACKETS sys_timer_stop(PANIC_TIMER); #endif //USE_PANIC_PACKETS } return SOS_OK; } ts_previous_list_ptr = ts_list_ptr; ts_list_ptr = ts_list_ptr->next; } DEBUG("RATS: Requested parent %d was not found\n", node_id); break; } case MSG_RATS_SERVER_STOP: { DEBUG("RATS: Received MSG_RATS_SERVER_STOP from %d\n", msg->saddr); //If node has minimum period, then go to validation protocol if(msg->saddr == s->ts_packet.min_period_node_id) { DEBUG("RATS: Going to validation protocol\n"); s->validation_timer_counter = 1; s->validation_timer_retransmissions = BROADCAST_VALIDATION_RETRANSMISSIONS; s->validation_node_id = ker_id(); } break; } case MSG_TIMER_TIMEOUT: { switch(p->byte) { case TRANSMIT_TIMER: { if( (--(s->transmit_timer_counter)) == 0) { DEBUG("RATS: Broadcasting MSG_TIMESTAMP packet\n"); LED_DBG(LED_GREEN_TOGGLE); post_net(s->pid, s->pid, MSG_TIMESTAMP, sizeof(ts_packet_t), &s->ts_packet, 0, BCAST_ADDRESS); #ifdef UART_DEBUG post_uart(s->pid, s->pid, UART_TIMESTAMP, sizeof(ts_packet_t), &s->ts_packet, 0, BCAST_ADDRESS); #endif //UART_DEBUG s->transmit_timer_counter = (uint16_t)(s->ts_packet.transmission_period / MIN_SAMPLING_PERIOD); } break; } case VALIDATION_TIMER: { if( (--(s->validation_timer_counter)) == 0) { s->validation_timer_counter = 1; //Send up to MSG_PERIOD_REQUEST packets (UNICAST_VALIDATION_RETRANSMISSIONS times) to node with minimum period. //If the node doesn't respond until then, then broadcast BROADCAST_VALIDATION_RETRANSMISSIONS times //After the transmitting BROADCAST_VALIDATION_RETRANSMISSIONS packets, use the minimum period that //was sent during that interval if( s->validation_timer_retransmissions > BROADCAST_VALIDATION_RETRANSMISSIONS ) { --s->validation_timer_retransmissions; DEBUG("RATS: Transmitting MSG_PERIOD_REQUEST (retries left = %d) to node %d\n", s->validation_timer_retransmissions, s->ts_packet.min_period_node_id); post_net(s->pid, s->pid, MSG_PERIOD_REQUEST, 0, NULL, 0, s->ts_packet.min_period_node_id); #ifdef UART_DEBUG post_uart(s->pid, s->pid, UART_PERIOD_REQUEST, 0, NULL, 0, s->ts_packet.min_period_node_id); #endif //UART_DEBUG } else if( s->validation_timer_retransmissions > 0) { --s->validation_timer_retransmissions; DEBUG("RATS: Broadcasting MSG_PERIOD_REQUEST (retries left = %d)\n", s->validation_timer_retransmissions); //Invalidate node with minimum period s->validation_node_id = ker_id(); post_net(s->pid, s->pid, MSG_PERIOD_REQUEST, 0, NULL, 0, BCAST_ADDRESS); #ifdef UART_DEBUG post_uart(s->pid, s->pid, UART_PERIOD_REQUEST, 0, NULL, 0, BCAST_ADDRESS); #endif //UART_DEBUG } else //s->validation_timer_retransmissions == 0 { sys_timer_stop(TRANSMIT_TIMER); sys_timer_stop(VALIDATION_TIMER); //Restart normal procedure only if there was a reply if(ker_id() != s->validation_node_id) { DEBUG("RATS: Setting node %d as the one with min period (%d)\n", s->validation_node_id, s->validation_period); s->ts_packet.min_period_node_id = s->validation_node_id; s->ts_packet.transmission_period = s->validation_period; s->transmit_timer_counter = s->ts_packet.transmission_period/INITIAL_TRANSMISSION_PERIOD; s->validation_timer_counter = s->transmit_timer_counter + 4; s->validation_timer_retransmissions = TOTAL_VALIDATION_RETRANSMISSIONS; sys_timer_start(TRANSMIT_TIMER, MIN_SAMPLING_PERIOD*1024, TIMER_REPEAT); sys_timer_start(VALIDATION_TIMER, MIN_SAMPLING_PERIOD*1024, TIMER_REPEAT); } else { DEBUG("RATS: Validation timer expired, without receiving any packets\n"); sys_timer_stop(TRANSMIT_TIMER); sys_timer_stop(VALIDATION_TIMER); } } } break; } case PANIC_TIMER: { //There is a fixed number of retransmissions. If the corresponding counter //reaches zero, then the child is removed from the list /* Select node at head of list */ timesync_t * ts_list_ptr = s->ts_list; timesync_t * ts_delete_list_ptr; timesync_t * ts_previous_list_ptr = s->ts_list; /* Loop until we've reached the end of the list */ while( ts_list_ptr != NULL ) { if(--ts_list_ptr->panic_timer_counter == 0) { if(ts_list_ptr->panic_timer_retransmissions > 0) { //Transmit the packet --ts_list_ptr->panic_timer_retransmissions; DEBUG("RATS: Sending panic packet to node %d (retries=%d)\n", ts_list_ptr->node_id, ts_list_ptr->panic_timer_retransmissions); post_net(s->pid, s->pid, MSG_PANIC, 0, NULL, 0, ts_list_ptr->node_id); //The retransmission period should be INITIAL_TRANSMISSION_PERIOD ts_list_ptr->panic_timer_counter = 1; } else { DEBUG("RATS: Removing node %d from list of parents\n", ts_list_ptr->node_id); /* Found the item to be deleted, re-link the list around it */ if( ts_list_ptr == s->ts_list ) /* We're deleting the head */ s->ts_list = ts_list_ptr->next; else ts_previous_list_ptr->next = ts_list_ptr->next; ts_delete_list_ptr = ts_list_ptr; ts_list_ptr = ts_list_ptr->next; /* Free the node */ sys_free( ts_delete_list_ptr ); continue; } } ts_previous_list_ptr = ts_list_ptr; ts_list_ptr = ts_list_ptr->next; } //If the parent list is empty, then we're stopping the panic timer if(s->ts_list == NULL) { DEBUG("RATS: Parent list is empty. Stopping panic timer\n"); #ifdef USE_PANIC_PACKETS sys_timer_stop(PANIC_TIMER); #endif //USE_PANIC_PACKETS } break; } default: break; } return SOS_OK; } case MSG_PERIOD_CHANGE: { uint16_t temp_transmission_period; DEBUG("RATS: Received packet for period change from %d\n", msg->saddr); LED_DBG(LED_YELLOW_TOGGLE); if((msg->data == NULL) || (msg->len != sizeof(uint16_t)) ) { DEBUG("RATS: Invalid parameters in MSG_PERIOD_CHANGE\n"); break; } temp_transmission_period = (* (uint16_t*)(msg->data)); //Change period if: //a)received period is smaller than period in use //b)node that sent period is the one that has the current smallest period //c)I am currently using myself as the node with the smallest period (used in the beginning and in transitive modes) if((temp_transmission_period < s->ts_packet.transmission_period) || (s->ts_packet.min_period_node_id == msg->saddr) || (s->ts_packet.min_period_node_id == ker_id()) ) { DEBUG("RATS: Changing period (new_period=%d new_node=%d). Sending to UART\n", temp_transmission_period, msg->saddr); sys_timer_stop(TRANSMIT_TIMER); sys_timer_stop(VALIDATION_TIMER); #ifdef UART_DEBUG period_packet_t * period_packet_ptr = sys_malloc(sizeof(period_packet_t)); period_packet_ptr->saddr = msg->saddr; period_packet_ptr->old_period = s->ts_packet.transmission_period; period_packet_ptr->new_period = temp_transmission_period; post_uart(s->pid, s->pid, UART_PERIOD_CHANGE, sizeof(period_packet_t), period_packet_ptr, SOS_MSG_RELEASE, UART_ADDRESS); #endif //UART_DEBUG s->ts_packet.transmission_period = temp_transmission_period; s->ts_packet.min_period_node_id = msg->saddr; s->transmit_timer_counter = (uint16_t)(s->ts_packet.transmission_period / MIN_SAMPLING_PERIOD); s->validation_timer_counter = s->transmit_timer_counter + 4; s->validation_timer_retransmissions = TOTAL_VALIDATION_RETRANSMISSIONS; sys_timer_start(TRANSMIT_TIMER, INITIAL_TRANSMISSION_PERIOD*1024, TIMER_REPEAT); sys_timer_start(VALIDATION_TIMER, INITIAL_TRANSMISSION_PERIOD*1024, TIMER_REPEAT); } return SOS_OK; } case MSG_TIMESTAMP: { ts_packet_t *ts_packet_ptr = (ts_packet_t *)msg->data; DEBUG("RATS: MSG_TIMESTAMP with type = %d\n", ts_packet_ptr->type); if(ts_packet_ptr->type == NORMAL_PACKET) { DEBUG("RATS: Receiving timestamp data from node %d\n", msg->saddr); if( add_values(s, msg) == TRUE) { LED_DBG(LED_GREEN_TOGGLE); DEBUG("RATS: Accessed internal structure\n"); } else { DEBUG("RATS: Discarding MSG_TIMESTAMP from node %d\n", msg->saddr); } } else // TEST_PACKET { if(ker_id() == ROOT_NODE) { DEBUG("RATS: Receiving test data from node %d. Sending to UART\n", msg->saddr); #ifdef UART_DEBUG ext_packet_t * ext_packet_ptr = (ext_packet_t *)msg->data; debug_packet_t * debug_packet_ptr = (debug_packet_t *)sys_malloc(sizeof(debug_packet_t)); debug_packet_ptr->time[0] = ticks_to_msec_float(ext_packet_ptr->time[0]); debug_packet_ptr->time[1] = ticks_to_msec_float(ext_packet_ptr->time[1]); debug_packet_ptr->node_id = ker_id(); debug_packet_ptr->int_parent_time = ext_packet_ptr->time[1]; post_uart(s->pid, s->pid, UART_FORWARD_EXT, sizeof(debug_packet_t), debug_packet_ptr, SOS_MSG_RELEASE, UART_ADDRESS); #endif //UART_DEBUG } else { DEBUG("RATS: Receiving test data from node %d. Sending to parent\n", msg->saddr); #ifdef UART_DEBUG ext_packet_t * ext_packet_ptr = (ext_packet_t *)msg->data; uint32_t parent_time = convert_from_mine_to_parent_time(ext_packet_ptr->time[1], ROOT_NODE); //Break if the parent is not found in the timestamping list if(parent_time == 0) { break; } debug_packet_t * debug_packet_ptr = (debug_packet_t *)sys_malloc(sizeof(debug_packet_t)); debug_packet_ptr->time[0] = ticks_to_msec_float(ext_packet_ptr->time[0]); debug_packet_ptr->time[1] = ticks_to_msec_float(parent_time); debug_packet_ptr->int_parent_time = parent_time; debug_packet_ptr->node_id = ker_id(); post_uart(s->pid, s->pid, UART_FORWARD_EXT, sizeof(debug_packet_t), debug_packet_ptr, SOS_MSG_RELEASE, UART_ADDRESS); #endif //UART_DEBUG } } break; } case MSG_PERIOD_REQUEST: { DEBUG("RATS: Received MSG_PERIOD_REQUEST packet from node %d\n", msg->saddr); timesync_t * temp_ts_ptr = get_timesync_ptr(s, msg->saddr); if(temp_ts_ptr == NULL) { DEBUG("RATS: Discarding MSG_PERIOD_REQUEST\n"); break; } uint16_t *sampling_period = (uint16_t *)sys_malloc(sizeof(uint16_t)); if(sampling_period != NULL) { *sampling_period = temp_ts_ptr->sampling_period; DEBUG("RATS: Sending MSG_PERIOD_REPLY packet (period=%d) to node %d\n", *sampling_period, msg->saddr); post_net(s->pid, s->pid, MSG_PERIOD_REPLY, sizeof(uint16_t), sampling_period, SOS_MSG_RELEASE, msg->saddr); } break; } case MSG_PERIOD_REPLY: { uint16_t transmission_period; DEBUG("RATS: Received MSG_PERIOD_REPLY packet from node %d\n", msg->saddr); memcpy(&transmission_period, &msg->data[0], sizeof(transmission_period)); s->validation_timer_counter = s->transmit_timer_counter + 4; s->validation_timer_retransmissions = TOTAL_VALIDATION_RETRANSMISSIONS; if((transmission_period < s->validation_period) || (s->validation_node_id == ker_id() ) ) { DEBUG("RATS: Changing VALIDATION period (new_period=%d new_node=%d)\n", transmission_period, msg->saddr); s->validation_period = transmission_period; s->validation_node_id = msg->saddr; } break; } case MSG_PANIC: { //Transmit MSG_TIMESTAMP, restart timer, recalculate value for transmit_timer_counter sys_timer_stop(TRANSMIT_TIMER); sys_timer_stop(VALIDATION_TIMER); #ifdef UART_DEBUG uint16_t *data = (uint16_t *)sys_malloc(sizeof(uint16_t)); *data = msg->saddr; post_uart(s->pid, s->pid, UART_PANIC, sizeof(uint16_t), data, SOS_MSG_RELEASE, UART_ADDRESS); #endif //UART_DEBUG post_net(s->pid, s->pid, MSG_TIMESTAMP, sizeof(ts_packet_t), &s->ts_packet, 0, BCAST_ADDRESS); s->transmit_timer_counter = (uint16_t)(s->ts_packet.transmission_period / MIN_SAMPLING_PERIOD); s->validation_timer_counter = s->transmit_timer_counter + 4; s->validation_timer_retransmissions = TOTAL_VALIDATION_RETRANSMISSIONS; sys_timer_start(TRANSMIT_TIMER, INITIAL_TRANSMISSION_PERIOD*1024, TIMER_REPEAT); sys_timer_start(VALIDATION_TIMER, INITIAL_TRANSMISSION_PERIOD*1024, TIMER_REPEAT); break; } case MSG_INVALIDATE_ENTRY: { DEBUG("RATS: Received invalidation message from node %d\n", msg->saddr); timesync_t * temp_ts_ptr = get_timesync_ptr(s, msg->saddr); if(temp_ts_ptr == NULL) { DEBUG("RATS: Discarding MSG_INVALIDATE_ENTRY\n"); break; } DEBUG("RATS: Invalidation entry for node %d\n", msg->saddr); temp_ts_ptr->packet_count = 0; temp_ts_ptr->a = 0; temp_ts_ptr->b = 0; temp_ts_ptr->sampling_period = INITIAL_TRANSMISSION_PERIOD; temp_ts_ptr->window_size = (uint8_t)BUFFER_SIZE; temp_ts_ptr->panic_timer_counter = 5; //(s->ts_list->sampling_period / INITIAL_TRANSMISSION_PERIOD) + 4; temp_ts_ptr->panic_timer_retransmissions = PANIC_TIMER_RETRANSMISSIONS; memset(temp_ts_ptr->timestamps, 0, BUFFER_SIZE*sizeof(uint32_t)); memset(temp_ts_ptr->my_time, 0, BUFFER_SIZE*sizeof(uint32_t)); //Notify node to start procedure from beginning post_net(s->pid, s->pid, MSG_RATS_SERVER_START, 0, NULL, 0, msg->saddr); break; } case MSG_FINAL: { sys_timer_stop(TRANSMIT_TIMER); sys_timer_stop(VALIDATION_TIMER); #ifdef USE_PANIC_PACKETS sys_timer_stop(PANIC_TIMER); #endif //USE_PANIC_PACKETS return SOS_OK; } default: return -EINVAL; } /** * Return SOS_OK for those handlers that have successfully been handled. */ return SOS_OK; }
static int monitor_subsys_log_modify( Operation *op, SlapReply *rs, Entry *e ) { monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private; int rc = LDAP_OTHER; int newlevel = ldap_syslog; Attribute *save_attrs; Modifications *modlist = op->orm_modlist; Modifications *ml; ldap_pvt_thread_mutex_lock( &monitor_log_mutex ); save_attrs = e->e_attrs; e->e_attrs = attrs_dup( e->e_attrs ); for ( ml = modlist; ml != NULL; ml = ml->sml_next ) { Modification *mod = &ml->sml_mod; /* * accept all operational attributes; * this includes modifersName and modifyTimestamp * if lastmod is "on" */ if ( is_at_operational( mod->sm_desc->ad_type ) ) { ( void ) attr_delete( &e->e_attrs, mod->sm_desc ); rc = rs->sr_err = attr_merge( e, mod->sm_desc, mod->sm_values, mod->sm_nvalues ); if ( rc != LDAP_SUCCESS ) { break; } continue; /* * only the "managedInfo" attribute can be modified */ } else if ( mod->sm_desc != mi->mi_ad_managedInfo ) { rc = rs->sr_err = LDAP_UNWILLING_TO_PERFORM; break; } switch ( mod->sm_op ) { case LDAP_MOD_ADD: rc = add_values( op, e, mod, &newlevel ); break; case LDAP_MOD_DELETE: rc = delete_values( op, e, mod, &newlevel ); break; case LDAP_MOD_REPLACE: rc = replace_values( op, e, mod, &newlevel ); break; default: rc = LDAP_OTHER; break; } if ( rc != LDAP_SUCCESS ) { rs->sr_err = rc; break; } } /* set the new debug level */ if ( rc == LDAP_SUCCESS ) { const char *text; static char textbuf[ BACKMONITOR_BUFSIZE ]; /* check for abandon */ if ( op->o_abandon ) { rc = rs->sr_err = SLAPD_ABANDON; goto cleanup; } /* check that the entry still obeys the schema */ rc = entry_schema_check( op, e, save_attrs, 0, 0, NULL, &text, textbuf, sizeof( textbuf ) ); if ( rc != LDAP_SUCCESS ) { rs->sr_err = rc; goto cleanup; } /* * Do we need to protect this with a mutex? */ ldap_syslog = newlevel; #if 0 /* debug rather than log */ slap_debug = newlevel; lutil_set_debug_level( "slapd", slap_debug ); ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &slap_debug); ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &slap_debug); ldif_debug = slap_debug; #endif } cleanup:; if ( rc == LDAP_SUCCESS ) { attrs_free( save_attrs ); } else { attrs_free( e->e_attrs ); e->e_attrs = save_attrs; } ldap_pvt_thread_mutex_unlock( &monitor_log_mutex ); if ( rc == LDAP_SUCCESS ) { rc = SLAP_CB_CONTINUE; } return rc; }