From d9064f5866f011cafb297873cc107db86b414238 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Sun, 7 Aug 2011 05:17:16 +0300 Subject: [PATCH] Implement session api for internal clients --- common/JackEngine.cpp | 18 +++++++++++++++--- common/JackEngine.h | 2 +- common/JackInternalClientChannel.h | 12 ++++++++++-- common/JackLockedEngine.h | 4 ++-- common/JackRequest.h | 26 ++++++++++++++++++++++++-- posix/JackSocketServerChannel.cpp | 2 +- windows/JackWinNamedPipeServerChannel.cpp | 2 +- 7 files changed, 54 insertions(+), 12 deletions(-) diff --git a/common/JackEngine.cpp b/common/JackEngine.cpp index e4342f81..a1b0a9d2 100644 --- a/common/JackEngine.cpp +++ b/common/JackEngine.cpp @@ -932,12 +932,15 @@ int JackEngine::PortRename(int refnum, jack_port_id_t port, const char* name) // Session management //-------------------- -void JackEngine::SessionNotify(int refnum, const char *target, jack_session_event_type_t type, const char *path, JackChannelTransaction *socket) +void JackEngine::SessionNotify(int refnum, const char *target, jack_session_event_type_t type, const char *path, JackChannelTransaction *socket, JackSessionNotifyResult** result) { if (fSessionPendingReplies != 0) { JackSessionNotifyResult res(-1); res.Write(socket); jack_log("JackEngine::SessionNotify ... busy"); + if (result != NULL) { + *result = NULL; + } return; } @@ -982,9 +985,15 @@ void JackEngine::SessionNotify(int refnum, const char *target, jack_session_even } } + if (result != NULL) { + *result = fSessionResult; + } + if (fSessionPendingReplies == 0) { fSessionResult->Write(socket); - delete fSessionResult; + if (result == NULL) { + delete fSessionResult; + } fSessionResult = NULL; } else { fSessionTransaction = socket; @@ -1004,7 +1013,10 @@ void JackEngine::SessionReply(int refnum) if (fSessionPendingReplies == 0) { fSessionResult->Write(fSessionTransaction); - delete fSessionResult; + if (fSessionTransaction != NULL) + { + delete fSessionResult; + } fSessionResult = NULL; } } diff --git a/common/JackEngine.h b/common/JackEngine.h index 179d7e07..ca38089e 100644 --- a/common/JackEngine.h +++ b/common/JackEngine.h @@ -145,7 +145,7 @@ class SERVER_EXPORT JackEngine : public JackLockAble void NotifyQuit(); // Session management - void SessionNotify(int refnum, const char *target, jack_session_event_type_t type, const char *path, JackChannelTransaction *socket); + void SessionNotify(int refnum, const char *target, jack_session_event_type_t type, const char *path, JackChannelTransaction *socket, JackSessionNotifyResult** result); void SessionReply(int refnum); void GetUUIDForClientName(const char *client_name, char *uuid_res, int *result); diff --git a/common/JackInternalClientChannel.h b/common/JackInternalClientChannel.h index 69588a99..e2ead4b7 100644 --- a/common/JackInternalClientChannel.h +++ b/common/JackInternalClientChannel.h @@ -146,8 +146,16 @@ class JackInternalClientChannel : public detail::JackClientChannelInterface void SessionNotify(int refnum, const char *target, jack_session_event_type_t type, const char *path, jack_session_command_t** result) { - //*result = fEngine->SessionNotify(refnum, target, type, path, result); - // TODO + JackSessionNotifyResult* res; + fEngine->SessionNotify(refnum, target, type, path, NULL, &res); + if (res == NULL) + { + *result = NULL; + return; + } + + *result = res->GetCommands(); + delete(res); } void SessionReply(int refnum, int* result) diff --git a/common/JackLockedEngine.h b/common/JackLockedEngine.h index d96e8678..bdb71ed0 100644 --- a/common/JackLockedEngine.h +++ b/common/JackLockedEngine.h @@ -325,11 +325,11 @@ class SERVER_EXPORT JackLockedEngine CATCH_EXCEPTION } - void SessionNotify(int refnum, const char* target, jack_session_event_type_t type, const char *path, JackChannelTransaction *socket) + void SessionNotify(int refnum, const char* target, jack_session_event_type_t type, const char *path, JackChannelTransaction *socket, JackSessionNotifyResult** result) { TRY_CALL JackLock lock(&fEngine); - fEngine.SessionNotify(refnum, target, type, path, socket); + fEngine.SessionNotify(refnum, target, type, path, socket, result); CATCH_EXCEPTION } diff --git a/common/JackRequest.h b/common/JackRequest.h index 95a1b7e7..bc70d38c 100644 --- a/common/JackRequest.h +++ b/common/JackRequest.h @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "JackConstants.h" #include "JackPlatformPlug.h" +#include "JackTime.h" #include "types.h" #include #include @@ -1147,15 +1148,21 @@ struct JackSessionNotifyResult : public JackResult { std::list fCommandList; + bool fDone; - JackSessionNotifyResult(): JackResult() + JackSessionNotifyResult(): JackResult(), fDone(false) {} JackSessionNotifyResult(int32_t result) - : JackResult(result) + : JackResult(result), fDone(false) {} int Read(JackChannelTransaction* trans) { + if (trans == NULL) + { + return 0; + } + CheckRes(JackResult::Read(trans)); while (true) { JackSessionCommand buffer; @@ -1170,11 +1177,20 @@ struct JackSessionNotifyResult : public JackResult fCommandList.push_back(buffer); } + + fDone = true; + return 0; } int Write(JackChannelTransaction* trans) { + if (trans == NULL) + { + fDone = true; + return 0; + } + char terminator[JACK_UUID_SIZE]; terminator[0] = '\0'; @@ -1191,6 +1207,12 @@ struct JackSessionNotifyResult : public JackResult jack_session_command_t* GetCommands() { + /* TODO: some kind of signal should be used instead */ + while (!fDone) + { + JackSleep(50000); /* 50 ms */ + } + jack_session_command_t* session_command = (jack_session_command_t *)malloc(sizeof(jack_session_command_t) * (fCommandList.size() + 1)); int i = 0; diff --git a/posix/JackSocketServerChannel.cpp b/posix/JackSocketServerChannel.cpp index 73a16b16..50480ee7 100644 --- a/posix/JackSocketServerChannel.cpp +++ b/posix/JackSocketServerChannel.cpp @@ -430,7 +430,7 @@ bool JackSocketServerChannel::HandleRequest(int fd) jack_log("JackRequest::SessionNotify"); JackSessionNotifyRequest req; if (req.Read(socket) == 0) { - fServer->GetEngine()->SessionNotify(req.fRefNum, req.fDst, req.fEventType, req.fPath, socket); + fServer->GetEngine()->SessionNotify(req.fRefNum, req.fDst, req.fEventType, req.fPath, socket, NULL); } break; } diff --git a/windows/JackWinNamedPipeServerChannel.cpp b/windows/JackWinNamedPipeServerChannel.cpp index b557a33c..194e68ac 100644 --- a/windows/JackWinNamedPipeServerChannel.cpp +++ b/windows/JackWinNamedPipeServerChannel.cpp @@ -343,7 +343,7 @@ bool JackClientPipeThread::HandleRequest() jack_log("JackRequest::SessionNotify"); JackSessionNotifyRequest req; if (req.Read(fPipe) == 0) { - fServer->GetEngine()->SessionNotify(req.fRefNum, req.fDst, req.fEventType, req.fPath, fPipe); + fServer->GetEngine()->SessionNotify(req.fRefNum, req.fDst, req.fEventType, req.fPath, fPipe, NULL); } res.Write(fPipe); break; -- 2.11.4.GIT