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 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. // 'cbFunc' will be called within the context of cmRtNetReceive() to receive
  29. // incoming network messages.
  30. cmRtNetRC_t cmRtNetAlloc( cmCtx_t* ctx, cmRtNetH_t* hp, cmUdpCallback_t cbFunc, void* cbArg );
  31. cmRtNetRC_t cmRtNetFree( cmRtNetH_t* hp );
  32. bool cmRtNetIsValid( cmRtNetH_t h );
  33. // Get the local host name for this machine. This function
  34. // is synonomous with gethostname().
  35. const cmChar_t* cmRtNetLocalHostName( cmRtNetH_t h );
  36. // Initialize the local network node.
  37. // 'bcastAddr' is the network broadcast address (e.g. 192.168.15.255).
  38. // 'nodeLabel' is the local network node label
  39. // 'ipAddr' may be set to NULL to use any available IP address.
  40. // 'ipPort' refers to the socket port (which may need to be made available
  41. // by the machine firewall cfg.)
  42. cmRtNetRC_t cmRtNetInitialize( cmRtNetH_t h, const cmChar_t* bcastAddr, const cmChar_t* nodeLabel, const cmChar_t* ipAddr, cmUdpPort_t ipPort );
  43. bool cmRtNetIsInitialized( cmRtNetH_t h );
  44. // Register the local endpoints.
  45. // Endpoints may only be registered once the network is initialized via
  46. // cmRtNetInitialize().
  47. // Remote nodes will be able to send messages to these endpoints by
  48. // referring to (nodeLabel/endPtLabel)
  49. cmRtNetRC_t cmRtNetRegisterEndPoint( cmRtNetH_t h, unsigned rtSubIdx, const cmChar_t* endPtLabel, unsigned endPtId );
  50. // Delete all nodes and endpoints.
  51. cmRtNetRC_t cmRtNetFinalize( cmRtNetH_t h );
  52. // Broadcast the 'hello' to all machines listening on the
  53. // broadcast addresss. This starts the synchronization sequence
  54. cmRtNetRC_t cmRtNetDoSync( cmRtNetH_t h );
  55. // This function must be polled to receive incoming network messages
  56. // via the callback funcion 'cbFunc' as passed to cmRtNetAlloc().
  57. // Note that all messages received via 'cbFunc' will be prefixed with
  58. // an cmRtNetMsg_t header (See cmRtSysMsg.h).
  59. cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h );
  60. // Get an end point handle for use with cmRtNetSend.
  61. cmRtNetRC_t cmRtNetEndpointHandle( cmRtNetH_t h, const cmChar_t* nodeLabel, unsigned rtSubIdx, const cmChar_t* endptLabel, cmRtNetEndptH_t* hp );
  62. // Send a message to a remote endpoint.
  63. cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, cmRtNetEndptH_t epH, const void* msg, unsigned msgByteCnt );
  64. // Send a message to a remote endpoint. This function is a composite
  65. // of cmRtNetEndpointHandle() and cmRtNetSend().
  66. cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, unsigned rtSubIdx, const cmChar_t* endptLabel, const void* msg, unsigned msgByteCnt );
  67. // Enable/disable synchronization protocol reporting.
  68. // Return the previous state of the report sync. flag.
  69. bool cmRtNetReportSyncEnable( cmRtNetH_t h, bool enableFl );
  70. bool cmRtNetReportSyncIsEnabled( cmRtNetH_t h );
  71. void cmRtNetReport( cmRtNetH_t h );
  72. void cmRtNetTest( cmCtx_t* ctx, bool mstrFl );
  73. /*
  74. Synchronization Protocol:
  75. Machine A Machine B
  76. ================================== ====================================
  77. broadcast 'hello' ------------------=-> create node-A w/ ei=0 -------+
  78. |
  79. +<-- create node-B w/ ei=0 <--------=-- send 'node' <----------------+
  80. |
  81. +--> switch(ei,m_t)
  82. | ei < en : send endpt[ei++] -=--> create endpt[] on node-A -->+
  83. | |
  84. | ei == en : ++ei,send 'done' -=------------------------------->+ |
  85. | |
  86. | m_t!='done': send 'done' -=------------------------------->+ |
  87. | |
  88. | (stop) : |
  89. | |
  90. | v
  91. | switch(ei,m_t)
  92. +<-- create endpt[] on node-B <---=----- send endpt[ei++] : ei < en
  93. |
  94. +<---------------------------------=----- send 'done',++ei : ei == en
  95. |
  96. +<---------------------------------=----- send 'done' : m_t!= 'done'
  97. : (stop)
  98. Notes:
  99. 1) 'ei' is the index of the next local end point to transmit.
  100. 2) 'en' is the count of local endpoints.
  101. 3) 'm_t' is the msg type (i.e.'hello','node','endpoint','done')
  102. of the incoming message.
  103. 4) The symbol -=- in the flow chart implies a network transmission.
  104. */
  105. #ifdef __cplusplus
  106. }
  107. #endif
  108. #endif