cmRtNet.h/c : Added hdrByteCnt field to cmRtNetSyncMsg_t. Updated _cmRtNetDeserializeSyncMsg()
to use cmRtNetSyncMsg_t.hdrByteCnt.
This commit is contained in:
parent
6815dd3570
commit
51a0d5c006
10
cmRtNet.c
10
cmRtNet.c
@ -263,7 +263,9 @@ unsigned _cmRtNetNodeEndpointCount( cmRtNetNode_t* np )
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned _cmRtNetSyncMsgSerialByteCount( const cmRtNetSyncMsg_t* m )
|
unsigned _cmRtNetSyncMsgSerialByteCount( const cmRtNetSyncMsg_t* m )
|
||||||
{ return sizeof(cmRtNetSyncMsg_t) + (m->label==NULL ? 1 : strlen(m->label) + 1); }
|
{
|
||||||
|
return sizeof(cmRtNetSyncMsg_t) + (m->label==NULL ? 1 : strlen(m->label) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
cmRtNetRC_t _cmRtNetSerializeSyncMsg( cmRtNet_t* p, const cmRtNetSyncMsg_t* m, void* buf, unsigned n )
|
cmRtNetRC_t _cmRtNetSerializeSyncMsg( cmRtNet_t* p, const cmRtNetSyncMsg_t* m, void* buf, unsigned n )
|
||||||
{
|
{
|
||||||
@ -283,7 +285,7 @@ cmRtNetRC_t _cmRtNetDeserializeSyncMsg( const void* buf, unsigned n, cmRtNetSync
|
|||||||
assert( n > sizeof(*m));
|
assert( n > sizeof(*m));
|
||||||
memcpy(m,buf,sizeof(*m));
|
memcpy(m,buf,sizeof(*m));
|
||||||
const cmRtNetSyncMsg_t* mp = (const cmRtNetSyncMsg_t*)buf;
|
const cmRtNetSyncMsg_t* mp = (const cmRtNetSyncMsg_t*)buf;
|
||||||
const cmChar_t* s = (const cmChar_t*)(mp+1);
|
const cmChar_t* s = ((const cmChar_t*)(mp)) + mp->hdrByteCnt;
|
||||||
m->label = cmMemAllocStr(s);
|
m->label = cmMemAllocStr(s);
|
||||||
return kOkNetRC;
|
return kOkNetRC;
|
||||||
}
|
}
|
||||||
@ -297,6 +299,7 @@ cmRtNetRC_t _cmRtNetSendSyncMsg( cmRtNet_t* p, cmRtNetNode_t* np, cmRtNetSelId_t
|
|||||||
m.hdr.rtSubIdx = cmInvalidIdx;
|
m.hdr.rtSubIdx = cmInvalidIdx;
|
||||||
m.hdr.selId = kNetSyncSelRtId;
|
m.hdr.selId = kNetSyncSelRtId;
|
||||||
m.selId = selId;
|
m.selId = selId;
|
||||||
|
m.hdrByteCnt = sizeof(cmRtNetSyncMsg_t);
|
||||||
m.label = msgLabel;
|
m.label = msgLabel;
|
||||||
m.id = msgId;
|
m.id = msgId;
|
||||||
m.rtSubIdx = msgRtSubIdx;
|
m.rtSubIdx = msgRtSubIdx;
|
||||||
@ -524,7 +527,7 @@ cmRtNetRC_t _cmRtNetSendEndpointReplyMsg( cmRtNet_t* p, cmRtNetNode_t* np, cmRt
|
|||||||
bool _cmRtNetIsSyncModeMsg( const void* data, unsigned dataByteCnt )
|
bool _cmRtNetIsSyncModeMsg( const void* data, unsigned dataByteCnt )
|
||||||
{
|
{
|
||||||
cmRtNetSyncMsg_t* m = (cmRtNetSyncMsg_t*)data;
|
cmRtNetSyncMsg_t* m = (cmRtNetSyncMsg_t*)data;
|
||||||
return dataByteCnt >= sizeof(cmRtNetSyncMsg_t) && m->hdr.selId == kNetSyncSelRtId;
|
return dataByteCnt >= sizeof(cmRtSysMsgHdr_t) && m->hdr.selId == kNetSyncSelRtId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When the network message recieve function (See cmRtNetAlloc() 'cbFunc')
|
// When the network message recieve function (See cmRtNetAlloc() 'cbFunc')
|
||||||
@ -673,7 +676,6 @@ void _cmRtNetRecv( void* cbArg, const char* data, unsigned dataByteCnt, const st
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// All non-sync messages arriving here are prefixed by a cmRtNetMsg_t header - fill in the source addr here.
|
// All non-sync messages arriving here are prefixed by a cmRtNetMsg_t header - fill in the source addr here.
|
||||||
|
|
||||||
// NOTE: the source addr could be filled in by the sender but this would increase the size
|
// NOTE: the source addr could be filled in by the sender but this would increase the size
|
||||||
// of the msg. Instead we choose the more time consuming method of looking up the
|
// of the msg. Instead we choose the more time consuming method of looking up the
|
||||||
// soure node here - hmmmm????.
|
// soure node here - hmmmm????.
|
||||||
|
@ -63,6 +63,7 @@ extern "C" {
|
|||||||
{
|
{
|
||||||
cmRtSysMsgHdr_t hdr; // standard cmRtSys msg header
|
cmRtSysMsgHdr_t hdr; // standard cmRtSys msg header
|
||||||
cmRtNetSelId_t selId; // message selector id (See kXXXSelNetId above)
|
cmRtNetSelId_t selId; // message selector id (See kXXXSelNetId above)
|
||||||
|
unsigned hdrByteCnt; // size of the header record at transmission (used to locate the serialzed label)
|
||||||
unsigned rtSubIdx; // cmInvalidIdx or rtSubIdx
|
unsigned rtSubIdx; // cmInvalidIdx or rtSubIdx
|
||||||
unsigned id; // endptCnt or endpoint id
|
unsigned id; // endptCnt or endpoint id
|
||||||
const cmChar_t* label; // node or endpoint label
|
const cmChar_t* label; // node or endpoint label
|
||||||
|
Loading…
Reference in New Issue
Block a user