jack2 codebase
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.

145 lines
4.0KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2008 Romain Moret at Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #ifndef __JackNetInterface__
  17. #define __JackNetInterface__
  18. #include "JackNetTool.h"
  19. namespace Jack
  20. {
  21. /**
  22. \Brief This class describes the basic Net Interface, used by both master and slave
  23. */
  24. class EXPORT JackNetInterface
  25. {
  26. protected:
  27. session_params_t fParams;
  28. JackNetSocket fSocket;
  29. char* fMulticastIP;
  30. uint fNSubProcess;
  31. //headers
  32. packet_header_t fTxHeader;
  33. packet_header_t fRxHeader;
  34. //network buffers
  35. char* fTxBuffer;
  36. char* fRxBuffer;
  37. char* fTxData;
  38. char* fRxData;
  39. //jack buffers
  40. NetMidiBuffer* fNetMidiCaptureBuffer;
  41. NetMidiBuffer* fNetMidiPlaybackBuffer;
  42. NetAudioBuffer* fNetAudioCaptureBuffer;
  43. NetAudioBuffer* fNetAudioPlaybackBuffer;
  44. //sizes
  45. int fAudioRxLen;
  46. int fAudioTxLen;
  47. int fPayloadSize;
  48. virtual void SetParams();
  49. //virtual methods : depends on the sub class master/slave
  50. virtual bool Init() = 0;
  51. virtual int SyncRecv() = 0;
  52. virtual int SyncSend() = 0;
  53. virtual int DataRecv() = 0;
  54. virtual int DataSend() = 0;
  55. virtual int Send ( size_t size, int flags ) = 0;
  56. virtual int Recv ( size_t size, int flags ) = 0;
  57. JackNetInterface()
  58. {}
  59. JackNetInterface ( const char* ip, int port );
  60. JackNetInterface ( session_params_t& params, JackNetSocket& socket, const char* multicast_ip );
  61. public:
  62. virtual ~JackNetInterface();
  63. };
  64. /**
  65. \Brief This class describes the Net Interface for slaves (NetDriver and NetAdapter)
  66. */
  67. class EXPORT JackNetSlaveInterface : public JackNetInterface
  68. {
  69. protected:
  70. bool Init();
  71. net_status_t GetNetMaster();
  72. net_status_t SendMasterStartSync();
  73. void SetParams();
  74. int SyncRecv();
  75. int SyncSend();
  76. int DataRecv();
  77. int DataSend();
  78. int Recv ( size_t size, int flags );
  79. int Send ( size_t size, int flags );
  80. public:
  81. JackNetSlaveInterface()
  82. {}
  83. JackNetSlaveInterface ( const char* ip, int port ) : JackNetInterface ( ip, port )
  84. {}
  85. ~JackNetSlaveInterface()
  86. {
  87. SocketAPIEnd();
  88. }
  89. };
  90. /**
  91. \Brief This class describes the Net Interface for masters (NetMaster)
  92. */
  93. class EXPORT JackNetMasterInterface : public JackNetInterface
  94. {
  95. protected:
  96. bool fRunning;
  97. bool Init();
  98. void SetParams();
  99. void Exit();
  100. int SyncRecv();
  101. int SyncSend();
  102. int DataRecv();
  103. int DataSend();
  104. int Send ( size_t size, int flags );
  105. int Recv ( size_t size, int flags );
  106. public:
  107. JackNetMasterInterface() : fRunning ( false )
  108. {}
  109. JackNetMasterInterface ( session_params_t& params, JackNetSocket& socket, const char* multicast_ip )
  110. : JackNetInterface ( params, socket, multicast_ip )
  111. {}
  112. ~JackNetMasterInterface()
  113. {}
  114. };
  115. }
  116. #endif