JackRequest.h 45.3 KB
Newer Older
sletz's avatar
sletz committed
1
/*
sletz's avatar
sletz committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Copyright (C) 2001 Paul Davis
Copyright (C) 2004-2008 Grame

This program is free software; you can redistribute it and/or modify
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
(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
GNU Lesser General Public License for more details.

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
sletz's avatar
sletz committed
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
sletz's avatar
sletz committed
18

sletz's avatar
sletz committed
19
20
21
22
23
*/

#ifndef __JackRequest__
#define __JackRequest__

sletz's avatar
sletz committed
24
#include "JackConstants.h"
sletz's avatar
sletz committed
25
#include "JackError.h"
26
#include "JackPlatformPlug.h"
27
#include "JackChannel.h"
28
#include "JackTime.h"
sletz's avatar
sletz committed
29
#include "types.h"
sletz's avatar
sletz committed
30
#include <string.h>
sletz's avatar
sletz committed
31
#include <stdio.h>
32
#include <stdlib.h>
Torben Hohn's avatar
Torben Hohn committed
33
#include <list>
sletz's avatar
sletz committed
34
35
36
37

namespace Jack
{

sletz's avatar
sletz committed
38
39
#define CheckRes(exp) { if ((exp) < 0) { jack_error("CheckRes error"); return -1; } }
#define CheckSize() { CheckRes(trans->Read(&fSize, sizeof(int))); if (fSize != Size()) { jack_error("CheckSize error size = %d Size() = %d", fSize, Size()); return -1; } }
Stephane Letz's avatar
Stephane Letz committed
40
41
42
43
44
45
46
47
48
49
50

/*!
\brief Session API constants.
*/

enum JackSessionReply {

    kImmediateSessionReply = 1,
    kPendingSessionReply = 2

};
sletz's avatar
Cleanup    
sletz committed
51

sletz's avatar
sletz committed
52
53
54
55
56
57
58
/*!
\brief Request from client to server.
*/

struct JackRequest
{

59
    enum RequestType {
sletz's avatar
sletz committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
        kRegisterPort = 1,
        kUnRegisterPort = 2,
        kConnectPorts = 3,
        kDisconnectPorts = 4,
        kSetTimeBaseClient = 5,
        kActivateClient = 6,
        kDeactivateClient = 7,
        kDisconnectPort = 8,
        kSetClientCapabilities = 9,
        kGetPortConnections = 10,
        kGetPortNConnections = 11,
        kReleaseTimebase = 12,
        kSetTimebaseCallback = 13,
        kSetBufferSize = 20,
        kSetFreeWheel = 21,
sletz's avatar
sletz committed
75
        kClientCheck = 22,
76
77
78
79
        kClientOpen = 23,
        kClientClose = 24,
        kConnectNamePorts = 25,
        kDisconnectNamePorts = 26,
sletz's avatar
sletz committed
80
81
82
83
        kGetInternalClientName = 27,
        kInternalClientHandle = 28,
        kInternalClientLoad = 29,
        kInternalClientUnload = 30,
84
        kPortRename = 31,
85
        kNotification = 32,
86
87
88
89
        kSessionNotify = 33,
        kSessionReply  = 34,
        kGetClientByUUID = 35,
        kReserveClientName = 36,
90
        kGetUUIDByClient = 37,
91
92
        kClientHasSessionCallback = 38,
        kComputeTotalLatencies = 39
93
    };
sletz's avatar
sletz committed
94
95

    RequestType fType;
sletz's avatar
sletz committed
96
    int fSize;
sletz's avatar
sletz committed
97

sletz's avatar
sletz committed
98
    JackRequest(): fType((RequestType)0), fSize(0)
sletz's avatar
sletz committed
99
100
    {}

sletz's avatar
sletz committed
101
    JackRequest(RequestType type): fType(type), fSize(0)
sletz's avatar
sletz committed
102
103
    {}

sletz's avatar
sletz committed
104
    virtual ~JackRequest()
sletz's avatar
sletz committed
105
106
    {}

107
    virtual int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
108
    {
sletz's avatar
sletz committed
109
        return trans->Read(&fType, sizeof(RequestType));
sletz's avatar
sletz committed
110
111
    }

sletz's avatar
sletz committed
112
113
114
    virtual int Write(detail::JackChannelTransactionInterface* trans) { return -1; }
    
    virtual int Write(detail::JackChannelTransactionInterface* trans, int size)
sletz's avatar
sletz committed
115
    {
sletz's avatar
sletz committed
116
117
118
        fSize = size;
        CheckRes(trans->Write(&fType, sizeof(RequestType)));
        return trans->Write(&fSize, sizeof(int));
sletz's avatar
sletz committed
119
    }
sletz's avatar
sletz committed
120
121
    
    virtual int Size() { return 0; }
sletz's avatar
sletz committed
122
123
124
125
126
127
128
129
130
131

};

/*!
\brief Result from the server.
*/

struct JackResult
{

132
    int fResult;
sletz's avatar
sletz committed
133
134
135

    JackResult(): fResult( -1)
    {}
136
    JackResult(int result): fResult(result)
sletz's avatar
sletz committed
137
138
139
140
    {}
    virtual ~JackResult()
    {}

141
    virtual int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
142
    {
sletz's avatar
sletz committed
143
        return trans->Read(&fResult, sizeof(int));
sletz's avatar
sletz committed
144
145
    }

146
    virtual int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
147
    {
sletz's avatar
sletz committed
148
        return trans->Write(&fResult, sizeof(int));
sletz's avatar
sletz committed
149
    }
150

sletz's avatar
sletz committed
151
152
};

153
154
155
156
157
158
159
/*!
\brief CheckClient request.
*/

struct JackClientCheckRequest : public JackRequest
{

Stephane Letz's avatar
Stephane Letz committed
160
    char fName[JACK_CLIENT_NAME_SIZE+1];
sletz's avatar
sletz committed
161
    int fProtocol;
sletz's avatar
sletz committed
162
    int fOptions;
163
    int fUUID;
164
    int fOpen;
165

166
167
168
169
    JackClientCheckRequest() : fProtocol(0), fOptions(0), fUUID(0), fOpen(0)
    {
        memset(fName, 0, sizeof(fName));
    }
170
171
    JackClientCheckRequest(const char* name, int protocol, int options, int uuid, int open = false)
        : JackRequest(JackRequest::kClientCheck), fProtocol(protocol), fOptions(options), fUUID(uuid), fOpen(open)
172
    {
173
        memset(fName, 0, sizeof(fName));
174
175
176
        snprintf(fName, sizeof(fName), "%s", name);
    }

177
    int Read(detail::JackChannelTransactionInterface* trans)
178
    {
sletz's avatar
sletz committed
179
        CheckSize();
180
        CheckRes(trans->Read(&fName, sizeof(fName)));
sletz's avatar
sletz committed
181
        CheckRes(trans->Read(&fProtocol, sizeof(int)));
182
        CheckRes(trans->Read(&fOptions, sizeof(int)));
183
184
        CheckRes(trans->Read(&fUUID, sizeof(int)));
        return trans->Read(&fOpen, sizeof(int));
185
186
    }

187
    int Write(detail::JackChannelTransactionInterface* trans)
188
    {
sletz's avatar
sletz committed
189
        CheckRes(JackRequest::Write(trans, Size()));
190
        CheckRes(trans->Write(&fName, sizeof(fName)));
sletz's avatar
sletz committed
191
        CheckRes(trans->Write(&fProtocol, sizeof(int)));
192
        CheckRes(trans->Write(&fOptions, sizeof(int)));
193
194
        CheckRes(trans->Write(&fUUID, sizeof(int)));
        return trans->Write(&fOpen, sizeof(int));
195
    }
sletz's avatar
sletz committed
196
197
    
    int Size() { return sizeof(fName) + 4 * sizeof(int); }
198

199
};
200
201
202
203
204
205
206
207

/*!
\brief CheckClient result.
*/

struct JackClientCheckResult : public JackResult
{

Stephane Letz's avatar
Stephane Letz committed
208
    char fName[JACK_CLIENT_NAME_SIZE+1];
sletz's avatar
sletz committed
209
    int fStatus;
210

sletz's avatar
sletz committed
211
    JackClientCheckResult(): JackResult(), fStatus(0)
212
213
214
    {
        memset(fName, 0, sizeof(fName));
    }
215
    JackClientCheckResult(int32_t result, const char* name, int status)
sletz's avatar
sletz committed
216
            : JackResult(result), fStatus(status)
217
    {
218
        memset(fName, 0, sizeof(fName));
sletz's avatar
sletz committed
219
220
        snprintf(fName, sizeof(fName), "%s", name);
    }
221

222
    int Read(detail::JackChannelTransactionInterface* trans)
223
    {
sletz's avatar
sletz committed
224
        CheckRes(JackResult::Read(trans));
225
        CheckRes(trans->Read(&fName, sizeof(fName)));
sletz's avatar
sletz committed
226
227
        CheckRes(trans->Read(&fStatus, sizeof(int)));
        return 0;
228
229
    }

230
    int Write(detail::JackChannelTransactionInterface* trans)
231
    {
sletz's avatar
sletz committed
232
        CheckRes(JackResult::Write(trans));
233
        CheckRes(trans->Write(&fName, sizeof(fName)));
sletz's avatar
sletz committed
234
235
        CheckRes(trans->Write(&fStatus, sizeof(int)));
        return 0;
236
    }
237

238
};
239

sletz's avatar
sletz committed
240
241
242
243
/*!
\brief NewClient request.
*/

sletz's avatar
sletz committed
244
struct JackClientOpenRequest : public JackRequest
sletz's avatar
sletz committed
245
246
{

247
    int fPID;
248
    int fUUID;
Stephane Letz's avatar
Stephane Letz committed
249
    char fName[JACK_CLIENT_NAME_SIZE+1];
250

251
252
253
254
    JackClientOpenRequest() : fPID(0), fUUID(0)
    {
        memset(fName, 0, sizeof(fName));
    }
255
    JackClientOpenRequest(const char* name, int pid, int uuid): JackRequest(JackRequest::kClientOpen)
sletz's avatar
sletz committed
256
    {
257
        memset(fName, 0, sizeof(fName));
sletz's avatar
sletz committed
258
        snprintf(fName, sizeof(fName), "%s", name);
259
        fPID = pid;
260
        fUUID = uuid;
sletz's avatar
sletz committed
261
262
    }

263
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
264
    {
sletz's avatar
sletz committed
265
        CheckSize();
266
        CheckRes(trans->Read(&fPID, sizeof(int)));
267
        CheckRes(trans->Read(&fUUID, sizeof(int)));
268
        return trans->Read(&fName, sizeof(fName));
sletz's avatar
sletz committed
269
270
    }

271
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
272
    {
sletz's avatar
sletz committed
273
        CheckRes(JackRequest::Write(trans, Size()));
274
        CheckRes(trans->Write(&fPID, sizeof(int)));
275
        CheckRes(trans->Write(&fUUID, sizeof(int)));
276
        return trans->Write(&fName, sizeof(fName));
sletz's avatar
sletz committed
277
    }
278

sletz's avatar
sletz committed
279
280
    int Size() { return 2 * sizeof(int) + sizeof(fName); }
    
281
};
sletz's avatar
sletz committed
282
283
284
285
286

/*!
\brief NewClient result.
*/

sletz's avatar
sletz committed
287
struct JackClientOpenResult : public JackResult
sletz's avatar
sletz committed
288
289
290
291
{

    int fSharedEngine;
    int fSharedClient;
sletz's avatar
sletz committed
292
    int fSharedGraph;
293

sletz's avatar
sletz committed
294
    JackClientOpenResult()
295
            : JackResult(), fSharedEngine(-1), fSharedClient(-1), fSharedGraph(-1)
sletz's avatar
sletz committed
296
    {}
297
    JackClientOpenResult(int32_t result, int index1, int index2, int index3)
298
            : JackResult(result), fSharedEngine(index1), fSharedClient(index2), fSharedGraph(index3)
sletz's avatar
sletz committed
299
300
    {}

301
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
302
    {
sletz's avatar
sletz committed
303
304
305
306
        CheckRes(JackResult::Read(trans));
        CheckRes(trans->Read(&fSharedEngine, sizeof(int)));
        CheckRes(trans->Read(&fSharedClient, sizeof(int)));
        CheckRes(trans->Read(&fSharedGraph, sizeof(int)));
307
        return 0;
sletz's avatar
sletz committed
308
309
    }

310
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
311
    {
sletz's avatar
sletz committed
312
313
314
315
316
        CheckRes(JackResult::Write(trans));
        CheckRes(trans->Write(&fSharedEngine, sizeof(int)));
        CheckRes(trans->Write(&fSharedClient, sizeof(int)));
        CheckRes(trans->Write(&fSharedGraph, sizeof(int)));
        return 0;
sletz's avatar
sletz committed
317
    }
318

319
};
sletz's avatar
sletz committed
320
321
322
323
324

/*!
\brief CloseClient request.
*/

325
struct JackClientCloseRequest : public JackRequest
sletz's avatar
sletz committed
326
327
328
329
{

    int fRefNum;

330
    JackClientCloseRequest() : fRefNum(0)
sletz's avatar
sletz committed
331
    {}
332
    JackClientCloseRequest(int refnum): JackRequest(JackRequest::kClientClose), fRefNum(refnum)
sletz's avatar
sletz committed
333
334
    {}

335
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
336
    {
sletz's avatar
sletz committed
337
        CheckSize();
sletz's avatar
sletz committed
338
        return trans->Read(&fRefNum, sizeof(int));
sletz's avatar
sletz committed
339
340
    }

341
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
342
    {
sletz's avatar
sletz committed
343
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
344
        return trans->Write(&fRefNum, sizeof(int));
sletz's avatar
sletz committed
345
    }
346

sletz's avatar
sletz committed
347
    int Size() { return sizeof(int); }
348
};
sletz's avatar
sletz committed
349
350
351
352
353

/*!
\brief Activate request.
*/

354
struct JackActivateRequest : public JackRequest
sletz's avatar
sletz committed
355
356
357
{

    int fRefNum;
sletz's avatar
sletz committed
358
    int fIsRealTime;
sletz's avatar
sletz committed
359

360
    JackActivateRequest() : fRefNum(0), fIsRealTime(0)
sletz's avatar
sletz committed
361
    {}
sletz's avatar
sletz committed
362
363
    JackActivateRequest(int refnum, int is_real_time)
        : JackRequest(JackRequest::kActivateClient), fRefNum(refnum), fIsRealTime(is_real_time)
sletz's avatar
sletz committed
364
365
    {}

366
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
367
    {
sletz's avatar
sletz committed
368
        CheckSize();
369
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
sletz's avatar
sletz committed
370
        return trans->Read(&fIsRealTime, sizeof(int));
sletz's avatar
sletz committed
371
372
    }

373
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
374
    {
sletz's avatar
sletz committed
375
        CheckRes(JackRequest::Write(trans, Size()));
376
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
sletz's avatar
sletz committed
377
        return trans->Write(&fIsRealTime, sizeof(int));
sletz's avatar
sletz committed
378
379
    }

sletz's avatar
sletz committed
380
    int Size() { return 2 * sizeof(int); }
381
};
sletz's avatar
sletz committed
382
383
384
385
386

/*!
\brief Deactivate request.
*/

387
struct JackDeactivateRequest : public JackRequest
sletz's avatar
sletz committed
388
389
390
391
{

    int fRefNum;

392
    JackDeactivateRequest() : fRefNum(0)
sletz's avatar
sletz committed
393
    {}
394
    JackDeactivateRequest(int refnum): JackRequest(JackRequest::kDeactivateClient), fRefNum(refnum)
sletz's avatar
sletz committed
395
396
    {}

397
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
398
    {
sletz's avatar
sletz committed
399
        CheckSize();
sletz's avatar
sletz committed
400
        return trans->Read(&fRefNum, sizeof(int));
sletz's avatar
sletz committed
401
402
    }

403
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
404
    {
sletz's avatar
sletz committed
405
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
406
        return trans->Write(&fRefNum, sizeof(int));
sletz's avatar
sletz committed
407
408
    }

sletz's avatar
sletz committed
409
    int Size() { return sizeof(int); }
410
};
sletz's avatar
sletz committed
411
412
413
414
415

/*!
\brief PortRegister request.
*/

416
struct JackPortRegisterRequest : public JackRequest
sletz's avatar
sletz committed
417
418
419
{

    int fRefNum;
420
    char fName[JACK_PORT_NAME_SIZE + 1];   // port short name
sletz's avatar
sletz committed
421
422
423
424
    char fPortType[JACK_PORT_TYPE_SIZE + 1];
    unsigned int fFlags;
    unsigned int fBufferSize;

425
426
427
428
429
    JackPortRegisterRequest() : fRefNum(0), fFlags(0), fBufferSize(0)
    {
        memset(fName, 0, sizeof(fName));
        memset(fPortType, 0, sizeof(fPortType));
    }
sletz's avatar
sletz committed
430
    JackPortRegisterRequest(int refnum, const char* name, const char* port_type, unsigned int flags, unsigned int buffer_size)
431
            : JackRequest(JackRequest::kRegisterPort), fRefNum(refnum), fFlags(flags), fBufferSize(buffer_size)
sletz's avatar
sletz committed
432
    {
433
434
435
436
        memset(fName, 0, sizeof(fName));
        memset(fPortType, 0, sizeof(fPortType));
        strncpy(fName, name, sizeof(fName)-1);
        strncpy(fPortType, port_type, sizeof(fPortType)-1);
sletz's avatar
sletz committed
437
438
    }

439
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
440
    {
sletz's avatar
sletz committed
441
        CheckSize();
sletz's avatar
sletz committed
442
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
443
444
        CheckRes(trans->Read(&fName, sizeof(fName)));
        CheckRes(trans->Read(&fPortType, sizeof(fPortType)));
sletz's avatar
sletz committed
445
446
447
        CheckRes(trans->Read(&fFlags, sizeof(unsigned int)));
        CheckRes(trans->Read(&fBufferSize, sizeof(unsigned int)));
        return 0;
sletz's avatar
sletz committed
448
449
    }

450
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
451
    {
sletz's avatar
sletz committed
452
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
453
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
454
455
        CheckRes(trans->Write(&fName, sizeof(fName)));
        CheckRes(trans->Write(&fPortType, sizeof(fPortType)));
sletz's avatar
sletz committed
456
457
458
        CheckRes(trans->Write(&fFlags, sizeof(unsigned int)));
        CheckRes(trans->Write(&fBufferSize, sizeof(unsigned int)));
        return 0;
sletz's avatar
sletz committed
459
    }
sletz's avatar
sletz committed
460
461
    
    int Size() { return sizeof(int) + sizeof(fName) + sizeof(fPortType) + 2 * sizeof(unsigned int); }
462

463
};
sletz's avatar
sletz committed
464
465
466
467
468

/*!
\brief PortRegister result.
*/

469
struct JackPortRegisterResult : public JackResult
sletz's avatar
sletz committed
470
471
{

472
    jack_port_id_t fPortIndex;
sletz's avatar
sletz committed
473

sletz's avatar
sletz committed
474
    JackPortRegisterResult(): JackResult(), fPortIndex(NO_PORT)
sletz's avatar
sletz committed
475
476
    {}

477
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
Cleanup    
sletz committed
478
    {
sletz's avatar
sletz committed
479
480
        CheckRes(JackResult::Read(trans));
        return trans->Read(&fPortIndex, sizeof(jack_port_id_t));
sletz's avatar
sletz committed
481
482
    }

483
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
484
    {
sletz's avatar
sletz committed
485
486
        CheckRes(JackResult::Write(trans));
        return trans->Write(&fPortIndex, sizeof(jack_port_id_t));
sletz's avatar
sletz committed
487
    }
488

489
};
sletz's avatar
sletz committed
490
491
492
493
494

/*!
\brief PortUnregister request.
*/

495
struct JackPortUnRegisterRequest : public JackRequest
sletz's avatar
sletz committed
496
497
498
{

    int fRefNum;
499
    jack_port_id_t fPortIndex;
sletz's avatar
sletz committed
500

501
    JackPortUnRegisterRequest() : fRefNum(0), fPortIndex(0)
sletz's avatar
sletz committed
502
    {}
503
    JackPortUnRegisterRequest(int refnum, jack_port_id_t index)
504
        : JackRequest(JackRequest::kUnRegisterPort), fRefNum(refnum), fPortIndex(index)
sletz's avatar
sletz committed
505
506
    {}

507
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
508
    {
sletz's avatar
sletz committed
509
        CheckSize();
sletz's avatar
sletz committed
510
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
sletz's avatar
sletz committed
511
        CheckRes(trans->Read(&fPortIndex, sizeof(jack_port_id_t)));
sletz's avatar
sletz committed
512
        return 0;
sletz's avatar
sletz committed
513
514
    }

515
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
516
    {
sletz's avatar
sletz committed
517
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
518
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
sletz's avatar
sletz committed
519
        CheckRes(trans->Write(&fPortIndex, sizeof(jack_port_id_t)));
sletz's avatar
sletz committed
520
        return 0;
sletz's avatar
sletz committed
521
    }
522

sletz's avatar
sletz committed
523
    int Size() { return sizeof(int) + sizeof(jack_port_id_t); }
524
};
sletz's avatar
sletz committed
525
526
527
528
529

/*!
\brief PortConnectName request.
*/

530
struct JackPortConnectNameRequest : public JackRequest
sletz's avatar
sletz committed
531
{
sletz's avatar
sletz committed
532

sletz's avatar
sletz committed
533
    int fRefNum;
Stephane Letz's avatar
Stephane Letz committed
534
535
    char fSrc[REAL_JACK_PORT_NAME_SIZE+1];    // port full name
    char fDst[REAL_JACK_PORT_NAME_SIZE+1];    // port full name
sletz's avatar
sletz committed
536

537
538
539
540
541
    JackPortConnectNameRequest() : fRefNum(0)
    {
        memset(fSrc, 0, sizeof(fSrc));
        memset(fDst, 0, sizeof(fDst));
    }
542
543
    JackPortConnectNameRequest(int refnum, const char* src_name, const char* dst_name)
        : JackRequest(JackRequest::kConnectNamePorts), fRefNum(refnum)
sletz's avatar
sletz committed
544
    {
545
546
547
548
        memset(fSrc, 0, sizeof(fSrc));
        memset(fDst, 0, sizeof(fDst));
        strncpy(fSrc, src_name, sizeof(fSrc)-1);
        strncpy(fDst, dst_name, sizeof(fDst)-1);
sletz's avatar
sletz committed
549
550
    }

551
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
552
    {
sletz's avatar
sletz committed
553
        CheckSize();
sletz's avatar
sletz committed
554
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
555
556
        CheckRes(trans->Read(&fSrc, sizeof(fSrc)));
        CheckRes(trans->Read(&fDst, sizeof(fDst)));
sletz's avatar
sletz committed
557
        return 0;
sletz's avatar
sletz committed
558
559
    }

560
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
561
    {
sletz's avatar
sletz committed
562
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
563
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
564
565
        CheckRes(trans->Write(&fSrc, sizeof(fSrc)));
        CheckRes(trans->Write(&fDst, sizeof(fDst)));
sletz's avatar
sletz committed
566
        return 0;
sletz's avatar
sletz committed
567
    }
sletz's avatar
sletz committed
568
569
    
    int Size() { return sizeof(int) + sizeof(fSrc) + sizeof(fDst); }
570

571
};
sletz's avatar
sletz committed
572
573
574
575
576

/*!
\brief PortDisconnectName request.
*/

577
struct JackPortDisconnectNameRequest : public JackRequest
sletz's avatar
sletz committed
578
579
580
{

    int fRefNum;
Stephane Letz's avatar
Stephane Letz committed
581
582
    char fSrc[REAL_JACK_PORT_NAME_SIZE+1];    // port full name
    char fDst[REAL_JACK_PORT_NAME_SIZE+1];    // port full name
sletz's avatar
sletz committed
583

584
585
586
587
588
    JackPortDisconnectNameRequest() : fRefNum(0)
    {
        memset(fSrc, 0, sizeof(fSrc));
        memset(fDst, 0, sizeof(fDst));
    }
589
590
    JackPortDisconnectNameRequest(int refnum, const char* src_name, const char* dst_name)
        : JackRequest(JackRequest::kDisconnectNamePorts), fRefNum(refnum)
sletz's avatar
sletz committed
591
    {
592
593
594
595
        memset(fSrc, 0, sizeof(fSrc));
        memset(fDst, 0, sizeof(fDst));
        strncpy(fSrc, src_name, sizeof(fSrc)-1);
        strncpy(fDst, dst_name, sizeof(fDst)-1);
sletz's avatar
sletz committed
596
597
    }

598
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
599
    {
sletz's avatar
sletz committed
600
        CheckSize();
sletz's avatar
sletz committed
601
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
602
603
        CheckRes(trans->Read(&fSrc, sizeof(fSrc)));
        CheckRes(trans->Read(&fDst, sizeof(fDst)));
sletz's avatar
sletz committed
604
        return 0;
sletz's avatar
sletz committed
605
606
    }

607
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
608
    {
sletz's avatar
sletz committed
609
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
610
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
611
612
        CheckRes(trans->Write(&fSrc, sizeof(fSrc)));
        CheckRes(trans->Write(&fDst, sizeof(fDst)));
sletz's avatar
sletz committed
613
        return 0;
sletz's avatar
sletz committed
614
    }
615

sletz's avatar
sletz committed
616
617
    int Size() { return sizeof(int) + sizeof(fSrc) + sizeof(fDst); }
    
618
};
sletz's avatar
sletz committed
619
620
621
622
623

/*!
\brief PortConnect request.
*/

624
struct JackPortConnectRequest : public JackRequest
sletz's avatar
sletz committed
625
626
627
628
629
630
{

    int fRefNum;
    jack_port_id_t fSrc;
    jack_port_id_t fDst;

631
    JackPortConnectRequest() : fRefNum(0), fSrc(0), fDst(0)
sletz's avatar
sletz committed
632
    {}
633
634
    JackPortConnectRequest(int refnum, jack_port_id_t src, jack_port_id_t dst)
        : JackRequest(JackRequest::kConnectPorts), fRefNum(refnum), fSrc(src), fDst(dst)
sletz's avatar
sletz committed
635
636
    {}

637
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
638
    {
sletz's avatar
sletz committed
639
        CheckSize();
sletz's avatar
sletz committed
640
641
642
643
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
        CheckRes(trans->Read(&fSrc, sizeof(jack_port_id_t)));
        CheckRes(trans->Read(&fDst, sizeof(jack_port_id_t)));
        return 0;
sletz's avatar
sletz committed
644
645
    }

646
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
647
    {
sletz's avatar
sletz committed
648
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
649
650
651
652
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
        CheckRes(trans->Write(&fSrc, sizeof(jack_port_id_t)));
        CheckRes(trans->Write(&fDst, sizeof(jack_port_id_t)));
        return 0;
sletz's avatar
sletz committed
653
    }
654

sletz's avatar
sletz committed
655
    int Size() { return sizeof(int) + sizeof(jack_port_id_t) + sizeof(jack_port_id_t); }
656
};
sletz's avatar
sletz committed
657
658
659
660
661

/*!
\brief PortDisconnect request.
*/

662
struct JackPortDisconnectRequest : public JackRequest
sletz's avatar
sletz committed
663
664
665
666
667
668
{

    int fRefNum;
    jack_port_id_t fSrc;
    jack_port_id_t fDst;

669
    JackPortDisconnectRequest() : fRefNum(0), fSrc(0), fDst(0)
sletz's avatar
sletz committed
670
    {}
671
672
    JackPortDisconnectRequest(int refnum, jack_port_id_t src, jack_port_id_t dst)
        : JackRequest(JackRequest::kDisconnectPorts), fRefNum(refnum), fSrc(src), fDst(dst)
sletz's avatar
sletz committed
673
674
    {}

675
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
676
    {
sletz's avatar
sletz committed
677
        CheckSize();
sletz's avatar
sletz committed
678
679
680
681
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
        CheckRes(trans->Read(&fSrc, sizeof(jack_port_id_t)));
        CheckRes(trans->Read(&fDst, sizeof(jack_port_id_t)));
        return 0;
sletz's avatar
sletz committed
682
683
    }

684
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
685
    {
sletz's avatar
sletz committed
686
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
687
688
689
690
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
        CheckRes(trans->Write(&fSrc, sizeof(jack_port_id_t)));
        CheckRes(trans->Write(&fDst, sizeof(jack_port_id_t)));
        return 0;
sletz's avatar
sletz committed
691
    }
692

sletz's avatar
sletz committed
693
    int Size() { return sizeof(int) + sizeof(jack_port_id_t) + sizeof(jack_port_id_t); }
694
};
sletz's avatar
sletz committed
695

696
697
698
699
700
701
702
703
704
/*!
\brief PortRename request.
*/

struct JackPortRenameRequest : public JackRequest
{

    int fRefNum;
    jack_port_id_t fPort;
705
    char fName[JACK_PORT_NAME_SIZE + 1];   // port short name
706

707
708
709
710
    JackPortRenameRequest() : fRefNum(0), fPort(0)
    {
        memset(fName, 0, sizeof(fName));
    }
711
712
713
    JackPortRenameRequest(int refnum, jack_port_id_t port, const char* name)
        : JackRequest(JackRequest::kPortRename), fRefNum(refnum), fPort(port)
    {
714
715
        memset(fName, 0, sizeof(fName));
        strncpy(fName, name, sizeof(fName)-1);
716
717
    }

718
    int Read(detail::JackChannelTransactionInterface* trans)
719
    {
sletz's avatar
sletz committed
720
        CheckSize();
721
722
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
        CheckRes(trans->Read(&fPort, sizeof(jack_port_id_t)));
723
        CheckRes(trans->Read(&fName, sizeof(fName)));
724
725
726
        return 0;
    }

727
    int Write(detail::JackChannelTransactionInterface* trans)
728
    {
sletz's avatar
sletz committed
729
        CheckRes(JackRequest::Write(trans, Size()));
730
731
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
        CheckRes(trans->Write(&fPort, sizeof(jack_port_id_t)));
732
        CheckRes(trans->Write(&fName, sizeof(fName)));
733
734
        return 0;
    }
sletz's avatar
sletz committed
735
736
    
    int Size() { return sizeof(int) + sizeof(jack_port_id_t) + sizeof(fName); }
737

738
};
739

sletz's avatar
sletz committed
740
741
742
743
/*!
\brief SetBufferSize request.
*/

744
struct JackSetBufferSizeRequest : public JackRequest
sletz's avatar
sletz committed
745
746
747
748
{

    jack_nframes_t fBufferSize;

749
    JackSetBufferSizeRequest() : fBufferSize(0)
sletz's avatar
sletz committed
750
    {}
751
752
    JackSetBufferSizeRequest(jack_nframes_t buffer_size)
        : JackRequest(JackRequest::kSetBufferSize), fBufferSize(buffer_size)
sletz's avatar
sletz committed
753
754
    {}

755
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
756
    {
sletz's avatar
sletz committed
757
        CheckSize();
sletz's avatar
sletz committed
758
        return trans->Read(&fBufferSize, sizeof(jack_nframes_t));
sletz's avatar
sletz committed
759
760
    }

761
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
762
    {
sletz's avatar
sletz committed
763
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
764
        return trans->Write(&fBufferSize, sizeof(jack_nframes_t));
sletz's avatar
sletz committed
765
    }
766

sletz's avatar
sletz committed
767
    int Size() { return sizeof(jack_nframes_t); }
768
};
sletz's avatar
sletz committed
769
770
771
772
773

/*!
\brief SetFreeWheel request.
*/

774
struct JackSetFreeWheelRequest : public JackRequest
sletz's avatar
sletz committed
775
776
777
778
{

    int fOnOff;

779
    JackSetFreeWheelRequest() : fOnOff(0)
sletz's avatar
sletz committed
780
    {}
781
782
    JackSetFreeWheelRequest(int onoff)
        : JackRequest(JackRequest::kSetFreeWheel), fOnOff(onoff)
sletz's avatar
sletz committed
783
784
    {}

785
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
786
    {
sletz's avatar
sletz committed
787
        CheckSize();
sletz's avatar
sletz committed
788
        return trans->Read(&fOnOff, sizeof(int));
sletz's avatar
sletz committed
789
790
    }

791
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
792
    {
sletz's avatar
sletz committed
793
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
794
        return trans->Write(&fOnOff, sizeof(int));
sletz's avatar
sletz committed
795
    }
sletz's avatar
sletz committed
796
797
    
    int Size() { return sizeof(int); }
798
799
800
801
802
803
804
805
806
807
808
809
810
811

};

/*!
\brief ComputeTotalLatencies request.
*/

struct JackComputeTotalLatenciesRequest : public JackRequest
{

    JackComputeTotalLatenciesRequest()
        : JackRequest(JackRequest::kComputeTotalLatencies)
    {}

812
    int Read(detail::JackChannelTransactionInterface* trans)
813
    {
sletz's avatar
sletz committed
814
        CheckSize();
815
816
817
        return 0;
    }

818
    int Write(detail::JackChannelTransactionInterface* trans)
819
    {
sletz's avatar
sletz committed
820
        CheckRes(JackRequest::Write(trans, Size()));
821
822
823
        return 0;
    }

sletz's avatar
sletz committed
824
    int Size() { return 0; }
825
};
sletz's avatar
sletz committed
826
827
828
829
830

/*!
\brief ReleaseTimebase request.
*/

831
struct JackReleaseTimebaseRequest : public JackRequest
sletz's avatar
sletz committed
832
833
834
835
{

    int fRefNum;

836
    JackReleaseTimebaseRequest() : fRefNum(0)
sletz's avatar
sletz committed
837
    {}
838
839
    JackReleaseTimebaseRequest(int refnum)
        : JackRequest(JackRequest::kReleaseTimebase), fRefNum(refnum)
sletz's avatar
sletz committed
840
841
    {}

842
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
843
    {
sletz's avatar
sletz committed
844
        CheckSize();
sletz's avatar
sletz committed
845
        return trans->Read(&fRefNum, sizeof(int));
sletz's avatar
sletz committed
846
847
    }

848
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed