cmRtNet.h/c : Added cmRtNetRemote* functions, cmRtNeSendByIndex() and cmRtNetSyncMsgLabel().

This commit is contained in:
kpl 2014-06-14 20:40:46 -07:00
parent 983f7098fa
commit 3027a27302
2 changed files with 168 additions and 7 deletions

155
cmRtNet.c
View File

@ -14,9 +14,9 @@
// flags for cmRtNetNode_t.flags; // flags for cmRtNetNode_t.flags;
enum enum
{ {
kLocalNodeNetFl = 0x01, kLocalNodeNetFl = 0x01,
kValidNodeNetFl = 0x02 kValidNodeNetFl = 0x02
}; };
// flags for cmRtNet_t.flags // flags for cmRtNet_t.flags
enum enum
@ -335,6 +335,57 @@ cmRtNetRC_t _cmRtNetFree( cmRtNet_t* p )
return rc; return rc;
} }
const cmRtNetNode_t* _cmRtNetIndexToRemoteNode( cmRtNet_t* p, unsigned idx )
{
const cmRtNetNode_t* np = p->nodes;
unsigned i = 0;
for(; np!=NULL; np=np->link)
if( np != p->localNode )
{
if( i == idx )
return np;
++i;
}
return NULL;
}
const cmRtNetEnd_t* _cmRtNetIndexToEndpt( const cmRtNetNode_t* np, unsigned endIdx )
{
const cmRtNetEnd_t* ep = np->ends;
unsigned i = 0;
for(; ep!=NULL; ep=ep->link,++i)
if( i==endIdx )
return ep;
return NULL;
}
const cmRtNetEnd_t* _cmRtNetFindEndpt( cmRtNet_t* p, unsigned nodeIdx, unsigned epIdx )
{
const cmRtNetNode_t* np;
const cmRtNetEnd_t* ep;
if((np = _cmRtNetIndexToRemoteNode( p, nodeIdx )) == NULL )
return NULL;
if((ep = _cmRtNetIndexToEndpt( np, epIdx )) == NULL )
return NULL;
return ep;
}
const cmChar_t* cmRtNetSyncMsgLabel( const cmRtNetSyncMsg_t* m )
{
if( m->selId==kNodeSelNetId || m->selId==kEndpointSelNetId )
return (const cmChar_t*)(m+1);
return "";
}
cmRtNetRC_t cmRtNetAlloc( cmCtx_t* ctx, cmRtNetH_t* hp, cmUdpCallback_t cbFunc, void* cbArg ) cmRtNetRC_t cmRtNetAlloc( cmCtx_t* ctx, cmRtNetH_t* hp, cmUdpCallback_t cbFunc, void* cbArg )
{ {
cmRtNetRC_t rc; cmRtNetRC_t rc;
@ -718,13 +769,9 @@ cmRtNetRC_t cmRtNetEndpointHandle( cmRtNetH_t h, const cmChar_t* nodeLabel, unsi
return rc; return rc;
} }
cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, cmRtNetEndptH_t epH, const void* msg, unsigned msgByteCnt ) cmRtNetRC_t _cmRtNetSend( cmRtNet_t* p, const cmRtNetEnd_t* ep, const void* msg, unsigned msgByteCnt )
{ {
cmRtNetRC_t rc = kOkNetRC; cmRtNetRC_t rc = kOkNetRC;
cmRtNet_t* p = _cmRtNetHandleToPtr(h);
cmRtNetEnd_t* ep = (cmRtNetEnd_t*)epH.h;
assert( ep != NULL );
unsigned dN = sizeof(cmRtNetMsg_t) + msgByteCnt; unsigned dN = sizeof(cmRtNetMsg_t) + msgByteCnt;
char data[ dN ]; char data[ dN ];
@ -741,6 +788,16 @@ cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, cmRtNetEndptH_t epH, const void* msg, uns
return rc; return rc;
} }
cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, cmRtNetEndptH_t epH, const void* msg, unsigned msgByteCnt )
{
cmRtNet_t* p = _cmRtNetHandleToPtr(h);
cmRtNetEnd_t* ep = (cmRtNetEnd_t*)epH.h;
assert( ep != NULL );
return _cmRtNetSend(p,ep,msg,msgByteCnt);
}
cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, unsigned rtSubIdx, const cmChar_t* endptLabel, const void* msg, unsigned msgByteCnt ) cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, unsigned rtSubIdx, const cmChar_t* endptLabel, const void* msg, unsigned msgByteCnt )
{ {
cmRtNetRC_t rc = kOkNetRC; cmRtNetRC_t rc = kOkNetRC;
@ -752,6 +809,17 @@ cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, unsign
return cmRtNetSend(h,epH,msg,msgByteCnt); return cmRtNetSend(h,epH,msg,msgByteCnt);
} }
cmRtNetRC_t cmRtNetSendByIndex( cmRtNetH_t h, unsigned nodeIdx, unsigned endptIdx, const void* msg, unsigned msgByteCnt )
{
cmRtNet_t* p = _cmRtNetHandleToPtr(h);
const cmRtNetEnd_t* ep;
if((ep = _cmRtNetFindEndpt(p, nodeIdx, endptIdx )) == NULL )
return cmErrMsg(&p->err,kEndNotFoundNetRC,"The endpoint at node index %i endpoint index %i was not found.",nodeIdx,endptIdx);
return _cmRtNetSend( p, ep, msg, msgByteCnt );
}
bool cmRtNetReportSyncEnable( cmRtNetH_t h, bool enableFl ) bool cmRtNetReportSyncEnable( cmRtNetH_t h, bool enableFl )
@ -800,6 +868,79 @@ void cmRtNetReport( cmRtNetH_t h )
} }
} }
const cmChar_t* cmRtNetLocalNodeLabel( cmRtNetH_t h )
{
cmRtNet_t* p = _cmRtNetHandleToPtr( h );
return p->localNode->label;
}
unsigned cmRtNetRemoteNodeCount( cmRtNetH_t h )
{
cmRtNet_t* p = _cmRtNetHandleToPtr( h );
const cmRtNetNode_t* np = p->nodes;
unsigned n = 0;
for(; np!=NULL; np=np->link)
if( np != p->localNode )
++n;
return n;
}
const cmChar_t* cmRtNetRemoteNodeLabel( cmRtNetH_t h, unsigned idx )
{
cmRtNet_t* p = _cmRtNetHandleToPtr( h );
const cmRtNetNode_t* np;
if((np = _cmRtNetIndexToRemoteNode( p, idx )) == NULL )
return NULL;
return np->label;
}
unsigned cmRtNetRemoteNodeEndPointCount( cmRtNetH_t h, unsigned nodeIdx )
{
const cmRtNetNode_t* np;
const cmRtNetEnd_t* ep;
cmRtNet_t* p = _cmRtNetHandleToPtr( h );
unsigned n = 0;
if((np = _cmRtNetIndexToRemoteNode( p, nodeIdx )) == NULL )
return 0;
for(ep=np->ends; ep!=NULL; ep=ep->link)
++n;
return n;
}
cmRtNetRC_t cmRtNetRemoteNodeEndPoint(
cmRtNetH_t h,
unsigned nodeIdx,
unsigned epIdx,
const cmChar_t** labelRef,
unsigned* idRef,
unsigned* rsiRef )
{
const cmRtNetEnd_t* ep;
cmRtNet_t* p = _cmRtNetHandleToPtr( h );
if(( ep = _cmRtNetFindEndpt(p, nodeIdx, epIdx )) == NULL )
{
*labelRef = NULL;
*idRef = cmInvalidId;
*rsiRef = cmInvalidIdx;
return kEndNotFoundNetRC;
}
*labelRef = ep->label;
*idRef = ep->id;
*rsiRef = ep->rtSubIdx;
return kOkNetRC;
}
//========================================================================== //==========================================================================
#include "cmThread.h" #include "cmThread.h"

View File

@ -53,6 +53,9 @@ extern "C" {
const cmChar_t* label; // node or endpoint label const cmChar_t* label; // node or endpoint label
} cmRtNetSyncMsg_t; } cmRtNetSyncMsg_t;
const cmChar_t* cmRtNetSyncMsgLabel( const cmRtNetSyncMsg_t* m );
// NOTE: Messages passed between cmRtNet nodes during the synchronization // NOTE: Messages passed between cmRtNet nodes during the synchronization
// process use the cmRtNetSyncMsg_t format (w/ the body of label following // process use the cmRtNetSyncMsg_t format (w/ the body of label following
// the record. All other messages use cmRtNetMsg_t (cmRtSysMsg.h) format. // the record. All other messages use cmRtNetMsg_t (cmRtSysMsg.h) format.
@ -107,13 +110,30 @@ extern "C" {
// of cmRtNetEndpointHandle() and cmRtNetSend(). // of cmRtNetEndpointHandle() and cmRtNetSend().
cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, unsigned rtSubIdx, const cmChar_t* endptLabel, const void* msg, unsigned msgByteCnt ); cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, unsigned rtSubIdx, const cmChar_t* endptLabel, const void* msg, unsigned msgByteCnt );
cmRtNetRC_t cmRtNetSendByIndex( cmRtNetH_t h, unsigned nodeIdx, unsigned endptIdx, const void* msg, unsigned msgByteCnt );
// Enable/disable synchronization protocol reporting. // Enable/disable synchronization protocol reporting.
// Return the previous state of the report sync. flag. // Return the previous state of the report sync. flag.
bool cmRtNetReportSyncEnable( cmRtNetH_t h, bool enableFl ); bool cmRtNetReportSyncEnable( cmRtNetH_t h, bool enableFl );
bool cmRtNetReportSyncIsEnabled( cmRtNetH_t h ); bool cmRtNetReportSyncIsEnabled( cmRtNetH_t h );
// Query network configuration. Returns true on success or false if
// {nodeIdx, epIdx} does not identify a valid endpoint.
const cmChar_t* cmRtNetLocalNodeLabel( cmRtNetH_t h );
unsigned cmRtNetRemoteNodeCount( cmRtNetH_t h );
const cmChar_t* cmRtNetRemoteNodeLabel( cmRtNetH_t h, unsigned idx );
unsigned cmRtNetRemoteNodeEndPointCount( cmRtNetH_t h, unsigned nodeIdx );
cmRtNetRC_t cmRtNetRemoteNodeEndPoint(
cmRtNetH_t h,
unsigned nodeIdx,
unsigned epIdx,
const cmChar_t** labelRef,
unsigned* idRef,
unsigned* rsiRef );
void cmRtNetReport( cmRtNetH_t h ); void cmRtNetReport( cmRtNetH_t h );
void cmRtNetTest( cmCtx_t* ctx, bool mstrFl ); void cmRtNetTest( cmCtx_t* ctx, bool mstrFl );
/* /*