JackRequest.h 42.1 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
160
/*!
\brief CheckClient request.
*/

struct JackClientCheckRequest : public JackRequest
{

    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

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

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

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

196
};
197
198
199
200
201
202
203
204

/*!
\brief CheckClient result.
*/

struct JackClientCheckResult : public JackResult
{

sletz's avatar
sletz committed
205
206
    char fName[JACK_CLIENT_NAME_SIZE + 1];
    int fStatus;
207

sletz's avatar
sletz committed
208
    JackClientCheckResult(): JackResult(), fStatus(0)
209
210
    {}
    JackClientCheckResult(int32_t result, const char* name, int status)
sletz's avatar
sletz committed
211
            : JackResult(result), fStatus(status)
212
    {
sletz's avatar
sletz committed
213
214
        snprintf(fName, sizeof(fName), "%s", name);
    }
215

216
    int Read(detail::JackChannelTransactionInterface* trans)
217
    {
sletz's avatar
sletz committed
218
        CheckRes(JackResult::Read(trans));
219
        CheckRes(trans->Read(&fName, sizeof(fName)));
sletz's avatar
sletz committed
220
221
        CheckRes(trans->Read(&fStatus, sizeof(int)));
        return 0;
222
223
    }

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

232
};
233

sletz's avatar
sletz committed
234
235
236
237
/*!
\brief NewClient request.
*/

sletz's avatar
sletz committed
238
struct JackClientOpenRequest : public JackRequest
sletz's avatar
sletz committed
239
240
{

241
    int fPID;
242
    int fUUID;
sletz's avatar
sletz committed
243
    char fName[JACK_CLIENT_NAME_SIZE + 1];
244

sletz's avatar
sletz committed
245
    JackClientOpenRequest()
sletz's avatar
sletz committed
246
    {}
247
    JackClientOpenRequest(const char* name, int pid, int uuid): JackRequest(JackRequest::kClientOpen)
sletz's avatar
sletz committed
248
249
    {
        snprintf(fName, sizeof(fName), "%s", name);
250
        fPID = pid;
251
        fUUID = uuid;
sletz's avatar
sletz committed
252
253
    }

254
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
255
    {
sletz's avatar
sletz committed
256
        CheckSize();
257
        CheckRes(trans->Read(&fPID, sizeof(int)));
258
        CheckRes(trans->Read(&fUUID, sizeof(int)));
259
        return trans->Read(&fName, sizeof(fName));
sletz's avatar
sletz committed
260
261
    }

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

sletz's avatar
sletz committed
270
271
    int Size() { return 2 * sizeof(int) + sizeof(fName); }
    
272
};
sletz's avatar
sletz committed
273
274
275
276
277

/*!
\brief NewClient result.
*/

sletz's avatar
sletz committed
278
struct JackClientOpenResult : public JackResult
sletz's avatar
sletz committed
279
280
281
282
{

    int fSharedEngine;
    int fSharedClient;
sletz's avatar
sletz committed
283
    int fSharedGraph;
284

sletz's avatar
sletz committed
285
    JackClientOpenResult()
286
            : JackResult(), fSharedEngine(-1), fSharedClient(-1), fSharedGraph(-1)
sletz's avatar
sletz committed
287
    {}
288
    JackClientOpenResult(int32_t result, int index1, int index2, int index3)
289
            : JackResult(result), fSharedEngine(index1), fSharedClient(index2), fSharedGraph(index3)
sletz's avatar
sletz committed
290
291
    {}

292
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
293
    {
sletz's avatar
sletz committed
294
295
296
297
        CheckRes(JackResult::Read(trans));
        CheckRes(trans->Read(&fSharedEngine, sizeof(int)));
        CheckRes(trans->Read(&fSharedClient, sizeof(int)));
        CheckRes(trans->Read(&fSharedGraph, sizeof(int)));
298
        return 0;
sletz's avatar
sletz committed
299
300
    }

301
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
302
    {
sletz's avatar
sletz committed
303
304
305
306
307
        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
308
    }
309

310
};
sletz's avatar
sletz committed
311
312
313
314
315

/*!
\brief CloseClient request.
*/

316
struct JackClientCloseRequest : public JackRequest
sletz's avatar
sletz committed
317
318
319
320
321
322
{

    int fRefNum;

    JackClientCloseRequest()
    {}
323
    JackClientCloseRequest(int refnum): JackRequest(JackRequest::kClientClose), fRefNum(refnum)
sletz's avatar
sletz committed
324
325
    {}

326
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
327
    {
sletz's avatar
sletz committed
328
        CheckSize();
sletz's avatar
sletz committed
329
        return trans->Read(&fRefNum, sizeof(int));
sletz's avatar
sletz committed
330
331
    }

332
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
333
    {
sletz's avatar
sletz committed
334
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
335
        return trans->Write(&fRefNum, sizeof(int));
sletz's avatar
sletz committed
336
    }
337

sletz's avatar
sletz committed
338
    int Size() { return sizeof(int); }
339
};
sletz's avatar
sletz committed
340
341
342
343
344

/*!
\brief Activate request.
*/

345
struct JackActivateRequest : public JackRequest
sletz's avatar
sletz committed
346
347
348
{

    int fRefNum;
sletz's avatar
sletz committed
349
    int fIsRealTime;
sletz's avatar
sletz committed
350
351
352

    JackActivateRequest()
    {}
sletz's avatar
sletz committed
353
354
    JackActivateRequest(int refnum, int is_real_time)
        : JackRequest(JackRequest::kActivateClient), fRefNum(refnum), fIsRealTime(is_real_time)
sletz's avatar
sletz committed
355
356
    {}

357
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
358
    {
sletz's avatar
sletz committed
359
        CheckSize();
360
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
sletz's avatar
sletz committed
361
        return trans->Read(&fIsRealTime, sizeof(int));
sletz's avatar
sletz committed
362
363
    }

364
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
365
    {
sletz's avatar
sletz committed
366
        CheckRes(JackRequest::Write(trans, Size()));
367
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
sletz's avatar
sletz committed
368
        return trans->Write(&fIsRealTime, sizeof(int));
sletz's avatar
sletz committed
369
370
    }

sletz's avatar
sletz committed
371
    int Size() { return 2 * sizeof(int); }
372
};
sletz's avatar
sletz committed
373
374
375
376
377

/*!
\brief Deactivate request.
*/

378
struct JackDeactivateRequest : public JackRequest
sletz's avatar
sletz committed
379
380
381
382
383
384
{

    int fRefNum;

    JackDeactivateRequest()
    {}
385
    JackDeactivateRequest(int refnum): JackRequest(JackRequest::kDeactivateClient), fRefNum(refnum)
sletz's avatar
sletz committed
386
387
    {}

388
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
389
    {
sletz's avatar
sletz committed
390
        CheckSize();
sletz's avatar
sletz committed
391
        return trans->Read(&fRefNum, sizeof(int));
sletz's avatar
sletz committed
392
393
    }

394
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
395
    {
sletz's avatar
sletz committed
396
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
397
        return trans->Write(&fRefNum, sizeof(int));
sletz's avatar
sletz committed
398
399
    }

sletz's avatar
sletz committed
400
    int Size() { return sizeof(int); }
401
};
sletz's avatar
sletz committed
402
403
404
405
406

/*!
\brief PortRegister request.
*/

407
struct JackPortRegisterRequest : public JackRequest
sletz's avatar
sletz committed
408
409
410
{

    int fRefNum;
411
    char fName[JACK_PORT_NAME_SIZE + 1];   // port short name
sletz's avatar
sletz committed
412
413
414
415
416
417
418
    char fPortType[JACK_PORT_TYPE_SIZE + 1];
    unsigned int fFlags;
    unsigned int fBufferSize;

    JackPortRegisterRequest()
    {}
    JackPortRegisterRequest(int refnum, const char* name, const char* port_type, unsigned int flags, unsigned int buffer_size)
419
            : JackRequest(JackRequest::kRegisterPort), fRefNum(refnum), fFlags(flags), fBufferSize(buffer_size)
sletz's avatar
sletz committed
420
421
422
423
424
    {
        strcpy(fName, name);
        strcpy(fPortType, port_type);
    }

425
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
426
    {
sletz's avatar
sletz committed
427
        CheckSize();
sletz's avatar
sletz committed
428
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
429
430
        CheckRes(trans->Read(&fName, sizeof(fName)));
        CheckRes(trans->Read(&fPortType, sizeof(fPortType)));
sletz's avatar
sletz committed
431
432
433
        CheckRes(trans->Read(&fFlags, sizeof(unsigned int)));
        CheckRes(trans->Read(&fBufferSize, sizeof(unsigned int)));
        return 0;
sletz's avatar
sletz committed
434
435
    }

436
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
437
    {
sletz's avatar
sletz committed
438
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
439
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
440
441
        CheckRes(trans->Write(&fName, sizeof(fName)));
        CheckRes(trans->Write(&fPortType, sizeof(fPortType)));
sletz's avatar
sletz committed
442
443
444
        CheckRes(trans->Write(&fFlags, sizeof(unsigned int)));
        CheckRes(trans->Write(&fBufferSize, sizeof(unsigned int)));
        return 0;
sletz's avatar
sletz committed
445
    }
sletz's avatar
sletz committed
446
447
    
    int Size() { return sizeof(int) + sizeof(fName) + sizeof(fPortType) + 2 * sizeof(unsigned int); }
448

449
};
sletz's avatar
sletz committed
450
451
452
453
454

/*!
\brief PortRegister result.
*/

455
struct JackPortRegisterResult : public JackResult
sletz's avatar
sletz committed
456
457
{

458
    jack_port_id_t fPortIndex;
sletz's avatar
sletz committed
459

sletz's avatar
sletz committed
460
    JackPortRegisterResult(): JackResult(), fPortIndex(NO_PORT)
sletz's avatar
sletz committed
461
462
    {}

463
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
Cleanup    
sletz committed
464
    {
sletz's avatar
sletz committed
465
466
        CheckRes(JackResult::Read(trans));
        return trans->Read(&fPortIndex, sizeof(jack_port_id_t));
sletz's avatar
sletz committed
467
468
    }

469
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
470
    {
sletz's avatar
sletz committed
471
472
        CheckRes(JackResult::Write(trans));
        return trans->Write(&fPortIndex, sizeof(jack_port_id_t));
sletz's avatar
sletz committed
473
    }
474

475
};
sletz's avatar
sletz committed
476
477
478
479
480

/*!
\brief PortUnregister request.
*/

481
struct JackPortUnRegisterRequest : public JackRequest
sletz's avatar
sletz committed
482
483
484
{

    int fRefNum;
485
    jack_port_id_t fPortIndex;
sletz's avatar
sletz committed
486
487
488

    JackPortUnRegisterRequest()
    {}
489
    JackPortUnRegisterRequest(int refnum, jack_port_id_t index)
490
        : JackRequest(JackRequest::kUnRegisterPort), fRefNum(refnum), fPortIndex(index)
sletz's avatar
sletz committed
491
492
    {}

493
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
494
    {
sletz's avatar
sletz committed
495
        CheckSize();
sletz's avatar
sletz committed
496
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
sletz's avatar
sletz committed
497
        CheckRes(trans->Read(&fPortIndex, sizeof(jack_port_id_t)));
sletz's avatar
sletz committed
498
        return 0;
sletz's avatar
sletz committed
499
500
    }

501
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
502
    {
sletz's avatar
sletz committed
503
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
504
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
sletz's avatar
sletz committed
505
        CheckRes(trans->Write(&fPortIndex, sizeof(jack_port_id_t)));
sletz's avatar
sletz committed
506
        return 0;
sletz's avatar
sletz committed
507
    }
508

sletz's avatar
sletz committed
509
    int Size() { return sizeof(int) + sizeof(jack_port_id_t); }
510
};
sletz's avatar
sletz committed
511
512
513
514
515

/*!
\brief PortConnectName request.
*/

516
struct JackPortConnectNameRequest : public JackRequest
sletz's avatar
sletz committed
517
{
sletz's avatar
sletz committed
518

sletz's avatar
sletz committed
519
    int fRefNum;
520
521
    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
522
523
524

    JackPortConnectNameRequest()
    {}
525
526
    JackPortConnectNameRequest(int refnum, const char* src_name, const char* dst_name)
        : JackRequest(JackRequest::kConnectNamePorts), fRefNum(refnum)
sletz's avatar
sletz committed
527
528
529
530
531
    {
        strcpy(fSrc, src_name);
        strcpy(fDst, dst_name);
    }

532
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
533
    {
sletz's avatar
sletz committed
534
        CheckSize();
sletz's avatar
sletz committed
535
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
536
537
        CheckRes(trans->Read(&fSrc, sizeof(fSrc)));
        CheckRes(trans->Read(&fDst, sizeof(fDst)));
sletz's avatar
sletz committed
538
        return 0;
sletz's avatar
sletz committed
539
540
    }

541
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
542
    {
sletz's avatar
sletz committed
543
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
544
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
545
546
        CheckRes(trans->Write(&fSrc, sizeof(fSrc)));
        CheckRes(trans->Write(&fDst, sizeof(fDst)));
sletz's avatar
sletz committed
547
        return 0;
sletz's avatar
sletz committed
548
    }
sletz's avatar
sletz committed
549
550
    
    int Size() { return sizeof(int) + sizeof(fSrc) + sizeof(fDst); }
551

552
};
sletz's avatar
sletz committed
553
554
555
556
557

/*!
\brief PortDisconnectName request.
*/

558
struct JackPortDisconnectNameRequest : public JackRequest
sletz's avatar
sletz committed
559
560
561
{

    int fRefNum;
562
563
    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
564
565
566

    JackPortDisconnectNameRequest()
    {}
567
568
    JackPortDisconnectNameRequest(int refnum, const char* src_name, const char* dst_name)
        : JackRequest(JackRequest::kDisconnectNamePorts), fRefNum(refnum)
sletz's avatar
sletz committed
569
570
571
572
573
    {
        strcpy(fSrc, src_name);
        strcpy(fDst, dst_name);
    }

574
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
575
    {
sletz's avatar
sletz committed
576
        CheckSize();
sletz's avatar
sletz committed
577
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
578
579
        CheckRes(trans->Read(&fSrc, sizeof(fSrc)));
        CheckRes(trans->Read(&fDst, sizeof(fDst)));
sletz's avatar
sletz committed
580
        return 0;
sletz's avatar
sletz committed
581
582
    }

583
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
584
    {
sletz's avatar
sletz committed
585
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
586
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
587
588
        CheckRes(trans->Write(&fSrc, sizeof(fSrc)));
        CheckRes(trans->Write(&fDst, sizeof(fDst)));
sletz's avatar
sletz committed
589
        return 0;
sletz's avatar
sletz committed
590
    }
591

sletz's avatar
sletz committed
592
593
    int Size() { return sizeof(int) + sizeof(fSrc) + sizeof(fDst); }
    
594
};
sletz's avatar
sletz committed
595
596
597
598
599

/*!
\brief PortConnect request.
*/

600
struct JackPortConnectRequest : public JackRequest
sletz's avatar
sletz committed
601
602
603
604
605
606
607
608
{

    int fRefNum;
    jack_port_id_t fSrc;
    jack_port_id_t fDst;

    JackPortConnectRequest()
    {}
609
610
    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
611
612
    {}

613
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
614
    {
sletz's avatar
sletz committed
615
        CheckSize();
sletz's avatar
sletz committed
616
617
618
619
        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
620
621
    }

622
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
623
    {
sletz's avatar
sletz committed
624
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
625
626
627
628
        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
629
    }
630

sletz's avatar
sletz committed
631
    int Size() { return sizeof(int) + sizeof(jack_port_id_t) + sizeof(jack_port_id_t); }
632
};
sletz's avatar
sletz committed
633
634
635
636
637

/*!
\brief PortDisconnect request.
*/

638
struct JackPortDisconnectRequest : public JackRequest
sletz's avatar
sletz committed
639
640
641
642
643
644
645
646
{

    int fRefNum;
    jack_port_id_t fSrc;
    jack_port_id_t fDst;

    JackPortDisconnectRequest()
    {}
647
648
    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
649
650
    {}

651
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
652
    {
sletz's avatar
sletz committed
653
        CheckSize();
sletz's avatar
sletz committed
654
655
656
657
        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
658
659
    }

660
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
661
    {
sletz's avatar
sletz committed
662
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
663
664
665
666
        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
667
    }
668

sletz's avatar
sletz committed
669
    int Size() { return sizeof(int) + sizeof(jack_port_id_t) + sizeof(jack_port_id_t); }
670
};
sletz's avatar
sletz committed
671

672
673
674
675
676
677
678
679
680
/*!
\brief PortRename request.
*/

struct JackPortRenameRequest : public JackRequest
{

    int fRefNum;
    jack_port_id_t fPort;
681
    char fName[JACK_PORT_NAME_SIZE + 1];   // port short name
682
683
684
685
686
687
688
689
690

    JackPortRenameRequest()
    {}
    JackPortRenameRequest(int refnum, jack_port_id_t port, const char* name)
        : JackRequest(JackRequest::kPortRename), fRefNum(refnum), fPort(port)
    {
        strcpy(fName, name);
    }

691
    int Read(detail::JackChannelTransactionInterface* trans)
692
    {
sletz's avatar
sletz committed
693
        CheckSize();
694
695
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
        CheckRes(trans->Read(&fPort, sizeof(jack_port_id_t)));
696
        CheckRes(trans->Read(&fName, sizeof(fName)));
697
698
699
        return 0;
    }

700
    int Write(detail::JackChannelTransactionInterface* trans)
701
    {
sletz's avatar
sletz committed
702
        CheckRes(JackRequest::Write(trans, Size()));
703
704
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
        CheckRes(trans->Write(&fPort, sizeof(jack_port_id_t)));
705
        CheckRes(trans->Write(&fName, sizeof(fName)));
706
707
        return 0;
    }
sletz's avatar
sletz committed
708
709
    
    int Size() { return sizeof(int) + sizeof(jack_port_id_t) + sizeof(fName); }
710

711
};
712

sletz's avatar
sletz committed
713
714
715
716
/*!
\brief SetBufferSize request.
*/

717
struct JackSetBufferSizeRequest : public JackRequest
sletz's avatar
sletz committed
718
719
720
721
722
723
{

    jack_nframes_t fBufferSize;

    JackSetBufferSizeRequest()
    {}
724
725
    JackSetBufferSizeRequest(jack_nframes_t buffer_size)
        : JackRequest(JackRequest::kSetBufferSize), fBufferSize(buffer_size)
sletz's avatar
sletz committed
726
727
    {}

728
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
729
    {
sletz's avatar
sletz committed
730
        CheckSize();
sletz's avatar
sletz committed
731
        return trans->Read(&fBufferSize, sizeof(jack_nframes_t));
sletz's avatar
sletz committed
732
733
    }

734
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
735
    {
sletz's avatar
sletz committed
736
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
737
        return trans->Write(&fBufferSize, sizeof(jack_nframes_t));
sletz's avatar
sletz committed
738
    }
739

sletz's avatar
sletz committed
740
    int Size() { return sizeof(jack_nframes_t); }
741
};
sletz's avatar
sletz committed
742
743
744
745
746

/*!
\brief SetFreeWheel request.
*/

747
struct JackSetFreeWheelRequest : public JackRequest
sletz's avatar
sletz committed
748
749
750
751
752
753
{

    int fOnOff;

    JackSetFreeWheelRequest()
    {}
754
755
    JackSetFreeWheelRequest(int onoff)
        : JackRequest(JackRequest::kSetFreeWheel), fOnOff(onoff)
sletz's avatar
sletz committed
756
757
    {}

758
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
759
    {
sletz's avatar
sletz committed
760
        CheckSize();
sletz's avatar
sletz committed
761
        return trans->Read(&fOnOff, sizeof(int));
sletz's avatar
sletz committed
762
763
    }

764
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
765
    {
sletz's avatar
sletz committed
766
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
767
        return trans->Write(&fOnOff, sizeof(int));
sletz's avatar
sletz committed
768
    }
sletz's avatar
sletz committed
769
770
    
    int Size() { return sizeof(int); }
771
772
773
774
775
776
777
778
779
780
781
782
783
784

};

/*!
\brief ComputeTotalLatencies request.
*/

struct JackComputeTotalLatenciesRequest : public JackRequest
{

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

785
    int Read(detail::JackChannelTransactionInterface* trans)
786
    {
sletz's avatar
sletz committed
787
        CheckSize();
788
789
790
        return 0;
    }

791
    int Write(detail::JackChannelTransactionInterface* trans)
792
    {
sletz's avatar
sletz committed
793
        CheckRes(JackRequest::Write(trans, Size()));
794
795
796
        return 0;
    }

sletz's avatar
sletz committed
797
    int Size() { return 0; }
798
};
sletz's avatar
sletz committed
799
800
801
802
803

/*!
\brief ReleaseTimebase request.
*/

804
struct JackReleaseTimebaseRequest : public JackRequest
sletz's avatar
sletz committed
805
806
807
808
809
810
{

    int fRefNum;

    JackReleaseTimebaseRequest()
    {}
811
812
    JackReleaseTimebaseRequest(int refnum)
        : JackRequest(JackRequest::kReleaseTimebase), fRefNum(refnum)
sletz's avatar
sletz committed
813
814
    {}

815
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
816
    {
sletz's avatar
sletz committed
817
        CheckSize();
sletz's avatar
sletz committed
818
        return trans->Read(&fRefNum, sizeof(int));
sletz's avatar
sletz committed
819
820
    }

821
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
822
    {
sletz's avatar
sletz committed
823
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
824
        return trans->Write(&fRefNum, sizeof(int));
sletz's avatar
sletz committed
825
    }
sletz's avatar
sletz committed
826
827
    
    int Size() { return sizeof(int); }
828

829
};
sletz's avatar
sletz committed
830
831
832
833
834

/*!
\brief SetTimebaseCallback request.
*/

835
struct JackSetTimebaseCallbackRequest : public JackRequest
sletz's avatar
sletz committed
836
837
838
839
840
841
842
{

    int fRefNum;
    int fConditionnal;

    JackSetTimebaseCallbackRequest()
    {}
843
844
    JackSetTimebaseCallbackRequest(int refnum, int conditional)
        : JackRequest(JackRequest::kSetTimebaseCallback), fRefNum(refnum), fConditionnal(conditional)
sletz's avatar
sletz committed
845
846
    {}

847
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
848
    {
sletz's avatar
sletz committed
849
        CheckSize();
sletz's avatar
sletz committed
850
851
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
        return trans->Read(&fConditionnal, sizeof(int));
sletz's avatar
sletz committed
852
853
    }

854
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
855
    {
sletz's avatar
sletz committed
856
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
857
858
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
        return trans->Write(&fConditionnal, sizeof(int));
sletz's avatar
sletz committed
859
    }
860

sletz's avatar
sletz committed
861
    int Size() { return sizeof(int) + sizeof(int); }
862
};
sletz's avatar
sletz committed
863

864
865
866
867
868
869
870
/*!
\brief GetInternalClientName request.
*/

struct JackGetInternalClientNameRequest : public JackRequest
{

sletz's avatar
sletz committed
871
    int fRefNum;
872
873
874
875
876
    int fIntRefNum;

    JackGetInternalClientNameRequest()
    {}
    JackGetInternalClientNameRequest(int refnum, int int_ref)
sletz's avatar
sletz committed
877
            : JackRequest(JackRequest::kGetInternalClientName), fRefNum(refnum), fIntRefNum(int_ref)
878
879
    {}

880
    int Read(detail::JackChannelTransactionInterface* trans)
881
    {
sletz's avatar
sletz committed
882
        CheckSize();
sletz's avatar
sletz committed
883
884
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
        return trans->Read(&fIntRefNum, sizeof(int));
885
886
    }