Commit 5845be13 authored by sletz's avatar sletz
Browse files

jack_client_has_session_callback implementation.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4158 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 43a2fcb6
......@@ -34,6 +34,10 @@ Valerio Pilo
Jackdmp changes log
---------------------------
2011-03-09 Stephane Letz <letz@grame.fr>
* jack_client_has_session_callback implementation.
2011-03-08 Stephane Letz <letz@grame.fr>
* Use of latency range in all backends.
......
......@@ -255,6 +255,16 @@ extern "C"
jack_intclient_t intclient);
EXPORT void jack_free(void* ptr);
EXPORT int jack_set_session_callback(jack_client_t* ext_client, JackSessionCallback session_callback, void* arg);
EXPORT jack_session_command_t *jack_session_notify(jack_client_t* ext_client, const char* target, jack_session_event_type_t ev_type, const char *path);
EXPORT int jack_session_reply(jack_client_t *ext_client, jack_session_event_t *event);
EXPORT void jack_session_event_free(jack_session_event_t* ev);
EXPORT char *jack_get_uuid_for_client_name(jack_client_t *ext_client, const char *client_name);
EXPORT char *jack_get_client_name_by_uuid(jack_client_t *ext_client, const char *client_uuid);
EXPORT int jack_reserve_client_name(jack_client_t *ext_client, const char *name, const char *uuid);
EXPORT void jack_session_commands_free(jack_session_command_t *cmds);
EXPORT int jack_client_has_session_callback(jack_client_t *client, const char *client_name);
#ifdef __cplusplus
}
#endif
......@@ -1975,7 +1985,7 @@ EXPORT void jack_session_event_free(jack_session_event_t* ev)
}
}
EXPORT char *jack_get_uuid_for_client_name( jack_client_t *ext_client, const char *client_name )
EXPORT char *jack_get_uuid_for_client_name(jack_client_t *ext_client, const char *client_name)
{
#ifdef __CLIENTDEBUG__
JackGlobals::CheckContext("jack_get_uuid_for_client_name");
......@@ -1990,7 +2000,7 @@ EXPORT char *jack_get_uuid_for_client_name( jack_client_t *ext_client, const cha
}
}
EXPORT char *jack_get_client_name_by_uuid( jack_client_t *ext_client, const char *client_uuid )
EXPORT char *jack_get_client_name_by_uuid(jack_client_t *ext_client, const char *client_uuid)
{
#ifdef __CLIENTDEBUG__
JackGlobals::CheckContext("jack_get_client_name_by_uuid");
......@@ -2001,11 +2011,11 @@ EXPORT char *jack_get_client_name_by_uuid( jack_client_t *ext_client, const char
jack_error("jack_get_client_name_by_uuid called with a NULL client");
return NULL;
} else {
return client->GetClientNameForUUID(client_uuid);
return client->GetClientNameByUUID(client_uuid);
}
}
EXPORT int jack_reserve_client_name( jack_client_t *ext_client, const char *name, const char *uuid )
EXPORT int jack_reserve_client_name(jack_client_t *ext_client, const char *client_name, const char *uuid)
{
#ifdef __CLIENTDEBUG__
JackGlobals::CheckContext("jack_reserve_client_name");
......@@ -2016,17 +2026,17 @@ EXPORT int jack_reserve_client_name( jack_client_t *ext_client, const char *name
jack_error("jack_reserve_client_name called with a NULL client");
return -1;
} else {
return client->ReserveClientName(name, uuid);
return client->ReserveClientName(client_name, uuid);
}
}
EXPORT void jack_session_commands_free( jack_session_command_t *cmds )
EXPORT void jack_session_commands_free(jack_session_command_t *cmds)
{
if (!cmds)
return;
int i=0;
while(1) {
int i = 0;
while (1) {
if (cmds[i].client_name)
free ((char *)cmds[i].client_name);
if (cmds[i].command)
......@@ -2041,3 +2051,18 @@ EXPORT void jack_session_commands_free( jack_session_command_t *cmds )
free(cmds);
}
EXPORT int jack_client_has_session_callback(jack_client_t *ext_client, const char *client_name)
{
#ifdef __CLIENTDEBUG__
JackGlobals::CheckContext("jack_client_has_session_callback");
#endif
JackClient* client = (JackClient*)ext_client;
jack_log("jack_client_has_session_callback ext_client %x client %x ", ext_client, client);
if (client == NULL) {
jack_error("jack_client_has_session_callback called with a NULL client");
return -1;
} else {
return client->ClientHasSessionCallback(client_name);
}
}
......@@ -107,41 +107,34 @@ class JackClientChannelInterface
{}
virtual void SetFreewheel(int onoff, int* result)
{}
virtual void ComputeTotalLatencies(int* result)
{}
virtual void ReleaseTimebase(int refnum, int* result)
{}
virtual void SetTimebaseCallback(int refnum, int conditional, int* result)
{}
virtual void GetInternalClientName(int refnum, int int_ref, char* name_res, int* result)
{}
virtual void InternalClientHandle(int refnum, const char* client_name, int* status, int* int_ref, int* result)
{}
virtual void InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int uuid, int* result)
{}
virtual void InternalClientUnload(int refnum, int int_ref, int* status, int* result)
{}
virtual void SessionNotify(int refnum, const char* target, jack_session_event_type_t type, const char *path, jack_session_command_t **result)
virtual void SessionNotify(int refnum, const char* target, jack_session_event_type_t type, const char* path, jack_session_command_t** result)
{}
virtual void SessionReply(int refnum, int *result)
virtual void SessionReply(int refnum, int* result)
{}
virtual void GetUUIDForClientName(int refnum, const char *client_name, char *uuid_res, int *result)
virtual void GetUUIDForClientName(int refnum, const char* client_name, char* uuid_res, int* result)
{}
virtual void GetClientNameForUUID(int refnum, const char *uuid, char *name_res, int *result)
virtual void GetClientNameForUUID(int refnum, const char* uuid, char* name_res, int* result)
{}
virtual void ReserveClientName(int refnum, const char *client_name, const char *uuid, int *result)
virtual void ReserveClientName(int refnum, const char* client_name, const char *uuid, int* result)
{}
virtual void ClientHasSessionCallback(const char* client_name, int* result)
{}
virtual bool IsChannelThread()
......
......@@ -1199,34 +1199,34 @@ void JackClient::InternalClientUnload(int ref, jack_status_t* status)
// Session API
//------------------
jack_session_command_t *JackClient::SessionNotify( const char* target, jack_session_event_type_t type, const char* path )
jack_session_command_t* JackClient::SessionNotify(const char* target, jack_session_event_type_t type, const char* path)
{
jack_session_command_t *res;
fChannel->SessionNotify( GetClientControl()->fRefNum, target, type, path, &res );
jack_session_command_t* res;
fChannel->SessionNotify(GetClientControl()->fRefNum, target, type, path, &res);
return res;
}
int JackClient::SessionReply( jack_session_event_t *ev )
int JackClient::SessionReply(jack_session_event_t* ev)
{
if (ev->command_line) {
strncpy( GetClientControl()->fSessionCommand, ev->command_line, sizeof(GetClientControl()->fSessionCommand) );
strncpy(GetClientControl()->fSessionCommand, ev->command_line, sizeof(GetClientControl()->fSessionCommand));
} else {
GetClientControl()->fSessionCommand[0] = '\0';
}
GetClientControl()->fSessionFlags = ev->flags;
jack_log( "JackClient::SessionReply... we are here" );
jack_log("JackClient::SessionReply... we are here");
if (fChannel->IsChannelThread()) {
jack_log( "JackClient::SessionReply... in callback reply" );
jack_log( "JackClient::SessionReply... in callback reply");
fImmediateSessionReply = true;
return 0;
}
jack_log( "JackClient::SessionReply... out of cb" );
jack_log("JackClient::SessionReply... out of cb");
int res;
fChannel->SessionReply( GetClientControl()->fRefNum, &res);
fChannel->SessionReply(GetClientControl()->fRefNum, &res);
return res;
}
......@@ -1234,30 +1234,29 @@ char* JackClient::GetUUIDForClientName(const char* client_name)
{
char uuid_res[JACK_UUID_SIZE];
int result = -1;
fChannel->GetUUIDForClientName( GetClientControl()->fRefNum, client_name, uuid_res, &result);
if (result)
return NULL;
return strdup(uuid_res);
fChannel->GetUUIDForClientName(GetClientControl()->fRefNum, client_name, uuid_res, &result);
return (result) ? NULL : strdup(uuid_res);
}
char* JackClient::GetClientNameForUUID(const char* uuid)
char* JackClient::GetClientNameByUUID(const char* uuid)
{
char name_res[JACK_CLIENT_NAME_SIZE + 1];
int result = -1;
fChannel->GetClientNameForUUID(GetClientControl()->fRefNum, uuid, name_res, &result);
return (result) ? NULL : strdup(name_res);
}
if (result)
return NULL;
return strdup(name_res);
int JackClient::ReserveClientName(const char* client_name, const char* uuid)
{
int result = -1;
fChannel->ReserveClientName( GetClientControl()->fRefNum, client_name, uuid, &result);
return result;
}
int JackClient::ReserveClientName(const char *name, const char* uuid)
int JackClient::ClientHasSessionCallback(const char* client_name)
{
int result = -1;
fChannel->ReserveClientName( GetClientControl()->fRefNum, name, uuid, &result);
fChannel->ClientHasSessionCallback(client_name, &result);
return result;
}
......
......@@ -191,16 +191,18 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
virtual int InternalClientLoad(const char* client_name, jack_options_t options, jack_status_t* status, jack_varargs_t* va);
virtual void InternalClientUnload(int ref, jack_status_t* status);
// RT Thread
jack_nframes_t CycleWait();
void CycleSignal(int status);
int SetProcessThread(JackThreadCallback fun, void *arg);
// Session api
virtual jack_session_command_t *SessionNotify(const char *target, jack_session_event_type_t type, const char *path);
virtual int SessionReply(jack_session_event_t *ev);
// Session API
virtual jack_session_command_t* SessionNotify(const char* target, jack_session_event_type_t type, const char* path);
virtual int SessionReply(jack_session_event_t* ev);
char* GetUUIDForClientName(const char* client_name);
char* GetClientNameForUUID(const char* uuid);
int ReserveClientName(const char *name, const char* uuid);
char* GetClientNameByUUID(const char* uuid);
int ReserveClientName(const char* client_name, const char* uuid);
int ClientHasSessionCallback(const char* client_name);
// JackRunnableInterface interface
bool Init();
......
......@@ -418,7 +418,7 @@ int JackEngine::ClientCheck(const char* name, int uuid, char* name_res, int prot
std::map<int,std::string>::iterator res = fReservationMap.find(uuid);
if (res != fReservationMap.end()) {
strncpy( name_res, res->second.c_str(), JACK_CLIENT_NAME_SIZE );
strncpy(name_res, res->second.c_str(), JACK_CLIENT_NAME_SIZE);
} else if (ClientCheckName(name)) {
*status |= JackNameNotUnique;
......@@ -479,7 +479,7 @@ bool JackEngine::ClientCheckName(const char* name)
return true;
}
for (std::map<int,std::string>::iterator i=fReservationMap.begin(); i!=fReservationMap.end(); i++) {
for (std::map<int,std::string>::iterator i = fReservationMap.begin(); i != fReservationMap.end(); i++) {
if (i->second == name)
return true;
}
......@@ -538,10 +538,10 @@ int JackEngine::ClientExternalOpen(const char* name, int pid, int uuid, int* ref
} 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 );
strncpy(real_name, res->second.c_str(), JACK_CLIENT_NAME_SIZE);
fReservationMap.erase(uuid);
} else {
strncpy( real_name, name, JACK_CLIENT_NAME_SIZE );
strncpy(real_name, name, JACK_CLIENT_NAME_SIZE);
}
EnsureUUID(uuid);
......@@ -912,6 +912,10 @@ int JackEngine::PortRename(int refnum, jack_port_id_t port, const char* name)
return 0;
}
//--------------------
// Session management
//--------------------
void JackEngine::SessionNotify(int refnum, const char *target, jack_session_event_type_t type, const char *path, JackChannelTransaction *socket)
{
if (fSessionPendingReplies != 0) {
......@@ -975,11 +979,11 @@ void JackEngine::SessionReply(int refnum)
{
JackClientInterface* client = fClientTable[refnum];
char uuid_buf[JACK_UUID_SIZE];
snprintf( uuid_buf, sizeof(uuid_buf), "%d", client->GetClientControl()->fSessionID );
fSessionResult->fCommandList.push_back( JackSessionCommand( uuid_buf,
client->GetClientControl()->fName,
client->GetClientControl()->fSessionCommand,
client->GetClientControl()->fSessionFlags ));
snprintf( uuid_buf, sizeof(uuid_buf), "%d", client->GetClientControl()->fSessionID);
fSessionResult->fCommandList.push_back(JackSessionCommand(uuid_buf,
client->GetClientControl()->fName,
client->GetClientControl()->fSessionCommand,
client->GetClientControl()->fSessionFlags));
fSessionPendingReplies -= 1;
if (fSessionPendingReplies == 0) {
......@@ -1000,9 +1004,8 @@ void JackEngine::GetUUIDForClientName(const char *client_name, char *uuid_res, i
return;
}
}
// did not find name.
// Did not find name.
*result = -1;
return;
}
void JackEngine::GetClientNameForUUID(const char *uuid, char *name_res, int *result)
......@@ -1022,18 +1025,17 @@ void JackEngine::GetClientNameForUUID(const char *uuid, char *name_res, int *res
return;
}
}
// did not find uuid.
// Did not find uuid.
*result = -1;
return;
}
void JackEngine::ReserveClientName(const char *name, const char *uuid, int *result)
{
jack_log( "JackEngine::ReserveClientName ( name = %s, uuid = %s )", name, uuid );
jack_log("JackEngine::ReserveClientName ( name = %s, uuid = %s )", name, uuid);
if (ClientCheckName(name)) {
*result = -1;
jack_log( "name already taken" );
jack_log("name already taken");
return;
}
......@@ -1042,5 +1044,21 @@ void JackEngine::ReserveClientName(const char *name, const char *uuid, int *resu
*result = 0;
}
void JackEngine::ClientHasSessionCallbackRequest(const char *name, int *result)
{
JackClientInterface* client = NULL;
for (int i = 0; i < CLIENT_NUM; i++) {
JackClientInterface* client = fClientTable[i];
if (client && (strcmp(client->GetClientControl()->fName, name) == 0))
break;
}
if (client) {
*result = client->GetClientControl()->fCallback[kSessionCallback];
} else {
*result = -1;
}
}
} // end of namespace
......@@ -151,6 +151,7 @@ class SERVER_EXPORT JackEngine : public JackLockAble
void GetUUIDForClientName(const char *client_name, char *uuid_res, int *result);
void GetClientNameForUUID(const char *uuid, char *name_res, int *result);
void ReserveClientName(const char *name, const char *uuid, int *result);
void ClientHasSessionCallbackRequest(const char *name, int *result);
};
......
......@@ -80,7 +80,6 @@ class JackInternalClientChannel : public detail::JackClientChannelInterface
{
*result = fEngine->PortUnRegister(refnum, port_index);
}
void PortConnect(int refnum, const char* src, const char* dst, int* result)
{
*result = fEngine->PortConnect(refnum, src, dst);
......@@ -89,7 +88,6 @@ class JackInternalClientChannel : public detail::JackClientChannelInterface
{
*result = fEngine->PortDisconnect(refnum, src, dst);
}
void PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
{
*result = fEngine->PortConnect(refnum, src, dst);
......@@ -111,17 +109,11 @@ class JackInternalClientChannel : public detail::JackClientChannelInterface
{
*result = fServer->SetFreewheel(onoff);
}
void ComputeTotalLatencies(int* result)
{
*result = fEngine->ComputeTotalLatencies();
}
void SessionNotify( int refnum, const char *target, jack_session_event_type_t type, const char *path, jack_session_command_t **result )
{
*result = NULL;
}
void ReleaseTimebase(int refnum, int* result)
{
*result = fServer->ReleaseTimebase(refnum);
......@@ -152,6 +144,12 @@ class JackInternalClientChannel : public detail::JackClientChannelInterface
*result = fEngine->InternalClientUnload(int_ref, status);
}
void SessionNotify(int refnum, const char *target, jack_session_event_type_t type, const char *path, jack_session_command_t** result)
{
*result = NULL;
}
};
} // end of namespace
......
......@@ -352,6 +352,14 @@ class SERVER_EXPORT JackLockedEngine
fEngine.ReserveClientName(name, uuid, result);
CATCH_EXCEPTION
}
void ClientHasSessionCallbackRequest(const char *name, int *result)
{
TRY_CALL
JackLock lock(&fEngine);
fEngine.ClientHasSessionCallbackRequest(name, result);
CATCH_EXCEPTION
}
};
} // end of namespace
......
......@@ -72,7 +72,8 @@ struct JackRequest
kGetClientByUUID = 35,
kReserveClientName = 36,
kGetUUIDByClient = 37,
kComputeTotalLatencies = 38
kClientHasSessionCallback = 38,
kComputeTotalLatencies = 39
};
RequestType fType;
......@@ -1393,6 +1394,34 @@ struct JackReserveNameRequest : public JackRequest
};
struct JackClientHasSessionCallbackRequest : public JackRequest
{
char fName[JACK_CLIENT_NAME_SIZE + 1];
JackClientHasSessionCallbackRequest()
{}
JackClientHasSessionCallbackRequest(const char *name)
: JackRequest(JackRequest::kClientHasSessionCallback)
{
strncpy(fName, name, sizeof(fName));
}
int Read(JackChannelTransaction* trans)
{
CheckRes(trans->Read(&fName, sizeof(fName)));
return 0;
}
int Write(JackChannelTransaction* trans)
{
CheckRes(JackRequest::Write(trans));
CheckRes(trans->Write(&fName, sizeof(fName)));
return 0;
}
};
/*!
\brief ClientNotification.
*/
......
......@@ -1108,14 +1108,14 @@
isa = PBXContainerItemProxy;
containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 4B3811551326878E00C61B14 /* jack_latent_client Universal */;
remoteGlobalIDString = 4B3811551326878E00C61B14;
remoteInfo = "jack_latent_client Universal";
};
4B38120213269CCB00C61B14 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 4B38118D1326884E00C61B14 /* jack_latent_client 64 bits */;
remoteGlobalIDString = 4B38118D1326884E00C61B14;
remoteInfo = "jack_latent_client 64 bits";
};
4B43A8CC1014607100E52943 /* PBXContainerItemProxy */ = {
......
......@@ -253,22 +253,22 @@ void JackSocketClientChannel::ComputeTotalLatencies(int* result)
ServerSyncCall(&req, &res, result);
}
void JackSocketClientChannel::SessionNotify(int refnum, const char* target, jack_session_event_type_t type, const char* path, jack_session_command_t ** result)
void JackSocketClientChannel::SessionNotify(int refnum, const char* target, jack_session_event_type_t type, const char* path, jack_session_command_t** result)
{
JackSessionNotifyRequest req(refnum, path, type, target);
JackSessionNotifyResult res;
JackSessionNotifyResult res;
int intresult;
ServerSyncCall(&req, &res, &intresult);
jack_session_command_t *session_command = (jack_session_command_t *)malloc( sizeof(jack_session_command_t) * (res.fCommandList.size()+1) );
int i=0;
jack_session_command_t* session_command = (jack_session_command_t *)malloc(sizeof(jack_session_command_t) * (res.fCommandList.size() + 1));
int i = 0;
for (std::list<JackSessionCommand>::iterator ci=res.fCommandList.begin(); ci!=res.fCommandList.end(); ci++) {
session_command[i].uuid = strdup( ci->fUUID );
session_command[i].client_name = strdup( ci->fClientName );
session_command[i].command = strdup( ci->fCommand );
session_command[i].flags = ci->fFlags;
i+=1;
i += 1;
}
session_command[i].uuid = NULL;
......@@ -282,30 +282,37 @@ void JackSocketClientChannel::SessionNotify(int refnum, const char* target, jack
void JackSocketClientChannel::SessionReply(int refnum, int* result)
{
JackSessionReplyRequest req(refnum);
JackResult res;
JackResult res;
ServerSyncCall(&req, &res, result);
}
void JackSocketClientChannel::GetUUIDForClientName( int refnum, const char *client_name, char *uuid_res, int *result )
void JackSocketClientChannel::GetUUIDForClientName(int refnum, const char* client_name, char* uuid_res, int* result)
{
JackGetUUIDRequest req(client_name);
JackUUIDResult res;
JackUUIDResult res;
ServerSyncCall(&req, &res, result);
strncpy( uuid_res, res.fUUID, JACK_UUID_SIZE );
strncpy(uuid_res, res.fUUID, JACK_UUID_SIZE);
}
void JackSocketClientChannel::GetClientNameForUUID( int refnum, const char *uuid, char *name_res, int *result )
void JackSocketClientChannel::GetClientNameForUUID(int refnum, const char* uuid, char* name_res, int* result)
{
JackGetClientNameRequest req(uuid);
JackClientNameResult res;
JackClientNameResult res;
ServerSyncCall(&req, &res, result);
strncpy( name_res, res.fName, JACK_CLIENT_NAME_SIZE );
strncpy(name_res, res.fName, JACK_CLIENT_NAME_SIZE);
}
void JackSocketClientChannel::ReserveClientName( int refnum, const char *client_name, const char *uuid, int *result )
void JackSocketClientChannel::ClientHasSessionCallback(const char* client_name, int* result)
{
JackClientHasSessionCallbackRequest req(client_name);
JackResult res;
ServerSyncCall(&req, &res, result);
}
void JackSocketClientChannel::ReserveClientName(int refnum, const char* client_name, const char* uuid, int* result)
{
JackReserveNameRequest req(refnum, client_name, uuid);
JackResult res;
JackResult res;
ServerSyncCall(&req, &res, result);
}
......
......@@ -38,11 +38,11 @@ class JackSocketClientChannel : public detail::JackClientChannelInterface, publi
private:
JackClientSocket fRequestSocket; // Socket to communicate with the server
JackServerSocket fNotificationListenSocket; // Socket listener for server notification
JackClientSocket* fNotificationSocket; // Socket for server notification
JackClientSocket fRequestSocket; // Socket to communicate with the server
JackServerSocket fNotificationListenSocket; // Socket listener for server notification
JackClientSocket* fNotificationSocket; // Socket for server notification
JackThread fThread; // Thread to execute the event loop
JackClient* fClient;
JackClient* fClient;
void ServerSyncCall(JackRequest* req, JackResult* res, int* result);
void ServerAsyncCall(JackRequest* req, JackResult* res, int* result);
......@@ -93,18 +93,18 @@ class JackSocketClientChannel : public detail::JackClientChannelInterface, publi
void InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int uuid, int* result);