Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the framework UUID configurable #763

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading