Correct netjack2 components help.
[jack2.git] / common / JackExternalClient.cpp
blob5fd1b60f1996ebdd4630fd8b1eca60a211b5c4ce
1 /*
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"
27 namespace Jack
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)
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;
44 int JackExternalClient::Open(const char* name, int pid, int refnum, int uuid, int* shared_client)
46 try {
48 if (fChannel.Open(name) < 0) {
49 jack_error("Cannot connect to client name = %s\n", name);
50 return -1;
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);
58 if (!fClientControl) {
59 jack_error("Cannot allocate client shared memory segment");
60 return -1;
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;
67 } catch (std::exception e) {
68 return -1;
72 int JackExternalClient::Close()
74 jack_log("JackExternalClient::Close");
75 fChannel.Close();
76 if (fClientControl) {
77 fClientControl->~JackClientControl();
78 JackShmMem::operator delete(fClientControl);
80 return 0;
83 JackClientControl* JackExternalClient::GetClientControl() const
85 return fClientControl;
88 } // end of namespace