celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [08/50] [abbrv] celix git commit: CELIX-237: Updated celix launcher so that mutiple embedded framework can be started (e.g. testing client / server rsa)
Date Tue, 13 Oct 2015 10:21:36 GMT
CELIX-237: Updated celix launcher so that mutiple embedded framework can be started (e.g. testing
client / server rsa)


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/55e75be7
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/55e75be7
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/55e75be7

Branch: refs/heads/develop
Commit: 55e75be72c24a62818fe3e2326c396725f1d7557
Parents: 87f3fab
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Thu Aug 6 13:27:13 2015 +0200
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Thu Aug 6 13:27:13 2015 +0200

----------------------------------------------------------------------
 framework/private/src/framework.c               |  2 +
 launcher/private/src/launcher.c                 | 46 ++++++++++----------
 launcher/private/src/main.c                     | 24 ++++++----
 launcher/public/include/launcher.h              | 12 ++---
 .../remote_service_admin_dfi/tst/rsa_tests.cpp  | 24 ++++++----
 .../remote_service_admin_dfi/tst/run_tests.cpp  | 17 --------
 6 files changed, 62 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/55e75be7/framework/private/src/framework.c
----------------------------------------------------------------------
diff --git a/framework/private/src/framework.c b/framework/private/src/framework.c
index 3f49cdc..6e6e1ba 100644
--- a/framework/private/src/framework.c
+++ b/framework/private/src/framework.c
@@ -335,6 +335,8 @@ celix_status_t framework_destroy(framework_pt framework) {
 	celixThreadMutex_destroy(&framework->mutex);
 	celixThreadCondition_destroy(&framework->condition);
 
+    properties_destroy(framework->configurationMap);
+
 	free(framework);
 
 	return status;

http://git-wip-us.apache.org/repos/asf/celix/blob/55e75be7/launcher/private/src/launcher.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/launcher.c b/launcher/private/src/launcher.c
index 9c021ed..432c709 100644
--- a/launcher/private/src/launcher.c
+++ b/launcher/private/src/launcher.c
@@ -32,23 +32,22 @@
 #include <libgen.h>
 #include <signal.h>
 
+#ifndef CELIX_NO_CURLINIT
 #include <curl/curl.h>
+#endif
 
 #include "framework.h"
 #include "linked_list_iterator.h"
 
-static struct framework * framework;
-static properties_pt config;
-
 #ifdef WITH_APR
 static apr_pool_t *memoryPool;
 #endif
 
-int celixLauncher_launch(const char *configFile) {
+int celixLauncher_launch(const char *configFile, framework_pt *framework) {
     int status = 0;
     FILE *config = fopen(configFile, "r");
     if (config != NULL) {
-        status = celixLauncher_launchWithStream(config);
+        status = celixLauncher_launchWithStream(config, framework);
     } else {
         fprintf(stderr, "Error: invalid or non-existing configuration file: '%s'.", configFile);
         perror("");
@@ -57,10 +56,10 @@ int celixLauncher_launch(const char *configFile) {
     return status;
 }
 
-int celixLauncher_launchWithStream(FILE *stream) {
+int celixLauncher_launchWithStream(FILE *stream, framework_pt *framework) {
     int status = 0;
 
-    config = properties_loadWithStream(stream);
+    properties_pt config = properties_loadWithStream(stream);
     fclose(stream);
     // Make sure we've read it and that nothing went wrong with the file access...
     if (config == NULL) {
@@ -69,14 +68,16 @@ int celixLauncher_launchWithStream(FILE *stream) {
         status = 1;
     }
 
-    // Set signal handler
+
 #ifdef WITH_APR
     apr_status_t rv;
     apr_status_t s;
 #endif
 
+#ifndef CELIX_NO_CURLINIT
     // Before doing anything else, let's setup Curl
     curl_global_init(CURL_GLOBAL_NOTHING);
+#endif
 
 #ifdef WITH_APR
 	rv = apr_initialize();
@@ -93,19 +94,18 @@ int celixLauncher_launchWithStream(FILE *stream) {
 
     if (status == 0) {
         char *autoStart = properties_get(config, "cosgi.auto.start.1");
-        framework = NULL;
         celix_status_t status;
 #ifdef WITH_APR
-        status = framework_create(&framework, memoryPool, config);
+        status = framework_create(framework, memoryPool, config);
 #else
-        status = framework_create(&framework, config);
+        status = framework_create(framework, config);
 #endif
         bundle_pt fwBundle = NULL;
         if (status == CELIX_SUCCESS) {
-            status = fw_init(framework);
+            status = fw_init(*framework);
             if (status == CELIX_SUCCESS) {
                 // Start the system bundle
-                framework_getFrameworkBundle(framework, &fwBundle);
+                framework_getFrameworkBundle(*framework, &fwBundle);
                 bundle_start(fwBundle);
 
                 char delims[] = " ";
@@ -128,7 +128,7 @@ int celixLauncher_launchWithStream(FILE *stream) {
                 // First install all bundles
                 // Afterwards start them
                 arrayList_create(&installed);
-                framework_getFrameworkBundle(framework, &bundle);
+                framework_getFrameworkBundle(*framework, &bundle);
                 bundle_getContext(bundle, &context);
                 iter = linkedListIterator_create(bundles, 0);
                 while (linkedListIterator_hasNext(iter)) {
@@ -164,8 +164,11 @@ int celixLauncher_launchWithStream(FILE *stream) {
 	apr_terminate();
 #endif
 
+
+#ifndef CELIX_NO_CURLINIT
         // Cleanup Curl
         curl_global_cleanup();
+#endif
 
         printf("Launcher: Exit\n");
     }
@@ -173,19 +176,16 @@ int celixLauncher_launchWithStream(FILE *stream) {
     return status;
 }
 
-void celixLauncher_waitForShutdown(void) {
+void celixLauncher_waitForShutdown(framework_pt framework) {
     framework_waitForStop(framework);
+}
+
+void celixLauncher_destroy(framework_pt framework) {
     framework_destroy(framework);
-    properties_destroy(config);
 }
 
-void celixLauncher_stop(void) {
+void celixLauncher_stop(framework_pt framework) {
     bundle_pt fwBundle = NULL;
     framework_getFrameworkBundle(framework, &fwBundle);
     bundle_stop(fwBundle);
-}
-
-struct framework *celixLauncher_getFramework(void) {
-    return framework;
-}
-
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/55e75be7/launcher/private/src/main.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/main.c b/launcher/private/src/main.c
index 00b08bd..82530e1 100644
--- a/launcher/private/src/main.c
+++ b/launcher/private/src/main.c
@@ -31,13 +31,13 @@
 #include "launcher.h"
 
 static void show_usage(char* prog_name);
-static void shutdownCelix(int signal);
+static void shutdown_framework(int signal);
 
 #define DEFAULT_CONFIG_FILE "config.properties"
 
-int main(int argc, char *argv[]) {
+static framework_pt framework = NULL;
 
-    (void) signal(SIGINT, shutdownCelix);
+int main(int argc, char *argv[]) {
 
     // Perform some minimal command-line option parsing...
     char *opt = NULL;
@@ -59,15 +59,21 @@ int main(int argc, char *argv[]) {
         config_file = DEFAULT_CONFIG_FILE;
     }
 
-    celixLauncher_launch(config_file);
-    celixLauncher_waitForShutdown();
+
+    // Set signal handler
+    (void) signal(SIGINT, shutdown_framework);
+
+    celixLauncher_launch(config_file, &framework);
+    celixLauncher_waitForShutdown(framework);
+    celixLauncher_destroy(framework);
 }
 
 static void show_usage(char* prog_name) {
     printf("Usage:\n  %s [path/to/config.properties]\n\n", basename(prog_name));
 }
 
-static void shutdownCelix(int signal) {
-    celixLauncher_stop();
-}
-
+static void shutdown_framework(int signal) {
+    if (framework != NULL) {
+        celixLauncher_stop(framework); //NOTE main thread will destroy
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/55e75be7/launcher/public/include/launcher.h
----------------------------------------------------------------------
diff --git a/launcher/public/include/launcher.h b/launcher/public/include/launcher.h
index 6ee8357..6077e03 100644
--- a/launcher/public/include/launcher.h
+++ b/launcher/public/include/launcher.h
@@ -30,10 +30,12 @@
 #include <stdio.h>
 #include "framework.h"
 
-int celixLauncher_launch(const char *configFile);
-int celixLauncher_launchWithStream(FILE *config);
-void celixLauncher_stop(void);
-void celixLauncher_waitForShutdown(void);
-struct framework *celixLauncher_getFramework(void);
+int celixLauncher_launch(const char *configFile, framework_pt *framework);
+int celixLauncher_launchWithStream(FILE *config, framework_pt *framework);
+
+void celixLauncher_stop(framework_pt framework);
+void celixLauncher_destroy(framework_pt framework);
+
+void celixLauncher_waitForShutdown(framework_pt framework);
 
 #endif //CELIX_LAUNCHER_H

http://git-wip-us.apache.org/repos/asf/celix/blob/55e75be7/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp b/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
index a5a556a..f23babd 100644
--- a/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
@@ -17,16 +17,19 @@ extern "C" {
 #include "remote_service_admin.h"
 
 
+framework_pt framework = NULL;
 bundle_context_pt context = NULL;
 service_reference_pt rsaRef = NULL;
 remote_service_admin_service_pt rsa = NULL;
 
-static void setupContextAndRsa(void) {
+static void setupFm(void) {
     int rc = 0;
-    struct framework *fm = celixLauncher_getFramework();
+
+    rc = celixLauncher_launch("config.properties", &framework);
+    CHECK_EQUAL(CELIX_SUCCESS, rc);
 
     bundle_pt bundle = NULL;
-    rc = framework_getFrameworkBundle(fm, &bundle);
+    rc = framework_getFrameworkBundle(framework, &bundle);
     CHECK_EQUAL(CELIX_SUCCESS, rc);
 
     rc = bundle_getContext(bundle, &context);
@@ -39,13 +42,19 @@ static void setupContextAndRsa(void) {
     CHECK_EQUAL(CELIX_SUCCESS, rc);
 }
 
-static void teardownContextAndRsa(void) {
+static void teardownFm(void) {
     int rc = 0;
     rc = bundleContext_ungetService(context, rsaRef, NULL);
     CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+    celixLauncher_stop(framework);
+    celixLauncher_waitForShutdown(framework);
+    celixLauncher_destroy(framework);
+
     rsaRef = NULL;
     rsa = NULL;
     context = NULL;
+    framework = NULL;
 }
 
 static void testInfo(void) {
@@ -77,14 +86,11 @@ static void testImportService(void) {
 
 TEST_GROUP(RsaDfiTests) {
     void setup() {
-        celixLauncher_launch("config.properties");
-        setupContextAndRsa();
+        setupFm();
     }
 
     void teardown() {
-        teardownContextAndRsa();
-        celixLauncher_stop();
-        celixLauncher_waitForShutdown();
+        teardownFm();
     }
 };
 

http://git-wip-us.apache.org/repos/asf/celix/blob/55e75be7/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/run_tests.cpp b/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
index 81d1908..c5e960c 100644
--- a/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
@@ -4,23 +4,6 @@
 #include <CppUTest/TestHarness.h>
 #include "CppUTest/CommandLineTestRunner.h"
 
-
-extern "C" {
-    #include <stdio.h>
-
-    #include "launcher.h"
-    #include "framework.h"
-
-    static int startCelix(void) {
-        celixLauncher_launch("config.properties");
-    }
-
-    static int stopCelix(void) {
-        celixLauncher_stop();
-        celixLauncher_waitForShutdown();
-    }
-}
-
 int main(int argc, char** argv) {
     return RUN_ALL_TESTS(argc, argv);
 }
\ No newline at end of file


Mime
View raw message