This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/refactor_c_dep_man_service_trackers
in repository https://gitbox.apache.org/repos/asf/celix.git

commit d954516a5547207bffa2566cbf7d68f84f6f7b78
Author: Pepijn Noltes <[email protected]>
AuthorDate: Fri Dec 18 15:49:32 2020 +0100

    Updates UUID handling for dm_component
---
 bundles/pubsub/test/CMakeLists.txt     | 10 ----------
 libs/framework/src/dm_component_impl.c | 29 ++++++++++++++++++++---------
 2 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/bundles/pubsub/test/CMakeLists.txt 
b/bundles/pubsub/test/CMakeLists.txt
index c0eb5fc..b770941 100644
--- a/bundles/pubsub/test/CMakeLists.txt
+++ b/bundles/pubsub/test/CMakeLists.txt
@@ -165,8 +165,6 @@ if (BUILD_PUBSUB_PSA_UDP_MC)
             Celix::pubsub_topology_manager
             Celix::pubsub_admin_udp_multicast
             Celix::pubsub_protocol_wire_v2
-            Celix::shell
-            Celix::shell_tui
             )
     target_compile_definitions(pstm_deadlock_udpmc_test PRIVATE 
-DDEADLOCK_SUT_BUNDLE_FILE=\"${DEADLOCK_SUT_BUNDLE_FILE}\")
     target_link_libraries(pstm_deadlock_udpmc_test PRIVATE Celix::pubsub_api 
GTest::gtest GTest::gtest_main Jansson Celix::dfi)
@@ -241,8 +239,6 @@ if (BUILD_PUBSUB_PSA_TCP)
             Celix::pubsub_topology_manager
             Celix::pubsub_admin_tcp
             Celix::pubsub_protocol_wire_v2
-            Celix::shell
-            Celix::shell_tui
             )
     target_compile_definitions(pstm_deadlock_tcp_test PRIVATE 
-DDEADLOCK_SUT_BUNDLE_FILE=\"${DEADLOCK_SUT_BUNDLE_FILE}\")
     target_link_libraries(pstm_deadlock_tcp_test PRIVATE Celix::pubsub_api 
GTest::gtest GTest::gtest_main Jansson Celix::dfi)
@@ -298,8 +294,6 @@ if (BUILD_PUBSUB_PSA_WS)
             Celix::pubsub_topology_manager
             Celix::pubsub_admin_websocket
             Celix::pubsub_protocol_wire_v2
-            Celix::shell
-            Celix::shell_tui
             )
     target_compile_definitions(pstm_deadlock_websocket_test PRIVATE 
-DDEADLOCK_SUT_BUNDLE_FILE=\"${DEADLOCK_SUT_BUNDLE_FILE}\")
     target_link_libraries(pstm_deadlock_websocket_test PRIVATE 
Celix::pubsub_api GTest::gtest GTest::gtest_main Jansson Celix::dfi)
@@ -468,8 +462,6 @@ if (BUILD_PUBSUB_PSA_ZMQ)
             Celix::pubsub_topology_manager
             Celix::pubsub_admin_zmq
             Celix::pubsub_protocol_wire_v2
-            Celix::shell
-            Celix::shell_tui
             )
 
 
@@ -484,8 +476,6 @@ if (BUILD_PUBSUB_PSA_ZMQ)
             Celix::pubsub_topology_manager
             Celix::pubsub_admin_zmq_v2
             Celix::pubsub_protocol_wire_v2
-            Celix::shell
-            Celix::shell_tui
             )
     target_compile_definitions(pstm_deadlock_zmq_test PRIVATE 
-DDEADLOCK_SUT_BUNDLE_FILE=\"${DEADLOCK_SUT_BUNDLE_FILE}\")
     target_link_libraries(pstm_deadlock_zmq_test PRIVATE Celix::pubsub_api 
GTest::gtest GTest::gtest_main Jansson Celix::dfi ZMQ::lib CZMQ::lib)
diff --git a/libs/framework/src/dm_component_impl.c 
b/libs/framework/src/dm_component_impl.c
index 39484f9..e887ca0 100644
--- a/libs/framework/src/dm_component_impl.c
+++ b/libs/framework/src/dm_component_impl.c
@@ -75,19 +75,30 @@ celix_dm_component_t* 
celix_dmComponent_create(bundle_context_t *context, const
     return celix_dmComponent_createWithUUID(context, name, NULL);
 }
 
-celix_dm_component_t* celix_dmComponent_createWithUUID(bundle_context_t 
*context, const char* name, const char *uuid) {
+celix_dm_component_t* celix_dmComponent_createWithUUID(bundle_context_t 
*context, const char* name, const char *uuidIn) {
     celix_dm_component_t *component = calloc(1, sizeof(*component));
 
-    char randomUUID[DM_COMPONENT_MAX_ID_LENGTH];
-    if (uuid == NULL) {
-        //gen uuid
-        uuid_t uid;
-        uuid_generate(uid);
-        uuid_unparse(uid, randomUUID);
-        uuid = randomUUID;
+    char uuidStr[DM_COMPONENT_MAX_ID_LENGTH];
+    bool genRandomUUID = true;
+    if (uuidIn != NULL) {
+        uuid_t uuid;
+        int rc = uuid_parse(uuidIn, uuid);
+        if (rc == 0) {
+            uuid_unparse(uuid, uuidStr);
+            genRandomUUID = false;
+        } else {
+            //parsing went wrong
+            //TODO print error
+        }
     }
-    snprintf(component->uuid, DM_COMPONENT_MAX_ID_LENGTH, "%s", uuid);
 
+    if (genRandomUUID) {
+        //gen uuid
+        uuid_t uuid;
+        uuid_generate(uuid);
+        uuid_unparse(uuid, uuidStr);
+    }
+    snprintf(component->uuid, DM_COMPONENT_MAX_ID_LENGTH, "%s", uuidStr);
 
     snprintf(component->name, DM_COMPONENT_MAX_NAME_LENGTH, "%s", name == NULL 
? "n/a" : name);
 

Reply via email to