Esempio n. 1
0
 virtual void externalTransition(
     const devs::ExternalEventList&  event ,
     const devs::Time& time)
 {
     for (vd::ExternalEventList::const_iterator it = event.begin();
          it != event.end(); ++it) {
         if ((*it)->onPort("surveillance")) {
             Intervention newIntervention;
             value::Map infNodes = (*it)->getMapAttributeValue("infectedNodes");
             for (vv::MapValue::const_iterator node = infNodes.begin();
                  node != infNodes.end(); node++) {
                 m_nodeStates[node->first] = node->second->toString().value();
                 newIntervention.second.push_back(node->first);
             }
             newIntervention.first = time.getValue() + m_delay;
             m_interventions.push_back(newIntervention);
             if (m_phase == IDLE)
                 m_phase = CONTROL;
             /*
             else {
                 vle::utils::InternalError error(
                     "\nControler must recieve only one surveillance repport in this version\n");
                 throw error;
                 }
             */
         }
     }
     m_current_time = time.getValue();
 }
Esempio n. 2
0
void Agent::externalTransition(
    const devs::ExternalEventList& events,
    const devs::Time& time)
{
    mCurrentTime = time;

    for (devs::ExternalEventList::const_iterator it = events.begin();
            it != events.end(); ++it) {
        const std::string& port((*it)->getPortName());
        const value::Map& atts = (*it)->getAttributes();

        if (port == "ack") {
            const std::string& activity(atts.getString("name"));
            const std::string& order(atts.getString("value"));

            if (order == "done") {
                setActivityDone(activity, time);
            } else if (order == "fail") {
                setActivityFailed(activity, time);
            } else {
                throw utils::ModellingError(
                    fmt(_("Decision: unknown order `%1%'")) % order);
            }
        } else {
            value::Map::const_iterator jt = atts.value().find("value");
            if (jt == atts.end()) {
                jt = atts.value().find("init");
            }

            if (jt == atts.end() or not jt->second) {
                throw utils::ModellingError(
                    fmt(_("Decision: no value in this message: `%1%'")) %
                    (*it));
            }

            if (mPortMode) {
                applyFact(port, *jt->second);
            } else {
                const std::string& fact((*it)->getStringAttributeValue("name"));
                applyFact(fact, *jt->second);
            }
        }
    }

    mState = UpdateFact;
}