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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef cmUdpNet_h
  2. #define cmUdpNet_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /*
  7. A cmUdpNet is a wrapper around a single cmUdpPort. This object
  8. maintains an array of remote nodes which map application defined
  9. node label/id's to IP address/port. This allows the application
  10. to communicate in terms of its own id scheme without having to
  11. consider the IP addr/port of the remote nodes.
  12. */
  13. enum
  14. {
  15. kOkUnRC = cmOkRC,
  16. kDuplicateNodeLabelUnRC,
  17. kDuplicateNodeIdUnRC,
  18. kUdpPortFailUnRC,
  19. kInvalidNodeLabelUnRC,
  20. kNodeNotFoundUnRC,
  21. kInvalidNodeAddrUnRC,
  22. kSendFailUnRC,
  23. kGetDataFailUnRC,
  24. kJsonFailUnRC
  25. };
  26. typedef cmRC_t cmUnRC_t;
  27. typedef cmHandle_t cmUdpNetH_t;
  28. extern cmUdpNetH_t cmUdpNetNullHandle;
  29. typedef void (*cmUdpNetCallback_t)( void* cbArg, cmUdpNetH_t h, const char* data, unsigned dataByteCnt, unsigned remoteNodeId );
  30. // Allocate a UDP net manager. To use the manager one of the
  31. // initialization functions must be used configure it.
  32. cmUnRC_t cmUdpNetAlloc( cmCtx_t* ctx, cmUdpNetH_t* hp );
  33. // Allocate and initialize a UDP network manager from
  34. // a JSON script. This function is a simple wrapper for
  35. // calls to cmUdpNetAlloc(), cmUdpNetInitJson(), and
  36. // cmUdpNetEnableListen(h,listenFl).
  37. enum { kListenUnFl=0x01, kNetOptionalUnFl=0x02 };
  38. cmUnRC_t cmUdpNetAllocJson(
  39. cmCtx_t* ctx,
  40. cmUdpNetH_t* hp,
  41. cmJsonH_t jsH,
  42. cmUdpNetCallback_t cbFunc,
  43. void* cbArg,
  44. unsigned flags);
  45. // Release a UDP network manager and any resources it may hold.
  46. cmUnRC_t cmUdpNetFree( cmUdpNetH_t* hp );
  47. // Initialize a UDP net using a previously allocated handle
  48. cmUnRC_t cmUdpNetInit(
  49. cmUdpNetH_t h,
  50. const cmChar_t* nodeLabel,
  51. unsigned nodeId,
  52. cmUdpPort_t nodeSocketPort,
  53. cmUdpNetCallback_t cbFunc,
  54. void* cbArg,
  55. unsigned recvBufByteCnt,
  56. unsigned socketRecvTimeOutMs );
  57. // Initialize a UDP net and register remote nodes using a JSON resource.
  58. cmUnRC_t cmUdpNetInitJson(
  59. cmUdpNetH_t h,
  60. cmJsonH_t jsH,
  61. cmUdpNetCallback_t cbFunc,
  62. void* cbArg );
  63. // Return true if the if the network has been initialized.
  64. bool cmUdpNetIsInitialized( cmUdpNetH_t h );
  65. // Finalize a UDP net. This releases any resources allocated
  66. // via one of the above 'init' functions.
  67. cmUnRC_t cmUdpNetFinal( cmUdpNetH_t h );
  68. // Enable/disable the networks listening port. While in
  69. // 'listening' mode the network internally queue's all arriving
  70. // messages. Messages are then forwarded to the client via
  71. // calls to cmUdpNetReceive().
  72. cmUnRC_t cmUdpNetEnableListen( cmUdpNetH_t h, bool enableFl );
  73. // Return true if the handle is valid.
  74. bool cmUdpNetIsValid( cmUdpNetH_t h );
  75. unsigned cmUdpNetLocalNodeId( cmUdpNetH_t h );
  76. const cmChar_t* cmUdpNetLocalNodeLabel( cmUdpNetH_t h );
  77. // Return the node id associated with a node label or 'cmInvalidId' if the
  78. // label is not found.
  79. unsigned cmUdpNetNodeLabelToId( cmUdpNetH_t h, const cmChar_t* label );
  80. // Return the node label associated with a node id or NULL if the id
  81. // is not found.
  82. const cmChar_t* cmUdpNetNodeIdToLabel( cmUdpNetH_t h, unsigned id );
  83. // Get the total count of nodes on the network. This count includes the local node.
  84. unsigned cmUdpNetNodeCount( cmUdpNetH_t h );
  85. // Return the node id of each network node.
  86. unsigned cmUdpNetNodeId( cmUdpNetH_t h, unsigned nodeIdx );
  87. // Register a remote node.
  88. cmUnRC_t cmUdpNetRegisterRemote(
  89. cmUdpNetH_t h,
  90. const cmChar_t* remoteNodeLabel,
  91. unsigned remoteNodeId,
  92. const char* remoteNodeSockAddr,
  93. cmUdpPort_t remoteNodePort );
  94. // Send a message to a remote network node.
  95. cmUnRC_t cmUdpNetSendById( cmUdpNetH_t h, unsigned remoteNodeId, const void* data, unsigned dataByteCnt );
  96. cmUnRC_t cmUdpNetSendByLabel( cmUdpNetH_t h, const cmChar_t* remoteNodeLabel, const void* data, unsigned dataByteCnt );
  97. // Transmit any waiting incoming messages to the client via the
  98. // cmUdpNetCallback_t callback function provided in the UDP
  99. // network's initialization function.
  100. // On input *msgCntPtr should hold the max. number of
  101. // messages to receive or NULL to receive all available.
  102. // On return *msgCntPtr is set to the actual number of
  103. // messages received.
  104. cmUnRC_t cmUdpNetReceive( cmUdpNetH_t h, unsigned* msgCntPtr );
  105. cmUnRC_t cmUdpNetPrintNodes( cmUdpNetH_t h, cmRpt_t* rpt );
  106. void cmUdpNetReport( cmUdpNetH_t h, cmRpt_t* rpt );
  107. cmRC_t cmUdpNetTest( cmCtx_t* ctx, int argc, char* argv[] );
  108. #ifdef __cplusplus
  109. }
  110. #endif
  111. #endif