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.

166 lines
5.7KB

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