Commit 5e7a792f authored by Torben Hohn's avatar Torben Hohn
Browse files

add uuid parameter to jack_client_open...

parent 4e6b4f13
......@@ -76,7 +76,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 pid, int* shared_engine, int* shared_client, int* shared_graph, int* result)
virtual void ClientOpen(const char* name, int pid, int uuid, 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)
{}
......
......@@ -123,7 +123,7 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
JackClient(JackSynchro* table);
virtual ~JackClient();
virtual int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status) = 0;
virtual int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status, int uuid) = 0;
virtual int Close();
virtual JackGraphManager* GetGraphManager() const = 0;
......
......@@ -50,22 +50,22 @@ struct JackClientControl : public JackShmMemAble
char fSessionCommand[256 + 1];
jack_session_flags_t fSessionFlags;
JackClientControl(const char* name, int pid, int refnum)
JackClientControl(const char* name, int pid, int refnum, int uuid)
{
Init(name, pid, refnum);
Init(name, pid, refnum, uuid);
}
JackClientControl(const char* name)
{
Init(name, 0, -1);
Init(name, 0, -1, -1);
}
JackClientControl()
{
Init("", 0, -1);
Init("", 0, -1, -1);
}
void Init(const char* name, int pid, int refnum)
void Init(const char* name, int pid, int refnum, int uuid)
{
strcpy(fName, name);
for (int i = 0; i < kMaxNotification; i++)
......@@ -84,7 +84,7 @@ struct JackClientControl : public JackShmMemAble
fTransportTimebase = false;
fActive = false;
fSessionID = 0;
fSessionID = uuid;
}
} POST_PACKED_STRUCTURE;
......
......@@ -1179,7 +1179,7 @@ EXPORT bool jackctl_server_load_internal(
{
int status;
if (server_ptr->engine != NULL) {
server_ptr->engine->InternalClientLoad(internal->desc_ptr->name, internal->desc_ptr->name, internal->set_parameters, JackNullOption, &internal->refnum, &status);
server_ptr->engine->InternalClientLoad(internal->desc_ptr->name, internal->desc_ptr->name, internal->set_parameters, JackNullOption, &internal->refnum, &status, -1);
return (internal->refnum > 0);
} else {
return false;
......
......@@ -78,9 +78,9 @@ JackDebugClient::~JackDebugClient()
delete fClient;
}
int JackDebugClient::Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status)
int JackDebugClient::Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status, int uuid)
{
int res = fClient->Open(server_name, name, options, status);
int res = fClient->Open(server_name, name, options, status, uuid);
char provstr[256];
char buffer[256];
time_t curtime;
......
......@@ -68,7 +68,7 @@ class JackDebugClient : public JackClient
JackDebugClient(JackClient* fTheClient);
virtual ~JackDebugClient();
virtual int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status);
virtual int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status, int uuid);
int Close();
virtual JackGraphManager* GetGraphManager() const;
......
......@@ -460,9 +460,32 @@ bool JackEngine::ClientCheckName(const char* name)
return true;
}
for (std::map<int,std::string>::iterator i=fReservationMap.begin(); i!=fReservationMap.end(); i++) {
if (i->second == name)
return true;
}
return false;
}
int JackEngine::GetNewUUID()
{
return fMaxUUID++;
}
void JackEngine::EnsureUUID(int uuid)
{
if (uuid > fMaxUUID)
fMaxUUID = uuid+1;
for (int i = 0; i < CLIENT_NUM; i++) {
JackClientInterface* client = fClientTable[i];
if (client && (client->GetClientControl()->fSessionID==uuid)) {
client->GetClientControl()->fSessionID = GetNewUUID();
}
}
}
int JackEngine::GetClientPID(const char* name)
{
for (int i = 0; i < CLIENT_NUM; i++) {
......@@ -486,9 +509,26 @@ int JackEngine::GetClientRefNum(const char* name)
}
// Used for external clients
int JackEngine::ClientExternalOpen(const char* name, int pid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
int JackEngine::ClientExternalOpen(const char* name, int pid, int uuid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
{
jack_log("JackEngine::ClientExternalOpen: name = %s ", name);
char real_name[JACK_CLIENT_NAME_SIZE+1];
if (uuid < 0) {
uuid = GetNewUUID();
strncpy( real_name, name, JACK_CLIENT_NAME_SIZE );
} else {
std::map<int,std::string>::iterator res = fReservationMap.find(uuid);
if (res != fReservationMap.end()) {
strncpy( real_name, res->second.c_str(), JACK_CLIENT_NAME_SIZE );
fReservationMap.erase(uuid);
} else {
strncpy( real_name, name, JACK_CLIENT_NAME_SIZE );
}
EnsureUUID(uuid);
}
jack_log("JackEngine::ClientExternalOpen: name = %s ", real_name);
int refnum = AllocateRefnum();
if (refnum < 0) {
......@@ -498,12 +538,17 @@ int JackEngine::ClientExternalOpen(const char* name, int pid, int* ref, int* sha
JackExternalClient* client = new JackExternalClient();
if (!fSynchroTable[refnum].Allocate(name, fEngineControl->fServerName, 0)) {
if (!fSynchroTable[refnum].Allocate(real_name, fEngineControl->fServerName, 0)) {
jack_error("Cannot allocate synchro");
goto error;
}
if (client->Open(name, pid, refnum, shared_client) < 0) {
if (uuid < 0)
uuid = GetNewUUID();
else
EnsureUUID(uuid);
if (client->Open(real_name, pid, refnum, uuid, shared_client) < 0) {
jack_error("Cannot open client");
goto error;
}
......@@ -516,7 +561,7 @@ int JackEngine::ClientExternalOpen(const char* name, int pid, int* ref, int* sha
fClientTable[refnum] = client;
if (NotifyAddClient(client, name, refnum) < 0) {
if (NotifyAddClient(client, real_name, refnum) < 0) {
jack_error("Cannot notify add client");
goto error;
}
......
......@@ -97,7 +97,7 @@ class SERVER_EXPORT JackEngine : public JackLockAble
// Client management
int ClientCheck(const char* name, char* name_res, int protocol, int options, int* status);
int ClientExternalOpen(const char* name, int pid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager);
int ClientExternalOpen(const char* name, int pid, int uuid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager);
int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait);
int ClientExternalClose(int refnum);
......
......@@ -41,7 +41,7 @@ int JackExternalClient::ClientNotify(int refnum, const char* name, int notify, i
return result;
}
int JackExternalClient::Open(const char* name, int pid, int refnum, int* shared_client)
int JackExternalClient::Open(const char* name, int pid, int refnum, int uuid, int* shared_client)
{
try {
......@@ -53,7 +53,7 @@ int JackExternalClient::Open(const char* name, int pid, int refnum, int* shared_
// Use "placement new" to allocate object in shared memory
JackShmMemAble* shared_mem = static_cast<JackShmMemAble*>(JackShmMem::operator new(sizeof(JackClientControl)));
shared_mem->Init();
fClientControl = new(shared_mem) JackClientControl(name, pid, refnum);
fClientControl = new(shared_mem) JackClientControl(name, pid, refnum, uuid);
if (!fClientControl) {
jack_error("Cannot allocate client shared memory segment");
......
......@@ -46,7 +46,7 @@ class JackExternalClient : public JackClientInterface
JackExternalClient();
virtual ~JackExternalClient();
int Open(const char* name, int pid, int refnum, int* shared_client);
int Open(const char* name, int pid, int refnum, int uuid, int* shared_client);
int Close();
int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
......
......@@ -63,7 +63,7 @@ JackInternalClient::~JackInternalClient()
delete fChannel;
}
int JackInternalClient::Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status)
int JackInternalClient::Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status, int uuid)
{
int result;
char name_res[JACK_CLIENT_NAME_SIZE + 1];
......@@ -198,11 +198,11 @@ JackLoadableInternalClient::~JackLoadableInternalClient()
UnloadJackModule(fHandle);
}
int JackLoadableInternalClient1::Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status)
int JackLoadableInternalClient1::Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status, int uuid)
{
int res = -1;
if (JackInternalClient::Open(server_name, name, options, status) == 0) {
if (JackInternalClient::Open(server_name, name, options, status, uuid) == 0) {
if (fInitialize((jack_client_t*)this, fObjectData) == 0) {
res = 0;
} else {
......@@ -214,11 +214,11 @@ int JackLoadableInternalClient1::Open(const char* server_name, const char* name,
return res;
}
int JackLoadableInternalClient2::Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status)
int JackLoadableInternalClient2::Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status, int uuid)
{
int res = -1;
if (JackInternalClient::Open(server_name, name, options, status) == 0) {
if (JackInternalClient::Open(server_name, name, options, status, uuid) == 0) {
if (fInitialize((jack_client_t*)this, fParameters) == 0) {
res = 0;
} else {
......
......@@ -46,7 +46,7 @@ class JackInternalClient : public JackClient
JackInternalClient(JackServer* server, JackSynchro* table);
virtual ~JackInternalClient();
int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status);
int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status, int uuid);
JackGraphManager* GetGraphManager() const;
JackEngineControl* GetEngineControl() const;
......@@ -100,7 +100,7 @@ class JackLoadableInternalClient1 : public JackLoadableInternalClient
{}
int Init(const char* so_name);
int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status);
int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status, int uuid);
};
......@@ -119,7 +119,7 @@ class JackLoadableInternalClient2 : public JackLoadableInternalClient
{}
int Init(const char* so_name);
int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status);
int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status, int uuid);
};
......
......@@ -137,9 +137,9 @@ class JackInternalClientChannel : public detail::JackClientChannelInterface
*result = fEngine->InternalClientHandle(client_name, status, int_ref);
}
void InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int* result)
void InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int* result, int uuid)
{
*result = fServer->InternalClientLoad(client_name, so_name, objet_data, options, int_ref, status);
*result = fServer->InternalClientLoad(client_name, so_name, objet_data, options, int_ref, status, uuid);
}
void InternalClientUnload(int refnum, int int_ref, int* status, int* result)
......
......@@ -96,7 +96,7 @@ jack_client_t* jack_client_new_aux(const char* client_name, jack_options_t optio
client = new JackLibClient(GetSynchroTable());
}
int res = client->Open(va.server_name, client_name, options, status);
int res = client->Open(va.server_name, client_name, options, status, va.session_id);
if (res < 0) {
delete client;
JackLibGlobals::Destroy(); // jack library destruction
......
......@@ -67,7 +67,7 @@ JackLibClient::~JackLibClient()
delete fChannel;
}
int JackLibClient::Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status)
int JackLibClient::Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status, int uuid)
{
int shared_engine, shared_client, shared_graph, result;
jack_log("JackLibClient::Open name = %s", name);
......@@ -88,7 +88,7 @@ int JackLibClient::Open(const char* server_name, const char* name, jack_options_
}
// Require new client
fChannel->ClientOpen(name_res, JackTools::GetPID(), &shared_engine, &shared_client, &shared_graph, &result);
fChannel->ClientOpen(name_res, JackTools::GetPID(), uuid, &shared_engine, &shared_client, &shared_graph, &result);
if (result < 0) {
jack_error("Cannot open %s client", name_res);
goto error;
......
......@@ -44,7 +44,7 @@ class JackLibClient : public JackClient
JackLibClient(JackSynchro* table);
virtual ~JackLibClient();
int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status);
int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status, int uuid);
int ClientNotifyImp(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
......
......@@ -103,11 +103,11 @@ class SERVER_EXPORT JackLockedEngine
return fEngine.ClientCheck(name, name_res, protocol, options, status);
CATCH_EXCEPTION_RETURN
}
int ClientExternalOpen(const char* name, int pid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
int ClientExternalOpen(const char* name, int pid, int uuid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
{
TRY_CALL
JackLock lock(&fEngine);
return fEngine.ClientExternalOpen(name, pid, ref, shared_engine, shared_client, shared_graph_manager);
return fEngine.ClientExternalOpen(name, pid, uuid, ref, shared_engine, shared_client, shared_graph_manager);
CATCH_EXCEPTION_RETURN
}
int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait)
......
......@@ -205,19 +205,23 @@ struct JackClientOpenRequest : public JackRequest
{
int fPID;
int fUUID;
char fName[JACK_CLIENT_NAME_SIZE + 1];
JackClientOpenRequest()
{}
JackClientOpenRequest(const char* name, int pid): JackRequest(JackRequest::kClientOpen)
JackClientOpenRequest(const char* name, int pid, int uuid): JackRequest(JackRequest::kClientOpen)
{
snprintf(fName, sizeof(fName), "%s", name);
fPID = pid;
fUUID = uuid;
}
int Read(JackChannelTransaction* trans)
{
CheckRes(trans->Read(&fPID, sizeof(int)));
CheckRes(trans->Read(&fUUID, sizeof(int)));
return trans->Read(&fName, JACK_CLIENT_NAME_SIZE + 1);
}
......@@ -225,6 +229,7 @@ struct JackClientOpenRequest : public JackRequest
{
CheckRes(JackRequest::Write(trans));
CheckRes(trans->Write(&fPID, sizeof(int)));
CheckRes(trans->Write(&fUUID, sizeof(int)));
return trans->Write(&fName, JACK_CLIENT_NAME_SIZE + 1);
}
......@@ -910,15 +915,17 @@ struct JackInternalClientLoadRequest : public JackRequest
char fDllName[MAX_PATH + 1];
char fLoadInitName[JACK_LOAD_INIT_LIMIT + 1];
int fOptions;
int fUUID;
JackInternalClientLoadRequest()
{}
JackInternalClientLoadRequest(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options)
: JackRequest(JackRequest::kInternalClientLoad), fRefNum(refnum), fOptions(options)
JackInternalClientLoadRequest(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int uuid )
: JackRequest(JackRequest::kInternalClientLoad), fRefNum(refnum), fOptions(options), fUUID(uuid)
{
snprintf(fName, sizeof(fName), "%s", client_name);
snprintf(fDllName, sizeof(fDllName), "%s", so_name);
snprintf(fLoadInitName, sizeof(fLoadInitName), "%s", objet_data);
snprintf(fLoadInitName, sizeof(fLoadInitName), "%s", objet_data);
}
int Read(JackChannelTransaction* trans)
......@@ -927,6 +934,7 @@ struct JackInternalClientLoadRequest : public JackRequest
CheckRes(trans->Read(&fName, JACK_CLIENT_NAME_SIZE + 1));
CheckRes(trans->Read(&fDllName, MAX_PATH + 1));
CheckRes(trans->Read(&fLoadInitName, JACK_LOAD_INIT_LIMIT + 1));
CheckRes(trans->Read(&fUUID, sizeof(int)));
return trans->Read(&fOptions, sizeof(int));
}
......@@ -937,6 +945,7 @@ struct JackInternalClientLoadRequest : public JackRequest
CheckRes(trans->Write(&fName, JACK_CLIENT_NAME_SIZE + 1));
CheckRes(trans->Write(&fDllName, MAX_PATH + 1));
CheckRes(trans->Write(&fLoadInitName, JACK_LOAD_INIT_LIMIT + 1));
CheckRes(trans->Write(&fUUID, sizeof(int)));
return trans->Write(&fOptions, sizeof(int));
}
......
......@@ -136,25 +136,25 @@ int JackServer::Close()
return 0;
}
int JackServer::InternalClientLoad(const char* client_name, const char* so_name, const char* objet_data, int options, int* int_ref, int* status)
int JackServer::InternalClientLoad(const char* client_name, const char* so_name, const char* objet_data, int options, int* int_ref, int* status, int uuid)
{
JackLoadableInternalClient* client = new JackLoadableInternalClient1(JackServerGlobals::fInstance, GetSynchroTable(), objet_data);
assert(client);
return InternalClientLoadAux(client, so_name, client_name, options, int_ref, status);
return InternalClientLoadAux(client, so_name, client_name, options, int_ref, status, uuid);
}
int JackServer::InternalClientLoad(const char* client_name, const char* so_name, const JSList * parameters, int options, int* int_ref, int* status)
int JackServer::InternalClientLoad(const char* client_name, const char* so_name, const JSList * parameters, int options, int* int_ref, int* status, int uuid)
{
JackLoadableInternalClient* client = new JackLoadableInternalClient2(JackServerGlobals::fInstance, GetSynchroTable(), parameters);
assert(client);
return InternalClientLoadAux(client, so_name, client_name, options, int_ref, status);
return InternalClientLoadAux(client, so_name, client_name, options, int_ref, status, uuid);
}
int JackServer::InternalClientLoadAux(JackLoadableInternalClient* client, const char* so_name, const char* client_name, int options, int* int_ref, int* status)
int JackServer::InternalClientLoadAux(JackLoadableInternalClient* client, const char* so_name, const char* client_name, int options, int* int_ref, int* status, int uuid)
{
// Clear status
*status = 0;
if ((client->Init(so_name) < 0) || (client->Open(JACK_DEFAULT_SERVER_NAME, client_name, (jack_options_t)options, (jack_status_t*)status) < 0)) {
if ((client->Init(so_name) < 0) || (client->Open(JACK_DEFAULT_SERVER_NAME, client_name, (jack_options_t)options, (jack_status_t*)status, uuid) < 0)) {
delete client;
int my_status1 = *status | JackFailure;
*status = (jack_status_t)my_status1;
......
......@@ -58,7 +58,7 @@ class SERVER_EXPORT JackServer
JackSynchro fSynchroTable[CLIENT_NUM];
bool fFreewheel;
int InternalClientLoadAux(JackLoadableInternalClient* client, const char* so_name, const char* client_name, int options, int* int_ref, int* status);
int InternalClientLoadAux(JackLoadableInternalClient* client, const char* so_name, const char* client_name, int options, int* int_ref, int* status, int uuid);
public:
......@@ -77,8 +77,8 @@ class SERVER_EXPORT JackServer
// Command thread : API
int SetBufferSize(jack_nframes_t buffer_size);
int SetFreewheel(bool onoff);
int InternalClientLoad(const char* client_name, const char* so_name, const char* objet_data, int options, int* int_ref, int* status);
int InternalClientLoad(const char* client_name, const char* so_name, const JSList * parameters, int options, int* int_ref, int* status);
int InternalClientLoad(const char* client_name, const char* so_name, const char* objet_data, int options, int* int_ref, int* statu, int uuid);
int InternalClientLoad(const char* client_name, const char* so_name, const JSList * parameters, int options, int* int_ref, int* status, int uuid);
void ClientKill(int refnum);
// Transport management
......
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