2 Copyright (C) 2001-2003 Paul Davis
3 Copyright (C) 2004-2008 Grame
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.
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.
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.
21 #include "JackExternalClient.h"
22 #include "JackClientControl.h"
23 #include "JackGlobals.h"
24 #include "JackChannel.h"
25 #include "JackError.h"
30 JackExternalClient::JackExternalClient(): fClientControl(NULL
)
33 JackExternalClient::~JackExternalClient()
36 int JackExternalClient::ClientNotify(int refnum
, const char* name
, int notify
, int sync
, const char* message
, int value1
, int value2
)
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
);
44 int JackExternalClient::Open(const char* name
, int pid
, int refnum
, jack_uuid_t uuid
, int* shared_client
)
48 if (fChannel
.Open(name
) < 0) {
49 jack_error("Cannot connect to client name = %s\n", name
);
53 // Use "placement new" to allocate object in shared memory
54 JackShmMemAble
* shared_mem
= static_cast<JackShmMemAble
*>(JackShmMem::operator new(sizeof(JackClientControl
)));
56 fClientControl
= new(shared_mem
) JackClientControl(name
, pid
, refnum
, uuid
);
58 if (!fClientControl
) {
59 jack_error("Cannot allocate client shared memory segment");
63 *shared_client
= shared_mem
->GetShmIndex();
64 jack_log("JackExternalClient::Open name = %s index = %ld base = %x", name
, shared_mem
->GetShmIndex(), shared_mem
->GetShmAddress());
67 } catch (std::exception
&) {
72 int JackExternalClient::Close()
74 jack_log("JackExternalClient::Close");
77 fClientControl
->~JackClientControl();
78 JackShmMem::operator delete(fClientControl
);
83 JackClientControl
* JackExternalClient::GetClientControl() const
85 return fClientControl
;