Browse Source

cmRtNet.h/c,cmRtSysMsg.h:Added cmRtNetMsg_t to suport use of rtSubIdx as part of endpoint description.

master
kpl 11 years ago
parent
commit
c1116f6fc0
3 changed files with 69 additions and 54 deletions
  1. 59
    51
      cmRtNet.c
  2. 3
    3
      cmRtNet.h
  3. 7
    0
      cmRtSysMsg.h

+ 59
- 51
cmRtNet.c View File

@@ -39,6 +39,7 @@ typedef struct cmRtNetEnd_str
39 39
 {
40 40
   cmChar_t*               label;
41 41
   unsigned                id;
42
+  unsigned                rtSubIdx;
42 43
   struct cmRtNetNode_str* np;   // Owner node.
43 44
   struct cmRtNetEnd_str*  link;
44 45
 } cmRtNetEnd_t;
@@ -75,10 +76,11 @@ typedef struct
75 76
 // Network synchronization message format
76 77
 typedef struct
77 78
 {
78
-  cmRtSysMsgHdr_t hdr;    // standard cmRtSys msg  header 
79
-  cmRtNetSelId_t  selId;  // message selector id (See kXXXSelNetId above)
80
-  const cmChar_t* label;  // node     or endpoint label
81
-  unsigned        id;     // endptCnt or endpoint id
79
+  cmRtSysMsgHdr_t hdr;      // standard cmRtSys msg  header 
80
+  cmRtNetSelId_t  selId;    // message selector id (See kXXXSelNetId above)
81
+  const cmChar_t* label;    // node         or endpoint label
82
+  unsigned        id;       // endptCnt     or endpoint id
83
+  unsigned        rtSubIdx; // cmInvalidIdx or rtSubIdx
82 84
 } cmRtNetSyncMsg_t;
83 85
 
84 86
 cmRtNetH_t      cmRtNetNullHandle      = cmSTATIC_NULL_HANDLE;
@@ -217,11 +219,11 @@ cmRtNetRC_t _cmRtNetCreateNode( cmRtNet_t* p, const cmChar_t* label, const cmCha
217 219
   return rc;
218 220
 }
219 221
 
220
-cmRtNetEnd_t* _cmRtNetFindNodeEnd(cmRtNetNode_t* np, const cmChar_t* endPtLabel )
222
+cmRtNetEnd_t* _cmRtNetFindNodeEnd(cmRtNetNode_t* np, unsigned rtSubIdx, const cmChar_t* endPtLabel )
221 223
 {
222 224
   cmRtNetEnd_t* ep = np->ends;
223 225
   for(; ep!=NULL; ep=ep->link)
224
-    if( strcmp(ep->label,endPtLabel)==0 )
226
+    if( ep->rtSubIdx==rtSubIdx && strcmp(ep->label,endPtLabel)==0 )
225 227
       return ep;
226 228
   return NULL;
227 229
 }
@@ -240,22 +242,23 @@ cmRtNetEnd_t* _cmRtNetIndexToEndpoint( cmRtNet_t* p, cmRtNetNode_t* np, unsigned
240 242
   return NULL;
241 243
 }
242 244
 
243
-cmRtNetRC_t _cmRtNetCreateEndpoint( cmRtNet_t* p, cmRtNetNode_t* np, const cmChar_t* endPtLabel, unsigned endPtId )
245
+cmRtNetRC_t _cmRtNetCreateEndpoint( cmRtNet_t* p, cmRtNetNode_t* np, unsigned rtSubIdx, const cmChar_t* endPtLabel, unsigned endPtId )
244 246
 {
245 247
   if( endPtLabel == NULL )
246 248
     return cmErrMsg(&p->err,kInvalidLabelNetRC,"A null or blank node label was encountered.");
247 249
 
248
-  if( _cmRtNetFindNodeEnd( np, endPtLabel) != NULL)
250
+  if( _cmRtNetFindNodeEnd( np, rtSubIdx, endPtLabel) != NULL)
249 251
     return cmErrMsg(&p->err,kDuplEndNetRC,"A duplicate endpoint ('%s') was encountered on node '%s'.",endPtLabel,np->label);
250 252
 
251 253
   cmRtNetRC_t   rc = kOkNetRC;
252 254
   cmRtNetEnd_t* ep = cmMemAllocZ(cmRtNetEnd_t,1);
253 255
 
254
-  ep->label = cmMemAllocStr(endPtLabel);
255
-  ep->id    = endPtId;
256
-  ep->np    = np;
257
-  ep->link  = np->ends;
258
-  np->ends  = ep;
256
+  ep->label    = cmMemAllocStr(endPtLabel);
257
+  ep->id       = endPtId;
258
+  ep->rtSubIdx = rtSubIdx;
259
+  ep->np       = np;
260
+  ep->link     = np->ends;
261
+  np->ends     = ep;
259 262
 
260 263
   return rc;
261 264
 }
@@ -295,7 +298,7 @@ cmRtNetRC_t _cmRtNetDeserializeSyncMsg( const void* buf, unsigned n, cmRtNetSync
295 298
   return kOkNetRC;
296 299
 }
297 300
 
298
-cmRtNetRC_t _cmRtNetSendSyncMsg( cmRtNet_t* p, cmRtNetNode_t* np, cmRtNetSelId_t selId, const cmChar_t* msgLabel, unsigned msgId )
301
+cmRtNetRC_t _cmRtNetSendSyncMsg( cmRtNet_t* p, cmRtNetNode_t* np, cmRtNetSelId_t selId, const cmChar_t* msgLabel, unsigned msgId, unsigned msgRtSubIdx )
299 302
 {
300 303
   cmRtNetSyncMsg_t m;
301 304
   cmRtNetRC_t      rc = kOkNetRC;
@@ -306,6 +309,7 @@ cmRtNetRC_t _cmRtNetSendSyncMsg( cmRtNet_t* p, cmRtNetNode_t* np, cmRtNetSelId_t
306 309
   m.selId        = selId;
307 310
   m.label        = msgLabel;
308 311
   m.id           = msgId;
312
+  m.rtSubIdx     = msgRtSubIdx;
309 313
 
310 314
   // determine size of msg to send
311 315
   unsigned n  = _cmRtNetSyncMsgSerialByteCount(&m);
@@ -415,12 +419,13 @@ cmUdpH_t  cmRtNetUdpPortHandle( cmRtNetH_t h )
415 419
 
416 420
 cmRtNetRC_t  _cmRtNetSendEndpointReplyMsg( cmRtNet_t* p, cmRtNetNode_t* np, cmRtNetSelId_t srcSelId )
417 421
 {
418
-  cmRtNetRC_t     rc = kOkNetRC;
419
-  cmRtNetEnd_t*   ep;
420
-  const cmChar_t* msgLabel = NULL;
421
-  unsigned        msgId    = cmInvalidId;  
422
-  cmRtNetSelId_t  selId    = kEndpointSelNetId;
423
-  const cmChar_t* rptLabel = "endpoint";
422
+  cmRtNetRC_t     rc          = kOkNetRC;
423
+  cmRtNetEnd_t*   ep          = NULL;
424
+  const cmChar_t* msgLabel    = NULL;
425
+  unsigned        msgId       = cmInvalidId;
426
+  unsigned        msgRtSubIdx = cmInvalidIdx;
427
+  cmRtNetSelId_t  selId       = kEndpointSelNetId;
428
+  const cmChar_t* rptLabel    = "endpoint";
424 429
 
425 430
   if( np == NULL )
426 431
     return cmErrMsg(&p->err,kNodeNotFoundNetRC,"The net node associated with an endpoint reply was not found.");
@@ -439,8 +444,9 @@ cmRtNetRC_t  _cmRtNetSendEndpointReplyMsg( cmRtNet_t* p, cmRtNetNode_t* np, cmRt
439 444
   // attempt to get the next local endpoint to send ...
440 445
   if((ep = _cmRtNetIndexToEndpoint(p,p->localNode,np->endPtIdx)) != NULL )
441 446
   {
442
-    msgLabel = ep->label;  // ... send next local endpoint
443
-    msgId    = ep->id;
447
+    msgLabel    = ep->label;  // ... send next local endpoint
448
+    msgId       = ep->id;
449
+    msgRtSubIdx = ep->rtSubIdx;
444 450
   }
445 451
   else // .... all local endpoints have been sent
446 452
   {
@@ -462,7 +468,7 @@ cmRtNetRC_t  _cmRtNetSendEndpointReplyMsg( cmRtNet_t* p, cmRtNetNode_t* np, cmRt
462 468
   // selId is set to kInvalidSelNetId when we encounter the (stop) criteria
463 469
   if( selId != kInvalidSelNetId )
464 470
   {
465
-    if((rc = _cmRtNetSendSyncMsg(p,np,selId,msgLabel,msgId )) != kOkNetRC )
471
+    if((rc = _cmRtNetSendSyncMsg(p,np,selId,msgLabel,msgId,msgRtSubIdx)) != kOkNetRC )
466 472
       rc = cmErrMsg(&p->err,rc,"Send '%s' to %s:%s:%i failed.",rptLabel,cmStringNullGuard(np->label),cmStringNullGuard(np->addr),np->port);
467 473
     else
468 474
       _cmRtNetRpt(p,"Sent %s.\n",cmStringNullGuard(rptLabel));
@@ -545,7 +551,7 @@ cmRtNetRC_t  _cmRtNetSyncModeRecv( cmRtNet_t* p, const char* data, unsigned data
545 551
         {
546 552
           case kHelloSelNetId:
547 553
             _cmRtNetRpt(p,"rcv hello\n"); // reply with local node
548
-            rc = _cmRtNetSendSyncMsg( p, np, kNodeSelNetId, p->localNode->label, p->localNode->endPtCnt );
554
+            rc = _cmRtNetSendSyncMsg( p, np, kNodeSelNetId, p->localNode->label, p->localNode->endPtCnt, cmInvalidIdx );
549 555
             break;
550 556
 
551 557
           case kNodeSelNetId:
@@ -577,12 +583,12 @@ cmRtNetRC_t  _cmRtNetSyncModeRecv( cmRtNet_t* p, const char* data, unsigned data
577 583
         }
578 584
         
579 585
         // attempt to find the end point 
580
-        if((ep = _cmRtNetFindNodeEnd(np,m.label)) != NULL )
586
+        if((ep = _cmRtNetFindNodeEnd(np, m.rtSubIdx, m.label)) != NULL )
581 587
           ep->id = m.id; // the endpoint was found update the endPtId
582 588
         else
583 589
         {
584 590
           // create a local proxy for the endpoint
585
-          if((rc = _cmRtNetCreateEndpoint(p,np,m.label,m.id)) != kOkNetRC )
591
+          if((rc = _cmRtNetCreateEndpoint(p,np,m.rtSubIdx,m.label,m.id)) != kOkNetRC )
586 592
             goto errLabel;
587 593
         }
588 594
 
@@ -666,7 +672,7 @@ bool cmRtNetIsInitialized( cmRtNetH_t h )
666 672
 }
667 673
 
668 674
 
669
-cmRtNetRC_t cmRtNetRegisterEndPoint( cmRtNetH_t h, const cmChar_t* endPtLabel, unsigned endPtId )
675
+cmRtNetRC_t cmRtNetRegisterEndPoint( cmRtNetH_t h, unsigned rtSubIdx, const cmChar_t* endPtLabel, unsigned endPtId )
670 676
 {
671 677
   cmRtNetRC_t rc = kOkNetRC;
672 678
   cmRtNet_t* p = _cmRtNetHandleToPtr(h);
@@ -674,7 +680,7 @@ cmRtNetRC_t cmRtNetRegisterEndPoint( cmRtNetH_t h, const cmChar_t* endPtLabel, u
674 680
   if( p->localNode == NULL )
675 681
     return cmErrMsg(&p->err,kLocalNodeNetRC,"Local endpoints may not be added if a local node has not been defined.");
676 682
 
677
-  if((rc = _cmRtNetCreateEndpoint(p, p->localNode,endPtLabel,endPtId )) == kOkNetRC )
683
+  if((rc = _cmRtNetCreateEndpoint(p, p->localNode,rtSubIdx,endPtLabel,endPtId )) == kOkNetRC )
678 684
     p->localNode->endPtCnt += 1;
679 685
 
680 686
   return rc;
@@ -693,7 +699,7 @@ cmRtNetRC_t cmRtNetDoSync( cmRtNetH_t h )
693 699
   cmRtNet_t* p = _cmRtNetHandleToPtr(h);
694 700
 
695 701
   // broadcast 'node' msg
696
-  return _cmRtNetSendSyncMsg( p, p->localNode, kHelloSelNetId, p->localNode->label, p->localNode->endPtCnt );
702
+  return _cmRtNetSendSyncMsg( p, p->localNode, kHelloSelNetId, p->localNode->label, p->localNode->endPtCnt, cmInvalidIdx );
697 703
 }
698 704
 
699 705
 cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h )
@@ -710,7 +716,7 @@ cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h )
710 716
   return rc;
711 717
 }
712 718
 
713
-cmRtNetRC_t cmRtNetEndpointHandle( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endptLabel, cmRtNetEndptH_t* hp )
719
+cmRtNetRC_t cmRtNetEndpointHandle( cmRtNetH_t h, const cmChar_t* nodeLabel, unsigned rtSubIdx, const cmChar_t* endptLabel, cmRtNetEndptH_t* hp )
714 720
 {
715 721
   cmRtNetRC_t     rc = kOkNetRC;
716 722
   cmRtNet_t*      p  = _cmRtNetHandleToPtr(h);
@@ -721,7 +727,7 @@ cmRtNetRC_t cmRtNetEndpointHandle( cmRtNetH_t h, const cmChar_t* nodeLabel, cons
721 727
     return cmErrMsg(&p->err,kNodeNotFoundNetRC,"The node '%s' was not found.",cmStringNullGuard(nodeLabel));
722 728
 
723 729
 
724
-  if(( ep = _cmRtNetFindNodeEnd(np, endptLabel )) == NULL )
730
+  if(( ep = _cmRtNetFindNodeEnd(np, rtSubIdx, endptLabel )) == NULL )
725 731
     return cmErrMsg(&p->err,kEndNotFoundNetRC,"The endpoint '%s' on '%s' on node was not found.",cmStringNullGuard(endptLabel),cmStringNullGuard(nodeLabel));
726 732
 
727 733
   hp->h = ep;
@@ -737,12 +743,13 @@ cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, cmRtNetEndptH_t epH, const void* msg, uns
737 743
  
738 744
   assert( ep != NULL );
739 745
   
740
-  unsigned dN = sizeof(cmRtSysMsgHdr_t) + msgByteCnt; 
746
+  unsigned dN = sizeof(cmRtNetMsg_t) + msgByteCnt; 
741 747
   char data[ dN ];
742 748
 
743
-  cmRtSysMsgHdr_t* hdr = (cmRtSysMsgHdr_t*)data;
744
-  hdr->rtSubIdx     = ep->id;
745
-  hdr->selId        = kMsgSelRtId;
749
+  cmRtNetMsg_t* r = (cmRtNetMsg_t*)data;
750
+  r->hdr.rtSubIdx     = ep->rtSubIdx;
751
+  r->hdr.selId        = kMsgSelRtId;
752
+  r->endptId          = ep->id;
746 753
   memcpy(data+sizeof(cmRtSysMsgHdr_t),msg,msgByteCnt);
747 754
   
748 755
   if( cmUdpSendTo(p->udpH, data, dN, &ep->np->sockaddr ) != kOkUdpRC )
@@ -751,12 +758,12 @@ cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, cmRtNetEndptH_t epH, const void* msg, uns
751 758
   return rc;
752 759
 }
753 760
 
754
-cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endptLabel, const void* msg, unsigned msgByteCnt )
761
+cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, unsigned rtSubIdx, const cmChar_t* endptLabel, const void* msg, unsigned msgByteCnt )
755 762
 {
756 763
   cmRtNetRC_t     rc  = kOkNetRC;
757 764
   cmRtNetEndptH_t epH = cmRtNetEndptNullHandle;
758 765
 
759
-  if((rc = cmRtNetEndpointHandle(h,nodeLabel,endptLabel,&epH)) != kOkNetRC )
766
+  if((rc = cmRtNetEndpointHandle(h,nodeLabel,rtSubIdx,endptLabel,&epH)) != kOkNetRC )
760 767
     return rc;
761 768
 
762 769
   return cmRtNetSend(h,epH,msg,msgByteCnt);
@@ -827,9 +834,9 @@ void _cmRtNetTestRecv( void* cbArg, const char* data, unsigned dataByteCnt, cons
827 834
 {
828 835
   //_cmRtNetTest_t* p = (_cmRtNetTest_t*)cbArg;
829 836
   
830
-  cmRtSysMsgHdr_t* hdr = (cmRtSysMsgHdr_t*)data;
831
-  unsigned i = *(unsigned*)(data + sizeof(cmRtSysMsgHdr_t));
832
-  printf("%i %i\n",hdr->rtSubIdx,i);
837
+  cmRtNetMsg_t* r = (cmRtNetMsg_t*)data;
838
+  unsigned      i = *(unsigned*)(data + sizeof(cmRtNetMsg_t));
839
+  printf("rtSubIdx:%i endptId:%i %i\n",r->hdr.rtSubIdx,r->endptId,i);
833 840
 
834 841
 }
835 842
 
@@ -852,15 +859,16 @@ void  cmRtNetTest( cmCtx_t* ctx, bool mstrFl )
852 859
 {
853 860
   char            c;
854 861
   _cmRtNetTest_t  t;
855
-  cmUdpPort_t     port = 5876;
856
-  _cmRtNetTest_t* p    = &t;
857
-  cmRtNetRC_t     rc   = kOkNetRC;
858
-  const cmChar_t* localHostStr   = mstrFl  ? "master"    : "slave";
859
-  const cmChar_t* localEndpStr   = mstrFl  ? "master_ep" : "slave_ep";
860
-  const cmChar_t* remoteHostStr  = !mstrFl ? "master"    : "slave";
861
-  const cmChar_t* remoteEndpStr  = !mstrFl ? "master_ep" : "slave_ep";
862
-  const cmChar_t* bcastAddr      = "192.168.15.255";
863
-
862
+  const unsigned  rtSubIdx      = 0;
863
+  cmUdpPort_t     port          = 5876;
864
+  _cmRtNetTest_t* p             = &t;
865
+  cmRtNetRC_t     rc            = kOkNetRC;
866
+  const cmChar_t* localHostStr  = mstrFl  ? "master"    : "slave";
867
+  const cmChar_t* localEndpStr  = mstrFl  ? "master_ep" : "slave_ep";
868
+  const cmChar_t* remoteHostStr = !mstrFl ? "master"    : "slave";
869
+  const cmChar_t* remoteEndpStr = !mstrFl ? "master_ep" : "slave_ep";
870
+  const cmChar_t* bcastAddr     = "192.168.15.255";
871
+  
864 872
   memset(&t,0,sizeof(t));
865 873
 
866 874
   if( cmThreadCreate(&p->thH,_cmRtNetTestThreadFunc,p,&ctx->rpt) != kOkThRC )
@@ -874,7 +882,7 @@ void  cmRtNetTest( cmCtx_t* ctx, bool mstrFl )
874 882
   if((rc = cmRtNetInitialize(p->netH, bcastAddr, localHostStr, NULL, port )) != kOkNetRC)
875 883
     goto errLabel;
876 884
 
877
-  if((rc = cmRtNetRegisterEndPoint(p->netH,localEndpStr, 0 )) != kOkNetRC )
885
+  if((rc = cmRtNetRegisterEndPoint(p->netH,rtSubIdx,localEndpStr, 0 )) != kOkNetRC )
878 886
     goto errLabel;
879 887
   
880 888
   if( cmThreadPause(p->thH,0) != kOkThRC )
@@ -896,7 +904,7 @@ void  cmRtNetTest( cmCtx_t* ctx, bool mstrFl )
896 904
 
897 905
       case 't':
898 906
         {
899
-          if( cmRtNetSendByLabels(p->netH, remoteHostStr, remoteEndpStr, &p->msgVal, sizeof(p->msgVal)) == kOkNetRC )
907
+          if( cmRtNetSendByLabels(p->netH, remoteHostStr, rtSubIdx, remoteEndpStr, &p->msgVal, sizeof(p->msgVal)) == kOkNetRC )
900 908
             p->msgVal += 1;
901 909
 
902 910
         }        

+ 3
- 3
cmRtNet.h View File

@@ -55,7 +55,7 @@ extern "C" {
55 55
   // cmRtNetInitialize().
56 56
   // Remote nodes will be able to send messages to these endpoints by
57 57
   // referring to (nodeLabel/endPtLabel)
58
-  cmRtNetRC_t cmRtNetRegisterEndPoint( cmRtNetH_t h, const cmChar_t* endPtLabel, unsigned endPtId );
58
+  cmRtNetRC_t cmRtNetRegisterEndPoint( cmRtNetH_t h, unsigned rtSubIdx, const cmChar_t* endPtLabel, unsigned endPtId );
59 59
 
60 60
   // Delete all nodes and endpoints.
61 61
   cmRtNetRC_t cmRtNetFinalize( cmRtNetH_t h );
@@ -69,14 +69,14 @@ extern "C" {
69 69
   cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h );
70 70
 
71 71
   // Get an end point handle for use with cmRtNetSend.
72
-  cmRtNetRC_t cmRtNetEndpointHandle( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endptLabel, cmRtNetEndptH_t* hp );
72
+  cmRtNetRC_t cmRtNetEndpointHandle( cmRtNetH_t h, const cmChar_t* nodeLabel, unsigned rtSubIdx, const cmChar_t* endptLabel, cmRtNetEndptH_t* hp );
73 73
 
74 74
   // Send a message to a remote endpoint.
75 75
   cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, cmRtNetEndptH_t epH, const void* msg, unsigned msgByteCnt );
76 76
 
77 77
   // Send a message to a remote endpoint. This function is a composite
78 78
   // of cmRtNetEndpointHandle() and cmRtNetSend().
79
-  cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endptLabel, const void* msg, unsigned msgByteCnt );
79
+  cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, unsigned rtSubIdx, const cmChar_t* endptLabel, const void* msg, unsigned msgByteCnt );
80 80
 
81 81
   // Enable/disable synchronization protocol reporting.
82 82
   // Return the previous state of the report sync. flag.

+ 7
- 0
cmRtSysMsg.h View File

@@ -95,6 +95,13 @@ extern "C" {
95 95
     // cmMidiMsg msgArray[msgCnt]
96 96
   } cmRtSysMidi_t;
97 97
 
98
+  typedef struct
99
+  {
100
+    cmRtSysMsgHdr_t hdr;
101
+    unsigned        endptId;
102
+    // char msg[ msgByteCnt ]
103
+  } cmRtNetMsg_t;
104
+
98 105
 #ifdef __cplusplus
99 106
 }
100 107
 #endif

Loading…
Cancel
Save