libcm is a C development framework with an emphasis on audio signal processing applications.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

cmVirtNet.h 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef cmVirtNet_h
  2. #define cmVirtNet_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. //( { file_desc:"Wrapper object for cmUdpNet to handle UDP network communications." kw:[network]}
  7. enum
  8. {
  9. kOkVnRC = cmOkRC,
  10. kUdpNetFailVnRC,
  11. kNodeNotFoundVnRC,
  12. kDuplicateNodeIdVnRC,
  13. kDuplicateNodeLabelVnRC,
  14. kQueueFailVnRC
  15. };
  16. typedef cmHandle_t cmVnH_t;
  17. typedef cmRC_t cmVnRC_t;
  18. extern cmVnH_t cmVnNullHandle;
  19. //
  20. typedef cmVnRC_t (*cmVnCb_t)( void* cbArg, unsigned srcNodeId, unsigned byteCnt, const char* buf );
  21. // Create a virtual network with a single node that represents the owner.
  22. // cbFunc() will be called to receive incoming msg's when the owning thread calls cmVnReceive().
  23. cmVnRC_t cmVnCreate(
  24. cmCtx_t* ctx,
  25. cmVnH_t* hp,
  26. cmVnCb_t cbFunc, // owner msg receive callback function
  27. void* cbArg, // owner supplied callback argument for cbFunc
  28. const cmChar_t* ownerNodelabel, // owners node label (must be unique among all nodes)
  29. unsigned ownerNodeId, // owners node id (must be unique among all nodes)
  30. unsigned udpRecvBufByteCnt, // size of the UDP incoming data buffer
  31. unsigned updRecvTimeOutMs, // UDP time out period while waiting for incoming data
  32. const cmChar_t* ipAddr, // this machines IP
  33. unsigned ipPort ); // this nodes port (must be unique among all local nodes)
  34. // Destroy and release any resources held by a virtual net created with cmVnCreate().
  35. cmVnRC_t cmVnDestroy( cmVnH_t* hp );
  36. bool cmVnIsValid( cmVnH_t h );
  37. // Put the network into listening mode. This function enables and disables
  38. // the UDP port listening thread.
  39. cmVnRC_t cmVnEnableListen( cmVnH_t h, bool enableFl );
  40. // Local nodes are nodes which are in the owners address space but controlled by a different thread.
  41. //
  42. cmVnRC_t cmVnCreateLocalNode( cmVnH_t h, const cmChar_t* label, unsigned nodeId, cmVnH_t localNet, unsigned queBufByteCnt );
  43. // Remote nodes are outside the owners address space and are communicated with via UDP.
  44. cmVnRC_t cmVnCreateRemoteNode( cmVnH_t h, const cmChar_t* label, unsigned nodeId, const cmChar_t* ipAddr, unsigned ipPort );
  45. // Send a msg from the owner node to another node.
  46. cmVnRC_t cmVnSendById( cmVnH_t h, unsigned nodeId, unsigned byteCnt, const cmChar_t* buf );
  47. cmVnRC_t cmVnSendByLabel( cmVnH_t h, const cmChar_t* nodeLabel, unsigned byteCnt, const cmChar_t* buf );
  48. // Recv a msg from a local node. This function may be called outside the 'owner' thread.
  49. // This function stores the incoming msg in a muliple-producer single-consumer queue.
  50. cmVnRC_t cmVnRecvFromLocal( cmVnH_t h, unsigned srcNodeId, unsigned byteCnt, const cmChar_t* buf );
  51. // Calling this function results in callback's to the cmVnCb_t function.
  52. cmVnRC_t cmVnReceive( cmVnH_t h, unsigned* msgCntPtr );
  53. cmVnRC_t cmVnTest( cmCtx_t* ctx );
  54. //)
  55. #ifdef __cplusplus
  56. }
  57. #endif
  58. #endif