You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by ab...@apache.org on 2011/11/07 19:06:11 UTC
svn commit: r1198846 [4/4] - in /incubator/celix/trunk: ./
framework/private/src/ remote_services/ remote_services/calc_shell/
remote_services/calc_shell/MANIFEST/ remote_services/calc_shell/private/
remote_services/calc_shell/private/include/ remote_s...
Added: incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_activator.c?rev=1198846&view=auto
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_activator.c (added)
+++ incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_activator.c Mon Nov 7 18:06:09 2011
@@ -0,0 +1,104 @@
+/*
+ * remote_service_admin_activator.c
+ *
+ * Created on: Sep 30, 2011
+ * Author: alexander
+ */
+#include <stdlib.h>
+
+#include "headers.h"
+#include "bundle_activator.h"
+#include "service_registration.h"
+
+#include "remote_service_admin_impl.h"
+#include "export_registration_impl.h"
+#include "import_registration_impl.h"
+
+struct activator {
+ apr_pool_t *pool;
+ remote_service_admin_t admin;
+ SERVICE_REGISTRATION registration;
+};
+
+celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData) {
+ celix_status_t status = CELIX_SUCCESS;
+ apr_pool_t *parentPool = NULL;
+ apr_pool_t *pool = NULL;
+ struct activator *activator;
+
+ status = bundleContext_getMemoryPool(context, &parentPool);
+ if (status == CELIX_SUCCESS) {
+ if (apr_pool_create(&pool, parentPool) != APR_SUCCESS) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ } else {
+ activator = apr_palloc(pool, sizeof(*activator));
+ if (!activator) {
+ status = CELIX_ENOMEM;
+ } else {
+ activator->pool = pool;
+
+ *userData = activator;
+ }
+ }
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+ remote_service_admin_service_t remoteServiceAdmin = NULL;
+
+ status = remoteServiceAdmin_create(activator->pool, context, &activator->admin);
+ if (status == CELIX_SUCCESS) {
+ remoteServiceAdmin = apr_palloc(activator->pool, sizeof(*remoteServiceAdmin));
+ if (!remoteServiceAdmin) {
+ status = CELIX_ENOMEM;
+ } else {
+ remoteServiceAdmin->admin = activator->admin;
+ remoteServiceAdmin->exportService = remoteServiceAdmin_exportService;
+ remoteServiceAdmin->getExportedServices = remoteServiceAdmin_getExportedServices;
+ remoteServiceAdmin->getImportedEndpoints = remoteServiceAdmin_getImportedEndpoints;
+ remoteServiceAdmin->importService = remoteServiceAdmin_importService;
+
+ remoteServiceAdmin->exportReference_getExportedEndpoint = exportReference_getExportedEndpoint;
+ remoteServiceAdmin->exportReference_getExportedService = exportReference_getExportedService;
+
+ remoteServiceAdmin->exportRegistration_close = exportRegistration_close;
+ remoteServiceAdmin->exportRegistration_getException = exportRegistration_getException;
+ remoteServiceAdmin->exportRegistration_getExportReference = exportRegistration_getExportReference;
+
+ remoteServiceAdmin->importReference_getImportedEndpoint = importReference_getImportedEndpoint;
+ remoteServiceAdmin->importReference_getImportedService = importReference_getImportedService;
+
+ remoteServiceAdmin->importRegistration_close = importRegistration_close;
+ remoteServiceAdmin->importRegistration_getException = importRegistration_getException;
+ remoteServiceAdmin->importRegistration_getImportReference = importRegistration_getImportReference;
+
+ status = bundleContext_registerService(context, REMOTE_SERVICE_ADMIN, remoteServiceAdmin, NULL, &activator->registration);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ remoteServiceAdmin_stop(activator->admin);
+ serviceRegistration_unregister(activator->registration);
+ activator->registration = NULL;
+
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+ return status;
+}
+
+
Added: incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c?rev=1198846&view=auto
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c (added)
+++ incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c Mon Nov 7 18:06:09 2011
@@ -0,0 +1,277 @@
+/*
+ * remote_service_admin_impl.c
+ *
+ * Created on: Sep 30, 2011
+ * Author: alexander
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <apr_strings.h>
+
+#include "headers.h"
+#include "remote_service_admin_impl.h"
+#include "export_registration_impl.h"
+#include "import_registration_impl.h"
+#include "remote_constants.h"
+#include "constants.h"
+#include "utils.h"
+#include "bundle_context.h"
+#include "bundle.h"
+
+static const char *ajax_reply_start =
+ "HTTP/1.1 200 OK\r\n"
+ "Cache: no-cache\r\n"
+ "Content-Type: application/x-javascript\r\n"
+ "\r\n";
+
+void *remoteServiceAdmin_callback(enum mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info);
+celix_status_t remoteServiceAdmin_installEndpoint(remote_service_admin_t admin, export_registration_t registration, SERVICE_REFERENCE reference, char *interface);
+celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_t admin, PROPERTIES serviceProperties, PROPERTIES endpointProperties, endpoint_description_t *description);
+
+celix_status_t remoteServiceAdmin_create(apr_pool_t *pool, BUNDLE_CONTEXT context, remote_service_admin_t *admin) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *admin = apr_palloc(pool, sizeof(**admin));
+ if (!*admin) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*admin)->pool = pool;
+ (*admin)->context = context;
+ (*admin)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL);
+ (*admin)->importedServices = hashMap_create(NULL, NULL, NULL, NULL);
+
+ // Start webserver
+ const char *port = getenv("RSA_PORT");
+ const char *options[] = {"listening_ports", port, NULL};
+ (*admin)->ctx = mg_start(remoteServiceAdmin_callback, (*admin), options);
+ printf("Mongoose started on: %s\n", mg_get_option((*admin)->ctx, "listening_ports"));
+ }
+
+ return status;
+}
+
+celix_status_t remoteServiceAdmin_stop(remote_service_admin_t admin) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ HASH_MAP_ITERATOR iter = hashMapIterator_create(admin->exportedServices);
+ while (hashMapIterator_hasNext(iter)) {
+ ARRAY_LIST exports = hashMapIterator_nextValue(iter);
+ int i;
+ for (i = 0; i < arrayList_size(exports); i++) {
+ export_registration_t export = arrayList_get(exports, i);
+ exportRegistration_stopTracking(export);
+ }
+ }
+ iter = hashMapIterator_create(admin->importedServices);
+ while (hashMapIterator_hasNext(iter)) {
+ ARRAY_LIST exports = hashMapIterator_nextValue(iter);
+ int i;
+ for (i = 0; i < arrayList_size(exports); i++) {
+ import_registration_t export = arrayList_get(exports, i);
+ importRegistration_stopTracking(export);
+ }
+ }
+
+ return status;
+}
+
+/**
+ * Request: http://host:port/services/{service}/{request}
+ */
+void *remoteServiceAdmin_callback(enum mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info) {
+ if (request_info->uri != NULL) {
+ printf("RSA Handle request: %s\n", request_info->uri);
+ remote_service_admin_t rsa = request_info->user_data;
+
+ if (strncmp(request_info->uri, "/services/", 10) == 0) {
+ // uri = /services/myservice/call
+ char *uri = request_info->uri;
+ // rest = myservice/call
+ char *rest = uri+10;
+ int length = strlen(rest);
+ char *callStart = strchr(rest, '/');
+ int pos = callStart - rest;
+ char service[pos+1];
+ strncpy(service, rest, pos);
+ service[pos] = '\0';
+ printf("RSA Find Handler for Service: %s\n", service);
+
+ char request[length - pos];
+ strncpy(request, rest + pos + 1, length - pos);
+ printf("RSA Send Request: %s\n", request);
+
+ const char *lengthStr = mg_get_header(conn, (const char *) "Content-Length");
+ int datalength = apr_atoi64(lengthStr);
+ char data[datalength+1];
+ mg_read(conn, data, datalength);
+ data[datalength] = '\0';
+
+ HASH_MAP_ITERATOR iter = hashMapIterator_create(rsa->exportedServices);
+ while (hashMapIterator_hasNext(iter)) {
+ HASH_MAP_ENTRY entry = hashMapIterator_nextEntry(iter);
+ ARRAY_LIST exports = hashMapEntry_getValue(entry);
+ int expIt = 0;
+ for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
+ export_registration_t export = arrayList_get(exports, expIt);
+ if (strcmp(service, export->endpointDescription->service) == 0) {
+ printf("RSA Sending Request: %s\n", request);
+ char *reply = NULL;
+ export->endpoint->handleRequest(export->endpoint->endpoint, request, data, &reply);
+ if (reply != NULL) {
+ mg_printf(conn, "%s", ajax_reply_start);
+ mg_printf(conn, "%s", reply);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return "";
+}
+
+celix_status_t remoteServiceAdmin_exportService(remote_service_admin_t admin, SERVICE_REFERENCE reference, PROPERTIES properties, ARRAY_LIST *registrations) {
+ celix_status_t status = CELIX_SUCCESS;
+ *registrations = arrayList_create();
+
+
+ char *exports = properties_get(reference->registration->properties, (char *) SERVICE_EXPORTED_INTERFACES);
+ char *provided = properties_get(reference->registration->properties, (char *) OBJECTCLASS);
+
+ if (exports == NULL || provided == NULL) {
+ printf("RSA Export Service - No Services to export.\n");
+ } else {
+ ARRAY_LIST interfaces = arrayList_create();
+ if (strcmp(string_trim(exports), "*") == 0) {
+ char *token;
+ char *interface = apr_strtok(provided, ",", &token);
+ while (interface != NULL) {
+ arrayList_add(interfaces, string_trim(interface));
+ interface = apr_strtok(NULL, ",", &token);
+ }
+ } else {
+ char *exportToken;
+ char *providedToken;
+
+ char *pinterface = apr_strtok(provided, ",", &providedToken);
+ while (pinterface != NULL) {
+ char *einterface = apr_strtok(exports, ",", &exportToken);
+ while (einterface != NULL) {
+ if (strcmp(einterface, pinterface) == 0) {
+ arrayList_add(interfaces, einterface);
+ }
+ einterface = apr_strtok(NULL, ",", &exportToken);
+ }
+ pinterface = apr_strtok(NULL, ",", &providedToken);
+ }
+ }
+
+ if (arrayList_size(interfaces) != 0) {
+ int iter = 0;
+ for (iter = 0; iter < arrayList_size(interfaces); iter++) {
+ char *interface = arrayList_get(interfaces, iter);
+ export_registration_t registration = NULL;
+
+ exportRegistration_create(admin->pool, reference, NULL, admin, admin->context, ®istration);
+ arrayList_add(*registrations, registration);
+
+ remoteServiceAdmin_installEndpoint(admin, registration, reference, interface);
+ exportRegistration_startTracking(registration);
+ }
+ hashMap_put(admin->exportedServices, reference, *registrations);
+ }
+ }
+
+
+ printf("RSA export service\n");
+ return status;
+}
+
+celix_status_t remoteServiceAdmin_installEndpoint(remote_service_admin_t admin, export_registration_t registration, SERVICE_REFERENCE reference, char *interface) {
+ celix_status_t status = CELIX_SUCCESS;
+ BUNDLE bundle = NULL;
+ PROPERTIES endpointProperties = properties_create();
+
+ // Find correct bundle
+// bundleContext_installBundle(admin->context, "path/to/bundle.zip", &bundle);
+// bundle_start(bundle, 0);
+
+ char *service = "/services/example";
+ properties_set(endpointProperties, (char *) SERVICE_LOCATION, apr_pstrdup(admin->pool, service));
+
+ endpoint_description_t endpointDescription = NULL;
+ remoteServiceAdmin_createEndpointDescription(admin, reference->registration->properties, endpointProperties, &endpointDescription);
+ exportRegistration_setEndpointDescription(registration, endpointDescription);
+
+ return status;
+}
+
+celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_t admin, PROPERTIES serviceProperties, PROPERTIES endpointProperties, endpoint_description_t *description) {
+ celix_status_t status = CELIX_SUCCESS;
+
+// *description = apr_palloc(admin->pool, sizeof(*description));
+ *description = malloc(sizeof(*description));
+ if (!*description) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*description)->properties = endpointProperties;
+ (*description)->serviceId = apr_atoi64(properties_get(serviceProperties, (char *) SERVICE_ID));
+ (*description)->id = properties_get(endpointProperties, (char *) SERVICE_LOCATION);
+ (*description)->service = strdup(properties_get(serviceProperties, (char *) OBJECTCLASS));
+ }
+
+ return status;
+}
+
+celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_t admin, ARRAY_LIST *services) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_t admin, ARRAY_LIST *services) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t remoteServiceAdmin_importService(remote_service_admin_t admin, endpoint_description_t endpoint, import_registration_t *registration) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ printf("RSA: Import service %s\n", endpoint->service);
+ importRegistration_create(admin->pool, endpoint, admin, admin->context, registration);
+
+ ARRAY_LIST importedRegs = hashMap_get(admin->importedServices, endpoint);
+ if (importedRegs == NULL) {
+ importedRegs = arrayList_create();
+ hashMap_put(admin->importedServices, endpoint, importedRegs);
+ }
+ arrayList_add(importedRegs, *registration);
+
+ importRegistration_startTracking(*registration);
+
+ return status;
+}
+
+
+celix_status_t exportReference_getExportedEndpoint(export_reference_t reference, endpoint_description_t *endpoint) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *endpoint = reference->endpoint;
+
+ return status;
+}
+
+celix_status_t exportReference_getExportedService(export_reference_t reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t importReference_getImportedEndpoint(import_reference_t reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t importReference_getImportedService(import_reference_t reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
Added: incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_constants.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_constants.h?rev=1198846&view=auto
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_constants.h (added)
+++ incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_constants.h Mon Nov 7 18:06:09 2011
@@ -0,0 +1,16 @@
+/*
+ * remote_constants.h
+ *
+ * Created on: Sep 30, 2011
+ * Author: alexander
+ */
+
+#ifndef REMOTE_CONSTANTS_H_
+#define REMOTE_CONSTANTS_H_
+
+static const char * const SERVICE_EXPORTED_INTERFACES = "service.exported.interfaces";
+static const char * const ENDPOINT_FRAMEWORK_UUID = "endpoint.framework.uuid";
+
+static const char * const SERVICE_LOCATION = "service.location";
+
+#endif /* REMOTE_CONSTANTS_H_ */
Added: incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint.h?rev=1198846&view=auto
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint.h (added)
+++ incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint.h Mon Nov 7 18:06:09 2011
@@ -0,0 +1,24 @@
+/*
+ * endpoint.h
+ *
+ * Created on: Oct 7, 2011
+ * Author: alexander
+ */
+
+#ifndef REMOTE_ENDPOINT_H_
+#define REMOTE_ENDPOINT_H_
+
+#define REMOTE_ENDPOINT "remote_endpoint"
+
+typedef struct remote_endpoint *remote_endpoint_t;
+
+struct remote_endpoint_service {
+ remote_endpoint_t endpoint;
+ celix_status_t (*setService)(remote_endpoint_t endpoint, void *service);
+ celix_status_t (*handleRequest)(remote_endpoint_t endpoint, char *request, char *data, char **reply);
+};
+
+typedef struct remote_endpoint_service *remote_endpoint_service_t;
+
+
+#endif /* REMOTE_ENDPOINT_H_ */
Added: incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint_impl.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint_impl.h?rev=1198846&view=auto
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint_impl.h (added)
+++ incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint_impl.h Mon Nov 7 18:06:09 2011
@@ -0,0 +1,17 @@
+/*
+ * remote_endpoint_impl.h
+ *
+ * Created on: Oct 11, 2011
+ * Author: alexander
+ */
+
+#ifndef REMOTE_ENDPOINT_IMPL_H_
+#define REMOTE_ENDPOINT_IMPL_H_
+
+#include "remote_endpoint.h"
+
+struct remote_endpoint {
+ void *service;
+};
+
+#endif /* REMOTE_ENDPOINT_IMPL_H_ */
Added: incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h?rev=1198846&view=auto
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h (added)
+++ incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h Mon Nov 7 18:06:09 2011
@@ -0,0 +1,22 @@
+/*
+ * remote_proxy.h
+ *
+ * Created on: Oct 13, 2011
+ * Author: alexander
+ */
+
+#ifndef REMOTE_PROXY_H_
+#define REMOTE_PROXY_H_
+
+#include "endpoint_listener.h"
+
+#define REMOTE_PROXY "remote_proxy"
+
+struct remote_proxy_service {
+ void *proxy;
+ celix_status_t (*setEndpointDescription)(void *proxy, endpoint_description_t service);
+};
+
+typedef struct remote_proxy_service *remote_proxy_service_t;
+
+#endif /* REMOTE_PROXY_H_ */
Added: incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_service_admin.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_service_admin.h?rev=1198846&view=auto
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_service_admin.h (added)
+++ incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_service_admin.h Mon Nov 7 18:06:09 2011
@@ -0,0 +1,48 @@
+/*
+ * remote_service_admin.h
+ *
+ * Created on: Sep 30, 2011
+ * Author: alexander
+ */
+
+#ifndef REMOTE_SERVICE_ADMIN_H_
+#define REMOTE_SERVICE_ADMIN_H_
+
+#include "endpoint_listener.h"
+
+#define REMOTE_SERVICE_ADMIN "remote_service_admin"
+
+typedef struct export_reference *export_reference_t;
+typedef struct export_registration *export_registration_t;
+typedef struct import_reference *import_reference_t;
+typedef struct import_registration *import_registration_t;
+typedef struct remote_service_admin *remote_service_admin_t;
+
+struct remote_service_admin_service {
+ remote_service_admin_t admin;
+ celix_status_t (*exportService)(remote_service_admin_t admin, SERVICE_REFERENCE reference, PROPERTIES properties, ARRAY_LIST *registrations);
+ celix_status_t (*getExportedServices)(remote_service_admin_t admin, ARRAY_LIST *services);
+ celix_status_t (*getImportedEndpoints)(remote_service_admin_t admin, ARRAY_LIST *services);
+ celix_status_t (*importService)(remote_service_admin_t admin, endpoint_description_t endpoint, import_registration_t *registration);
+
+
+ celix_status_t (*exportReference_getExportedEndpoint)(export_reference_t reference, endpoint_description_t *endpoint);
+ celix_status_t (*exportReference_getExportedService)(export_reference_t reference);
+
+ celix_status_t (*exportRegistration_close)(export_registration_t registration);
+ celix_status_t (*exportRegistration_getException)(export_registration_t registration);
+ celix_status_t (*exportRegistration_getExportReference)(export_registration_t registration, export_reference_t *reference);
+
+ celix_status_t (*importReference_getImportedEndpoint)(import_reference_t reference);
+ celix_status_t (*importReference_getImportedService)(import_reference_t reference);
+
+ celix_status_t (*importRegistration_close)(import_registration_t registration);
+ celix_status_t (*importRegistration_getException)(import_registration_t registration);
+ celix_status_t (*importRegistration_getImportReference)(import_registration_t registration);
+
+};
+
+typedef struct remote_service_admin_service *remote_service_admin_service_t;
+
+
+#endif /* REMOTE_SERVICE_ADMIN_H_ */
Added: incubator/celix/trunk/remote_services/topology_manager/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/topology_manager/CMakeLists.txt?rev=1198846&view=auto
==============================================================================
--- incubator/celix/trunk/remote_services/topology_manager/CMakeLists.txt (added)
+++ incubator/celix/trunk/remote_services/topology_manager/CMakeLists.txt Mon Nov 7 18:06:09 2011
@@ -0,0 +1,26 @@
+# 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.
+
+include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
+include_directories("${PROJECT_SOURCE_DIR}/remote_services/topology_manager/private/include")
+include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
+include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
+
+add_library(topology_manager SHARED private/src/topology_manager private/src/activator)
+target_link_libraries(topology_manager framework)
+
+bundle(topology_manager)
Added: incubator/celix/trunk/remote_services/topology_manager/MANIFEST/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/topology_manager/MANIFEST/MANIFEST.MF?rev=1198846&view=auto
==============================================================================
--- incubator/celix/trunk/remote_services/topology_manager/MANIFEST/MANIFEST.MF (added)
+++ incubator/celix/trunk/remote_services/topology_manager/MANIFEST/MANIFEST.MF Mon Nov 7 18:06:09 2011
@@ -0,0 +1,5 @@
+Bundle-SymbolicName: topology_manager
+Bundle-Version: 1.0.0
+library: topology_manager
+Import-Service: remote_service_admin, endpoint_listener
+Export-Service: endpoint_listener
Added: incubator/celix/trunk/remote_services/topology_manager/private/include/topology_manager.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/topology_manager/private/include/topology_manager.h?rev=1198846&view=auto
==============================================================================
--- incubator/celix/trunk/remote_services/topology_manager/private/include/topology_manager.h (added)
+++ incubator/celix/trunk/remote_services/topology_manager/private/include/topology_manager.h Mon Nov 7 18:06:09 2011
@@ -0,0 +1,31 @@
+/*
+ * topology_manager.h
+ *
+ * Created on: Sep 29, 2011
+ * Author: alexander
+ */
+
+#ifndef TOPOLOGY_MANAGER_H_
+#define TOPOLOGY_MANAGER_H_
+
+#include "endpoint_listener.h"
+
+typedef struct topology_manager *topology_manager_t;
+
+celix_status_t topologyManager_create(BUNDLE_CONTEXT context, apr_pool_t *pool, topology_manager_t *manager);
+
+celix_status_t topologyManager_rsaAdding(void *handle, SERVICE_REFERENCE reference, void **service);
+celix_status_t topologyManager_rsaAdded(void *handle, SERVICE_REFERENCE reference, void *service);
+celix_status_t topologyManager_rsaModified(void *handle, SERVICE_REFERENCE reference, void *service);
+celix_status_t topologyManager_rsaRemoved(void *handle, SERVICE_REFERENCE reference, void *service);
+
+celix_status_t topologyManager_serviceChanged(void *listener, SERVICE_EVENT event);
+
+celix_status_t topologyManager_endpointAdded(void *handle, endpoint_description_t endpoint, char *machtedFilter);
+celix_status_t topologyManager_endpointRemoved(void *handle, endpoint_description_t endpoint, char *machtedFilter);
+
+celix_status_t topologyManager_importService(topology_manager_t manager, endpoint_description_t endpoint);
+celix_status_t topologyManager_exportService(topology_manager_t manager, SERVICE_REFERENCE reference);
+celix_status_t topologyManager_removeService(topology_manager_t manager, SERVICE_REFERENCE reference);
+
+#endif /* TOPOLOGY_MANAGER_H_ */
Added: incubator/celix/trunk/remote_services/topology_manager/private/src/activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/topology_manager/private/src/activator.c?rev=1198846&view=auto
==============================================================================
--- incubator/celix/trunk/remote_services/topology_manager/private/src/activator.c (added)
+++ incubator/celix/trunk/remote_services/topology_manager/private/src/activator.c Mon Nov 7 18:06:09 2011
@@ -0,0 +1,125 @@
+/*
+ * dependency_activator.c
+ *
+ * Created on: Sep 29, 2011
+ * Author: alexander
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "headers.h"
+#include "bundle_activator.h"
+#include "service_tracker.h"
+#include "service_registration.h"
+
+#include "topology_manager.h"
+#include "endpoint_listener.h"
+
+struct activator {
+ apr_pool_t *pool;
+ BUNDLE_CONTEXT context;
+
+ topology_manager_t manager;
+
+ SERVICE_TRACKER remoteServiceAdminTracker;
+ SERVICE_LISTENER serviceListener;
+
+ SERVICE_REGISTRATION endpointListenerService;
+};
+
+celix_status_t bundleActivator_createRSATracker(struct activator *activator, SERVICE_TRACKER *tracker);
+celix_status_t bundleActivator_createServiceListener(struct activator *activator, SERVICE_LISTENER *listener);
+
+celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData) {
+ celix_status_t status = CELIX_SUCCESS;
+ apr_pool_t *parentPool = NULL;
+ apr_pool_t *pool = NULL;
+ struct activator *activator = NULL;
+
+ bundleContext_getMemoryPool(context, &parentPool);
+ apr_pool_create(&pool, parentPool);
+ activator = apr_palloc(pool, sizeof(*activator));
+ if (!activator) {
+ status = CELIX_ENOMEM;
+ } else {
+ activator->pool = pool;
+ activator->context = context;
+
+ topologyManager_create(context, pool, &activator->manager);
+
+ bundleActivator_createRSATracker(activator, &activator->remoteServiceAdminTracker);
+ bundleActivator_createServiceListener(activator, &activator->serviceListener);
+
+ *userData = activator;
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_createRSATracker(struct activator *activator, SERVICE_TRACKER *tracker) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ SERVICE_TRACKER_CUSTOMIZER custumizer = (SERVICE_TRACKER_CUSTOMIZER) apr_palloc(activator->pool, sizeof(*custumizer));
+ if (!custumizer) {
+ status = CELIX_ENOMEM;
+ } else {
+ custumizer->handle = activator->manager;
+ custumizer->addingService = topologyManager_rsaAdding;
+ custumizer->addedService = topologyManager_rsaAdded;
+ custumizer->modifiedService = topologyManager_rsaModified;
+ custumizer->removedService = topologyManager_rsaRemoved;
+
+ status = serviceTracker_create(activator->context, "remote_service_admin", custumizer, tracker);
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_createServiceListener(struct activator *activator, SERVICE_LISTENER *listener) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *listener = apr_palloc(activator->pool, sizeof(*listener));
+ if (!*listener) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*listener)->handle = activator->manager;
+ (*listener)->serviceChanged = topologyManager_serviceChanged;
+ }
+
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+ apr_pool_t *pool = NULL;
+ apr_pool_create(&pool, activator->pool);
+
+ endpoint_listener_t endpointListener = apr_palloc(pool, sizeof(*endpointListener));
+ endpointListener->handle = activator->manager;
+ endpointListener->endpointAdded = topologyManager_endpointAdded;
+ endpointListener->endpointRemoved = topologyManager_endpointRemoved;
+ bundleContext_registerService(context, (char *) endpoint_listener_service, endpointListener, NULL, &activator->endpointListenerService);
+
+ bundleContext_addServiceListener(context, activator->serviceListener, NULL);
+ serviceTracker_open(activator->remoteServiceAdminTracker);
+
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+ celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ serviceRegistration_unregister(activator->endpointListenerService);
+ serviceTracker_close(activator->remoteServiceAdminTracker);
+ bundleContext_removeServiceListener(context, activator->serviceListener);
+
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT context) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
Added: incubator/celix/trunk/remote_services/topology_manager/private/src/topology_manager.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/topology_manager/private/src/topology_manager.c?rev=1198846&view=auto
==============================================================================
--- incubator/celix/trunk/remote_services/topology_manager/private/src/topology_manager.c (added)
+++ incubator/celix/trunk/remote_services/topology_manager/private/src/topology_manager.c Mon Nov 7 18:06:09 2011
@@ -0,0 +1,202 @@
+/*
+ * topology_manager.c
+ *
+ * Created on: Sep 29, 2011
+ * Author: alexander
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "headers.h"
+#include "topology_manager.h"
+#include "bundle_context.h"
+#include "constants.h"
+#include "module.h"
+#include "bundle.h"
+#include "remote_service_admin.h"
+#include "remote_constants.h"
+
+struct topology_manager {
+ apr_pool_t *pool;
+ BUNDLE_CONTEXT context;
+
+ ARRAY_LIST rsaList;
+ HASH_MAP exportedServices;
+};
+
+celix_status_t topologyManager_notifyListeners(topology_manager_t manager, remote_service_admin_service_t rsa, ARRAY_LIST registrations);
+
+celix_status_t topologyManager_create(BUNDLE_CONTEXT context, apr_pool_t *pool, topology_manager_t *manager) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ *manager = apr_palloc(pool, sizeof(**manager));
+ if (!*manager) {
+ status = CELIX_ENOMEM;
+ } else {
+ (*manager)->pool = pool;
+ (*manager)->context = context;
+ (*manager)->rsaList = arrayList_create();
+ (*manager)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL);
+ }
+
+ return status;
+}
+
+celix_status_t topologyManager_rsaAdding(void * handle, SERVICE_REFERENCE reference, void **service) {
+ celix_status_t status = CELIX_SUCCESS;
+ topology_manager_t manager = handle;
+
+ bundleContext_getService(manager->context, reference, service);
+
+ return status;
+}
+
+celix_status_t topologyManager_rsaAdded(void * handle, SERVICE_REFERENCE reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+ topology_manager_t manager = handle;
+
+ printf("TOPOLOGY_MANAGER: Added RSA\n");
+ arrayList_add(manager->rsaList, service);
+
+ return status;
+}
+
+celix_status_t topologyManager_rsaModified(void * handle, SERVICE_REFERENCE reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+ topology_manager_t manager = handle;
+ return status;
+}
+
+celix_status_t topologyManager_rsaRemoved(void * handle, SERVICE_REFERENCE reference, void * service) {
+ celix_status_t status = CELIX_SUCCESS;
+ topology_manager_t manager = handle;
+
+ printf("TOPOLOGY_MANAGER: Removed RSA\n");
+ arrayList_removeElement(manager->rsaList, service);
+
+ return status;
+}
+
+celix_status_t topologyManager_serviceChanged(void *listener, SERVICE_EVENT event) {
+ celix_status_t status = CELIX_SUCCESS;
+ SERVICE_LISTENER listen = listener;
+ topology_manager_t manager = listen->handle;
+ PROPERTIES props = event->reference->registration->properties;
+ char *name = properties_get(props, (char *) OBJECTCLASS);
+ char *export = properties_get(props, (char *) SERVICE_EXPORTED_INTERFACES);
+
+ if (event->type == REGISTERED) {
+ if (export != NULL) {
+ printf("TOPOLOGY_MANAGER: Service registered: %s\n", name);
+ topologyManager_exportService(manager, event->reference);
+ }
+ } else if (event->type == UNREGISTERING) {
+ printf("TOPOLOGY_MANAGER: Service unregistering: %s\n", name);
+ topologyManager_removeService(manager, event->reference);
+ }
+
+ return status;
+}
+
+celix_status_t topologyManager_endpointAdded(void *handle, endpoint_description_t endpoint, char *machtedFilter) {
+ celix_status_t status = CELIX_SUCCESS;
+ topology_manager_t manager = handle;
+ printf("TOPOLOGY_MANAGER: Endpoint added\n");
+
+ topologyManager_importService(manager, endpoint);
+
+
+ return status;
+}
+
+celix_status_t topologyManager_endpointRemoved(void *handle, endpoint_description_t endpoint, char *machtedFilter) {
+ celix_status_t status = CELIX_SUCCESS;
+ return status;
+}
+
+celix_status_t topologyManager_exportService(topology_manager_t manager, SERVICE_REFERENCE reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ HASH_MAP exports = hashMap_create(NULL, NULL, NULL, NULL);
+
+ hashMap_put(manager->exportedServices, reference, exports);
+
+ if (arrayList_size(manager->rsaList) == 0) {
+ char *symbolicName = module_getSymbolicName(bundle_getCurrentModule(reference->bundle));
+ printf("TOPOLOGY_MANAGER: No RemoteServiceAdmin available, unable to export service from bundle %s.\n", symbolicName);
+ } else {
+ int size = arrayList_size(manager->rsaList);
+ int iter = 0;
+ for (iter = 0; iter < size; iter++) {
+ remote_service_admin_service_t rsa = arrayList_get(manager->rsaList, iter);
+
+ ARRAY_LIST endpoints = NULL;
+ rsa->exportService(rsa->admin, reference, NULL, &endpoints);
+ hashMap_put(exports, rsa, endpoints);
+ topologyManager_notifyListeners(manager, rsa, endpoints);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t topologyManager_notifyListeners(topology_manager_t manager, remote_service_admin_service_t rsa, ARRAY_LIST registrations) {
+ celix_status_t status = CELIX_SUCCESS;
+ ARRAY_LIST endpointListeners = NULL;
+
+ status = bundleContext_getServiceReferences(manager->context, endpoint_listener_service, NULL, &endpointListeners);
+ if (status == CELIX_SUCCESS) {
+ if (endpointListeners != NULL) {
+ int eplIt;
+ for (eplIt = 0; eplIt < arrayList_size(endpointListeners); eplIt++) {
+ SERVICE_REFERENCE eplRef = arrayList_get(endpointListeners, eplIt);
+ endpoint_listener_t epl = NULL;
+ status = bundleContext_getService(manager->context, eplRef, (void **) &epl);
+ if (status == CELIX_SUCCESS) {
+ int regIt;
+ for (regIt = 0; regIt < arrayList_size(registrations); regIt++) {
+ export_registration_t export = arrayList_get(registrations, regIt);
+ export_reference_t reference = NULL;
+ endpoint_description_t endpoint = NULL;
+ rsa->exportRegistration_getExportReference(export, &reference);
+ rsa->exportReference_getExportedEndpoint(reference, &endpoint);
+ status = epl->endpointAdded(epl->handle, endpoint, NULL);
+ }
+ }
+ }
+ }
+ }
+
+ return status;
+}
+
+celix_status_t topologyManager_importService(topology_manager_t manager, endpoint_description_t endpoint) {
+ celix_status_t status = CELIX_SUCCESS;
+ HASH_MAP exports = hashMap_create(NULL, NULL, NULL, NULL);
+
+ //hashMap_put(manager->exportedServices, reference, exports);
+
+ if (arrayList_size(manager->rsaList) == 0) {
+ printf("TOPOLOGY_MANAGER: No RemoteServiceAdmin available, unable to import service %s.\n", endpoint->service);
+ } else {
+ int size = arrayList_size(manager->rsaList);
+ int iter = 0;
+ for (iter = 0; iter < size; iter++) {
+ remote_service_admin_service_t rsa = arrayList_get(manager->rsaList, iter);
+
+ import_registration_t import = NULL;
+ rsa->importService(rsa->admin, endpoint, &import);
+ //hashMap_put(exports, rsa, endpoints);
+ }
+ }
+
+ return status;
+}
+
+celix_status_t topologyManager_removeService(topology_manager_t manager, SERVICE_REFERENCE reference) {
+ celix_status_t status = CELIX_SUCCESS;
+ char *name = properties_get(reference->registration->properties, (char *) OBJECTCLASS);
+
+ printf("TOPOLOGY_MANAGER: Remove Service: %s.\n", name);
+
+ return status;
+}