JackClient.h 7.2 KB
Newer Older
sletz's avatar
sletz committed
1
/*
sletz's avatar
sletz committed
2
Copyright (C) 2001 Paul Davis
sletz's avatar
sletz committed
3
Copyright (C) 2004-2008 Grame
sletz's avatar
sletz committed
4
5

This program is free software; you can redistribute it and/or modify
sletz's avatar
sletz committed
6
7
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
sletz's avatar
sletz committed
8
9
10
11
12
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
sletz's avatar
sletz committed
13
GNU Lesser General Public License for more details.
sletz's avatar
sletz committed
14

sletz's avatar
sletz committed
15
16
17
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software 
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
sletz's avatar
sletz committed
18
19
20
21
22
23
24
25
26
27

*/

#ifndef __JackClient__
#define __JackClient__

#include "JackClientInterface.h"
#include "JackThread.h"
#include "JackConstants.h"
#include "JackSynchro.h"
sletz's avatar
sletz committed
28
29
#include "JackPlatformPlug.h"
#include "JackChannel.h"
sletz's avatar
sletz committed
30
#include "types.h"
31
#include "varargs.h"
sletz's avatar
sletz committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <list>

namespace Jack
{

class JackGraphManager;
class JackServer;
class JackEngine;
struct JackClientControl;
struct JackEngineControl;

/*!
\brief The base class for clients: share part of the implementation for JackInternalClient and JackLibClient.
*/

class JackClient : public JackClientInterface, public JackRunnableInterface
{
sletz's avatar
sletz committed
49
50
        friend class JackDebugClient;

sletz's avatar
sletz committed
51
52
53
54
55
56
    protected:

        JackProcessCallback fProcess;
        JackGraphOrderCallback fGraphOrder;
        JackXRunCallback fXrun;
        JackShutdownCallback fShutdown;
57
        JackInfoShutdownCallback fInfoShutdown;
sletz's avatar
sletz committed
58
59
        JackThreadInitCallback fInit;
        JackBufferSizeCallback fBufferSize;
60
        JackSampleRateCallback fSampleRate;
sletz's avatar
sletz committed
61
        JackClientRegistrationCallback fClientRegistration;
sletz's avatar
sletz committed
62
63
        JackFreewheelCallback fFreewheel;
        JackPortRegistrationCallback fPortRegistration;
sletz's avatar
sletz committed
64
        JackPortConnectCallback fPortConnect;
65
        JackPortRenameCallback fPortRename;
sletz's avatar
sletz committed
66
67
        JackTimebaseCallback fTimebase;
        JackSyncCallback fSync;
sletz's avatar
sletz committed
68
69
        JackThreadCallback fThreadFun;

sletz's avatar
sletz committed
70
71
72
73
        void* fProcessArg;
        void* fGraphOrderArg;
        void* fXrunArg;
        void* fShutdownArg;
74
        void* fInfoShutdownArg;
sletz's avatar
sletz committed
75
76
        void* fInitArg;
        void* fBufferSizeArg;
77
        void* fSampleRateArg;
sletz's avatar
sletz committed
78
        void* fClientRegistrationArg;
sletz's avatar
sletz committed
79
80
        void* fFreewheelArg;
        void* fPortRegistrationArg;
sletz's avatar
sletz committed
81
        void* fPortConnectArg;
82
        void* fPortRenameArg;
sletz's avatar
sletz committed
83
84
        void* fTimebaseArg;
        void* fSyncArg;
sletz's avatar
sletz committed
85
86
        void* fThreadFunArg;
        char fServerName[64];
sletz's avatar
sletz committed
87

88
89
90
        JackThread fThread;    /*! Thread to execute the Process function */
        detail::JackClientChannelInterface* fChannel;
        JackSynchro* fSynchroTable;
sletz's avatar
sletz committed
91
        std::list<jack_port_id_t> fPortList;
92
  
sletz's avatar
sletz committed
93
94
95
96
97
98
        int StartThread();
        void SetupDriverSync(bool freewheel);
        bool IsActive();

        void CallSyncCallback();
        void CallTimebaseCallback();
99
   
100
        virtual int ClientNotifyImp(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value);
sletz's avatar
sletz committed
101

102
        inline void DummyCycle();
sletz's avatar
sletz committed
103
104
105
106
        inline void ExecuteThread();
        inline bool WaitSync();
        inline void SignalSync();
        inline int CallProcessCallback();
107
108
        inline void End();
        inline void Error();
109
110
111
112
        inline jack_nframes_t CycleWaitAux();
        inline void CycleSignalAux(int status);
        inline void CallSyncCallbackAux();
        inline void CallTimebaseCallbackAux();
113
        inline int ActivateAux();
114
   
sletz's avatar
sletz committed
115
116
117
    public:

        JackClient();
118
        JackClient(JackSynchro* table);
sletz's avatar
sletz committed
119
120
        virtual ~JackClient();

121
        virtual int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status) = 0;
sletz's avatar
sletz committed
122
123
124
125
126
127
        virtual int Close();

        virtual JackGraphManager* GetGraphManager() const = 0;
        virtual JackEngineControl* GetEngineControl() const = 0;

        // Notifications
128
        virtual int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
sletz's avatar
sletz committed
129
130
131
132
133

        virtual int Activate();
        virtual int Deactivate();

        // Context
134
        virtual int SetBufferSize(jack_nframes_t buffer_size);
sletz's avatar
sletz committed
135
136
137
138
139
140
141
142
143
144
145
146
        virtual int SetFreeWheel(int onoff);
        virtual void ShutDown();
        virtual pthread_t GetThreadID();

        // Port management
        virtual int PortRegister(const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size);
        virtual int PortUnRegister(jack_port_id_t port);

        virtual int PortConnect(const char* src, const char* dst);
        virtual int PortDisconnect(const char* src, const char* dst);
        virtual int PortDisconnect(jack_port_id_t src);

sletz's avatar
Cleanup    
sletz committed
147
        virtual int PortIsMine(jack_port_id_t port_index);
148
        virtual int PortRename(jack_port_id_t port_index, const char* name);
sletz's avatar
sletz committed
149
150
151
152
153
154

        // Transport
        virtual int ReleaseTimebase();
        virtual int SetSyncCallback(JackSyncCallback sync_callback, void* arg);
        virtual int SetSyncTimeout(jack_time_t timeout);
        virtual int SetTimebaseCallback(int conditional, JackTimebaseCallback timebase_callback, void* arg);
155
        virtual void TransportLocate(jack_nframes_t frame);
sletz's avatar
sletz committed
156
157
158
159
160
161
162
163
        virtual jack_transport_state_t TransportQuery(jack_position_t* pos);
        virtual jack_nframes_t GetCurrentTransportFrame();
        virtual int TransportReposition(jack_position_t* pos);
        virtual void TransportStart();
        virtual void TransportStop();

        // Callbacks
        virtual void OnShutdown(JackShutdownCallback callback, void *arg);
164
        virtual void OnInfoShutdown(JackInfoShutdownCallback callback, void *arg);
sletz's avatar
sletz committed
165
166
167
168
169
        virtual int SetProcessCallback(JackProcessCallback callback, void* arg);
        virtual int SetXRunCallback(JackXRunCallback callback, void* arg);
        virtual int SetInitCallback(JackThreadInitCallback callback, void* arg);
        virtual int SetGraphOrderCallback(JackGraphOrderCallback callback, void* arg);
        virtual int SetBufferSizeCallback(JackBufferSizeCallback callback, void* arg);
170
        virtual int SetSampleRateCallback(JackBufferSizeCallback callback, void* arg);
sletz's avatar
sletz committed
171
        virtual int SetClientRegistrationCallback(JackClientRegistrationCallback callback, void* arg);
sletz's avatar
sletz committed
172
173
        virtual int SetFreewheelCallback(JackFreewheelCallback callback, void* arg);
        virtual int SetPortRegistrationCallback(JackPortRegistrationCallback callback, void* arg);
sletz's avatar
sletz committed
174
        virtual int SetPortConnectCallback(JackPortConnectCallback callback, void *arg);
175
        virtual int SetPortRenameCallback(JackPortRenameCallback callback, void *arg);
sletz's avatar
sletz committed
176
177
178
179
180
181
182

        // Internal clients
        virtual char* GetInternalClientName(int ref);
        virtual int InternalClientHandle(const char* client_name, jack_status_t* status);
        virtual int InternalClientLoad(const char* client_name, jack_options_t options, jack_status_t* status, jack_varargs_t* va);
        virtual void InternalClientUnload(int ref, jack_status_t* status);

183
        jack_nframes_t CycleWait();
sletz's avatar
sletz committed
184
185
        void CycleSignal(int status);
        int SetProcessThread(JackThreadCallback fun, void *arg);
sletz's avatar
sletz committed
186
187
188
189
190
191
192
193
194

        // JackRunnableInterface interface
        bool Init();
        bool Execute();
};

} // end of namespace

#endif