JackRequest.h 13.4 KB
Newer Older
sletz's avatar
sletz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

/*
    Copyright (C) 2001 Paul Davis 
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 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 General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
*/

#ifndef __JackRequest__
#define __JackRequest__

#include "JackPort.h"
#include "JackChannelTransaction.h"
#include "JackError.h"
#include <stdio.h>

namespace Jack
{

/*!
\brief Request from client to server.
*/

struct JackRequest
{

public:

    typedef enum {
        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,
        kClientNew = 22,
        kClientClose = 23,
        kConnectNamePorts = 24,
        kDisconnectNamePorts = 25,

        kNotification = 26
    } RequestType;

    RequestType fType;

    JackRequest()
    {}

    JackRequest(RequestType type): fType(type)
    {}

sletz's avatar
sletz committed
75
  	~JackRequest()
sletz's avatar
sletz committed
76
77
    {}

sletz's avatar
sletz committed
78
 	int Read(JackChannelTransaction* trans)
sletz's avatar
sletz committed
79
80
81
82
    {
        return trans->Read(this, sizeof(JackRequest));
    }

sletz's avatar
sletz committed
83
 	int Write(JackChannelTransaction* trans)
sletz's avatar
sletz committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
    {
        return -1;
    }

};

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

struct JackResult
{

    int	fResult;

    JackResult(): fResult( -1)
    {}
    JackResult(int status): fResult(status)
    {}
    virtual ~JackResult()
    {}

    virtual int Read(JackChannelTransaction* trans)
    {
        return trans->Read(this, sizeof(JackResult));
    }

    virtual int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackResult));
    }
};

/*!
\brief NewClient request.
*/

sletz's avatar
sletz committed
121
struct JackClientNewRequest 
sletz's avatar
sletz committed
122
123
{

sletz's avatar
sletz committed
124
	JackRequest fHeader;	
sletz's avatar
sletz committed
125
126
127
128
    char fName[JACK_CLIENT_NAME_SIZE + 1];

    JackClientNewRequest()
    {}
sletz's avatar
sletz committed
129
    JackClientNewRequest(const char* name): fHeader(JackRequest::kClientNew)
sletz's avatar
sletz committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
    {
        snprintf(fName, sizeof(fName), "%s", name);
    }

    int Read(JackChannelTransaction* trans)
    {
        return trans->Read(&fName, sizeof(JackClientNewRequest) - sizeof(JackRequest));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackClientNewRequest));
    }
};

/*!
\brief NewClient result.
*/

sletz's avatar
sletz committed
149
struct JackClientNewResult 
sletz's avatar
sletz committed
150
151
{

sletz's avatar
sletz committed
152
	JackResult fHeader;
sletz's avatar
sletz committed
153
154
    int fSharedEngine;
    int fSharedClient;
sletz's avatar
sletz committed
155
    int fSharedGraph;
sletz's avatar
sletz committed
156
157
    uint32_t fProtocolVersion;

sletz's avatar
sletz committed
158
159
    JackClientNewResult()
		:fSharedEngine(-1), fSharedClient(-1), fSharedGraph(-1), fProtocolVersion(0)
sletz's avatar
sletz committed
160
161
    {}
    JackClientNewResult(int32_t status, int index1, int index2, int index3)
sletz's avatar
sletz committed
162
         : fHeader(status), fSharedEngine(index1), fSharedClient(index2), fSharedGraph(index3), fProtocolVersion(0)
sletz's avatar
sletz committed
163
164
    {}

sletz's avatar
sletz committed
165
166
    //virtual int Read(JackChannelTransaction* trans)
	int Read(JackChannelTransaction* trans)
sletz's avatar
sletz committed
167
168
169
170
171
172
173
174
175
176
177
178
179
180
    {
        return trans->Read(this, sizeof(JackClientNewResult));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackClientNewResult));
    }
};

/*!
\brief CloseClient request.
*/

sletz's avatar
sletz committed
181
struct JackClientCloseRequest
sletz's avatar
sletz committed
182
183
{

sletz's avatar
sletz committed
184
	JackRequest fHeader;
sletz's avatar
sletz committed
185
186
187
188
    int fRefNum;

    JackClientCloseRequest()
    {}
sletz's avatar
sletz committed
189
    JackClientCloseRequest(int refnum): fHeader(JackRequest::kClientClose), fRefNum(refnum)
sletz's avatar
sletz committed
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
    {}

    int Read(JackChannelTransaction* trans)
    {
        return trans->Read(&fRefNum, sizeof(JackClientCloseRequest) - sizeof(JackRequest));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackClientCloseRequest));
    }
};

/*!
\brief Activate request.
*/

sletz's avatar
sletz committed
207
struct JackActivateRequest
sletz's avatar
sletz committed
208
209
{

sletz's avatar
sletz committed
210
	JackRequest fHeader;
sletz's avatar
sletz committed
211
212
213
214
    int fRefNum;

    JackActivateRequest()
    {}
sletz's avatar
sletz committed
215
    JackActivateRequest(int refnum): fHeader(JackRequest::kActivateClient), fRefNum(refnum)
sletz's avatar
sletz committed
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
    {}

    int Read(JackChannelTransaction* trans)
    {
        return trans->Read(&fRefNum, sizeof(JackActivateRequest) - sizeof(JackRequest));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackActivateRequest));
    }

};

/*!
\brief Deactivate request.
*/

sletz's avatar
sletz committed
234
struct JackDeactivateRequest
sletz's avatar
sletz committed
235
236
{

sletz's avatar
sletz committed
237
	JackRequest fHeader;
sletz's avatar
sletz committed
238
239
240
241
    int fRefNum;

    JackDeactivateRequest()
    {}
sletz's avatar
sletz committed
242
    JackDeactivateRequest(int refnum): fHeader(JackRequest::kDeactivateClient), fRefNum(refnum)
sletz's avatar
sletz committed
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
    {}

    int Read(JackChannelTransaction* trans)
    {
        return trans->Read(&fRefNum, sizeof(JackDeactivateRequest) - sizeof(JackRequest));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackDeactivateRequest));
    }

};

/*!
\brief PortRegister request.
*/

sletz's avatar
sletz committed
261
struct JackPortRegisterRequest
sletz's avatar
sletz committed
262
263
{

sletz's avatar
sletz committed
264
	JackRequest fHeader;
sletz's avatar
sletz committed
265
266
267
268
269
270
271
272
273
    int fRefNum;
    char fName[JACK_PORT_NAME_SIZE + 1];
    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)
sletz's avatar
sletz committed
274
            : fHeader(JackRequest::kRegisterPort), fRefNum(refnum), fFlags(flags), fBufferSize(buffer_size)
sletz's avatar
sletz committed
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
    {
        strcpy(fName, name);
        strcpy(fPortType, port_type);
    }

    int Read(JackChannelTransaction* trans)
    {
        return trans->Read(&fRefNum, sizeof(JackPortRegisterRequest) - sizeof(JackRequest)) ;
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackPortRegisterRequest));
    }
};

/*!
\brief PortRegister result.
*/

sletz's avatar
sletz committed
295
struct JackPortRegisterResult
sletz's avatar
sletz committed
296
297
{

sletz's avatar
sletz committed
298
	JackResult fHeader;
sletz's avatar
sletz committed
299
300
301
302
303
    jack_port_id_t fPortIndex;

    JackPortRegisterResult(): fPortIndex(NO_PORT)
    {}

sletz's avatar
sletz committed
304
    int Read(JackChannelTransaction* trans)
sletz's avatar
sletz committed
305
306
307
308
309
310
311
312
313
314
315
316
317
318
    {
        return trans->Read(this, sizeof(JackPortRegisterResult));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackPortRegisterResult));
    }
};

/*!
\brief PortUnregister request.
*/

sletz's avatar
sletz committed
319
struct JackPortUnRegisterRequest
sletz's avatar
sletz committed
320
321
{

sletz's avatar
sletz committed
322
	JackRequest fHeader;
sletz's avatar
sletz committed
323
324
325
326
327
    int fRefNum;
    int fPortIndex;

    JackPortUnRegisterRequest()
    {}
sletz's avatar
sletz committed
328
    JackPortUnRegisterRequest(int refnum, int index): fHeader(JackRequest::kUnRegisterPort), fRefNum(refnum), fPortIndex(index)
sletz's avatar
sletz committed
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
    {}

    int Read(JackChannelTransaction* trans)
    {
        return trans->Read(&fRefNum, sizeof(JackPortUnRegisterRequest) - sizeof(JackRequest));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackPortUnRegisterRequest));
    }
};

/*!
\brief PortConnectName request.
*/

sletz's avatar
sletz committed
346
struct JackPortConnectNameRequest
sletz's avatar
sletz committed
347
{
sletz's avatar
sletz committed
348
349
	
	JackRequest fHeader;
sletz's avatar
sletz committed
350
351
352
353
354
355
    int fRefNum;
    char fSrc[JACK_PORT_NAME_SIZE + 1];
    char fDst[JACK_PORT_NAME_SIZE + 1];

    JackPortConnectNameRequest()
    {}
sletz's avatar
sletz committed
356
    JackPortConnectNameRequest(int refnum, const char* src_name, const char* dst_name): fHeader(JackRequest::kConnectNamePorts), fRefNum(refnum)
sletz's avatar
sletz committed
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
    {
        strcpy(fSrc, src_name);
        strcpy(fDst, dst_name);
    }

    int Read(JackChannelTransaction* trans)
    {
        return trans->Read(&fRefNum, sizeof(JackPortConnectNameRequest) - sizeof(JackRequest));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackPortConnectNameRequest));
    }
};

/*!
\brief PortDisconnectName request.
*/

sletz's avatar
sletz committed
377
struct JackPortDisconnectNameRequest
sletz's avatar
sletz committed
378
379
{

sletz's avatar
sletz committed
380
	JackRequest fHeader;
sletz's avatar
sletz committed
381
382
383
384
385
386
    int fRefNum;
    char fSrc[JACK_PORT_NAME_SIZE + 1];
    char fDst[JACK_PORT_NAME_SIZE + 1];

    JackPortDisconnectNameRequest()
    {}
sletz's avatar
sletz committed
387
    JackPortDisconnectNameRequest(int refnum, const char* src_name, const char* dst_name): fHeader(JackRequest::kDisconnectNamePorts), fRefNum(refnum)
sletz's avatar
sletz committed
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
    {
        strcpy(fSrc, src_name);
        strcpy(fDst, dst_name);
    }

    int Read(JackChannelTransaction* trans)
    {
        return trans->Read(&fRefNum, sizeof(JackPortDisconnectNameRequest) - sizeof(JackRequest));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackPortDisconnectNameRequest));
    }
};

/*!
\brief PortConnect request.
*/

sletz's avatar
sletz committed
408
struct JackPortConnectRequest
sletz's avatar
sletz committed
409
410
{

sletz's avatar
sletz committed
411
	JackRequest fHeader;
sletz's avatar
sletz committed
412
413
414
415
416
417
    int fRefNum;
    jack_port_id_t fSrc;
    jack_port_id_t fDst;

    JackPortConnectRequest()
    {}
sletz's avatar
sletz committed
418
    JackPortConnectRequest(int refnum, jack_port_id_t src, jack_port_id_t dst): fHeader(JackRequest::kConnectPorts), fRefNum(refnum), fSrc(src), fDst(dst)
sletz's avatar
sletz committed
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
    {}

    int Read(JackChannelTransaction* trans)
    {
        return trans->Read(&fRefNum, sizeof(JackPortConnectRequest) - sizeof(JackRequest));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackPortConnectRequest));
    }
};


/*!
\brief PortDisconnect request.
*/

sletz's avatar
sletz committed
437
struct JackPortDisconnectRequest
sletz's avatar
sletz committed
438
439
{

sletz's avatar
sletz committed
440
	JackRequest fHeader;
sletz's avatar
sletz committed
441
442
443
444
445
446
    int fRefNum;
    jack_port_id_t fSrc;
    jack_port_id_t fDst;

    JackPortDisconnectRequest()
    {}
sletz's avatar
sletz committed
447
    JackPortDisconnectRequest(int refnum, jack_port_id_t src, jack_port_id_t dst): fHeader(JackRequest::kDisconnectPorts), fRefNum(refnum), fSrc(src), fDst(dst)
sletz's avatar
sletz committed
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
    {}

    int Read(JackChannelTransaction* trans)
    {
        return trans->Read(&fRefNum, sizeof(JackPortDisconnectRequest) - sizeof(JackRequest));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackPortDisconnectRequest));
    }
};

/*!
\brief SetBufferSize request.
*/

sletz's avatar
sletz committed
465
struct JackSetBufferSizeRequest
sletz's avatar
sletz committed
466
467
{

sletz's avatar
sletz committed
468
	JackRequest fHeader;
sletz's avatar
sletz committed
469
470
471
472
    jack_nframes_t fBufferSize;

    JackSetBufferSizeRequest()
    {}
sletz's avatar
sletz committed
473
    JackSetBufferSizeRequest(jack_nframes_t buffer_size): fHeader(JackRequest::kSetBufferSize), fBufferSize(buffer_size)
sletz's avatar
sletz committed
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
    {}

    int Read(JackChannelTransaction* trans)
    {
        return trans->Read(&fBufferSize, sizeof(JackSetBufferSizeRequest) - sizeof(JackRequest));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackSetBufferSizeRequest));
    }
};

/*!
\brief SetFreeWheel request.
*/

sletz's avatar
sletz committed
491
struct JackSetFreeWheelRequest
sletz's avatar
sletz committed
492
493
{

sletz's avatar
sletz committed
494
	JackRequest fHeader;
sletz's avatar
sletz committed
495
496
497
498
    int fOnOff;

    JackSetFreeWheelRequest()
    {}
sletz's avatar
sletz committed
499
    JackSetFreeWheelRequest(int onoff): fHeader(JackRequest::kSetFreeWheel), fOnOff(onoff)
sletz's avatar
sletz committed
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
    {}

    int Read(JackChannelTransaction* trans)
    {
        return trans->Read(&fOnOff, sizeof(JackSetFreeWheelRequest) - sizeof(JackRequest));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackSetFreeWheelRequest));
    }
};

/*!
\brief ReleaseTimebase request.
*/

sletz's avatar
sletz committed
517
struct JackReleaseTimebaseRequest
sletz's avatar
sletz committed
518
519
{

sletz's avatar
sletz committed
520
	JackRequest fHeader;
sletz's avatar
sletz committed
521
522
523
524
    int fRefNum;

    JackReleaseTimebaseRequest()
    {}
sletz's avatar
sletz committed
525
    JackReleaseTimebaseRequest(int refnum): fHeader(JackRequest::kReleaseTimebase), fRefNum(refnum)
sletz's avatar
sletz committed
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
    {}

    int Read(JackChannelTransaction* trans)
    {
        return trans->Read(&fRefNum, sizeof(JackReleaseTimebaseRequest) - sizeof(JackRequest));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackReleaseTimebaseRequest));
    }

};

/*!
\brief SetTimebaseCallback request.
*/

sletz's avatar
sletz committed
544
struct JackSetTimebaseCallbackRequest
sletz's avatar
sletz committed
545
546
{

sletz's avatar
sletz committed
547
	JackRequest fHeader;
sletz's avatar
sletz committed
548
549
550
551
552
    int fRefNum;
    int fConditionnal;

    JackSetTimebaseCallbackRequest()
    {}
sletz's avatar
sletz committed
553
    JackSetTimebaseCallbackRequest(int refnum, int conditional): fHeader(JackRequest::kSetTimebaseCallback), fRefNum(refnum), fConditionnal(conditional)
sletz's avatar
sletz committed
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
    {}

    int Read(JackChannelTransaction* trans)
    {
        return trans->Read(&fRefNum, sizeof(JackSetTimebaseCallbackRequest) - sizeof(JackRequest));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackSetTimebaseCallbackRequest));
    }
};

/*!
\brief ClientNotification request.
*/

sletz's avatar
sletz committed
571
struct JackClientNotificationRequest
sletz's avatar
sletz committed
572
{
sletz's avatar
sletz committed
573
574
	
	JackRequest fHeader;
sletz's avatar
sletz committed
575
576
577
578
579
580
581
    int fRefNum;
    int fNotify;
    int fValue;

    JackClientNotificationRequest()
    {}
    JackClientNotificationRequest(int refnum, int notify, int value)
sletz's avatar
sletz committed
582
            : fHeader(JackRequest::kNotification), fRefNum(refnum), fNotify(notify), fValue(value)
sletz's avatar
sletz committed
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
    {}

    int Read(JackChannelTransaction* trans)
    {
        return trans->Read(&fRefNum, sizeof(JackClientNotificationRequest) - sizeof(JackRequest));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackClientNotificationRequest));
    }

};

/*!
\brief ClientNotification.
*/

struct JackClientNotification
{
    char fName[JACK_CLIENT_NAME_SIZE + 1];
    int fRefNum;
    int fNotify;
    int fValue;
    int fSync;

    JackClientNotification(): fNotify( -1), fValue( -1)
    {}
    JackClientNotification(const char* name, int refnum, int notify, int sync, int value)
            : fRefNum(refnum), fNotify(notify), fValue(value), fSync(sync)
    {
        snprintf(fName, sizeof(fName), "%s", name);
    }

    int Read(JackChannelTransaction* trans)
    {
        return trans->Read(this, sizeof(JackClientNotification));
    }

    int Write(JackChannelTransaction* trans)
    {
        return trans->Write(this, sizeof(JackClientNotification));
    }

};

} // end of namespace

#endif