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.

196 lines
7.0KB

  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 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 __JackClient__
  17. #define __JackClient__
  18. #include "JackClientInterface.h"
  19. #include "JackThread.h"
  20. #include "JackConstants.h"
  21. #include "JackSynchro.h"
  22. #include "types.h"
  23. #include "transport_types.h"
  24. #include "varargs.h"
  25. #include <list>
  26. namespace Jack
  27. {
  28. class JackClientChannelInterface;
  29. class JackGraphManager;
  30. class JackServer;
  31. class JackEngine;
  32. class JackSynchro;
  33. struct JackClientControl;
  34. struct JackEngineControl;
  35. class JackSyncInterface;
  36. typedef void (*JackShutdownCallback)(void *arg);
  37. /*!
  38. \brief The base class for clients: share part of the implementation for JackInternalClient and JackLibClient.
  39. */
  40. class JackClient : public JackClientInterface, public JackRunnableInterface
  41. {
  42. friend class JackDebugClient;
  43. protected:
  44. JackProcessCallback fProcess;
  45. JackGraphOrderCallback fGraphOrder;
  46. JackXRunCallback fXrun;
  47. JackShutdownCallback fShutdown;
  48. JackThreadInitCallback fInit;
  49. JackBufferSizeCallback fBufferSize;
  50. JackClientRegistrationCallback fClientRegistration;
  51. JackFreewheelCallback fFreewheel;
  52. JackPortRegistrationCallback fPortRegistration;
  53. JackPortConnectCallback fPortConnect;
  54. JackTimebaseCallback fTimebase;
  55. JackSyncCallback fSync;
  56. JackThreadCallback fThreadFun;
  57. void* fProcessArg;
  58. void* fGraphOrderArg;
  59. void* fXrunArg;
  60. void* fShutdownArg;
  61. void* fInitArg;
  62. void* fBufferSizeArg;
  63. void* fClientRegistrationArg;
  64. void* fFreewheelArg;
  65. void* fPortRegistrationArg;
  66. void* fPortConnectArg;
  67. void* fTimebaseArg;
  68. void* fSyncArg;
  69. void* fThreadFunArg;
  70. int fConditionnal;
  71. char fServerName[64];
  72. JackThread* fThread; /*! Thread to execute the Process function */
  73. JackClientChannelInterface* fChannel;
  74. JackSynchro** fSynchroTable;
  75. std::list<jack_port_id_t> fPortList;
  76. int StartThread();
  77. void SetupDriverSync(bool freewheel);
  78. bool IsActive();
  79. void CallSyncCallback();
  80. void CallTimebaseCallback();
  81. int RequestNewPos(jack_position_t* pos);
  82. virtual int ClientNotifyImp(int refnum, const char* name, int notify, int sync, int value1, int value);
  83. // Fons Adriaensen thread model
  84. inline bool WaitFirstSync();
  85. inline void ExecuteThread();
  86. inline bool WaitSync();
  87. inline void SignalSync();
  88. inline int CallProcessCallback();
  89. inline int End();
  90. inline int Error();
  91. public:
  92. JackClient();
  93. JackClient(JackSynchro** table);
  94. virtual ~JackClient();
  95. virtual int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status) = 0;
  96. virtual int Close();
  97. virtual JackGraphManager* GetGraphManager() const = 0;
  98. virtual JackEngineControl* GetEngineControl() const = 0;
  99. // Notifications
  100. virtual int ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2);
  101. virtual int Activate();
  102. virtual int Deactivate();
  103. // Context
  104. virtual int SetBufferSize(jack_nframes_t buffer_size);
  105. virtual int SetFreeWheel(int onoff);
  106. virtual void ShutDown();
  107. virtual pthread_t GetThreadID();
  108. // Port management
  109. virtual int PortRegister(const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size);
  110. virtual int PortUnRegister(jack_port_id_t port);
  111. virtual int PortConnect(const char* src, const char* dst);
  112. virtual int PortDisconnect(const char* src, const char* dst);
  113. virtual int PortConnect(jack_port_id_t src, jack_port_id_t dst);
  114. virtual int PortDisconnect(jack_port_id_t src);
  115. virtual int PortIsMine(jack_port_id_t port_index);
  116. // Transport
  117. virtual int ReleaseTimebase();
  118. virtual int SetSyncCallback(JackSyncCallback sync_callback, void* arg);
  119. virtual int SetSyncTimeout(jack_time_t timeout);
  120. virtual int SetTimebaseCallback(int conditional, JackTimebaseCallback timebase_callback, void* arg);
  121. virtual int TransportLocate(jack_nframes_t frame);
  122. virtual jack_transport_state_t TransportQuery(jack_position_t* pos);
  123. virtual jack_nframes_t GetCurrentTransportFrame();
  124. virtual int TransportReposition(jack_position_t* pos);
  125. virtual void TransportStart();
  126. virtual void TransportStop();
  127. // Callbacks
  128. virtual void OnShutdown(JackShutdownCallback callback, void *arg);
  129. virtual int SetProcessCallback(JackProcessCallback callback, void* arg);
  130. virtual int SetXRunCallback(JackXRunCallback callback, void* arg);
  131. virtual int SetInitCallback(JackThreadInitCallback callback, void* arg);
  132. virtual int SetGraphOrderCallback(JackGraphOrderCallback callback, void* arg);
  133. virtual int SetBufferSizeCallback(JackBufferSizeCallback callback, void* arg);
  134. virtual int SetClientRegistrationCallback(JackClientRegistrationCallback callback, void* arg);
  135. virtual int SetFreewheelCallback(JackFreewheelCallback callback, void* arg);
  136. virtual int SetPortRegistrationCallback(JackPortRegistrationCallback callback, void* arg);
  137. virtual int SetPortConnectCallback(JackPortConnectCallback callback, void *arg);
  138. // Internal clients
  139. virtual char* GetInternalClientName(int ref);
  140. virtual int InternalClientHandle(const char* client_name, jack_status_t* status);
  141. virtual int InternalClientLoad(const char* client_name, jack_options_t options, jack_status_t* status, jack_varargs_t* va);
  142. virtual void InternalClientUnload(int ref, jack_status_t* status);
  143. // Fons Adriaensen thread model
  144. virtual jack_nframes_t Wait(int status);
  145. virtual jack_nframes_t CycleWait();
  146. void CycleSignal(int status);
  147. int SetProcessThread(JackThreadCallback fun, void *arg);
  148. // JackRunnableInterface interface
  149. bool Init();
  150. bool Execute();
  151. };
  152. // Each "side" server and client will implement this to get the shared graph manager, engine control and inter-process synchro table.
  153. extern JackGraphManager* GetGraphManager();
  154. extern JackEngineControl* GetEngineControl();
  155. extern JackSynchro** GetSynchroTable();
  156. } // end of namespace
  157. #endif