Commit d09d8c3c authored by sletz's avatar sletz
Browse files

Add a string parameter to server ==> client notification, add a new InfoShutdown callback.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@3653 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 95047be5
......@@ -24,6 +24,10 @@ Paul Davis
---------------------------
Jackdmp changes log
---------------------------
2009-10-20 Stephane Letz <letz@grame.fr>
* Add a string parameter to server ==> client notification, add a new "InfoShutdown" callback.
2009-10-17 Stephane Letz <letz@grame.fr>
......
......@@ -72,6 +72,8 @@ extern "C"
EXPORT int jack_is_realtime (jack_client_t *client);
EXPORT void jack_on_shutdown (jack_client_t *client,
JackShutdownCallback shutdown_callback, void *arg);
EXPORT void jack_on_info_shutdown (jack_client_t *client,
JackInfoShutdownCallback shutdown_callback, void *arg);
EXPORT int jack_set_process_callback (jack_client_t *client,
JackProcessCallback process_callback,
void *arg);
......@@ -812,6 +814,7 @@ EXPORT void jack_on_shutdown(jack_client_t* ext_client, JackShutdownCallback cal
JackLibGlobals::CheckContext();
#endif
JackClient* client = (JackClient*)ext_client;
jack_error("jack_on_shutdown: deprecated, use jack_on_info_shutdown");
if (client == NULL) {
jack_error("jack_on_shutdown called with a NULL client");
} else {
......@@ -819,6 +822,19 @@ EXPORT void jack_on_shutdown(jack_client_t* ext_client, JackShutdownCallback cal
}
}
EXPORT void jack_on_info_shutdown(jack_client_t* ext_client, JackInfoShutdownCallback callback, void* arg)
{
#ifdef __CLIENTDEBUG__
JackLibGlobals::CheckContext();
#endif
JackClient* client = (JackClient*)ext_client;
if (client == NULL) {
jack_error("jack_on_info_shutdown called with a NULL client");
} else {
client->OnInfoShutdown(callback, arg);
}
}
EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
{
#ifdef __CLIENTDEBUG__
......
......@@ -49,6 +49,7 @@ JackClient::JackClient(JackSynchro* table):fThread(this)
fGraphOrder = NULL;
fXrun = NULL;
fShutdown = NULL;
fInfoShutdown = NULL;
fInit = NULL;
fBufferSize = NULL;
fClientRegistration = NULL;
......@@ -63,6 +64,7 @@ JackClient::JackClient(JackSynchro* table):fThread(this)
fGraphOrderArg = NULL;
fXrunArg = NULL;
fShutdownArg = NULL;
fInfoShutdownArg = NULL;
fInitArg = NULL;
fBufferSizeArg = NULL;
fFreewheelArg = NULL;
......@@ -132,12 +134,12 @@ void JackClient::SetupDriverSync(bool freewheel)
\brief Notification received from the server.
*/
int JackClient::ClientNotifyImp(int refnum, const char* name, int notify, int sync, int value1, int value2)
int JackClient::ClientNotifyImp(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2)
{
return 0;
}
int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2)
int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2)
{
int res = 0;
......@@ -145,11 +147,11 @@ int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync,
switch (notify) {
case kAddClient:
res = ClientNotifyImp(refnum, name, notify, sync, value1, value2);
res = ClientNotifyImp(refnum, name, notify, sync, message, value1, value2);
break;
case kRemoveClient:
res = ClientNotifyImp(refnum, name, notify, sync, value1, value2);
res = ClientNotifyImp(refnum, name, notify, sync, message, value1, value2);
break;
case kActivateClient:
......@@ -247,6 +249,12 @@ int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync,
if (fXrun)
res = fXrun(fXrunArg);
break;
case kShutDownCallback:
jack_log("JackClient::kShutDownCallback");
if (fInfoShutdown)
fInfoShutdown(message, fInfoShutdownArg);
break;
}
}
......@@ -582,7 +590,10 @@ void JackClient::ShutDown()
jack_log("ShutDown");
JackGlobals::fServerRunning = false;
if (fShutdown) {
if (fInfoShutdown) {
fInfoShutdown("JACK server has been closed", fInfoShutdownArg);
fInfoShutdown = NULL;
} else if (fShutdown) {
fShutdown(fShutdownArg);
fShutdown = NULL;
}
......@@ -772,6 +783,16 @@ void JackClient::OnShutdown(JackShutdownCallback callback, void *arg)
fShutdown = callback;
}
}
void JackClient::OnInfoShutdown(JackInfoShutdownCallback callback, void *arg)
{
if (IsActive()) {
jack_error("You cannot set callbacks on an active client");
} else {
fInfoShutdownArg = arg;
fInfoShutdown = callback;
}
}
int JackClient::SetProcessCallback(JackProcessCallback callback, void *arg)
{
......
......@@ -54,6 +54,7 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
JackGraphOrderCallback fGraphOrder;
JackXRunCallback fXrun;
JackShutdownCallback fShutdown;
JackInfoShutdownCallback fInfoShutdown;
JackThreadInitCallback fInit;
JackBufferSizeCallback fBufferSize;
JackSampleRateCallback fSampleRate;
......@@ -70,6 +71,7 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
void* fGraphOrderArg;
void* fXrunArg;
void* fShutdownArg;
void* fInfoShutdownArg;
void* fInitArg;
void* fBufferSizeArg;
void* fSampleRateArg;
......@@ -95,7 +97,7 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
void CallSyncCallback();
void CallTimebaseCallback();
virtual int ClientNotifyImp(int refnum, const char* name, int notify, int sync, int value1, int value);
virtual int ClientNotifyImp(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value);
inline void DummyCycle();
inline void ExecuteThread();
......@@ -123,7 +125,7 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
virtual JackEngineControl* GetEngineControl() const = 0;
// Notifications
virtual int ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2);
virtual int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
virtual int Activate();
virtual int Deactivate();
......@@ -159,6 +161,7 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
// Callbacks
virtual void OnShutdown(JackShutdownCallback callback, void *arg);
virtual void OnInfoShutdown(JackInfoShutdownCallback callback, void *arg);
virtual int SetProcessCallback(JackProcessCallback callback, void* arg);
virtual int SetXRunCallback(JackXRunCallback callback, void* arg);
virtual int SetInitCallback(JackThreadInitCallback callback, void* arg);
......
......@@ -44,7 +44,7 @@ class SERVER_EXPORT JackClientInterface
virtual int Close() = 0;
virtual int ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2) = 0;
virtual int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2) = 0;
virtual JackClientControl* GetClientControl() const = 0;
};
......
......@@ -32,6 +32,7 @@
#define JACK_PORT_TYPE_SIZE 32
#define JACK_CLIENT_NAME_SIZE 64
#define JACK_MESSAGE_SIZE 512
#ifndef PORT_NUM
#define PORT_NUM 1024
......
......@@ -139,10 +139,10 @@ JackEngineControl* JackDebugClient::GetEngineControl() const
\brief Notification received from the server.
*/
int JackDebugClient::ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2)
int JackDebugClient::ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2)
{
CheckClient();
return fClient->ClientNotify( refnum, name, notify, sync, value1, value2);
return fClient->ClientNotify( refnum, name, notify, sync, message, value1, value2);
}
int JackDebugClient::Activate()
......@@ -416,6 +416,12 @@ void JackDebugClient::OnShutdown(JackShutdownCallback callback, void *arg)
fClient->OnShutdown(callback, arg);
}
void JackDebugClient::OnInfoShutdown(JackInfoShutdownCallback callback, void *arg)
{
CheckClient();
fClient->OnInfoShutdown(callback, arg);
}
int JackDebugClient::TimeCallback(jack_nframes_t nframes, void *arg)
{
JackDebugClient* client = (JackDebugClient*)arg;
......
......@@ -75,7 +75,7 @@ class JackDebugClient : public JackClient
virtual JackEngineControl* GetEngineControl() const;
// Notifications
int ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2);
int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
int Activate();
int Deactivate();
......@@ -110,6 +110,7 @@ class JackDebugClient : public JackClient
// Callbacks
void OnShutdown(JackShutdownCallback callback, void *arg);
void OnInfoShutdown(JackInfoShutdownCallback callback, void *arg);
int SetProcessCallback(JackProcessCallback callback, void* arg);
int SetXRunCallback(JackXRunCallback callback, void* arg);
int SetInitCallback(JackThreadInitCallback callback, void* arg);
......
......@@ -190,7 +190,7 @@ void JackDriver::SetupDriverSync(int ref, bool freewheel)
}
}
int JackDriver::ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2)
int JackDriver::ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2)
{
switch (notify) {
......
......@@ -199,7 +199,7 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface
virtual int SetBufferSize(jack_nframes_t buffer_size);
virtual int SetSampleRate(jack_nframes_t sample_rate);
virtual int ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2);
virtual int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
virtual JackClientControl* GetClientControl() const;
virtual bool IsRealTime() const;
......
......@@ -203,7 +203,7 @@ void JackEngine::CheckXRun(jack_time_t callback_usecs) // REVOIR les conditions
// Notifications
//---------------
void JackEngine::NotifyClient(int refnum, int event, int sync, int value1, int value2)
void JackEngine::NotifyClient(int refnum, int event, int sync, const char* message, int value1, int value2)
{
JackClientInterface* client = fClientTable[refnum];
......@@ -211,20 +211,20 @@ void JackEngine::NotifyClient(int refnum, int event, int sync, int value1, int v
if (!client) {
jack_log("JackEngine::NotifyClient: client not available anymore");
} else if (client->GetClientControl()->fCallback[event]) {
if (client->ClientNotify(refnum, client->GetClientControl()->fName, event, sync, value1, value2) < 0)
if (client->ClientNotify(refnum, client->GetClientControl()->fName, event, sync, message, value1, value2) < 0)
jack_error("NotifyClient fails name = %s event = %ld val1 = %ld val2 = %ld", client->GetClientControl()->fName, event, value1, value2);
} else {
jack_log("JackEngine::NotifyClient: no callback for event = %ld", event);
}
}
void JackEngine::NotifyClients(int event, int sync, int value1, int value2)
void JackEngine::NotifyClients(int event, int sync, const char* message, int value1, int value2)
{
for (int i = 0; i < CLIENT_NUM; i++) {
JackClientInterface* client = fClientTable[i];
if (client) {
if (client->GetClientControl()->fCallback[event]) {
if (client->ClientNotify(i, client->GetClientControl()->fName, event, sync, value1, value2) < 0)
if (client->ClientNotify(i, client->GetClientControl()->fName, event, sync, message, value1, value2) < 0)
jack_error("NotifyClient fails name = %s event = %ld val1 = %ld val2 = %ld", client->GetClientControl()->fName, event, value1, value2);
} else {
jack_log("JackEngine::NotifyClients: no callback for event = %ld", event);
......@@ -240,11 +240,11 @@ int JackEngine::NotifyAddClient(JackClientInterface* new_client, const char* nam
for (int i = 0; i < CLIENT_NUM; i++) {
JackClientInterface* old_client = fClientTable[i];
if (old_client) {
if (old_client->ClientNotify(refnum, name, kAddClient, true, 0, 0) < 0) {
if (old_client->ClientNotify(refnum, name, kAddClient, true, "", 0, 0) < 0) {
jack_error("NotifyAddClient old_client fails name = %s", old_client->GetClientControl()->fName);
return -1;
}
if (new_client->ClientNotify(i, old_client->GetClientControl()->fName, kAddClient, true, 0, 0) < 0) {
if (new_client->ClientNotify(i, old_client->GetClientControl()->fName, kAddClient, true, "", 0, 0) < 0) {
jack_error("NotifyAddClient new_client fails name = %s", name);
return -1;
}
......@@ -260,7 +260,7 @@ void JackEngine::NotifyRemoveClient(const char* name, int refnum)
for (int i = 0; i < CLIENT_NUM; i++) {
JackClientInterface* client = fClientTable[i];
if (client) {
client->ClientNotify(refnum, name, kRemoveClient, true, 0, 0);
client->ClientNotify(refnum, name, kRemoveClient, true, "",0, 0);
}
}
}
......@@ -277,51 +277,51 @@ void JackEngine::NotifyXRun(jack_time_t callback_usecs, float delayed_usecs)
void JackEngine::NotifyXRun(int refnum)
{
if (refnum == ALL_CLIENTS) {
NotifyClients(kXRunCallback, false, 0, 0);
NotifyClients(kXRunCallback, false, "", 0, 0);
} else {
NotifyClient(refnum, kXRunCallback, false, 0, 0);
NotifyClient(refnum, kXRunCallback, false, "", 0, 0);
}
}
void JackEngine::NotifyGraphReorder()
{
NotifyClients(kGraphOrderCallback, false, 0, 0);
NotifyClients(kGraphOrderCallback, false, "", 0, 0);
}
void JackEngine::NotifyBufferSize(jack_nframes_t buffer_size)
{
NotifyClients(kBufferSizeCallback, true, buffer_size, 0);
NotifyClients(kBufferSizeCallback, true, "", buffer_size, 0);
}
void JackEngine::NotifySampleRate(jack_nframes_t sample_rate)
{
NotifyClients(kSampleRateCallback, true, sample_rate, 0);
NotifyClients(kSampleRateCallback, true, "", sample_rate, 0);
}
void JackEngine::NotifyFreewheel(bool onoff)
{
fEngineControl->fRealTime = !onoff;
NotifyClients((onoff ? kStartFreewheelCallback : kStopFreewheelCallback), true, 0, 0);
NotifyClients((onoff ? kStartFreewheelCallback : kStopFreewheelCallback), true, "", 0, 0);
}
void JackEngine::NotifyPortRegistation(jack_port_id_t port_index, bool onoff)
{
NotifyClients((onoff ? kPortRegistrationOnCallback : kPortRegistrationOffCallback), false, port_index, 0);
NotifyClients((onoff ? kPortRegistrationOnCallback : kPortRegistrationOffCallback), false, "", port_index, 0);
}
void JackEngine::NotifyPortRename(jack_port_id_t port)
{
NotifyClients(kPortRenameCallback, false, port, 0);
NotifyClients(kPortRenameCallback, false, "", port, 0);
}
void JackEngine::NotifyPortConnect(jack_port_id_t src, jack_port_id_t dst, bool onoff)
{
NotifyClients((onoff ? kPortConnectCallback : kPortDisconnectCallback), false, src, dst);
NotifyClients((onoff ? kPortConnectCallback : kPortDisconnectCallback), false, "", src, dst);
}
void JackEngine::NotifyActivate(int refnum)
{
NotifyClient(refnum, kActivateClient, true, 0, 0);
NotifyClient(refnum, kActivateClient, true, "", 0, 0);
}
//----------------------------
......
......@@ -64,8 +64,9 @@ class SERVER_EXPORT JackEngine
int AllocateRefnum();
void ReleaseRefnum(int ref);
void NotifyClient(int refnum, int event, int sync, int value1, int value2);
void NotifyClients(int event, int sync, int value1, int value2);
void NotifyClient(int refnum, int event, int sync, const char* message, int value1, int value2);
void NotifyClients(int event, int sync, const char* message, int value1, int value2);
void NotifyPortRegistation(jack_port_id_t port_index, bool onoff);
void NotifyPortConnect(jack_port_id_t src, jack_port_id_t dst, bool onoff);
void NotifyPortRename(jack_port_id_t src);
......
......@@ -33,11 +33,11 @@ JackExternalClient::JackExternalClient(): fClientControl(NULL)
JackExternalClient::~JackExternalClient()
{}
int JackExternalClient::ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2)
int JackExternalClient::ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2)
{
int result = -1;
jack_log("JackExternalClient::ClientNotify ref = %ld name = %s notify = %ld", refnum, name, notify);
fChannel.ClientNotify(refnum, name, notify, sync, value1, value2, &result);
fChannel.ClientNotify(refnum, name, notify, sync, message, value1, value2, &result);
return result;
}
......
......@@ -49,7 +49,7 @@ class JackExternalClient : public JackClientInterface
int Open(const char* name, int pid, int refnum, int* shared_client);
int Close();
int ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2);
int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
JackClientControl* GetClientControl() const;
};
......
......@@ -128,7 +128,7 @@ error:
// Notifications received from the server
// TODO this should be done once for all clients in the process, when a shared notification channel
// will be shared by all clients...
int JackLibClient::ClientNotifyImp(int refnum, const char* name, int notify, int sync, int value1, int value2)
int JackLibClient::ClientNotifyImp(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2)
{
int res = 0;
......
......@@ -46,7 +46,7 @@ class JackLibClient : public JackClient
int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status);
int ClientNotifyImp(int refnum, const char* name, int notify, int sync, int value1, int value2);
int ClientNotifyImp(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
JackGraphManager* GetGraphManager() const;
JackEngineControl* GetEngineControl() const;
......
......@@ -43,6 +43,7 @@ enum NotificationType {
kPortDisconnectCallback = 12,
kPortRenameCallback = 13,
kRealTimeCallback = 14,
kShutDownCallback = 15,
kMaxNotification
};
......
......@@ -1079,13 +1079,15 @@ struct JackClientNotification
int fValue1;
int fValue2;
int fSync;
char fMessage[JACK_MESSAGE_SIZE + 1];
JackClientNotification(): fNotify(-1), fValue1(-1), fValue2(-1)
{}
JackClientNotification(const char* name, int refnum, int notify, int sync, int value1, int value2)
JackClientNotification(const char* name, int refnum, int notify, int sync, const char* message, int value1, int value2)
: fRefNum(refnum), fNotify(notify), fValue1(value1), fValue2(value2), fSync(sync)
{
snprintf(fName, sizeof(fName), "%s", name);
snprintf(fMessage, sizeof(fMessage), "%s", message);
}
int Read(JackChannelTransaction* trans)
......@@ -1096,6 +1098,7 @@ struct JackClientNotification
CheckRes(trans->Read(&fValue1, sizeof(int)));
CheckRes(trans->Read(&fValue2, sizeof(int)));
CheckRes(trans->Read(&fSync, sizeof(int)));
CheckRes(trans->Read(&fMessage, JACK_MESSAGE_SIZE + 1));
return 0;
}
......@@ -1107,6 +1110,7 @@ struct JackClientNotification
CheckRes(trans->Write(&fValue1, sizeof(int)));
CheckRes(trans->Write(&fValue2, sizeof(int)));
CheckRes(trans->Write(&fSync, sizeof(int)));
CheckRes(trans->Write(&fMessage, JACK_MESSAGE_SIZE + 1));
return 0;
}
......
......@@ -137,9 +137,9 @@ std::list<JackDriverInterface*> JackThreadedDriver::GetSlaves()
return fDriver->GetSlaves();
}
int JackThreadedDriver::ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2)
int JackThreadedDriver::ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2)
{
return fDriver->ClientNotify(refnum, name, notify, sync, value1, value2);
return fDriver->ClientNotify(refnum, name, notify, sync, message, value1, value2);
}
JackClientControl* JackThreadedDriver::GetClientControl() const
......
......@@ -94,7 +94,7 @@ class SERVER_EXPORT JackThreadedDriver : public JackDriverClientInterface, publi
virtual std::list<JackDriverInterface*> GetSlaves();
virtual int ProcessSlaves();
virtual int ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2);
virtual int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
virtual JackClientControl* GetClientControl() const;
virtual bool IsRealTime() const;
......
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