Simplify JackClient RT code, jack_thread_wait API marked deprecated.
[jack2.git] / common / JackClient.h
blobf41d734fb0a3f3a6b6761f85172daed2594170c2
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #ifndef __JackClient__
22 #define __JackClient__
24 #include "JackClientInterface.h"
25 #include "JackThread.h"
26 #include "JackConstants.h"
27 #include "JackSynchro.h"
28 #include "JackPlatformPlug.h"
29 #include "JackChannel.h"
30 #include "types.h"
31 #include "varargs.h"
32 #include <list>
34 namespace Jack
37 class JackGraphManager;
38 class JackServer;
39 class JackEngine;
40 struct JackClientControl;
41 struct JackEngineControl;
43 /*!
44 \brief The base class for clients: share part of the implementation for JackInternalClient and JackLibClient.
47 class JackClient : public JackClientInterface, public JackRunnableInterface
49 friend class JackDebugClient;
51 protected:
53 JackProcessCallback fProcess;
54 JackGraphOrderCallback fGraphOrder;
55 JackXRunCallback fXrun;
56 JackShutdownCallback fShutdown;
57 JackThreadInitCallback fInit;
58 JackBufferSizeCallback fBufferSize;
59 JackSampleRateCallback fSampleRate;
60 JackClientRegistrationCallback fClientRegistration;
61 JackFreewheelCallback fFreewheel;
62 JackPortRegistrationCallback fPortRegistration;
63 JackPortConnectCallback fPortConnect;
64 JackPortRenameCallback fPortRename;
65 JackTimebaseCallback fTimebase;
66 JackSyncCallback fSync;
67 JackThreadCallback fThreadFun;
69 void* fProcessArg;
70 void* fGraphOrderArg;
71 void* fXrunArg;
72 void* fShutdownArg;
73 void* fInitArg;
74 void* fBufferSizeArg;
75 void* fSampleRateArg;
76 void* fClientRegistrationArg;
77 void* fFreewheelArg;
78 void* fPortRegistrationArg;
79 void* fPortConnectArg;
80 void* fPortRenameArg;
81 void* fTimebaseArg;
82 void* fSyncArg;
83 void* fThreadFunArg;
84 char fServerName[64];
86 JackThread fThread; /*! Thread to execute the Process function */
87 detail::JackClientChannelInterface* fChannel;
88 JackSynchro* fSynchroTable;
89 std::list<jack_port_id_t> fPortList;
91 int StartThread();
92 void SetupDriverSync(bool freewheel);
93 bool IsActive();
95 void CallSyncCallback();
96 void CallTimebaseCallback();
98 virtual int ClientNotifyImp(int refnum, const char* name, int notify, int sync, int value1, int value);
100 inline void DummyCycle();
101 inline void ExecuteThread();
102 inline bool WaitSync();
103 inline void SignalSync();
104 inline int CallProcessCallback();
105 inline void End();
106 inline void Error();
107 inline jack_nframes_t CycleWaitAux();
108 inline void CycleSignalAux(int status);
109 inline void CallSyncCallbackAux();
110 inline void CallTimebaseCallbackAux();
112 public:
114 JackClient();
115 JackClient(JackSynchro* table);
116 virtual ~JackClient();
118 virtual int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status) = 0;
119 virtual int Close();
121 virtual JackGraphManager* GetGraphManager() const = 0;
122 virtual JackEngineControl* GetEngineControl() const = 0;
124 // Notifications
125 virtual int ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2);
127 virtual int Activate();
128 virtual int Deactivate();
130 // Context
131 virtual int SetBufferSize(jack_nframes_t buffer_size);
132 virtual int SetFreeWheel(int onoff);
133 virtual void ShutDown();
134 virtual pthread_t GetThreadID();
136 // Port management
137 virtual int PortRegister(const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size);
138 virtual int PortUnRegister(jack_port_id_t port);
140 virtual int PortConnect(const char* src, const char* dst);
141 virtual int PortDisconnect(const char* src, const char* dst);
142 virtual int PortDisconnect(jack_port_id_t src);
144 virtual int PortIsMine(jack_port_id_t port_index);
145 virtual int PortRename(jack_port_id_t port_index, const char* name);
147 // Transport
148 virtual int ReleaseTimebase();
149 virtual int SetSyncCallback(JackSyncCallback sync_callback, void* arg);
150 virtual int SetSyncTimeout(jack_time_t timeout);
151 virtual int SetTimebaseCallback(int conditional, JackTimebaseCallback timebase_callback, void* arg);
152 virtual void TransportLocate(jack_nframes_t frame);
153 virtual jack_transport_state_t TransportQuery(jack_position_t* pos);
154 virtual jack_nframes_t GetCurrentTransportFrame();
155 virtual int TransportReposition(jack_position_t* pos);
156 virtual void TransportStart();
157 virtual void TransportStop();
159 // Callbacks
160 virtual void OnShutdown(JackShutdownCallback callback, void *arg);
161 virtual int SetProcessCallback(JackProcessCallback callback, void* arg);
162 virtual int SetXRunCallback(JackXRunCallback callback, void* arg);
163 virtual int SetInitCallback(JackThreadInitCallback callback, void* arg);
164 virtual int SetGraphOrderCallback(JackGraphOrderCallback callback, void* arg);
165 virtual int SetBufferSizeCallback(JackBufferSizeCallback callback, void* arg);
166 virtual int SetSampleRateCallback(JackBufferSizeCallback callback, void* arg);
167 virtual int SetClientRegistrationCallback(JackClientRegistrationCallback callback, void* arg);
168 virtual int SetFreewheelCallback(JackFreewheelCallback callback, void* arg);
169 virtual int SetPortRegistrationCallback(JackPortRegistrationCallback callback, void* arg);
170 virtual int SetPortConnectCallback(JackPortConnectCallback callback, void *arg);
171 virtual int SetPortRenameCallback(JackPortRenameCallback callback, void *arg);
173 // Internal clients
174 virtual char* GetInternalClientName(int ref);
175 virtual int InternalClientHandle(const char* client_name, jack_status_t* status);
176 virtual int InternalClientLoad(const char* client_name, jack_options_t options, jack_status_t* status, jack_varargs_t* va);
177 virtual void InternalClientUnload(int ref, jack_status_t* status);
179 jack_nframes_t CycleWait();
180 void CycleSignal(int status);
181 int SetProcessThread(JackThreadCallback fun, void *arg);
183 // JackRunnableInterface interface
184 bool Init();
185 bool Execute();
188 } // end of namespace
190 #endif