diff --git a/common/JackClient.cpp b/common/JackClient.cpp index 8c3c6de5..121e7f91 100644 --- a/common/JackClient.cpp +++ b/common/JackClient.cpp @@ -81,6 +81,8 @@ JackClient::JackClient(JackSynchro* table):fThread(this) fThreadFunArg = NULL; fSessionArg = NULL; fLatencyArg = NULL; + + fSessionReply = kPendingSessionReply; } JackClient::~JackClient() @@ -284,17 +286,18 @@ int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync, case kSessionCallback: jack_log("JackClient::kSessionCallback"); if (fSession) { - jack_session_event_t *event = (jack_session_event_t *) malloc( sizeof(jack_session_event_t) ); + jack_session_event_t* event = (jack_session_event_t*)malloc( sizeof(jack_session_event_t)); char uuid_buf[JACK_UUID_SIZE]; - event->type = (jack_session_event_type_t) value1; - event->session_dir = strdup( message ); + event->type = (jack_session_event_type_t)value1; + event->session_dir = strdup(message); event->command_line = NULL; - event->flags = (jack_session_flags_t) 0; - snprintf( uuid_buf, sizeof(uuid_buf), "%d", GetClientControl()->fSessionID ); - event->client_uuid = strdup( uuid_buf ); - fImmediateSessionReply = false; + event->flags = (jack_session_flags_t)0; + snprintf(uuid_buf, sizeof(uuid_buf), "%d", GetClientControl()->fSessionID); + event->client_uuid = strdup(uuid_buf); + fSessionReply = kPendingSessionReply; + // Session callback may change fSessionReply by directly using jack_session_reply fSession(event, fSessionArg); - res = (fImmediateSessionReply) ? 1 : 2; + res = fSessionReply; } break; @@ -1232,8 +1235,9 @@ int JackClient::SessionReply(jack_session_event_t* ev) jack_log("JackClient::SessionReply... we are here"); if (fChannel->IsChannelThread()) { - jack_log( "JackClient::SessionReply... in callback reply"); - fImmediateSessionReply = true; + jack_log("JackClient::SessionReply... in callback reply"); + // OK, immediate reply... + fSessionReply = kImmediateSessionReply; return 0; } diff --git a/common/JackClient.h b/common/JackClient.h index 7d8e0864..889a36f1 100644 --- a/common/JackClient.h +++ b/common/JackClient.h @@ -93,7 +93,7 @@ class SERVER_EXPORT JackClient : public JackClientInterface, public JackRunnable JackSynchro* fSynchroTable; std::list fPortList; - bool fImmediateSessionReply; + JackSessionReply fSessionReply; int StartThread(); void SetupDriverSync(bool freewheel); diff --git a/common/JackEngine.cpp b/common/JackEngine.cpp index ca653cc3..ff991fde 100644 --- a/common/JackEngine.cpp +++ b/common/JackEngine.cpp @@ -972,11 +972,11 @@ void JackEngine::SessionNotify(int refnum, const char *target, jack_session_even if (res) jack_error("JackEngine::SessionNotify: can not create session directory '%s'", path_buf); - int result = client->ClientNotify(i, client->GetClientControl()->fName, kSessionCallback, true, path_buf, (int) type, 0); + int result = client->ClientNotify(i, client->GetClientControl()->fName, kSessionCallback, true, path_buf, (int)type, 0); - if (result == 2) { + if (result == kPendingSessionReply) { fSessionPendingReplies += 1; - } else if (result == 1) { + } else if (result == kImmediateSessionReply) { char uuid_buf[JACK_UUID_SIZE]; snprintf(uuid_buf, sizeof(uuid_buf), "%d", client->GetClientControl()->fSessionID); fSessionResult->fCommandList.push_back(JackSessionCommand(uuid_buf, @@ -1000,7 +1000,7 @@ 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); + snprintf(uuid_buf, sizeof(uuid_buf), "%d", client->GetClientControl()->fSessionID); fSessionResult->fCommandList.push_back(JackSessionCommand(uuid_buf, client->GetClientControl()->fName, client->GetClientControl()->fSessionCommand, diff --git a/common/JackEngine.h b/common/JackEngine.h index 8fcd6307..179d7e07 100644 --- a/common/JackEngine.h +++ b/common/JackEngine.h @@ -54,8 +54,8 @@ class SERVER_EXPORT JackEngine : public JackLockAble jack_time_t fLastSwitchUsecs; int fSessionPendingReplies; - JackChannelTransaction *fSessionTransaction; - JackSessionNotifyResult *fSessionResult; + JackChannelTransaction* fSessionTransaction; + JackSessionNotifyResult* fSessionResult; std::map fReservationMap; int fMaxUUID; diff --git a/common/JackRequest.h b/common/JackRequest.h index 71f47b4b..f5e86543 100644 --- a/common/JackRequest.h +++ b/common/JackRequest.h @@ -31,7 +31,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. namespace Jack { -#define CheckRes(exp) { if ((exp) < 0) return -1;} +#define CheckRes(exp) { if ((exp) < 0) return -1; } + +/*! +\brief Session API constants. +*/ + +enum JackSessionReply { + + kImmediateSessionReply = 1, + kPendingSessionReply = 2 + +}; /*! \brief Request from client to server. @@ -1119,11 +1130,11 @@ struct JackSessionCommand JackSessionCommand() {} - JackSessionCommand( const char *uuid, const char *clientname, const char *command, jack_session_flags_t flags ) + JackSessionCommand(const char *uuid, const char *clientname, const char *command, jack_session_flags_t flags) { - strncpy( fUUID, uuid, sizeof(fUUID)); - strncpy( fClientName, clientname, sizeof(fClientName)); - strncpy( fCommand, command, sizeof(fCommand)); + strncpy(fUUID, uuid, sizeof(fUUID)); + strncpy(fClientName, clientname, sizeof(fClientName)); + strncpy(fCommand, command, sizeof(fCommand)); fFlags = flags; } }; @@ -1184,19 +1195,20 @@ struct JackSessionNotifyRequest : public JackRequest { char fPath[JACK_MESSAGE_SIZE + 1]; char fDst[JACK_CLIENT_NAME_SIZE + 1]; - jack_session_event_type_t fEventType; - int fRefNum; + jack_session_event_type_t fEventType; + int fRefNum; JackSessionNotifyRequest() {} - JackSessionNotifyRequest(int refnum, const char *path, jack_session_event_type_t type, const char *dst) + JackSessionNotifyRequest(int refnum, const char* path, jack_session_event_type_t type, const char* dst) : JackRequest(JackRequest::kSessionNotify), fEventType(type), fRefNum(refnum) { snprintf(fPath, sizeof(fPath), "%s", path); - if (dst) + if (dst) { snprintf(fDst, sizeof(fDst), "%s", dst); - else + } else { fDst[0] = '\0'; + } } int Read(JackChannelTransaction* trans) @@ -1276,7 +1288,6 @@ struct JackClientNameResult : public JackResult struct JackUUIDResult : public JackResult { - char fUUID[JACK_UUID_SIZE]; JackUUIDResult(): JackResult() diff --git a/example-clients/session_notify.c b/example-clients/session_notify.c index 9cb3f894..1872d8c4 100644 --- a/example-clients/session_notify.c +++ b/example-clients/session_notify.c @@ -2,7 +2,7 @@ * session_notify.c -- ultra minimal session manager * * Copyright (C) 2010 Torben Hohn. - * + * * 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 @@ -141,15 +141,15 @@ int main(int argc, char *argv[]) retval = jack_session_notify( client, NULL, notify_type, save_path ); - for(i=0; retval[i].uuid; i++ ) { + for (i = 0; retval[i].uuid; i++) { printf( "export SESSION_DIR=\"%s%s/\"\n", save_path, retval[i].client_name ); printf( "%s &\n", retval[i].command ); - add_uuid_mapping(retval[i].uuid); + add_uuid_mapping(retval[i].uuid); } printf( "sleep 10\n" ); - for(k=0; retval[k].uuid; k++ ) { + for (k = 0; retval[k].uuid; k++) { char* port_regexp = alloca( jack_client_name_size()+3 ); char* client_name = jack_get_client_name_by_uuid( client, retval[k].uuid ); @@ -163,12 +163,12 @@ int main(int argc, char *argv[]) const char **connections; if ((connections = jack_port_get_all_connections (client, jack_port_by_name(client, ports[i]))) != 0) { for (j = 0; connections[j]; j++) { - char *src = map_port_name_to_uuid_port( ports[i] ); - char *dst = map_port_name_to_uuid_port( connections[j] ); + char *src = map_port_name_to_uuid_port( ports[i] ); + char *dst = map_port_name_to_uuid_port( connections[j] ); printf( "jack_connect -u \"%s\" \"%s\"\n", src, dst ); } jack_free (connections); - } + } } jack_free(ports); diff --git a/posix/JackSocketServerChannel.cpp b/posix/JackSocketServerChannel.cpp index fb3fa355..caaac23c 100644 --- a/posix/JackSocketServerChannel.cpp +++ b/posix/JackSocketServerChannel.cpp @@ -426,7 +426,6 @@ bool JackSocketServerChannel::HandleRequest(int fd) case JackRequest::kSessionNotify: { jack_log("JackRequest::SessionNotify"); JackSessionNotifyRequest req; - JackSessionNotifyResult res; if (req.Read(socket) == 0) { fServer->GetEngine()->SessionNotify(req.fRefNum, req.fDst, req.fEventType, req.fPath, socket); } diff --git a/windows/JackWinNamedPipeClientChannel.cpp b/windows/JackWinNamedPipeClientChannel.cpp index f29f7ff5..e866e80d 100644 --- a/windows/JackWinNamedPipeClientChannel.cpp +++ b/windows/JackWinNamedPipeClientChannel.cpp @@ -263,10 +263,10 @@ void JackWinNamedPipeClientChannel::SessionNotify(int refnum, const char* target 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::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 ); + for (std::list::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; } diff --git a/windows/JackWinNamedPipeServerChannel.cpp b/windows/JackWinNamedPipeServerChannel.cpp index fd5a8eda..8b3bbdc5 100644 --- a/windows/JackWinNamedPipeServerChannel.cpp +++ b/windows/JackWinNamedPipeServerChannel.cpp @@ -339,7 +339,6 @@ bool JackClientPipeThread::HandleRequest() case JackRequest::kSessionNotify: { jack_log("JackRequest::SessionNotify"); JackSessionNotifyRequest req; - JackSessionNotifyResult res; if (req.Read(fPipe) == 0) { fServer->GetEngine()->SessionNotify(req.fRefNum, req.fDst, req.fEventType, req.fPath, fPipe); }