Commit 1274ff1d authored by sletz's avatar sletz
Browse files

Add new jack_set_port_rename_callback API, jack_port_set_name is now a server...

Add new jack_set_port_rename_callback API, jack_port_set_name is now a server request that call port rename callbacks.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2857 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 4309c5ad
......@@ -22,6 +22,10 @@ Florian Faber
Jackdmp changes log
---------------------------
2008-09-01 Stephane Letz <letz@grame.fr>
* Add new jack_set_port_rename_callback API, jack_port_set_name is now a server request that call port rename callbacks.
2008-08-26 Stephane Letz <letz@grame.fr>
* Better parameter handling in JackCoreAudioAdapter.
......
......@@ -113,6 +113,9 @@ extern "C"
EXPORT int jack_set_port_connect_callback (jack_client_t *,
JackPortConnectCallback
connect_callback, void *arg);
EXPORT int jack_set_port_rename_callback (jack_client_t *,
JackPortRenameCallback
rename_callback, void *arg);
EXPORT int jack_set_graph_order_callback (jack_client_t *,
JackGraphOrderCallback graph_callback,
void *);
......@@ -552,7 +555,13 @@ EXPORT int jack_port_set_name(jack_port_t* port, const char* name)
return -1;
} else {
JackGraphManager* manager = GetGraphManager();
return (manager ? manager->GetPort(myport)->SetName(name) : -1);
if (manager) {
JackClient* client = JackClient::fClientTable[manager->GetPort(myport)->GetRefNum()];
assert(client);
return client->PortRename(myport, name);
} else {
return -1;
}
}
}
......@@ -886,6 +895,20 @@ EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortCon
}
}
EXPORT int jack_set_port_rename_callback(jack_client_t* ext_client, JackPortRenameCallback rename_callback, void* arg)
{
#ifdef __CLIENTDEBUG__
JackLibGlobals::CheckContext();
#endif
JackClient* client = (JackClient*)ext_client;
if (client == NULL) {
jack_error("jack_set_port_rename_callback called with a NULL client");
return -1;
} else {
return client->SetPortRenameCallback(rename_callback, arg);
}
}
EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
{
#ifdef __CLIENTDEBUG__
......
......@@ -100,6 +100,8 @@ class JackClientChannelInterface
{}
virtual void PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
{}
virtual void PortRename(int refnum, jack_port_id_t port, const char* name, int* result)
{}
virtual void SetBufferSize(jack_nframes_t buffer_size, int* result)
{}
......
......@@ -41,6 +41,8 @@ using namespace std;
namespace Jack
{
JackClient* JackClient::fClientTable[CLIENT_NUM] = {};
#define IsRealTime() ((fProcess != NULL) | (fThreadFun != NULL) | (fSync != NULL) | (fTimebase != NULL))
JackClient::JackClient():fThread(this)
......@@ -59,6 +61,7 @@ JackClient::JackClient(JackSynchro* table):fThread(this)
fFreewheel = NULL;
fPortRegistration = NULL;
fPortConnect = NULL;
fPortRename = NULL;
fTimebase = NULL;
fSync = NULL;
fThreadFun = NULL;
......@@ -72,6 +75,7 @@ JackClient::JackClient(JackSynchro* table):fThread(this)
fClientRegistrationArg = NULL;
fPortRegistrationArg = NULL;
fPortConnectArg = NULL;
fPortRenameArg = NULL;
fSyncArg = NULL;
fTimebaseArg = NULL;
fThreadFunArg = NULL;
......@@ -97,6 +101,7 @@ int JackClient::Close()
fChannel->Close();
fSynchroTable[GetClientControl()->fRefNum].Disconnect();
fClientTable[GetClientControl()->fRefNum] = NULL;
return result;
}
......@@ -237,6 +242,12 @@ int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync,
if (fPortConnect)
fPortConnect(value1, value2, 0, fPortConnectArg);
break;
case kPortRenameCallback:
jack_log("JackClient::kPortRenameCallback src = %ld dst = %ld", value1, value2);
if (fPortRename)
fPortRename(value1, GetGraphManager()->GetPort(value1)->GetName(), fPortRenameArg);
break;
case kXRunCallback:
jack_log("JackClient::kXRunCallback");
......@@ -554,6 +565,13 @@ int JackClient::PortIsMine(jack_port_id_t port_index)
return GetClientControl()->fRefNum == port->GetRefNum();
}
int JackClient::PortRename(jack_port_id_t port_index, const char* name)
{
int result = -1;
fChannel->PortRename(GetClientControl()->fRefNum, port_index, name, &result);
return result;
}
//--------------------
// Context management
//--------------------
......@@ -880,6 +898,19 @@ int JackClient::SetPortConnectCallback(JackPortConnectCallback callback, void *a
}
}
int JackClient::SetPortRenameCallback(JackPortRenameCallback callback, void *arg)
{
if (IsActive()) {
jack_error("You cannot set callbacks on an active client");
return -1;
} else {
GetClientControl()->fCallback[kPortRenameCallback] = (callback != NULL);
fPortRenameArg = arg;
fPortRename = callback;
return 0;
}
}
int JackClient::SetProcessThread(JackThreadCallback fun, void *arg)
{
if (IsActive()) {
......
......@@ -65,6 +65,7 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
JackFreewheelCallback fFreewheel;
JackPortRegistrationCallback fPortRegistration;
JackPortConnectCallback fPortConnect;
JackPortRenameCallback fPortRename;
JackTimebaseCallback fTimebase;
JackSyncCallback fSync;
JackThreadCallback fThreadFun;
......@@ -80,6 +81,7 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
void* fFreewheelArg;
void* fPortRegistrationArg;
void* fPortConnectArg;
void* fPortRenameArg;
void* fTimebaseArg;
void* fSyncArg;
void* fThreadFunArg;
......@@ -142,6 +144,8 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
virtual int PortDisconnect(jack_port_id_t src);
virtual int PortIsMine(jack_port_id_t port_index);
virtual int PortRename(jack_port_id_t port_index, const char* name);
// Transport
virtual int ReleaseTimebase();
......@@ -167,6 +171,7 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
virtual int SetFreewheelCallback(JackFreewheelCallback callback, void* arg);
virtual int SetPortRegistrationCallback(JackPortRegistrationCallback callback, void* arg);
virtual int SetPortConnectCallback(JackPortConnectCallback callback, void *arg);
virtual int SetPortRenameCallback(JackPortRenameCallback callback, void *arg);
// Internal clients
virtual char* GetInternalClientName(int ref);
......@@ -184,6 +189,8 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
// JackRunnableInterface interface
bool Init();
bool Execute();
static JackClient* fClientTable[CLIENT_NUM];
};
......
......@@ -488,6 +488,12 @@ int JackDebugClient::SetPortConnectCallback(JackPortConnectCallback callback, vo
return fClient->SetPortConnectCallback(callback, arg);
}
int JackDebugClient::SetPortRenameCallback(JackPortRenameCallback callback, void *arg)
{
CheckClient();
return fClient->SetPortRenameCallback(callback, arg);
}
JackClientControl* JackDebugClient::GetClientControl() const
{
CheckClient();
......
......@@ -119,6 +119,7 @@ class JackDebugClient : public JackClient
int SetFreewheelCallback(JackFreewheelCallback callback, void* arg);
int SetPortRegistrationCallback(JackPortRegistrationCallback callback, void* arg);
int SetPortConnectCallback(JackPortConnectCallback callback, void *arg);
int SetPortRenameCallback(JackPortRenameCallback callback, void *arg);
// Internal clients
char* GetInternalClientName(int ref);
......
......@@ -319,6 +319,11 @@ void JackEngine::NotifyPortRegistation(jack_port_id_t port_index, bool onoff)
NotifyClients((onoff ? kPortRegistrationOnCallback : kPortRegistrationOffCallback), false, port_index, 0);
}
void JackEngine::NotifyPortRename(jack_port_id_t port)
{
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);
......@@ -826,6 +831,15 @@ int JackEngine::PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t ds
}
}
int JackEngine::PortRename(int refnum, jack_port_id_t port, const char* name)
{
if (fGraphManager->GetPort(port)->SetName(name) == 0) {
NotifyPortRename(port);
return 0;
} else {
return -1;
}
}
} // end of namespace
......@@ -69,6 +69,7 @@ class EXPORT JackEngine
void NotifyClients(int event, int sync, 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);
void NotifyActivate(int refnum);
public:
......@@ -106,6 +107,8 @@ class EXPORT JackEngine
int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst);
int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst);
int PortRename(int refnum, jack_port_id_t port, const char* name);
// Graph
bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end);
......
......@@ -147,6 +147,7 @@ int JackInternalClient::Open(const char* server_name, const char* name, jack_opt
}
SetupDriverSync(false);
fClientTable[GetClientControl()->fRefNum] = this;
return 0;
error:
......
......@@ -117,6 +117,7 @@ int JackLibClient::Open(const char* server_name, const char* name, jack_options_
goto error;
}
fClientTable[GetClientControl()->fRefNum] = this;
jack_log("JackLibClient::Open name = %s refnum = %ld", name_res, GetClientControl()->fRefNum);
return 0;
......
......@@ -144,6 +144,12 @@ class EXPORT JackLockedEngine : public JackLockAble
JackLock lock(this);
return fEngine.PortDisconnect(refnum, src, dst);
}
int PortRename(int refnum, jack_port_id_t port, const char* name)
{
JackLock lock(this);
return fEngine.PortRename(refnum, port, name);
}
// Graph
bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end)
......
......@@ -41,7 +41,8 @@ enum NotificationType {
kPortRegistrationOffCallback = 10,
kPortConnectCallback = 11,
kPortDisconnectCallback = 12,
kRealTimeCallback = 13,
kPortRenameCallback = 13,
kRealTimeCallback = 14,
kMaxNotification
};
......
......@@ -64,7 +64,8 @@ struct JackRequest
kInternalClientHandle = 28,
kInternalClientLoad = 29,
kInternalClientUnload = 30,
kNotification = 31
kPortRename = 31,
kNotification = 32
};
RequestType fType;
......@@ -590,6 +591,44 @@ struct JackPortDisconnectRequest : public JackRequest
}
};
/*!
\brief PortRename request.
*/
struct JackPortRenameRequest : public JackRequest
{
int fRefNum;
jack_port_id_t fPort;
char fName[JACK_PORT_NAME_SIZE + 1];
JackPortRenameRequest()
{}
JackPortRenameRequest(int refnum, jack_port_id_t port, const char* name)
: JackRequest(JackRequest::kPortRename), fRefNum(refnum), fPort(port)
{
strcpy(fName, name);
}
int Read(JackChannelTransaction* trans)
{
CheckRes(trans->Read(&fRefNum, sizeof(int)));
CheckRes(trans->Read(&fPort, sizeof(jack_port_id_t)));
CheckRes(trans->Read(&fName, JACK_PORT_NAME_SIZE + 1));
return 0;
}
int Write(JackChannelTransaction* trans)
{
CheckRes(JackRequest::Write(trans));
CheckRes(trans->Write(&fRefNum, sizeof(int)));
CheckRes(trans->Write(&fPort, sizeof(jack_port_id_t)));
CheckRes(trans->Write(&fName, JACK_PORT_NAME_SIZE + 1));
return 0;
}
};
/*!
\brief SetBufferSize request.
*/
......
......@@ -229,6 +229,13 @@ void JackSocketClientChannel::PortDisconnect(int refnum, jack_port_id_t src, jac
ServerSyncCall(&req, &res, result);
}
void JackSocketClientChannel::PortRename(int refnum, jack_port_id_t port, const char* name, int* result)
{
JackPortRenameRequest req(refnum, port, name);
JackResult res;
ServerSyncCall(&req, &res, result);
}
void JackSocketClientChannel::SetBufferSize(jack_nframes_t buffer_size, int* result)
{
JackSetBufferSizeRequest req(buffer_size);
......
......@@ -77,6 +77,8 @@ class JackSocketClientChannel : public detail::JackClientChannelInterface, publi
void PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result);
void PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result);
void PortRename(int refnum, jack_port_id_t port, const char* name, int* result);
void SetBufferSize(jack_nframes_t buffer_size, int* result);
void SetFreewheel(int onoff, int* result);
......
......@@ -286,6 +286,17 @@ bool JackSocketServerChannel::HandleRequest(int fd)
jack_error("JackRequest::DisconnectPorts write error ref = %d", req.fRefNum);
break;
}
case JackRequest::kPortRename: {
jack_log("JackRequest::kPortRename");
JackPortRenameRequest req;
JackResult res;
if (req.Read(socket) == 0)
res.fResult = fServer->GetEngine()->PortRename(req.fRefNum, req.fPort, req.fName);
if (res.Write(socket) < 0)
jack_error("JackRequest::PortRename write error ref = %d", req.fRefNum);
break;
}
case JackRequest::kSetBufferSize: {
jack_log("JackRequest::SetBufferSize");
......
......@@ -437,6 +437,23 @@ extern "C"
JackPortConnectCallback
connect_callback, void *arg);
/**
* Tell the JACK server to call @a rename_callback whenever a
* port is renamed, passing @a arg as a parameter.
*
* All "notification events" are received in a seperated non RT thread,
* the code in the supplied function does not need to be
* suitable for real-time execution.
*
* NOTE: this function cannot be called while the client is activated
* (after jack_activate has been called.)
*
* @return 0 on success, otherwise a non-zero error code
*/
int jack_set_port_rename_callback (jack_client_t *,
JackPortRenameCallback
rename_callback, void *arg);
/**
* Tell the JACK server to call @a graph_callback whenever the
* processing graph is reordered, passing @a arg as a parameter.
......
......@@ -219,6 +219,18 @@ typedef void (*JackClientRegistrationCallback)(const char* name, int val, void *
*/
typedef void (*JackPortConnectCallback)(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
/**
* Prototype for the client supplied function that is called
* whenever the port name has been changed.
*
* @param port the port that has been renamed
* @param new_name the new name
* @param arg pointer to a client supplied structure
*
* @return zero on success, non-zero on error
*/
typedef int (*JackPortRenameCallback)(jack_port_id_t port, const char* new_name, void *arg);
/**
* Prototype for the client supplied function that is called
* whenever jackd starts or stops freewheeling.
......@@ -228,7 +240,6 @@ typedef void (*JackPortConnectCallback)(jack_port_id_t a, jack_port_id_t b, int
*/
typedef void (*JackFreewheelCallback)(int starting, void *arg);
/**
* Used for the type argument of jack_port_register() for default
* audio ports and midi ports.
......
......@@ -139,6 +139,15 @@ rpc_type server_rpc_jack_port_disconnect(mach_port_t private_port, int refnum, i
return KERN_SUCCESS;
}
rpc_type server_rpc_jack_port_rename(mach_port_t private_port, int refnum, int port, client_port_name_t name, int* result)
{
jack_log("server_rpc_jack_port_rename");
JackMachServerChannel* channel = JackMachServerChannel::fPortTable[private_port];
assert(channel);
*result = channel->GetEngine()->PortRename(refnum, port, name);
return KERN_SUCCESS;
}
//------------------------
// Buffer size, freewheel
//------------------------
......
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