|
@@ -76,6 +76,13 @@ cmRtNet_t* _cmRtNetHandleToPtr( cmRtNetH_t h )
|
76
|
76
|
return p;
|
77
|
77
|
}
|
78
|
78
|
|
|
79
|
+cmRtNetEnd_t* _cmRtNetEndptHandleToPtr( cmRtNetEndptH_t h )
|
|
80
|
+{
|
|
81
|
+ cmRtNetEnd_t* p = (cmRtNetEnd_t*)h.h;
|
|
82
|
+ assert( p != NULL );
|
|
83
|
+ return p;
|
|
84
|
+}
|
|
85
|
+
|
79
|
86
|
void _cmRtNetVRpt( cmRtNet_t* p, const cmChar_t* fmt, va_list vl )
|
80
|
87
|
{
|
81
|
88
|
if( cmIsFlag(p->flags,kReportSyncNetFl) )
|
|
@@ -643,14 +650,38 @@ cmRtNetRC_t _cmRtNetSyncModeRecv( cmRtNet_t* p, const char* data, unsigned data
|
643
|
650
|
return rc;
|
644
|
651
|
}
|
645
|
652
|
|
|
653
|
+unsigned _cmRtNetAddrToNodeIndex( cmRtNet_t* p, const struct sockaddr_in* addr )
|
|
654
|
+{
|
|
655
|
+ unsigned i;
|
|
656
|
+ cmRtNetNode_t* np = p->nodes;
|
|
657
|
+ for(i=0; np!=NULL; np=np->link,++i)
|
|
658
|
+ if( cmUdpAddrIsEqual( addr, &np->sockaddr ) )
|
|
659
|
+ return i;
|
|
660
|
+
|
|
661
|
+ return cmInvalidIdx;
|
|
662
|
+}
|
|
663
|
+
|
|
664
|
+
|
646
|
665
|
// This is called in the context of cmRtNetReceive().
|
647
|
666
|
void _cmRtNetRecv( void* cbArg, const char* data, unsigned dataByteCnt, const struct sockaddr_in* fromAddr )
|
648
|
667
|
{
|
649
|
668
|
cmRtNet_t* p = (cmRtNet_t*)cbArg;
|
650
|
669
|
|
|
670
|
+ // if this is a sync msg - then handle it here
|
651
|
671
|
if( _cmRtNetIsSyncModeMsg(data,dataByteCnt))
|
652
|
672
|
_cmRtNetSyncModeRecv(p,data,dataByteCnt,fromAddr);
|
653
|
|
-
|
|
673
|
+ else
|
|
674
|
+ {
|
|
675
|
+ // All non-sync messages arriving here are prefixed by a cmRtNetMsg_t header - fill in the source addr here.
|
|
676
|
+
|
|
677
|
+ // NOTE: the source addr could be filled in by the sender but this would increase the size
|
|
678
|
+ // of the msg. Instead we choose the more time consuming method of looking up the
|
|
679
|
+ // soure node here - hmmmm????.
|
|
680
|
+
|
|
681
|
+ cmRtNetMsg_t* hdr = (cmRtNetMsg_t*)(data);
|
|
682
|
+ hdr->srcNodeIdx = _cmRtNetAddrToNodeIndex(p,fromAddr);
|
|
683
|
+ }
|
|
684
|
+
|
654
|
685
|
p->cbFunc(p->cbArg,data,dataByteCnt,fromAddr);
|
655
|
686
|
|
656
|
687
|
}
|
|
@@ -753,6 +784,13 @@ cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h )
|
753
|
784
|
return rc;
|
754
|
785
|
}
|
755
|
786
|
|
|
787
|
+unsigned cmRtNetAddrToNodeIndex( cmRtNetH_t h, const struct sockaddr_in* a )
|
|
788
|
+{
|
|
789
|
+ cmRtNet_t* p = _cmRtNetHandleToPtr(h);
|
|
790
|
+ return _cmRtNetAddrToNodeIndex(p,a);
|
|
791
|
+}
|
|
792
|
+
|
|
793
|
+
|
756
|
794
|
cmRtNetRC_t cmRtNetEndpointHandle( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endptLabel, cmRtNetEndptH_t* hp )
|
757
|
795
|
{
|
758
|
796
|
cmRtNetRC_t rc = kOkNetRC;
|
|
@@ -772,7 +810,29 @@ cmRtNetRC_t cmRtNetEndpointHandle( cmRtNetH_t h, const cmChar_t* nodeLabel, cons
|
772
|
810
|
return rc;
|
773
|
811
|
}
|
774
|
812
|
|
775
|
|
-cmRtNetRC_t _cmRtNetSend( cmRtNet_t* p, const cmRtNetEnd_t* ep, const void* msg, unsigned msgByteCnt )
|
|
813
|
+bool cmRtNetEndpointIsValid( cmRtNetEndptH_t endPtH )
|
|
814
|
+{ return endPtH.h != NULL; }
|
|
815
|
+
|
|
816
|
+unsigned cmRtNetEndpointId( cmRtNetEndptH_t endPtH )
|
|
817
|
+{
|
|
818
|
+ if( !cmRtNetEndpointIsValid(endPtH) )
|
|
819
|
+ return cmInvalidId;
|
|
820
|
+
|
|
821
|
+ cmRtNetEnd_t* ep = _cmRtNetEndptHandleToPtr( endPtH );
|
|
822
|
+ return ep->id;
|
|
823
|
+}
|
|
824
|
+
|
|
825
|
+const cmChar_t* cmRtNetEndpointLabel( cmRtNetEndptH_t endPtH )
|
|
826
|
+{
|
|
827
|
+ if( !cmRtNetEndpointIsValid(endPtH) )
|
|
828
|
+ return NULL;
|
|
829
|
+
|
|
830
|
+ cmRtNetEnd_t* ep = _cmRtNetEndptHandleToPtr( endPtH );
|
|
831
|
+ return ep->label;
|
|
832
|
+}
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+cmRtNetRC_t _cmRtNetSend( cmRtNet_t* p, unsigned srcEndPtId, const cmRtNetEnd_t* ep, const void* msg, unsigned msgByteCnt )
|
776
|
836
|
{
|
777
|
837
|
cmRtNetRC_t rc = kOkNetRC;
|
778
|
838
|
|
|
@@ -783,7 +843,8 @@ cmRtNetRC_t _cmRtNetSend( cmRtNet_t* p, const cmRtNetEnd_t* ep, const void* msg,
|
783
|
843
|
cmRtNetMsg_t* r = (cmRtNetMsg_t*)data;
|
784
|
844
|
r->hdr.rtSubIdx = ep->np->rtSubIdx;
|
785
|
845
|
r->hdr.selId = kMsgSelRtId;
|
786
|
|
- r->endptId = ep->id;
|
|
846
|
+ r->dstEndPtId = ep->id;
|
|
847
|
+ r->srcEndPtId = srcEndPtId;
|
787
|
848
|
memcpy(data+hN,msg,msgByteCnt);
|
788
|
849
|
|
789
|
850
|
// ep->np->sockaddr identifies the node on the receiving cmRtNet.
|
|
@@ -796,17 +857,17 @@ cmRtNetRC_t _cmRtNetSend( cmRtNet_t* p, const cmRtNetEnd_t* ep, const void* msg,
|
796
|
857
|
return rc;
|
797
|
858
|
}
|
798
|
859
|
|
799
|
|
-cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, cmRtNetEndptH_t epH, const void* msg, unsigned msgByteCnt )
|
|
860
|
+cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, unsigned srcEndPtId, cmRtNetEndptH_t epH, const void* msg, unsigned msgByteCnt )
|
800
|
861
|
{
|
801
|
862
|
cmRtNet_t* p = _cmRtNetHandleToPtr(h);
|
802
|
|
- cmRtNetEnd_t* ep = (cmRtNetEnd_t*)epH.h;
|
|
863
|
+ cmRtNetEnd_t* ep = _cmRtNetEndptHandleToPtr(epH);
|
803
|
864
|
|
804
|
865
|
assert( ep != NULL );
|
805
|
|
- return _cmRtNetSend(p,ep,msg,msgByteCnt);
|
|
866
|
+ return _cmRtNetSend(p,srcEndPtId,ep,msg,msgByteCnt);
|
806
|
867
|
}
|
807
|
868
|
|
808
|
869
|
|
809
|
|
-cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endptLabel, const void* msg, unsigned msgByteCnt )
|
|
870
|
+cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, unsigned srcEndPtId, const cmChar_t* nodeLabel, const cmChar_t* endptLabel, const void* msg, unsigned msgByteCnt )
|
810
|
871
|
{
|
811
|
872
|
cmRtNetRC_t rc = kOkNetRC;
|
812
|
873
|
cmRtNetEndptH_t epH = cmRtNetEndptNullHandle;
|
|
@@ -814,10 +875,10 @@ cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, const
|
814
|
875
|
if((rc = cmRtNetEndpointHandle(h,nodeLabel,endptLabel,&epH)) != kOkNetRC )
|
815
|
876
|
return rc;
|
816
|
877
|
|
817
|
|
- return cmRtNetSend(h,epH,msg,msgByteCnt);
|
|
878
|
+ return cmRtNetSend(h,srcEndPtId,epH,msg,msgByteCnt);
|
818
|
879
|
}
|
819
|
880
|
|
820
|
|
-cmRtNetRC_t cmRtNetSendByIndex( cmRtNetH_t h, unsigned nodeIdx, unsigned endptIdx, const void* msg, unsigned msgByteCnt )
|
|
881
|
+cmRtNetRC_t cmRtNetSendByIndex( cmRtNetH_t h, unsigned srcEndPtId, unsigned nodeIdx, unsigned endptIdx, const void* msg, unsigned msgByteCnt )
|
821
|
882
|
{
|
822
|
883
|
cmRtNet_t* p = _cmRtNetHandleToPtr(h);
|
823
|
884
|
|
|
@@ -826,7 +887,7 @@ cmRtNetRC_t cmRtNetSendByIndex( cmRtNetH_t h, unsigned nodeIdx, unsigned endptId
|
826
|
887
|
if((ep = _cmRtNetFindEndpt(p, nodeIdx, endptIdx )) == NULL )
|
827
|
888
|
return cmErrMsg(&p->err,kEndNotFoundNetRC,"The endpoint at node index %i endpoint index %i was not found.",nodeIdx,endptIdx);
|
828
|
889
|
|
829
|
|
- return _cmRtNetSend( p, ep, msg, msgByteCnt );
|
|
890
|
+ return _cmRtNetSend( p, srcEndPtId, ep, msg, msgByteCnt );
|
830
|
891
|
}
|
831
|
892
|
|
832
|
893
|
|
|
@@ -968,7 +1029,7 @@ void _cmRtNetTestRecv( void* cbArg, const char* data, unsigned dataByteCnt, cons
|
968
|
1029
|
|
969
|
1030
|
cmRtNetMsg_t* r = (cmRtNetMsg_t*)data;
|
970
|
1031
|
unsigned i = *(unsigned*)(data + sizeof(cmRtNetMsg_t));
|
971
|
|
- printf("rtSubIdx:%i endptId:%i %i\n",r->hdr.rtSubIdx,r->endptId,i);
|
|
1032
|
+ printf("rtSubIdx:%i endptId:%i %i\n",r->hdr.rtSubIdx,r->dstEndPtId,i);
|
972
|
1033
|
|
973
|
1034
|
}
|
974
|
1035
|
|
|
@@ -1000,7 +1061,9 @@ void cmRtNetTest( cmCtx_t* ctx, bool mstrFl )
|
1000
|
1061
|
const cmChar_t* remoteHostStr = !mstrFl ? "master" : "slave";
|
1001
|
1062
|
const cmChar_t* remoteEndpStr = !mstrFl ? "master_ep" : "slave_ep";
|
1002
|
1063
|
const cmChar_t* bcastAddr = "192.168.15.255";
|
1003
|
|
-
|
|
1064
|
+ cmRtNetEndptH_t eH = cmRtNetEndptNullHandle;
|
|
1065
|
+ unsigned srcEndPtId = cmInvalidId;
|
|
1066
|
+
|
1004
|
1067
|
memset(&t,0,sizeof(t));
|
1005
|
1068
|
|
1006
|
1069
|
if( cmThreadCreate(&p->thH,_cmRtNetTestThreadFunc,p,&ctx->rpt) != kOkThRC )
|
|
@@ -1016,6 +1079,12 @@ void cmRtNetTest( cmCtx_t* ctx, bool mstrFl )
|
1016
|
1079
|
|
1017
|
1080
|
if((rc = cmRtNetRegisterEndPoint(p->netH,localEndpStr, 0 )) != kOkNetRC )
|
1018
|
1081
|
goto errLabel;
|
|
1082
|
+
|
|
1083
|
+ if((rc = cmRtNetEndpointHandle(p->netH, localHostStr, localEndpStr, &eH )) != kOkNetRC )
|
|
1084
|
+ goto errLabel;
|
|
1085
|
+
|
|
1086
|
+ if((srcEndPtId = cmRtNetEndpointId(eH)) == cmInvalidIdx )
|
|
1087
|
+ goto errLabel;
|
1019
|
1088
|
|
1020
|
1089
|
if( cmThreadPause(p->thH,0) != kOkThRC )
|
1021
|
1090
|
goto errLabel;
|
|
@@ -1036,7 +1105,7 @@ void cmRtNetTest( cmCtx_t* ctx, bool mstrFl )
|
1036
|
1105
|
|
1037
|
1106
|
case 't':
|
1038
|
1107
|
{
|
1039
|
|
- if( cmRtNetSendByLabels(p->netH, remoteHostStr, remoteEndpStr, &p->msgVal, sizeof(p->msgVal)) == kOkNetRC )
|
|
1108
|
+ if( cmRtNetSendByLabels(p->netH, srcEndPtId, remoteHostStr, remoteEndpStr, &p->msgVal, sizeof(p->msgVal)) == kOkNetRC )
|
1040
|
1109
|
p->msgVal += 1;
|
1041
|
1110
|
|
1042
|
1111
|
}
|