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.

173 lines
6.1KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004-2006 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. protected:
  43. JackProcessCallback fProcess;
  44. JackGraphOrderCallback fGraphOrder;
  45. JackXRunCallback fXrun;
  46. JackShutdownCallback fShutdown;
  47. JackThreadInitCallback fInit;
  48. JackBufferSizeCallback fBufferSize;
  49. JackClientRegistrationCallback fClientRegistration;
  50. JackFreewheelCallback fFreewheel;
  51. JackPortRegistrationCallback fPortRegistration;
  52. JackTimebaseCallback fTimebase;
  53. JackSyncCallback fSync;
  54. void* fProcessArg;
  55. void* fGraphOrderArg;
  56. void* fXrunArg;
  57. void* fShutdownArg;
  58. void* fInitArg;
  59. void* fBufferSizeArg;
  60. void* fClientRegistrationArg;
  61. void* fFreewheelArg;
  62. void* fPortRegistrationArg;
  63. void* fTimebaseArg;
  64. void* fSyncArg;
  65. int fConditionnal;
  66. JackThread* fThread; /*! Thread to execute the Process function */
  67. JackClientChannelInterface* fChannel;
  68. JackSynchro** fSynchroTable;
  69. std::list<jack_port_id_t> fPortList;
  70. int StartThread();
  71. void SetupDriverSync(bool freewheel);
  72. bool IsActive();
  73. bool CallProcessCallback();
  74. void CallSyncCallback();
  75. void CallTimebaseCallback();
  76. int RequestNewPos(jack_position_t* pos);
  77. virtual int ClientNotifyImp(int refnum, const char* name, int notify, int sync, int value);
  78. public:
  79. JackClient();
  80. JackClient(JackSynchro** table);
  81. virtual ~JackClient();
  82. virtual int Open(const char* name, jack_options_t options, jack_status_t* status) = 0;
  83. virtual int Close();
  84. virtual JackGraphManager* GetGraphManager() const = 0;
  85. virtual JackEngineControl* GetEngineControl() const = 0;
  86. // Notifications
  87. virtual int ClientNotify(int refnum, const char* name, int notify, int sync, int value);
  88. virtual int Activate();
  89. virtual int Deactivate();
  90. // Context
  91. virtual int SetBufferSize(jack_nframes_t buffer_size);
  92. virtual int SetFreeWheel(int onoff);
  93. virtual void ShutDown();
  94. virtual pthread_t GetThreadID();
  95. // Port management
  96. virtual int PortRegister(const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size);
  97. virtual int PortUnRegister(jack_port_id_t port);
  98. virtual int PortConnect(const char* src, const char* dst);
  99. virtual int PortDisconnect(const char* src, const char* dst);
  100. virtual int PortConnect(jack_port_id_t src, jack_port_id_t dst);
  101. virtual int PortDisconnect(jack_port_id_t src);
  102. virtual int PortIsMine(jack_port_id_t port_index);
  103. // Transport
  104. virtual int ReleaseTimebase();
  105. virtual int SetSyncCallback(JackSyncCallback sync_callback, void* arg);
  106. virtual int SetSyncTimeout(jack_time_t timeout);
  107. virtual int SetTimebaseCallback(int conditional, JackTimebaseCallback timebase_callback, void* arg);
  108. virtual int TransportLocate(jack_nframes_t frame);
  109. virtual jack_transport_state_t TransportQuery(jack_position_t* pos);
  110. virtual jack_nframes_t GetCurrentTransportFrame();
  111. virtual int TransportReposition(jack_position_t* pos);
  112. virtual void TransportStart();
  113. virtual void TransportStop();
  114. // Callbacks
  115. virtual void OnShutdown(JackShutdownCallback callback, void *arg);
  116. virtual int SetProcessCallback(JackProcessCallback callback, void* arg);
  117. virtual int SetXRunCallback(JackXRunCallback callback, void* arg);
  118. virtual int SetInitCallback(JackThreadInitCallback callback, void* arg);
  119. virtual int SetGraphOrderCallback(JackGraphOrderCallback callback, void* arg);
  120. virtual int SetBufferSizeCallback(JackBufferSizeCallback callback, void* arg);
  121. virtual int SetClientRegistrationCallback(JackClientRegistrationCallback callback, void* arg);
  122. virtual int SetFreewheelCallback(JackFreewheelCallback callback, void* arg);
  123. virtual int SetPortRegistrationCallback(JackPortRegistrationCallback callback, void* arg);
  124. // Internal clients
  125. virtual char* GetInternalClientName(int ref);
  126. virtual int InternalClientHandle(const char* client_name, jack_status_t* status);
  127. virtual int InternalClientLoad(const char* client_name, jack_options_t options, jack_status_t* status, jack_varargs_t* va);
  128. virtual void InternalClientUnload(int ref, jack_status_t* status);
  129. // JackRunnableInterface interface
  130. bool Init();
  131. bool Execute();
  132. };
  133. // Each "side" server and client will implement this to get the shared graph manager, engine control and inter-process synchro table.
  134. extern JackGraphManager* GetGraphManager();
  135. extern JackEngineControl* GetEngineControl();
  136. extern JackSynchro** GetSynchroTable();
  137. } // end of namespace
  138. #endif