celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpe...@apache.org
Subject celix git commit: CELIX-328: Add service version support for RSA DFI
Date Tue, 05 Jan 2016 15:04:31 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 265bcb416 -> 63b9aa86e


CELIX-328: Add service version support for RSA DFI


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

Branch: refs/heads/develop
Commit: 63b9aa86e4526434403a721a8b1fa114b3f92926
Parents: 265bcb4
Author: Bjoern Petri <bpetri@apache.org>
Authored: Tue Jan 5 16:03:49 2016 +0100
Committer: Bjoern Petri <bpetri@apache.org>
Committed: Tue Jan 5 16:03:49 2016 +0100

----------------------------------------------------------------------
 cmake/cmake_celix/Config.cmake.in               |  4 ++
 cmake/cmake_celix/Packaging.cmake               |  1 +
 cmake/cmake_celix/RunConfig.in                  |  2 +-
 cmake/cmake_celix/run.sh.in                     |  2 +-
 .../discovery_etcd/private/src/etcd_watcher.c   |  2 +-
 ...apache.celix.calc.api.Calculator2.descriptor |  2 +-
 .../examples/calculator_shell/CMakeLists.txt    |  1 +
 ...apache.celix.calc.api.Calculator2.descriptor | 11 +++++
 .../calculator_shell/private/src/add_command.c  |  9 +++-
 .../calculator_shell/private/src/sqrt_command.c |  9 +++-
 .../calculator_shell/private/src/sub_command.c  |  9 +++-
 remote_services/examples/deploy.cmake           |  8 +++-
 .../private/include/import_registration_dfi.h   |  2 +-
 .../rsa/private/src/export_registration_dfi.c   | 11 ++++-
 .../rsa/private/src/import_registration_dfi.c   | 50 +++++++++++++++-----
 .../rsa/private/src/remote_service_admin_dfi.c  | 13 +++--
 .../rsa_tst/rsa_tests.cpp                       |  1 +
 .../topology_manager/tms_tst/tms_tests.cpp      |  4 ++
 utils/private/src/version.c                     | 17 +++++++
 utils/private/test/version_test.cpp             | 34 ++++++++++++-
 utils/public/include/version.h                  | 18 +++++++
 21 files changed, 182 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/cmake/cmake_celix/Config.cmake.in
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/Config.cmake.in b/cmake/cmake_celix/Config.cmake.in
new file mode 100644
index 0000000..9b4c9ee
--- /dev/null
+++ b/cmake/cmake_celix/Config.cmake.in
@@ -0,0 +1,4 @@
+@PACKAGE_INIT@
+
+include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake")
+check_required_components("@PROJECT_NAME@")

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/cmake/cmake_celix/Packaging.cmake
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/Packaging.cmake b/cmake/cmake_celix/Packaging.cmake
index f802a9c..69d5a46 100644
--- a/cmake/cmake_celix/Packaging.cmake
+++ b/cmake/cmake_celix/Packaging.cmake
@@ -421,6 +421,7 @@ MACRO(deploy)
 		ELSE(CELIX_FOUND)
 			set(FW_PATH ${CMAKE_BINARY_DIR}/framework)
 			set(UTILS_PATH ${CMAKE_BINARY_DIR}/utils)
+			set(DFI_PATH ${CMAKE_BINARY_DIR}/dfi)
 			set(LAUNCHER ${CMAKE_BINARY_DIR}/launcher/celix)
 		ENDIF(CELIX_FOUND)
 		

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/cmake/cmake_celix/RunConfig.in
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/RunConfig.in b/cmake/cmake_celix/RunConfig.in
index a63be99..641f434 100644
--- a/cmake/cmake_celix/RunConfig.in
+++ b/cmake/cmake_celix/RunConfig.in
@@ -16,6 +16,6 @@
 <listEntry value="4"/>
 </listAttribute>
 <mapAttribute key="org.eclipse.debug.core.environmentVariables">
-<mapEntry key="@LIBRARY_PATH@" value="@FW_PATH@:@UTILS_PATH@"/>
+<mapEntry key="@LIBRARY_PATH@" value="@FW_PATH@:@UTILS_PATH@:@DFI_PATH@"/>
 </mapAttribute>
 </launchConfiguration>

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/cmake/cmake_celix/run.sh.in
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/run.sh.in b/cmake/cmake_celix/run.sh.in
index 606f0e6..05e68d1 100644
--- a/cmake/cmake_celix/run.sh.in
+++ b/cmake/cmake_celix/run.sh.in
@@ -1,2 +1,2 @@
-export @LIBRARY_PATH@=@FW_PATH@:@UTILS_PATH@
+export @LIBRARY_PATH@=@FW_PATH@:@UTILS_PATH@:@DFI_PATH@
 @LAUNCHER@ $@

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/remote_services/discovery_etcd/private/src/etcd_watcher.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_etcd/private/src/etcd_watcher.c b/remote_services/discovery_etcd/private/src/etcd_watcher.c
index 9e3a0f7..919aefd 100644
--- a/remote_services/discovery_etcd/private/src/etcd_watcher.c
+++ b/remote_services/discovery_etcd/private/src/etcd_watcher.c
@@ -58,7 +58,7 @@ struct etcd_watcher {
 #define DEFAULT_ETCD_SERVER_IP	"127.0.0.1"
 
 #define CFG_ETCD_SERVER_PORT	"DISCOVERY_ETCD_SERVER_PORT"
-#define DEFAULT_ETCD_SERVER_PORT 4001
+#define DEFAULT_ETCD_SERVER_PORT 2379
 
 // be careful - this should be higher than the curl timeout
 #define CFG_ETCD_TTL   "DISCOVERY_ETCD_TTL"

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
b/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
index c8ba53d..b784838 100644
--- a/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
+++ b/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
@@ -1,7 +1,7 @@
 :header
 type=interface
 name=calculator
-version=1.0.0
+version=1.3.0
 :annotations
 classname=org.example.Calculator
 :types

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/remote_services/examples/calculator_shell/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/CMakeLists.txt b/remote_services/examples/calculator_shell/CMakeLists.txt
index b93afca..24a4d1e 100644
--- a/remote_services/examples/calculator_shell/CMakeLists.txt
+++ b/remote_services/examples/calculator_shell/CMakeLists.txt
@@ -36,6 +36,7 @@ bundle(calculator_shell SOURCES
 
         FILES
             ../calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
+            #private/include/org.apache.celix.calc.api.Calculator2.descriptor ##Use this
descriptor in case you want to try out versioning!
 )
 
 target_link_libraries(calculator_shell celix_framework)

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/remote_services/examples/calculator_shell/private/include/org.apache.celix.calc.api.Calculator2.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/private/include/org.apache.celix.calc.api.Calculator2.descriptor
b/remote_services/examples/calculator_shell/private/include/org.apache.celix.calc.api.Calculator2.descriptor
new file mode 100644
index 0000000..789af9a
--- /dev/null
+++ b/remote_services/examples/calculator_shell/private/include/org.apache.celix.calc.api.Calculator2.descriptor
@@ -0,0 +1,11 @@
++:header
++type=interface
++name=calculator
++version=1.2.3
++:annotations
++classname=org.example.Calculator
++:types
++:methods
++add(DD)D=add(#am=handle;PDD#am=pre;*D)N
++sub(DD)D=sub(#am=handle;PDD#am=pre;*D)N
++sqrt(D)D=sqrt(#am=handle;PD#am=pre;*D)N

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/remote_services/examples/calculator_shell/private/src/add_command.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/private/src/add_command.c b/remote_services/examples/calculator_shell/private/src/add_command.c
index 838ff25..b003a5b 100644
--- a/remote_services/examples/calculator_shell/private/src/add_command.c
+++ b/remote_services/examples/calculator_shell/private/src/add_command.c
@@ -42,6 +42,13 @@ void addCommand_execute(bundle_context_pt context, char *line, FILE *out,
FILE *
     service_reference_pt calculatorService = NULL;
 
     status = bundleContext_getServiceReference(context, (char *) CALCULATOR_SERVICE, &calculatorService);
+    if (calculatorService == NULL) {
+        fprintf(err, "ADD: Cannot get reference for %s. Trying to get one for %s\n", CALCULATOR_SERVICE,
CALCULATOR2_SERVICE);
+        status = bundleContext_getServiceReference(context, (char *) CALCULATOR2_SERVICE,
&calculatorService);
+        if (calculatorService == NULL) {
+            fprintf(err, "ADD: Cannot get reference even for %s.\n", CALCULATOR2_SERVICE);
+        }
+    }
     if (status == CELIX_SUCCESS) {
     	char *token = line;
     	strtok_r(line, " ", &token);
@@ -54,7 +61,7 @@ void addCommand_execute(bundle_context_pt context, char *line, FILE *out,
FILE *
 			if (bStr != NULL && numeric) {
 				calculator_service_pt calculator = NULL;
 				status = bundleContext_getService(context, calculatorService, (void *) &calculator);
-				if (status == CELIX_SUCCESS) {
+                if (status == CELIX_SUCCESS && calculator != NULL) {
 					double a = atof(aStr);
 					double b = atof(bStr);
 					double result = 0;

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/remote_services/examples/calculator_shell/private/src/sqrt_command.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/private/src/sqrt_command.c b/remote_services/examples/calculator_shell/private/src/sqrt_command.c
index 3cd0e5d..8c53896 100644
--- a/remote_services/examples/calculator_shell/private/src/sqrt_command.c
+++ b/remote_services/examples/calculator_shell/private/src/sqrt_command.c
@@ -40,6 +40,13 @@ void sqrtCommand_execute(bundle_context_pt context, char *line, FILE *out,
FILE
     service_reference_pt calculatorService = NULL;
 
     status = bundleContext_getServiceReference(context, (char *) CALCULATOR_SERVICE, &calculatorService);
+    if (calculatorService == NULL) {
+        fprintf(err, "SQRT: Cannot get reference for %s. Trying to get one for %s\n", CALCULATOR_SERVICE,
CALCULATOR2_SERVICE);
+        status = bundleContext_getServiceReference(context, (char *) CALCULATOR2_SERVICE,
&calculatorService);
+        if (calculatorService == NULL) {
+            fprintf(err, "SQRT: Cannot get reference even for %s.\n", CALCULATOR2_SERVICE);
+        }
+    }
     if (status == CELIX_SUCCESS) {
     	char *token = line;
     	strtok_r(line, " ", &token);
@@ -49,7 +56,7 @@ void sqrtCommand_execute(bundle_context_pt context, char *line, FILE *out,
FILE
 		if (aStr != NULL && numeric) {
 			calculator_service_pt calculator = NULL;
 			status = bundleContext_getService(context, calculatorService, (void *) &calculator);
-			if (status == CELIX_SUCCESS) {
+			if (status == CELIX_SUCCESS && calculator != NULL) {
 				double a = atof(aStr);
 				double result = 0;
 				status = calculator->sqrt(calculator->calculator, a, &result);

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/remote_services/examples/calculator_shell/private/src/sub_command.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/private/src/sub_command.c b/remote_services/examples/calculator_shell/private/src/sub_command.c
index 87fabc2..7cdc394 100644
--- a/remote_services/examples/calculator_shell/private/src/sub_command.c
+++ b/remote_services/examples/calculator_shell/private/src/sub_command.c
@@ -40,6 +40,13 @@ void subCommand_execute(bundle_context_pt context, char *line, FILE *out,
FILE *
     service_reference_pt calculatorService = NULL;
 
     status = bundleContext_getServiceReference(context, (char *) CALCULATOR_SERVICE, &calculatorService);
+    if (calculatorService == NULL) {
+        fprintf(err, "SUB: Cannot get reference for %s. Trying to get one for %s\n", CALCULATOR_SERVICE,
CALCULATOR2_SERVICE);
+        status = bundleContext_getServiceReference(context, (char *) CALCULATOR2_SERVICE,
&calculatorService);
+        if (calculatorService == NULL) {
+            fprintf(err, "SUB: Cannot get reference even for %s.\n", CALCULATOR2_SERVICE);
+        }
+    }
     if (status == CELIX_SUCCESS) {
     	char *token = line;
     	strtok_r(line, " ", &token);
@@ -52,7 +59,7 @@ void subCommand_execute(bundle_context_pt context, char *line, FILE *out,
FILE *
 			if (bStr != NULL && numeric) {
 				calculator_service_pt calculator = NULL;
 				status = bundleContext_getService(context, calculatorService, (void *) &calculator);
-				if (status == CELIX_SUCCESS) {
+				if (status == CELIX_SUCCESS && calculator != NULL) {
 					double a = atof(aStr);
 					double b = atof(bStr);
 					double result = 0;

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/remote_services/examples/deploy.cmake
----------------------------------------------------------------------
diff --git a/remote_services/examples/deploy.cmake b/remote_services/examples/deploy.cmake
index 0515917..4d1c111 100644
--- a/remote_services/examples/deploy.cmake
+++ b/remote_services/examples/deploy.cmake
@@ -55,5 +55,11 @@ if (RSA_EXAMPLES)
         deploy("remote-services-etcd-client" BUNDLES topology_manager remote_service_admin_http
shell shell_tui log_service log_writer calculator_shell discovery_etcd
                                             ENDPOINTS org.apache.celix.calc.api.Calculator_proxy)
     endif ()
+     
+    is_enabled(RSA_REMOTE_SERVICE_ADMIN_DFI)
+    if(RSA_REMOTE_SERVICE_ADMIN_DFI)
+        deploy("remote-services-dfi-etcd" BUNDLES discovery_etcd topology_manager remote_service_admin_dfi
calculator shell shell_tui log_service log_writer)
+        deploy("remote-services-dfi-etcd-client" BUNDLES topology_manager remote_service_admin_dfi
shell shell_tui log_service log_writer calculator_shell discovery_etcd)
+    endif()
 
-endif (RSA_EXAMPLES)
\ No newline at end of file
+endif (RSA_EXAMPLES)

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/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 8b6140e..53eb604 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
@@ -26,7 +26,7 @@
 
 typedef void (*send_func_type)(void *handle, endpoint_description_pt endpointDescription,
char *request, char **reply, int* replyStatus);
 
-celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt
description, const char *classObject,
+celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt
description, const char *classObject, const char* serviceVersion,
                                          import_registration_pt *import);
 celix_status_t importRegistration_close(import_registration_pt import);
 void importRegistration_destroy(import_registration_pt import);

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/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 4b7ec57..6eb4b86 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
@@ -25,6 +25,7 @@
 #include <service_tracker_customizer.h>
 #include <service_tracker.h>
 #include <json_rpc.h>
+#include "constants.h"
 #include "export_registration_dfi.h"
 
 struct export_reference {
@@ -105,6 +106,12 @@ celix_status_t exportRegistration_create(log_helper_pt helper, service_reference
                 status = CELIX_BUNDLE_EXCEPTION;
                 logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "RSA: Error parsing service
descriptor.");
             }
+            else{
+                /* Add the interface version as a property in the properties_map */
+                char* intfVersion = NULL;
+                dynInterface_getVersionString(reg->intf, &intfVersion);
+                properties_set(endpoint->properties, (char*) CELIX_FRAMEWORK_SERVICE_VERSION,
intfVersion);
+            }
         } else {
             status = CELIX_BUNDLE_EXCEPTION;
             logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Cannot open descriptor '%s'", descriptorFile);
@@ -113,6 +120,8 @@ celix_status_t exportRegistration_create(log_helper_pt helper, service_reference
         free(descriptorFile);
     }
 
+
+
     if (status == CELIX_SUCCESS) {
         service_tracker_customizer_pt cust = NULL;
         status = serviceTrackerCustomizer_create(reg, NULL, (void *) exportRegistration_addServ,
NULL,
@@ -156,7 +165,7 @@ void exportRegistration_destroy(export_registration_pt reg) {
         }
 
         if (reg->exportReference.endpoint != NULL) {
-            endpoint_description_pt  ep = reg->exportReference.endpoint;
+            endpoint_description_pt ep = reg->exportReference.endpoint;
             reg->exportReference.endpoint = NULL;
             endpointDescription_destroy(ep);
         }

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
index 813d75f..eab6215 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
@@ -21,6 +21,7 @@
 #include <jansson.h>
 #include <json_rpc.h>
 #include <assert.h>
+#include "version.h"
 #include "json_serializer.h"
 #include "dyn_interface.h"
 #include "import_registration.h"
@@ -30,6 +31,7 @@ struct import_registration {
     bundle_context_pt context;
     endpoint_description_pt  endpoint; //TODO owner? -> free when destroyed
     const char *classObject; //NOTE owned by endpoint
+    version_pt version;
 
     celix_thread_mutex_t mutex; //protects send & sendhandle
     send_func_type send;
@@ -54,7 +56,7 @@ static void importRegistration_proxyFunc(void *userData, void *args[], void
*ret
 static void importRegistration_destroyProxy(struct service_proxy *proxy);
 static void importRegistration_clearProxies(import_registration_pt import);
 
-celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt
endpoint, const char *classObject,
+celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt
endpoint, const char *classObject, const char* serviceVersion,
                                          import_registration_pt *out) {
     celix_status_t status = CELIX_SUCCESS;
     import_registration_pt reg = calloc(1, sizeof(*reg));
@@ -71,6 +73,7 @@ celix_status_t importRegistration_create(bundle_context_pt context, endpoint_des
 
         celixThreadMutex_create(&reg->mutex, NULL);
         celixThreadMutex_create(&reg->proxiesMutex, NULL);
+        version_createVersionFromString((char*)serviceVersion,&(reg->version));
 
         reg->factory->factory = reg;
         reg->factory->getService = (void *)importRegistration_getService;
@@ -118,7 +121,6 @@ static void importRegistration_clearProxies(import_registration_pt import)
{
 void importRegistration_destroy(import_registration_pt import) {
     if (import != NULL) {
         if (import->proxies != NULL) {
-            importRegistration_clearProxies(import);
             hashMap_destroy(import->proxies, false, false);
             import->proxies = NULL;
         }
@@ -129,6 +131,10 @@ void importRegistration_destroy(import_registration_pt import) {
         if (import->factory != NULL) {
             free(import->factory);
         }
+
+        if(import->version!=NULL){
+        	version_destroy(import->version);
+        }
         free(import);
     }
 }
@@ -189,9 +195,10 @@ celix_status_t importRegistration_getService(import_registration_pt import,
bund
 
 static celix_status_t importRegistration_createProxy(import_registration_pt import, bundle_pt
bundle, struct service_proxy **out) {
     celix_status_t  status;
-
+    dyn_interface_type* intf = NULL;
     char *descriptorFile = NULL;
     char name[128];
+
     snprintf(name, 128, "%s.descriptor", import->classObject);
     status = bundle_getEntry(bundle, name, &descriptorFile);
     if (descriptorFile == NULL) {
@@ -201,18 +208,10 @@ static celix_status_t importRegistration_createProxy(import_registration_pt
impo
         printf("Found descriptor at '%s'\n", descriptorFile);
     }
 
-    struct service_proxy *proxy = NULL;
-    if (status == CELIX_SUCCESS) {
-        proxy = calloc(1, sizeof(*proxy));
-        if (proxy == NULL) {
-            status = CELIX_ENOMEM;
-        }
-    }
-
     if (status == CELIX_SUCCESS) {
         FILE *df = fopen(descriptorFile, "r");
         if (df != NULL) {
-            int rc = dynInterface_parse(df, &proxy->intf);
+            int rc = dynInterface_parse(df, &intf);
             fclose(df);
             if (rc != 0) {
                 status = CELIX_BUNDLE_EXCEPTION;
@@ -222,7 +221,34 @@ static celix_status_t importRegistration_createProxy(import_registration_pt
impo
         free(descriptorFile);
     }
 
+    /* Check if the imported service version is compatible with the one in the consumer descriptor
*/
+    version_pt consumerVersion = NULL;
+    bool isCompatible = false;
+    dynInterface_getVersion(intf,&consumerVersion);
+    version_isCompatible(consumerVersion,import->version,&isCompatible);
+
+    if(!isCompatible){
+    	char* cVerString = NULL;
+    	char* pVerString = NULL;
+    	version_toString(consumerVersion,&cVerString);
+    	version_toString(import->version,&pVerString);
+    	printf("Service version mismatch: consumer has %s, provider has %s. NOT creating proxy.\n",cVerString,pVerString);
+    	dynInterface_destroy(intf);
+    	free(cVerString);
+    	free(pVerString);
+    	status = CELIX_SERVICE_EXCEPTION;
+    }
+
+    struct service_proxy *proxy = NULL;
+    if (status == CELIX_SUCCESS) {
+        proxy = calloc(1, sizeof(*proxy));
+        if (proxy == NULL) {
+            status = CELIX_ENOMEM;
+        }
+    }
+
     if (status == CELIX_SUCCESS) {
+    	proxy->intf = intf;
         size_t count = dynInterface_nrOfMethods(proxy->intf);
         proxy->service = calloc(1 + count, sizeof(void *));
         if (proxy->service == NULL) {

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/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 c7a645b..8d463c1 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
@@ -36,6 +36,9 @@
 #include <jansson.h>
 #include "json_serializer.h"
 #include "remote_service_admin.h"
+#include "celix_threads.h"
+#include "hash_map.h"
+#include "array_list.h"
 
 #include "import_registration_dfi.h"
 #include "export_registration_dfi.h"
@@ -611,16 +614,16 @@ celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt
a
 
 celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt
endpointDescription, import_registration_pt *out) {
     celix_status_t status = CELIX_SUCCESS;
-
-    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Import service %s", endpointDescription->service);
+    import_registration_pt import = NULL;
 
     const char *objectClass = properties_get(endpointDescription->properties, "objectClass");
-    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "Registering service factory
(proxy) for service '%s'\n", objectClass);
+    const char *serviceVersion = properties_get(endpointDescription->properties, (char*)
CELIX_FRAMEWORK_SERVICE_VERSION);
 
+    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Import service %s", endpointDescription->service);
+    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "Registering service factory
(proxy) for service '%s'\n", objectClass);
 
-    import_registration_pt import = NULL;
     if (objectClass != NULL) {
-        status = importRegistration_create(admin->context, endpointDescription, objectClass,
&import);
+        status = importRegistration_create(admin->context, endpointDescription, objectClass,
serviceVersion, &import);
     }
     if (status == CELIX_SUCCESS) {
         importRegistration_setSendFn(import, (send_func_type) remoteServiceAdmin_send, admin);

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp b/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp
index d733909..d6db569 100644
--- a/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp
@@ -152,6 +152,7 @@ extern "C" {
         properties_set(props, (char *)OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42");
         properties_set(props, (char *)OSGI_RSA_ENDPOINT_ID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42-42");
         properties_set(props, (char *)OSGI_FRAMEWORK_OBJECTCLASS,(char *)"org.apache.celix.Example");
+        properties_set(props, (char *)"service.version",(char *)"1.0.0"); //TODO find out
standard in osgi spec
 
         rc = endpointDescription_create(props, &endpoint);
         CHECK_EQUAL(CELIX_SUCCESS, rc);

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/remote_services/topology_manager/tms_tst/tms_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/tms_tst/tms_tests.cpp b/remote_services/topology_manager/tms_tst/tms_tests.cpp
index b7db826..4257a01 100644
--- a/remote_services/topology_manager/tms_tst/tms_tests.cpp
+++ b/remote_services/topology_manager/tms_tst/tms_tests.cpp
@@ -508,6 +508,7 @@ extern "C" {
         properties_set(props, (char *)OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42");
         properties_set(props, (char *)OSGI_RSA_ENDPOINT_ID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42-42");
         properties_set(props, (char *)OSGI_FRAMEWORK_OBJECTCLASS,(char *)"org.apache.celix.test.MyBundle");
+        properties_set(props, (char *)"service.version",(char *)"1.0.0"); //TODO find out
standard in osgi spec
         properties_set(props, (char *)"zone", (char *)"thales");
 
         rc = endpointDescription_create(props, &endpoint);
@@ -549,6 +550,7 @@ extern "C" {
         properties_set(props, (char *)OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42");
         properties_set(props, (char *)OSGI_RSA_ENDPOINT_ID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42-42");
         properties_set(props, (char *)OSGI_FRAMEWORK_OBJECTCLASS,(char *)"org.apache.celix.test.MyBundle");
+        properties_set(props, (char *)"service.version",(char *)"1.0.0"); //TODO find out
standard in osgi spec
         properties_set(props, (char *)"zone", (char *)"thales");
 
         rc = endpointDescription_create(props, &endpoint);
@@ -590,6 +592,7 @@ extern "C" {
         properties_set(props, (char *)OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42");
         properties_set(props, (char *)OSGI_RSA_ENDPOINT_ID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42-42");
         properties_set(props, (char *)OSGI_FRAMEWORK_OBJECTCLASS,(char *)"org.apache.celix.test.MyBundle");
+        properties_set(props, (char *)"service.version",(char *)"1.0.0"); //TODO find out
standard in osgi spec
         properties_set(props, (char *)"zone", (char *)"thales");
 
         rc = endpointDescription_create(props, &endpoint);
@@ -630,6 +633,7 @@ extern "C" {
         properties_set(props, (char *)OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42");
         properties_set(props, (char *)OSGI_RSA_ENDPOINT_ID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42-42");
         properties_set(props, (char *)OSGI_FRAMEWORK_OBJECTCLASS,(char *)"org.apache.celix.test.MyBundle");
+        properties_set(props, (char *)"service.version",(char *)"1.0.0"); //TODO find out
standard in osgi spec
         properties_set(props, (char *)"zone", (char *)"thales");
 
         rc = endpointDescription_create(props, &endpoint);

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/utils/private/src/version.c
----------------------------------------------------------------------
diff --git a/utils/private/src/version.c b/utils/private/src/version.c
index 4010953..73ade95 100644
--- a/utils/private/src/version.c
+++ b/utils/private/src/version.c
@@ -245,3 +245,20 @@ celix_status_t version_toString(version_pt version, char **string) {
 	}
 	return status;
 }
+
+celix_status_t version_isCompatible(version_pt user, version_pt provider, bool* isCompatible)
{
+    celix_status_t status = CELIX_SUCCESS;
+    bool result = false;
+
+    if (user == NULL || provider == NULL) {
+        return CELIX_ILLEGAL_ARGUMENT;
+    }
+
+    if (user->major == provider->major) {
+        result = (provider->minor >= user->minor);
+    }
+
+    *isCompatible = result;
+
+    return status;
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/utils/private/test/version_test.cpp
----------------------------------------------------------------------
diff --git a/utils/private/test/version_test.cpp b/utils/private/test/version_test.cpp
index e1b0eee..5603a33 100644
--- a/utils/private/test/version_test.cpp
+++ b/utils/private/test/version_test.cpp
@@ -352,5 +352,37 @@ TEST(version, toString) {
 	free(str);
 }
 
-
+TEST(version,semanticCompatibility) {
+    version_pt provider = NULL;
+    version_pt compatible_user = NULL;
+    version_pt incompatible_user_by_major = NULL;
+    version_pt incompatible_user_by_minor = NULL;
+    celix_status_t status = CELIX_SUCCESS;
+    bool isCompatible = false;
+
+    status = version_isCompatible(compatible_user, provider, &isCompatible);
+    LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
+
+    version_createVersion(2, 3, 5, NULL, &provider);
+    version_createVersion(2, 1, 9, NULL, &compatible_user);
+    version_createVersion(1, 3, 5, NULL, &incompatible_user_by_major);
+    version_createVersion(2, 5, 7, NULL, &incompatible_user_by_minor);
+
+    status = version_isCompatible(compatible_user, provider, &isCompatible);
+    CHECK(isCompatible == true);
+    LONGS_EQUAL(CELIX_SUCCESS, status);
+
+    status = version_isCompatible(incompatible_user_by_major, provider, &isCompatible);
+    CHECK(isCompatible == false);
+    LONGS_EQUAL(CELIX_SUCCESS, status);
+
+    status = version_isCompatible(incompatible_user_by_minor, provider, &isCompatible);
+    CHECK(isCompatible == false);
+    LONGS_EQUAL(CELIX_SUCCESS, status);
+
+    version_destroy(provider);
+    version_destroy(compatible_user);
+    version_destroy(incompatible_user_by_major);
+    version_destroy(incompatible_user_by_minor);
+}
 

http://git-wip-us.apache.org/repos/asf/celix/blob/63b9aa86/utils/public/include/version.h
----------------------------------------------------------------------
diff --git a/utils/public/include/version.h b/utils/public/include/version.h
index ca1a2fa..3144740 100644
--- a/utils/public/include/version.h
+++ b/utils/public/include/version.h
@@ -28,6 +28,7 @@
 #define VERSION_H_
 
 #include "celix_errno.h"
+#include <stdbool.h>
 /**
  * The definition of the version_pt abstract data type.
  */
@@ -155,6 +156,23 @@ celix_status_t version_compareTo(version_pt version, version_pt compare,
int *re
 celix_status_t version_toString(version_pt version, char **string);
 
 /**
+ * Check if two versions are semantically compatible.
+ *
+ * <p>
+ * The user version is compatible with the provider version if the provider version is in
the range
+ * [user_version, next_macro_from_user_version)
+ *
+ * @return Boolean indicating if the versions are compatible
+ * @param version The user <code>version_pt</code> .
+ * @param version The reference provider <code>version_pt</code> .
+ * @param Boolean indicating if the versions are compatible
+ * @return Status code indication failure or success:
+ * 		- CELIX_SUCCESS when no errors are encountered.
+ */
+celix_status_t version_isCompatible(version_pt user, version_pt provider, bool* isCompatible);
+
+
+/**
  * @}
  */
 


Mime
View raw message