incubator-celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpe...@apache.org
Subject svn commit: r1608661 - in /incubator/celix/trunk/remote_services: calculator_proxy/private/include/ calculator_proxy/private/src/ discovery_slp/private/src/ remote_service_admin/private/include/ remote_service_admin/public/include/ remote_service_admin...
Date Tue, 08 Jul 2014 05:11:05 GMT
Author: bpetri
Date: Tue Jul  8 05:11:04 2014
New Revision: 1608661

URL: http://svn.apache.org/r1608661
Log:

CELIX-121

implemented proxyFactory for remoteServiceAdmin


Modified:
    incubator/celix/trunk/remote_services/calculator_proxy/private/include/calculator_proxy_impl.h
    incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c
    incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c
    incubator/celix/trunk/remote_services/discovery_slp/private/src/discovery.c
    incubator/celix/trunk/remote_services/remote_service_admin/private/include/import_registration_impl.h
    incubator/celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
    incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h
    incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_service_admin.h
    incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/import_registration_impl.c
    incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c
    incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
    incubator/celix/trunk/remote_services/remote_service_admin_shm/private/src/import_registration_impl.c
    incubator/celix/trunk/remote_services/remote_service_admin_shm/private/src/remote_service_admin_activator.c
    incubator/celix/trunk/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
    incubator/celix/trunk/remote_services/topology_manager/private/src/topology_manager.c

Modified: incubator/celix/trunk/remote_services/calculator_proxy/private/include/calculator_proxy_impl.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/calculator_proxy/private/include/calculator_proxy_impl.h?rev=1608661&r1=1608660&r2=1608661&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/calculator_proxy/private/include/calculator_proxy_impl.h (original)
+++ incubator/celix/trunk/remote_services/calculator_proxy/private/include/calculator_proxy_impl.h Tue Jul  8 05:11:04 2014
@@ -33,24 +33,29 @@
 
 #include "calculator_service.h"
 #include "remote_proxy.h"
+#include "constants.h"
+#include "bundle_context.h"
+#include "hash_map.h"
 
 #include "endpoint_listener.h"
 
 
 struct calculator {
 	apr_pool_t *pool;
+	bundle_context_pt context;
+
 	endpoint_description_pt endpoint;
 	sendToHandle sendToCallback;
 	void * sendToHandler;
 };
 
-celix_status_t calculatorProxy_create(apr_pool_t *pool, calculator_pt *endpoint);
+
+celix_status_t calculatorProxy_create(apr_pool_t *pool, bundle_context_pt context, calculator_pt *endpoint);
 celix_status_t calculatorProxy_add(calculator_pt calculator, double a, double b, double *result);
 celix_status_t calculatorProxy_sub(calculator_pt calculator, double a, double b, double *result);
 celix_status_t calculatorProxy_sqrt(calculator_pt calculator, double a, double *result);
 
-celix_status_t calculatorProxy_setEndpointDescription(void *proxy, endpoint_description_pt endpoint);
-celix_status_t calculatorProxy_setHandler(void *proxy, void *handler);
-celix_status_t calculatorProxy_setCallback(void *proxy, sendToHandle callback);
+celix_status_t calculatorProxy_registerProxyService(void* proxyFactoryService, endpoint_description_pt endpoint, void* handler, sendToHandle callback);
+celix_status_t calculatorProxy_unregisterProxyService(void* proxyFactoryService, endpoint_description_pt endpoint);
 
 #endif /* CALCULATOR_PROXY_IMPL_H_ */

Modified: incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c?rev=1608661&r1=1608660&r2=1608661&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c (original)
+++ incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c Tue Jul  8 05:11:04 2014
@@ -26,16 +26,13 @@
 #include <stdlib.h>
 
 #include "bundle_activator.h"
+#include "service_registration.h"
 
 #include "calculator_proxy_impl.h"
 
-#include "service_registration.h"
-
 struct activator {
 	apr_pool_t *pool;
-
-	service_registration_pt proxy;
-	service_registration_pt service;
+	service_registration_pt proxyFactoryService;
 };
 
 celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
@@ -55,8 +52,7 @@ celix_status_t bundleActivator_create(bu
 				status = CELIX_ENOMEM;
 			} else {
 				activator->pool = pool;
-				activator->proxy = NULL;
-				activator->service = NULL;
+				activator->proxyFactoryService = NULL;
 
 				*userData = activator;
 			}
@@ -69,32 +65,22 @@ celix_status_t bundleActivator_create(bu
 celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
 	celix_status_t status = CELIX_SUCCESS;
 	struct activator *activator = userData;
-	calculator_pt calculator;
-	calculator_service_pt calculatorService;
-	remote_proxy_service_pt calculatorProxy;
-
-	calculatorProxy_create(activator->pool, &calculator);
-
-	calculatorService = apr_palloc(activator->pool, sizeof(*calculatorService));
-	calculatorService->calculator = calculator;
-	calculatorService->add = calculatorProxy_add;
-	calculatorService->sub = calculatorProxy_sub;
-	calculatorService->sqrt = calculatorProxy_sqrt;
-	calculatorProxy = apr_palloc(activator->pool, sizeof(*calculatorProxy));
-	calculatorProxy->proxy = calculator;
-	calculatorProxy->setEndpointDescription = calculatorProxy_setEndpointDescription;
-	calculatorProxy->setHandler = calculatorProxy_setHandler;
-	calculatorProxy->setCallback = calculatorProxy_setCallback;
-
-	char **services = malloc(2);
-	services[0] = CALCULATOR_SERVICE;
-	services[1] = OSGI_RSA_REMOTE_PROXY;
+	remote_proxy_factory_service_pt calculatorProxyFactoryService;
 
-	bundleContext_registerService(context, CALCULATOR_SERVICE, calculatorService, NULL, &activator->service);
+	calculatorProxyFactoryService = apr_palloc(activator->pool, sizeof(*calculatorProxyFactoryService));
+	calculatorProxyFactoryService->pool = activator->pool;
+	calculatorProxyFactoryService->context = context;
+	calculatorProxyFactoryService->proxy_registrations = hashMap_create(NULL, NULL, NULL, NULL);
+	calculatorProxyFactoryService->registerProxyService = calculatorProxy_registerProxyService;
+	calculatorProxyFactoryService->unregisterProxyService = calculatorProxy_unregisterProxyService;
 
 	properties_pt props = properties_create();
 	properties_set(props, (char *) "proxy.interface", (char *) CALCULATOR_SERVICE);
-	bundleContext_registerService(context, OSGI_RSA_REMOTE_PROXY, calculatorProxy, props, &activator->proxy);
+
+	if (bundleContext_registerService(context, OSGI_RSA_REMOTE_PROXY_FACTORY, calculatorProxyFactoryService, props, &activator->proxyFactoryService) == CELIX_SUCCESS);
+	{
+		printf("CALCULATOR_PROXY: Proxy registered OSGI_RSA_REMOTE_PROXY_FACTORY (%s)\n", OSGI_RSA_REMOTE_PROXY_FACTORY);
+	}
 
 	return status;
 }
@@ -103,15 +89,15 @@ celix_status_t bundleActivator_stop(void
 	celix_status_t status = CELIX_SUCCESS;
 	struct activator *activator = userData;
 
-	serviceRegistration_unregister(activator->proxy);
-	serviceRegistration_unregister(activator->service);
-	activator->proxy = NULL;
-	activator->service = NULL;
+	// TODO: unregister proxy registrations
+	serviceRegistration_unregister(activator->proxyFactoryService);
+	activator->proxyFactoryService = NULL;
 
 	return status;
 }
 
 celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
 	celix_status_t status = CELIX_SUCCESS;
+
 	return status;
 }

Modified: incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c?rev=1608661&r1=1608660&r2=1608661&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c (original)
+++ incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c Tue Jul  8 05:11:04 2014
@@ -31,19 +31,26 @@
 #include <stddef.h>
 
 #include "celix_errno.h"
-
+#include "array_list.h"
 #include "calculator_proxy_impl.h"
 
-celix_status_t calculatorProxy_create(apr_pool_t *pool, calculator_pt *calculator)  {
+celix_status_t calculatorProxy_setEndpointDescription(void *proxy, endpoint_description_pt endpoint);
+celix_status_t calculatorProxy_setHandler(void *proxy, void *handler);
+celix_status_t calculatorProxy_setCallback(void *proxy, sendToHandle callback);
+
+
+celix_status_t calculatorProxy_create(apr_pool_t *pool, bundle_context_pt context, calculator_pt *calculator)  {
 	celix_status_t status = CELIX_SUCCESS;
 	*calculator = apr_palloc(pool, sizeof(**calculator));
 	if (!*calculator) {
 		status = CELIX_ENOMEM;
 	} else {
 		(*calculator)->pool = pool;
+		(*calculator)->context = context;
 		(*calculator)->endpoint = NULL;
 		(*calculator)->sendToCallback=NULL;
 		(*calculator)->sendToHandler=NULL;
+
 	}
 
 	return status;
@@ -123,6 +130,59 @@ celix_status_t calculatorProxy_sqrt(calc
 	return status;
 }
 
+
+
+celix_status_t calculatorProxy_registerProxyService(void* proxyFactoryService, endpoint_description_pt endpointDescription, void* rsa, sendToHandle sendToCallback) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	remote_proxy_factory_service_pt calculatorProxyFactoryService = (remote_proxy_factory_service_pt) proxyFactoryService;
+	calculator_pt calculator = NULL;
+	calculator_service_pt calculatorService = NULL;
+
+	calculatorProxy_create(calculatorProxyFactoryService->pool, calculatorProxyFactoryService->context, &calculator);
+	calculatorService = apr_palloc(calculatorProxyFactoryService->pool, sizeof(*calculatorService));
+	calculatorService->calculator = calculator;
+	calculatorService->add = calculatorProxy_add;
+	calculatorService->sub = calculatorProxy_sub;
+	calculatorService->sqrt = calculatorProxy_sqrt;
+
+	properties_pt srvcProps = properties_create();
+	properties_set(srvcProps, (char *) "proxy.interface", (char *) CALCULATOR_SERVICE);
+	properties_set(srvcProps, (char *) "endpoint.framework.uuid", (char *) endpointDescription->frameworkUUID);
+
+	service_registration_pt proxyReg = NULL;
+
+	calculatorProxy_setEndpointDescription(calculator, endpointDescription);
+	calculatorProxy_setHandler(calculator, rsa);
+	calculatorProxy_setCallback(calculator, sendToCallback);
+
+	if (bundleContext_registerService(calculatorProxyFactoryService->context, CALCULATOR_SERVICE, calculatorService, srvcProps, &proxyReg) != CELIX_SUCCESS)
+	{
+		printf("CALCULATOR_PROXY: error while registering calculator service\n");
+	}
+
+	hashMap_put(calculatorProxyFactoryService->proxy_registrations, endpointDescription, proxyReg);
+
+
+	return status;
+}
+
+
+celix_status_t calculatorProxy_unregisterProxyService(void* proxyFactoryService, endpoint_description_pt endpointDescription) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	remote_proxy_factory_service_pt calculatorProxyFactoryService = (remote_proxy_factory_service_pt) proxyFactoryService;
+	service_registration_pt proxyReg = hashMap_get(calculatorProxyFactoryService->proxy_registrations, endpointDescription);
+
+	if (proxyReg != NULL)
+	{
+		serviceRegistration_unregister(proxyReg);
+	}
+
+	return status;
+}
+
+
 celix_status_t calculatorProxy_setEndpointDescription(void *proxy, endpoint_description_pt endpoint) {
 	celix_status_t status = CELIX_SUCCESS;
 
@@ -151,3 +211,4 @@ celix_status_t calculatorProxy_setCallba
 
 	return status;
 }
+

Modified: incubator/celix/trunk/remote_services/discovery_slp/private/src/discovery.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/discovery_slp/private/src/discovery.c?rev=1608661&r1=1608660&r2=1608661&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/discovery_slp/private/src/discovery.c (original)
+++ incubator/celix/trunk/remote_services/discovery_slp/private/src/discovery.c Tue Jul  8 05:11:04 2014
@@ -270,11 +270,14 @@ celix_status_t discovery_endpointAdded(v
 				attributes = apr_pstrcat(discovery->pool, attributes, "(", key, "=", value, ")", NULL);
 			}
             hashMapIterator_destroy(iter);
+
+
 			err = SLPReg(slp, serviceUrl, SLP_LIFETIME_MAXIMUM, 0, attributes, SLP_TRUE, discovery_registrationReport, &callbackerr);
 			if ((err != SLP_OK) || (callbackerr != SLP_OK)) {
 				status = CELIX_ILLEGAL_STATE;
 				printf("DISCOVERY: Error registering service (%s) with slp %i\n", serviceUrl, err);
 			}
+
 			arrayList_add(discovery->registered, serviceUrl);
 		}
 		SLPClose(slp);
@@ -477,8 +480,9 @@ SLPBoolean discovery_pollSLPCallback(SLP
 				endpoint->serviceId = 42;
 				endpoint->service = apr_pstrdup(discovery->pool, srv);
 				endpoint->properties = props;
-				discovery_addService(discovery, endpoint);
+				endpoint->frameworkUUID = properties_get(props, "endpoint.framework.uuid");
 
+				discovery_addService(discovery, endpoint);
 				hashMap_put(discovery->slpServices, apr_pstrdup(discovery->pool, srvurl), endpoint);
 			}
 		}

Modified: incubator/celix/trunk/remote_services/remote_service_admin/private/include/import_registration_impl.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/private/include/import_registration_impl.h?rev=1608661&r1=1608660&r2=1608661&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/private/include/import_registration_impl.h (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin/private/include/import_registration_impl.h Tue Jul  8 05:11:04 2014
@@ -34,30 +34,49 @@
 struct import_registration {
 	apr_pool_t *pool;
 	bundle_context_pt context;
-	remote_service_admin_pt rsa;
 	endpoint_description_pt endpointDescription;
 
-	service_tracker_pt proxyTracker;
-
 	service_reference_pt reference;
-	remote_proxy_service_pt proxy;
 	import_reference_pt importReference;
-	bundle_pt bundle;
+
+	remote_service_admin_pt rsa;
+	sendToHandle sendToCallback;
 
 	bool closed;
 };
 
-celix_status_t importRegistration_create(apr_pool_t *pool, endpoint_description_pt endpoint, remote_service_admin_pt rsa, bundle_context_pt context, import_registration_pt *registration);
-celix_status_t importRegistration_open(import_registration_pt registration);
-celix_status_t importRegistration_close(import_registration_pt registration);
-celix_status_t importRegistration_getException(import_registration_pt registration);
-celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference);
+
+
+struct import_registration_factory
+{
+	apr_pool_t *pool;
+	char* serviceName;
+	remote_proxy_factory_service_pt trackedFactory;
+	service_tracker_pt proxyFactoryTracker;
+	bundle_context_pt context;
+	array_list_pt registrations;
+	bundle_pt bundle;
+};
+
+
+celix_status_t importRegistration_create(apr_pool_t *pool, endpoint_description_pt endpoint, remote_service_admin_pt rsa, sendToHandle callback, bundle_context_pt context, import_registration_pt *registration);
+celix_status_t importRegistration_destroy(import_registration_pt registration);
 
 celix_status_t importRegistration_setEndpointDescription(import_registration_pt registration, endpoint_description_pt endpointDescription);
 celix_status_t importRegistration_setHandler(import_registration_pt registration, void * handler);
 celix_status_t importRegistration_setCallback(import_registration_pt registration, sendToHandle callback);
 
-celix_status_t importRegistration_startTracking(import_registration_pt registration);
-celix_status_t importRegistration_stopTracking(import_registration_pt registration);
+celix_status_t importRegistration_getException(import_registration_pt registration);
+celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference);
+
+celix_status_t importRegistration_createProxyFactoryTracker(import_registration_factory_pt registration_factory, service_tracker_pt *tracker);
+
+//celix_status_t importRegistrationFactory_create(apr_pool_t *pool, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory);
+celix_status_t importRegistrationFactory_destroy(import_registration_factory_pt* registration_factory);
+//celix_status_t importRegistrationFactory_open(import_registration_factory_pt registration_factory);
+celix_status_t importRegistrationFactory_close(import_registration_factory_pt registration_factory);
+celix_status_t importRegistrationFactory_install(apr_pool_t *pool, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory);
+
+
 
 #endif /* IMPORT_REGISTRATION_IMPL_H_ */

Modified: incubator/celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h?rev=1608661&r1=1608660&r2=1608661&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h Tue Jul  8 05:11:04 2014
@@ -52,6 +52,8 @@ celix_status_t remoteServiceAdmin_remove
 celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services);
 celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services);
 celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
+celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration);
+
 
 celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint);
 celix_status_t exportReference_getExportedService(export_reference_pt reference);

Modified: 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=1608661&r1=1608660&r2=1608661&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h Tue Jul  8 05:11:04 2014
@@ -28,18 +28,23 @@
 #define REMOTE_PROXY_H_
 
 #include "endpoint_listener.h"
+#include "remote_service_admin.h"
 
-#define OSGI_RSA_REMOTE_PROXY "remote_proxy"
+#define OSGI_RSA_REMOTE_PROXY_FACTORY 	"remote_proxy_factory"
 
 typedef celix_status_t (*sendToHandle)(void *handler, endpoint_description_pt endpointDescription, char *methodSignature, char *request, char **reply, int* replyStatus);
 
-struct remote_proxy_service {
-	void *proxy;
-	celix_status_t (*setEndpointDescription)(void *proxy, endpoint_description_pt service);
-	celix_status_t (*setHandler)(void *proxy, void *handler);
-	celix_status_t (*setCallback)(void *proxy, sendToHandle callback);
+typedef struct remote_proxy_service *remote_proxy_service_pt;
+
+struct remote_proxy_factory_service {
+	void* context;
+	void* pool;
+	hash_map_pt proxy_registrations;
+	celix_status_t (*registerProxyService)(void* proxyFactoryService, endpoint_description_pt endpoint, void* handler, sendToHandle callback);
+	celix_status_t (*unregisterProxyService)(void* proxyFactoryService, endpoint_description_pt endpoint);
 };
 
-typedef struct remote_proxy_service *remote_proxy_service_pt;
+typedef struct remote_proxy_factory_service *remote_proxy_factory_service_pt;
+
 
 #endif /* REMOTE_PROXY_H_ */

Modified: 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=1608661&r1=1608660&r2=1608661&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_service_admin.h (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_service_admin.h Tue Jul  8 05:11:04 2014
@@ -36,6 +36,7 @@ typedef struct export_reference *export_
 typedef struct export_registration *export_registration_pt;
 typedef struct import_reference *import_reference_pt;
 typedef struct import_registration *import_registration_pt;
+typedef struct import_registration_factory *import_registration_factory_pt;
 typedef struct remote_service_admin *remote_service_admin_pt;
 
 struct remote_service_admin_service {
@@ -45,7 +46,6 @@ struct remote_service_admin_service {
 	celix_status_t (*getImportedEndpoints)(remote_service_admin_pt admin, array_list_pt *services);
 	celix_status_t (*importService)(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
 
-
 	celix_status_t (*exportReference_getExportedEndpoint)(export_reference_pt reference, endpoint_description_pt *endpoint);
 	celix_status_t (*exportReference_getExportedService)(export_reference_pt reference);
 
@@ -56,7 +56,7 @@ struct remote_service_admin_service {
 	celix_status_t (*importReference_getImportedEndpoint)(import_reference_pt reference);
 	celix_status_t (*importReference_getImportedService)(import_reference_pt reference);
 
-	celix_status_t (*importRegistration_close)(import_registration_pt registration);
+	celix_status_t (*importRegistration_close)(remote_service_admin_pt admin, import_registration_pt registration);
 	celix_status_t (*importRegistration_getException)(import_registration_pt registration);
 	celix_status_t (*importRegistration_getImportReference)(import_registration_pt registration, import_reference_pt *reference);
 

Modified: incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/import_registration_impl.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/import_registration_impl.c?rev=1608661&r1=1608660&r2=1608661&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/import_registration_impl.c (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/import_registration_impl.c Tue Jul  8 05:11:04 2014
@@ -39,14 +39,13 @@
 #include "bundle_context.h"
 #include "bundle.h"
 
-celix_status_t importRegistration_proxyAdding(void * handle, service_reference_pt reference, void **service);
-celix_status_t importRegistration_proxyAdded(void * handle, service_reference_pt reference, void *service);
-celix_status_t importRegistration_proxyModified(void * handle, service_reference_pt reference, void *service);
-celix_status_t importRegistration_proxyRemoved(void * handle, service_reference_pt reference, void *service);
 
-celix_status_t importRegistration_createProxyTracker(import_registration_pt registration, service_tracker_pt *tracker);
+celix_status_t importRegistration_proxyFactoryAdding(void * handle, service_reference_pt reference, void **service);
+celix_status_t importRegistration_proxyFactoryAdded(void * handle, service_reference_pt reference, void *service);
+celix_status_t importRegistration_proxyFactoryModified(void * handle, service_reference_pt reference, void *service);
+celix_status_t importRegistration_proxyFactoryRemoved(void * handle, service_reference_pt reference, void *service);
 
-celix_status_t importRegistration_create(apr_pool_t *pool, endpoint_description_pt endpoint, remote_service_admin_pt rsa, bundle_context_pt context, import_registration_pt *registration) {
+celix_status_t importRegistration_create(apr_pool_t *pool, endpoint_description_pt endpoint, remote_service_admin_pt rsa, 	sendToHandle sendToCallback, bundle_context_pt context, import_registration_pt *registration) {
 	celix_status_t status = CELIX_SUCCESS;
 	apr_pool_t *mypool = NULL;
 	apr_pool_create(&mypool, pool);
@@ -60,149 +59,185 @@ celix_status_t importRegistration_create
 		(*registration)->closed = false;
 		(*registration)->endpointDescription = endpoint;
 		(*registration)->rsa = rsa;
-		(*registration)->proxy = NULL;
+		(*registration)->sendToCallback = sendToCallback;
 		(*registration)->reference = NULL;
-		(*registration)->proxyTracker = NULL;
-		(*registration)->bundle = NULL;
 		(*registration)->importReference = NULL;
 	}
 
 	return status;
 }
 
-celix_status_t importRegistration_startTracking(import_registration_pt registration) {
+celix_status_t importRegistration_destroy(import_registration_pt registration)
+{
+	return CELIX_SUCCESS;
+}
+
+
+celix_status_t importRegistrationFactory_create(apr_pool_t *pool, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory) {
 	celix_status_t status = CELIX_SUCCESS;
+	apr_pool_t *mypool = NULL;
+	apr_pool_create(&mypool, pool);
 
-	if (registration->proxyTracker == NULL) {
-		importRegistration_createProxyTracker(registration, &registration->proxyTracker);
-		serviceTracker_open(registration->proxyTracker);
+	*registration_factory = calloc(1, sizeof(**registration_factory));
+	if (!*registration_factory) {
+		status = CELIX_ENOMEM;
+	} else {
+		(*registration_factory)->serviceName = strdup(serviceName);
+		(*registration_factory)->pool = mypool;
+		(*registration_factory)->context = context;
+		(*registration_factory)->bundle = NULL;
+		arrayList_create(&(*registration_factory)->registrations);
 	}
 
 	return status;
 }
 
-celix_status_t importRegistration_stopTracking(import_registration_pt registration) {
+
+
+celix_status_t importRegistrationFactory_destroy(import_registration_factory_pt* registration_factory) {
 	celix_status_t status = CELIX_SUCCESS;
 
-	if (registration->proxyTracker != NULL) {
-		serviceTracker_close(registration->proxyTracker);
+	if (*registration_factory != NULL)
+	{
+		free((*registration_factory)->serviceName);
+		arrayList_destroy((*registration_factory)->registrations);
+
+		free(*registration_factory);
 	}
 
+
 	return status;
 }
 
-celix_status_t importRegistration_createProxyTracker(import_registration_pt registration, service_tracker_pt *tracker) {
+
+celix_status_t importRegistrationFactory_open(import_registration_factory_pt registration_factory)
+{
 	celix_status_t status = CELIX_SUCCESS;
 
-	service_tracker_customizer_pt customizer = NULL;
+	char *bundleStore = NULL;
+	bundleContext_getProperty(registration_factory->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore);
+
+	if (bundleStore == NULL) {
+		bundleStore = DEFAULT_BUNDLE_STORE;
+	}
 
-	status = serviceTrackerCustomizer_create(registration, importRegistration_proxyAdding,
-			importRegistration_proxyAdded, importRegistration_proxyModified, importRegistration_proxyRemoved, &customizer);
+	char *name = apr_pstrcat(registration_factory->pool, bundleStore, "/", registration_factory->serviceName, "_proxy.zip", NULL);
+	status = bundleContext_installBundle(registration_factory->context, name, &registration_factory->bundle);
 
 	if (status == CELIX_SUCCESS) {
-		char *filter = apr_pstrcat(registration->pool, "(&(", OSGI_FRAMEWORK_OBJECTCLASS, "=", OSGI_RSA_REMOTE_PROXY,
-				")(proxy.interface=", registration->endpointDescription->service, "))", NULL);
-		status = serviceTracker_createWithFilter(registration->context, filter, customizer, tracker);
+		status = bundle_start(registration_factory->bundle);
+		if (status == CELIX_SUCCESS) {
+			printf("%s sucessfully started\n", name);
+		}
+	}
+	else
+	{
+
+		printf("%s could not be installed.\n", name);
 	}
 
 	return status;
 }
 
-celix_status_t importRegistration_proxyAdding(void * handle, service_reference_pt reference, void **service) {
+celix_status_t importRegistrationFactory_close(import_registration_factory_pt registration_factory)
+{
 	celix_status_t status = CELIX_SUCCESS;
-	import_registration_pt registration = handle;
 
-	bundleContext_getService(registration->context, reference, service);
+	if (registration_factory->bundle != NULL) {
+		bundle_stop(registration_factory->bundle);
+		bundle_uninstall(registration_factory->bundle);
+	}
 
 	return status;
 }
 
-celix_status_t importRegistration_proxyAdded(void * handle, service_reference_pt reference, void *service) {
+
+celix_status_t importRegistration_createProxyFactoryTracker(import_registration_factory_pt registration_factory, service_tracker_pt *tracker) {
 	celix_status_t status = CELIX_SUCCESS;
-	import_registration_pt registration = handle;
-	remote_proxy_service_pt proxy = (remote_proxy_service_pt) service;
+	service_tracker_customizer_pt customizer = NULL;
+
+	status = serviceTrackerCustomizer_create(registration_factory, importRegistration_proxyFactoryAdding, importRegistration_proxyFactoryAdded, importRegistration_proxyFactoryModified, importRegistration_proxyFactoryRemoved, &customizer);
+
+	if (status == CELIX_SUCCESS) {
+		char *filter = apr_pstrcat(registration_factory->pool, "(&(", OSGI_FRAMEWORK_OBJECTCLASS, "=", OSGI_RSA_REMOTE_PROXY_FACTORY,")(proxy.interface=", registration_factory->serviceName, "))", NULL);
+		status = serviceTracker_createWithFilter(registration_factory->context, filter, customizer, tracker);
 
-	if (registration->proxy == NULL) {
-		registration->reference = reference;
-		registration->proxy = proxy;
-		if (registration->endpointDescription != NULL) {
-			proxy->setEndpointDescription(proxy->proxy, registration->endpointDescription);
-			proxy->setHandler(proxy->proxy, registration->rsa);
-			proxy->setCallback(proxy->proxy, (sendToHandle) &remoteServiceAdmin_send);
+		if (status == CELIX_SUCCESS)
+		{
+			serviceTracker_open(*tracker);
 		}
 	}
 
 	return status;
 }
 
-celix_status_t importRegistration_proxyModified(void * handle, service_reference_pt reference, void *service) {
+celix_status_t importRegistration_proxyFactoryAdding(void * handle, service_reference_pt reference, void **service) {
 	celix_status_t status = CELIX_SUCCESS;
-	import_registration_pt registration = handle;
+	import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
 
-	//remote_proxy_service_pt endpoint = service;
-	//if (registration->endpoint != NULL) {
-	//	registration->endpoint = endpoint;
-	//	endpoint->setServiceReference(endpoint->endpoint, registration->reference);
-	//}
+	bundleContext_getService(registration_factory->context, reference, service);
 
 	return status;
 }
 
-celix_status_t importRegistration_proxyRemoved(void * handle, service_reference_pt reference, void *service) {
+celix_status_t importRegistration_proxyFactoryAdded(void * handle, service_reference_pt reference, void *service) {
 	celix_status_t status = CELIX_SUCCESS;
-	import_registration_pt registration = handle;
 
-	remote_proxy_service_pt proxy = service;
-	if (registration->proxy != NULL) {
-		registration->reference = NULL;
-		registration->proxy = NULL;
-		proxy->setEndpointDescription(proxy->proxy, NULL);
-		proxy->setHandler(proxy->proxy, NULL);
-		proxy->setCallback(proxy->proxy, NULL);
-	}
+	import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
+	registration_factory->trackedFactory = (remote_proxy_factory_service_pt) service;
 
 	return status;
 }
 
-celix_status_t importRegistration_open(import_registration_pt registration) {
+celix_status_t importRegistration_proxyFactoryModified(void * handle, service_reference_pt reference, void *service) {
 	celix_status_t status = CELIX_SUCCESS;
+	import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
 
-	char *bundleStore = NULL;
-	bundleContext_getProperty(registration->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore);
+	return status;
+}
 
-	if (bundleStore == NULL) {
-		bundleStore = DEFAULT_BUNDLE_STORE;
-	}
+celix_status_t importRegistration_proxyFactoryRemoved(void * handle, service_reference_pt reference, void *service) {
+	celix_status_t status = CELIX_SUCCESS;
+	import_registration_pt registration = handle;
+
+	import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
+	registration_factory->trackedFactory = NULL;
 
-	char *name = apr_pstrcat(registration->pool, bundleStore, "/", registration->endpointDescription->service, "_proxy.zip", NULL);
-	status = bundleContext_installBundle(registration->context, name, &registration->bundle);
 
-	if (status == CELIX_SUCCESS) {
-		status = bundle_start(registration->bundle);
-		if (status == CELIX_SUCCESS) {
-		}
-	}
 	return status;
 }
 
-celix_status_t importRegistration_close(import_registration_pt registration) {
-	celix_status_t status = CELIX_SUCCESS;
 
-	importRegistration_stopTracking(registration);
 
-	if (registration->bundle != NULL) {
-		bundle_stop(registration->bundle);
-		bundle_uninstall(registration->bundle);
+celix_status_t importRegistrationFactory_install(apr_pool_t *pool, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory)
+{
+	celix_status_t status = CELIX_SUCCESS;
+
+	if ( (status = importRegistrationFactory_create(pool, serviceName, context, registration_factory)) != CELIX_SUCCESS)
+	{
+		printf("remoteServiceAdmin_importService: error while creating importRegistrationFactory\n");
+	}
+	else if ((status = importRegistrationFactory_open(*registration_factory)) != CELIX_SUCCESS)
+	{
+		printf("remoteServiceAdmin_importService: cannot open registration_factory for %s \n  ", serviceName);
+		importRegistrationFactory_destroy(registration_factory);
+	}
+	else
+	{
+		importRegistration_createProxyFactoryTracker(*registration_factory, &((*registration_factory)->proxyFactoryTracker));
+		printf("remoteServiceAdmin_importService: new registration_factory added for %s at %p\n  ", serviceName, (*registration_factory)->proxyFactoryTracker);
 	}
 
 	return status;
 }
 
+
 celix_status_t importRegistration_getException(import_registration_pt registration) {
 	celix_status_t status = CELIX_SUCCESS;
 	return status;
 }
 
+
 celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference) {
 	celix_status_t status = CELIX_SUCCESS;
 
@@ -220,37 +255,3 @@ celix_status_t importRegistration_getImp
 
 	return status;
 }
-
-celix_status_t importRegistration_setEndpointDescription(import_registration_pt registration, endpoint_description_pt endpointDescription) {
-	celix_status_t status = CELIX_SUCCESS;
-
-	registration->endpointDescription = endpointDescription;
-	if (registration->proxy != NULL) {
-		registration->proxy->setEndpointDescription(registration->proxy->proxy, endpointDescription);
-	}
-
-	return status;
-}
-
-
-celix_status_t importRegistration_setHandler(import_registration_pt registration, void * handler) {
-	celix_status_t status = CELIX_SUCCESS;
-
-	if (registration->proxy != NULL) {
-		registration->proxy->setHandler(registration->proxy->proxy, handler);
-	}
-
-	return status;
-}
-
-
-celix_status_t importRegistration_setCallback(import_registration_pt registration, sendToHandle callback) {
-	celix_status_t status = CELIX_SUCCESS;
-
-	if (registration->proxy != NULL) {
-		registration->proxy->setCallback(registration->proxy->proxy, callback);
-	}
-
-	return status;
-}
-

Modified: incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c?rev=1608661&r1=1608660&r2=1608661&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c Tue Jul  8 05:11:04 2014
@@ -92,7 +92,7 @@ celix_status_t bundleActivator_start(voi
 			remoteServiceAdmin->importReference_getImportedEndpoint = importReference_getImportedEndpoint;
 			remoteServiceAdmin->importReference_getImportedService = importReference_getImportedService;
 
-			remoteServiceAdmin->importRegistration_close = importRegistration_close;
+			remoteServiceAdmin->importRegistration_close = remoteServiceAdmin_removeImportedService;
 			remoteServiceAdmin->importRegistration_getException = importRegistration_getException;
 			remoteServiceAdmin->importRegistration_getImportReference = importRegistration_getImportReference;
 

Modified: incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c?rev=1608661&r1=1608660&r2=1608661&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c Tue Jul  8 05:11:04 2014
@@ -119,15 +119,24 @@ celix_status_t remoteServiceAdmin_stop(r
 		}
 	}
     hashMapIterator_destroy(iter);
-	iter = hashMapIterator_create(admin->importedServices);
-	while (hashMapIterator_hasNext(iter)) {
-		array_list_pt exports = hashMapIterator_nextValue(iter);
-		int i;
-		for (i = 0; i < arrayList_size(exports); i++) {
-			import_registration_pt export = arrayList_get(exports, i);
-			importRegistration_stopTracking(export);
-		}
-	}
+    iter = hashMapIterator_create(admin->importedServices);
+    while (hashMapIterator_hasNext(iter))
+    {
+    	import_registration_factory_pt importFactory = hashMapIterator_nextValue(iter);
+        int i;
+        for (i = 0; i < arrayList_size(importFactory->registrations); i++)
+        {
+            import_registration_pt importRegistration = arrayList_get(importFactory->registrations, i);
+
+			if (importFactory->trackedFactory != NULL)
+			{
+				importFactory->trackedFactory->unregisterProxyService(importFactory->trackedFactory, importRegistration->endpointDescription);
+			}
+        }
+
+        serviceTracker_close(importFactory->proxyFactoryTracker);
+        importRegistrationFactory_close(importFactory);
+    }
     hashMapIterator_destroy(iter);
 
 	return status;
@@ -330,10 +339,10 @@ celix_status_t remoteServiceAdmin_instal
 	char *serviceId = (char *) hashMap_remove(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
 	char *uuid = NULL;
 	bundleContext_getProperty(admin->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
+	properties_set(endpointProperties, (char *) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
 	properties_set(endpointProperties, (char *) OSGI_FRAMEWORK_OBJECTCLASS, interface);
 	properties_set(endpointProperties, (char *) OSGI_RSA_ENDPOINT_SERVICE_ID, serviceId);
 	properties_set(endpointProperties, "service.imported", "true");
-	properties_set(endpointProperties, (char *) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
 
 //    properties_set(endpointProperties, ".ars.path", buf);
 //    properties_set(endpointProperties, ".ars.port", admin->port);
@@ -425,25 +434,74 @@ celix_status_t remoteServiceAdmin_getImp
 	return status;
 }
 
-celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration) {
+
+
+celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpointDescription, import_registration_pt *registration) {
 	celix_status_t status = CELIX_SUCCESS;
 
-	printf("RSA: Import service %s\n", endpoint->service);
-	importRegistration_create(admin->pool, endpoint, admin, admin->context, registration);
+	printf("RSA: Import service %s\n", endpointDescription->service);
 
-	array_list_pt importedRegs = hashMap_get(admin->importedServices, endpoint);
-	if (importedRegs == NULL) {
-		arrayList_create(&importedRegs);
-		hashMap_put(admin->importedServices, endpoint, importedRegs);
+   import_registration_factory_pt registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
+
+	// check whether we already have a registration_factory
+	if (registration_factory == NULL)
+	{
+		importRegistrationFactory_install(admin->pool, endpointDescription->service, admin->context, &registration_factory);
+		hashMap_put(admin->importedServices, endpointDescription->service, registration_factory);
 	}
-	arrayList_add(importedRegs, *registration);
 
-	importRegistration_open(*registration);
-	importRegistration_startTracking(*registration);
+	 // factory available
+	if (status != CELIX_SUCCESS || (registration_factory->trackedFactory == NULL))
+	{
+		printf("RSA: no proxyFactory available.\n");
+	}
+	else
+	{
+		// we create an importRegistration per imported service
+		importRegistration_create(admin->pool, endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send, admin->context, registration);
+		registration_factory->trackedFactory->registerProxyService(registration_factory->trackedFactory,  endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send);
+
+		arrayList_add(registration_factory->registrations, *registration);
+	}
 
 	return status;
 }
 
+
+celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration) {
+	celix_status_t status = CELIX_SUCCESS;
+	endpoint_description_pt endpointDescription = (endpoint_description_pt) registration->endpointDescription;
+	import_registration_factory_pt registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
+
+    // factory available
+    if ((registration_factory == NULL) || (registration_factory->trackedFactory == NULL))
+    {
+    	printf("RSA: Error while retrieving registration factory for imported service %s\n", endpointDescription->service);
+    }
+    else
+    {
+		registration_factory->trackedFactory->unregisterProxyService(registration_factory->trackedFactory, endpointDescription);
+		arrayList_removeElement(registration_factory->registrations, registration);
+		importRegistration_destroy(registration);
+
+		if (arrayList_isEmpty(registration_factory->registrations))
+		{
+			printf("RSA: closing proxy\n");
+
+			serviceTracker_close(registration_factory->proxyFactoryTracker);
+			importRegistrationFactory_close(registration_factory);
+
+			hashMap_remove(admin->importedServices, endpointDescription->service);
+			importRegistrationFactory_destroy(&registration_factory);
+		}
+    }
+
+	return status;
+}
+
+
+
+
 celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *methodSignature, char *request, char **reply, int* replyStatus) {
 
     struct post post;

Modified: incubator/celix/trunk/remote_services/remote_service_admin_shm/private/src/import_registration_impl.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin_shm/private/src/import_registration_impl.c?rev=1608661&r1=1608660&r2=1608661&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin_shm/private/src/import_registration_impl.c (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin_shm/private/src/import_registration_impl.c Tue Jul  8 05:11:04 2014
@@ -39,14 +39,13 @@
 #include "bundle_context.h"
 #include "bundle.h"
 
-celix_status_t importRegistration_proxyAdding(void * handle, service_reference_pt reference, void **service);
-celix_status_t importRegistration_proxyAdded(void * handle, service_reference_pt reference, void *service);
-celix_status_t importRegistration_proxyModified(void * handle, service_reference_pt reference, void *service);
-celix_status_t importRegistration_proxyRemoved(void * handle, service_reference_pt reference, void *service);
 
-celix_status_t importRegistration_createProxyTracker(import_registration_pt registration, service_tracker_pt *tracker);
+celix_status_t importRegistration_proxyFactoryAdding(void * handle, service_reference_pt reference, void **service);
+celix_status_t importRegistration_proxyFactoryAdded(void * handle, service_reference_pt reference, void *service);
+celix_status_t importRegistration_proxyFactoryModified(void * handle, service_reference_pt reference, void *service);
+celix_status_t importRegistration_proxyFactoryRemoved(void * handle, service_reference_pt reference, void *service);
 
-celix_status_t importRegistration_create(apr_pool_t *pool, endpoint_description_pt endpoint, remote_service_admin_pt rsa, bundle_context_pt context, import_registration_pt *registration) {
+celix_status_t importRegistration_create(apr_pool_t *pool, endpoint_description_pt endpoint, remote_service_admin_pt rsa, 	sendToHandle sendToCallback, bundle_context_pt context, import_registration_pt *registration) {
 	celix_status_t status = CELIX_SUCCESS;
 	apr_pool_t *mypool = NULL;
 	apr_pool_create(&mypool, pool);
@@ -60,149 +59,183 @@ celix_status_t importRegistration_create
 		(*registration)->closed = false;
 		(*registration)->endpointDescription = endpoint;
 		(*registration)->rsa = rsa;
-		(*registration)->proxy = NULL;
+		(*registration)->sendToCallback = sendToCallback;
 		(*registration)->reference = NULL;
-		(*registration)->proxyTracker = NULL;
-		(*registration)->bundle = NULL;
 		(*registration)->importReference = NULL;
 	}
 
 	return status;
 }
 
-celix_status_t importRegistration_startTracking(import_registration_pt registration) {
+celix_status_t importRegistration_destroy(import_registration_pt registration)
+{
+	return CELIX_SUCCESS;
+}
+
+
+celix_status_t importRegistrationFactory_create(apr_pool_t *pool, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory) {
 	celix_status_t status = CELIX_SUCCESS;
+	apr_pool_t *mypool = NULL;
+	apr_pool_create(&mypool, pool);
 
-	if (registration->proxyTracker == NULL) {
-		importRegistration_createProxyTracker(registration, &registration->proxyTracker);
-		serviceTracker_open(registration->proxyTracker);
+	*registration_factory = calloc(1, sizeof(**registration_factory));
+	if (!*registration_factory) {
+		status = CELIX_ENOMEM;
+	} else {
+		(*registration_factory)->serviceName = strdup(serviceName);
+		(*registration_factory)->pool = mypool;
+		(*registration_factory)->context = context;
+		(*registration_factory)->bundle = NULL;
+		arrayList_create(&(*registration_factory)->registrations);
 	}
 
 	return status;
 }
 
-celix_status_t importRegistration_stopTracking(import_registration_pt registration) {
+
+
+celix_status_t importRegistrationFactory_destroy(import_registration_factory_pt* registration_factory) {
 	celix_status_t status = CELIX_SUCCESS;
 
-	if (registration->proxyTracker != NULL) {
-		serviceTracker_close(registration->proxyTracker);
+	if (*registration_factory != NULL)
+	{
+		free((*registration_factory)->serviceName);
+		arrayList_destroy((*registration_factory)->registrations);
+
+		free(*registration_factory);
 	}
 
 	return status;
 }
 
-celix_status_t importRegistration_createProxyTracker(import_registration_pt registration, service_tracker_pt *tracker) {
+
+celix_status_t importRegistrationFactory_open(import_registration_factory_pt registration_factory)
+{
 	celix_status_t status = CELIX_SUCCESS;
 
-	service_tracker_customizer_pt customizer = NULL;
+	char *bundleStore = NULL;
+	bundleContext_getProperty(registration_factory->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore);
 
-	status = serviceTrackerCustomizer_create(registration, importRegistration_proxyAdding,
-			importRegistration_proxyAdded, importRegistration_proxyModified, importRegistration_proxyRemoved, &customizer);
+	if (bundleStore == NULL) {
+		bundleStore = DEFAULT_BUNDLE_STORE;
+	}
+
+	char *name = apr_pstrcat(registration_factory->pool, bundleStore, "/", registration_factory->serviceName, "_proxy.zip", NULL);
+	status = bundleContext_installBundle(registration_factory->context, name, &registration_factory->bundle);
 
 	if (status == CELIX_SUCCESS) {
-		char *filter = apr_pstrcat(registration->pool, "(&(", OSGI_FRAMEWORK_OBJECTCLASS, "=", OSGI_RSA_REMOTE_PROXY,
-				")(proxy.interface=", registration->endpointDescription->service, "))", NULL);
-		status = serviceTracker_createWithFilter(registration->context, filter, customizer, tracker);
+		status = bundle_start(registration_factory->bundle);
+		if (status == CELIX_SUCCESS) {
+			printf("%s sucessfully started\n", name);
+		}
+	}
+	else
+	{
+
+		printf("%s could not be installed.\n", name);
 	}
 
 	return status;
 }
 
-celix_status_t importRegistration_proxyAdding(void * handle, service_reference_pt reference, void **service) {
+celix_status_t importRegistrationFactory_close(import_registration_factory_pt registration_factory)
+{
 	celix_status_t status = CELIX_SUCCESS;
-	import_registration_pt registration = handle;
 
-	bundleContext_getService(registration->context, reference, service);
+	if (registration_factory->bundle != NULL) {
+		bundle_stop(registration_factory->bundle);
+		bundle_uninstall(registration_factory->bundle);
+	}
 
 	return status;
 }
 
-celix_status_t importRegistration_proxyAdded(void * handle, service_reference_pt reference, void *service) {
+
+celix_status_t importRegistration_createProxyFactoryTracker(import_registration_factory_pt registration_factory, service_tracker_pt *tracker) {
 	celix_status_t status = CELIX_SUCCESS;
-	import_registration_pt registration = handle;
-	remote_proxy_service_pt proxy = (remote_proxy_service_pt) service;
+	service_tracker_customizer_pt customizer = NULL;
+
+	status = serviceTrackerCustomizer_create(registration_factory, importRegistration_proxyFactoryAdding, importRegistration_proxyFactoryAdded, importRegistration_proxyFactoryModified, importRegistration_proxyFactoryRemoved, &customizer);
+
+	if (status == CELIX_SUCCESS) {
+		char *filter = apr_pstrcat(registration_factory->pool, "(&(", OSGI_FRAMEWORK_OBJECTCLASS, "=", OSGI_RSA_REMOTE_PROXY_FACTORY,")(proxy.interface=", registration_factory->serviceName, "))", NULL);
+		status = serviceTracker_createWithFilter(registration_factory->context, filter, customizer, tracker);
 
-	if (registration->proxy == NULL) {
-		registration->reference = reference;
-		registration->proxy = proxy;
-		if (registration->endpointDescription != NULL) {
-			proxy->setEndpointDescription(proxy->proxy, registration->endpointDescription);
-			proxy->setHandler(proxy->proxy, registration->rsa);
-			proxy->setCallback(proxy->proxy, (sendToHandle) &remoteServiceAdmin_send);
+		if (status == CELIX_SUCCESS)
+		{
+			serviceTracker_open(*tracker);
 		}
 	}
 
 	return status;
 }
 
-celix_status_t importRegistration_proxyModified(void * handle, service_reference_pt reference, void *service) {
+celix_status_t importRegistration_proxyFactoryAdding(void * handle, service_reference_pt reference, void **service) {
 	celix_status_t status = CELIX_SUCCESS;
-	import_registration_pt registration = handle;
+	import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
 
-	//remote_proxy_service_pt endpoint = service;
-	//if (registration->endpoint != NULL) {
-	//	registration->endpoint = endpoint;
-	//	endpoint->setServiceReference(endpoint->endpoint, registration->reference);
-	//}
+	bundleContext_getService(registration_factory->context, reference, service);
 
 	return status;
 }
 
-celix_status_t importRegistration_proxyRemoved(void * handle, service_reference_pt reference, void *service) {
+celix_status_t importRegistration_proxyFactoryAdded(void * handle, service_reference_pt reference, void *service) {
 	celix_status_t status = CELIX_SUCCESS;
-	import_registration_pt registration = handle;
 
-	remote_proxy_service_pt proxy = service;
-	if (registration->proxy != NULL) {
-		registration->reference = NULL;
-		registration->proxy = NULL;
-		proxy->setEndpointDescription(proxy->proxy, NULL);
-		proxy->setHandler(proxy->proxy, NULL);
-		proxy->setCallback(proxy->proxy, NULL);
-	}
+	import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
+	registration_factory->trackedFactory = (remote_proxy_factory_service_pt) service;
 
 	return status;
 }
 
-celix_status_t importRegistration_open(import_registration_pt registration) {
+celix_status_t importRegistration_proxyFactoryModified(void * handle, service_reference_pt reference, void *service) {
 	celix_status_t status = CELIX_SUCCESS;
+	import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
 
-	char *bundleStore = NULL;
-	bundleContext_getProperty(registration->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore);
+	return status;
+}
 
-	if (bundleStore == NULL) {
-		bundleStore = DEFAULT_BUNDLE_STORE;
-	}
+celix_status_t importRegistration_proxyFactoryRemoved(void * handle, service_reference_pt reference, void *service) {
+	celix_status_t status = CELIX_SUCCESS;
+	import_registration_pt registration = handle;
+
+	import_registration_factory_pt registration_factory = (import_registration_factory_pt) handle;
+	registration_factory->trackedFactory = NULL;
 
-	char *name = apr_pstrcat(registration->pool, bundleStore, "/", registration->endpointDescription->service, "_proxy.zip", NULL);
-	status = bundleContext_installBundle(registration->context, name, &registration->bundle);
 
-	if (status == CELIX_SUCCESS) {
-		status = bundle_start(registration->bundle);
-		if (status == CELIX_SUCCESS) {
-		}
-	}
 	return status;
 }
 
-celix_status_t importRegistration_close(import_registration_pt registration) {
-	celix_status_t status = CELIX_SUCCESS;
 
-	importRegistration_stopTracking(registration);
+celix_status_t importRegistrationFactory_install(apr_pool_t *pool, char* serviceName, bundle_context_pt context, import_registration_factory_pt *registration_factory)
+{
+	celix_status_t status = CELIX_SUCCESS;
 
-	if (registration->bundle != NULL) {
-		bundle_stop(registration->bundle);
-		bundle_uninstall(registration->bundle);
+	if ( (status = importRegistrationFactory_create(pool, serviceName, context, registration_factory)) != CELIX_SUCCESS)
+	{
+		printf("remoteServiceAdmin_importService: error while creating importRegistrationFactory\n");
+	}
+	else if ((status = importRegistrationFactory_open(*registration_factory)) != CELIX_SUCCESS)
+	{
+		printf("remoteServiceAdmin_importService: cannot open registration_factory for %s \n  ", serviceName);
+		importRegistrationFactory_destroy(registration_factory);
+	}
+	else
+	{
+		importRegistration_createProxyFactoryTracker(*registration_factory, &((*registration_factory)->proxyFactoryTracker));
+		printf("remoteServiceAdmin_importService: new registration_factory added for %s at %p\n  ", serviceName, (*registration_factory)->proxyFactoryTracker);
 	}
 
 	return status;
 }
 
+
 celix_status_t importRegistration_getException(import_registration_pt registration) {
 	celix_status_t status = CELIX_SUCCESS;
 	return status;
 }
 
+
 celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference) {
 	celix_status_t status = CELIX_SUCCESS;
 
@@ -220,37 +253,3 @@ celix_status_t importRegistration_getImp
 
 	return status;
 }
-
-celix_status_t importRegistration_setEndpointDescription(import_registration_pt registration, endpoint_description_pt endpointDescription) {
-	celix_status_t status = CELIX_SUCCESS;
-
-	registration->endpointDescription = endpointDescription;
-	if (registration->proxy != NULL) {
-		registration->proxy->setEndpointDescription(registration->proxy->proxy, endpointDescription);
-	}
-
-	return status;
-}
-
-
-celix_status_t importRegistration_setHandler(import_registration_pt registration, void * handler) {
-	celix_status_t status = CELIX_SUCCESS;
-
-	if (registration->proxy != NULL) {
-		registration->proxy->setHandler(registration->proxy->proxy, handler);
-	}
-
-	return status;
-}
-
-
-celix_status_t importRegistration_setCallback(import_registration_pt registration, sendToHandle callback) {
-	celix_status_t status = CELIX_SUCCESS;
-
-	if (registration->proxy != NULL) {
-		registration->proxy->setCallback(registration->proxy->proxy, callback);
-	}
-
-	return status;
-}
-

Modified: incubator/celix/trunk/remote_services/remote_service_admin_shm/private/src/remote_service_admin_activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin_shm/private/src/remote_service_admin_activator.c?rev=1608661&r1=1608660&r2=1608661&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin_shm/private/src/remote_service_admin_activator.c (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin_shm/private/src/remote_service_admin_activator.c Tue Jul  8 05:11:04 2014
@@ -92,7 +92,7 @@ celix_status_t bundleActivator_start(voi
 			remoteServiceAdmin->importReference_getImportedEndpoint = importReference_getImportedEndpoint;
 			remoteServiceAdmin->importReference_getImportedService = importReference_getImportedService;
 
-			remoteServiceAdmin->importRegistration_close = importRegistration_close;
+			remoteServiceAdmin->importRegistration_close = remoteServiceAdmin_removeImportedService;
 			remoteServiceAdmin->importRegistration_getException = importRegistration_getException;
 			remoteServiceAdmin->importRegistration_getImportReference = importRegistration_getImportReference;
 

Modified: incubator/celix/trunk/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c?rev=1608661&r1=1608660&r2=1608661&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c Tue Jul  8 05:11:04 2014
@@ -58,6 +58,9 @@ celix_status_t remoteServiceAdmin_wait(i
 
 
 celix_status_t remoteServiceAdmin_createOrAttachShm(hash_map_pt ipcSegment, remote_service_admin_pt admin, endpoint_description_pt endpointDescription, bool createIfNotFound);
+celix_status_t remoteServiceAdmin_getIpcSegment(remote_service_admin_pt admin, endpoint_description_pt endpointDescription, ipc_segment_pt* ipc);
+celix_status_t remoteServiceAdmin_detachIpcSegment(ipc_segment_pt ipc);
+celix_status_t remoteServiceAdmin_deleteIpcSegment(ipc_segment_pt ipc);
 
 celix_status_t remoteServiceAdmin_getSharedIdentifierFile(char *fwUuid, char* servicename, char* outFile);
 celix_status_t remoteServiceAdmin_removeSharedIdentityFile(char *fwUuid, char* servicename);
@@ -77,7 +80,7 @@ celix_status_t remoteServiceAdmin_create
         (*admin)->pool = pool;
         (*admin)->context = context;
         (*admin)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL);
-        (*admin)->importedServices = hashMap_create(NULL, NULL, NULL, NULL);
+        (*admin)->importedServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
         (*admin)->exportedIpcSegment = hashMap_create(NULL, NULL, NULL, NULL);
         (*admin)->importedIpcSegment = hashMap_create(NULL, NULL, NULL, NULL);
         (*admin)->pollThread = hashMap_create(NULL, NULL, NULL, NULL);
@@ -110,13 +113,20 @@ celix_status_t remoteServiceAdmin_stop(r
     hash_map_iterator_pt iter = hashMapIterator_create(admin->importedServices);
     while (hashMapIterator_hasNext(iter))
     {
-        array_list_pt exports = hashMapIterator_nextValue(iter);
+    	import_registration_factory_pt importFactory = hashMapIterator_nextValue(iter);
         int i;
-        for (i = 0; i < arrayList_size(exports); i++)
+        for (i = 0; i < arrayList_size(importFactory->registrations); i++)
         {
-            import_registration_pt export = arrayList_get(exports, i);
-            importRegistration_stopTracking(export);
+            import_registration_pt importRegistration = arrayList_get(importFactory->registrations, i);
+
+			if (importFactory->trackedFactory != NULL)
+			{
+				importFactory->trackedFactory->unregisterProxyService(importFactory->trackedFactory, importRegistration->endpointDescription);
+			}
         }
+
+        serviceTracker_close(importFactory->proxyFactoryTracker);
+        importRegistrationFactory_close(importFactory);
     }
     hashMapIterator_destroy(iter);
 
@@ -155,7 +165,7 @@ celix_status_t remoteServiceAdmin_stop(r
             }
         }
     }
-	hashMapIterator_destroy(iter);
+    hashMapIterator_destroy(iter);
 
     iter = hashMapIterator_create(admin->importedIpcSegment);
     while (hashMapIterator_hasNext(iter))
@@ -334,7 +344,7 @@ static void *APR_THREAD_FUNC remoteServi
         while (*pollThreadRunning == true)
         {
             if (((status = remoteServiceAdmin_lock(ipc->semId, 1)) == CELIX_SUCCESS) && (*pollThreadRunning == true))
-			{
+            	{
 				apr_pool_t *pool = NULL;
 				hash_map_pt receivedMethodCall = hashMap_create(utils_stringHash, utils_stringHash, utils_stringEquals, utils_stringEquals);
 
@@ -344,16 +354,16 @@ static void *APR_THREAD_FUNC remoteServi
 				}
 				else if ((status = netstring_decodeToHashMap(pool, ipc->shmBaseAdress, receivedMethodCall)) != CELIX_SUCCESS)
 				{
-					printf("DISCOVERY : receiveFromSharedMemory : decoding data to Properties\n");
+					fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "RSA : receiveFromSharedMemory : decoding data to Properties");
 				}
-                else
+				else
                 {
                     char *method = hashMap_get(receivedMethodCall, RSA_FUNCTIONCALL_METHOD_PROPERTYNAME);
                     char *data = hashMap_get(receivedMethodCall, RSA_FUNCTIONCALL_DATA_PROPERTYNAME);
 
                     if (method == NULL)
                     {
-                        printf("RSA : receiveFromSharedMemory : no method found. \n");
+                    	fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "RSA : receiveFromSharedMemory : no method found.");
                     }
                     else
                     {
@@ -387,7 +397,7 @@ static void *APR_THREAD_FUNC remoteServi
 
                                             if ((strlen(encReply) * sizeof(char)) >= RSA_SHM_MEMSIZE)
                                             {
-                                                printf("RSA : receiveFromSharedMemory : size of message bigger than shared memory message. NOT SENDING.\n");
+                                            	fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "RSA : receiveFromSharedMemory : size of message bigger than shared memory message. NOT SENDING.");
                                             }
                                             else
                                             {
@@ -396,7 +406,7 @@ static void *APR_THREAD_FUNC remoteServi
                                         }
                                         else
                                         {
-                                            printf("RSA : receiveFromSharedMemory : encoding of reply failed\n");
+                                        	fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "RSA : receiveFromSharedMemory : encoding of reply failed");
                                         }
                                     }
                                 }
@@ -428,20 +438,27 @@ celix_status_t remoteServiceAdmin_getSha
 	celix_status_t status = CELIX_SUCCESS;
 	snprintf(outFile, RSA_FILEPATH_LENGTH, "%s/%s/%s", P_tmpdir, fwUuid, servicename);
 
-	if (access(outFile, F_OK) != 0) {
+	if (access(outFile, F_OK) != 0)
+	{
 		char tmpDir[RSA_FILEPATH_LENGTH];
 
 		snprintf(tmpDir, sizeof(tmpDir), "%s/%s", P_tmpdir, fwUuid);
 
 		// we call, even if it already exists (and just don't care about the return value)
 		mkdir(tmpDir, 0755);
-		if (fopen(outFile, "wb") == NULL) {
-			printf("RSA: error while creating shared identifier file %s (%s)", outFile, strerror(errno));
-			status = CELIX_FILE_IO_EXCEPTION;
-		} else {
+
+		if (fopen(outFile, "wb") == NULL)
+		{
+				printf("RSA: error while creating shared identifier file %s (%s)", outFile, strerror(errno));
+				status = CELIX_FILE_IO_EXCEPTION;
+		}
+		else
+		{
 			printf("RSA:create shared identifier file %s", outFile);
 		}
-	} else {
+	}
+	else
+	{
 		printf("RSA: shared identifier file %s already exists", outFile);
 	}
 
@@ -454,7 +471,8 @@ celix_status_t remoteServiceAdmin_remove
 
 	snprintf(tmpPath, sizeof(tmpPath), "%s/%s/%s", P_tmpdir, fwUuid, servicename);
 
-	if (access(tmpPath, F_OK) == 0) {
+	if (access(tmpPath, F_OK) == 0)
+	{
 		printf("RSA: removing shared identifier file %s", tmpPath);
 		unlink(tmpPath);
 	}
@@ -476,28 +494,32 @@ celix_status_t remoteServiceAdmin_remove
 	int retVal = 0;
 
 
-	if (d) {
+	if (d)
+	{
 		struct dirent *p;
 
-		while (!retVal && (p = readdir(d))) {
+		while (!retVal && (p = readdir(d)))
+		{
 			char* f_name;
 			size_t len;
 
-			if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) {
+			if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, ".."))
+			{
 				continue;
 			}
 
 			len = path_len + strlen(p->d_name) + 2;
 			f_name = (char*) calloc(len, 1);
 
-			if (f_name) {
+			if (f_name)
+			{
 				struct stat statbuf;
 
 				snprintf(f_name, len, "%s/%s", tmpDir, p->d_name);
 
 				if (!stat(f_name, &statbuf)) {
-					printf("RSA: removing shared identifier file %s (unproper clean-up?)", f_name);
-					retVal = unlink(f_name);
+						printf("RSA: removing shared identifier file %s (unproper clean-up?)", f_name);
+						retVal = unlink(f_name);
 				}
 			}
 			free(f_name);
@@ -507,7 +529,9 @@ celix_status_t remoteServiceAdmin_remove
 	closedir(d);
 
 	if (!retVal)
+	{
 		rmdir(tmpDir);
+	}
 
 	return retVal;
 }
@@ -540,9 +564,6 @@ celix_status_t remoteServiceAdmin_export
         {
             reference = arrayList_get(references, 0);
         }
-    }
-
-    if(references!=NULL){
         arrayList_destroy(references);
     }
 
@@ -570,7 +591,8 @@ celix_status_t remoteServiceAdmin_export
         if (strcmp(utils_stringTrim(exports), "*") == 0)
         {
             char *token;
-            char *interface = apr_strtok(provided, ",", &token);
+           char *interface = apr_strtok(provided, ",", &token);
+
             while (interface != NULL)
             {
                 arrayList_add(interfaces, utils_stringTrim(interface));
@@ -582,7 +604,7 @@ celix_status_t remoteServiceAdmin_export
             char *exportToken;
             char *providedToken;
 
-            char *pinterface = apr_strtok(provided, ",", &providedToken);
+           char *pinterface = apr_strtok(provided, ",", &providedToken);
             while (pinterface != NULL)
             {
                 char *einterface = apr_strtok(exports, ",", &exportToken);
@@ -658,9 +680,6 @@ celix_status_t remoteServiceAdmin_remove
     ipc_segment_pt ipc = NULL;
     apr_thread_t *pollThread = NULL;
 
-	if(admin==NULL){
-		return CELIX_BUNDLE_EXCEPTION;
-	}
     hashMap_remove(admin->exportedServices, registration->reference);
 
     if ((pollThreadRunning = hashMap_get(admin->pollThreadRunning, registration->endpointDescription)) != NULL)
@@ -686,6 +705,8 @@ celix_status_t remoteServiceAdmin_remove
                 semctl(ipc->semId, 1 /*ignored*/, IPC_RMID);
                 shmctl(ipc->shmId, IPC_RMID, 0);
 
+                remoteServiceAdmin_removeSharedIdentityFile(registration->endpointDescription->frameworkUUID, registration->endpointDescription->service);
+
                 hashMap_remove(admin->pollThreadRunning, registration->endpointDescription);
                 hashMap_remove(admin->exportedIpcSegment, registration->endpointDescription->service);
                 hashMap_remove(admin->pollThread, registration->endpointDescription);
@@ -693,11 +714,31 @@ celix_status_t remoteServiceAdmin_remove
         }
     }
 
-
     return status;
 }
 
 
+
+celix_status_t remoteServiceAdmin_getIpcSegment(remote_service_admin_pt admin, endpoint_description_pt endpointDescription, ipc_segment_pt* ipc)
+{
+        (*ipc) = (hashMap_containsKey(admin->importedIpcSegment, endpointDescription) == true) ? hashMap_get(admin->importedIpcSegment, endpointDescription) : NULL;
+
+        return (*ipc != NULL) ? CELIX_SUCCESS : CELIX_ILLEGAL_ARGUMENT;
+}
+
+celix_status_t remoteServiceAdmin_detachIpcSegment(ipc_segment_pt ipc)
+{
+        return (shmdt(ipc->shmBaseAdress) != -1) ? CELIX_SUCCESS : CELIX_BUNDLE_EXCEPTION;
+}
+
+celix_status_t remoteServiceAdmin_deleteIpcSegment(ipc_segment_pt ipc)
+{
+        return ((semctl(ipc->semId, 1 /*ignored*/, IPC_RMID) != -1) && (shmctl(ipc->shmId, IPC_RMID, 0) != -1)) ? CELIX_SUCCESS : CELIX_BUNDLE_EXCEPTION;
+}
+
+
+
+
 celix_status_t remoteServiceAdmin_createOrAttachShm(hash_map_pt ipcSegment, remote_service_admin_pt admin, endpoint_description_pt endpointDescription, bool createIfNotFound)
 {
     celix_status_t status = CELIX_SUCCESS;
@@ -742,7 +783,7 @@ celix_status_t remoteServiceAdmin_create
 
         if ((ipc->shmId = shmget(shmKey, RSA_SHM_MEMSIZE, 0666)) < 0)
         {
-            printf("RSA : Could not attach to shared memory\n");
+        	fw_log(logger, OSGI_FRAMEWORK_LOG_WARNING, "RSA : Could not attach to shared memory");
 
             if (createIfNotFound == true)
             {
@@ -781,9 +822,9 @@ celix_status_t remoteServiceAdmin_create
 
         if (semid != -1)
         {
-  			// only reset semaphores if a create was supposed
+			// only reset semaphores if a create was supposed
 			if ((createIfNotFound == true) && ((semctl(semid, 0, SETVAL, (int) 1) == -1) || (semctl(semid, 1, SETVAL, (int) 0) == -1) || (semctl(semid, 2, SETVAL, (int) 0) == -1))) {
-				printf("RSA : error while initialize semaphores \n");
+					printf("RSA : error while initialize semaphores \n");
 			}
 
             printf("RSA : semaphores w/ key %s and id %i added \n", endpointDescription->service, semid);
@@ -833,12 +874,15 @@ celix_status_t remoteServiceAdmin_instal
     bundleContext_getProperty(admin->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
     properties_set(endpointProperties, (char *) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
     properties_set(endpointProperties, (char *) OSGI_RSA_SERVICE_LOCATION, apr_pstrdup(admin->pool, interface));
-	if (properties_get(endpointProperties, (char *) RSA_SHM_PATH_PROPERTYNAME) == NULL) {
+	if (properties_get(endpointProperties, (char *) RSA_SHM_PATH_PROPERTYNAME) == NULL)
+	{
 		char sharedIdentifierFile[RSA_FILEPATH_LENGTH];
 
-		if (remoteServiceAdmin_getSharedIdentifierFile(uuid, interface, sharedIdentifierFile) == CELIX_SUCCESS) {
+		if (remoteServiceAdmin_getSharedIdentifierFile(uuid, interface, sharedIdentifierFile) == CELIX_SUCCESS)
+		{
 			properties_set(endpointProperties, (char *) RSA_SHM_PATH_PROPERTYNAME, sharedIdentifierFile);
-		} else {
+		} else
+		{
 			properties_set(endpointProperties, (char *) RSA_SHM_PATH_PROPERTYNAME, apr_pstrdup(admin->pool, (char *) RSA_SHM_DEFAULTPATH));
 		}
 	}
@@ -846,12 +890,15 @@ celix_status_t remoteServiceAdmin_instal
     {
         properties_set(endpointProperties, (char *) RSA_SHM_FTOK_ID_PROPERTYNAME, apr_pstrdup(admin->pool, (char *) RSA_SHM_DEFAULT_FTOK_ID));
     }
-	if (properties_get(endpointProperties, (char *) RSA_SEM_PATH_PROPERTYNAME) == NULL) {
+	if (properties_get(endpointProperties, (char *) RSA_SEM_PATH_PROPERTYNAME) == NULL)
+	{
 		char sharedIdentifierFile[RSA_FILEPATH_LENGTH];
 
-		if (remoteServiceAdmin_getSharedIdentifierFile(uuid, interface, sharedIdentifierFile) == CELIX_SUCCESS) {
+		if (remoteServiceAdmin_getSharedIdentifierFile(uuid, interface, sharedIdentifierFile) == CELIX_SUCCESS)
+		{
 			properties_set(endpointProperties, (char *) RSA_SEM_PATH_PROPERTYNAME, sharedIdentifierFile);
-		} else {
+		} else
+		{
 			properties_set(endpointProperties, (char *) RSA_SEM_PATH_PROPERTYNAME, apr_pstrdup(admin->pool, (char *) RSA_SEM_DEFAULTPATH));
 		}
 	}
@@ -914,27 +961,86 @@ celix_status_t remoteServiceAdmin_import
 {
     celix_status_t status = CELIX_SUCCESS;
 
-    printf("RSA: Import service %s\n", endpointDescription->service);
+    printf("\n\nRSA: Import service %s\n", endpointDescription->service);
 
-    importRegistration_create(admin->pool, endpointDescription, admin, admin->context, registration);
+    import_registration_factory_pt registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
 
-    array_list_pt importedRegs = hashMap_get(admin->importedServices, endpointDescription);
-    if (importedRegs == NULL)
-    {
-        arrayList_create(&importedRegs);
-        hashMap_put(admin->importedServices, endpointDescription, importedRegs);
+	// check whether we already have a registration_factory
+	if (registration_factory == NULL)
+	{
+		importRegistrationFactory_install(admin->pool, endpointDescription->service, admin->context, &registration_factory);
+		hashMap_put(admin->importedServices, endpointDescription->service, registration_factory);
+	}
 
-    }
-    arrayList_add(importedRegs, *registration);
+	 // factory available
+	if (status != CELIX_SUCCESS || (registration_factory->trackedFactory == NULL))
+	{
+		printf("RSA: no proxyFactory available.\n");
+	}
+	else
+	{
+		// we create an importRegistration per imported service
+		importRegistration_create(admin->pool, endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send, admin->context, registration);
+		registration_factory->trackedFactory->registerProxyService(registration_factory->trackedFactory,  endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send);
 
-    importRegistration_open(*registration);
-    importRegistration_startTracking(*registration);
-    remoteServiceAdmin_createOrAttachShm(admin->importedIpcSegment, admin, endpointDescription, false);
+		arrayList_add(registration_factory->registrations, *registration);
+		remoteServiceAdmin_createOrAttachShm(admin->importedIpcSegment, admin, endpointDescription, false);
+	}
 
     return status;
 }
 
 
+
+celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration)
+{
+    celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+
+    if (registration != NULL)
+    {
+		ipc_segment_pt ipc = NULL;
+		endpoint_description_pt endpointDescription = (endpoint_description_pt) registration->endpointDescription;
+		import_registration_factory_pt registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
+
+        // detach from IPC
+        if(remoteServiceAdmin_getIpcSegment(admin, endpointDescription, &ipc) != CELIX_SUCCESS)
+        {
+        	printf("RSA: Error while retrieving IPC segment for imported service %s\n", endpointDescription->service);
+        }
+        else if (remoteServiceAdmin_detachIpcSegment(ipc) != CELIX_SUCCESS)
+        {
+        	printf("RSA: Error while detaching IPC segment for imported service %s\n", endpointDescription->service);
+        }
+
+		// factory available
+		if ((registration_factory == NULL) || (registration_factory->trackedFactory == NULL))
+		{
+			printf("RSA: Error while retrieving registration factory for imported service %s\n", endpointDescription->service);
+		}
+		else
+		{
+			registration_factory->trackedFactory->unregisterProxyService(registration_factory->trackedFactory, endpointDescription);
+			arrayList_removeElement(registration_factory->registrations, registration);
+			importRegistration_destroy(registration);
+
+			if (arrayList_isEmpty(registration_factory->registrations) == true)
+			{
+				printf("RSA: closing proxy\n");
+
+				serviceTracker_close(registration_factory->proxyFactoryTracker);
+				importRegistrationFactory_close(registration_factory);
+
+				hashMap_remove(admin->importedServices, endpointDescription->service);
+				importRegistrationFactory_destroy(&registration_factory);
+			}
+		}
+    }
+
+	return status;
+}
+
+
+
 celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint)
 {
     celix_status_t status = CELIX_SUCCESS;

Modified: 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=1608661&r1=1608660&r2=1608661&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/topology_manager/private/src/topology_manager.c (original)
+++ incubator/celix/trunk/remote_services/topology_manager/private/src/topology_manager.c Tue Jul  8 05:11:04 2014
@@ -81,10 +81,10 @@ celix_status_t topologyManager_create(bu
 }
 
 celix_status_t topologyManager_destroy(topology_manager_pt manager) {
+
 	celix_status_t status = CELIX_SUCCESS;
 
 	arrayList_destroy(manager->rsaList);
-
 	hashMap_destroy(manager->exportedServices,false,false);
 	hashMap_destroy(manager->importedServices,false,false);
 	hashMap_destroy(manager->importInterests,false,false);
@@ -174,12 +174,14 @@ celix_status_t topologyManager_endpointR
 	if (hashMap_containsKey(manager->importedServices, endpoint)) {
 		hash_map_pt imports = hashMap_get(manager->importedServices, endpoint);
 		hash_map_iterator_pt iter = hashMapIterator_create(imports);
+
 		while (hashMapIterator_hasNext(iter)) {
 			hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
 			remote_service_admin_service_pt rsa = hashMapEntry_getKey(entry);
 			import_registration_pt import = hashMapEntry_getValue(entry);
-			rsa->importRegistration_close(import);
+			rsa->importRegistration_close(rsa->admin, import);
 		}
+
 		hashMapIterator_destroy(iter);
 	}
 
@@ -260,11 +262,11 @@ celix_status_t topologyManager_notifyLis
 					}
 				}
 				filter_destroy(filter);
-			}
-			}
+	 		}
 		}
+	 }
 
-	if(endpointListeners!=NULL){
+	if(endpointListeners != NULL) {
 		arrayList_destroy(endpointListeners);
 	}
 
@@ -320,7 +322,6 @@ celix_status_t topologyManager_removeSer
 				rsa->exportRegistration_close(export);
 				topologyManager_notifyListenersOfRemoval(manager, rsa, export);
 			}
-
 		}
 		hashMapIterator_destroy(iter);
 	}
@@ -355,7 +356,7 @@ celix_status_t topologyManager_notifyLis
 		}
 	}
 
-	if(endpointListeners!=NULL){
+	if(endpointListeners != NULL) {
 		arrayList_destroy(endpointListeners);
 	}
 



Mime
View raw message