8 #include <boost/type_traits/remove_cv.hpp> 9 #include <boost/variant/get.hpp> 10 #include <boost/variant/recursive_variant.hpp> 11 #include <boost/variant/variant.hpp> 12 #include <base-logging/Logging.hpp> 23 typedef fipa::acl::bitefficient::Message<std::string::const_iterator> bitefficient_message_grammar;
24 bitefficient_message_grammar grammar;
27 std::string::const_iterator iter = storage.begin();
28 std::string::const_iterator end = storage.end();
29 bool r = parse(iter, end, grammar, parseTree);
48 void BitefficientMessageParser::buildParameters(
const std::vector<message::Parameter>& parsedParams,
ACLMessage &msg)
50 std::vector<message::Parameter>::const_iterator it = parsedParams.begin();
52 for (; it != parsedParams.end(); ++it)
55 buildPredefMessageParameters(*it,msg);
56 }
catch(
const std::runtime_error& e)
59 LOG_INFO(
"Creating userdefined parameter name: '%s' value: '%s'", param.
getName().c_str(), param.
getValue().c_str());
68 if (param.
name ==
"sender")
70 buildSender(param, msg);
73 if (param.
name ==
"receiver")
75 buildReceiver(param, msg);
78 if (param.
name ==
"content")
80 buildContent(param, msg);
83 if (param.
name ==
"reply-by")
85 buildReplyBy(param, msg);
88 if (param.
name ==
"reply-to")
90 buildReplyTo(param, msg);
97 value = boost::get<std::string>(param.
data);
98 }
catch (
const boost::bad_get& e)
100 LOG_ERROR(
"Failed getting data for parameter '%s'", param.
name.c_str());
104 if (param.
name ==
"in-reply-to")
109 if (param.
name ==
"reply-with")
114 if (param.
name ==
"language")
119 if (param.
name ==
"encoding")
124 if (param.
name ==
"ontology")
129 if (param.
name ==
"protocol")
135 if (param.
name ==
"conversation-id")
141 std::string errorMsg =
"Message parameter '" + param.
name +
"' is not predefined";
142 LOG_ERROR(
"%s",errorMsg.c_str());
143 throw std::runtime_error(errorMsg);
149 AgentID sender = buildAgentID(temp);
161 std::vector<std::string>::const_iterator it = agent.
addresses.begin();
170 buildResolvers(agent, retAg);
175 buildAgentParameters(agent, retAg);
182 void BitefficientMessageParser::buildResolvers(
const AgentIdentifier& agentIdentifier,
AgentID& outAgentID)
184 std::vector<fipa::acl::Resolver>::const_iterator it = agentIdentifier.
resolvers.begin();
185 for (; it != agentIdentifier.
resolvers.end(); ++it)
188 AgentID agent = buildAgentID(resolver);
193 void BitefficientMessageParser::buildAgentParameters(
const AgentIdentifier& agentIdentifier,
AgentID& outAgentID)
195 std::vector<UserDefinedParameter>::const_iterator it = agentIdentifier.
parameters.begin();
196 for (; it != agentIdentifier.
parameters.end(); ++it)
206 const std::string& value = boost::get<std::string>(param.
data);
210 retParam.setValue(value);
217 const std::string& value = boost::get<std::string>(param.
data);
221 retParam.setValue(value);
230 const std::vector<AgentIdentifier>& unbuiltReceivers = boost::get<std::vector<AgentIdentifier> >(param.
data);
231 std::vector<AgentIdentifier>::const_iterator it = unbuiltReceivers.begin();
232 for (; it!= unbuiltReceivers.end(); ++it)
234 AgentID receiver = buildAgentID(*it);
241 const DateTime& dateTime = boost::get<DateTime>(param.
data);
242 base::Time date = dateTime.
toTime();
248 const std::vector<AgentIdentifier>& agentIds = boost::get<std::vector<AgentIdentifier> >(param.
data);
250 std::vector<AgentIdentifier>::const_iterator it = agentIds.begin();
251 for (; it != agentIds.end(); ++it)
253 AgentID agentId = buildAgentID(*it);
void setReplyWith(const std::string &str)
void setConversationID(const std::string &str)
std::string toRawDataString() const
void setName(const std::string &name)
the method checks whether the passed name string is a word or not(according to the fipa spec) ...
void setLanguage(const std::string &str)
void addResolver(const AgentID &aid)
Add resolver.
void addAddress(const std::string &adr)
the method checks whether the passed address string is a word or not(according to the fipa spec) ...
std::vector< message::Parameter > parameters
std::vector< std::string > addresses
void setInReplyTo(const std::string &str)
Representation of a byte sequence. We also embed information about the encoding.
base::Time toTime() const
void addReplyTo(const AgentID &aid)
const std::string & getValue() const
void addUserdefParam(const UserdefParam &p)
Add a userdefined parameter.
rebuilds an ACLMessage from a parsed bit-efficient encoded received message
fipa::acl::UserDefinedParameterValue data
void setContent(const std::string &content)
void setSender(const AgentID &sender)
void setName(const std::string &name)
the method checks whether the passed name string is a word or not(according to the fipa spec) ...
void addUserdefParam(const UserdefParam &p)
Definition for AgentIdentifier.
bool parseData(const std::string &storage, ACLMessage &msg)
parses a correctly encoded message according to grammar_bitefficient.h and creates a Message object f...
const std::string & getName() const
This class provides a representation of a message conforming to the FIPA specification SC00061...
void setReplyBy(const base::Time &time)
bool buildMessage(const Message &parsedMsg, ACLMessage &msg)
creates an unpopulated message object and passes it around to have its fields populated, along with the parsed message where the data is extracted from
std::vector< fipa::acl::UserDefinedParameter > parameters
overloaded equality operator for UserdefParam class objects
void addReceiver(const AgentID &aid)
std::vector< fipa::acl::Resolver > resolvers
void setPerformative(Performative perf)
Set performative.
Implements the general AgentID functionality, which is present throughout the fipa specifications(FIP...
Foundation of Physical Intelligent Agents.
void setEncoding(const std::string &str)
void setProtocol(const std::string &str)
the method checks whether the passed protocol string is a word or not(according to the fipa spec) ...
void setOntology(const std::string &str)