Browse Source

cmRtNet.h/c: Added cmRtNetTest().

master
kevin 11 years ago
parent
commit
75f3882a61
2 changed files with 119 additions and 8 deletions
  1. 91
    1
      cmRtNet.c
  2. 28
    7
      cmRtNet.h

+ 91
- 1
cmRtNet.c View File

@@ -74,7 +74,7 @@ typedef struct
74 74
 typedef struct
75 75
 {
76 76
   cmRtSysMsgHdr_t hdr;
77
-  cmRtNetSelId_t    selId;
77
+  cmRtNetSelId_t  selId;
78 78
   const cmChar_t* endPtLabel;
79 79
   unsigned        endPtId;
80 80
 } cmRtNetSyncMsg_t;
@@ -703,6 +703,13 @@ cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h )
703 703
   return rc;
704 704
 }
705 705
 
706
+bool    cmRtNetIsSyncModeMsg( const void* data, unsigned dataByteCnt )
707
+{
708
+  cmRtNetSyncMsg_t* m = (cmRtNetSyncMsg_t*)data;
709
+  return dataByteCnt >= sizeof(cmRtNetSyncMsg_t) && m->hdr.selId == kNetSyncSelRtId;
710
+}
711
+
712
+
706 713
 unsigned  cmRtNetEndPointIndex( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endPtLabel )
707 714
 {
708 715
   //cmRtNet_t* p = _cmRtNetHandleToPtr(h);
@@ -749,3 +756,86 @@ void   cmRtNetReport( cmRtNetH_t h )
749 756
     }
750 757
   }
751 758
 }
759
+
760
+
761
+//==========================================================================
762
+
763
+typedef struct
764
+{
765
+  cmThreadH_t thH;
766
+  cmRtNetH_t netH;
767
+} _cmRtNetTest_t;
768
+
769
+void _cmRtNetTestRecv( void* cbArg, const char* data, unsigned dataByteCnt, const struct sockaddr_in* fromAddr )
770
+{
771
+  _cmRtNetTest_t* p = (_cmrtNetTest_t*)cbArg;
772
+
773
+  if( cmRtNetIsSyncModeMsg(data,dataByteCnt))
774
+    cmRtNetSyncModeRecv(p->netH,data,dataByteCnt,fromAddr);
775
+
776
+}
777
+
778
+
779
+bool _cmRtNetTestThreadFunc(void* param)
780
+{
781
+  _cmrtNetTest_t* p = (_cmRtNetTest_t*)param;
782
+
783
+  
784
+  if( cmRtNetIsValid(p->netH) && cmRtNetIsInSyncMode(p->netH) )
785
+    cmRtNetSyncModeSend(p->netH);
786
+
787
+  return true;
788
+}
789
+
790
+void    cmRtNetTest( cmCtx_t* ctx, bool mstrFl )
791
+{
792
+  char c;
793
+  _cmRtNetTest_t t;
794
+  cmUdpPort_t port = 5867;
795
+  _cmRtNetTest_t* p = &t;
796
+  cmRtNetRC_t rc = kOkNetRC;
797
+  memset(&t,0,sizeof(t));
798
+
799
+  if( cmThreadCreate(&p->thH,_cmRtNetTestThreadFunc,p,&ctx->rpt) != kOkThRC )
800
+    goto errLabel;
801
+
802
+  if((rc = cmRtNetAlloc(ctx,&p->netH,p)) != kOkNetRC )
803
+    goto errLabel;
804
+
805
+  if((rc = cmRtNetCreateNode(p->netH, "local", NULL, port )) != kOkNetRC)
806
+    goto errLabel;
807
+
808
+  if( mstrFl )
809
+  {
810
+    if((rc = cmRtNetCreate(p->netH,"whirl", "192.168.15.109", port )) != kOkNetRC )
811
+      goto errLabel;
812
+
813
+    if((rc = cmRtNetEndPoint(p->netH,"thunk_ep0", 0 )) != kOkNetRC )
814
+      goto errLabel;
815
+
816
+    if(( rc = cmRtNetBeginSyncMode(p->netH)) != kOkNetRC )
817
+      goto errLabel;
818
+    
819
+  }
820
+  else
821
+  {
822
+    if((rc = cmRtNetEndPoint(p->netH,"whirl_ep0", 0 )) != kOkNetRC )
823
+      goto errLabel;
824
+  }
825
+  
826
+  if( cmThreadPause(p->thH,0) != kOkThRC )
827
+    goto errLabel;
828
+
829
+  while( (c=getchar()) != 'q' )
830
+  {
831
+    
832
+  }
833
+
834
+ errLabel:
835
+
836
+  cmRtNetFree(&p->netH);
837
+
838
+  cmThreadDestroy(&p->thH);
839
+  return;
840
+
841
+}

+ 28
- 7
cmRtNet.h View File

@@ -52,12 +52,13 @@ extern "C" {
52 52
 
53 53
 
54 54
   // Go into 'sync' node.
55
-  // When a node enters sync mode it systematically transmits all of it's local endpoint 
56
-  // information to each registered remote node.  Prior to entering sync mode a node 
57
-  // must therefore have been setup with a list of remote nodes (via cmRtNetCreateNode()) 
58
-  // and a list of local endpoints (cmRtNetRegisterEndpoint()). 
59
-  // During sync mode a node sends it's local endpoint list to each registered remote node.
60
-  // When a remote node receives an endpoint it updates it's own remote node/endpoint 
55
+  // When a node enters sync mode it systematically transmits all of it's 
56
+  // local endpoint information to each registered remote node.  Prior to 
57
+  // entering sync mode a node must therefore have been setup with a list 
58
+  // of remote nodes (via cmRtNetCreateNode()) and a list of local endpoints 
59
+  // (cmRtNetRegisterEndpoint()).  During sync mode a node sends it's local 
60
+  // endpoint list to each registered remote node. When a remote node receives 
61
+  // an endpoint it updates it's own remote node/endpoint 
61 62
   // list.
62 63
   cmRtNetRC_t cmRtNetBeginSyncMode( cmRtNetH_t h );
63 64
   bool      cmRtNetIsInSyncMode(  cmRtNetH_t h );
@@ -77,6 +78,8 @@ extern "C" {
77 78
   // via the callback funcion 'cbFunc' as passed to cmRtNetAlloc()
78 79
   cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h );
79 80
 
81
+  bool        cmRtNetIsSyncModeMsg( const void* data, unsigned dataByteCnt );
82
+
80 83
   unsigned  cmRtNetEndPointIndex( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endPtLabel );
81 84
   
82 85
 
@@ -84,7 +87,25 @@ extern "C" {
84 87
 
85 88
   void      cmRtNetReport( cmRtNetH_t h );
86 89
     
87
-  
90
+  void      cmRtNetTest( cmCtx_t* ctx );
91
+
92
+  /*
93
+    Master:
94
+      cmRtNetBeginSyncMode().
95
+      while( cmRtNetIsSyncMode())
96
+      {
97
+       // Give the master an oppurtunity to advance it's sync mode state.
98
+       // When the master is has sync'd with all remote nodes in it's
99
+       // remote node list then it will automatically exit sync mode.
100
+       cmRtNetSyncModeSend()
101
+      }
102
+
103
+      _myNetRecv(dataV,dataN,addr)
104
+     {
105
+       if( cmRtNetIsSyncModeMsg(dataV,dataN) )
106
+         cmRtNetSyncModeRecv(dataV,dataN,addr)
107
+     }   
108
+   */  
88 109
 
89 110
 #ifdef __cplusplus
90 111
 }

Loading…
Cancel
Save