Return-Path: X-Original-To: apmail-celix-commits-archive@www.apache.org Delivered-To: apmail-celix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EBC8D19C04 for ; Mon, 11 Apr 2016 12:00:10 +0000 (UTC) Received: (qmail 21306 invoked by uid 500); 11 Apr 2016 12:00:10 -0000 Delivered-To: apmail-celix-commits-archive@celix.apache.org Received: (qmail 21227 invoked by uid 500); 11 Apr 2016 12:00:10 -0000 Mailing-List: contact commits-help@celix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@celix.apache.org Delivered-To: mailing list commits@celix.apache.org Received: (qmail 21152 invoked by uid 99); 11 Apr 2016 12:00:10 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Apr 2016 12:00:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9B20CDFBA3; Mon, 11 Apr 2016 12:00:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: pnoltes@apache.org To: commits@celix.apache.org Date: Mon, 11 Apr 2016 12:00:11 -0000 Message-Id: In-Reply-To: <3aba73c7f879491bb1a81d4d4f94f182@git.apache.org> References: <3aba73c7f879491bb1a81d4d4f94f182@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [02/50] celix git commit: CELIX-66: Added initial code for config admin example. 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/master Commit: d5666c57106dacc9a5bfb81e18ebc11806d7afa7 Parents: 2eac60e Author: Pepijn Noltes Authored: Tue Jan 26 15:49:59 2016 +0100 Committer: Pepijn Noltes 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 +#include +#include + +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 +#include + +#include +#include +#include + +#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 + +#include + +#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; +}