scds_pso_tuple.cpp
Go to the documentation of this file.
00001 
00023 #include "micros_swarm/scds_pso_tuple.h"
00024 
00025 namespace micros_swarm{
00026 
00027     SCDSPSOTuple::SCDSPSOTuple()
00028     {
00029         rth_ = Singleton<RuntimeHandle>::getSingleton();
00030         mqm_ = Singleton<MsgQueueManager>::getSingleton();
00031     }
00032 
00033     SCDSPSOTuple::SCDSPSOTuple(const SCDSPSOTuple& t)
00034     {
00035         rth_ = Singleton<RuntimeHandle>::getSingleton();
00036         mqm_ = Singleton<MsgQueueManager>::getSingleton();
00037     }
00038 
00039     SCDSPSOTuple& SCDSPSOTuple::operator=(const SCDSPSOTuple& t)
00040     {
00041         if(this == &t) {
00042             return *this;
00043         }
00044         rth_ = Singleton<RuntimeHandle>::getSingleton();
00045         mqm_ = Singleton<MsgQueueManager>::getSingleton();
00046         return *this;
00047     }
00048 
00049     SCDSPSOTuple::~SCDSPSOTuple()
00050     {
00051         rth_.reset();
00052         mqm_.reset();
00053     }
00054 
00055     void SCDSPSOTuple::put(const std::string& key, const SCDSPSODataTuple& data)
00056     {
00057         rth_->insertOrUpdateSCDSPSOValue(key, data);
00058 
00059         gsdf_msgs::SCDSPSOPut scds_put;
00060         scds_put.key = key;
00061         scds_put.pos = data.pos;
00062         scds_put.val = data.val;
00063         scds_put.robot_id = data.robot_id;
00064         scds_put.gen = data.gen;
00065         scds_put.timestamp = data.timestamp;
00066         std::vector<uint8_t> scds_put_vec = serialize_ros(scds_put);
00067 
00068         gsdf_msgs::CommPacket p;
00069         p.header.source = rth_->getRobotID();
00070         p.header.type = SCDS_PSO_PUT;
00071         p.header.data_len = scds_put_vec.size();
00072         p.header.version = 1;
00073         p.header.checksum = 0;
00074         p.content.buf = scds_put_vec;
00075         std::vector<uint8_t> msg_data = serialize_ros(p);
00076         mqm_->getOutMsgQueue("scds_pso")->push(msg_data);
00077     }
00078 
00079     SCDSPSODataTuple SCDSPSOTuple::get(const std::string& key)
00080     {
00081         SCDSPSODataTuple data;
00082         if (!rth_->getSCDSPSOValue(key, data)) {
00083             std::cout<<"scds pso tuple, "<<key<<" is not exist."<<std::endl;
00084             exit(-1);
00085         }
00086 
00087         gsdf_msgs::SCDSPSOGet scds_get;
00088         scds_get.key = key;
00089         scds_get.pos = data.pos;
00090         scds_get.val = data.val;
00091         scds_get.robot_id = data.robot_id;
00092         scds_get.gen = data.gen;
00093         scds_get.timestamp = data.timestamp;
00094         std::vector<uint8_t> scds_get_vec = serialize_ros(scds_get);
00095 
00096         gsdf_msgs::CommPacket p;
00097         p.header.source = rth_->getRobotID();
00098         p.header.type = SCDS_PSO_GET;
00099         p.header.data_len = scds_get_vec.size();
00100         p.header.version = 1;
00101         p.header.checksum = 0;
00102         p.content.buf = scds_get_vec;
00103         std::vector<uint8_t> msg_data = serialize_ros(p);
00104         mqm_->getOutMsgQueue("scds_pso")->push(msg_data);
00105 
00106         return data;
00107     }
00108 }


micros_swarm
Author(s):
autogenerated on Thu Jun 6 2019 18:52:14