Cleanup thread code.
[jack2.git] / common / JackClient.h
blob215098a03b67bd7a1976089a20087a4ed41afb06
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 JackInfoShutdownCallback fInfoShutdown;
58 JackThreadInitCallback fInit;
59 JackBufferSizeCallback fBufferSize;
60 JackSampleRateCallback fSampleRate;
61 JackClientRegistrationCallback fClientRegistration;
62 JackFreewheelCallback fFreewheel;
63 JackPortRegistrationCallback fPortRegistration;
64 JackPortConnectCallback fPortConnect;
65 JackPortRenameCallback fPortRename;
66 JackTimebaseCallback fTimebase;
67 JackSyncCallback fSync;
68 JackThreadCallback fThreadFun;
70 void* fProcessArg;
71 void* fGraphOrderArg;
72 void* fXrunArg;
73 void* fShutdownArg;
74 void* fInfoShutdownArg;
75 void* fInitArg;
76 void* fBufferSizeArg;
77 void* fSampleRateArg;
78 void* fClientRegistrationArg;
79 void* fFreewheelArg;
80 void* fPortRegistrationArg;
81 void* fPortConnectArg;
82 void* fPortRenameArg;
83 void* fTimebaseArg;
84 void* fSyncArg;
85 void* fThreadFunArg;
86 char fServerName[64];
88 JackThread fThread; /*! Thread to execute the Process function */
89 detail::JackClientChannelInterface* fChannel;
90 JackSynchro* fSynchroTable;
91 std::list<jack_port_id_t> fPortList;
93 int StartThread();
94 void SetupDriverSync(bool freewheel);
95 bool IsActive();
97 void CallSyncCallback();
98 void CallTimebaseCallback();
100 virtual int ClientNotifyImp(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value);
102 inline void DummyCycle();
103 inline void ExecuteThread();
104 inline bool WaitSync();
105 inline void SignalSync();
106 inline int CallProcessCallback();
107 inline void End();
108 inline void Error();
109 inline jack_nframes_t CycleWaitAux();
110 inline void CycleSignalAux(int status);
111 inline void CallSyncCallbackAux();
112 inline void CallTimebaseCallbackAux();
113 inline int ActivateAux();
115 public:
117 JackClient();
118 JackClient(JackSynchro* table);
119 virtual ~JackClient();
121 virtual int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status) = 0;
122 virtual int Close();
124 virtual JackGraphManager* GetGraphManager() const = 0;
125 virtual JackEngineControl* GetEngineControl() const = 0;
127 // Notifications
128 virtual int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
130 virtual int Activate();
131 virtual int Deactivate();
133 // Context
134 virtual int SetBufferSize(jack_nframes_t buffer_size);
135 virtual int SetFreeWheel(int onoff);
136 virtual void ShutDown();
137 virtual pthread_t GetThreadID();
139 // Port management
140 virtual int PortRegister(const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size);
141 virtual int PortUnRegister(jack_port_id_t port);
143 virtual int PortConnect(const char* src, const char* dst);
144 virtual int PortDisconnect(const char* src, const char* dst);
145 virtual int PortDisconnect(jack_port_id_t src);
147 virtual int PortIsMine(jack_port_id_t port_index);
148 virtual int PortRename(jack_port_id_t port_index, const char* name);
150 // Transport
151 virtual int ReleaseTimebase();
152 virtual int SetSyncCallback(JackSyncCallback sync_callback, void* arg);
153 virtual int SetSyncTimeout(jack_time_t timeout);
154 virtual int SetTimebaseCallback(int conditional, JackTimebaseCallback timebase_callback, void* arg);
155 virtual void TransportLocate(jack_nframes_t frame);
156 virtual jack_transport_state_t TransportQuery(jack_position_t* pos);
157 virtual jack_nframes_t GetCurrentTransportFrame();
158 virtual int TransportReposition(jack_position_t* pos);
159 virtual void TransportStart();
160 virtual void TransportStop();
162 // Callbacks
163 virtual void OnShutdown(JackShutdownCallback callback, void *arg);
164 virtual void OnInfoShutdown(JackInfoShutdownCallback callback, void *arg);
165 virtual int SetProcessCallback(JackProcessCallback callback, void* arg);
166 virtual int SetXRunCallback(JackXRunCallback callback, void* arg);
167 virtual int SetInitCallback(JackThreadInitCallback callback, void* arg);
168 virtual int SetGraphOrderCallback(JackGraphOrderCallback callback, void* arg);
169 virtual int SetBufferSizeCallback(JackBufferSizeCallback callback, void* arg);
170 virtual int SetSampleRateCallback(JackBufferSizeCallback callback, void* arg);
171 virtual int SetClientRegistrationCallback(JackClientRegistrationCallback callback, void* arg);
172 virtual int SetFreewheelCallback(JackFreewheelCallback callback, void* arg);
173 virtual int SetPortRegistrationCallback(JackPortRegistrationCallback callback, void* arg);
174 virtual int SetPortConnectCallback(JackPortConnectCallback callback, void *arg);
175 virtual int SetPortRenameCallback(JackPortRenameCallback callback, void *arg);
177 // Internal clients
178 virtual char* GetInternalClientName(int ref);
179 virtual int InternalClientHandle(const char* client_name, jack_status_t* status);
180 virtual int InternalClientLoad(const char* client_name, jack_options_t options, jack_status_t* status, jack_varargs_t* va);
181 virtual void InternalClientUnload(int ref, jack_status_t* status);
183 jack_nframes_t CycleWait();
184 void CycleSignal(int status);
185 int SetProcessThread(JackThreadCallback fun, void *arg);
187 // JackRunnableInterface interface
188 bool Init();
189 bool Execute();
192 } // end of namespace
194 #endif