From c8cac65cadfbac03c5a86e39d7400624ca2197bc Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Mon, 10 Mar 2014 03:31:23 +0200 Subject: [PATCH] remove the JackSelfConnectMode enum type It was introduced before the parameter was actually exposed. The parameter is exposed through a char type in both jackd and jackdbus, thus a mappnig was required. This changeset removes the enum and makes the code simpler at the expense of not allowing arbitrary chars as values. As it is exposed and used in sessions, it is not arbitrary anyway. --- common/JackConstants.h | 2 +- common/JackControlAPI.cpp | 25 +---------- common/JackEngine.cpp | 83 +++++++++++++----------------------- common/JackEngine.h | 4 +- common/JackLockedEngine.h | 2 +- common/JackServer.cpp | 2 +- common/JackServer.h | 2 +- common/JackServerGlobals.cpp | 2 +- common/JackServerGlobals.h | 2 +- common/JackTypes.h | 10 ----- 10 files changed, 40 insertions(+), 94 deletions(-) diff --git a/common/JackConstants.h b/common/JackConstants.h index 67b60c66..98d031a4 100644 --- a/common/JackConstants.h +++ b/common/JackConstants.h @@ -84,6 +84,6 @@ #define EMPTY 0xFFFD #define FREE 0xFFFC -#define JACK_DEFAULT_SELF_CONNECT_MODE JackSelfConnectAllow +#define JACK_DEFAULT_SELF_CONNECT_MODE ' ' /* allow all requests */ #endif diff --git a/common/JackControlAPI.cpp b/common/JackControlAPI.cpp index c908db1c..3be9fb0b 100644 --- a/common/JackControlAPI.cpp +++ b/common/JackControlAPI.cpp @@ -47,6 +47,7 @@ using namespace Jack; +/* JackEngine::CheckPortsConnect() has some assumptions about values of these */ #define SELF_CONNECT_MODE_ALLOW_CHAR ' ' #define SELF_CONNECT_MODE_FAIL_EXTERNAL_ONLY_CHAR 'E' #define SELF_CONNECT_MODE_IGNORE_EXTERNAL_ONLY_CHAR 'e' @@ -1000,7 +1001,6 @@ jackctl_server_open( jackctl_server *server_ptr, jackctl_driver *driver_ptr) { - JackSelfConnectMode self_connect_mode; JSList * paramlist = NULL; try { @@ -1034,27 +1034,6 @@ jackctl_server_open( server_ptr->client_timeout.i = 500; /* 0.5 sec; usable when non realtime. */ } - switch (server_ptr->self_connect_mode.c) - { - case SELF_CONNECT_MODE_ALLOW_CHAR: - self_connect_mode = JackSelfConnectAllow; - break; - case SELF_CONNECT_MODE_FAIL_EXTERNAL_ONLY_CHAR: - self_connect_mode = JackSelfConnectFailExternalOnly; - break; - case SELF_CONNECT_MODE_IGNORE_EXTERNAL_ONLY_CHAR: - self_connect_mode = JackSelfConnectIgnoreExternalOnly; - break; - case SELF_CONNECT_MODE_FAIL_ALL_CHAR: - self_connect_mode = JackSelfConnectFailAll; - break; - case SELF_CONNECT_MODE_IGNORE_ALL_CHAR: - self_connect_mode = JackSelfConnectIgnoreAll; - break; - default: - self_connect_mode = JACK_DEFAULT_SELF_CONNECT_MODE; - } - /* check port max value before allocating server */ if (server_ptr->port_max.ui > PORT_NUM_MAX) { jack_error("Jack server started with too much ports %d (when port max can be %d)", server_ptr->port_max.ui, PORT_NUM_MAX); @@ -1071,7 +1050,7 @@ jackctl_server_open( server_ptr->port_max.ui, server_ptr->verbose.b, (jack_timer_type_t)server_ptr->clock_source.ui, - self_connect_mode, + server_ptr->self_connect_mode.c, server_ptr->name.str); if (server_ptr->engine == NULL) { diff --git a/common/JackEngine.cpp b/common/JackEngine.cpp index 04b8c780..81f381f4 100644 --- a/common/JackEngine.cpp +++ b/common/JackEngine.cpp @@ -21,6 +21,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include #include #include +#include #include "JackSystemDeps.h" #include "JackLockedEngine.h" @@ -39,7 +40,7 @@ namespace Jack JackEngine::JackEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* control, - JackSelfConnectMode self_connect_mode) + char self_connect_mode) : JackLockAble(control->fServerName), fSignal(control->fServerName) { @@ -892,66 +893,42 @@ int JackEngine::PortUnRegister(int refnum, jack_port_id_t port_index) // TODO: make this work with multiple clients per app int JackEngine::CheckPortsConnect(int refnum, jack_port_id_t src, jack_port_id_t dst) { + if (fSelfConnectMode == ' ') return 1; + JackPort* src_port = fGraphManager->GetPort(src); JackPort* dst_port = fGraphManager->GetPort(dst); jack_log("JackEngine::CheckPortsConnect(ref = %d, src = %d, dst = %d)", refnum, src_port->GetRefNum(), dst_port->GetRefNum()); + //jack_log("%s -> %s", src_port->GetName(), dst_port->GetName()); + //jack_log("mode = '%c'", fSelfConnectMode); + int src_self = src_port->GetRefNum() == refnum ? 1 : 0; int dst_self = dst_port->GetRefNum() == refnum ? 1 : 0; - jack_log("src_self is %s", src_self ? "true" : "false"); - jack_log("dst_self is %s", dst_self ? "true" : "false"); - - // 0 means client is connecting other client ports (i.e. control app patchbay functionality) - // 1 means client is connecting its own port to port of other client (i.e. self hooking into system app) - // 2 means client is connecting its own ports (i.e. for app internal functionality) - // TODO: Make this check an engine option and more tweakable (return error or success) - // MAYBE: make the engine option changable on the fly and expose it through client or control API - - switch (fSelfConnectMode) - { - case JackSelfConnectFailExternalOnly: - if (src_self + dst_self == 1) - { - jack_info("rejecting port self connect request to external port (%s -> %s)", src_port->GetName(), dst_port->GetName()); - return -1; - } - - return 1; - - case JackSelfConnectIgnoreExternalOnly: - if (src_self + dst_self == 1) - { - jack_info("ignoring port self connect request to external port (%s -> %s)", src_port->GetName(), dst_port->GetName()); - return 0; - } - - return 1; - - case JackSelfConnectFailAll: - if (src_self + dst_self != 0) - { - jack_info("rejecting port self connect request (%s -> %s)", src_port->GetName(), dst_port->GetName()); - return -1; - } - - return 1; - - case JackSelfConnectIgnoreAll: - if (src_self + dst_self != 0) - { - jack_info("ignoring port self connect request (%s -> %s)", src_port->GetName(), dst_port->GetName()); - return 0; - } - - return 1; - - case JackSelfConnectAllow: // fix warning - return 1; - } - - return 1; + //jack_log("src_self is %s", src_self ? "true" : "false"); + //jack_log("dst_self is %s", dst_self ? "true" : "false"); + + // 0 means client is connecting other client ports (control app patchbay functionality) + // 1 means client is connecting its own port to port of other client (e.g. self connecting into "system" client) + // 2 means client is connecting its own ports (for app internal functionality) + int sum = src_self + dst_self; + //jack_log("sum = %d", sum); + if (sum == 0) return 1; + char lmode = tolower(fSelfConnectMode); + //jack_log("lmode = '%c'", lmode); + if (sum == 2 && lmode == 'e') return 1; + bool fail = lmode != fSelfConnectMode; // fail modes are upper case + //jack_log("fail = %d", (int)fail); + + jack_info( + "%s port self connect request%s (%s -> %s)", + fail ? "rejecting" : "ignoring", + sum == 1 ? " to external port" : "", + src_port->GetName(), + dst_port->GetName()); + + return fail ? -1 : 0; } int JackEngine::PortConnect(int refnum, const char* src, const char* dst) diff --git a/common/JackEngine.h b/common/JackEngine.h index a1138088..e3a471b5 100644 --- a/common/JackEngine.h +++ b/common/JackEngine.h @@ -49,7 +49,7 @@ class SERVER_EXPORT JackEngine : public JackLockAble JackGraphManager* fGraphManager; JackEngineControl* fEngineControl; - JackSelfConnectMode fSelfConnectMode; + char fSelfConnectMode; JackClientInterface* fClientTable[CLIENT_NUM]; JackSynchro* fSynchroTable; JackServerNotifyChannel fChannel; /*! To communicate between the RT thread and server */ @@ -99,7 +99,7 @@ class SERVER_EXPORT JackEngine : public JackLockAble public: - JackEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler, JackSelfConnectMode self_connect_mode); + JackEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler, char self_connect_mode); ~JackEngine(); int Open(); diff --git a/common/JackLockedEngine.h b/common/JackLockedEngine.h index d0e67412..b7fc3890 100644 --- a/common/JackLockedEngine.h +++ b/common/JackLockedEngine.h @@ -83,7 +83,7 @@ class SERVER_EXPORT JackLockedEngine public: - JackLockedEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler, JackSelfConnectMode self_connect_mode): + JackLockedEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler, char self_connect_mode): fEngine(manager, table, controler, self_connect_mode) {} ~JackLockedEngine() diff --git a/common/JackServer.cpp b/common/JackServer.cpp index 32e229c5..6ec7f582 100644 --- a/common/JackServer.cpp +++ b/common/JackServer.cpp @@ -40,7 +40,7 @@ namespace Jack //---------------- // Server control //---------------- -JackServer::JackServer(bool sync, bool temporary, int timeout, bool rt, int priority, int port_max, bool verbose, jack_timer_type_t clock, JackSelfConnectMode self_connect_mode, const char* server_name) +JackServer::JackServer(bool sync, bool temporary, int timeout, bool rt, int priority, int port_max, bool verbose, jack_timer_type_t clock, char self_connect_mode, const char* server_name) { if (rt) { jack_info("JACK server starting in realtime mode with priority %ld", priority); diff --git a/common/JackServer.h b/common/JackServer.h index c8c6a8e5..473f88ff 100644 --- a/common/JackServer.h +++ b/common/JackServer.h @@ -64,7 +64,7 @@ class SERVER_EXPORT JackServer public: - JackServer(bool sync, bool temporary, int timeout, bool rt, int priority, int port_max, bool verbose, jack_timer_type_t clock, JackSelfConnectMode self_connect_mode, const char* server_name); + JackServer(bool sync, bool temporary, int timeout, bool rt, int priority, int port_max, bool verbose, jack_timer_type_t clock, char self_connect_mode, const char* server_name); ~JackServer(); // Server control diff --git a/common/JackServerGlobals.cpp b/common/JackServerGlobals.cpp index 2ad74234..6d804bcb 100644 --- a/common/JackServerGlobals.cpp +++ b/common/JackServerGlobals.cpp @@ -48,7 +48,7 @@ int JackServerGlobals::Start(const char* server_name, int port_max, int verbose, jack_timer_type_t clock, - JackSelfConnectMode self_connect_mode) + char self_connect_mode) { jack_log("Jackdmp: sync = %ld timeout = %ld rt = %ld priority = %ld verbose = %ld ", sync, time_out_ms, rt, priority, verbose); new JackServer(sync, temporary, time_out_ms, rt, priority, port_max, verbose, clock, self_connect_mode, server_name); // Will setup fInstance and fUserCount globals diff --git a/common/JackServerGlobals.h b/common/JackServerGlobals.h index c2e44fc8..beb1880f 100644 --- a/common/JackServerGlobals.h +++ b/common/JackServerGlobals.h @@ -61,7 +61,7 @@ struct SERVER_EXPORT JackServerGlobals int port_max, int verbose, jack_timer_type_t clock, - JackSelfConnectMode self_connect_mode); + char self_connect_mode); static void Stop(); static void Delete(); }; diff --git a/common/JackTypes.h b/common/JackTypes.h index cfb92701..04f186e0 100644 --- a/common/JackTypes.h +++ b/common/JackTypes.h @@ -50,14 +50,4 @@ typedef enum { Finished, } jack_client_state_t; - -enum JackSelfConnectMode -{ - JackSelfConnectAllow, - JackSelfConnectFailExternalOnly, - JackSelfConnectIgnoreExternalOnly, - JackSelfConnectFailAll, - JackSelfConnectIgnoreAll, -}; - #endif