celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [04/50] celix git commit: CELIX-66: Added initial code for config admin example.
Date Mon, 11 Apr 2016 10:54:31 GMT
CELIX-66: Added initial code for config admin example.


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

Branch: refs/heads/release/celix-2.0.0
Commit: d5666c57106dacc9a5bfb81e18ebc11806d7afa7
Parents: 2eac60e
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Tue Jan 26 15:49:59 2016 +0100
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Tue Jan 26 15:49:59 2016 +0100

----------------------------------------------------------------------
 config_admin/CMakeLists.txt                     |  2 +-
 config_admin/deploy.cmake                       |  7 +-
 config_admin/example/CMakeLists.txt             | 28 ++++++++
 config_admin/example/private/include/example.h  | 18 +++++
 .../example/private/src/bundle_activator.c      | 75 ++++++++++++++++++++
 config_admin/example/private/src/example.c      | 46 ++++++++++++
 6 files changed, 171 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/d5666c57/config_admin/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/config_admin/CMakeLists.txt b/config_admin/CMakeLists.txt
index 3801e6e..ff2ad15 100644
--- a/config_admin/CMakeLists.txt
+++ b/config_admin/CMakeLists.txt
@@ -20,7 +20,7 @@ celix_subproject(CONFIG_ADMIN "Option to enable building the Config Admin
Servic
 if (CONFIG_ADMIN)
 
 	add_subdirectory(service)
-#	add_subdirectory(examples)
+    add_subdirectory(example)
 	
 	if (ENABLE_TESTING)
 		find_package(CppUTest REQUIRED)

http://git-wip-us.apache.org/repos/asf/celix/blob/d5666c57/config_admin/deploy.cmake
----------------------------------------------------------------------
diff --git a/config_admin/deploy.cmake b/config_admin/deploy.cmake
index d1a769d..53bdfd7 100644
--- a/config_admin/deploy.cmake
+++ b/config_admin/deploy.cmake
@@ -16,9 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
-if (CONFIG_ADMIN)
+if (BUILD_CONFIG_ADMIN)
  	
-	deploy("config_admin1" BUNDLES config_admin shell shell_tui log_service log_writer example_test)
-	deploy("config_admin2" BUNDLES config_admin shell shell_tui log_service log_writer bundle_managed_service
bundle_configuring)
+    deploy("config_admin" BUNDLES config_admin shell shell_tui log_service log_writer config_admin_example)
 
-endif (CONFIG_ADMIN)
+endif (BUILD_CONFIG_ADMIN)

http://git-wip-us.apache.org/repos/asf/celix/blob/d5666c57/config_admin/example/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/config_admin/example/CMakeLists.txt b/config_admin/example/CMakeLists.txt
new file mode 100644
index 0000000..b19c73b
--- /dev/null
+++ b/config_admin/example/CMakeLists.txt
@@ -0,0 +1,28 @@
+
+
+SET(
+	BUNDLE_NAME 
+"config_admin_example"
+)
+
+SET(
+	BUNDLE_SYMBOLICNAME 
+"org.apache.celix.config_admin.example"
+)
+
+SET(BUNDLE_VERSION "0.0.1")
+
+include_directories(
+	"private/include"
+	"public/include"
+    ${PROJECT_SOURCE_DIR}/utils/public/include
+    ../service/public/include
+)
+
+bundle(
+config_admin_example SOURCES
+	private/src/bundle_activator
+	private/src/example
+)
+
+target_link_libraries(config_admin_example ${CELIX_FRAMEWORK_LIBRARY} ${CELIX_UTILS_LIBRARY})

http://git-wip-us.apache.org/repos/asf/celix/blob/d5666c57/config_admin/example/private/include/example.h
----------------------------------------------------------------------
diff --git a/config_admin/example/private/include/example.h b/config_admin/example/private/include/example.h
new file mode 100644
index 0000000..7239ea5
--- /dev/null
+++ b/config_admin/example/private/include/example.h
@@ -0,0 +1,18 @@
+#ifndef __EXAMPLE_H_
+#define __EXAMPLE_H_
+
+
+
+#include <celix_errno.h>
+#include <array_list.h>
+#include <properties.h>
+
+typedef struct example *example_pt;
+
+celix_status_t example_create(example_pt *component);
+celix_status_t example_start(example_pt component);
+celix_status_t example_stop(example_pt component);
+celix_status_t example_destroy(example_pt component);
+celix_status_t example_updated(example_pt component, properties_pt updatedProperties);
+
+#endif //__EXAMPLE_H_

http://git-wip-us.apache.org/repos/asf/celix/blob/d5666c57/config_admin/example/private/src/bundle_activator.c
----------------------------------------------------------------------
diff --git a/config_admin/example/private/src/bundle_activator.c b/config_admin/example/private/src/bundle_activator.c
new file mode 100644
index 0000000..55bc11e
--- /dev/null
+++ b/config_admin/example/private/src/bundle_activator.c
@@ -0,0 +1,75 @@
+#include <stdlib.h>
+#include <pthread.h>
+
+#include <constants.h>
+#include <bundle_context.h>
+#include <service_tracker.h>
+
+#include "example.h"
+#include "managed_service.h"
+
+struct activator {
+	bundle_context_pt context;
+	example_pt example;
+	managed_service_service_pt managed;
+	service_registration_pt managedServiceRegistry;
+};
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+	celix_status_t status = CELIX_SUCCESS;
+	struct activator *activator = calloc(1, sizeof(struct activator));
+	if (activator != NULL) {
+		(*userData) = activator;
+		activator->example = NULL;
+		example_create(&activator->example);
+		activator->managed = NULL;
+		activator->managedServiceRegistry = NULL;
+
+	} else {
+		status = CELIX_ENOMEM;
+	}
+	return status;
+}
+
+celix_status_t bundleActivator_start(void *userData, bundle_context_pt context) {
+	celix_status_t status = CELIX_SUCCESS;
+	struct activator *activator = userData;
+
+	example_start(activator->example);
+    
+    activator->managed = calloc(1, sizeof(*activator->managed));
+    properties_pt props = properties_create();
+
+	if (activator->managed != NULL && props != NULL) {
+        properties_set(props, "service.pid", "org.example.config.admin"); 
+        activator->managed->managedService = (void *)activator->example;
+        activator->managed->updated = (void *)example_updated;
+		bundleContext_registerService(context, (char *)  MANAGED_SERVICE_SERVICE_NAME, activator->managed,
NULL, &activator->managedServiceRegistry);
+	}
+
+	return status;
+}
+
+celix_status_t bundleActivator_stop(void *userData, bundle_context_pt context) {
+	celix_status_t status = CELIX_SUCCESS;
+	struct activator *activator = userData;
+
+	if (activator->managed != NULL) {
+		serviceRegistration_unregister(activator->managedServiceRegistry);
+	}
+	example_stop(activator->example);
+
+	return status;
+}
+
+celix_status_t bundleActivator_destroy(void *userData, bundle_context_pt context) {
+	celix_status_t status = CELIX_SUCCESS;
+	struct activator *activator = userData;
+
+	example_destroy(activator->example);
+	if (activator->managed != NULL) {
+		free(activator->managed);
+	}
+
+	return status;
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/d5666c57/config_admin/example/private/src/example.c
----------------------------------------------------------------------
diff --git a/config_admin/example/private/src/example.c b/config_admin/example/private/src/example.c
new file mode 100644
index 0000000..9158943
--- /dev/null
+++ b/config_admin/example/private/src/example.c
@@ -0,0 +1,46 @@
+#include <stdlib.h>
+
+#include <pthread.h>
+
+#include "example.h"
+
+struct example {
+};
+
+//Create function
+celix_status_t example_create(example_pt *result) {
+	celix_status_t status = CELIX_SUCCESS;
+	
+    example_pt component = calloc(1, sizeof(*component));
+	if (component != NULL) {
+		(*result) = component;
+	} else {
+		status = CELIX_ENOMEM;
+	}	
+	return status;
+}
+
+celix_status_t example_destroy(example_pt component) {
+	celix_status_t status = CELIX_SUCCESS;
+	if (component != NULL) {
+		free(component);
+	} else {
+		status = CELIX_ILLEGAL_ARGUMENT;
+	}
+	return status;
+}
+
+celix_status_t example_start(example_pt component) {
+	celix_status_t status = CELIX_SUCCESS;
+	return status;
+}
+
+celix_status_t example_stop(example_pt component) {
+	celix_status_t status = CELIX_SUCCESS;
+	return status;
+}
+
+celix_status_t example_updated(example_pt component, properties_pt updatedProperties) {
+    printf("updated called\n");
+    return CELIX_SUCCESS;
+}


Mime
View raw message