revert 8ce7718201
revert FIX: fixed message class to that only one any message can be stored; deleted track class
This commit is contained in:
54
src/WHISPER/Messages/Join.cpp
Normal file
54
src/WHISPER/Messages/Join.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "WHISPER/Messages/Message.hpp"
|
||||
#include <WHISPER/Messages/Join.hpp>
|
||||
#include <memory>
|
||||
|
||||
|
||||
|
||||
|
||||
namespace WHISPER {
|
||||
|
||||
Join::Join(std::string receivedMessage){
|
||||
msg = messages::header::Message();
|
||||
try {
|
||||
msg.ParseFromString(receivedMessage);
|
||||
topic_ = msg.topic();
|
||||
sourceType_ = msg.sourcetype();
|
||||
msgType_ = msg.msgtype();
|
||||
joinMessage = messages::join::Join();
|
||||
deviceId_ = msg.sourceid();
|
||||
|
||||
if ( msg.payload_size()) {
|
||||
if (msg.payload().begin()->Is<messages::join::Join>()) {
|
||||
msg.payload().begin()->UnpackTo(&joinMessage);
|
||||
}
|
||||
}
|
||||
port = joinMessage.port();
|
||||
sourceAddr = joinMessage.srcaddress();
|
||||
|
||||
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
LOG_S(ERROR)<<e.what();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
WHISPER::Join::Join(std::uint32_t deviceID, SourceType src,std::uint32_t port, std::string addr):
|
||||
Message(deviceID,WHISPER::MsgTopics::MANAGEMENT,WHISPER::JOIN,src),port(port),sourceAddr(addr)
|
||||
{
|
||||
joinMessage = messages::join::Join();
|
||||
joinMessage.set_port(port);
|
||||
joinMessage.set_srcaddress(sourceAddr);
|
||||
|
||||
auto payloadMessage = std::make_shared<google::protobuf::Any>();
|
||||
payloadMessage->PackFrom(joinMessage);
|
||||
addPayLoad(payloadMessage);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
55
src/WHISPER/Messages/Leave.cpp
Normal file
55
src/WHISPER/Messages/Leave.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "WHISPER/Messages/Message.hpp"
|
||||
#include <WHISPER/Messages/Leave.hpp>
|
||||
#include <memory>
|
||||
|
||||
|
||||
|
||||
|
||||
namespace WHISPER {
|
||||
|
||||
Leave::Leave(std::string receivedMessage){
|
||||
msg = messages::header::Message();
|
||||
try {
|
||||
msg.ParseFromString(receivedMessage);
|
||||
topic_ = msg.topic();
|
||||
sourceType_ = msg.sourcetype();
|
||||
msgType_ = msg.msgtype();
|
||||
|
||||
leaveMessage = messages::leave::Leave();
|
||||
|
||||
if ( msg.payload_size()) {
|
||||
if (msg.payload().begin()->Is<messages::leave::Leave>()) {
|
||||
msg.payload().begin()->UnpackTo(&leaveMessage);
|
||||
}
|
||||
}
|
||||
port = leaveMessage.port();
|
||||
sourceAddr = leaveMessage.srcaddress();
|
||||
|
||||
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
LOG_S(ERROR)<<e.what();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Leave::Leave(std::uint32_t deviceID, SourceType src,std::uint32_t port, std::string addr):
|
||||
Message(deviceID,WHISPER::MsgTopics::MANAGEMENT,WHISPER::LEAVE,src),port(port),sourceAddr(addr)
|
||||
{
|
||||
|
||||
leaveMessage = messages::leave::Leave();
|
||||
leaveMessage.set_port(port);
|
||||
leaveMessage.set_srcaddress(sourceAddr);
|
||||
|
||||
auto payloadMessage = std::make_shared<google::protobuf::Any>();
|
||||
payloadMessage->PackFrom(leaveMessage);
|
||||
addPayLoad(payloadMessage);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
74
src/WHISPER/Messages/Message.cpp
Normal file
74
src/WHISPER/Messages/Message.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
|
||||
#include <WHISPER/Messages/Message.hpp>
|
||||
#include <memory>
|
||||
|
||||
|
||||
|
||||
|
||||
namespace WHISPER {
|
||||
Message::Message(std::string stringMessage)
|
||||
{
|
||||
msg = messages::header::Message();
|
||||
try {
|
||||
msg.ParseFromString(stringMessage);
|
||||
|
||||
deviceId_ = msg.sourceid();
|
||||
topic_ = msg.topic();
|
||||
sourceType_ = msg.sourcetype();
|
||||
msgType_ = msg.msgtype();
|
||||
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
LOG_S(ERROR)<<e.what();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Message::Message(std::int32_t deviceId, MsgTopics topic, MsgType Type,SourceType src):topic_(topic),sourceType_(src),msgType_(Type){
|
||||
msg = messages::header::Message();
|
||||
|
||||
if(msg.IsInitialized())
|
||||
{
|
||||
msg.set_sourceid(deviceId);
|
||||
msg.set_topic(topic);
|
||||
msg.set_sourcetype(sourceType_);
|
||||
msg.set_msgtype(msgType_);
|
||||
}
|
||||
deviceId_ = deviceId;
|
||||
topic_ = topic;
|
||||
sourceType_ = src;
|
||||
msgType_ = Type;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string Message::getPayloadString(){
|
||||
return payloadString_;
|
||||
}
|
||||
|
||||
|
||||
void Message::addPayLoad(std::shared_ptr<google::protobuf::Any> payload){
|
||||
payload_ = payload;
|
||||
|
||||
msg.clear_payload();
|
||||
msg.add_payload()->CopyFrom(*payload_);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string Message::serialize(){
|
||||
|
||||
std::string serializedMessage;
|
||||
if (msg.IsInitialized()) {
|
||||
serializedMessage = msg.SerializeAsString();
|
||||
}
|
||||
return serializedMessage;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
56
src/WHISPER/Messages/Track.cpp
Normal file
56
src/WHISPER/Messages/Track.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "WHISPER/Messages/Message.hpp"
|
||||
#include "WHISPER/Messages/Protos/raw_track.pb.h"
|
||||
#include <WHISPER/Messages/Track.hpp>
|
||||
#include <memory>
|
||||
|
||||
|
||||
|
||||
|
||||
namespace WHISPER {
|
||||
|
||||
RawTrack::RawTrack(std::string receivedMessage){
|
||||
msg = messages::header::Message();
|
||||
try {
|
||||
msg.ParseFromString(receivedMessage);
|
||||
topic_ = msg.topic();
|
||||
sourceType_ = msg.sourcetype();
|
||||
msgType_ = msg.msgtype();
|
||||
|
||||
trackMessage = messages::raw_track::RawTrack();
|
||||
|
||||
if ( msg.payload_size()) {
|
||||
if (msg.payload().begin()->Is<messages::raw_track::RawTrack>()) {
|
||||
msg.payload().begin()->UnpackTo(&trackMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
trackNo = trackMessage.trackno();
|
||||
|
||||
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
LOG_S(ERROR)<<e.what();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
RawTrack::RawTrack(std::uint32_t deviceID,WHISPER::MsgTopics topic, SourceType src,std::uint32_t trackNo):
|
||||
Message(deviceID,WHISPER::MsgTopics::TRACK,WHISPER::RAW_TRACK,src),trackNo(trackNo)
|
||||
{
|
||||
|
||||
trackMessage = messages::raw_track::RawTrack();
|
||||
trackMessage.set_trackno(trackNo);
|
||||
|
||||
auto payloadMessage = std::make_shared<google::protobuf::Any>();
|
||||
payloadMessage->PackFrom(trackMessage);
|
||||
addPayLoad(payloadMessage);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user