proper solution for variable-args jack_client_open()
authorRobin Gareus <robin@gareus.org>
Sat, 25 Oct 2014 14:12:38 +0000 (16:12 +0200)
committerRobin Gareus <robin@gareus.org>
Sat, 25 Oct 2014 15:28:13 +0000 (17:28 +0200)
libs/backends/jack/jack_connection.cc
libs/backends/jack/weak_libjack.c
libs/backends/jack/weak_libjack.h

index 201769070b20980af1be15da9cac6940c0d26139..f9824143cebfa14a18b0db434a6d2f43a7800984 100644 (file)
@@ -74,7 +74,7 @@ JackConnection::JackConnection (const std::string& arg1, const std::string& arg2
         }
 
        jack_status_t status;
-       jack_client_t* c = jack_client_open1 ("ardourprobe", JackNoStartServer, &status);
+       jack_client_t* c = jack_client_open ("ardourprobe", JackNoStartServer, &status);
 
        if (status == 0) {
                jack_client_close (c);
@@ -114,7 +114,7 @@ JackConnection::open ()
        get_jack_server_dir_paths (dirs);
        set_path_env_for_jack_autostart (dirs);
 
-       if ((_jack = jack_client_open2 (_client_name.c_str(), JackSessionID, &status, session_uuid.c_str())) == 0) {
+       if ((_jack = jack_client_open (_client_name.c_str(), JackSessionID, &status, session_uuid.c_str())) == 0) {
                return -1;
        }
 
index 4e137ab715e876dae3cb8389a32d9849e0c4790d..ebde208e42f6f7467bf61a018baa42fb43c8a8d8 100644 (file)
@@ -180,25 +180,16 @@ int have_libjack (void) {
  * (jack ringbuffer may be an exception for some apps)
  */
 
-/* expand ellipsis for jack-session */
-jack_client_t * WJACK_client_open2 (const char *client_name, jack_options_t options, jack_status_t *status, const char *uuid) {
-       if (_j._client_open) {
-               return ((jack_client_t* (*)(const char *, jack_options_t, jack_status_t *, ...))(_j._client_open))(client_name, options, status, uuid);
-       } else {
-               WJACK_WARNING(client_open);
-               if (status) *status = (jack_status_t)0;
-               return NULL;
-       }
+/* dedicated support for jack_client_open(,..) variable arg function macro */
+func_t WJACK_get_client_open(void) {
+       return _j._client_open;
 }
 
-jack_client_t * WJACK_client_open1 (const char *client_name, jack_options_t options, jack_status_t *status) {
-       if (_j._client_open) {
-               return ((jack_client_t* (*)(const char *, jack_options_t, jack_status_t *, ...))_j._client_open)(client_name, options, status);
-       } else {
-               WJACK_WARNING(client_open);
-               if (status) *status = (jack_status_t)0;
-               return NULL;
-       }
+/* callback to set status */
+jack_client_t * WJACK_no_client_open (const char *client_name, jack_options_t options, jack_status_t *status, ...) {
+       WJACK_WARNING(client_open);
+       if (status) { *status = JackFailure; }
+       return NULL;
 }
 
 /*******************************************************************************
index 10e2751d0fc03945838bafc4a9ea5c404ce3d868..349861f6ab211e3921da1670d620852438aca8d9 100644 (file)
@@ -48,7 +48,6 @@ int have_libjack(void);
 #ifdef USE_WEAK_JACK
 
 /* <jack/jack.h> */
-#define jack_client_open                    WJACK_client_openX
 #define jack_client_close                   WJACK_client_close
 #define jack_get_client_name                WJACK_get_client_name
 #define jack_get_sample_rate                WJACK_get_sample_rate
@@ -153,42 +152,39 @@ int have_libjack(void);
 #define jack_client_stop_thread             WJACK_client_stop_thread
 #define jack_client_kill_thread             WJACK_client_kill_thread
 
-/* var-args hack */
-#define jack_client_open1                   WJACK_client_open1
-#define jack_client_open2                   WJACK_client_open2
+#define jack_client_open                    WJACK_client_client_openXXX
 
-#include <jack/types.h> // needed for jack_client_open abstraction
+#endif // end USE_WEAK_JACK
 
-#ifdef __cplusplus
-extern "C"
-{
-#endif
+#include <jack/jack.h>
+#include <jack/transport.h>
+#include <jack/ringbuffer.h>
+#include <jack/midiport.h>
+#include <jack/session.h>
+#include <jack/thread.h>
+
+#ifdef USE_WEAK_JACK
 
-jack_client_t * WJACK_client_open1 (
-        const char *client_name,
-        jack_options_t options, jack_status_t *status);
+#undef jack_client_open
 
-jack_client_t * WJACK_client_open2 (
-        const char *client_name,
-        jack_options_t options, jack_status_t *status, const char *uuid);
+/* var-args hack */
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+void (* WJACK_get_client_open (void)) (void);
+jack_client_t * WJACK_no_client_open (const char *client_name, jack_options_t options, jack_status_t *status, ...);
 #ifdef __cplusplus
 }
 #endif
 
-#else /* directly use JACK API */
-
-/* var-args hack */
-#define jack_client_open1                  jack_client_open
-#define jack_client_open2                  jack_client_open
+#define jack_client_open(...) \
+( \
+       (WJACK_get_client_open() != NULL) \
+       ?  ((jack_client_t* (*)(const char *, jack_options_t, jack_status_t *, ...))(WJACK_get_client_open()))(__VA_ARGS__) \
+       : WJACK_no_client_open(__VA_ARGS__) \
+)
 
 #endif // end USE_WEAK_JACK
 
-#include <jack/jack.h>
-#include <jack/transport.h>
-#include <jack/ringbuffer.h>
-#include <jack/midiport.h>
-#include <jack/session.h>
-#include <jack/thread.h>
-
 #endif // _WEAK_JACK_H