23 #include "moos_node.h" 25 #include "goby/common/logger.h" 27 #include "goby/util/binary.h" 37 glog.
add_group(
"in_hex", common::Colors::green,
"Goby MOOS (hex) - Incoming");
38 glog.
add_group(
"out_hex", common::Colors::magenta,
"Goby MOOS (hex) - Outgoing");
41 void goby::moos::MOOSNode::inbox(common::MarshallingScheme marshalling_scheme,
42 const std::string& identifier,
const std::string& bytes,
45 glog.is(DEBUG2) &&
glog << group(
"in_hex")
46 <<
"Received marshalling scheme: " << marshalling_scheme << std::endl;
48 if (marshalling_scheme == goby::common::MARSHALLING_MOOS)
50 boost::shared_ptr<CMOOSMsg> msg(
new CMOOSMsg);
52 glog.is(DEBUG2) &&
glog << group(
"in_hex") << goby::util::hex_encode(bytes) << std::endl;
53 MOOSSerializer::parse(msg.get(), bytes);
55 const std::string& key = msg->GetKey();
56 newest_vars[key] = msg;
61 void goby::moos::MOOSNode::send(
const CMOOSMsg& msg,
int socket_id,
const std::string& group_unused)
64 MOOSSerializer::serialize(msg, &bytes);
67 <<
"CMOOSMsg/" << msg.GetKey() <<
"/" << std::endl;
69 glog.is(DEBUG2) &&
glog << group(
"out_hex") << goby::util::hex_encode(bytes) << std::endl;
71 zeromq_service()->send(goby::common::MARSHALLING_MOOS,
"CMOOSMsg/" + msg.GetKey() +
"/", bytes,
75 void goby::moos::MOOSNode::subscribe(
const std::string& full_or_partial_moos_name,
int socket_id)
77 std::string trimmed_name = boost::trim_copy(full_or_partial_moos_name);
78 unsigned size = trimmed_name.size();
81 zeromq_service()->subscribe(goby::common::MARSHALLING_MOOS,
"CMOOSMsg/", socket_id);
83 else if (trimmed_name[size - 1] ==
'*')
85 zeromq_service()->subscribe(goby::common::MARSHALLING_MOOS,
86 "CMOOSMsg/" + trimmed_name.substr(0, size - 1), socket_id);
90 zeromq_service()->subscribe(goby::common::MARSHALLING_MOOS,
91 "CMOOSMsg/" + trimmed_name +
"/", socket_id);
95 void goby::moos::MOOSNode::unsubscribe(
const std::string& full_or_partial_moos_name,
int socket_id)
97 std::string trimmed_name = boost::trim_copy(full_or_partial_moos_name);
98 unsigned size = trimmed_name.size();
101 glog.is(WARN) &&
glog << warn <<
"Not unsubscribing for empty string!" << std::endl;
103 else if (trimmed_name[size - 1] ==
'*')
105 zeromq_service()->unsubscribe(goby::common::MARSHALLING_MOOS,
106 "CMOOSMsg/" + trimmed_name.substr(0, size - 1), socket_id);
110 zeromq_service()->unsubscribe(goby::common::MARSHALLING_MOOS,
111 "CMOOSMsg/" + trimmed_name +
"/", socket_id);
115 CMOOSMsg& goby::moos::MOOSNode::newest(
const std::string& key)
117 if (!newest_vars.count(key))
118 newest_vars[key] = boost::shared_ptr<CMOOSMsg>(
new CMOOSMsg);
120 return *newest_vars[key];
123 std::vector<CMOOSMsg> goby::moos::MOOSNode::newest_substr(
const std::string& substring)
125 std::vector<CMOOSMsg> out;
127 std::string trimmed_substring = boost::trim_copy(substring);
128 unsigned size = trimmed_substring.size();
132 if (trimmed_substring[size - 1] ==
'*')
134 trimmed_substring = trimmed_substring.substr(0, size - 1);
138 if (newest_vars.count(trimmed_substring))
139 out.push_back(*newest_vars[trimmed_substring]);
144 for (std::map<std::string, boost::shared_ptr<CMOOSMsg> >::const_iterator
145 it = newest_vars.begin(),
146 end = newest_vars.end();
149 if (!size || it->first.compare(0, trimmed_substring.size(), trimmed_substring) == 0)
150 out.push_back(*(it->second));
void add_group(const std::string &name, Colors::Color color=Colors::nocolor, const std::string &description="")
Add another group to the logger. A group provides related manipulator for categorizing log messages...
common::FlexOstream glog
Access the Goby logger through this object.
The global namespace for the Goby project.