libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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