diff options
author | Filipe Coelho <falktx@falktx.com> | 2019-03-18 08:33:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-18 08:33:50 +0100 |
commit | 59550f67ee357c82886816391aaeefd6448e8eb7 (patch) | |
tree | dc7a7a6714975d8ccda2f8da55064a7b2d4eda50 /common/JackEngine.cpp | |
parent | bb3f5cb2963dc74ba045a1553e05f755af8623cc (diff) | |
download | jack2-59550f67ee357c82886816391aaeefd6448e8eb7.tar.gz |
Fix client UUID gen, and some warnings (#440)
* Fix generation of client uuid
Signed-off-by: falkTX <falktx@falktx.com>
* Remove all client properties when removed; Cleanup a few things
Signed-off-by: falkTX <falktx@falktx.com>
* Make all uuid function arguments use jack_uuid_t type; Fix warnings
Signed-off-by: falkTX <falktx@falktx.com>
* Rework uuids to never be int, more cleanup
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat (limited to 'common/JackEngine.cpp')
-rw-r--r-- | common/JackEngine.cpp | 78 |
1 files changed, 45 insertions, 33 deletions
diff --git a/common/JackEngine.cpp b/common/JackEngine.cpp index 37d1022d..be87c977 100644 --- a/common/JackEngine.cpp +++ b/common/JackEngine.cpp @@ -42,7 +42,8 @@ JackEngine::JackEngine(JackGraphManager* manager, JackEngineControl* control, char self_connect_mode) : JackLockAble(control->fServerName), - fSignal(control->fServerName) + fSignal(control->fServerName), + fMetadata(NULL) // FIXME use control->fServerName? { fGraphManager = manager; fSynchroTable = table; @@ -52,7 +53,6 @@ JackEngine::JackEngine(JackGraphManager* manager, fClientTable[i] = NULL; } fLastSwitchUsecs = 0; - fMaxUUID = 0; fSessionPendingReplies = 0; fSessionTransaction = NULL; fSessionResult = NULL; @@ -476,7 +476,7 @@ int JackEngine::InternalClientUnload(int refnum, int* status) // Client management //------------------- -int JackEngine::ClientCheck(const char* name, int uuid, char* name_res, int protocol, int options, int* status) +int JackEngine::ClientCheck(const char* name, jack_uuid_t uuid, char* name_res, int protocol, int options, int* status) { // Clear status *status = 0; @@ -564,21 +564,17 @@ bool JackEngine::ClientCheckName(const char* name) return false; } -int JackEngine::GetNewUUID() +void JackEngine::EnsureUUID(jack_uuid_t uuid) { - return fMaxUUID++; -} - -void JackEngine::EnsureUUID(int uuid) -{ - if (uuid > fMaxUUID) { - fMaxUUID = uuid + 1; - } + if (jack_uuid_empty(uuid)) + return; for (int i = 0; i < CLIENT_NUM; i++) { JackClientInterface* client = fClientTable[i]; - if (client && (client->GetClientControl()->fSessionID == uuid)) { - client->GetClientControl()->fSessionID = GetNewUUID(); + if (client && jack_uuid_compare(client->GetClientControl()->fSessionID, uuid) == 0) { + // FIXME? this code does nothing, but jack1 has it like this too.. + jack_uuid_clear (&uuid); + // client->GetClientControl()->fSessionID = jack_client_uuid_generate(); } } } @@ -608,12 +604,12 @@ int JackEngine::GetClientRefNum(const char* name) } // Used for external clients -int JackEngine::ClientExternalOpen(const char* name, int pid, int uuid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager) +int JackEngine::ClientExternalOpen(const char* name, int pid, jack_uuid_t uuid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager) { char real_name[JACK_CLIENT_NAME_SIZE + 1]; - if (uuid < 0) { - uuid = GetNewUUID(); + if (jack_uuid_empty(uuid)) { + uuid = jack_client_uuid_generate(); strncpy(real_name, name, JACK_CLIENT_NAME_SIZE); } else { std::map<int, std::string>::iterator res = fReservationMap.find(uuid); @@ -744,6 +740,9 @@ int JackEngine::ClientCloseAux(int refnum, bool wait) JackClientInterface* client = fClientTable[refnum]; fEngineControl->fTransport.ResetTimebase(refnum); + jack_uuid_t uuid = JACK_UUID_EMPTY_INITIALIZER; + jack_uuid_copy (&uuid, client->GetClientControl()->fSessionID); + // Unregister all ports ==> notifications are sent jack_int_t ports[PORT_NUM_FOR_CLIENT]; int i; @@ -774,6 +773,12 @@ int JackEngine::ClientCloseAux(int refnum, bool wait) // Notify running clients NotifyRemoveClient(client->GetClientControl()->fName, refnum); + fMetadata.RemoveProperties(NULL, uuid); + /* have to do the notification ourselves, since the client argument + to fMetadata->RemoveProperties() was NULL + */ + PropertyChangeNotify(uuid, NULL, PropertyDeleted); + // Cleanup... fSynchroTable[refnum].Destroy(); fEngineControl->ResetRollingUsecs(); @@ -1082,8 +1087,8 @@ void JackEngine::SessionNotify(int refnum, const char *target, jack_session_even for (int i = 0; i < CLIENT_NUM; i++) { JackClientInterface* client = fClientTable[i]; - if (client && (client->GetClientControl()->fSessionID < 0)) { - client->GetClientControl()->fSessionID = GetNewUUID(); + if (client && jack_uuid_empty(client->GetClientControl()->fSessionID)) { + client->GetClientControl()->fSessionID = jack_client_uuid_generate(); } } fSessionResult = new JackSessionNotifyResult(); @@ -1114,8 +1119,8 @@ void JackEngine::SessionNotify(int refnum, const char *target, jack_session_even if (result == kPendingSessionReply) { fSessionPendingReplies += 1; } else if (result == kImmediateSessionReply) { - char uuid_buf[JACK_UUID_SIZE]; - snprintf(uuid_buf, sizeof(uuid_buf), "%d", client->GetClientControl()->fSessionID); + char uuid_buf[JACK_UUID_STRING_SIZE]; + jack_uuid_unparse(client->GetClientControl()->fSessionID, uuid_buf); fSessionResult->fCommandList.push_back(JackSessionCommand(uuid_buf, client->GetClientControl()->fName, client->GetClientControl()->fSessionCommand, @@ -1139,8 +1144,8 @@ int JackEngine::SessionReply(int refnum) { JackClientInterface* client = fClientTable[refnum]; assert(client); - char uuid_buf[JACK_UUID_SIZE]; - snprintf(uuid_buf, sizeof(uuid_buf), "%d", client->GetClientControl()->fSessionID); + char uuid_buf[JACK_UUID_STRING_SIZE]; + jack_uuid_unparse(client->GetClientControl()->fSessionID, uuid_buf); fSessionResult->fCommandList.push_back(JackSessionCommand(uuid_buf, client->GetClientControl()->fName, client->GetClientControl()->fSessionCommand, @@ -1164,7 +1169,7 @@ int JackEngine::GetUUIDForClientName(const char *client_name, char *uuid_res) JackClientInterface* client = fClientTable[i]; if (client && (strcmp(client_name, client->GetClientControl()->fName) == 0)) { - snprintf(uuid_res, JACK_UUID_SIZE, "%d", client->GetClientControl()->fSessionID); + jack_uuid_unparse(client->GetClientControl()->fSessionID, uuid_res); return 0; } } @@ -1172,8 +1177,12 @@ int JackEngine::GetUUIDForClientName(const char *client_name, char *uuid_res) return -1; } -int JackEngine::GetClientNameForUUID(const char *uuid, char *name_res) +int JackEngine::GetClientNameForUUID(const char *uuid_buf, char *name_res) { + jack_uuid_t uuid; + if (jack_uuid_parse(uuid_buf, &uuid) != 0) + return -1; + for (int i = 0; i < CLIENT_NUM; i++) { JackClientInterface* client = fClientTable[i]; @@ -1181,10 +1190,7 @@ int JackEngine::GetClientNameForUUID(const char *uuid, char *name_res) continue; } - char uuid_buf[JACK_UUID_SIZE]; - snprintf(uuid_buf, JACK_UUID_SIZE, "%d", client->GetClientControl()->fSessionID); - - if (strcmp(uuid,uuid_buf) == 0) { + if (jack_uuid_compare(client->GetClientControl()->fSessionID, uuid) == 0) { strncpy(name_res, client->GetClientControl()->fName, JACK_CLIENT_NAME_SIZE); return 0; } @@ -1193,17 +1199,23 @@ int JackEngine::GetClientNameForUUID(const char *uuid, char *name_res) return -1; } -int JackEngine::ReserveClientName(const char *name, const char *uuid) +int JackEngine::ReserveClientName(const char *name, const char *uuidstr) { - jack_log("JackEngine::ReserveClientName ( name = %s, uuid = %s )", name, uuid); + jack_log("JackEngine::ReserveClientName ( name = %s, uuid = %s )", name, uuidstr); if (ClientCheckName(name)) { jack_log("name already taken"); return -1; } - EnsureUUID(atoi(uuid)); - fReservationMap[atoi(uuid)] = name; + jack_uuid_t uuid; + if (jack_uuid_parse(uuidstr, &uuid) != 0) { + jack_error("JackEngine::ReserveClientName invalid uuid %s", uuidstr); + return -1; + } + + EnsureUUID(uuid); + fReservationMap[uuid] = name; return 0; } |