cmRtNet.h/c: Added cmRtNetTest().
This commit is contained in:
parent
6552c90322
commit
75f3882a61
92
cmRtNet.c
92
cmRtNet.c
@ -74,7 +74,7 @@ typedef struct
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
cmRtSysMsgHdr_t hdr;
|
cmRtSysMsgHdr_t hdr;
|
||||||
cmRtNetSelId_t selId;
|
cmRtNetSelId_t selId;
|
||||||
const cmChar_t* endPtLabel;
|
const cmChar_t* endPtLabel;
|
||||||
unsigned endPtId;
|
unsigned endPtId;
|
||||||
} cmRtNetSyncMsg_t;
|
} cmRtNetSyncMsg_t;
|
||||||
@ -703,6 +703,13 @@ cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h )
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cmRtNetIsSyncModeMsg( const void* data, unsigned dataByteCnt )
|
||||||
|
{
|
||||||
|
cmRtNetSyncMsg_t* m = (cmRtNetSyncMsg_t*)data;
|
||||||
|
return dataByteCnt >= sizeof(cmRtNetSyncMsg_t) && m->hdr.selId == kNetSyncSelRtId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned cmRtNetEndPointIndex( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endPtLabel )
|
unsigned cmRtNetEndPointIndex( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endPtLabel )
|
||||||
{
|
{
|
||||||
//cmRtNet_t* p = _cmRtNetHandleToPtr(h);
|
//cmRtNet_t* p = _cmRtNetHandleToPtr(h);
|
||||||
@ -749,3 +756,86 @@ void cmRtNetReport( cmRtNetH_t h )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
cmThreadH_t thH;
|
||||||
|
cmRtNetH_t netH;
|
||||||
|
} _cmRtNetTest_t;
|
||||||
|
|
||||||
|
void _cmRtNetTestRecv( void* cbArg, const char* data, unsigned dataByteCnt, const struct sockaddr_in* fromAddr )
|
||||||
|
{
|
||||||
|
_cmRtNetTest_t* p = (_cmrtNetTest_t*)cbArg;
|
||||||
|
|
||||||
|
if( cmRtNetIsSyncModeMsg(data,dataByteCnt))
|
||||||
|
cmRtNetSyncModeRecv(p->netH,data,dataByteCnt,fromAddr);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool _cmRtNetTestThreadFunc(void* param)
|
||||||
|
{
|
||||||
|
_cmrtNetTest_t* p = (_cmRtNetTest_t*)param;
|
||||||
|
|
||||||
|
|
||||||
|
if( cmRtNetIsValid(p->netH) && cmRtNetIsInSyncMode(p->netH) )
|
||||||
|
cmRtNetSyncModeSend(p->netH);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmRtNetTest( cmCtx_t* ctx, bool mstrFl )
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
_cmRtNetTest_t t;
|
||||||
|
cmUdpPort_t port = 5867;
|
||||||
|
_cmRtNetTest_t* p = &t;
|
||||||
|
cmRtNetRC_t rc = kOkNetRC;
|
||||||
|
memset(&t,0,sizeof(t));
|
||||||
|
|
||||||
|
if( cmThreadCreate(&p->thH,_cmRtNetTestThreadFunc,p,&ctx->rpt) != kOkThRC )
|
||||||
|
goto errLabel;
|
||||||
|
|
||||||
|
if((rc = cmRtNetAlloc(ctx,&p->netH,p)) != kOkNetRC )
|
||||||
|
goto errLabel;
|
||||||
|
|
||||||
|
if((rc = cmRtNetCreateNode(p->netH, "local", NULL, port )) != kOkNetRC)
|
||||||
|
goto errLabel;
|
||||||
|
|
||||||
|
if( mstrFl )
|
||||||
|
{
|
||||||
|
if((rc = cmRtNetCreate(p->netH,"whirl", "192.168.15.109", port )) != kOkNetRC )
|
||||||
|
goto errLabel;
|
||||||
|
|
||||||
|
if((rc = cmRtNetEndPoint(p->netH,"thunk_ep0", 0 )) != kOkNetRC )
|
||||||
|
goto errLabel;
|
||||||
|
|
||||||
|
if(( rc = cmRtNetBeginSyncMode(p->netH)) != kOkNetRC )
|
||||||
|
goto errLabel;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if((rc = cmRtNetEndPoint(p->netH,"whirl_ep0", 0 )) != kOkNetRC )
|
||||||
|
goto errLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( cmThreadPause(p->thH,0) != kOkThRC )
|
||||||
|
goto errLabel;
|
||||||
|
|
||||||
|
while( (c=getchar()) != 'q' )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
errLabel:
|
||||||
|
|
||||||
|
cmRtNetFree(&p->netH);
|
||||||
|
|
||||||
|
cmThreadDestroy(&p->thH);
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
33
cmRtNet.h
33
cmRtNet.h
@ -52,12 +52,13 @@ extern "C" {
|
|||||||
|
|
||||||
|
|
||||||
// Go into 'sync' node.
|
// Go into 'sync' node.
|
||||||
// When a node enters sync mode it systematically transmits all of it's local endpoint
|
// When a node enters sync mode it systematically transmits all of it's
|
||||||
// information to each registered remote node. Prior to entering sync mode a node
|
// local endpoint information to each registered remote node. Prior to
|
||||||
// must therefore have been setup with a list of remote nodes (via cmRtNetCreateNode())
|
// entering sync mode a node must therefore have been setup with a list
|
||||||
// and a list of local endpoints (cmRtNetRegisterEndpoint()).
|
// of remote nodes (via cmRtNetCreateNode()) and a list of local endpoints
|
||||||
// During sync mode a node sends it's local endpoint list to each registered remote node.
|
// (cmRtNetRegisterEndpoint()). During sync mode a node sends it's local
|
||||||
// When a remote node receives an endpoint it updates it's own remote node/endpoint
|
// endpoint list to each registered remote node. When a remote node receives
|
||||||
|
// an endpoint it updates it's own remote node/endpoint
|
||||||
// list.
|
// list.
|
||||||
cmRtNetRC_t cmRtNetBeginSyncMode( cmRtNetH_t h );
|
cmRtNetRC_t cmRtNetBeginSyncMode( cmRtNetH_t h );
|
||||||
bool cmRtNetIsInSyncMode( cmRtNetH_t h );
|
bool cmRtNetIsInSyncMode( cmRtNetH_t h );
|
||||||
@ -77,6 +78,8 @@ extern "C" {
|
|||||||
// via the callback funcion 'cbFunc' as passed to cmRtNetAlloc()
|
// via the callback funcion 'cbFunc' as passed to cmRtNetAlloc()
|
||||||
cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h );
|
cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h );
|
||||||
|
|
||||||
|
bool cmRtNetIsSyncModeMsg( const void* data, unsigned dataByteCnt );
|
||||||
|
|
||||||
unsigned cmRtNetEndPointIndex( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endPtLabel );
|
unsigned cmRtNetEndPointIndex( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endPtLabel );
|
||||||
|
|
||||||
|
|
||||||
@ -84,7 +87,25 @@ extern "C" {
|
|||||||
|
|
||||||
void cmRtNetReport( cmRtNetH_t h );
|
void cmRtNetReport( cmRtNetH_t h );
|
||||||
|
|
||||||
|
void cmRtNetTest( cmCtx_t* ctx );
|
||||||
|
|
||||||
|
/*
|
||||||
|
Master:
|
||||||
|
cmRtNetBeginSyncMode().
|
||||||
|
while( cmRtNetIsSyncMode())
|
||||||
|
{
|
||||||
|
// Give the master an oppurtunity to advance it's sync mode state.
|
||||||
|
// When the master is has sync'd with all remote nodes in it's
|
||||||
|
// remote node list then it will automatically exit sync mode.
|
||||||
|
cmRtNetSyncModeSend()
|
||||||
|
}
|
||||||
|
|
||||||
|
_myNetRecv(dataV,dataN,addr)
|
||||||
|
{
|
||||||
|
if( cmRtNetIsSyncModeMsg(dataV,dataN) )
|
||||||
|
cmRtNetSyncModeRecv(dataV,dataN,addr)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user