/** * Called on transition to a new action pattern. If the arbiter is currently * inactive open is called afterwards. Note that if the arbiter is already * part of the current behaviour, arbitrate can be called concurrently. */ void Arbiter::init(const ArbiterParameters * _params) { Guard guard(mutex_); // convert current arbitration to new configuration // build new message vector MessageVector tmp(_params->priorities.size(), NULL); MessageVector::iterator first, last = tmp.end(); for (first = tmp.begin(); first != last; ++first) delete *first; // copy old message values if available // allways except first time if (params_) { ArbiterParameters::RegistrationMap::const_iterator i, j; // for each behaviour for (i = _params->priorities.begin(); i != _params->priorities.end(); ++i) { // if it existed before j = params_->priorities.find(i->first); if (j != params_->priorities.end()) { // copy its current arbitration message to // the new index in the new message vector tmp[i->second] = message_[j->second]; // remove copy of pointer to avoid confusion message_[j->second] = NULL; } else { // else build new entry tmp[i->second] = getMessageInstance(); } } } else for (first = tmp.begin(); first != last; ++first) *first = getMessageInstance(); // swap old and new message vectors message_.swap(tmp); // delete old messages last = tmp.end(); for (first = tmp.begin(); first != last; ++first) delete *first; // create local copy of current priority mapping // for next arbitration change params_ = _params; // new activations calcActivation(); }
void MsgHandler::initOutputOptions(bool gui) { OptionsCont& oc = OptionsCont::getOptions(); //getMessageInstance()->report2cout(!gui && oc.getBool("verbose")); getMessageInstance()->report2cout(true); getWarningInstance()->report2cerr(!gui && !oc.getBool("suppress-warnings")); // build the logger if possible if (oc.isSet("log-file")) { try { OutputDevice *logFile = &OutputDevice::getDevice(oc.getString("log-file")); getErrorInstance()->addRetriever(logFile); getWarningInstance()->addRetriever(logFile); getMessageInstance()->addRetriever(logFile); } catch (IOError &) { throw ProcessError("Could not build logging file '" + oc.getString("log-file") + "'"); } } if (oc.isSet("message-log")) { try { OutputDevice *logFile = &OutputDevice::getDevice(oc.getString("message-log")); getMessageInstance()->addRetriever(logFile); } catch (IOError &) { throw ProcessError("Could not build logging file '" + oc.getString("message-log") + "'"); } } if (oc.isSet("error-log")) { try { OutputDevice *logFile = &OutputDevice::getDevice(oc.getString("error-log")); getErrorInstance()->addRetriever(logFile); getWarningInstance()->addRetriever(logFile); } catch (IOError &) { throw ProcessError("Could not build logging file '" + oc.getString("error-log") + "'"); } } }