EventTrigger* EventTrigger::create( class MapLogic* map_logic, const ValueMap& event_data ) { EventTrigger* ret = new EventTrigger(); if( ret && ret->init( map_logic, event_data ) ) { ret->autorelease(); return ret; } else { CC_SAFE_DELETE( ret ); return nullptr; } }
void EventTrigger::serialize( Kernel::IArchive& ar, EventTrigger& obj ) { std::string tmp; if( obj.IsUninitialized() ) tmp = NoTrigger.ToString(); else tmp = obj.ToString(); ar & tmp; obj = tmp; }
bool IncidenceCounterSurveillance::notifyOnEvent( IIndividualHumanEventContext *pEntity, const EventTrigger& trigger ) { LOG_INFO_F( "notifyOnEvent received: %s\n", trigger.ToString().c_str() ); if ( m_NodePropertyRestrictions.Qualifies(pEntity->GetNodeEventContext()->GetNodeContext()->GetNodeProperties() ) && m_DemographicRestrictions.IsQualified(pEntity) && !IsDoneCounting() ) { if( Find( m_PercentageEventsToCountIndividual, trigger ) ) { ++m_PercentageEventsCounted; } if( Find( m_TriggerConditionListIndividual, trigger ) ) { ++m_Count; LOG_INFO_F( "notifyOnEvent received: %s m_Count: %d\n", trigger.ToString().c_str(), m_Count ); } } return true; }
void AbstractBednet::BroadcastEvent( const EventTrigger& trigger ) const { if( !trigger.IsUninitialized() ) { INodeTriggeredInterventionConsumer* broadcaster = nullptr; if( s_OK != parent->GetEventContext()->GetNodeEventContext()->QueryInterface( GET_IID( INodeTriggeredInterventionConsumer ), (void**)&broadcaster ) ) { throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent->GetEventContext()->GetNodeEventContext()", "INodeTriggeredInterventionConsumer", "INodeEventContext" ); } broadcaster->TriggerNodeEventObservers( parent->GetEventContext(), trigger ); } }
bool ReportEventRecorder::notifyOnEvent( IIndividualHumanEventContext *context, const EventTrigger& trigger ) { int id = context->GetSuid().data; ExternalNodeId_t node_id = context->GetNodeEventContext()->GetExternalId(); IdmDateTime sim_time = context->GetNodeEventContext()->GetTime(); const char* event_name = trigger.c_str(); float age = context->GetAge(); const char gender = (context->GetGender() == Gender::MALE) ? 'M' : 'F' ; bool infected = context->IsInfected(); float infectious = context->GetInfectiousness() ; GetOutputStream() << GetTime( sim_time ) << "," << node_id << "," << event_name << "," << id << "," << age << "," << gender << "," << infected << "," << infectious; // Report requested properties const auto * pProp = context->GetProperties(); for (const auto& prop_name : properties_to_report) { IPKey key( prop_name ); if( !pProp->Contains( key ) ) { throw BadMapKeyException( __FILE__, __LINE__, __FUNCTION__, "properties", prop_name.c_str() ); } GetOutputStream() << "," << pProp->Get( key ).GetValueAsString(); } GetOutputStream() << GetOtherData( context, trigger ); GetOutputStream() << std::endl; return true ; }
//returns false if didn't get the intervention bool NodeLevelHealthTriggeredIV::notifyOnEvent( IIndividualHumanEventContext *pIndiv, const EventTrigger& trigger ) { // ---------------------------------------------------------------------- // --- Ignore events for nodes that don't qualify due to their properties // ---------------------------------------------------------------------- if( !node_property_restrictions.Qualifies( parent->GetNodeContext()->GetNodeProperties() ) ) { return false; } IIndividualHuman *p_human = nullptr; if (s_OK != pIndiv->QueryInterface(GET_IID(IIndividualHuman), (void**)&p_human)) { throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "pIndiv", "IIndividualHuman", "IIndividualHumanEventContext" ); } bool missed_intervention = false ; if( distribute_on_return_home && (trigger == EventTrigger::Emigrating) ) { if( p_human->AtHome() ) { // ------------------------------------------------------------------------------------------------ // --- If the individual is leaving his node of residence, then we want to keep track that he left // --- so that when he returns we can give him the interventions that he missed. // ------------------------------------------------------------------------------------------------ release_assert( event_occurred_while_resident_away.count( pIndiv->GetSuid() ) == 0 ); event_occurred_while_resident_away.insert( make_pair( pIndiv->GetSuid(), false ) ); } return false ; } else if( distribute_on_return_home && (trigger == EventTrigger::Immigrating) ) { if( p_human->AtHome() ) { // ------------------------------------------------------------------------------ // --- If the individual has returned home and they missed the intervention, then // --- we want them to get it, assuming they qualify. // ------------------------------------------------------------------------------ release_assert( event_occurred_while_resident_away.count( pIndiv->GetSuid() ) > 0 ); missed_intervention = event_occurred_while_resident_away[ pIndiv->GetSuid() ] ; event_occurred_while_resident_away.erase( pIndiv->GetSuid() ); if( missed_intervention ) { LOG_DEBUG_F( "Resident %d came home and intervention was distributed while away.\n", pIndiv->GetSuid().data ); } } if( !missed_intervention ) { return false ; } } else // the trigger event { // -------------------------------------------------------------------------------------------- // --- If this is one of the non-migrating events that they intervention is listening for // --- and this is not a blackout period, then record that the residents that are away missed // --- the intervention. // -------------------------------------------------------------------------------------------- if( blackout_time_remaining <= 0.0f ) { for( auto& rEntry : event_occurred_while_resident_away ) { rEntry.second = true ; } } } if( !blackout_event_trigger.IsUninitialized() && (blackout_period > 0.0) ) { if( (event_occured_list[ trigger.GetIndex() ].count( pIndiv->GetSuid().data ) > 0) || (!missed_intervention && (blackout_time_remaining > 0.0f)) ) { INodeTriggeredInterventionConsumer * pNTIC = NULL; if (s_OK != parent->QueryInterface(GET_IID(INodeTriggeredInterventionConsumer), (void**)&pNTIC) ) { throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent", "INodeTriggeredInterventionConsumer", "INodeEventContext" ); } pNTIC->TriggerNodeEventObservers( pIndiv, blackout_event_trigger ); return false; } } LOG_DEBUG_F("Individual %d experienced event %s, check to see if they pass the conditions before distributing actual_intervention \n", pIndiv->GetInterventionsContext()->GetParent()->GetSuid().data, trigger.c_str() ); assert( parent ); assert( parent->GetRng() ); bool distributed = false; if( _di != nullptr ) { //initialize this flag by individual (not by node) m_disqualified_by_coverage_only = false; if( qualifiesToGetIntervention( pIndiv ) == false ) { LOG_DEBUG_F("Individual failed to qualify for intervention, m_disqualified_by_coverage_only is %d \n", m_disqualified_by_coverage_only); if (m_disqualified_by_coverage_only == true) { onDisqualifiedByCoverage( pIndiv ); } return false; } // Query for campaign cost observer interface from INodeEventContext *parent ICampaignCostObserver *iCCO; if (s_OK != parent->QueryInterface(GET_IID(ICampaignCostObserver), (void**)&iCCO)) { throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent", "ICampaignCostObserver", "INodeEventContext" ); } // Huge performance win by cloning instead of configuring. IDistributableIntervention *di = _di->Clone(); release_assert( di ); di->AddRef(); distributed = di->Distribute( pIndiv->GetInterventionsContext(), iCCO ); if( distributed ) { std::string classname = GetInterventionClassName(); LOG_DEBUG_F("A Node level health-triggered intervention (%s) was successfully distributed to individual %d\n", classname.c_str(), pIndiv->GetInterventionsContext()->GetParent()->GetSuid().data ); } else { LOG_DEBUG_F( "Intervention not distributed?\n" ); } di->Release(); } else { release_assert( _ndi ); // Huge performance win by cloning instead of configuring. INodeDistributableIntervention *ndi = _ndi->Clone(); release_assert( ndi ); ndi->AddRef(); distributed = ndi->Distribute( parent, nullptr ); if( distributed ) { std::string classname = GetInterventionClassName(); LOG_INFO_F("Distributed '%s' intervention to node %d\n", classname.c_str(), parent->GetExternalId() ); } ndi->Release(); } if( distributed ) { if( blackout_on_first_occurrence ) { blackout_time_remaining = blackout_period ; } else { notification_occured = true ; } event_occured_list[ trigger.GetIndex() ].insert( pIndiv->GetSuid().data ); } return distributed; }