libcm is a C development framework with an emphasis on audio signal processing applications.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

cmRtNet.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #ifndef cmNet_h
  2. #define cmNet_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. enum
  7. {
  8. kOkNetRC = cmOkRC,
  9. kUdpPortFailNetRC,
  10. kInvalidLabelNetRC,
  11. kDuplLabelNetRC,
  12. kDuplLocalNetRC,
  13. kDuplEndNetRC,
  14. kThreadFailNetRC,
  15. kBufToSmallNetRC,
  16. kNodeNotFoundNetRC,
  17. kNodeStateErrNetRC,
  18. kTimeOutErrNetRC,
  19. kLocalNodeNetRC,
  20. };
  21. typedef cmRC_t cmRtNetRC_t;
  22. typedef cmHandle_t cmRtNetH_t;
  23. extern cmRtNetH_t cmRtNetNullHandle;
  24. // 'cbFunc' will be called within the context of cmRtNetReceive() to receive
  25. // incoming network messages.
  26. cmRtNetRC_t cmRtNetAlloc( cmCtx_t* ctx, cmRtNetH_t* hp, cmUdpCallback_t cbFunc, void* cbArg );
  27. cmRtNetRC_t cmRtNetFree( cmRtNetH_t* hp );
  28. bool cmRtNetIsValid( cmRtNetH_t h );
  29. const cmChar_t* cmRtNetLocalHostName( cmRtNetH_t h );
  30. // Create a network node.
  31. // The 'nodeLabel' refers to a network device cfg. (see cmDevCfg).
  32. // Set 'ipAddr' to NULL if this is the local node.
  33. // During sync mode this node will attempt to sync with all
  34. // nodes in the node list.
  35. cmRtNetRC_t cmRtNetRegisterLocalNode( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* ipAddr, cmUdpPort_t ipPort );
  36. // Register the local endpoints.
  37. // Remote nodes will be able to send messages to these endpoints by
  38. // referring to (nodeLabel/endPtLabel)
  39. cmRtNetRC_t cmRtNetRegisterEndPoint( cmRtNetH_t h, const cmChar_t* endPtLabel, unsigned endPtId );
  40. // Delete all nodes and endpoints.
  41. cmRtNetRC_t cmRtNetClearAll( cmRtNetH_t h );
  42. // Go into 'sync' node.
  43. // When a node enters sync mode it systematically transmits all of it's
  44. // local endpoint information to each registered remote node. Prior to
  45. // entering sync mode a node must therefore have been setup with a list
  46. // of remote nodes (via cmRtNetCreateNode()) and a list of local endpoints
  47. // (cmRtNetRegisterEndpoint()). During sync mode a node sends it's local
  48. // endpoint list to each registered remote node. When a remote node receives
  49. // an endpoint it updates it's own remote node/endpoint
  50. // list.
  51. cmRtNetRC_t cmRtNetBeginSyncMode( cmRtNetH_t h );
  52. // This function must be polled to receive incoming network messages
  53. // via the callback funcion 'cbFunc' as passed to cmRtNetAlloc()
  54. cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h );
  55. bool cmRtNetIsSyncModeMsg( const void* data, unsigned dataByteCnt );
  56. unsigned cmRtNetEndPointIndex( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endPtLabel );
  57. cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, unsigned endPointIndex, const void* msg, unsigned msgByteCnt );
  58. void cmRtNetReport( cmRtNetH_t h );
  59. void cmRtNetTest( cmCtx_t* ctx, bool mstrFl );
  60. /*
  61. Master:
  62. cmRtNetBeginSyncMode().
  63. while( cmRtNetIsSyncMode())
  64. {
  65. // Give the master an oppurtunity to advance it's sync mode state.
  66. // When the master is has sync'd with all remote nodes in it's
  67. // remote node list then it will automatically exit sync mode.
  68. cmRtNetSyncModeSend()
  69. }
  70. _myNetRecv(dataV,dataN,addr)
  71. {
  72. if( cmRtNetIsSyncModeMsg(dataV,dataN) )
  73. cmRtNetSyncModeRecv(dataV,dataN,addr)
  74. }
  75. The 'master' is the machine which cmRtNetBeginSyncMode() is called on.
  76. 1) 'master' sends local endpoints to all registered remote nodes.
  77. 2) When a 'slave' receives the kDoneSelNetId msg it transmits
  78. it's own local endpoints back to the master.
  79. a. Each node in the node list has a type id:
  80. 1. local
  81. 2. registered - remote node that was explicitely registered on a master
  82. 3. received - remote node that was received from a master
  83. b.
  84. 1. All nodes are created in the 'send-hello' state.
  85. 2. If a master machine is in 'sync-mode' then it systematically sends
  86. each of it's local endpoints to all 'registered' nodes.
  87. 3. When a slave machine recives a 'hello' it creates a
  88. 'received' node.
  89. 4. When a slave machine recieves a 'done' it enters sync mode
  90. and systematically sends each of its local endpoints to
  91. the 'done' source.
  92. Protocol:
  93. 1. A: on init bcast 'hello'
  94. 2. B: on 'hello' - create node-A w/ ei=0 - send 'node'
  95. 3. A: on 'node' - create node-B w/ ei=0 - send first 'endpt'
  96. 4. B: on 'endpt' - create endpt on node-A - ei!=en ? send 'endpt' or send 'done'
  97. 5. A: on 'endpt' - create endpt on node-B - ei!=en ? send 'endpt' or send 'done'
  98. 6. B: on 'done' - mark node-A as 'valid'
  99. 7. A: on 'done' - mark node-B as 'valid'.
  100. */
  101. #ifdef __cplusplus
  102. }
  103. #endif
  104. #endif