celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erjanalt...@apache.org
Subject celix git commit: Added log service example
Date Mon, 11 Sep 2017 20:26:32 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 0d5e9c814 -> c9779f9ea


Added log service example


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

Branch: refs/heads/develop
Commit: c9779f9ea2c9db7b21a8e2138788259d597c78c4
Parents: 0d5e9c8
Author: Erjan Altena <erjanaltena@gmail.com>
Authored: Mon Sep 11 22:22:47 2017 +0200
Committer: Erjan Altena <erjanaltena@gmail.com>
Committed: Mon Sep 11 22:23:01 2017 +0200

----------------------------------------------------------------------
 examples/CMakeLists.txt                         |  1 +
 examples/log_service_example/CMakeLists.txt     | 34 ++++++++
 .../log_service_example/private/src/activator.c | 85 ++++++++++++++++++++
 log_service/public/src/log_helper.c             |  1 +
 4 files changed, 121 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/c9779f9e/examples/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 122f87c..164500d 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -31,5 +31,6 @@ if (EXAMPLES)
     add_subdirectory(whiteboard)
     add_subdirectory(embedding)
     add_subdirectory(service_hook_example)
+    add_subdirectory(log_service_example)
 
 endif(EXAMPLES)

http://git-wip-us.apache.org/repos/asf/celix/blob/c9779f9e/examples/log_service_example/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/log_service_example/CMakeLists.txt b/examples/log_service_example/CMakeLists.txt
new file mode 100644
index 0000000..fbfc291
--- /dev/null
+++ b/examples/log_service_example/CMakeLists.txt
@@ -0,0 +1,34 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+#Importing and exporting libraries not (yet) work under OSX.
+
+include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
+include_directories("public/include")
+include_directories("${CMAKE_SOURCE_DIR}/log_service/public/include")
+
+add_bundle(log_service_example
+    VERSION "1.0"
+    SOURCES
+        private/src/activator.c
+        ${CMAKE_SOURCE_DIR}/log_service/public/src/log_helper.c
+)
+
+add_deploy(log_example
+    GROUP log_service
+    BUNDLES log_service_example log_service shell shell_tui
+)

http://git-wip-us.apache.org/repos/asf/celix/blob/c9779f9e/examples/log_service_example/private/src/activator.c
----------------------------------------------------------------------
diff --git a/examples/log_service_example/private/src/activator.c b/examples/log_service_example/private/src/activator.c
new file mode 100644
index 0000000..75eaf59
--- /dev/null
+++ b/examples/log_service_example/private/src/activator.c
@@ -0,0 +1,85 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership.  The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+/*
+ * activator.c
+ *
+ *  \date       Sep 11, 2017
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "bundle_activator.h"
+#include "log_helper.h"
+
+struct userData {
+	pthread_t logger_thread;
+	bool running;
+	log_helper_pt log_helper;
+};
+
+static void *loggerThread(void *userData);
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+	celix_status_t status = CELIX_SUCCESS;
+    *userData = calloc(1, sizeof(struct userData));
+    if (*userData != NULL) {
+        struct userData * data = (struct userData *) *userData;
+        status = logHelper_create(context, &data->log_helper);
+	} else {
+		status = CELIX_START_ERROR;
+	}
+	return status;
+}
+
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+	struct userData * data = (struct userData *) userData;
+	printf("Started log example\n");
+    logHelper_start(data->log_helper);
+	data->running = true;
+    pthread_create(&data->logger_thread, NULL, loggerThread, data);
+	return CELIX_SUCCESS;
+}
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+	struct userData * data = (struct userData *) userData;
+	printf("Stopping logger example\n");
+	data->running = false;
+	pthread_join(data->logger_thread, NULL);
+    logHelper_stop(data->log_helper);
+	return CELIX_SUCCESS;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+    struct userData * data = (struct userData *) userData;
+    logHelper_destroy(&data->log_helper);
+    free(userData);
+	return CELIX_SUCCESS;
+}
+
+static void *loggerThread(void *userData) {
+    struct userData * data = (struct userData *) userData;
+    while (data->running) {
+        logHelper_log(data->log_helper, OSGI_LOGSERVICE_INFO, "My log message");
+        sleep(1);
+    }
+    return NULL;
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/c9779f9e/log_service/public/src/log_helper.c
----------------------------------------------------------------------
diff --git a/log_service/public/src/log_helper.c b/log_service/public/src/log_helper.c
index 7fcb172..c0cd309 100644
--- a/log_service/public/src/log_helper.c
+++ b/log_service/public/src/log_helper.c
@@ -90,6 +90,7 @@ celix_status_t logHelper_start(log_helper_pt loghelper)
 	status = serviceTrackerCustomizer_create(loghelper, NULL, logHelper_logServiceAdded, NULL,
logHelper_logServiceRemoved, &logTrackerCustomizer);
 
 	if (status == CELIX_SUCCESS) {
+        loghelper->logServiceTracker = NULL;
 		status = serviceTracker_create(loghelper->bundleContext, (char*) OSGI_LOGSERVICE_NAME,
logTrackerCustomizer, &loghelper->logServiceTracker);
 	}
 


Mime
View raw message