libcm is a C development framework with an emphasis on audio signal processing applications.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

cmUdpNet.h 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. // The node information (nodeLabel,nodeId,nodeSocketPort) refers
  49. // to the local node. The callback information (cbFunc,cbArg)
  50. // are used during cmUdpNetReceive() to receive incoming
  51. // information from the local node.
  52. cmUnRC_t cmUdpNetInit(
  53. cmUdpNetH_t h,
  54. const cmChar_t* nodeLabel,
  55. unsigned nodeId,
  56. cmUdpPort_t nodeSocketPort,
  57. cmUdpNetCallback_t cbFunc,
  58. void* cbArg,
  59. unsigned recvBufByteCnt,
  60. unsigned socketRecvTimeOutMs );
  61. // Initialize a UDP net and register remote nodes using a JSON resource.
  62. cmUnRC_t cmUdpNetInitJson(
  63. cmUdpNetH_t h,
  64. cmJsonH_t jsH,
  65. cmUdpNetCallback_t cbFunc,
  66. void* cbArg );
  67. // Return true if the if the network has been initialized.
  68. bool cmUdpNetIsInitialized( cmUdpNetH_t h );
  69. // Finalize a UDP net. This releases any resources allocated
  70. // via one of the above 'init' functions.
  71. cmUnRC_t cmUdpNetFinal( cmUdpNetH_t h );
  72. // Enable/disable the networks listening port. While in
  73. // 'listening' mode the network internally queue's all arriving
  74. // messages. Messages are then forwarded to the client via
  75. // calls to cmUdpNetReceive().
  76. cmUnRC_t cmUdpNetEnableListen( cmUdpNetH_t h, bool enableFl );
  77. // Return true if the handle is valid.
  78. bool cmUdpNetIsValid( cmUdpNetH_t h );
  79. unsigned cmUdpNetLocalNodeId( cmUdpNetH_t h );
  80. const cmChar_t* cmUdpNetLocalNodeLabel( cmUdpNetH_t h );
  81. // Return the node id associated with a node label or 'cmInvalidId' if the
  82. // label is not found.
  83. unsigned cmUdpNetNodeLabelToId( cmUdpNetH_t h, const cmChar_t* label );
  84. // Return the node label associated with a node id or NULL if the id
  85. // is not found.
  86. const cmChar_t* cmUdpNetNodeIdToLabel( cmUdpNetH_t h, unsigned id );
  87. // Get the total count of nodes on the network. This count includes the local node.
  88. unsigned cmUdpNetNodeCount( cmUdpNetH_t h );
  89. // Return the node id of each network node.
  90. unsigned cmUdpNetNodeId( cmUdpNetH_t h, unsigned nodeIdx );
  91. // Register a remote node.
  92. cmUnRC_t cmUdpNetRegisterRemote(
  93. cmUdpNetH_t h,
  94. const cmChar_t* remoteNodeLabel,
  95. unsigned remoteNodeId,
  96. const char* remoteNodeSockAddr,
  97. cmUdpPort_t remoteNodePort );
  98. // Send a message to a remote network node.
  99. cmUnRC_t cmUdpNetSendById( cmUdpNetH_t h, unsigned remoteNodeId, const void* data, unsigned dataByteCnt );
  100. cmUnRC_t cmUdpNetSendByLabel( cmUdpNetH_t h, const cmChar_t* remoteNodeLabel, const void* data, unsigned dataByteCnt );
  101. // Transmit any waiting incoming messages to the client via the
  102. // cmUdpNetCallback_t callback function provided
  103. // cmUdpNetInit().
  104. // On input *msgCntPtr should hold the max. number of
  105. // messages to receive or NULL to receive all available.
  106. // On return *msgCntPtr is set to the actual number of
  107. // messages received.
  108. cmUnRC_t cmUdpNetReceive( cmUdpNetH_t h, unsigned* msgCntPtr );
  109. cmUnRC_t cmUdpNetPrintNodes( cmUdpNetH_t h, cmRpt_t* rpt );
  110. void cmUdpNetReport( cmUdpNetH_t h, cmRpt_t* rpt );
  111. cmRC_t cmUdpNetTest( cmCtx_t* ctx, int argc, const char* argv[] );
  112. #ifdef __cplusplus
  113. }
  114. #endif
  115. #endif