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.

cmUdpNet.h 4.4KB

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