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.

cmVirtNet.h 3.1KB

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