libcm is a C development framework with an emphasis on audio signal processing applications.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

cmRtNet.h 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. kDuplEndNetRC,
  13. kDuplLocalNetRC,
  14. kThreadFailNetRC,
  15. kBufToSmallNetRC,
  16. kNodeNotFoundNetRC,
  17. kEndNotFoundNetRC,
  18. kLocalNodeNetRC,
  19. kInvalidArgNetRC,
  20. kSyncFailNetRC,
  21. kNodeEndCntErrNetRC
  22. };
  23. typedef cmRC_t cmRtNetRC_t;
  24. typedef cmHandle_t cmRtNetH_t;
  25. typedef cmHandle_t cmRtNetEndptH_t;
  26. extern cmRtNetH_t cmRtNetNullHandle;
  27. extern cmRtNetEndptH_t cmRtNetEndptNullHandle;
  28. // selector id's for cmRtNetSyncMsg_t.selId.
  29. typedef enum
  30. {
  31. kHelloSelNetId, // broadcast msg (label=node label, id=endpt cnt)
  32. kNodeSelNetId, // define remote node (label=remote node label, id=endpt cnt)
  33. kEndpointSelNetId, // define remote endpt (label=remote endpt label, id=endpt id)
  34. kDoneSelNetId, // declare all endpts sent
  35. kInvalidSelNetId
  36. } cmRtNetSelId_t;
  37. // Network synchronization message format.
  38. // cmRtNetRC_t.hdr.selId == kNetSyncSelRtid.
  39. typedef struct
  40. {
  41. cmRtSysMsgHdr_t hdr; // standard cmRtSys msg header
  42. cmRtNetSelId_t selId; // message selector id (See kXXXSelNetId above)
  43. unsigned rtSubIdx; // cmInvalidIdx or rtSubIdx
  44. unsigned id; // endptCnt or endpoint id
  45. const cmChar_t* label; // node or endpoint label
  46. } cmRtNetSyncMsg_t;
  47. const cmChar_t* cmRtNetSyncMsgLabel( const cmRtNetSyncMsg_t* m );
  48. // NOTE: Messages passed between cmRtNet nodes during the synchronization
  49. // process use the cmRtNetSyncMsg_t format (w/ the body of label following
  50. // the record. All other messages use cmRtNetMsg_t (cmRtSysMsg.h) format.
  51. // 'cbFunc' will be called within the context of cmRtNetReceive() to receive
  52. // incoming network messages.
  53. cmRtNetRC_t cmRtNetAlloc( cmCtx_t* ctx, cmRtNetH_t* hp, cmUdpCallback_t cbFunc, void* cbArg );
  54. cmRtNetRC_t cmRtNetFree( cmRtNetH_t* hp );
  55. bool cmRtNetIsValid( cmRtNetH_t h );
  56. // Get the local host name for this machine. This function
  57. // is synonomous with gethostname().
  58. const cmChar_t* cmRtNetLocalHostName( cmRtNetH_t h );
  59. // Initialize the local network node.
  60. // 'bcastAddr' is the network broadcast address (e.g. 192.168.15.255).
  61. // 'nodeLabel' is the local network node label
  62. // 'ipAddr' may be set to NULL to use any available IP address.
  63. // 'ipPort' refers to the socket port (which may need to be made available
  64. // by the machine firewall cfg.)
  65. cmRtNetRC_t cmRtNetInitialize( cmRtNetH_t h, const cmChar_t* bcastAddr, const cmChar_t* nodeLabel, const cmChar_t* ipAddr, cmUdpPort_t ipPort );
  66. bool cmRtNetIsInitialized( cmRtNetH_t h );
  67. // Register the local endpoints.
  68. // Endpoints may only be registered once the network is initialized via
  69. // cmRtNetInitialize().
  70. // Remote nodes will be able to send messages to these endpoints by
  71. // referring to (nodeLabel/endPtLabel)
  72. cmRtNetRC_t cmRtNetRegisterEndPoint( cmRtNetH_t h, unsigned rtSubIdx, const cmChar_t* endPtLabel, unsigned endPtId );
  73. // Delete all nodes and endpoints.
  74. cmRtNetRC_t cmRtNetFinalize( cmRtNetH_t h );
  75. // Broadcast the 'hello' to all machines listening on the
  76. // broadcast addresss. This starts the synchronization sequence
  77. cmRtNetRC_t cmRtNetDoSync( cmRtNetH_t h );
  78. // This function must be polled to receive incoming network messages
  79. // via the callback funcion 'cbFunc' as passed to cmRtNetAlloc().
  80. // Note that all messages received via 'cbFunc' will be prefixed with
  81. // an cmRtSysMsgHdr_t header (See cmRtSysMsg.h).
  82. cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h );
  83. // Get an end point handle for use with cmRtNetSend.
  84. cmRtNetRC_t cmRtNetEndpointHandle( cmRtNetH_t h, const cmChar_t* nodeLabel, unsigned rtSubIdx, const cmChar_t* endptLabel, cmRtNetEndptH_t* hp );
  85. // Send a message to a remote endpoint.
  86. cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, cmRtNetEndptH_t epH, const void* msg, unsigned msgByteCnt );
  87. // Send a message to a remote endpoint. This function is a composite
  88. // of cmRtNetEndpointHandle() and cmRtNetSend().
  89. cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, unsigned rtSubIdx, const cmChar_t* endptLabel, const void* msg, unsigned msgByteCnt );
  90. cmRtNetRC_t cmRtNetSendByIndex( cmRtNetH_t h, unsigned nodeIdx, unsigned endptIdx, const void* msg, unsigned msgByteCnt );
  91. // Enable/disable synchronization protocol reporting.
  92. // Return the previous state of the report sync. flag.
  93. bool cmRtNetReportSyncEnable( cmRtNetH_t h, bool enableFl );
  94. bool cmRtNetReportSyncIsEnabled( cmRtNetH_t h );
  95. // Query network configuration. Returns true on success or false if
  96. // {nodeIdx, epIdx} does not identify a valid endpoint.
  97. const cmChar_t* cmRtNetLocalNodeLabel( cmRtNetH_t h );
  98. unsigned cmRtNetRemoteNodeCount( cmRtNetH_t h );
  99. const cmChar_t* cmRtNetRemoteNodeLabel( cmRtNetH_t h, unsigned idx );
  100. unsigned cmRtNetRemoteNodeEndPointCount( cmRtNetH_t h, unsigned nodeIdx );
  101. cmRtNetRC_t cmRtNetRemoteNodeEndPoint(
  102. cmRtNetH_t h,
  103. unsigned nodeIdx,
  104. unsigned epIdx,
  105. const cmChar_t** labelRef,
  106. unsigned* idRef,
  107. unsigned* rsiRef );
  108. void cmRtNetReport( cmRtNetH_t h );
  109. void cmRtNetTest( cmCtx_t* ctx, bool mstrFl );
  110. /*
  111. Synchronization Protocol:
  112. Machine A Machine B
  113. ================================== ====================================
  114. broadcast 'hello' ------------------=-> create node-A w/ ei=0 -------+
  115. |
  116. +<-- create node-B w/ ei=0 <--------=-- send 'node' <----------------+
  117. |
  118. +--> switch(ei,m_t)
  119. | ei < en : send endpt[ei++] -=--> create endpt[] on node-A -->+
  120. | |
  121. | ei == en : ++ei,send 'done' -=------------------------------->+ |
  122. | |
  123. | m_t!='done': send 'done' -=------------------------------->+ |
  124. | |
  125. | (stop) : |
  126. | |
  127. | v
  128. | switch(ei,m_t)
  129. +<-- create endpt[] on node-B <---=----- send endpt[ei++] : ei < en
  130. |
  131. +<---------------------------------=----- send 'done',++ei : ei == en
  132. |
  133. +<---------------------------------=----- send 'done' : m_t!= 'done'
  134. : (stop)
  135. Notes:
  136. 1) 'ei' is the index of the next local end point to transmit.
  137. 2) 'en' is the count of local endpoints.
  138. 3) 'm_t' is the msg type (i.e.'hello','node','endpoint','done')
  139. of the incoming message.
  140. 4) The symbol -=- in the flow chart implies a network transmission.
  141. */
  142. #ifdef __cplusplus
  143. }
  144. #endif
  145. #endif