2006-09-03 10:39:10 +03:00
|
|
|
/*
|
|
|
|
Copyright (C) 2001-2003 Paul Davis
|
2008-02-01 21:46:45 +02:00
|
|
|
Copyright (C) 2004-2008 Grame
|
2008-03-05 18:39:51 +02:00
|
|
|
|
2006-09-03 10:39:10 +03:00
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "JackExternalClient.h"
|
|
|
|
#include "JackClientControl.h"
|
|
|
|
#include "JackGlobals.h"
|
|
|
|
#include "JackChannel.h"
|
2008-05-26 12:49:27 +03:00
|
|
|
#include "JackError.h"
|
2006-09-03 10:39:10 +03:00
|
|
|
|
|
|
|
namespace Jack
|
|
|
|
{
|
|
|
|
|
|
|
|
JackExternalClient::JackExternalClient(): fClientControl(NULL)
|
2008-06-06 09:50:19 +03:00
|
|
|
{}
|
2006-09-03 10:39:10 +03:00
|
|
|
|
|
|
|
JackExternalClient::~JackExternalClient()
|
2008-06-06 09:50:19 +03:00
|
|
|
{}
|
2006-09-03 10:39:10 +03:00
|
|
|
|
2009-10-20 14:07:58 +03:00
|
|
|
int JackExternalClient::ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2)
|
2006-09-03 10:39:10 +03:00
|
|
|
{
|
|
|
|
int result = -1;
|
2011-07-23 16:27:17 +03:00
|
|
|
jack_log("JackExternalClient::ClientNotify ref = %ld client = %s name = %s notify = %ld", refnum, fClientControl->fName, name, notify);
|
2009-10-20 14:07:58 +03:00
|
|
|
fChannel.ClientNotify(refnum, name, notify, sync, message, value1, value2, &result);
|
2006-09-03 10:39:10 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-03-18 09:33:50 +02:00
|
|
|
int JackExternalClient::Open(const char* name, int pid, int refnum, jack_uuid_t uuid, int* shared_client)
|
2006-09-03 10:39:10 +03:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
|
2008-06-03 11:48:09 +03:00
|
|
|
if (fChannel.Open(name) < 0) {
|
2006-09-08 19:12:35 +03:00
|
|
|
jack_error("Cannot connect to client name = %s\n", name);
|
2006-09-03 10:39:10 +03:00
|
|
|
return -1;
|
|
|
|
}
|
2011-07-23 16:27:17 +03:00
|
|
|
|
2008-06-13 17:32:26 +03:00
|
|
|
// Use "placement new" to allocate object in shared memory
|
|
|
|
JackShmMemAble* shared_mem = static_cast<JackShmMemAble*>(JackShmMem::operator new(sizeof(JackClientControl)));
|
|
|
|
shared_mem->Init();
|
2010-04-19 08:23:33 +03:00
|
|
|
fClientControl = new(shared_mem) JackClientControl(name, pid, refnum, uuid);
|
2011-07-23 16:27:17 +03:00
|
|
|
|
2006-09-03 10:39:10 +03:00
|
|
|
if (!fClientControl) {
|
|
|
|
jack_error("Cannot allocate client shared memory segment");
|
|
|
|
return -1;
|
|
|
|
}
|
2011-07-23 16:27:17 +03:00
|
|
|
|
2008-06-13 17:32:26 +03:00
|
|
|
*shared_client = shared_mem->GetShmIndex();
|
|
|
|
jack_log("JackExternalClient::Open name = %s index = %ld base = %x", name, shared_mem->GetShmIndex(), shared_mem->GetShmAddress());
|
2006-09-03 10:39:10 +03:00
|
|
|
return 0;
|
|
|
|
|
2019-03-18 09:33:50 +02:00
|
|
|
} catch (std::exception&) {
|
2006-09-03 10:39:10 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int JackExternalClient::Close()
|
|
|
|
{
|
2011-04-01 17:30:21 +03:00
|
|
|
jack_log("JackExternalClient::Close");
|
2008-06-03 11:48:09 +03:00
|
|
|
fChannel.Close();
|
2008-07-25 19:33:58 +03:00
|
|
|
if (fClientControl) {
|
|
|
|
fClientControl->~JackClientControl();
|
|
|
|
JackShmMem::operator delete(fClientControl);
|
|
|
|
}
|
2006-09-03 10:39:10 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
JackClientControl* JackExternalClient::GetClientControl() const
|
|
|
|
{
|
|
|
|
return fClientControl;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end of namespace
|