You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by bp...@apache.org on 2015/12/18 08:35:08 UTC

celix git commit: CELIX-208: remove APR from embedded celix example

Repository: celix
Updated Branches:
  refs/heads/develop 268f4e494 -> 3809c4cd4


CELIX-208: remove APR from embedded celix example


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

Branch: refs/heads/develop
Commit: 3809c4cd49fec9712b3cb2d18733a154d2453e12
Parents: 268f4e4
Author: Bjoern Petri <bp...@apache.org>
Authored: Fri Dec 18 08:34:46 2015 +0100
Committer: Bjoern Petri <bp...@apache.org>
Committed: Fri Dec 18 08:34:46 2015 +0100

----------------------------------------------------------------------
 examples/CMakeLists.txt               |  2 +-
 examples/embedding/private/src/main.c | 72 +++++++++++++++---------------
 2 files changed, 38 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/3809c4cd/examples/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 55468a4..c4eb9b4 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -34,5 +34,5 @@ if (EXAMPLES)
     #add_subdirectory(osgi-in-action/chapter04-paint-example) chapter4 example is still based on APR
     add_subdirectory(locking)
     
-    #add_subdirectory(embedding) embedding is still baed on APR
+    add_subdirectory(embedding)
 endif(EXAMPLES)

http://git-wip-us.apache.org/repos/asf/celix/blob/3809c4cd/examples/embedding/private/src/main.c
----------------------------------------------------------------------
diff --git a/examples/embedding/private/src/main.c b/examples/embedding/private/src/main.c
index 35ddeda..c04099e 100644
--- a/examples/embedding/private/src/main.c
+++ b/examples/embedding/private/src/main.c
@@ -25,8 +25,7 @@
  */
 #include <stdlib.h>
 
-#include <apr_general.h>
-
+#include "celix_launcher.h"
 #include "celix_errno.h"
 #include "framework.h"
 #include "bundle_context.h"
@@ -36,56 +35,59 @@ struct foo {
 };
 
 struct fooSrv {
-	struct foo *handle;
-	celix_status_t (*foo)(struct foo *handle);
+    struct foo *handle;
+    celix_status_t (*foo)(struct foo *handle);
 };
 
 celix_status_t embedded_foo();
 
 int main(void) {
-	apr_status_t status = APR_SUCCESS;
-	apr_pool_t *memoryPool = NULL;
 
-	status = apr_initialize();
-	if (status != APR_SUCCESS) {
-		return CELIX_START_ERROR;
-	}
+    framework_pt framework = NULL;
+
+    properties_pt config = properties_create();
+    int rc = celixLauncher_launchWithProperties(config, &framework);
+
+    if (rc == 0) {
+        bundle_pt fwBundle = NULL;
+        framework_getFrameworkBundle(framework, &fwBundle);
+        bundle_start(fwBundle);
+
+        bundle_context_pt context = NULL;
+        bundle_getContext(fwBundle, &context);
+
+        struct foo *f = calloc(1, sizeof(*f));
+        struct fooSrv *fs = calloc(1, sizeof(*fs));
+
+        fs->handle = f;
+        fs->foo = embedded_foo;
 
-	status = apr_pool_create(&memoryPool, NULL);
-	if (status != APR_SUCCESS) {
-		return CELIX_START_ERROR;
-	}
+        service_registration_pt reg = NULL;
+        bundleContext_registerService(context, "foo", fs, NULL, &reg);
 
-	framework_pt framework = NULL;
-	framework_create(&framework, memoryPool, NULL);
-	fw_init(framework);
+        service_reference_pt ref = NULL;
+        bundleContext_getServiceReference(context, "foo", &ref);
 
-	bundle_pt fwBundle = NULL;
-	framework_getFrameworkBundle(framework, &fwBundle);
-	bundle_start(fwBundle);
+        void *fs2 = NULL;
+        bundleContext_getService(context, ref, &fs2);
 
-	bundle_context_pt context = NULL;
-	bundle_getContext(fwBundle, &context);
+        ((struct fooSrv*) fs2)->foo(((struct fooSrv*) fs2)->handle);
 
-	struct foo *f = calloc(1, sizeof(*f));
-	struct fooSrv *fs = calloc(1, sizeof(*fs));
-	fs->handle = f;
-	fs->foo = embedded_foo;
+        bundleContext_ungetServiceReference(context, ref);
+        serviceRegistration_unregister(reg);
 
-	service_registration_pt reg = NULL;
-	bundleContext_registerService(context, "foo", fs, NULL, &reg);
+        free(f);
+        free(fs);
 
-	service_reference_pt ref = NULL;
-	bundleContext_getServiceReference(context, "foo", &ref);
+        celixLauncher_destroy(framework);
+    }
 
-	void *fs2 = NULL;
-	bundleContext_getService(context, ref, &fs2);
+    return rc;
 
-	((struct fooSrv*)fs2)->foo(((struct fooSrv*)fs2)->handle);
 }
 
 celix_status_t embedded_foo() {
-	printf("foo\n");
-	return CELIX_SUCCESS;
+    printf("foo\n");
+    return CELIX_SUCCESS;
 }