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.

174 lines
6.2KB

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