libcm is a C development framework with an emphasis on audio signal processing applications.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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, 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. cmRtNetRC_t cmRtNetReceive( cmRtNetH_t h );
  58. // Get an end point handle for use with cmRtNetSend.
  59. cmRtNetRC_t cmRtNetEndpointHandle( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endptLabel, cmRtNetEndptH_t* hp );
  60. // Send a message to a remote endpoint.
  61. cmRtNetRC_t cmRtNetSend( cmRtNetH_t h, cmRtNetEndptH_t epH, const void* msg, unsigned msgByteCnt );
  62. // Send a message to a remote endpoint. This function is a composite
  63. // of cmRtNetEndpointHandle() and cmRtNetSend().
  64. cmRtNetRC_t cmRtNetSendByLabels( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* endptLabel, const void* msg, unsigned msgByteCnt );
  65. // Enable/disable synchronization protocol reporting.
  66. // Return the previous state of the report sync. flag.
  67. bool cmRtNetReportSyncEnable( cmRtNetH_t h, bool enableFl );
  68. bool cmRtNetReportSyncIsEnabled( cmRtNetH_t h );
  69. void cmRtNetReport( cmRtNetH_t h );
  70. void cmRtNetTest( cmCtx_t* ctx, bool mstrFl );
  71. /*
  72. Synchronization Protocol:
  73. Machine A Machine B
  74. ================================== ====================================
  75. broadcast 'hello' --------------------> create node-A w/ ei=0 -------+
  76. |
  77. +<-- create node-B w/ ei=0 <----------- send 'node' <----------------+
  78. |
  79. +--> switch(ei,m_t)
  80. | ei < en : send endpt[ei++] ---> create endpt[] on node-A -->+
  81. | |
  82. | ei == en : ++ei,send 'done' -------------------------------->+ |
  83. | |
  84. | m_t!='done' : send 'done' -------------------------------->+ |
  85. | |
  86. | (stop) : |
  87. | |
  88. | v
  89. | switch(ei,m_t)
  90. +<-- create endpt[] on node-B <--------- send endpt[ei++] : ei < en
  91. |
  92. +<--------------------------------------- send 'done',++ei : ei == en
  93. |
  94. +<--------------------------------------- send 'done' : m_t!= 'done'
  95. : (stop)
  96. Notes:
  97. 1) 'ei' is the index of the next local end point to transmit.
  98. 2) 'en' is the count of local endpoints.
  99. 3) 'm_t' is the msg type (i.e.'hello','node','endpoint','done')
  100. of the incoming message.
  101. */
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif