1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
11 #include <anna/core/tracing/Logger.hpp>
12 #include <anna/core/tracing/TraceMethod.hpp>
14 #include <anna/xml/Node.hpp>
15 #include <anna/xml/Attribute.hpp>
17 #include <anna/app/functions.hpp>
19 #include <anna/comm/Network.hpp>
20 #include <anna/comm/Host.hpp>
21 #include <anna/comm/Server.hpp>
23 #include <anna/comm/Communicator.hpp>
24 #include <anna/comm/IndexedDelivery.hpp>
25 #include <anna/comm/functions.hpp>
30 void comm::IndexedDelivery::prepare(const int key)
31 throw(RuntimeException) {
32 const int size = comm::Delivery::size();
35 string msg(asString());
36 msg += " | No resource has been attached";
37 throw RuntimeException(msg, ANNA_FILE_LOCATION);
40 const int index = key % size;
42 a_iikey = begin() + index;
45 string msg("anna::comm::IndexedDelivery::prepare | Key: ");
46 msg += functions::asString(key);
48 msg += resource(a_iikey)->asString();
49 Logger::debug(msg, ANNA_FILE_LOCATION);
53 comm::Resource* comm::IndexedDelivery::do_apply()
54 throw(RuntimeException) {
55 comm::Resource* result = NULL;
57 if(a_iikey == comm::Delivery::end())
60 comm::Resource* w = result = comm::Delivery::resource(a_iikey);
62 if(w->isAvailable() == false || w->isEnabled() == false) {
64 string msg(asString());
67 msg += " | Unavailable";
68 Logger::warning(msg, ANNA_FILE_LOCATION);
73 if(a_mode == Mode::Flexible) {
78 if((ii = a_iikey + 1) == comm::Delivery::end())
79 ii = comm::Delivery::begin();
82 w = comm::Delivery::resource(ii);
84 if(w->isAvailable() == true && w->isEnabled() == true) {
91 if(ii == comm::Delivery::end())
92 ii = comm::Delivery::begin();
99 string comm::IndexedDelivery::asString() const
101 string result = className();
103 result += comm::Delivery::asString();
104 result += " | Mode: ";
105 result += (a_mode == Mode::Strict) ? "Strict" : "Flexible";
106 return result += " }";
109 xml::Node* comm::IndexedDelivery::asXML(xml::Node* parent) const
111 xml::Node* node = parent->createChild("comm.IndexedDelivery");
112 node->createAttribute("Mode", (a_mode == Mode::Strict) ? "Strict" : "Flexible");
113 comm::Service::asXML(node);