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.

226 lines
8.7KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004-2008 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #ifndef __JackClient__
  17. #define __JackClient__
  18. #include "JackClientInterface.h"
  19. #include "JackThread.h"
  20. #include "JackConstants.h"
  21. #include "JackSynchro.h"
  22. #include "JackPlatformPlug.h"
  23. #include "JackChannel.h"
  24. #include "JackRequest.h"
  25. #include "JackMetadata.h"
  26. #include "varargs.h"
  27. #include <list>
  28. namespace Jack
  29. {
  30. class JackGraphManager;
  31. class JackServer;
  32. class JackEngine;
  33. struct JackClientControl;
  34. struct JackEngineControl;
  35. /*!
  36. \brief The base class for clients: share part of the implementation for JackInternalClient and JackLibClient.
  37. */
  38. class SERVER_EXPORT JackClient : public JackClientInterface, public JackRunnableInterface
  39. {
  40. friend class JackDebugClient;
  41. protected:
  42. JackProcessCallback fProcess;
  43. JackGraphOrderCallback fGraphOrder;
  44. JackXRunCallback fXrun;
  45. JackShutdownCallback fShutdown;
  46. JackInfoShutdownCallback fInfoShutdown;
  47. JackThreadInitCallback fInit;
  48. JackBufferSizeCallback fBufferSize;
  49. JackSampleRateCallback fSampleRate;
  50. JackClientRegistrationCallback fClientRegistration;
  51. JackFreewheelCallback fFreewheel;
  52. JackPortRegistrationCallback fPortRegistration;
  53. JackPortConnectCallback fPortConnect;
  54. JackPortRenameCallback fPortRename;
  55. JackTimebaseCallback fTimebase;
  56. JackSyncCallback fSync;
  57. JackThreadCallback fThreadFun;
  58. JackSessionCallback fSession;
  59. JackLatencyCallback fLatency;
  60. JackPropertyChangeCallback fPropertyChange;
  61. void* fProcessArg;
  62. void* fGraphOrderArg;
  63. void* fXrunArg;
  64. void* fShutdownArg;
  65. void* fInfoShutdownArg;
  66. void* fInitArg;
  67. void* fBufferSizeArg;
  68. void* fSampleRateArg;
  69. void* fClientRegistrationArg;
  70. void* fFreewheelArg;
  71. void* fPortRegistrationArg;
  72. void* fPortConnectArg;
  73. void* fPortRenameArg;
  74. void* fTimebaseArg;
  75. void* fSyncArg;
  76. void* fThreadFunArg;
  77. void* fSessionArg;
  78. void* fLatencyArg;
  79. void* fPropertyChangeArg;
  80. char fServerName[JACK_SERVER_NAME_SIZE+1];
  81. JackThread fThread; /*! Thread to execute the Process function */
  82. detail::JackClientChannelInterface* fChannel;
  83. JackSynchro* fSynchroTable;
  84. std::list<jack_port_id_t> fPortList;
  85. JackSessionReply fSessionReply;
  86. int StartThread();
  87. void SetupDriverSync(bool freewheel);
  88. bool IsActive();
  89. void CallSyncCallback();
  90. void CallTimebaseCallback();
  91. virtual int ClientNotifyImp(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value);
  92. inline void DummyCycle();
  93. inline void ExecuteThread();
  94. inline bool WaitSync();
  95. inline void SignalSync();
  96. inline int CallProcessCallback();
  97. inline void End();
  98. inline void Error();
  99. inline jack_nframes_t CycleWaitAux();
  100. inline void CycleSignalAux(int status);
  101. inline void CallSyncCallbackAux();
  102. inline void CallTimebaseCallbackAux();
  103. inline int ActivateAux();
  104. inline void InitAux();
  105. inline void SetupRealTime();
  106. int HandleLatencyCallback(int status);
  107. public:
  108. JackClient(JackSynchro* table);
  109. virtual ~JackClient();
  110. char* GetServerName() { return fServerName; }
  111. virtual int Open(const char* server_name, const char* name, jack_uuid_t uuid, jack_options_t options, jack_status_t* status) = 0;
  112. virtual int Close();
  113. virtual JackGraphManager* GetGraphManager() const = 0;
  114. virtual JackEngineControl* GetEngineControl() const = 0;
  115. // Notifications
  116. virtual int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
  117. virtual int Activate();
  118. virtual int Deactivate();
  119. // Context
  120. virtual int SetBufferSize(jack_nframes_t buffer_size);
  121. virtual int SetFreeWheel(int onoff);
  122. virtual int ComputeTotalLatencies();
  123. virtual void ShutDown(jack_status_t code, const char* message);
  124. virtual jack_native_thread_t GetThreadID();
  125. // Port management
  126. virtual int PortRegister(const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size);
  127. virtual int PortUnRegister(jack_port_id_t port);
  128. virtual int PortConnect(const char* src, const char* dst);
  129. virtual int PortDisconnect(const char* src, const char* dst);
  130. virtual int PortDisconnect(jack_port_id_t src);
  131. virtual int PortIsMine(jack_port_id_t port_index);
  132. virtual int PortRename(jack_port_id_t port_index, const char* name);
  133. // Transport
  134. virtual int ReleaseTimebase();
  135. virtual int SetSyncCallback(JackSyncCallback sync_callback, void* arg);
  136. virtual int SetSyncTimeout(jack_time_t timeout);
  137. virtual int SetTimebaseCallback(int conditional, JackTimebaseCallback timebase_callback, void* arg);
  138. virtual void TransportLocate(jack_nframes_t frame);
  139. virtual jack_transport_state_t TransportQuery(jack_position_t* pos);
  140. virtual jack_nframes_t GetCurrentTransportFrame();
  141. virtual int TransportReposition(const jack_position_t* pos);
  142. virtual void TransportStart();
  143. virtual void TransportStop();
  144. // Callbacks
  145. virtual void OnShutdown(JackShutdownCallback callback, void *arg);
  146. virtual void OnInfoShutdown(JackInfoShutdownCallback callback, void *arg);
  147. virtual int SetProcessCallback(JackProcessCallback callback, void* arg);
  148. virtual int SetXRunCallback(JackXRunCallback callback, void* arg);
  149. virtual int SetInitCallback(JackThreadInitCallback callback, void* arg);
  150. virtual int SetGraphOrderCallback(JackGraphOrderCallback callback, void* arg);
  151. virtual int SetBufferSizeCallback(JackBufferSizeCallback callback, void* arg);
  152. virtual int SetSampleRateCallback(JackBufferSizeCallback callback, void* arg);
  153. virtual int SetClientRegistrationCallback(JackClientRegistrationCallback callback, void* arg);
  154. virtual int SetFreewheelCallback(JackFreewheelCallback callback, void* arg);
  155. virtual int SetPortRegistrationCallback(JackPortRegistrationCallback callback, void* arg);
  156. virtual int SetPortConnectCallback(JackPortConnectCallback callback, void *arg);
  157. virtual int SetPortRenameCallback(JackPortRenameCallback callback, void *arg);
  158. virtual int SetSessionCallback(JackSessionCallback callback, void *arg);
  159. virtual int SetLatencyCallback(JackLatencyCallback callback, void *arg);
  160. virtual int SetPropertyChangeCallback(JackPropertyChangeCallback callback, void* arg);
  161. // Internal clients
  162. virtual char* GetInternalClientName(int ref);
  163. virtual int InternalClientHandle(const char* client_name, jack_status_t* status);
  164. virtual int InternalClientLoad(const char* client_name, jack_options_t options, jack_status_t* status, jack_varargs_t* va);
  165. virtual void InternalClientUnload(int ref, jack_status_t* status);
  166. // RT Thread
  167. jack_nframes_t CycleWait();
  168. void CycleSignal(int status);
  169. virtual int SetProcessThread(JackThreadCallback fun, void *arg);
  170. // Session API
  171. virtual jack_session_command_t* SessionNotify(const char* target, jack_session_event_type_t type, const char* path);
  172. virtual int SessionReply(jack_session_event_t* ev);
  173. virtual char* GetUUIDForClientName(const char* client_name);
  174. virtual char* GetClientNameByUUID(const char* uuid);
  175. virtual int ReserveClientName(const char* client_name, const char* uuid);
  176. virtual int ClientHasSessionCallback(const char* client_name);
  177. // Metadata API
  178. virtual int PropertyChangeNotify(jack_uuid_t subject, const char* key, jack_property_change_t change);
  179. // JackRunnableInterface interface
  180. bool Init();
  181. bool Execute();
  182. };
  183. } // end of namespace
  184. #endif