// ---------------------------------------------------------------------- void VisEnergyProcessor:: work( void ) throw() { if( simulation_round()-last_time_of_receive_ > 30 ) { cout << "ID " << id() << " DONE: " << (unsigned int)neighbours_.size() << " neighbours: "; for( std::set<const Node*>::const_iterator it = neighbours_.begin(), first = it, endit = neighbours_.end(); it != endit; ++it ) { if( it != first ) cout << ", "; cout << "'"<<(**it).label()<<"'"; } cout << endl; set_state( Inactive ); } }
// ---------------------------------------------------------------------- void HelloworldProcessor:: boot( void ) throw() { last_time_of_receive_ = simulation_round(); send( new HelloworldMessage ); }
// ---------------------------------------------------------------------- void LocalizationGPSfreeLCSModule:: work( void ) throw() { // send initial messages if ( state_ == gflcs_init ) { send( new LocalizationGPSfreeLCSInitMessage() ); state_ = gflcs_wait_bc; } // after idle-time passed, initial messages of neighbors had already been // received and state is set to 'broadcast'. if ( state_ == gflcs_wait_bc && simulation_round() - last_useful_msg_ > observer().idle_time() ) { state_ = gflcs_broadcast; last_useful_msg_ = simulation_round(); } // broadcast collected information if ( state_ == gflcs_broadcast ) { broadcast_neighborhood(); state_ = gflcs_wait_w; } // after idle-time passed, neighborhood messages of neighbors had already been // received and state is set to 'work'. if ( state_ == gflcs_wait_w && simulation_round() - last_useful_msg_ > observer().idle_time() ) state_ = gflcs_work; if ( state_ == gflcs_work ) { build_lcs(); state_ = gflcs_finished; } // maybe shutdown processor if ( simulation_round() - last_useful_msg_ > observer().idle_shutdown_time() ) { state_ = gflcs_finished; } }
// ---------------------------------------------------------------------- void SimpleAppProcessor:: work( void ) throw() { // send message only in the first simulation round if ( simulation_round() == 0 ) { send( new SimpleAppMessage ); } }
// ---------------------------------------------------------------------- void VisEnergyProcessor:: boot( void ) throw() { last_time_of_receive_ = simulation_round(); //Creates an event to the event_scheduler event_handle_ = owner_w().world_w().scheduler_w().new_event(*this,sending_time_ ,NULL); this->owner_w().add_tag(new shawn::DoubleTag("VisBattery", 1.0)); std::string labelvalue = "LabelTest"; this->owner_w().add_tag(new shawn::StringTag("VisLabel", labelvalue)); }
// ---------------------------------------------------------------------- bool LocalizationGPSfreeLCSModule:: process_gpsfree_lcs_init_message( const LocalizationGPSfreeLCSInitMessage& lgflcsim ) throw() { const Node& source = lgflcsim.source(); Vec source_pos = lgflcsim.source().real_position(); double distance = estimate_distance( source, node() ); last_useful_msg_ = simulation_round(); neighborhood_w().update_neighbor( source, distance ); return true; }
// ---------------------------------------------------------------------- bool VisEnergyProcessor:: process_message( const ConstMessageHandle& mh ) throw() { const helloworld::HelloworldMessage* hmsg = dynamic_cast<const helloworld::HelloworldMessage*> ( mh.get() ); if( hmsg != NULL ) { last_time_of_receive_=simulation_round(); neighbours_.insert( &hmsg->source() ); cout << "ID '" << owner().label() << "' GOT HELLO FROM '" << hmsg->source().label() << "'" << endl; this->owner_w().remove_tag_by_name("VisBattery"); this->owner_w().add_tag(new shawn::DoubleTag("VisBattery", 0.0)); return true; } this->owner_w().remove_tag_by_name("VisBattery"); this->owner_w().add_tag(new shawn::DoubleTag("VisBattery", 0.0)); return Processor::process_message( mh ); }
// ---------------------------------------------------------------------- bool HelloworldProcessor:: process_message( const ConstMessageHandle& mh ) throw() { const HelloworldMessage* hmsg = dynamic_cast<const HelloworldMessage*> ( mh.get() ); if( hmsg != NULL ) { last_time_of_receive_=simulation_round(); neighbours_.insert( &hmsg->source() ); if( owner() != hmsg->source() ) cout << "ID '" << owner().label() << "' GOT HELLO FROM '" << hmsg->source().label() << "'" << endl; return true; } else { cout << "ID '" << owner().label() << "' GOT MESSAGE FROM '" << mh.get()->source().label() << "'" << endl; } return Processor::process_message( mh ); }
// ---------------------------------------------------------------------- void AutoCastProcessor:: work( void ) throw() { /*neighbors_count_+=neighborhood_.neighborhood_size(); real_neighbors_count_+=owner().get_adjacent_nodes().size(); velocity_count_+=owner().movement().velocity().euclidean_norm(); update_time_count_+=update_time_;*/ if (active_times_.size() > 0) { // If activeTimes were read from file int now = static_cast<int>(owner().world().scheduler().current_time()); if (active_times_it_ != active_times_.end() && *active_times_it_ == now) { // it's time o switch the State if (this->state() == Processor::Active) { this->set_state(Processor::Sleeping); } else { this->set_state(Processor::Active); if ( update_timer_ ) { owner_w().world_w().scheduler_w().delete_event(update_timer_); update_timer_ = NULL; } update_timer_ = owner_w().world_w().scheduler_w().new_event(*this,now + max_update_time_ * uniform_random(0.0,1.0),NULL); } ++active_times_it_; } } if (logging_ && state() == Processor::Active) activeTime_++; if (logging_ && (activeTime_ > 0) && (simulation_round() == max_iterations_ - 1)){ KeeperManagedHandle kmh = owner_w().world_w().simulation_controller_w().simulation_task_keeper_w().find_managed_w("AutoCastTask"); assert(kmh.is_not_null()); autocast::AutoCastTask* act = dynamic_cast<autocast::AutoCastTask*>( kmh.get() ); if (act){ act->process_sent_statistic( &owner(), packets_sent_total_, bytes_sent_total_, dataUnits_sent_total_, dataUnits_bytes_sent_total_, received_messages_ids_total_.size(), received_DataUnits_total_, received_DataUnit_ids_total_.size(), activeTime_, msgCountBeacon_, msgCountAnswer_, msgCountAnswer_only_, msgCountFlood_, msgCountFlood_only_, msgCountRequest_, msgCountRequest_only_ ); } // And at least clean_up(); } }