cmRtNet.h/c: Added cmRtNetTest().

This commit is contained in:
kevin 2013-04-26 13:04:26 -07:00
parent 6552c90322
commit 75f3882a61
2 changed files with 119 additions and 8 deletions

View File

@ -74,7 +74,7 @@ typedef struct
typedef struct
{
cmRtSysMsgHdr_t hdr;
cmRtNetSelId_t selId;
cmRtNetSelId_t selId;
const cmChar_t* endPtLabel;
unsigned endPtId;
} cmRtNetSyncMsg_t;
@ -703,6 +703,13 @@ cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h )
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 )
{
//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;
}

View File

@ -52,12 +52,13 @@ extern "C" {
// Go into 'sync' node.
// When a node enters sync mode it systematically transmits all of it's local endpoint
// information to each registered remote node. Prior to entering sync mode a node
// must therefore have been setup with a list of remote nodes (via cmRtNetCreateNode())
// and a list of local endpoints (cmRtNetRegisterEndpoint()).
// During sync mode a node sends it's local endpoint list to each registered remote node.
// When a remote node receives an endpoint it updates it's own remote node/endpoint
// When a node enters sync mode it systematically transmits all of it's
// local endpoint information to each registered remote node. Prior to
// entering sync mode a node must therefore have been setup with a list
// of remote nodes (via cmRtNetCreateNode()) and a list of local endpoints
// (cmRtNetRegisterEndpoint()). During sync mode a node sends it's local
// endpoint list to each registered remote node. When a remote node receives
// an endpoint it updates it's own remote node/endpoint
// list.
cmRtNetRC_t cmRtNetBeginSyncMode( cmRtNetH_t h );
bool cmRtNetIsInSyncMode( cmRtNetH_t h );
@ -77,6 +78,8 @@ extern "C" {
// via the callback funcion 'cbFunc' as passed to cmRtNetAlloc()
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 );
@ -84,7 +87,25 @@ extern "C" {
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
}