From ae6e10fa9cd2b23088f51c0dc1a48f6add8b4f1e Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 12 Jun 2020 11:34:15 +0100 Subject: [PATCH] libjack: Implement client name uuid stuff Signed-off-by: falkTX --- source/libjack/libjack.cpp | 46 +++++++++++++++++++++++++++++++ source/libjack/libjack.hpp | 2 ++ source/libjack/libjack_client.cpp | 18 ++++++------ 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/source/libjack/libjack.cpp b/source/libjack/libjack.cpp index d45dacc86..7e0e6f689 100644 --- a/source/libjack/libjack.cpp +++ b/source/libjack/libjack.cpp @@ -270,6 +270,20 @@ public: return true; } + const char* getClientNameFromUUID(jack_uuid_t uuid) const + { + for (LinkedList::Itenerator it = fClients.begin2(); it.valid(); it.next()) + { + JackClientState* const jclient(it.getValue(nullptr)); + CARLA_SAFE_ASSERT_CONTINUE(jclient != nullptr); + + if (jclient->uuid == uuid) + return jclient->name; + } + + return nullptr; + } + pthread_t getRealtimeThreadId() const noexcept { return (pthread_t)fRealtimeThread.getThreadId(); @@ -1377,6 +1391,38 @@ int jack_deactivate(jack_client_t* client) // --------------------------------------------------------------------------------------------------------------------- +CARLA_EXPORT +char* jack_get_client_name_by_uuid(jack_client_t* const client, const char* const uuidstr) +{ + carla_debug("%s(%p, %s)", __FUNCTION__, client, uuidstr); + + jack_uuid_t uuid = JACK_UUID_EMPTY_INITIALIZER; + CARLA_SAFE_ASSERT_RETURN(jack_uuid_parse(uuidstr, &uuid) == 0, nullptr); + + JackClientState* const jclient = (JackClientState*)client; + CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, nullptr); + + const char* clientName; + + if (jclient->uuid == uuid) + { + clientName = jclient->name; + CARLA_SAFE_ASSERT_RETURN(clientName != nullptr, nullptr); + } + else + { + CarlaJackAppClient* const jackAppPtr = jclient->server.jackAppPtr; + CARLA_SAFE_ASSERT_RETURN(jackAppPtr != nullptr && jackAppPtr == &gClient, nullptr); + + clientName = jackAppPtr->getClientNameFromUUID(uuid); + CARLA_SAFE_ASSERT_RETURN(clientName != nullptr, nullptr); + } + + return strdup(clientName); +} + +// --------------------------------------------------------------------------------------------------------------------- + CARLA_EXPORT pthread_t jack_client_thread_id(jack_client_t* client) { diff --git a/source/libjack/libjack.hpp b/source/libjack/libjack.hpp index 8d3d12e2d..85bca7003 100644 --- a/source/libjack/libjack.hpp +++ b/source/libjack/libjack.hpp @@ -164,6 +164,7 @@ struct JackClientState { bool deactivated; // activated once, then deactivated char* name; + jack_uuid_t uuid; LinkedList audioIns; LinkedList audioOuts; @@ -202,6 +203,7 @@ struct JackClientState { activated(false), deactivated(false), name(strdup(n)), + uuid(jack_client_uuid_generate()), audioIns(), audioOuts(), midiIns(), diff --git a/source/libjack/libjack_client.cpp b/source/libjack/libjack_client.cpp index 1dd752adc..b47c95d72 100644 --- a/source/libjack/libjack_client.cpp +++ b/source/libjack/libjack_client.cpp @@ -43,15 +43,17 @@ char* jack_get_client_name(jack_client_t* client) CARLA_EXPORT char* jack_get_uuid_for_client_name(jack_client_t* client, const char* name) { - carla_stderr2("%s(%p, %s)", __FUNCTION__, client, name); - return nullptr; -} + carla_debug("%s(%p, %s)", __FUNCTION__, client, name); -CARLA_EXPORT -char* jack_get_client_name_by_uuid(jack_client_t* client, const char* uuid) -{ - carla_stderr2("%s(%p, %s)", __FUNCTION__, client, uuid); - return nullptr; + JackClientState* const jclient = (JackClientState*)client; + CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, nullptr); + + char* const uuidstr = static_cast(std::malloc(JACK_UUID_STRING_SIZE)); + CARLA_SAFE_ASSERT_RETURN(uuidstr != nullptr, nullptr); + + jack_uuid_unparse(jclient->uuid, uuidstr); + + return uuidstr; } // --------------------------------------------------------------------------------------------------------------------