Jack2: JackExternalClient.cpp Source File

Jack2 1.9.12

JackExternalClient.cpp
1 /*
2 Copyright (C) 2001-2003 Paul Davis
3 Copyright (C) 2004-2008 Grame
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #include "JackExternalClient.h"
22 #include "JackClientControl.h"
23 #include "JackGlobals.h"
24 #include "JackChannel.h"
25 #include "JackError.h"
26
27 namespace Jack
28 {
29
30 JackExternalClient::JackExternalClient(): fClientControl(NULL)
31 {}
32
33 JackExternalClient::~JackExternalClient()
34 {}
35
36 int JackExternalClient::ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2)
37 {
38 int result = -1;
39 jack_log("JackExternalClient::ClientNotify ref = %ld client = %s name = %s notify = %ld", refnum, fClientControl->fName, name, notify);
40 fChannel.ClientNotify(refnum, name, notify, sync, message, value1, value2, &result);
41 return result;
42 }
43
44 int JackExternalClient::Open(const char* name, int pid, int refnum, int uuid, int* shared_client)
45 {
46 try {
47
48 if (fChannel.Open(name) < 0) {
49 jack_error("Cannot connect to client name = %s\n", name);
50 return -1;
51 }
52
53 // Use "placement new" to allocate object in shared memory
54 JackShmMemAble* shared_mem = static_cast<JackShmMemAble*>(JackShmMem::operator new(sizeof(JackClientControl)));
55 shared_mem->Init();
56 fClientControl = new(shared_mem) JackClientControl(name, pid, refnum, uuid);
57
58 if (!fClientControl) {
59 jack_error("Cannot allocate client shared memory segment");
60 return -1;
61 }
62
63 *shared_client = shared_mem->GetShmIndex();
64 jack_log("JackExternalClient::Open name = %s index = %ld base = %x", name, shared_mem->GetShmIndex(), shared_mem->GetShmAddress());
65 return 0;
66
67 } catch (std::exception e) {
68 return -1;
69 }
70 }
71
72 int JackExternalClient::Close()
73 {
74 jack_log("JackExternalClient::Close");
75 fChannel.Close();
76 if (fClientControl) {
77 fClientControl->~JackClientControl();
78 JackShmMem::operator delete(fClientControl);
79 }
80 return 0;
81 }
82
83 JackClientControl* JackExternalClient::GetClientControl() const
84 {
85 return fClientControl;
86 }
87
88 } // end of namespace
Jack::JackExternalClient::JackExternalClient
JackExternalClient()
Definition: JackExternalClient.cpp:30
jack_error
SERVER_EXPORT void jack_error(const char *fmt,...)
Definition: JackError.cpp:92
jack_log
SERVER_EXPORT void jack_log(const char *fmt,...)
Definition: JackError.cpp:108