|
@@ -14,9 +14,9 @@
|
14
|
14
|
// flags for cmRtNetNode_t.flags;
|
15
|
15
|
enum
|
16
|
16
|
{
|
17
|
|
- kLocalNodeNetFl = 0x01,
|
|
17
|
+kLocalNodeNetFl = 0x01,
|
18
|
18
|
kValidNodeNetFl = 0x02
|
19
|
|
-};
|
|
19
|
+ };
|
20
|
20
|
|
21
|
21
|
// flags for cmRtNet_t.flags
|
22
|
22
|
enum
|
|
@@ -335,6 +335,57 @@ cmRtNetRC_t _cmRtNetFree( cmRtNet_t* p )
|
335
|
335
|
return rc;
|
336
|
336
|
}
|
337
|
337
|
|
|
338
|
+const cmRtNetNode_t* _cmRtNetIndexToRemoteNode( cmRtNet_t* p, unsigned idx )
|
|
339
|
+{
|
|
340
|
+ const cmRtNetNode_t* np = p->nodes;
|
|
341
|
+ unsigned i = 0;
|
|
342
|
+
|
|
343
|
+ for(; np!=NULL; np=np->link)
|
|
344
|
+ if( np != p->localNode )
|
|
345
|
+ {
|
|
346
|
+ if( i == idx )
|
|
347
|
+ return np;
|
|
348
|
+ ++i;
|
|
349
|
+ }
|
|
350
|
+
|
|
351
|
+ return NULL;
|
|
352
|
+}
|
|
353
|
+
|
|
354
|
+const cmRtNetEnd_t* _cmRtNetIndexToEndpt( const cmRtNetNode_t* np, unsigned endIdx )
|
|
355
|
+{
|
|
356
|
+ const cmRtNetEnd_t* ep = np->ends;
|
|
357
|
+ unsigned i = 0;
|
|
358
|
+
|
|
359
|
+ for(; ep!=NULL; ep=ep->link,++i)
|
|
360
|
+ if( i==endIdx )
|
|
361
|
+ return ep;
|
|
362
|
+
|
|
363
|
+ return NULL;
|
|
364
|
+}
|
|
365
|
+
|
|
366
|
+const cmRtNetEnd_t* _cmRtNetFindEndpt( cmRtNet_t* p, unsigned nodeIdx, unsigned epIdx )
|
|
367
|
+{
|
|
368
|
+ const cmRtNetNode_t* np;
|
|
369
|
+ const cmRtNetEnd_t* ep;
|
|
370
|
+
|
|
371
|
+ if((np = _cmRtNetIndexToRemoteNode( p, nodeIdx )) == NULL )
|
|
372
|
+ return NULL;
|
|
373
|
+
|
|
374
|
+ if((ep = _cmRtNetIndexToEndpt( np, epIdx )) == NULL )
|
|
375
|
+ return NULL;
|
|
376
|
+
|
|
377
|
+ return ep;
|
|
378
|
+}
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+const cmChar_t* cmRtNetSyncMsgLabel( const cmRtNetSyncMsg_t* m )
|
|
382
|
+{
|
|
383
|
+ if( m->selId==kNodeSelNetId || m->selId==kEndpointSelNetId )
|
|
384
|
+ return (const cmChar_t*)(m+1);
|
|
385
|
+
|
|
386
|
+ return "";
|
|
387
|
+}
|
|
388
|
+
|
338
|
389
|
cmRtNetRC_t cmRtNetAlloc( cmCtx_t* ctx, cmRtNetH_t* hp, cmUdpCallback_t cbFunc, void* cbArg )
|
339
|
390
|
{
|
340
|
391
|
cmRtNetRC_t rc;
|
|
@@ -718,13 +769,9 @@ cmRtNetRC_t cmRtNetEndpointHandle( cmRtNetH_t h, const cmChar_t* nodeLabel, unsi
|
718
|
769
|
return rc;
|
719
|
770
|
}
|
720
|
771
|
|
721
|
|
-cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, cmRtNetEndptH_t epH, const void* msg, unsigned msgByteCnt )
|
|
772
|
+cmRtNetRC_t _cmRtNetSend( cmRtNet_t* p, const cmRtNetEnd_t* ep, const void* msg, unsigned msgByteCnt )
|
722
|
773
|
{
|
723
|
774
|
cmRtNetRC_t rc = kOkNetRC;
|
724
|
|
- cmRtNet_t* p = _cmRtNetHandleToPtr(h);
|
725
|
|
- cmRtNetEnd_t* ep = (cmRtNetEnd_t*)epH.h;
|
726
|
|
-
|
727
|
|
- assert( ep != NULL );
|
728
|
775
|
|
729
|
776
|
unsigned dN = sizeof(cmRtNetMsg_t) + msgByteCnt;
|
730
|
777
|
char data[ dN ];
|
|
@@ -741,6 +788,16 @@ cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, cmRtNetEndptH_t epH, const void* msg, uns
|
741
|
788
|
return rc;
|
742
|
789
|
}
|
743
|
790
|
|
|
791
|
+cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, cmRtNetEndptH_t epH, const void* msg, unsigned msgByteCnt )
|
|
792
|
+{
|
|
793
|
+ cmRtNet_t* p = _cmRtNetHandleToPtr(h);
|
|
794
|
+ cmRtNetEnd_t* ep = (cmRtNetEnd_t*)epH.h;
|
|
795
|
+
|
|
796
|
+ assert( ep != NULL );
|
|
797
|
+ return _cmRtNetSend(p,ep,msg,msgByteCnt);
|
|
798
|
+}
|
|
799
|
+
|
|
800
|
+
|
744
|
801
|
cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, unsigned rtSubIdx, const cmChar_t* endptLabel, const void* msg, unsigned msgByteCnt )
|
745
|
802
|
{
|
746
|
803
|
cmRtNetRC_t rc = kOkNetRC;
|
|
@@ -752,6 +809,17 @@ cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, unsign
|
752
|
809
|
return cmRtNetSend(h,epH,msg,msgByteCnt);
|
753
|
810
|
}
|
754
|
811
|
|
|
812
|
+cmRtNetRC_t cmRtNetSendByIndex( cmRtNetH_t h, unsigned nodeIdx, unsigned endptIdx, const void* msg, unsigned msgByteCnt )
|
|
813
|
+{
|
|
814
|
+ cmRtNet_t* p = _cmRtNetHandleToPtr(h);
|
|
815
|
+
|
|
816
|
+ const cmRtNetEnd_t* ep;
|
|
817
|
+
|
|
818
|
+ if((ep = _cmRtNetFindEndpt(p, nodeIdx, endptIdx )) == NULL )
|
|
819
|
+ return cmErrMsg(&p->err,kEndNotFoundNetRC,"The endpoint at node index %i endpoint index %i was not found.",nodeIdx,endptIdx);
|
|
820
|
+
|
|
821
|
+ return _cmRtNetSend( p, ep, msg, msgByteCnt );
|
|
822
|
+}
|
755
|
823
|
|
756
|
824
|
|
757
|
825
|
bool cmRtNetReportSyncEnable( cmRtNetH_t h, bool enableFl )
|
|
@@ -800,6 +868,79 @@ void cmRtNetReport( cmRtNetH_t h )
|
800
|
868
|
}
|
801
|
869
|
}
|
802
|
870
|
|
|
871
|
+const cmChar_t* cmRtNetLocalNodeLabel( cmRtNetH_t h )
|
|
872
|
+{
|
|
873
|
+ cmRtNet_t* p = _cmRtNetHandleToPtr( h );
|
|
874
|
+ return p->localNode->label;
|
|
875
|
+}
|
|
876
|
+
|
|
877
|
+unsigned cmRtNetRemoteNodeCount( cmRtNetH_t h )
|
|
878
|
+{
|
|
879
|
+ cmRtNet_t* p = _cmRtNetHandleToPtr( h );
|
|
880
|
+ const cmRtNetNode_t* np = p->nodes;
|
|
881
|
+ unsigned n = 0;
|
|
882
|
+
|
|
883
|
+ for(; np!=NULL; np=np->link)
|
|
884
|
+ if( np != p->localNode )
|
|
885
|
+ ++n;
|
|
886
|
+
|
|
887
|
+ return n;
|
|
888
|
+}
|
|
889
|
+
|
|
890
|
+const cmChar_t* cmRtNetRemoteNodeLabel( cmRtNetH_t h, unsigned idx )
|
|
891
|
+{
|
|
892
|
+ cmRtNet_t* p = _cmRtNetHandleToPtr( h );
|
|
893
|
+ const cmRtNetNode_t* np;
|
|
894
|
+
|
|
895
|
+ if((np = _cmRtNetIndexToRemoteNode( p, idx )) == NULL )
|
|
896
|
+ return NULL;
|
|
897
|
+
|
|
898
|
+ return np->label;
|
|
899
|
+}
|
|
900
|
+
|
|
901
|
+unsigned cmRtNetRemoteNodeEndPointCount( cmRtNetH_t h, unsigned nodeIdx )
|
|
902
|
+{
|
|
903
|
+ const cmRtNetNode_t* np;
|
|
904
|
+ const cmRtNetEnd_t* ep;
|
|
905
|
+ cmRtNet_t* p = _cmRtNetHandleToPtr( h );
|
|
906
|
+ unsigned n = 0;
|
|
907
|
+
|
|
908
|
+ if((np = _cmRtNetIndexToRemoteNode( p, nodeIdx )) == NULL )
|
|
909
|
+ return 0;
|
|
910
|
+
|
|
911
|
+ for(ep=np->ends; ep!=NULL; ep=ep->link)
|
|
912
|
+ ++n;
|
|
913
|
+
|
|
914
|
+ return n;
|
|
915
|
+}
|
|
916
|
+
|
|
917
|
+cmRtNetRC_t cmRtNetRemoteNodeEndPoint(
|
|
918
|
+ cmRtNetH_t h,
|
|
919
|
+ unsigned nodeIdx,
|
|
920
|
+ unsigned epIdx,
|
|
921
|
+ const cmChar_t** labelRef,
|
|
922
|
+ unsigned* idRef,
|
|
923
|
+ unsigned* rsiRef )
|
|
924
|
+{
|
|
925
|
+ const cmRtNetEnd_t* ep;
|
|
926
|
+ cmRtNet_t* p = _cmRtNetHandleToPtr( h );
|
|
927
|
+
|
|
928
|
+ if(( ep = _cmRtNetFindEndpt(p, nodeIdx, epIdx )) == NULL )
|
|
929
|
+ {
|
|
930
|
+ *labelRef = NULL;
|
|
931
|
+ *idRef = cmInvalidId;
|
|
932
|
+ *rsiRef = cmInvalidIdx;
|
|
933
|
+ return kEndNotFoundNetRC;
|
|
934
|
+ }
|
|
935
|
+
|
|
936
|
+ *labelRef = ep->label;
|
|
937
|
+ *idRef = ep->id;
|
|
938
|
+ *rsiRef = ep->rtSubIdx;
|
|
939
|
+
|
|
940
|
+ return kOkNetRC;
|
|
941
|
+}
|
|
942
|
+
|
|
943
|
+
|
803
|
944
|
|
804
|
945
|
//==========================================================================
|
805
|
946
|
#include "cmThread.h"
|