JackDebugClient.cpp 22.6 KB
Newer Older
sletz's avatar
sletz committed
1
/*
sletz's avatar
sletz committed
2
Copyright (C) 2004-2008 Grame
sletz's avatar
sletz committed
3
4

This program is free software; you can redistribute it and/or modify
sletz's avatar
sletz committed
5
6
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
7
8
9
10
11
(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
12
GNU Lesser General Public License for more details.
sletz's avatar
sletz committed
13

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

*/

#include "JackDebugClient.h"
21
#include "JackEngineControl.h"
sletz's avatar
sletz committed
22
#include "JackException.h"
sletz's avatar
sletz committed
23
#include "JackError.h"
24
#include "JackTime.h"
sletz's avatar
sletz committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <time.h>

using namespace std;

namespace Jack
{

JackDebugClient::JackDebugClient(JackClient * client)
{
39
40
    fTotalPortNumber = 1;       // The total number of port opened and maybe closed. Historical view.
    fOpenPortNumber = 0;        // The current number of opened port.
sletz's avatar
sletz committed
41
42
43
44
    fIsActivated = 0;
    fIsDeactivated = 0;
    fIsClosed = 0;
    fClient = client;
45
    fFreewheel = false;
sletz's avatar
sletz committed
46
47
48
49
50
51
52
53
54
55
56
57
58
}

JackDebugClient::~JackDebugClient()
{
    fTotalPortNumber--; // fTotalPortNumber start at 1
    *fStream << endl << endl << "----------------------------------- JackDebugClient summary ------------------------------- " << endl << endl;
    *fStream << "Client flags ( 1:yes / 0:no ) :" << endl;
    *fStream << setw(5) << "- Client call activated : " << fIsActivated << endl;
    *fStream << setw(5) << "- Client call deactivated : " << fIsDeactivated << endl;
    *fStream << setw(5) << "- Client call closed : " << fIsClosed << endl;
    *fStream << setw(5) << "- Total number of instantiated port : " << fTotalPortNumber << endl;
    *fStream << setw(5) << "- Number of port remaining open when exiting client : " << fOpenPortNumber << endl;
    if (fOpenPortNumber != 0)
sletz's avatar
sletz committed
59
        *fStream << "!!! WARNING !!! Some ports have not been unregistered ! Incorrect exiting !" << endl;
sletz's avatar
sletz committed
60
    if (fIsDeactivated != fIsActivated)
sletz's avatar
sletz committed
61
        *fStream << "!!! ERROR !!! Client seem to not perform symetric activation-deactivation ! (not the same number of activate and deactivate)" << endl;
sletz's avatar
sletz committed
62
63
64
65
66
67
68
69
70
71
    if (fIsClosed == 0)
        *fStream << "!!! ERROR !!! Client have not been closed with jack_client_close() !" << endl;

    *fStream << endl << endl << "---------------------------- JackDebugClient detailed port summary ------------------------ " << endl << endl;
    //for (int i = 0; i < fTotalPortNumber ; i++) {
    for (int i = 1; i <= fTotalPortNumber ; i++) {
        *fStream << endl << "Port index (internal debug test value) : " << i << endl;
        *fStream << setw(5) << "- Name : " << fPortList[i].name << endl;
        *fStream << setw(5) << "- idport : " << fPortList[i].idport << endl;
        *fStream << setw(5) << "- IsConnected : " << fPortList[i].IsConnected << endl;
sletz's avatar
sletz committed
72
73
74
        *fStream << setw(5) << "- IsUnregistered : " << fPortList[i].IsUnregistered << endl;
        if (fPortList[i].IsUnregistered == 0)
            *fStream << "!!! WARNING !!! Port have not been unregistered ! Incorrect exiting !" << endl;
sletz's avatar
sletz committed
75
76
77
78
79
80
    }
    *fStream << "delete object JackDebugClient : end of tracing" << endl;
    delete fStream;
    delete fClient;
}

Stéphane LETZ's avatar
Stéphane LETZ committed
81
int JackDebugClient::Open(const char* server_name, const char* name, int uuid, jack_options_t options, jack_status_t* status)
sletz's avatar
sletz committed
82
{
Stéphane LETZ's avatar
Stéphane LETZ committed
83
    int res = fClient->Open(server_name, name, uuid, options, status);
sletz's avatar
sletz committed
84
85
86
87
88
89
90
91
92
    char provstr[256];
    char buffer[256];
    time_t curtime;
    struct tm *loctime;
    /* Get the current time. */
    curtime = time (NULL);
    /* Convert it to local time representation. */
    loctime = localtime (&curtime);
    strftime (buffer, 256, "%I-%M", loctime);
sletz's avatar
sletz committed
93
    snprintf(provstr, sizeof(provstr), "JackClientDebug-%s-%s.log", name, buffer);
sletz's avatar
sletz committed
94
95
    fStream = new ofstream(provstr, ios_base::ate);
    if (fStream->is_open()) {
96
97
        if (res == -1) {
            *fStream << "Trying to open client with name '" << name << "' with bad result (client not opened)." << res << endl;
sletz's avatar
sletz committed
98
        } else {
99
            *fStream << "Open client with name '" << name << "'." << endl;
sletz's avatar
sletz committed
100
101
        }
    } else {
sletz's avatar
sletz committed
102
        jack_log("JackDebugClient::Open : cannot open log file");
sletz's avatar
sletz committed
103
104
    }
    strcpy(fClientName, name);
105
    return res;
sletz's avatar
sletz committed
106
107
108
109
}

int JackDebugClient::Close()
{
110
    *fStream << "Client '" << fClientName << "' was closed" << endl;
sletz's avatar
sletz committed
111
112
113
    int res = fClient->Close();
    fIsClosed++;
    return res;
sletz's avatar
sletz committed
114
115
}

sletz's avatar
sletz committed
116
void JackDebugClient::CheckClient(const char* function_name) const
117
{
sletz's avatar
sletz committed
118
119
120
#ifdef WIN32
    *fStream << "CheckClient : " << function_name << ", calling thread : " << GetCurrentThread() << endl;
#else
sletz's avatar
sletz committed
121
    *fStream << "CheckClient : " << function_name << ", calling thread : " << pthread_self() << endl;
sletz's avatar
sletz committed
122
#endif
123

124
    if (fIsClosed > 0)  {
125
        *fStream << "!!! ERROR !!! : Accessing a client '" << fClientName << "' already closed " << "from " << function_name << endl;
sletz's avatar
sletz committed
126
        *fStream << "This is likely to cause crash !'" << endl;
sletz's avatar
sletz committed
127
    #ifdef __APPLE__
sletz's avatar
sletz committed
128
       // Debugger();
129
    #endif
sletz's avatar
sletz committed
130
    }
131
132
}

133
jack_native_thread_t JackDebugClient::GetThreadID()
sletz's avatar
sletz committed
134
{
sletz's avatar
sletz committed
135
    CheckClient("GetThreadID");
sletz's avatar
sletz committed
136
137
138
139
140
    return fClient->GetThreadID();
}

JackGraphManager* JackDebugClient::GetGraphManager() const
{
sletz's avatar
sletz committed
141
    CheckClient("GetGraphManager");
sletz's avatar
sletz committed
142
143
144
145
    return fClient->GetGraphManager();
}
JackEngineControl* JackDebugClient::GetEngineControl() const
{
sletz's avatar
sletz committed
146
    CheckClient("GetEngineControl");
sletz's avatar
sletz committed
147
148
149
150
151
152
    return fClient->GetEngineControl();
}
/*!
\brief Notification received from the server.
*/

153
int JackDebugClient::ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2)
sletz's avatar
sletz committed
154
{
sletz's avatar
sletz committed
155
    CheckClient("ClientNotify");
156
    return fClient->ClientNotify( refnum, name, notify, sync, message, value1, value2);
sletz's avatar
sletz committed
157
158
159
160
}

int JackDebugClient::Activate()
{
sletz's avatar
sletz committed
161
    CheckClient("Activate");
sletz's avatar
Cleanup    
sletz committed
162
    int res = fClient->Activate();
sletz's avatar
sletz committed
163
164
165
166
    fIsActivated++;
    if (fIsDeactivated)
        *fStream << "Client '" << fClientName << "' call activate a new time (it already call 'activate' previously)." << endl;
    *fStream << "Client '" << fClientName << "' Activated" << endl;
167
168
169
    if (res != 0)
        *fStream << "Client '" << fClientName << "' try to activate but server return " << res << " ." << endl;
    return res;
sletz's avatar
sletz committed
170
171
172
173
}

int JackDebugClient::Deactivate()
{
sletz's avatar
sletz committed
174
    CheckClient("Deactivate");
sletz's avatar
Cleanup    
sletz committed
175
    int res = fClient->Deactivate();
sletz's avatar
sletz committed
176
177
178
179
    fIsDeactivated++;
    if (fIsActivated == 0)
        *fStream << "Client '" << fClientName << "' deactivate while it hasn't been previoulsy activated !" << endl;
    *fStream << "Client '" << fClientName << "' Deactivated" << endl;
180
181
182
    if (res != 0)
        *fStream << "Client '" << fClientName << "' try to deactivate but server return " << res << " ." << endl;
    return res;
sletz's avatar
sletz committed
183
184
185
186
187
188
189
190
}

//-----------------
// Port management
//-----------------

int JackDebugClient::PortRegister(const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size)
{
sletz's avatar
sletz committed
191
    CheckClient("PortRegister");
sletz's avatar
Cleanup    
sletz committed
192
    int res = fClient->PortRegister(port_name, port_type, flags, buffer_size);
193
194
    if (res <= 0) {
        *fStream << "Client '" << fClientName << "' try port register ('" << port_name << "') and server return error  " << res << " ." << endl;
sletz's avatar
sletz committed
195
196
    } else {
        if (fTotalPortNumber < MAX_PORT_HISTORY) {
197
            fPortList[fTotalPortNumber].idport = res;
sletz's avatar
sletz committed
198
199
            strcpy(fPortList[fTotalPortNumber].name, port_name);
            fPortList[fTotalPortNumber].IsConnected = 0;
sletz's avatar
sletz committed
200
            fPortList[fTotalPortNumber].IsUnregistered = 0;
sletz's avatar
sletz committed
201
202
203
204
205
        } else {
            *fStream << "!!! WARNING !!! History is full : no more port history will be recorded." << endl;
        }
        fTotalPortNumber++;
        fOpenPortNumber++;
206
        *fStream << "Client '" << fClientName << "' port register with portname '" << port_name << " port " << res << "' ." << endl;
sletz's avatar
sletz committed
207
    }
208
    return res;
sletz's avatar
sletz committed
209
210
211
212
}

int JackDebugClient::PortUnRegister(jack_port_id_t port_index)
{
sletz's avatar
sletz committed
213
    CheckClient("PortUnRegister");
sletz's avatar
Cleanup    
sletz committed
214
    int res = fClient->PortUnRegister(port_index);
sletz's avatar
sletz committed
215
216
    fOpenPortNumber--;
    int i;
217
218
    for (i = (fTotalPortNumber - 1); i >= 0; i--) {     // We search the record into the history
        if (fPortList[i].idport == port_index) {                // We found the last record
sletz's avatar
sletz committed
219
            if (fPortList[i].IsUnregistered != 0)
sletz's avatar
sletz committed
220
                *fStream << "!!! ERROR !!! : '" << fClientName << "' id deregistering port '" << fPortList[i].name << "' that have already been unregistered !" << endl;
sletz's avatar
sletz committed
221
            fPortList[i].IsUnregistered++;
sletz's avatar
sletz committed
222
223
224
225
226
            break;
        }
    }
    if (i == 0) // Port is not found
        *fStream << "JackClientDebug : PortUnregister : port " << port_index << " was not previously registered !" << endl;
227
    if (res != 0)
sletz's avatar
sletz committed
228
        *fStream << "Client '" << fClientName << "' try to do PortUnregister and server return " << res << endl;
sletz's avatar
sletz committed
229
    *fStream << "Client '" << fClientName << "' unregister port '" << port_index << "'." << endl;
230
    return res;
sletz's avatar
sletz committed
231
232
233
234
}

int JackDebugClient::PortConnect(const char* src, const char* dst)
{
sletz's avatar
sletz committed
235
    CheckClient("PortConnect");
236
    if (!fIsActivated)
sletz's avatar
sletz committed
237
238
        *fStream << "!!! ERROR !!! Trying to connect a port ( " << src << " to " << dst << ") while the client has not been activated !" << endl;
    int i;
sletz's avatar
Cleanup    
sletz committed
239
    int res = fClient->PortConnect( src, dst);
240
241
    for (i = (fTotalPortNumber - 1); i >= 0; i--) {     // We search the record into the history
        if (strcmp(fPortList[i].name, src) == 0) {      // We found the last record in sources
sletz's avatar
sletz committed
242
            if (fPortList[i].IsUnregistered != 0)
sletz's avatar
sletz committed
243
244
245
246
247
                *fStream << "!!! ERROR !!! Connecting port " << src << " previoulsy unregistered !" << endl;
            fPortList[i].IsConnected++;
            *fStream << "Connecting port " << src << " to " << dst << ". ";
            break;
        } else if (strcmp(fPortList[i].name, dst) == 0 ) { // We found the record in dest
sletz's avatar
sletz committed
248
            if (fPortList[i].IsUnregistered != 0)
sletz's avatar
sletz committed
249
250
251
252
253
254
255
256
                *fStream << "!!! ERROR !!! Connecting port  " << dst << " previoulsy unregistered !" << endl;
            fPortList[i].IsConnected++;
            *fStream << "Connecting port " << src << " to " << dst << ". ";
            break;
        }
    }
    if (i == 0) // Port is not found
        *fStream << "JackClientDebug : PortConnect : port was not found in debug database !" << endl;
257
258
    if (res != 0)
        *fStream << "Client '" << fClientName << "' try to do PortConnect but server return " << res << " ." << endl;
sletz's avatar
sletz committed
259
    //*fStream << "Client Port Connect done with names" << endl;
260
    return res;
sletz's avatar
sletz committed
261
262
263
264
}

int JackDebugClient::PortDisconnect(const char* src, const char* dst)
{
sletz's avatar
sletz committed
265
    CheckClient("PortDisconnect");
266
    if (!fIsActivated)
sletz's avatar
sletz committed
267
        *fStream << "!!! ERROR !!! Trying to disconnect a port ( " << src << " to " << dst << ") while the client has not been activated !" << endl;
sletz's avatar
Cleanup    
sletz committed
268
    int res = fClient->PortDisconnect( src, dst);
sletz's avatar
sletz committed
269
270
271
    int i;
    for (i = (fTotalPortNumber - 1); i >= 0; i--) { // We search the record into the history
        if (strcmp(fPortList[i].name, src) == 0) { // We found the record in sources
sletz's avatar
sletz committed
272
            if (fPortList[i].IsUnregistered != 0)
sletz's avatar
sletz committed
273
274
275
276
277
                *fStream << "!!! ERROR !!! : Disconnecting port " << src << " previoulsy unregistered !" << endl;
            fPortList[i].IsConnected--;
            *fStream << "disconnecting port " << src << ". ";
            break;
        } else if (strcmp(fPortList[i].name, dst) == 0 ) { // We found the record in dest
sletz's avatar
sletz committed
278
            if (fPortList[i].IsUnregistered != 0)
sletz's avatar
sletz committed
279
280
281
282
283
284
285
286
                *fStream << "!!! ERROR !!! : Disonnecting port  " << dst << " previoulsy unregistered !" << endl;
            fPortList[i].IsConnected--;
            *fStream << "disconnecting port " << dst << ". ";
            break;
        }
    }
    if (i == 0) // Port is not found
        *fStream << "JackClientDebug : PortDisConnect : port was not found in debug database !" << endl;
287
288
    if (res != 0)
        *fStream << "Client '" << fClientName << "' try to do PortDisconnect but server return " << res << " ." << endl;
sletz's avatar
sletz committed
289
    //*fStream << "Client Port Disconnect done." << endl;
290
    return res;
sletz's avatar
sletz committed
291
292
293
294
}

int JackDebugClient::PortDisconnect(jack_port_id_t src)
{
sletz's avatar
sletz committed
295
    CheckClient("PortDisconnect");
296
    if (!fIsActivated)
Stephane Letz's avatar
Stephane Letz committed
297
        *fStream << "!!! ERROR !!! : Trying to disconnect port " << src << " while that client has not been activated !" << endl;
sletz's avatar
Cleanup    
sletz committed
298
    int res = fClient->PortDisconnect(src);
sletz's avatar
sletz committed
299
    int i;
300
301
    for (i = (fTotalPortNumber - 1); i >= 0; i--) {             // We search the record into the history
        if (fPortList[i].idport == src) {                               // We found the record in sources
sletz's avatar
sletz committed
302
            if (fPortList[i].IsUnregistered != 0)
Stephane Letz's avatar
Stephane Letz committed
303
                *fStream << "!!! ERROR !!! : Disconnecting port " << src << " previoulsy unregistered !" << endl;
sletz's avatar
sletz committed
304
305
306
307
308
309
310
            fPortList[i].IsConnected--;
            *fStream << "Disconnecting port " << src << ". " << endl;
            break;
        }
    }
    if (i == 0) // Port is not found
        *fStream << "JackClientDebug : PortDisconnect : port was not found in debug database !" << endl;
311
312
    if (res != 0)
        *fStream << "Client '" << fClientName << "' try to do PortDisconnect but server return " << res << " ." << endl;
sletz's avatar
sletz committed
313
    //*fStream << "Client Port Disconnect with ID done." << endl;
314
    return res;
sletz's avatar
sletz committed
315
316
317
318
}

int JackDebugClient::PortIsMine(jack_port_id_t port_index)
{
sletz's avatar
sletz committed
319
    CheckClient("PortIsMine");
Stephane Letz's avatar
Stephane Letz committed
320
    *fStream << "JackClientDebug : PortIsMine port_index " << port_index << endl;
sletz's avatar
sletz committed
321
322
323
    return fClient->PortIsMine(port_index);
}

324
325
326
int JackDebugClient::PortRename(jack_port_id_t port_index, const char* name)
{
    CheckClient("PortRename");
Stephane Letz's avatar
Stephane Letz committed
327
    *fStream << "JackClientDebug : PortRename port_index " << port_index << "name" << name << endl;
328
329
330
    return fClient->PortRename(port_index, name);
}

sletz's avatar
sletz committed
331
332
333
334
//--------------------
// Context management
//--------------------

335
int JackDebugClient::SetBufferSize(jack_nframes_t buffer_size)
sletz's avatar
sletz committed
336
{
sletz's avatar
sletz committed
337
    CheckClient("SetBufferSize");
Stephane Letz's avatar
Stephane Letz committed
338
    *fStream << "JackClientDebug : SetBufferSize buffer_size " << buffer_size << endl;
339
    return fClient->SetBufferSize(buffer_size);
sletz's avatar
sletz committed
340
341
342
343
}

int JackDebugClient::SetFreeWheel(int onoff)
{
sletz's avatar
sletz committed
344
    CheckClient("SetFreeWheel");
345
    if (onoff && fFreewheel)
Stephane Letz's avatar
Stephane Letz committed
346
        *fStream << "!!! ERROR !!! : Freewheel setup seems incorrect : set = ON while FW is already ON " << endl;
347
    if (!onoff && !fFreewheel)
Stephane Letz's avatar
Stephane Letz committed
348
        *fStream << "!!! ERROR !!! : Freewheel setup seems incorrect : set = OFF while FW is already OFF " << endl;
349
    fFreewheel = onoff ? true : false;
sletz's avatar
sletz committed
350
351
352
    return fClient->SetFreeWheel(onoff);
}

353
354
355
356
357
358
int JackDebugClient::ComputeTotalLatencies()
{
    CheckClient("ComputeTotalLatencies");
    return fClient->ComputeTotalLatencies();
}

sletz's avatar
sletz committed
359
360
361
362
363
364
365
/*
ShutDown is called:
- from the RT thread when Execute method fails
- possibly from a "closed" notification channel
(Not needed since the synch object used (Sema of Fifo will fails when server quits... see ShutDown))
*/

366
void JackDebugClient::ShutDown(const char* message)
sletz's avatar
sletz committed
367
{
Stephane Letz's avatar
Stephane Letz committed
368
    CheckClient("ShutDown");
369
    fClient->ShutDown(message);
sletz's avatar
sletz committed
370
371
372
373
374
375
376
377
}

//---------------------
// Transport management
//---------------------

int JackDebugClient::ReleaseTimebase()
{
sletz's avatar
sletz committed
378
    CheckClient("ReleaseTimebase");
sletz's avatar
sletz committed
379
380
381
382
383
    return fClient->ReleaseTimebase();
}

int JackDebugClient::SetSyncCallback(JackSyncCallback sync_callback, void* arg)
{
sletz's avatar
sletz committed
384
    CheckClient("SetSyncCallback");
sletz's avatar
sletz committed
385
386
387
388
389
    return fClient->SetSyncCallback(sync_callback, arg);
}

int JackDebugClient::SetSyncTimeout(jack_time_t timeout)
{
sletz's avatar
sletz committed
390
    CheckClient("SetSyncTimeout");
Stephane Letz's avatar
Stephane Letz committed
391
    *fStream << "JackClientDebug : SetSyncTimeout timeout " << timeout << endl;
sletz's avatar
sletz committed
392
393
394
395
396
    return fClient->SetSyncTimeout(timeout);
}

int JackDebugClient::SetTimebaseCallback(int conditional, JackTimebaseCallback timebase_callback, void* arg)
{
sletz's avatar
sletz committed
397
    CheckClient("SetTimebaseCallback");
sletz's avatar
sletz committed
398
399
400
    return fClient->SetTimebaseCallback( conditional, timebase_callback, arg);
}

401
void JackDebugClient::TransportLocate(jack_nframes_t frame)
sletz's avatar
sletz committed
402
{
sletz's avatar
sletz committed
403
    CheckClient("TransportLocate");
Stephane Letz's avatar
Stephane Letz committed
404
    *fStream << "JackClientDebug : TransportLocate frame " << frame << endl;
405
    fClient->TransportLocate(frame);
sletz's avatar
sletz committed
406
407
408
409
}

jack_transport_state_t JackDebugClient::TransportQuery(jack_position_t* pos)
{
sletz's avatar
sletz committed
410
    CheckClient("TransportQuery");
sletz's avatar
sletz committed
411
412
413
414
415
    return fClient->TransportQuery(pos);
}

jack_nframes_t JackDebugClient::GetCurrentTransportFrame()
{
sletz's avatar
sletz committed
416
    CheckClient("GetCurrentTransportFrame");
sletz's avatar
sletz committed
417
418
419
    return fClient->GetCurrentTransportFrame();
}

420
int JackDebugClient::TransportReposition(const jack_position_t* pos)
sletz's avatar
sletz committed
421
{
sletz's avatar
sletz committed
422
    CheckClient("TransportReposition");
sletz's avatar
sletz committed
423
424
425
426
427
    return fClient->TransportReposition(pos);
}

void JackDebugClient::TransportStart()
{
sletz's avatar
sletz committed
428
    CheckClient("TransportStart");
sletz's avatar
sletz committed
429
430
431
432
433
    fClient->TransportStart();
}

void JackDebugClient::TransportStop()
{
sletz's avatar
sletz committed
434
    CheckClient("TransportStop");
sletz's avatar
sletz committed
435
436
437
438
439
440
441
442
443
    fClient->TransportStop();
}

//---------------------
// Callback management
//---------------------

void JackDebugClient::OnShutdown(JackShutdownCallback callback, void *arg)
{
sletz's avatar
sletz committed
444
    CheckClient("OnShutdown");
sletz's avatar
sletz committed
445
446
447
    fClient->OnShutdown(callback, arg);
}

448
449
void JackDebugClient::OnInfoShutdown(JackInfoShutdownCallback callback, void *arg)
{
sletz's avatar
sletz committed
450
    CheckClient("OnInfoShutdown");
451
452
    fClient->OnInfoShutdown(callback, arg);
}
453

454
455
int JackDebugClient::TimeCallback(jack_nframes_t nframes, void *arg)
{
sletz's avatar
sletz committed
456
457
458
    JackDebugClient* client = (JackDebugClient*)arg;
    jack_time_t t1 = GetMicroSeconds();
    int res = client->fProcessTimeCallback(nframes, client->fProcessTimeCallbackArg);
sletz's avatar
sletz committed
459
    if (res == 0) {
460
        jack_time_t t2 = GetMicroSeconds();
sletz's avatar
sletz committed
461
        long delta = long((t2 - t1) - client->GetEngineControl()->fPeriodUsecs);
462
        if (delta > 0 && !client->fFreewheel) {
sletz's avatar
sletz committed
463
            *client->fStream << "!!! ERROR !!! : Process overload of " << delta << " us" << endl;
464
        }
sletz's avatar
sletz committed
465
    }
sletz's avatar
sletz committed
466
    return res;
467
468
}

sletz's avatar
sletz committed
469
470
int JackDebugClient::SetProcessCallback(JackProcessCallback callback, void *arg)
{
sletz's avatar
sletz committed
471
    CheckClient("SetProcessCallback");
472
    
sletz's avatar
sletz committed
473
474
    fProcessTimeCallback = callback;
    fProcessTimeCallbackArg = arg;
475
476
477
478
479
480
481
482
        
    if (callback == NULL) {
        // Clear the callback...
        return fClient->SetProcessCallback(callback, arg);
    } else {
        // Setup the measuring version...
        return fClient->SetProcessCallback(TimeCallback, this);
    }
sletz's avatar
sletz committed
483
484
485
486
}

int JackDebugClient::SetXRunCallback(JackXRunCallback callback, void *arg)
{
sletz's avatar
sletz committed
487
    CheckClient("SetXRunCallback");
sletz's avatar
sletz committed
488
489
490
491
492
    return fClient->SetXRunCallback(callback, arg);
}

int JackDebugClient::SetInitCallback(JackThreadInitCallback callback, void *arg)
{
sletz's avatar
sletz committed
493
    CheckClient("SetInitCallback");
sletz's avatar
sletz committed
494
495
496
497
498
    return fClient->SetInitCallback(callback, arg);
}

int JackDebugClient::SetGraphOrderCallback(JackGraphOrderCallback callback, void *arg)
{
sletz's avatar
sletz committed
499
    CheckClient("SetGraphOrderCallback");
sletz's avatar
sletz committed
500
501
502
503
504
    return fClient->SetGraphOrderCallback(callback, arg);
}

int JackDebugClient::SetBufferSizeCallback(JackBufferSizeCallback callback, void *arg)
{
sletz's avatar
sletz committed
505
    CheckClient("SetBufferSizeCallback");
sletz's avatar
sletz committed
506
507
508
    return fClient->SetBufferSizeCallback(callback, arg);
}

sletz's avatar
Cleanup    
sletz committed
509
510
int JackDebugClient::SetClientRegistrationCallback(JackClientRegistrationCallback callback, void* arg)
{
sletz's avatar
sletz committed
511
    CheckClient("SetClientRegistrationCallback");
sletz's avatar
Cleanup    
sletz committed
512
513
514
    return fClient->SetClientRegistrationCallback(callback, arg);
}

sletz's avatar
sletz committed
515
516
int JackDebugClient::SetFreewheelCallback(JackFreewheelCallback callback, void *arg)
{
sletz's avatar
sletz committed
517
    CheckClient("SetFreewheelCallback");
sletz's avatar
sletz committed
518
519
520
521
522
    return fClient->SetFreewheelCallback(callback, arg);
}

int JackDebugClient::SetPortRegistrationCallback(JackPortRegistrationCallback callback, void *arg)
{
sletz's avatar
sletz committed
523
    CheckClient("SetPortRegistrationCallback");
sletz's avatar
sletz committed
524
525
526
    return fClient->SetPortRegistrationCallback(callback, arg);
}

sletz's avatar
sletz committed
527
528
int JackDebugClient::SetPortConnectCallback(JackPortConnectCallback callback, void *arg)
{
sletz's avatar
sletz committed
529
    CheckClient("SetPortConnectCallback");
sletz's avatar
sletz committed
530
531
532
    return fClient->SetPortConnectCallback(callback, arg);
}

533
534
int JackDebugClient::SetPortRenameCallback(JackPortRenameCallback callback, void *arg)
{
sletz's avatar
sletz committed
535
    CheckClient("SetPortRenameCallback");
536
537
538
    return fClient->SetPortRenameCallback(callback, arg);
}

539
540
541
542
543
544
545
546
547
548
549
550
int JackDebugClient::SetSessionCallback(JackSessionCallback callback, void *arg)
{
    CheckClient("SetSessionCallback");
    return fClient->SetSessionCallback(callback, arg);
}

int JackDebugClient::SetLatencyCallback(JackLatencyCallback callback, void *arg)
{
    CheckClient("SetLatencyCallback");
    return fClient->SetLatencyCallback(callback, arg);
}

551
552
553
554
555
556
int JackDebugClient::SetProcessThread(JackThreadCallback fun, void *arg)
{
    CheckClient("SetProcessThread");
    return fClient->SetProcessThread(fun, arg);
}

557
558
559
jack_session_command_t* JackDebugClient::SessionNotify(const char* target, jack_session_event_type_t type, const char* path)
{
    CheckClient("SessionNotify");
Stephane Letz's avatar
Stephane Letz committed
560
    *fStream << "JackClientDebug : SessionNotify target " << target << "type " << type << "path " << path << endl;
561
562
563
564
565
566
567
568
569
570
571
572
    return fClient->SessionNotify(target, type, path);
}

int JackDebugClient::SessionReply(jack_session_event_t* ev)
{
    CheckClient("SessionReply");
    return fClient->SessionReply(ev);
}

char* JackDebugClient::GetUUIDForClientName(const char* client_name)
{
    CheckClient("GetUUIDForClientName");
Stephane Letz's avatar
Stephane Letz committed
573
    *fStream << "JackClientDebug : GetUUIDForClientName client_name " << client_name << endl;
574
575
576
577
578
579
    return fClient->GetUUIDForClientName(client_name);
}

char* JackDebugClient::GetClientNameByUUID(const char* uuid)
{
    CheckClient("GetClientNameByUUID");
Stephane Letz's avatar
Stephane Letz committed
580
    *fStream << "JackClientDebug : GetClientNameByUUID uuid " << uuid << endl;
581
582
583
584
585
586
    return fClient->GetClientNameByUUID(uuid);
}

int JackDebugClient::ReserveClientName(const char* client_name, const char* uuid)
{
    CheckClient("ReserveClientName");
Stephane Letz's avatar
Stephane Letz committed
587
    *fStream << "JackClientDebug : ReserveClientName client_name " << client_name << "uuid " << uuid << endl;
588
589
590
591
592
593
    return fClient->ReserveClientName(client_name, uuid);
}

int JackDebugClient::ClientHasSessionCallback(const char* client_name)
{
    CheckClient("ClientHasSessionCallback");
Stephane Letz's avatar
Stephane Letz committed
594
    *fStream << "JackClientDebug : ClientHasSessionCallback client_name " << client_name << endl;
595
596
597
    return fClient->ClientHasSessionCallback(client_name);
}

sletz's avatar
sletz committed
598
599
JackClientControl* JackDebugClient::GetClientControl() const
{
sletz's avatar
sletz committed
600
    CheckClient("GetClientControl");
sletz's avatar
sletz committed
601
602
603
    return fClient->GetClientControl();
}

sletz's avatar
sletz committed
604
605
606
// Internal clients
char* JackDebugClient::GetInternalClientName(int ref)
{
sletz's avatar
sletz committed
607
    CheckClient("GetInternalClientName");
sletz's avatar
sletz committed
608
609
610
611
612
    return fClient->GetInternalClientName(ref);
}

int JackDebugClient::InternalClientHandle(const char* client_name, jack_status_t* status)
{
sletz's avatar
sletz committed
613
    CheckClient("InternalClientHandle");
sletz's avatar
sletz committed
614
615
616
617
618
    return fClient->InternalClientHandle(client_name, status);
}

int JackDebugClient::InternalClientLoad(const char* client_name, jack_options_t options, jack_status_t* status, jack_varargs_t* va)
{
sletz's avatar
sletz committed
619
    CheckClient("InternalClientLoad");
sletz's avatar
sletz committed
620
621
622
623
624
    return fClient->InternalClientLoad(client_name, options, status, va);
}

void JackDebugClient::InternalClientUnload(int ref, jack_status_t* status)
{
sletz's avatar
sletz committed
625
    CheckClient("InternalClientUnload");
sletz's avatar
sletz committed
626
627
    fClient->InternalClientUnload(ref, status);
}
sletz's avatar
sletz committed
628

sletz's avatar
sletz committed
629
630
} // end of namespace