Commit d9064f58 authored by Nedko Arnaudov's avatar Nedko Arnaudov
Browse files

Implement session api for internal clients

parent 1e962ef0
......@@ -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;
}
}
......
......@@ -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);
......
......@@ -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)
......
......@@ -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
}
......
......@@ -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 <string.h>
#include <stdio.h>
......@@ -1147,15 +1148,21 @@ struct JackSessionNotifyResult : public JackResult
{
std::list<JackSessionCommand> 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;
......
......@@ -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;
}
......
......@@ -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;
......
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