JackRequest.h 43.4 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

    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
        memset(fName, 0, sizeof(fName));
172
173
174
        snprintf(fName, sizeof(fName), "%s", name);
    }

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

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

197
};
198
199
200
201
202
203
204
205

/*!
\brief CheckClient result.
*/

struct JackClientCheckResult : public JackResult
{

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

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

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

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

234
};
235

sletz's avatar
sletz committed
236
237
238
239
/*!
\brief NewClient request.
*/

sletz's avatar
sletz committed
240
struct JackClientOpenRequest : public JackRequest
sletz's avatar
sletz committed
241
242
{

243
    int fPID;
244
    int fUUID;
Stephane Letz's avatar
Stephane Letz committed
245
    char fName[JACK_CLIENT_NAME_SIZE+1];
246

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

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

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

sletz's avatar
sletz committed
273
274
    int Size() { return 2 * sizeof(int) + sizeof(fName); }
    
275
};
sletz's avatar
sletz committed
276
277
278
279
280

/*!
\brief NewClient result.
*/

sletz's avatar
sletz committed
281
struct JackClientOpenResult : public JackResult
sletz's avatar
sletz committed
282
283
284
285
{

    int fSharedEngine;
    int fSharedClient;
sletz's avatar
sletz committed
286
    int fSharedGraph;
287

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

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

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

313
};
sletz's avatar
sletz committed
314
315
316
317
318

/*!
\brief CloseClient request.
*/

319
struct JackClientCloseRequest : public JackRequest
sletz's avatar
sletz committed
320
321
322
323
324
325
{

    int fRefNum;

    JackClientCloseRequest()
    {}
326
    JackClientCloseRequest(int refnum): JackRequest(JackRequest::kClientClose), fRefNum(refnum)
sletz's avatar
sletz committed
327
328
    {}

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

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

sletz's avatar
sletz committed
341
    int Size() { return sizeof(int); }
342
};
sletz's avatar
sletz committed
343
344
345
346
347

/*!
\brief Activate request.
*/

348
struct JackActivateRequest : public JackRequest
sletz's avatar
sletz committed
349
350
351
{

    int fRefNum;
sletz's avatar
sletz committed
352
    int fIsRealTime;
sletz's avatar
sletz committed
353
354
355

    JackActivateRequest()
    {}
sletz's avatar
sletz committed
356
357
    JackActivateRequest(int refnum, int is_real_time)
        : JackRequest(JackRequest::kActivateClient), fRefNum(refnum), fIsRealTime(is_real_time)
sletz's avatar
sletz committed
358
359
    {}

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

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

sletz's avatar
sletz committed
374
    int Size() { return 2 * sizeof(int); }
375
};
sletz's avatar
sletz committed
376
377
378
379
380

/*!
\brief Deactivate request.
*/

381
struct JackDeactivateRequest : public JackRequest
sletz's avatar
sletz committed
382
383
384
385
386
387
{

    int fRefNum;

    JackDeactivateRequest()
    {}
388
    JackDeactivateRequest(int refnum): JackRequest(JackRequest::kDeactivateClient), fRefNum(refnum)
sletz's avatar
sletz committed
389
390
    {}

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

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

sletz's avatar
sletz committed
403
    int Size() { return sizeof(int); }
404
};
sletz's avatar
sletz committed
405
406
407
408
409

/*!
\brief PortRegister request.
*/

410
struct JackPortRegisterRequest : public JackRequest
sletz's avatar
sletz committed
411
412
413
{

    int fRefNum;
414
    char fName[JACK_PORT_NAME_SIZE + 1];   // port short name
sletz's avatar
sletz committed
415
416
417
418
419
420
421
    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)
422
            : JackRequest(JackRequest::kRegisterPort), fRefNum(refnum), fFlags(flags), fBufferSize(buffer_size)
sletz's avatar
sletz committed
423
    {
424
425
426
427
        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
428
429
    }

430
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
431
    {
sletz's avatar
sletz committed
432
        CheckSize();
sletz's avatar
sletz committed
433
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
434
435
        CheckRes(trans->Read(&fName, sizeof(fName)));
        CheckRes(trans->Read(&fPortType, sizeof(fPortType)));
sletz's avatar
sletz committed
436
437
438
        CheckRes(trans->Read(&fFlags, sizeof(unsigned int)));
        CheckRes(trans->Read(&fBufferSize, sizeof(unsigned int)));
        return 0;
sletz's avatar
sletz committed
439
440
    }

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

454
};
sletz's avatar
sletz committed
455
456
457
458
459

/*!
\brief PortRegister result.
*/

460
struct JackPortRegisterResult : public JackResult
sletz's avatar
sletz committed
461
462
{

463
    jack_port_id_t fPortIndex;
sletz's avatar
sletz committed
464

sletz's avatar
sletz committed
465
    JackPortRegisterResult(): JackResult(), fPortIndex(NO_PORT)
sletz's avatar
sletz committed
466
467
    {}

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

474
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
475
    {
sletz's avatar
sletz committed
476
477
        CheckRes(JackResult::Write(trans));
        return trans->Write(&fPortIndex, sizeof(jack_port_id_t));
sletz's avatar
sletz committed
478
    }
479

480
};
sletz's avatar
sletz committed
481
482
483
484
485

/*!
\brief PortUnregister request.
*/

486
struct JackPortUnRegisterRequest : public JackRequest
sletz's avatar
sletz committed
487
488
489
{

    int fRefNum;
490
    jack_port_id_t fPortIndex;
sletz's avatar
sletz committed
491
492
493

    JackPortUnRegisterRequest()
    {}
494
    JackPortUnRegisterRequest(int refnum, jack_port_id_t index)
495
        : JackRequest(JackRequest::kUnRegisterPort), fRefNum(refnum), fPortIndex(index)
sletz's avatar
sletz committed
496
497
    {}

498
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
499
    {
sletz's avatar
sletz committed
500
        CheckSize();
sletz's avatar
sletz committed
501
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
sletz's avatar
sletz committed
502
        CheckRes(trans->Read(&fPortIndex, sizeof(jack_port_id_t)));
sletz's avatar
sletz committed
503
        return 0;
sletz's avatar
sletz committed
504
505
    }

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

sletz's avatar
sletz committed
514
    int Size() { return sizeof(int) + sizeof(jack_port_id_t); }
515
};
sletz's avatar
sletz committed
516
517
518
519
520

/*!
\brief PortConnectName request.
*/

521
struct JackPortConnectNameRequest : public JackRequest
sletz's avatar
sletz committed
522
{
sletz's avatar
sletz committed
523

sletz's avatar
sletz committed
524
    int fRefNum;
Stephane Letz's avatar
Stephane Letz committed
525
526
    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
527
528
529

    JackPortConnectNameRequest()
    {}
530
531
    JackPortConnectNameRequest(int refnum, const char* src_name, const char* dst_name)
        : JackRequest(JackRequest::kConnectNamePorts), fRefNum(refnum)
sletz's avatar
sletz committed
532
    {
533
534
535
536
        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
537
538
    }

539
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
540
    {
sletz's avatar
sletz committed
541
        CheckSize();
sletz's avatar
sletz committed
542
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
543
544
        CheckRes(trans->Read(&fSrc, sizeof(fSrc)));
        CheckRes(trans->Read(&fDst, sizeof(fDst)));
sletz's avatar
sletz committed
545
        return 0;
sletz's avatar
sletz committed
546
547
    }

548
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
549
    {
sletz's avatar
sletz committed
550
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
551
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
552
553
        CheckRes(trans->Write(&fSrc, sizeof(fSrc)));
        CheckRes(trans->Write(&fDst, sizeof(fDst)));
sletz's avatar
sletz committed
554
        return 0;
sletz's avatar
sletz committed
555
    }
sletz's avatar
sletz committed
556
557
    
    int Size() { return sizeof(int) + sizeof(fSrc) + sizeof(fDst); }
558

559
};
sletz's avatar
sletz committed
560
561
562
563
564

/*!
\brief PortDisconnectName request.
*/

565
struct JackPortDisconnectNameRequest : public JackRequest
sletz's avatar
sletz committed
566
567
568
{

    int fRefNum;
Stephane Letz's avatar
Stephane Letz committed
569
570
    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
571
572
573

    JackPortDisconnectNameRequest()
    {}
574
575
    JackPortDisconnectNameRequest(int refnum, const char* src_name, const char* dst_name)
        : JackRequest(JackRequest::kDisconnectNamePorts), fRefNum(refnum)
sletz's avatar
sletz committed
576
    {
577
578
579
580
        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
581
582
    }

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

592
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
593
    {
sletz's avatar
sletz committed
594
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
595
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
596
597
        CheckRes(trans->Write(&fSrc, sizeof(fSrc)));
        CheckRes(trans->Write(&fDst, sizeof(fDst)));
sletz's avatar
sletz committed
598
        return 0;
sletz's avatar
sletz committed
599
    }
600

sletz's avatar
sletz committed
601
602
    int Size() { return sizeof(int) + sizeof(fSrc) + sizeof(fDst); }
    
603
};
sletz's avatar
sletz committed
604
605
606
607
608

/*!
\brief PortConnect request.
*/

609
struct JackPortConnectRequest : public JackRequest
sletz's avatar
sletz committed
610
611
612
613
614
615
616
617
{

    int fRefNum;
    jack_port_id_t fSrc;
    jack_port_id_t fDst;

    JackPortConnectRequest()
    {}
618
619
    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
620
621
    {}

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

631
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
632
    {
sletz's avatar
sletz committed
633
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
634
635
636
637
        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
638
    }
639

sletz's avatar
sletz committed
640
    int Size() { return sizeof(int) + sizeof(jack_port_id_t) + sizeof(jack_port_id_t); }
641
};
sletz's avatar
sletz committed
642
643
644
645
646

/*!
\brief PortDisconnect request.
*/

647
struct JackPortDisconnectRequest : public JackRequest
sletz's avatar
sletz committed
648
649
650
651
652
653
654
655
{

    int fRefNum;
    jack_port_id_t fSrc;
    jack_port_id_t fDst;

    JackPortDisconnectRequest()
    {}
656
657
    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
658
659
    {}

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

669
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
670
    {
sletz's avatar
sletz committed
671
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
672
673
674
675
        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
676
    }
677

sletz's avatar
sletz committed
678
    int Size() { return sizeof(int) + sizeof(jack_port_id_t) + sizeof(jack_port_id_t); }
679
};
sletz's avatar
sletz committed
680

681
682
683
684
685
686
687
688
689
/*!
\brief PortRename request.
*/

struct JackPortRenameRequest : public JackRequest
{

    int fRefNum;
    jack_port_id_t fPort;
690
    char fName[JACK_PORT_NAME_SIZE + 1];   // port short name
691
692
693
694
695
696

    JackPortRenameRequest()
    {}
    JackPortRenameRequest(int refnum, jack_port_id_t port, const char* name)
        : JackRequest(JackRequest::kPortRename), fRefNum(refnum), fPort(port)
    {
697
698
        memset(fName, 0, sizeof(fName));
        strncpy(fName, name, sizeof(fName)-1);
699
700
    }

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

710
    int Write(detail::JackChannelTransactionInterface* trans)
711
    {
sletz's avatar
sletz committed
712
        CheckRes(JackRequest::Write(trans, Size()));
713
714
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
        CheckRes(trans->Write(&fPort, sizeof(jack_port_id_t)));
715
        CheckRes(trans->Write(&fName, sizeof(fName)));
716
717
        return 0;
    }
sletz's avatar
sletz committed
718
719
    
    int Size() { return sizeof(int) + sizeof(jack_port_id_t) + sizeof(fName); }
720

721
};
722

sletz's avatar
sletz committed
723
724
725
726
/*!
\brief SetBufferSize request.
*/

727
struct JackSetBufferSizeRequest : public JackRequest
sletz's avatar
sletz committed
728
729
730
731
732
733
{

    jack_nframes_t fBufferSize;

    JackSetBufferSizeRequest()
    {}
734
735
    JackSetBufferSizeRequest(jack_nframes_t buffer_size)
        : JackRequest(JackRequest::kSetBufferSize), fBufferSize(buffer_size)
sletz's avatar
sletz committed
736
737
    {}

738
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
739
    {
sletz's avatar
sletz committed
740
        CheckSize();
sletz's avatar
sletz committed
741
        return trans->Read(&fBufferSize, sizeof(jack_nframes_t));
sletz's avatar
sletz committed
742
743
    }

744
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
745
    {
sletz's avatar
sletz committed
746
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
747
        return trans->Write(&fBufferSize, sizeof(jack_nframes_t));
sletz's avatar
sletz committed
748
    }
749

sletz's avatar
sletz committed
750
    int Size() { return sizeof(jack_nframes_t); }
751
};
sletz's avatar
sletz committed
752
753
754
755
756

/*!
\brief SetFreeWheel request.
*/

757
struct JackSetFreeWheelRequest : public JackRequest
sletz's avatar
sletz committed
758
759
760
761
762
763
{

    int fOnOff;

    JackSetFreeWheelRequest()
    {}
764
765
    JackSetFreeWheelRequest(int onoff)
        : JackRequest(JackRequest::kSetFreeWheel), fOnOff(onoff)
sletz's avatar
sletz committed
766
767
    {}

768
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
769
    {
sletz's avatar
sletz committed
770
        CheckSize();
sletz's avatar
sletz committed
771
        return trans->Read(&fOnOff, sizeof(int));
sletz's avatar
sletz committed
772
773
    }

774
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
775
    {
sletz's avatar
sletz committed
776
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
777
        return trans->Write(&fOnOff, sizeof(int));
sletz's avatar
sletz committed
778
    }
sletz's avatar
sletz committed
779
780
    
    int Size() { return sizeof(int); }
781
782
783
784
785
786
787
788
789
790
791
792
793
794

};

/*!
\brief ComputeTotalLatencies request.
*/

struct JackComputeTotalLatenciesRequest : public JackRequest
{

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

795
    int Read(detail::JackChannelTransactionInterface* trans)
796
    {
sletz's avatar
sletz committed
797
        CheckSize();
798
799
800
        return 0;
    }

801
    int Write(detail::JackChannelTransactionInterface* trans)
802
    {
sletz's avatar
sletz committed
803
        CheckRes(JackRequest::Write(trans, Size()));
804
805
806
        return 0;
    }

sletz's avatar
sletz committed
807
    int Size() { return 0; }
808
};
sletz's avatar
sletz committed
809
810
811
812
813

/*!
\brief ReleaseTimebase request.
*/

814
struct JackReleaseTimebaseRequest : public JackRequest
sletz's avatar
sletz committed
815
816
817
818
819
820
{

    int fRefNum;

    JackReleaseTimebaseRequest()
    {}
821
822
    JackReleaseTimebaseRequest(int refnum)
        : JackRequest(JackRequest::kReleaseTimebase), fRefNum(refnum)
sletz's avatar
sletz committed
823
824
    {}

825
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
826
    {
sletz's avatar
sletz committed
827
        CheckSize();
sletz's avatar
sletz committed
828
        return trans->Read(&fRefNum, sizeof(int));
sletz's avatar
sletz committed
829
830
    }

831
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
832
    {
sletz's avatar
sletz committed
833
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
834
        return trans->Write(&fRefNum, sizeof(int));
sletz's avatar
sletz committed
835
    }
sletz's avatar
sletz committed
836
837
    
    int Size() { return sizeof(int); }
838

839
};
sletz's avatar
sletz committed
840
841
842
843
844

/*!
\brief SetTimebaseCallback request.
*/

845
struct JackSetTimebaseCallbackRequest : public JackRequest
sletz's avatar
sletz committed
846
847
848
849
850
851
852
{

    int fRefNum;
    int fConditionnal;

    JackSetTimebaseCallbackRequest()
    {}
853
854
    JackSetTimebaseCallbackRequest(int refnum, int conditional)
        : JackRequest(JackRequest::kSetTimebaseCallback), fRefNum(refnum), fConditionnal(conditional)
sletz's avatar
sletz committed
855
856
    {}

857
    int Read(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
858
    {
sletz's avatar
sletz committed
859
        CheckSize();
sletz's avatar
sletz committed
860
861
        CheckRes(trans->Read(&fRefNum, sizeof(int)));
        return trans->Read(&fConditionnal, sizeof(int));
sletz's avatar
sletz committed
862
863
    }

864
    int Write(detail::JackChannelTransactionInterface* trans)
sletz's avatar
sletz committed
865
    {
sletz's avatar
sletz committed
866
        CheckRes(JackRequest::Write(trans, Size()));
sletz's avatar
sletz committed
867
868
        CheckRes(trans->Write(&fRefNum, sizeof(int)));
        return trans->Write(&fConditionnal, sizeof(int));
sletz's avatar
sletz committed
869
    }
870

sletz's avatar
sletz committed
871