opensplice_dds_broker.cpp
Go to the documentation of this file.
1 
23 #include <iostream>
25 
27 
28 namespace opensplice_dds_broker{
29 
30  OpenSpliceDDSBroker::OpenSpliceDDSBroker()
31  {
32  packet_publisher_.reset(new opensplice_dds_broker::Publisher("micros_swarm_framework_topic"));
33  packet_subscriber_.reset(new opensplice_dds_broker::Subscriber("micros_swarm_framework_topic"));
34  }
35 
36  void OpenSpliceDDSBroker::init(std::string name, const micros_swarm::PacketParser& parser)
37  {
38  name_ = name;
39  parser_ = parser;
40  }
41 
42  void OpenSpliceDDSBroker::broadcast(const std::vector<uint8_t>& msg_data)
43  {
45  unsigned int bufsize = msg_data.size();
46  if(!msg_data.empty()) {
47  dds_msg.data.replace(bufsize, bufsize, (char*)(&msg_data[0]), false);
48  packet_publisher_->publish(dds_msg);
49  }
50  }
51 
52  void OpenSpliceDDSBroker::callback(const opensplice_dds_broker::GSDFPacket& dds_msg)
53  {
54  int msgLen = dds_msg.data.length();
55  if (msgLen == 0) {
56  std::cout<<"opensplice dds recv error."<<std::endl;
57  }
58  else {
59  uint8_t* buf = (uint8_t*)malloc(sizeof(uint8_t)*msgLen);
60  memcpy(buf, dds_msg.data.get_buffer(), msgLen);
61  parser_.parse(buf, msgLen);
62  }
63  }
64 
65  void OpenSpliceDDSBroker::receive()
66  {
67  boost::function<void(const opensplice_dds_broker::GSDFPacket&)> func = boost::bind(&OpenSpliceDDSBroker::callback, this, _1);
68  packet_subscriber_->subscribe(func);
69  }
70 };
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)


opensplice_dds_broker
Author(s):
autogenerated on Mon Jun 10 2019 14:02:23