celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpe...@apache.org
Subject [4/4] celix git commit: CELIX-284: Restrict export and imports based on properties
Date Fri, 20 Nov 2015 17:25:33 GMT
CELIX-284: Restrict export and imports based on properties


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

Branch: refs/heads/develop
Commit: fe94cd14b1a2a073ca0ef1496b22f9ee3da35cdf
Parents: b320876
Author: Bjoern Petri <bpetri@apache.org>
Authored: Fri Nov 20 18:24:32 2015 +0100
Committer: Bjoern Petri <bpetri@apache.org>
Committed: Fri Nov 20 18:24:32 2015 +0100

----------------------------------------------------------------------
 framework/private/src/filter.c                  |  16 +
 framework/public/include/filter.h               |   1 +
 framework/public/include/service_registration.h |   1 +
 remote_services/CMakeLists.txt                  |   6 +-
 .../private/include/remote_service_admin_impl.h |   2 +-
 .../private/src/export_registration_impl.c      |   7 +-
 .../public/include/export_registration.h        |   2 +-
 .../public/include/remote_service_admin.h       |   6 +-
 .../remote_service_admin_dfi/CMakeLists.txt     |   2 +-
 .../remote_service_admin_dfi/rsa/CMakeLists.txt |   1 +
 .../private/include/export_registration_dfi.h   |   1 +
 .../private/include/import_registration_dfi.h   |   1 +
 .../private/include/remote_service_admin_dfi.h  |   5 +-
 .../rsa/private/src/export_registration_dfi.c   |   5 +-
 .../src/remote_service_admin_activator.c        |   2 +-
 .../rsa/private/src/remote_service_admin_dfi.c  |  42 +-
 .../src/remote_service_admin_activator.c        |   2 +-
 .../private/src/remote_service_admin_impl.c     |  29 +-
 .../private/test/rsa_client_server_tests.cpp    |   1 -
 .../src/remote_service_admin_activator.c        |   2 +-
 .../private/src/remote_service_admin_impl.c     |  26 +-
 .../private/test/rsa_client_server_tests.cpp    |   5 +-
 remote_services/topology_manager/CMakeLists.txt |  17 +-
 .../topology_manager/private/include/scope.h    | 150 ++++
 .../private/include/topology_manager.h          |   3 +-
 .../topology_manager/private/src/activator.c    |  44 +-
 .../topology_manager/private/src/scope.c        | 327 ++++++++
 .../private/src/topology_manager.c              | 815 +++++++++++--------
 .../topology_manager/public/include/tm_scope.h  |  45 +
 .../topology_manager/tms_tst/CMakeLists.txt     |  52 ++
 .../tms_tst/bundle/CMakeLists.txt               |  23 +
 .../org.apache.celix.test.MyBundle.descriptor   |   9 +
 .../tms_tst/bundle/tst_activator.c              | 126 +++
 .../tms_tst/bundle/tst_service.h                |  17 +
 .../tms_tst/config.properties.in                |   3 +
 .../tms_tst/config_import.properties.in         |   3 +
 .../tms_tst/disc_mock/CMakeLists.txt            |  23 +
 .../tms_tst/disc_mock/disc_mock_activator.c     | 135 +++
 .../tms_tst/disc_mock/disc_mock_service.c       |  42 +
 .../tms_tst/disc_mock/disc_mock_service.h       |  41 +
 .../topology_manager/tms_tst/run_tests.cpp      |   9 +
 .../topology_manager/tms_tst/scope.json         |  15 +
 .../topology_manager/tms_tst/scope2.json        |  22 +
 .../topology_manager/tms_tst/scope3.json        |  28 +
 .../topology_manager/tms_tst/scope4.json        |  21 +
 .../topology_manager/tms_tst/tms_tests.cpp      | 715 ++++++++++++++++
 46 files changed, 2457 insertions(+), 393 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/framework/private/src/filter.c
----------------------------------------------------------------------
diff --git a/framework/private/src/filter.c b/framework/private/src/filter.c
index de069a4..834280d 100644
--- a/framework/private/src/filter.c
+++ b/framework/private/src/filter.c
@@ -572,3 +572,19 @@ celix_status_t filter_getString(filter_pt filter, char **filterStr) {
 	}
 	return CELIX_SUCCESS;
 }
+
+celix_status_t filter_match_filter(filter_pt src, filter_pt dest, bool *result) {
+	char *srcStr = NULL;
+	char *destStr = NULL;
+	*result = false;
+
+	if (src) srcStr = src->filterStr;
+	if (dest) destStr = dest->filterStr;
+
+	if ((srcStr != NULL) && (destStr != NULL)) {
+		// TODO: should be done smarted, e.g. src="&(a=1)(b=2)" and dest="&(b=2)(a=1)" should result in true
+		*result = (strcmp(srcStr, destStr) == 0);
+	}
+
+	return CELIX_SUCCESS;
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/framework/public/include/filter.h
----------------------------------------------------------------------
diff --git a/framework/public/include/filter.h b/framework/public/include/filter.h
index 94fbf6c..9e78192 100644
--- a/framework/public/include/filter.h
+++ b/framework/public/include/filter.h
@@ -38,6 +38,7 @@ FRAMEWORK_EXPORT filter_pt filter_create(char * filterString);
 FRAMEWORK_EXPORT void filter_destroy(filter_pt filter);
 
 FRAMEWORK_EXPORT celix_status_t filter_match(filter_pt filter, properties_pt properties, bool *result);
+FRAMEWORK_EXPORT celix_status_t filter_match_filter(filter_pt src, filter_pt dest, bool *result);
 
 FRAMEWORK_EXPORT celix_status_t filter_getString(filter_pt filter, char **filterStr);
 

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/framework/public/include/service_registration.h
----------------------------------------------------------------------
diff --git a/framework/public/include/service_registration.h b/framework/public/include/service_registration.h
index 22685a9..7f0e17a 100644
--- a/framework/public/include/service_registration.h
+++ b/framework/public/include/service_registration.h
@@ -40,5 +40,6 @@ typedef struct serviceRegistration * service_registration_pt;
 FRAMEWORK_EXPORT celix_status_t serviceRegistration_unregister(service_registration_pt registration);
 FRAMEWORK_EXPORT celix_status_t serviceRegistration_getProperties(service_registration_pt registration, properties_pt *properties);
 FRAMEWORK_EXPORT celix_status_t serviceRegistration_setProperties(service_registration_pt registration, properties_pt properties);
+FRAMEWORK_EXPORT celix_status_t serviceRegistration_getServiceName(service_registration_pt registration, char **serviceName);
 
 #endif /* SERVICE_REGISTRATION_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/CMakeLists.txt b/remote_services/CMakeLists.txt
index abc9177..d5d07a3 100644
--- a/remote_services/CMakeLists.txt
+++ b/remote_services/CMakeLists.txt
@@ -32,15 +32,15 @@ if (REMOTE_SERVICE_ADMIN)
     add_subdirectory(examples)
 
     add_subdirectory(topology_manager)
-
+ 
     add_subdirectory(discovery_configured)
     add_subdirectory(discovery_etcd)
     add_subdirectory(discovery_shm)
 
-    add_subdirectory(remote_service_admin)
     add_subdirectory(remote_service_admin_http)
-    add_subdirectory(remote_service_admin_dfi)
     add_subdirectory(remote_service_admin_shm)
+    add_subdirectory(remote_service_admin)
+    add_subdirectory(remote_service_admin_dfi)
 
 
 endif (REMOTE_SERVICE_ADMIN)

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h b/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
index b28757b..e8a5e1f 100644
--- a/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
+++ b/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
@@ -38,7 +38,7 @@ celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin);
 celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *methodSignature, char **reply, int* replyStatus);
 
 celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
-celix_status_t remoteServiceAdmin_removeExportedService(export_registration_pt registration);
+celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration);
 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);

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin/private/src/export_registration_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/private/src/export_registration_impl.c b/remote_services/remote_service_admin/private/src/export_registration_impl.c
index 18cff6c..20be900 100644
--- a/remote_services/remote_service_admin/private/src/export_registration_impl.c
+++ b/remote_services/remote_service_admin/private/src/export_registration_impl.c
@@ -171,8 +171,6 @@ celix_status_t exportRegistration_endpointRemoved(void * handle, service_referen
 
 	remote_endpoint_service_pt endpoint = service;
 	if (registration->endpoint != NULL) {
-		remoteServiceAdmin_removeExportedService(registration);
-//		registration->endpoint = NULL;
 		endpoint->setService(endpoint->endpoint, NULL);
 	}
 
@@ -208,9 +206,7 @@ celix_status_t exportRegistration_close(export_registration_pt registration) {
 	exportRegistration_stopTracking(registration);
 
 	bundle_uninstall(registration->bundle);
-	remoteServiceAdmin_removeExportedService(registration);
 
-	exportRegistration_destroy(&registration);
 
 	return status;
 }
@@ -253,8 +249,9 @@ celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference
 	return status;
 }
 
-celix_status_t exportReference_getExportedService(export_reference_pt reference) {
+celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service) {
 	celix_status_t status = CELIX_SUCCESS;
+	*service = reference->reference;
 	return status;
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin/public/include/export_registration.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/public/include/export_registration.h b/remote_services/remote_service_admin/public/include/export_registration.h
index 9332274..dc3882b 100644
--- a/remote_services/remote_service_admin/public/include/export_registration.h
+++ b/remote_services/remote_service_admin/public/include/export_registration.h
@@ -17,6 +17,6 @@ celix_status_t exportRegistration_getException(export_registration_pt registrati
 celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *reference);
 
 celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint);
-celix_status_t exportReference_getExportedService(export_reference_pt reference);
+celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service);
 
 #endif //CELIX_EXPORT_REGISTRATION_H

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin/public/include/remote_service_admin.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/public/include/remote_service_admin.h b/remote_services/remote_service_admin/public/include/remote_service_admin.h
index 274f2e4..1521383 100644
--- a/remote_services/remote_service_admin/public/include/remote_service_admin.h
+++ b/remote_services/remote_service_admin/public/include/remote_service_admin.h
@@ -40,15 +40,15 @@ typedef struct remote_service_admin *remote_service_admin_pt;
 struct remote_service_admin_service {
 	remote_service_admin_pt admin;
 	celix_status_t (*exportService)(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
-	celix_status_t (*removeExportedService)(export_registration_pt registration);
+	celix_status_t (*removeExportedService)(remote_service_admin_pt admin, export_registration_pt registration);
 	celix_status_t (*getExportedServices)(remote_service_admin_pt admin, array_list_pt *services);
 	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);
+	celix_status_t (*exportReference_getExportedService)(export_reference_pt reference, service_reference_pt *service);
 
-	celix_status_t (*exportRegistration_close)(export_registration_pt registration);
+	celix_status_t (*exportRegistration_close)(remote_service_admin_pt admin, export_registration_pt registration);
 	celix_status_t (*exportRegistration_getException)(export_registration_pt registration);
 	celix_status_t (*exportRegistration_getExportReference)(export_registration_pt registration, export_reference_pt *reference);
 	celix_status_t (*exportRegistration_freeExportReference)(export_reference_pt *reference);

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin_dfi/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/CMakeLists.txt b/remote_services/remote_service_admin_dfi/CMakeLists.txt
index 275a991..b25909d 100644
--- a/remote_services/remote_service_admin_dfi/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/CMakeLists.txt
@@ -16,7 +16,7 @@
 # under the License.
 
 
-celix_subproject(RSA_REMOTE_SERVICE_ADMIN_DFI "Option to enable building the Remote Service Admin Service DFI" ON)
+celix_subproject(RSA_REMOTE_SERVICE_ADMIN_DFI "Option to enable building the Remote Service Admin Service DFI" OFF DEPS TOPOLOGY_MANAGER)
 
 if (RSA_REMOTE_SERVICE_ADMIN_DFI)
 

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt b/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
index 2c8ef5d..3fdfd29 100644
--- a/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
@@ -21,6 +21,7 @@ include_directories(
     ${PROJECT_SOURCE_DIR}/log_service/public/include
     ${PROJECT_SOURCE_DIR}/remote_services/utils/private/include
     ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include
+    ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/include
     ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_http/private/include
     ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_dfi/dynamic_function_interface
     ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h b/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
index 64d5392..93f37ba 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
+++ b/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
@@ -26,6 +26,7 @@
 #include "endpoint_description.h"
 
 celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, bundle_context_pt context, export_registration_pt *registration);
+celix_status_t exportRegistration_close(export_registration_pt registration);
 void exportRegistration_destroy(export_registration_pt registration);
 
 celix_status_t exportRegistration_start(export_registration_pt registration);

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h b/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
index 296fc46..8b6140e 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
+++ b/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
@@ -28,6 +28,7 @@ typedef void (*send_func_type)(void *handle, endpoint_description_pt endpointDes
 
 celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt description, const char *classObject,
                                          import_registration_pt *import);
+celix_status_t importRegistration_close(import_registration_pt import);
 void importRegistration_destroy(import_registration_pt import);
 
 celix_status_t importRegistration_setSendFn(import_registration_pt reg,

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h b/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h
index 64e69e4..b820b79 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h
+++ b/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h
@@ -27,6 +27,7 @@
 #ifndef REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
 #define REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
 
+
 #include "bundle_context.h"
 #include "endpoint_description.h"
 
@@ -38,7 +39,7 @@ celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin);
 celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin);
 
 celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
-celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt  admin, export_registration_pt registration);
+celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration);
 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);
@@ -46,7 +47,7 @@ celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt
 
 
 celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint);
-celix_status_t exportReference_getExportedService(export_reference_pt reference);
+celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *service);
 
 celix_status_t importReference_getImportedEndpoint(import_reference_pt reference);
 celix_status_t importReference_getImportedService(import_reference_pt reference);

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
index b528ccd..4b7ec57 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
@@ -200,12 +200,14 @@ static void exportRegistration_removeServ(export_registration_pt reg, service_re
     celixThreadMutex_unlock(&reg->mutex);
 }
 
+
 celix_status_t exportRegistration_close(export_registration_pt reg) {
     celix_status_t status = CELIX_SUCCESS;
     exportRegistration_stop(reg);
     return status;
 }
 
+
 celix_status_t exportRegistration_getException(export_registration_pt registration) {
     celix_status_t status = CELIX_SUCCESS;
     //TODO
@@ -235,8 +237,9 @@ celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference
     return status;
 }
 
-celix_status_t exportReference_getExportedService(export_reference_pt reference) {
+celix_status_t exportReference_getExportedService(export_reference_pt reference, service_reference_pt *ref) {
     celix_status_t status = CELIX_SUCCESS;
+    *ref = reference->reference;
     return status;
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c
index 242e851..d4cc765 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c
@@ -78,7 +78,7 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
 			remoteServiceAdmin->exportReference_getExportedEndpoint = exportReference_getExportedEndpoint;
 			remoteServiceAdmin->exportReference_getExportedService = exportReference_getExportedService;
 
-			remoteServiceAdmin->exportRegistration_close = exportRegistration_close;
+			remoteServiceAdmin->exportRegistration_close = remoteServiceAdmin_removeExportedService;
 			remoteServiceAdmin->exportRegistration_getException = exportRegistration_getException;
 			remoteServiceAdmin->exportRegistration_getExportReference = exportRegistration_getExportReference;
 

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
index 384bd76..01cd700 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
@@ -108,7 +108,7 @@ static const char *DEFAULT_IP = "127.0.0.1";
 static const unsigned int DEFAULT_TIMEOUT = 0;
 
 static int remoteServiceAdmin_callback(struct mg_connection *conn);
-static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, char *interface, endpoint_description_pt *description);
+static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, properties_pt props, char *interface, endpoint_description_pt *description);
 static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
 static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip);
 static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp);
@@ -213,6 +213,14 @@ celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_servi
         } while(((*admin)->ctx == NULL) && (port_counter < MAX_NUMBER_OF_RESTARTS));
 
     }
+
+    if (status != CELIX_SUCCESS)
+    printf("111 status is not success\n ");
+    else {
+        printf("111 status is success\n ");
+
+    }
+
     return status;
 }
 
@@ -418,8 +426,7 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c
         endpoint_description_pt endpoint = NULL;
         export_registration_pt registration = NULL;
 
-        remoteServiceAdmin_createEndpointDescription(admin, reference, interface, &endpoint);
-        printf("RSA: Creating export registration with endpoint pointer %p\n", endpoint);
+        remoteServiceAdmin_createEndpointDescription(admin, reference, properties, interface, &endpoint);
         //TOOD precheck if descriptor exists
         status = exportRegistration_create(admin->loghelper, reference, endpoint, admin->context, &registration);
         if (status == CELIX_SUCCESS) {
@@ -442,25 +449,36 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c
 
 celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration) {
     celix_status_t status = CELIX_SUCCESS;
+
     logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_DFI: Removing exported service");
 
     export_reference_pt  ref = NULL;
     status = exportRegistration_getExportReference(registration, &ref);
 
     if (status == CELIX_SUCCESS) {
+    	service_reference_pt servRef;
         celixThreadMutex_lock(&admin->exportedServicesLock);
+    	exportReference_getExportedService(ref, &servRef);
+
+    	hashMap_remove(admin->exportedServices, servRef);
+
         exportRegistration_close(registration);
-        //exportRegistration_destroy(registration); TODO test
-        hashMap_remove(admin->exportedServices, ref);
+        exportRegistration_destroy(registration);
+
         celixThreadMutex_unlock(&admin->exportedServicesLock);
+
+        if (ref != NULL) {
+        	free(ref);
+        }
     } else {
-        RSA_LOG_ERROR(admin, "Cannot find reference for registration");
+    	logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "Cannot find reference for registration");
     }
 
     return status;
 }
 
-static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, char *interface, endpoint_description_pt *endpoint) {
+static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, properties_pt props, char *interface, endpoint_description_pt *endpoint) {
+
     celix_status_t status = CELIX_SUCCESS;
     properties_pt endpointProperties = properties_create();
 
@@ -477,7 +495,6 @@ static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_servic
             && strcmp(key, (char*) OSGI_RSA_SERVICE_EXPORTED_INTERFACES) != 0
             && strcmp(key, (char*) OSGI_FRAMEWORK_OBJECTCLASS) != 0) {
             properties_set(endpointProperties, key, value);
-            printf("Added property '%s' with value '%s'\n", key, value);
         }
     }
 
@@ -507,7 +524,14 @@ static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_servic
     properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED_CONFIGS, (char*) CONFIGURATION_TYPE);
     properties_set(endpointProperties, (char*) ENDPOINT_URL, url);
 
-
+    if (props != NULL) {
+        hash_map_iterator_pt propIter = hashMapIterator_create(props);
+        while (hashMapIterator_hasNext(propIter)) {
+    	    hash_map_entry_pt entry = hashMapIterator_nextEntry(propIter);
+    	    properties_set(endpointProperties, (char*)hashMapEntry_getKey(entry), (char*)hashMapEntry_getValue(entry));
+        }
+        hashMapIterator_destroy(propIter);
+    }
 
     *endpoint = calloc(1, sizeof(**endpoint));
     if (!*endpoint) {

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c b/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c
index 1b4c59c..2851a29 100644
--- a/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c
+++ b/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c
@@ -76,7 +76,7 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
 			remoteServiceAdmin->exportReference_getExportedEndpoint = exportReference_getExportedEndpoint;
 			remoteServiceAdmin->exportReference_getExportedService = exportReference_getExportedService;
 
-			remoteServiceAdmin->exportRegistration_close = exportRegistration_close;
+			remoteServiceAdmin->exportRegistration_close = remoteServiceAdmin_removeExportedService;
 			remoteServiceAdmin->exportRegistration_getException = exportRegistration_getException;
 			remoteServiceAdmin->exportRegistration_getExportReference = exportRegistration_getExportReference;
 

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c b/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
index c6e9353..8567e23 100644
--- a/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
+++ b/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
@@ -459,19 +459,32 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c
 	return status;
 }
 
-celix_status_t remoteServiceAdmin_removeExportedService(export_registration_pt registration) {
+celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration) {
     celix_status_t status = CELIX_SUCCESS;
-    remote_service_admin_pt admin = registration->rsa;
 
-    celixThreadMutex_lock(&admin->exportedServicesLock);
+    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_HTTP: Removing exported service");
 
-    array_list_pt registrations = (array_list_pt) hashMap_remove(admin->exportedServices, registration->reference);
+    export_reference_pt ref = NULL;
+    status = exportRegistration_getExportReference(registration, &ref);
 
-    if (registrations != NULL) {
-    	arrayList_destroy(registrations);
-    }
+    if (status == CELIX_SUCCESS) {
+    	service_reference_pt servRef;
+        celixThreadMutex_lock(&admin->exportedServicesLock);
+    	exportReference_getExportedService(ref, &servRef);
 
-    celixThreadMutex_unlock(&admin->exportedServicesLock);
+    	hashMap_remove(admin->exportedServices, servRef);
+
+        exportRegistration_close(registration);
+        exportRegistration_destroy(&registration);
+
+        celixThreadMutex_unlock(&admin->exportedServicesLock);
+
+        if (ref != NULL) {
+        	free(ref);
+        }
+    } else {
+    	 logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "Cannot find reference for registration");
+    }
 
     return status;
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin_http/private/test/rsa_client_server_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/test/rsa_client_server_tests.cpp b/remote_services/remote_service_admin_http/private/test/rsa_client_server_tests.cpp
index 8e9676d..a2a087a 100644
--- a/remote_services/remote_service_admin_http/private/test/rsa_client_server_tests.cpp
+++ b/remote_services/remote_service_admin_http/private/test/rsa_client_server_tests.cpp
@@ -476,6 +476,5 @@ TEST(RsaHttpClientServerTests, TestProxyRemoval) {
 TEST(RsaHttpClientServerTests, TestEndpointRemoval) {
 	// test is currenlty failing
 	//testEndpointRemoval();
-
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin_shm/private/src/remote_service_admin_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_shm/private/src/remote_service_admin_activator.c b/remote_services/remote_service_admin_shm/private/src/remote_service_admin_activator.c
index dd2fb4d..a2b72d0 100644
--- a/remote_services/remote_service_admin_shm/private/src/remote_service_admin_activator.c
+++ b/remote_services/remote_service_admin_shm/private/src/remote_service_admin_activator.c
@@ -76,7 +76,7 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
 			remoteServiceAdmin->exportReference_getExportedEndpoint = exportReference_getExportedEndpoint;
 			remoteServiceAdmin->exportReference_getExportedService = exportReference_getExportedService;
 
-			remoteServiceAdmin->exportRegistration_close = exportRegistration_close;
+			remoteServiceAdmin->exportRegistration_close = remoteServiceAdmin_removeExportedService;
 			remoteServiceAdmin->exportRegistration_getException = exportRegistration_getException;
 			remoteServiceAdmin->exportRegistration_getExportReference = exportRegistration_getExportReference;
 

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c b/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
index 385e9be..813fa19 100644
--- a/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
+++ b/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
@@ -552,17 +552,24 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c
     return status;
 }
 
-celix_status_t remoteServiceAdmin_removeExportedService(export_registration_pt registration) {
+celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration) {
     celix_status_t status = CELIX_SUCCESS;
-    remote_service_admin_pt admin = registration->rsa;
     ipc_segment_pt ipc = NULL;
 
-    celixThreadMutex_lock(&admin->exportedServicesLock);
+    export_reference_pt ref = NULL;
+    status = exportRegistration_getExportReference(registration, &ref);
+
+    if (status == CELIX_SUCCESS) {
+        bool *pollThreadRunning = NULL;
+
+        service_reference_pt servRef;
+        celixThreadMutex_lock(&admin->exportedServicesLock);
+        exportReference_getExportedService(ref, &servRef);
 
-    array_list_pt registrations = hashMap_remove(admin->exportedServices, registration->reference);
+        hashMap_remove(admin->exportedServices, servRef);
+
+        exportRegistration_close(registration);
 
-    if ((registrations) != NULL) {
-    	bool *pollThreadRunning = NULL;
         if ((pollThreadRunning = hashMap_get(admin->pollThreadRunning, registration->endpointDescription)) != NULL) {
             *pollThreadRunning = false;
 
@@ -575,7 +582,7 @@ celix_status_t remoteServiceAdmin_removeExportedService(export_registration_pt r
                     status = celixThread_join(*pollThread, NULL);
 
                     if (status == CELIX_SUCCESS) {
-                        semctl(ipc->semId, 1 /*ignored*/, IPC_RMID);
+                        semctl(ipc->semId, 1 , IPC_RMID);
                         shmctl(ipc->shmId, IPC_RMID, 0);
 
                         remoteServiceAdmin_removeSharedIdentityFile(admin, registration->endpointDescription->frameworkUUID, registration->endpointDescription->service);
@@ -591,10 +598,9 @@ celix_status_t remoteServiceAdmin_removeExportedService(export_registration_pt r
                 }
             }
         }
-
-        arrayList_destroy(registrations);
-        registrations = NULL;
+        exportRegistration_destroy(&registration);
     }
+
     celixThreadMutex_unlock(&admin->exportedServicesLock);
 
     return status;

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/remote_service_admin_shm/private/test/rsa_client_server_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_shm/private/test/rsa_client_server_tests.cpp b/remote_services/remote_service_admin_shm/private/test/rsa_client_server_tests.cpp
index c5ca43b..b2ebb39 100644
--- a/remote_services/remote_service_admin_shm/private/test/rsa_client_server_tests.cpp
+++ b/remote_services/remote_service_admin_shm/private/test/rsa_client_server_tests.cpp
@@ -453,6 +453,7 @@ extern "C" {
 	}
 };
 
+
 TEST(RsaShmClientServerTests, Test1) {
 	test1();
 }
@@ -465,7 +466,7 @@ TEST(RsaShmClientServerTests, TestExport) {
 	// test is currenlty failing
 	//testExport();
 }
-
+/*
 TEST(RsaShmClientServerTests, TestProxyRemoval) {
 	// test is currenlty failing
 	// testProxyRemoval();
@@ -475,4 +476,4 @@ TEST(RsaShmClientServerTests, TestEndpointRemoval) {
 	// test is currenlty failing
 	//testEndpointRemoval();
 }
-
+*/

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/topology_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/CMakeLists.txt b/remote_services/topology_manager/CMakeLists.txt
index 27d8501..65194aa 100644
--- a/remote_services/topology_manager/CMakeLists.txt
+++ b/remote_services/topology_manager/CMakeLists.txt
@@ -14,7 +14,7 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-celix_subproject(RSA_TOPOLOGY_MANAGER "Option to enable building the Remote Service Admin Service SHM bundle" ON)
+celix_subproject(RSA_TOPOLOGY_MANAGER "Option to enable building the Remote Service Admin Service SHM bundle" ON DEPS REMOTE_SERVICE_ADMIN_DFI)
 if (RSA_TOPOLOGY_MANAGER)
     include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
     include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/public/include")
@@ -22,21 +22,32 @@ if (RSA_TOPOLOGY_MANAGER)
     include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
     include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
     include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
+    include_directories("${PROJECT_SOURCE_DIR}/remote_services/topology_manager/public/include")
 
     SET_HEADER(BUNDLE_SYMBOLICNAME "apache_celix_rs_topology_manager")
-    SET(BUNDLE_VERSION "0.0.1")
+    SET(BUNDLE_VERSION "0.0.2")
     SET_HEADERS("Bundle-Name: Apache Celix RS Topology Manager")
 
     bundle(topology_manager SOURCES
         private/src/topology_manager
+        private/src/scope
         private/src/activator
 
         ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
 
         private/include/topology_manager.h
+        public/include/tm_scope.h
     )
 
     install_bundle(topology_manager)
 
-    target_link_libraries(topology_manager celix_framework)
+    if (ENABLE_TESTING)
+        find_package(CppUTest REQUIRED)
+
+        include_directories(${CPPUTEST_INCLUDE_DIR})
+        include_directories(${CPPUTEST_EXT_INCLUDE_DIR})
+        add_subdirectory(tms_tst)
+   endif (ENABLE_TESTING)
+
+   target_link_libraries(topology_manager celix_framework)
 endif (RSA_TOPOLOGY_MANAGER)

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/topology_manager/private/include/scope.h
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/private/include/scope.h b/remote_services/topology_manager/private/include/scope.h
new file mode 100644
index 0000000..4035e2c
--- /dev/null
+++ b/remote_services/topology_manager/private/include/scope.h
@@ -0,0 +1,150 @@
+/**
+ *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.
+ */
+/*
+ * scope.h
+ *
+ *  \date       Sep 29, 2015
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+
+#ifndef TOPOLOGY_SCOPE_H_
+#define TOPOLOGY_SCOPE_H_
+
+#include "celixbool.h"
+#include "celix_errno.h"
+#include "celix_threads.h"
+#include "hash_map.h"
+#include "endpoint_description.h"
+#include "properties.h"
+#include "service_reference.h"
+#include "tm_scope.h"
+
+typedef struct scope *scope_pt;
+
+
+
+/* \brief  create scope structure
+ *
+ * \param  owning component pointer
+ * \param  scope to be created
+ *
+ * \return CELIX_SUCCESS
+ *         CELIX_ENOMEM
+ */
+celix_status_t scope_scopeCreate(void *handle, scope_pt *scope);
+
+/* \brief  destroy scope structure
+ *
+ * \param  scope to be destroyed
+ *
+ * \return CELIX_SUCCESS
+ */
+celix_status_t scope_scopeDestroy(scope_pt scope);
+
+/* \brief  register export scope change callback of topology manager
+ *
+ * \param  scope structure
+ * \param  changed function pointer
+ *
+ * \return -
+ */
+void scope_setExportScopeChangedCallback(scope_pt scope, celix_status_t (*changed)(void *handle, char *servName));
+
+/* \brief  register import scope change callback of topology manager
+ *
+ * \param  scope structure
+ * \param  changed function pointer
+ *
+ * \return -
+ */
+void scope_setImportScopeChangedCallback(scope_pt scope, celix_status_t (*changed)(void *handle, char *servName));
+
+
+/* \brief  Test if scope allows import of service
+ *
+ * \param  scope containing import rules
+ * \param  endpoint import service endpoint description
+ *
+ * \return true import allowed
+ *         false import not allowed
+ */
+bool scope_allowImport(scope_pt scope, endpoint_description_pt endpoint);
+
+/* \brief  Test if scope allows import of service
+ *
+ * \param  scope containing export rules
+ * \param  reference to service
+ * \param  props, additional properties defining restrictions for the exported service
+ *                NULL if no additional restrictions found
+ *
+ * \return CELIX_SUCCESS
+ *
+ */
+celix_status_t scope_getExportProperties(scope_pt scope, service_reference_pt reference, properties_pt *props);
+
+/* \brief  add restricted scope for specified exported service
+ *
+ * \param  handle pointer to scope
+ * \param  filter, filter string
+ * \param  props additional properties defining restrictions for the exported service
+ *
+ * \return CELIX_SUCCESS if added to scope
+ *         CELIX_ILLEGAL_ARGUMENT if service scope is already restricted before
+ *
+ */
+celix_status_t tm_addExportScope(void *handle, char *filter, properties_pt props);
+
+/* \brief  remove restricted scope for specified exported service
+ *
+ * \param  handle pointer to scope
+ * \param  filter, filter string
+ *
+ * \return CELIX_SUCCESS if removed
+ *         CELIX_ILLEGAL_ARGUMENT if service not found in scope
+ *
+ */
+celix_status_t tm_removeExportScope(void *handle, char *filter);
+
+/* \brief  add restricted scope for specified imported service
+ *
+ * \param  handle pointer to scope
+ * \param  filter, filter string
+ * \param  props additional properties defining restrictions for the imported service
+ *
+ * \return CELIX_SUCCESS if added to scope
+ *         CELIX_ILLEGAL_ARGUMENT if service scope is already restricted before
+ *
+ */
+celix_status_t tm_addImportScope(void *handle, char *filter);
+
+
+/* \brief  remove restricted scope for specified imported service
+ *
+ * \param  handle pointer to scope
+ * \param  filter, filter string
+ *
+ * \return CELIX_SUCCESS if removed
+ *         CELIX_ILLEGAL_ARGUMENT if service not found in scope
+ *
+ */
+celix_status_t tm_removeImportScope(void *handle, char *filter);
+
+
+#endif // TOPOLOGY_SCOPE_H_

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/topology_manager/private/include/topology_manager.h
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/private/include/topology_manager.h b/remote_services/topology_manager/private/include/topology_manager.h
index ade5a1e..7e5e917 100644
--- a/remote_services/topology_manager/private/include/topology_manager.h
+++ b/remote_services/topology_manager/private/include/topology_manager.h
@@ -31,12 +31,13 @@
 #include "service_reference.h"
 #include "bundle_context.h"
 #include "log_helper.h"
+#include "scope.h"
 
 #define OSGI_RSA_REMOTE_SERVICE_ADMIN "remote_service_admin"
 
 typedef struct topology_manager *topology_manager_pt;
 
-celix_status_t topologyManager_create(bundle_context_pt context, log_helper_pt logHelper, topology_manager_pt *manager);
+celix_status_t topologyManager_create(bundle_context_pt context, log_helper_pt logHelper, topology_manager_pt *manager, void **scope);
 celix_status_t topologyManager_destroy(topology_manager_pt manager);
 celix_status_t topologyManager_closeImports(topology_manager_pt manager);
 

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/topology_manager/private/src/activator.c
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/private/src/activator.c b/remote_services/topology_manager/private/src/activator.c
index 42046b3..a6ee750 100644
--- a/remote_services/topology_manager/private/src/activator.c
+++ b/remote_services/topology_manager/private/src/activator.c
@@ -39,6 +39,9 @@
 #include "listener_hook_service.h"
 #include "log_service.h"
 #include "log_helper.h"
+#include "scope.h"
+#include "tm_scope.h"
+#include "topology_manager.h"
 
 struct activator {
     bundle_context_pt context;
@@ -55,6 +58,9 @@ struct activator {
     listener_hook_service_pt hookService;
     service_registration_pt hook;
 
+    tm_scope_service_pt	scopeService;
+    service_registration_pt scopeReg;
+
     log_helper_pt loghelper;
 };
 
@@ -66,8 +72,9 @@ static celix_status_t bundleActivator_createServiceListener(struct activator *ac
 celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
     celix_status_t status = CELIX_SUCCESS;
     struct activator *activator = NULL;
+    void *scope;
 
-    activator = malloc(sizeof(struct activator));
+    activator = calloc(1, sizeof(struct activator));
 
     if (!activator) {
         return CELIX_ENOMEM;
@@ -80,11 +87,25 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData
     activator->manager = NULL;
     activator->remoteServiceAdminTracker = NULL;
     activator->serviceListener = NULL;
+    activator->scopeService = calloc(1, sizeof(*(activator->scopeService)));
+    if (activator->scopeService == NULL)
+    {
+    	free(activator);
+    	return CELIX_ENOMEM;
+    }
+
+    activator->scopeService->addExportScope = tm_addExportScope;
+    activator->scopeService->removeExportScope = tm_removeExportScope;
+    activator->scopeService->addImportScope = tm_addImportScope;
+    activator->scopeService->removeImportScope = tm_removeImportScope;
+    activator->scopeReg = NULL; // explicitly needed, otherwise exception
 
     logHelper_create(context, &activator->loghelper);
     logHelper_start(activator->loghelper);
 
-    status = topologyManager_create(context, activator->loghelper, &activator->manager);
+    status = topologyManager_create(context, activator->loghelper, &activator->manager, &scope);
+    activator->scopeService->handle = scope;
+
     if (status == CELIX_SUCCESS) {
         status = bundleActivator_createEPLTracker(activator, &activator->endpointListenerTracker);
         if (status == CELIX_SUCCESS) {
@@ -92,7 +113,7 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData
             if (status == CELIX_SUCCESS) {
                 status = bundleActivator_createServiceListener(activator, &activator->serviceListener);
                 if (status == CELIX_SUCCESS) {
-                    *userData = activator;
+                	*userData = activator;
                 }
             }
         }
@@ -117,7 +138,7 @@ static celix_status_t bundleActivator_createEPLTracker(struct activator *activat
 }
 
 static celix_status_t bundleActivator_createRSATracker(struct activator *activator, service_tracker_pt *tracker) {
-    celix_status_t status = CELIX_SUCCESS;
+    celix_status_t status;
 
     service_tracker_customizer_pt customizer = NULL;
 
@@ -145,7 +166,7 @@ static celix_status_t bundleActivator_createServiceListener(struct activator *ac
 }
 
 celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
-    celix_status_t status = CELIX_SUCCESS;
+    celix_status_t status;
     struct activator *activator = userData;
 
     endpoint_listener_pt endpointListener = malloc(sizeof(*endpointListener));
@@ -196,6 +217,8 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
         status = serviceTracker_open(activator->endpointListenerTracker);
     }
 
+	bundleContext_registerService(context, (char *) TOPOLOGYMANAGER_SCOPE_SERVICE, activator->scopeService, NULL, &activator->scopeReg);
+
     array_list_pt references = NULL;
     bundleContext_getServiceReferences(context, NULL, "(service.exported.interfaces=*)", &references);
     int i;
@@ -203,9 +226,9 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
         service_reference_pt reference = arrayList_get(references, i);
         char *serviceId = NULL;
         status = CELIX_DO_IF(status, serviceReference_getProperty(reference, (char *)OSGI_FRAMEWORK_SERVICE_ID, &serviceId));
-        status = CELIX_DO_IF(status, topologyManager_addExportedService(activator->manager, reference, serviceId));
-    }
 
+        CELIX_DO_IF(status, topologyManager_addExportedService(activator->manager, reference, serviceId));
+    }
     arrayList_destroy(references);
 
     return status;
@@ -232,6 +255,8 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context)
     serviceRegistration_unregister(activator->endpointListenerService);
     free(activator->endpointListener);
 
+    serviceRegistration_unregister(activator->scopeReg);
+
     topologyManager_closeImports(activator->manager);
 
     return status;
@@ -248,6 +273,11 @@ celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt contex
         logHelper_destroy(&activator->loghelper);
 
         status = topologyManager_destroy(activator->manager);
+
+        if (activator->scopeService) {
+        	free(activator->scopeService);
+        }
+
         free(activator);
     }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/fe94cd14/remote_services/topology_manager/private/src/scope.c
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/private/src/scope.c b/remote_services/topology_manager/private/src/scope.c
new file mode 100644
index 0000000..38eadfc
--- /dev/null
+++ b/remote_services/topology_manager/private/src/scope.c
@@ -0,0 +1,327 @@
+/**
+ *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.
+ */
+/*
+ * scope.c
+ *
+ *  \date       Sep 29, 2015
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <jansson.h>
+#include "scope.h"
+#include "tm_scope.h"
+#include "topology_manager.h"
+#include "utils.h"
+
+struct scope_item {
+    properties_pt props;
+};
+
+struct scope {
+    void *manager;	// owner of the scope datastructure
+    celix_thread_mutex_t exportScopeLock;
+    hash_map_pt exportScopes;           // key is filter, value is scope_item (properties set)
+
+    celix_thread_mutex_t importScopeLock;
+    array_list_pt importScopes;			// list of filters
+
+    celix_status_t (*exportScopeChangedHandler)(void* manager, char *filter);
+    celix_status_t (*importScopeChangedHandler)(void* manager, char *filter);
+};
+
+static celix_status_t import_equal(void *, void *, bool *equals);
+
+/*
+ * SERVICES
+ */
+
+celix_status_t tm_addExportScope(void *handle, char *filter, properties_pt props) {
+    celix_status_t status = CELIX_SUCCESS;
+    scope_pt scope = (scope_pt) handle;
+    properties_pt present;
+
+    if (handle == NULL)
+        return CELIX_ILLEGAL_ARGUMENT;
+
+    if (celixThreadMutex_lock(&scope->exportScopeLock) == CELIX_SUCCESS) {
+        // For now we just don't allow two exactly the same filters
+        // TODO: What we actually need is the following
+        // If part of the new filter is already present in any of the filters in exportScopes
+        // we have to assure that the new filter defines other property keys than the property keys
+        // in the already defined filter!
+        present = (properties_pt) hashMap_get(scope->exportScopes, filter);
+        if (present == NULL) {
+            struct scope_item *item = calloc(1, sizeof(*item));
+            if (item == NULL) {
+                status = CELIX_ENOMEM;
+            } else {
+                item->props = props;
+                hashMap_put(scope->exportScopes, (void*) strdup(filter), (void*) item);
+            }
+        } else {
+            // don't allow the same filter twice
+            properties_destroy(props);
+            status = CELIX_ILLEGAL_ARGUMENT;
+        }
+        celixThreadMutex_unlock(&scope->exportScopeLock);
+    }
+
+    if (scope->exportScopeChangedHandler != NULL) {
+        status = CELIX_DO_IF(status, scope->exportScopeChangedHandler(scope->manager, filter));
+    }
+
+    return status;
+}
+
+celix_status_t tm_removeExportScope(void *handle, char *filter) {
+    celix_status_t status = CELIX_SUCCESS;
+    scope_pt scope = (scope_pt) handle;
+
+    if (handle == NULL)
+        return CELIX_ILLEGAL_ARGUMENT;
+
+    if (celixThreadMutex_lock(&scope->exportScopeLock) == CELIX_SUCCESS) {
+        struct scope_item *present = (struct scope_item *) hashMap_get(scope->exportScopes, filter);
+        if (present == NULL) {
+            status = CELIX_ILLEGAL_ARGUMENT;
+        } else {
+            properties_destroy(present->props);
+            hashMap_remove(scope->exportScopes, filter); // frees also the item!
+        }
+        celixThreadMutex_unlock(&scope->exportScopeLock);
+    }
+    if (scope->exportScopeChangedHandler != NULL) {
+        status = CELIX_DO_IF(status, scope->exportScopeChangedHandler(scope->manager, filter));
+    }
+    return status;
+}
+
+celix_status_t tm_addImportScope(void *handle, char *filter) {
+    celix_status_t status = CELIX_SUCCESS;
+    scope_pt scope = (scope_pt) handle;
+
+    filter_pt new;
+
+    if (handle == NULL)
+        return CELIX_ILLEGAL_ARGUMENT;
+    new = filter_create(filter);
+    if (new == NULL) {
+        return CELIX_ILLEGAL_ARGUMENT; // filter not parseble
+    }
+    if (celixThreadMutex_lock(&scope->importScopeLock) == CELIX_SUCCESS) {
+        int index = arrayList_indexOf(scope->importScopes, new);
+        filter_pt present = (filter_pt) arrayList_get(scope->importScopes, index);
+        if (present == NULL) {
+            arrayList_add(scope->importScopes, new);
+        } else {
+            filter_destroy(new);
+            status = CELIX_ILLEGAL_ARGUMENT;
+        }
+
+        celixThreadMutex_unlock(&scope->importScopeLock);
+    }
+    if (scope->importScopeChangedHandler != NULL) {
+        status = CELIX_DO_IF(status, scope->importScopeChangedHandler(scope->manager, filter));
+    }
+    return status;
+}
+
+celix_status_t tm_removeImportScope(void *handle, char *filter) {
+    celix_status_t status = CELIX_SUCCESS;
+    scope_pt scope = (scope_pt) handle;
+    filter_pt new;
+
+    if (handle == NULL)
+        return CELIX_ILLEGAL_ARGUMENT;
+
+    new = filter_create(filter);
+    if (new == NULL) {
+        return CELIX_ILLEGAL_ARGUMENT; // filter not parseble
+    }
+
+    if (celixThreadMutex_lock(&scope->importScopeLock) == CELIX_SUCCESS) {
+        int index = arrayList_indexOf(scope->importScopes, new);
+        filter_pt present = (filter_pt) arrayList_get(scope->importScopes, index);
+        if (present == NULL)
+            status = CELIX_ILLEGAL_ARGUMENT;
+        else {
+            arrayList_removeElement(scope->importScopes, present);
+            filter_destroy(present);
+        }
+        celixThreadMutex_unlock(&scope->importScopeLock);
+    }
+    if (scope->importScopeChangedHandler != NULL) {
+        status = CELIX_DO_IF(status, scope->importScopeChangedHandler(scope->manager, filter));
+    }
+    filter_destroy(new);
+    return status;
+}
+
+/*****************************************************************************
+ * GLOBAL FUNCTIONS
+ *****************************************************************************/
+
+void scope_setExportScopeChangedCallback(scope_pt scope, celix_status_t (*changed)(void *handle, char *servName)) {
+    scope->exportScopeChangedHandler = changed;
+}
+
+void scope_setImportScopeChangedCallback(scope_pt scope, celix_status_t (*changed)(void *handle, char *servName)) {
+    scope->importScopeChangedHandler = changed;
+}
+
+celix_status_t scope_scopeCreate(void *handle, scope_pt *scope) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    *scope = calloc(1, sizeof **scope);
+
+    if (*scope == NULL) {
+        return CELIX_ENOMEM;
+    }
+
+    (*scope)->manager = handle;
+    celixThreadMutex_create(&(*scope)->exportScopeLock, NULL);
+    celixThreadMutex_create(&(*scope)->importScopeLock, NULL);
+
+    (*scope)->exportScopes = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+    arrayList_createWithEquals(import_equal, &((*scope)->importScopes));
+    (*scope)->exportScopeChangedHandler = NULL;
+
+    return status;
+}
+
+celix_status_t scope_scopeDestroy(scope_pt scope) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    if (celixThreadMutex_lock(&scope->exportScopeLock) == CELIX_SUCCESS) {
+        hash_map_iterator_pt iter = hashMapIterator_create(scope->exportScopes);
+        while (hashMapIterator_hasNext(iter)) {
+            hash_map_entry_pt scopedEntry = hashMapIterator_nextEntry(iter);
+            struct scope_item *item = (struct scope_item*) hashMapEntry_getValue(scopedEntry);
+            properties_destroy(item->props);
+        }
+        hashMapIterator_destroy(iter);
+        hashMap_destroy(scope->exportScopes, true, true); // free keys, free values
+        celixThreadMutex_unlock(&scope->exportScopeLock);
+    }
+
+    if (celixThreadMutex_lock(&scope->importScopeLock) == CELIX_SUCCESS) {
+        array_list_iterator_pt imp_iter = arrayListIterator_create(scope->importScopes);
+        while (arrayListIterator_hasNext(imp_iter)) {
+            filter_pt element = (filter_pt) arrayListIterator_next(imp_iter);
+            filter_destroy(element);
+            // no need to call arrayList_removeElement(element) because complete list is destroyed
+        }
+        arrayListIterator_destroy(imp_iter);
+        arrayList_destroy(scope->importScopes);
+        celixThreadMutex_unlock(&scope->importScopeLock);
+    }
+
+    celixThreadMutex_destroy(&scope->exportScopeLock);
+    celixThreadMutex_destroy(&scope->importScopeLock);
+    free(scope);
+    return status;
+}
+
+/*****************************************************************************
+ * STATIC FUNCTIONS
+ *****************************************************************************/
+static celix_status_t import_equal(void *src, void *dest, bool *equals) {
+    celix_status_t status;
+
+    filter_pt src_filter = (filter_pt) src;
+    filter_pt dest_filter = (filter_pt) dest;
+    status = filter_match_filter(src_filter, dest_filter, equals);
+    return status;
+}
+
+bool scope_allowImport(scope_pt scope, endpoint_description_pt endpoint) {
+    bool allowImport = false;
+    array_list_iterator_pt iter;
+
+    if (celixThreadMutex_lock(&(scope->importScopeLock)) == CELIX_SUCCESS) {
+        if (arrayList_size(scope->importScopes) == 0) {
+            allowImport = true;
+        } else {
+            iter = arrayListIterator_create(scope->importScopes);
+            while ((allowImport == false) && arrayListIterator_hasNext(iter)) {
+                filter_pt element = (filter_pt) arrayListIterator_next(iter);
+                filter_match(element, endpoint->properties, &allowImport);
+            }
+            arrayListIterator_destroy(iter);
+        }
+        celixThreadMutex_unlock(&scope->importScopeLock);
+    }
+    return allowImport;
+}
+
+celix_status_t scope_getExportProperties(scope_pt scope, service_reference_pt reference, properties_pt *props) {
+    celix_status_t status = CELIX_SUCCESS;
+    unsigned int size = 0;
+    char **keys;
+    bool found = false;
+
+    *props = NULL;
+    properties_pt serviceProperties = properties_create();  // GB: not sure if a copy is needed
+                                                            // or serviceReference_getProperties() is
+                                                            // is acceptable
+
+    serviceReference_getPropertyKeys(reference, &keys, &size);
+    for (int i = 0; i < size; i++) {
+        char *key = keys[i];
+        char *value = NULL;
+
+        if (serviceReference_getProperty(reference, key, &value) == CELIX_SUCCESS) {
+//        		&& strcmp(key, (char*) OSGI_RSA_SERVICE_EXPORTED_INTERFACES) != 0
+//        		&& strcmp(key, (char*) OSGI_FRAMEWORK_OBJECTCLASS) != 0) {
+            properties_set(serviceProperties, key, value);
+        }
+
+    }
+
+    free(keys);
+
+    if (celixThreadMutex_lock(&(scope->exportScopeLock)) == CELIX_SUCCESS) {
+        hash_map_iterator_pt scopedPropIter = hashMapIterator_create(scope->exportScopes);
+        // TODO: now stopping if first filter matches, alternatively we could build up
+        //       the additional output properties for each filter that matches?
+        while ((!found) && hashMapIterator_hasNext(scopedPropIter)) {
+            hash_map_entry_pt scopedEntry = hashMapIterator_nextEntry(scopedPropIter);
+            char *filterStr = (char *) hashMapEntry_getKey(scopedEntry);
+            filter_pt filter = filter_create(filterStr);
+            if (filter != NULL) {
+                // test if the scope filter matches the exported service properties
+                status = filter_match(filter, serviceProperties, &found);
+                if (found) {
+                    struct scope_item *item = (struct scope_item *) hashMapEntry_getValue(scopedEntry);
+                    *props = item->props;
+                }
+            }
+            filter_destroy(filter);
+        }
+        hashMapIterator_destroy(scopedPropIter);
+        properties_destroy(serviceProperties);
+
+        celixThreadMutex_unlock(&(scope->exportScopeLock));
+    }
+
+    return status;
+}


Mime
View raw message