Skip to content

Commit

Permalink
Make the framework UUID configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
xuzhenbao committed Jul 25, 2024
1 parent 81d3b6b commit 697e77a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
9 changes: 9 additions & 0 deletions libs/framework/gtest/src/CelixFrameworkTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ TEST_F(FrameworkFactoryTestSuite, FactoryCreateTest) {
celix_frameworkFactory_destroyFramework(fw);
}

TEST_F(FrameworkFactoryTestSuite, ConfigureFrameworkUUIDTest) {
celix_properties_t* config = celix_properties_create();
celix_properties_set(config, CELIX_FRAMEWORK_UUID, "test-framework");
framework_t* fw = celix_frameworkFactory_createFramework(config);
ASSERT_TRUE(fw != nullptr);
EXPECT_STREQ("test-framework", celix_framework_getUUID(fw));
celix_frameworkFactory_destroyFramework(fw);
}

TEST_F(FrameworkFactoryTestSuite, FactoryCreateAndToManyStartAndStopsTest) {
framework_t* fw = celix_frameworkFactory_createFramework(nullptr);
ASSERT_TRUE(fw != nullptr);
Expand Down
2 changes: 1 addition & 1 deletion libs/framework/include/celix/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace celix {
constexpr const char * const FRAMEWORK_CACHE_DIR = CELIX_FRAMEWORK_CACHE_DIR;

/**
* @brief Celix framework environment property (named "org.osgi.framework.uuid") specifying the UUID for the
* @brief Celix framework environment property (named "CELIX_FRAMEWORK_UUID") specifying the UUID for the
* framework UUID.
*
* The framework UUID is used to uniquely identify a single framework. If no framework uuid is provided
Expand Down
4 changes: 2 additions & 2 deletions libs/framework/include/celix_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ extern "C" {
#define CELIX_FRAMEWORK_CLEAN_CACHE_DIR_ON_CREATE "CELIX_FRAMEWORK_CLEAN_CACHE_DIR_ON_CREATE"

/**
* @brief Celix framework environment property (named "org.osgi.framework.uuid") specifying the UUID for the
* @brief Celix framework environment property (named "CELIX_FRAMEWORK_UUID") specifying the UUID for the
* framework UUID.
*
* The framework UUID is used to uniquely identify a single framework. If no framework uuid is provided
* random uuid will be generated during startup.
*
* @note The Celix framework expects framework UUIDs to be unique per process.
*/
#define CELIX_FRAMEWORK_UUID "org.osgi.framework.uuid"
#define CELIX_FRAMEWORK_UUID "CELIX_FRAMEWORK_UUID"

/**
* @brief Celix framework environment property (named "CELIX_BUNDLES_PATH") which specified a `:` separated
Expand Down
16 changes: 10 additions & 6 deletions libs/framework/src/framework.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ struct fw_frameworkListener {

typedef struct fw_frameworkListener * fw_framework_listener_pt;

static void celix_framework_createAndStoreFrameworkUUID(celix_framework_t* fw) {
if (celix_properties_get(fw->configurationMap, CELIX_FRAMEWORK_UUID, NULL) == NULL) {
char uuid[37];
uuid_t uid;
uuid_generate(uid);
uuid_unparse(uid, uuid);
celix_properties_set(fw->configurationMap, CELIX_FRAMEWORK_UUID, uuid);
}
}

celix_status_t framework_create(framework_pt *out, celix_properties_t* config) {
celix_framework_t* framework = calloc(1, sizeof(*framework));
Expand Down Expand Up @@ -244,12 +253,7 @@ celix_status_t framework_create(framework_pt *out, celix_properties_t* config) {
framework->dispatcher.dynamicEventQueue = celix_arrayList_create();
framework->dispatcher.scheduledEvents = celix_longHashMap_create();

//create and store framework uuid
char uuid[37];
uuid_t uid;
uuid_generate(uid);
uuid_unparse(uid, uuid);
celix_properties_set(framework->configurationMap, CELIX_FRAMEWORK_UUID, uuid);
celix_framework_createAndStoreFrameworkUUID(framework);

//setup framework logger
const char* logStr = celix_framework_getConfigProperty(framework, CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL_CONFIG_NAME, CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL_DEFAULT_VALUE, NULL);
Expand Down

0 comments on commit 697e77a

Please sign in to comment.