1 #ifndef INCLUDE_COMMUNICATION_MSG_H_
2 #define INCLUDE_COMMUNICATION_MSG_H_
5 #include <glog/logging.h>
20 virtual void set_src(
int first,
int second,
int flag)=0;
21 virtual void set_dst(
int first,
int second,
int flag)=0;
22 virtual void set_src(
int procs_id,
int flag)=0;
23 virtual void set_dst(
int procs_id,
int flag)=0;
24 virtual int src_first()
const=0;
25 virtual int dst_first()
const=0;
26 virtual int src_second()
const=0;
27 virtual int dst_second()
const=0;
28 virtual int src_flag()
const=0;
29 virtual int dst_flag()
const=0;
30 virtual void set_type(
int type)=0;
31 virtual int type()
const=0;
32 virtual void set_target(
int first,
int second)=0;
33 virtual int target_first()
const=0;
34 virtual int target_second()
const=0;
40 virtual void SetAddr(
BaseMsg* msg)=0;
45 virtual void add_frame(
const void*,
int nBytes)=0;
46 virtual int frame_size()=0;
47 virtual void* frame_data()=0;
68 virtual void set_src(
int first,
int second,
int flag){
69 src_=(first<<kOff1)|(second<<kOff2)|flag;
71 virtual void set_dst(
int first,
int second,
int flag){
72 dst_=(first<<kOff1)|(second<<kOff2)|flag;
74 virtual void set_src(
int procs_id,
int flag){
77 virtual void set_dst(
int procs_id,
int flag){
78 set_dst(procs_id, 0, flag);
86 virtual int src_first()
const {
91 virtual int dst_first()
const{
95 virtual int src_second()
const{
96 int ret=(src_&kMask1)>>kOff2;
99 virtual int dst_second()
const{
100 int ret=(dst_&kMask1)>>kOff2;
103 virtual int src_flag()
const{
107 virtual int dst_flag()
const{
113 std::swap(src_,dst_);
116 virtual void set_type(
int type){
119 virtual int type()
const{
123 virtual void set_target(
int first,
int second){
125 target_second_=second;
127 virtual int target_first()
const{
128 return target_first_;
130 virtual int target_second()
const{
131 return target_second_;
141 virtual void SetAddr(
BaseMsg* msg){
142 src_=(
static_cast<Msg*
>(msg))->src_;
143 dst_=(
static_cast<Msg*
>(msg))->dst_;
147 zmsg_addmem(msg_, addr, nBytes);
149 virtual int frame_size(){
150 return zframe_size(frame_);
153 virtual void* frame_data(){
154 return zframe_data(frame_);
158 frame_=zmsg_next(msg_);
162 void ParseFromZmsg(zmsg_t* msg){
163 char* tmp=zmsg_popstr(msg);
164 sscanf(tmp,
"%d %d %d %d %d",
165 &src_, &dst_, &type_, &target_first_, &target_second_);
167 frame_=zmsg_next(msg);
171 zmsg_t* DumpToZmsg(){
172 zmsg_pushstrf(msg_,
"%d %d %d %d %d",
173 src_, dst_, type_, target_first_, target_second_);
181 static const unsigned int kOff1=16, kOff2=4;
182 static const unsigned int kMask1=(1<<kOff1)-1, kMask2=(1<<kOff2)-1;
184 int type_, target_first_, target_second_;
192 #endif // INCLUDE_COMMUNICATION_MSG_H_
virtual bool next_frame()
Move the cursor to the next frame.
Definition: msg.h:157
virtual ~BaseMsg()
Destructor to free memory.
Definition: msg.h:14
virtual bool next_frame()=0
Move the cursor to the next frame.
virtual void set_src(int first, int second, int flag)=0
virtual BaseMsg * CopyAddr()=0
Copy src and dst address, including first, id, flag.
virtual void add_frame(const void *, int nBytes)=0
Add a frame (a chunck of bytes) into the message.
virtual void set_src(int first, int second, int flag)
Definition: msg.h:68
virtual void add_frame(const void *addr, int nBytes)
Add a frame (a chunck of bytes) into the message.
Definition: msg.h:146
virtual BaseMsg * CopyAddr()
Copy src and dst address, including first, id, flag.
Definition: msg.h:134