Commit 152a1711 authored by sletz's avatar sletz
Browse files

New jack_get_client_pid API, implemented on server side.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2299 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 8a2e1e2e
......@@ -23,6 +23,7 @@ Fernando Lopez-Lezcano
2008-05-21 Stephane Letz <letz@grame.fr>
* Correct JackEngine::PortUnRegister, JackEngine::ClientCloseAux and JackEngine::ClientDeactivate to correctly send notifications.
* New jack_get_client_pid API, implemented on server side.
2008-05-20 Stephane Letz <letz@grame.fr>
......
......@@ -36,8 +36,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
JackAudioDriver::JackAudioDriver(const char* name, JackEngine* engine, JackSynchro** table)
: JackDriver(name, engine, table),
JackAudioDriver::JackAudioDriver(const char* name, const char* alias, JackEngine* engine, JackSynchro** table)
: JackDriver(name, alias, engine, table),
fCaptureChannels(0),
fPlaybackChannels(0),
fWithMonitorPorts(false)
......@@ -95,8 +95,8 @@ int JackAudioDriver::Attach()
jack_log("JackAudioDriver::Attach fBufferSize = %ld fSampleRate = %ld", fEngineControl->fBufferSize, fEngineControl->fSampleRate);
for (i = 0; i < fCaptureChannels; i++) {
snprintf(alias, sizeof(alias) - 1, "%s:%s:out%d", fClientControl->fName, fCaptureDriverName, i + 1);
snprintf(name, sizeof(name) - 1, "system:capture_%d", i + 1);
snprintf(alias, sizeof(alias) - 1, "%s:%s:out%d", fAliasName, fCaptureDriverName, i + 1);
snprintf(name, sizeof(name) - 1, "%s:capture_%d", fClientControl->fName, i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("driver: cannot register port for %s", name);
return -1;
......@@ -111,8 +111,8 @@ int JackAudioDriver::Attach()
port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;
for (i = 0; i < fPlaybackChannels; i++) {
snprintf(alias, sizeof(alias) - 1, "%s:%s:in%d", fClientControl->fName, fPlaybackDriverName, i + 1);
snprintf(name, sizeof(name) - 1, "system:playback_%d", i + 1);
snprintf(alias, sizeof(alias) - 1, "%s:%s:in%d", fAliasName, fPlaybackDriverName, i + 1);
snprintf(name, sizeof(name) - 1, "%s:playback_%d", fClientControl->fName, i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("driver: cannot register port for %s", name);
return -1;
......@@ -127,7 +127,7 @@ int JackAudioDriver::Attach()
// Monitor ports
if (fWithMonitorPorts) {
jack_log("Create monitor port ");
snprintf(name, sizeof(name) - 1, "%s:%s:monitor_%u", fClientControl->fName, fPlaybackDriverName, i + 1);
snprintf(name, sizeof(name) - 1, "%s:%s:monitor_%u", fAliasName, fPlaybackDriverName, i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("Cannot register monitor port for %s", name);
return -1;
......
......@@ -57,7 +57,7 @@ class EXPORT JackAudioDriver : public JackDriver
public:
JackAudioDriver(const char* name, JackEngine* engine, JackSynchro** table);
JackAudioDriver(const char* name, const char* alias, JackEngine* engine, JackSynchro** table);
virtual ~JackAudioDriver();
virtual int Process();
......
......@@ -73,7 +73,7 @@ class JackClientChannelInterface
virtual void ClientCheck(const char* name, char* name_res, int protocol, int options, int* status, int* result)
{}
virtual void ClientOpen(const char* name, int* shared_engine, int* shared_client, int* shared_graph, int* result)
virtual void ClientOpen(const char* name, int pid, int* shared_engine, int* shared_client, int* shared_graph, int* result)
{}
virtual void ClientOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, int* result)
{}
......
......@@ -42,24 +42,25 @@ struct JackClientControl : public JackShmMem
volatile bool fTransportSync; /* Will be true when slow-sync cb has to be called */
volatile bool fTransportTimebase; /* Will be true when timebase cb is called with new_pos on */
int fRefNum;
int fPID;
bool fActive;
JackClientControl(const char* name, int refnum)
JackClientControl(const char* name, int pid, int refnum)
{
Init(name, refnum);
Init(name, pid, refnum);
}
JackClientControl(const char* name)
{
Init(name, -1);
Init(name, 0, -1);
}
JackClientControl()
{
Init("", -1);
Init("", 0, -1);
}
void Init(const char* name, int refnum)
void Init(const char* name, int pid, int refnum)
{
strcpy(fName, name);
for (int i = 0; i < kMaxNotification; i++)
......@@ -72,6 +73,7 @@ struct JackClientControl : public JackShmMem
fCallback[kStartFreewheelCallback] = true;
fCallback[kStopFreewheelCallback] = true;
fRefNum = refnum;
fPID = pid;
fTransportState = JackTransportStopped;
fTransportSync = false;
fTransportTimebase = false;
......
......@@ -58,7 +58,7 @@ class JackDebugClient : public JackClient
int fIsActivated;
int fIsDeactivated;
int fIsClosed;
char fClientName[JACK_CLIENT_NAME_SIZE];
char fClientName[JACK_CLIENT_NAME_SIZE + 1];
JackProcessCallback fProcessTimeCallback;
void* fProcessTimeCallbackArg;
......
......@@ -39,11 +39,12 @@ using namespace std;
namespace Jack
{
JackDriver::JackDriver(const char* name, JackEngine* engine, JackSynchro** table)
JackDriver::JackDriver(const char* name, const char* alias, JackEngine* engine, JackSynchro** table)
{
assert(strlen(name) < JACK_CLIENT_NAME_SIZE);
fSynchroTable = table;
fClientControl = new JackClientControl(name);
strcpy(fAliasName, alias);
fEngine = engine;
fGraphManager = NULL;
fLastWaitUst = 0;
......
......@@ -143,8 +143,9 @@ class EXPORT JackDriver : public JackDriverClient
protected:
char fCaptureDriverName[JACK_CLIENT_NAME_SIZE];
char fPlaybackDriverName[JACK_CLIENT_NAME_SIZE];
char fCaptureDriverName[JACK_CLIENT_NAME_SIZE + 1];
char fPlaybackDriverName[JACK_CLIENT_NAME_SIZE + 1];
char fAliasName[JACK_CLIENT_NAME_SIZE + 1];
jack_nframes_t fCaptureLatency;
jack_nframes_t fPlaybackLatency;
jack_time_t fLastWaitUst;
......@@ -159,7 +160,7 @@ class EXPORT JackDriver : public JackDriverClient
public:
JackDriver(const char* name, JackEngine* engine, JackSynchro** table);
JackDriver(const char* name, const char* alias, JackEngine* engine, JackSynchro** table);
JackDriver();
virtual ~JackDriver();
......
......@@ -178,7 +178,7 @@ extern "C"
if (wait_time == 0) // Not set
wait_time = (unsigned long)((((float)period_size) / ((float)sample_rate)) * 1000000.0f);
Jack::JackDriverClientInterface* driver = new Jack::JackThreadedDriver(new Jack::JackDummyDriver("dummy_pcm", engine, table, wait_time));
Jack::JackDriverClientInterface* driver = new Jack::JackThreadedDriver(new Jack::JackDummyDriver("system", "dummy_pcm", engine, table, wait_time));
if (driver->Open(period_size, sample_rate, 1, 1, capture_ports, playback_ports, monitor, "dummy", "dummy", 0, 0) == 0) {
return driver;
} else {
......
......@@ -38,8 +38,8 @@ class JackDummyDriver : public JackAudioDriver
public:
JackDummyDriver(const char* name, JackEngine* engine, JackSynchro** table, unsigned long wait_time)
: JackAudioDriver(name, engine, table), fWaitTime(wait_time)
JackDummyDriver(const char* name, const char* alias, JackEngine* engine, JackSynchro** table, unsigned long wait_time)
: JackAudioDriver(name, alias, engine, table), fWaitTime(wait_time)
{}
virtual ~JackDummyDriver()
{}
......
......@@ -447,8 +447,19 @@ bool JackEngine::ClientCheckName(const char* name)
return false;
}
int JackEngine::GetClientPID(const char* name)
{
for (int i = 0; i < CLIENT_NUM; i++) {
JackClientInterface* client = fClientTable[i];
if (client && (strcmp(client->GetClientControl()->fName, name) == 0))
return client->GetClientControl()->fPID;
}
return 0;
}
// Used for external clients
int JackEngine::ClientExternalOpen(const char* name, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
int JackEngine::ClientExternalOpen(const char* name, int pid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
{
jack_log("JackEngine::ClientOpen: name = %s ", name);
......@@ -465,7 +476,7 @@ int JackEngine::ClientExternalOpen(const char* name, int* ref, int* shared_engin
goto error;
}
if (client->Open(name, refnum, shared_client) < 0) {
if (client->Open(name, pid, refnum, shared_client) < 0) {
jack_error("Cannot open client");
goto error;
}
......@@ -476,12 +487,13 @@ int JackEngine::ClientExternalOpen(const char* name, int* ref, int* shared_engin
goto error;
}
fClientTable[refnum] = client;
if (NotifyAddClient(client, name, refnum) < 0) {
jack_error("Cannot notify add client");
goto error;
}
fClientTable[refnum] = client;
fGraphManager->InitRefNum(refnum);
fEngineControl->ResetRollingUsecs();
*shared_engine = fEngineControl->GetShmIndex();
......@@ -490,7 +502,9 @@ int JackEngine::ClientExternalOpen(const char* name, int* ref, int* shared_engin
return 0;
error:
ClientCloseAux(refnum, client, false);
// Cleanup...
fSynchroTable[refnum]->Destroy();
fClientTable[refnum] = 0;
client->Close();
delete client;
return -1;
......@@ -504,32 +518,39 @@ int JackEngine::ClientInternalOpen(const char* name, int* ref, JackEngineControl
int refnum = AllocateRefnum();
if (refnum < 0) {
jack_error("No more refnum available");
return -1;
goto error;
}
if (!fSynchroTable[refnum]->Allocate(name, fEngineControl->fServerName, 0)) {
jack_error("Cannot allocate synchro");
return -1;
goto error;
}
if (wait && !fSignal->TimedWait(DRIVER_OPEN_TIMEOUT * 1000000)) {
// Failure if RT thread is not running (problem with the driver...)
jack_error("Driver is not running");
return -1;
goto error;
}
fClientTable[refnum] = client;
if (NotifyAddClient(client, name, refnum) < 0) {
jack_error("Cannot notify add client");
return -1;
goto error;
}
fClientTable[refnum] = client;
fGraphManager->InitRefNum(refnum);
fEngineControl->ResetRollingUsecs();
*shared_engine = fEngineControl;
*shared_manager = fGraphManager;
*ref = refnum;
return 0;
error:
// Cleanup...
fSynchroTable[refnum]->Destroy();
fClientTable[refnum] = 0;
return -1;
}
// Used for external clients
......@@ -556,9 +577,7 @@ int JackEngine::ClientInternalClose(int refnum, bool wait)
int JackEngine::ClientCloseAux(int refnum, JackClientInterface* client, bool wait)
{
jack_log("JackEngine::ClientCloseAux ref = %ld name = %s",
refnum,
(client->GetClientControl()) ? client->GetClientControl()->fName : "No name");
jack_log("JackEngine::ClientCloseAux ref = %ld", refnum);
// Unregister all ports ==> notifications are sent
jack_int_t ports[PORT_NUM_FOR_CLIENT];
......@@ -588,8 +607,7 @@ int JackEngine::ClientCloseAux(int refnum, JackClientInterface* client, bool wai
}
// Notify running clients
if (client->GetClientControl()) // When called in error cases, client may not be completely allocated
NotifyRemoveClient(client->GetClientControl()->fName, client->GetClientControl()->fRefNum);
NotifyRemoveClient(client->GetClientControl()->fName, client->GetClientControl()->fRefNum);
// Cleanup...
fSynchroTable[refnum]->Destroy();
......
......@@ -80,7 +80,7 @@ class JackEngine
// Client management
virtual int ClientCheck(const char* name, char* name_res, int protocol, int options, int* status);
virtual int ClientExternalOpen(const char* name, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager);
virtual int ClientExternalOpen(const char* name, int pid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager);
virtual int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait);
virtual int ClientExternalClose(int refnum);
......@@ -88,7 +88,9 @@ class JackEngine
virtual int ClientActivate(int refnum, bool state);
virtual int ClientDeactivate(int refnum);
virtual int GetClientPID(const char* name);
// Internal client management
virtual int GetInternalClientName(int int_ref, char* name_res);
virtual int InternalClientHandle(const char* client_name, int* status, int* int_ref);
......
......@@ -44,7 +44,7 @@ int JackExternalClient::ClientNotify(int refnum, const char* name, int notify, i
return result;
}
int JackExternalClient::Open(const char* name, int refnum, int* shared_client)
int JackExternalClient::Open(const char* name, int pid, int refnum, int* shared_client)
{
try {
......@@ -53,7 +53,7 @@ int JackExternalClient::Open(const char* name, int refnum, int* shared_client)
return -1;
}
fClientControl = new JackClientControl(name, refnum);
fClientControl = new JackClientControl(name, pid, refnum);
if (!fClientControl) {
jack_error("Cannot allocate client shared memory segment");
return -1;
......
......@@ -46,7 +46,7 @@ class JackExternalClient : public JackClientInterface
JackExternalClient();
virtual ~JackExternalClient();
int Open(const char* name, int refnum, int* shared_client);
int Open(const char* name, int pid, int refnum, int* shared_client);
int Close();
int ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2);
......
......@@ -35,7 +35,7 @@ class JackFreewheelDriver : public JackDriver
public:
JackFreewheelDriver(const char* name, JackEngine* engine, JackSynchro** table): JackDriver(name, engine, table)
JackFreewheelDriver(JackEngine* engine, JackSynchro** table): JackDriver("freewheel", "", engine, table)
{}
virtual ~JackFreewheelDriver()
{}
......
......@@ -35,6 +35,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "JackEngineControl.h"
#include "JackClientControl.h"
#include "JackInternalClientChannel.h"
#include "JackTools.h"
#include <assert.h>
namespace Jack
......@@ -74,7 +75,7 @@ JackInternalClient::~JackInternalClient()
int JackInternalClient::Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status)
{
int result;
char name_res[JACK_CLIENT_NAME_SIZE];
char name_res[JACK_CLIENT_NAME_SIZE + 1];
jack_log("JackInternalClient::Open name = %s", name);
snprintf(fServerName, sizeof(fServerName), server_name);
......@@ -97,7 +98,7 @@ int JackInternalClient::Open(const char* server_name, const char* name, jack_opt
jack_error("Cannot open client name = %s", name_res);
goto error;
}
SetupDriverSync(false);
return 0;
......
......@@ -46,6 +46,7 @@ extern "C"
jack_options_t options,
jack_status_t *status, ...);
EXPORT int jack_client_close (jack_client_t *client);
EXPORT int jack_get_client_pid (const char *name);
#ifdef __cplusplus
}
......@@ -59,7 +60,7 @@ EXPORT jack_client_t* jack_client_open_aux(const char* ext_client_name, jack_opt
jack_varargs_t va; /* variable arguments */
jack_status_t my_status;
JackClient* client;
char client_name[JACK_CLIENT_NAME_SIZE];
char client_name[JACK_CLIENT_NAME_SIZE + 1];
if (ext_client_name == NULL) {
jack_error("jack_client_open called with a NULL client_name");
......@@ -143,4 +144,9 @@ EXPORT int jack_client_close(jack_client_t* ext_client)
}
}
EXPORT int jack_get_client_pid(const char *name)
{
jack_error("jack_get_client_pid : not implemented on library side");
return 0;
}
......@@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "JackLibGlobals.h"
#include "JackGlobals.h"
#include "JackChannel.h"
#include "JackTools.h"
namespace Jack
{
......@@ -50,7 +51,6 @@ JackSynchro** GetSynchroTable()
return (JackLibGlobals::fGlobals ? JackLibGlobals::fGlobals->fSynchroTable : 0);
}
//-------------------
// Client management
//-------------------
......@@ -75,7 +75,7 @@ int JackLibClient::Open(const char* server_name, const char* name, jack_options_
snprintf(fServerName, sizeof(fServerName), server_name);
// Open server/client channel
char name_res[JACK_CLIENT_NAME_SIZE];
char name_res[JACK_CLIENT_NAME_SIZE + 1];
if (fChannel->Open(server_name, name, name_res, this, options, status) < 0) {
jack_error("Cannot connect to the server");
goto error;
......@@ -88,7 +88,7 @@ int JackLibClient::Open(const char* server_name, const char* name, jack_options_
}
// Require new client
fChannel->ClientOpen(name_res, &shared_engine, &shared_client, &shared_graph, &result);
fChannel->ClientOpen(name_res, JackTools::GetPID(), &shared_engine, &shared_client, &shared_graph, &result);
if (result < 0) {
jack_error("Cannot open %s client", name_res);
goto error;
......
......@@ -62,10 +62,10 @@ class JackLockedEngine : public JackEngine, public JackLockAble
JackLock lock(this);
return fEngine->ClientCheck(name, name_res, protocol, options, status);
}
int ClientExternalOpen(const char* name, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
int ClientExternalOpen(const char* name, int pid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
{
JackLock lock(this);
return fEngine->ClientExternalOpen(name, ref, shared_engine, shared_client, shared_graph_manager);
return fEngine->ClientExternalOpen(name, pid, ref, shared_engine, shared_client, shared_graph_manager);
}
int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait)
{
......@@ -195,6 +195,13 @@ class JackLockedEngine : public JackEngine, public JackLockAble
JackLock lock(this);
fEngine->NotifyActivate(refnum);
}
int GetClientPID(const char* name)
{
JackLock lock(this);
return fEngine->GetClientPID(name);
}
};
......
......@@ -35,8 +35,8 @@ class JackLoopbackDriver : public JackAudioDriver
public:
JackLoopbackDriver(const char* name, JackEngine* engine, JackSynchro** table)
: JackAudioDriver(name, engine, table)
JackLoopbackDriver(JackEngine* engine, JackSynchro** table)
: JackAudioDriver("loopback", "", engine, table)
{}
virtual ~JackLoopbackDriver()
{}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment