3 namespace remote
{ namespace protocols
{ namespace host_server
{
5 HostMsg::HostMsg(MsgPlugEvent
& message
)
6 : protocolVersion(HOST_SERVER_PROTOCOL_VERSION
),
7 type(HOSTMSGTYPE_PLUGEVENT
),
13 HostMsg::HostMsg(MsgHostRequest
& message
)
14 : protocolVersion(HOST_SERVER_PROTOCOL_VERSION
),
15 type(HOSTMSGTYPE_HOSTREQUEST
),
21 HostMsg::HostMsg(MsgHostConfirm
& message
)
22 : protocolVersion(HOST_SERVER_PROTOCOL_VERSION
),
23 type(HOSTMSGTYPE_HOSTCONFIRM
),
29 HostMsg::HostMsg(uint8_t*& buffer
, uint32_t& buflen
)
31 buffer
= this->read(buffer
,buflen
);
37 if (deleteMsg
) { delete this->message
; }
40 uint32_t HostMsg::getLength()
42 return sizeof(type
) + sizeof(protocolVersion
) + message
->getLength();
45 uint8_t* HostMsg::write(uint8_t* buffer
, uint32_t& buflen
)
47 buffer
= writevalue(protocolVersion
,buffer
,buflen
);
48 buffer
= writevalue(type
,buffer
,buflen
);
49 buffer
= message
->write(buffer
,buflen
);
53 void HostMsg::print(FILE* s
)
55 fprintf(s
,"MESSAGE HostMsg\n");
56 fprintf(s
,"protocolVersion: %u\n",protocolVersion
);
60 case HOSTMSGTYPE_PLUGEVENT
:
61 fprintf(s
,"HOSTMSGTYPE_PLUGEVENT\n");
63 case HOSTMSGTYPE_HOSTREQUEST
:
64 fprintf(s
,"HOSTMSGTYPE_HOSTMOTE\n");
67 fprintf(s
,"Invalid type\n");
73 uint8_t* HostMsg::read(uint8_t* buffer
, uint32_t& buflen
)
75 buffer
= readvalue(protocolVersion
,buffer
,buflen
);
76 if (protocolVersion
!= HOST_SERVER_PROTOCOL_VERSION
)
78 __THROW__("Host/Server protocol version conflict!");
80 buffer
= readvalue(type
,buffer
,buflen
);
83 case HOSTMSGTYPE_PLUGEVENT
:
84 message
= new MsgPlugEvent(buffer
,buflen
);
86 case HOSTMSGTYPE_HOSTREQUEST
:
87 message
= new MsgHostRequest(buffer
,buflen
);
89 case HOSTMSGTYPE_HOSTCONFIRM
:
90 message
= new MsgHostConfirm(buffer
,buflen
);
93 __THROW__("Unknown type of HostMsg!");
99 uint32_t HostMsg::getProtocolVersion()
101 return protocolVersion
;
104 uint8_t HostMsg::getType()
109 MsgHostRequest
& HostMsg::getHostRequest()
111 if (type
!= HOSTMSGTYPE_HOSTREQUEST
)
112 __THROW__ ("Cannot get MsgHostRequest when type is not HOSTMSGTYPE_HOSTREQUEST!");
113 return *((MsgHostRequest
*)message
);
116 MsgHostConfirm
& HostMsg::getHostConfirm()
118 if (type
!= HOSTMSGTYPE_HOSTCONFIRM
)
119 __THROW__ ("Cannot get MsgHostConfirm when type is not HOSTMSGTYPE_HOSTCONFIRM!");
120 return *((MsgHostConfirm
*)message
);
123 MsgPlugEvent
& HostMsg::getPlugEvent()
125 if (type
!= HOSTMSGTYPE_PLUGEVENT
)
126 __THROW__ ("Cannot get plugevent when type is not HOST_PLUGEVENT!");
127 return *((MsgPlugEvent
*)message
);