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-326: Add support for versionRanges
Date Tue, 15 Dec 2015 15:00:24 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 135ea22a9 -> d5a51766c


CELIX-326: Add support for versionRanges


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

Branch: refs/heads/develop
Commit: d5a51766c8a1fa3aee0d15bd404d74cc8f4bcef3
Parents: 135ea22
Author: Bjoern Petri <bpetri@apache.org>
Authored: Tue Dec 15 15:59:57 2015 +0100
Committer: Bjoern Petri <bpetri@apache.org>
Committed: Tue Dec 15 15:59:57 2015 +0100

----------------------------------------------------------------------
 .../private/src/dm_service_dependency.c         | 46 ++++++++++++++---
 .../phase2a/private/src/phase2a_activator.c     |  3 +-
 .../phase2b/private/src/phase2b_activator.c     |  2 +-
 examples/dm_example/services/phase1.h           |  8 ++-
 utils/private/src/version_range.c               | 54 ++++++++++++++++++++
 utils/public/include/version_range.h            | 44 ++++++++++++++++
 6 files changed, 147 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/d5a51766/dependency_manager/private/src/dm_service_dependency.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_service_dependency.c b/dependency_manager/private/src/dm_service_dependency.c
index df51463..be865eb 100644
--- a/dependency_manager/private/src/dm_service_dependency.c
+++ b/dependency_manager/private/src/dm_service_dependency.c
@@ -148,7 +148,7 @@ celix_status_t serviceDependency_getStrategy(dm_service_dependency_pt
dependency
 
 }
 
-celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency, char *serviceName,
char *serviceVersion, char *filter) {
+celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency, char *serviceName,
char *serviceVersionRange, char *filter) {
     celix_status_t status = CELIX_SUCCESS;
     if (!dependency) {
         status = CELIX_ILLEGAL_ARGUMENT;
@@ -162,11 +162,45 @@ celix_status_t serviceDependency_setService(dm_service_dependency_pt
dependency,
             dependency->tracked_service = strdup(serviceName);
         }
 
-        if (serviceVersion != NULL) {
-            size_t len = strlen(CELIX_FRAMEWORK_SERVICE_VERSION) + strlen(serviceVersion)
+ 4;
-            char serviceVersionFilter[len];
-            snprintf(serviceVersionFilter, len, "(%s=%s)", CELIX_FRAMEWORK_SERVICE_VERSION,
serviceVersion);
-            arrayList_add(filterElements, strdup(serviceVersionFilter));
+        if (serviceVersionRange != NULL) {
+            version_range_pt versionRange;
+
+            if (versionRange_parse(serviceVersionRange, &versionRange) == CELIX_SUCCESS)
{
+                version_pt lowVersion = NULL;
+                version_pt highVersion = NULL;
+
+                if ((versionRange_getHighVersion(versionRange, &highVersion) == CELIX_SUCCESS)
&& (highVersion != NULL)) {
+                    bool isHighInclusive;
+                    char* highOperator;
+                    char* highVersionStr;
+
+                    versionRange_isHighInclusive(versionRange, &isHighInclusive);
+                    version_toString(highVersion, &highVersionStr);
+
+                    highOperator = isHighInclusive ? "<=" : "<";
+
+                    size_t len = strlen(CELIX_FRAMEWORK_SERVICE_VERSION) + strlen(highVersionStr)
+ strlen(highOperator) + 3;
+                    char serviceVersionFilter[len];
+                    snprintf(serviceVersionFilter, len, "(%s%s%s)", CELIX_FRAMEWORK_SERVICE_VERSION,
highOperator, highVersionStr);
+                    arrayList_add(filterElements, strdup(serviceVersionFilter));
+                }
+
+                if ((versionRange_getLowVersion(versionRange, &lowVersion) == CELIX_SUCCESS)
&& (lowVersion != NULL)) {
+                    bool isLowInclusive;
+                    char* lowOperator;
+                    char* lowVersionStr;
+
+                    versionRange_isLowInclusive(versionRange, &isLowInclusive);
+                    version_toString(lowVersion, &lowVersionStr);
+
+                    lowOperator = isLowInclusive ? ">=" : ">";
+
+                    size_t len = strlen(CELIX_FRAMEWORK_SERVICE_VERSION) + strlen(lowVersionStr)
+ strlen(lowOperator) + 3;
+                    char serviceVersionFilter[len];
+                    snprintf(serviceVersionFilter, len, "(%s%s%s)", CELIX_FRAMEWORK_SERVICE_VERSION,
lowOperator, lowVersionStr);
+                    arrayList_add(filterElements, strdup(serviceVersionFilter));
+                }
+            }
         }
 
         if (filter != NULL) {

http://git-wip-us.apache.org/repos/asf/celix/blob/d5a51766/examples/dm_example/phase2a/private/src/phase2a_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2a/private/src/phase2a_activator.c b/examples/dm_example/phase2a/private/src/phase2a_activator.c
index 4a3051f..df639a8 100644
--- a/examples/dm_example/phase2a/private/src/phase2a_activator.c
+++ b/examples/dm_example/phase2a/private/src/phase2a_activator.c
@@ -68,7 +68,8 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
 
 		dm_service_dependency_pt dep;
 		serviceDependency_create(&dep);
-		serviceDependency_setService(dep, PHASE1_NAME, PHASE1_VERSION, NULL);
+		serviceDependency_setService(dep, PHASE1_NAME, PHASE1_RANGE_ALL, NULL);
+
         serviceDependency_setCallbacksSafe(dep, phase2a_cmp_t *, phase1_t *, phase2a_setPhase1,
NULL, NULL, NULL, NULL);
 		serviceDependency_setRequired(dep, true);
 		component_addServiceDependency(cmp, dep);

http://git-wip-us.apache.org/repos/asf/celix/blob/d5a51766/examples/dm_example/phase2b/private/src/phase2b_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase2b/private/src/phase2b_activator.c b/examples/dm_example/phase2b/private/src/phase2b_activator.c
index 2beb45a..8797271 100644
--- a/examples/dm_example/phase2b/private/src/phase2b_activator.c
+++ b/examples/dm_example/phase2b/private/src/phase2b_activator.c
@@ -68,7 +68,7 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
 
 		dm_service_dependency_pt dep;
 		serviceDependency_create(&dep);
-		serviceDependency_setService(dep, PHASE1_NAME, PHASE1_VERSION, NULL);
+		serviceDependency_setService(dep, PHASE1_NAME, PHASE1_RANGE_EXACT, NULL);
 		serviceDependency_setCallbacksSafe(dep, phase2b_cmp_t *, phase1_t *, phase2b_setPhase1,
NULL, NULL, NULL, NULL);
 		serviceDependency_setRequired(dep, true);
 		component_addServiceDependency(cmp, dep);

http://git-wip-us.apache.org/repos/asf/celix/blob/d5a51766/examples/dm_example/services/phase1.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/services/phase1.h b/examples/dm_example/services/phase1.h
index 5714553..04e9da7 100644
--- a/examples/dm_example/services/phase1.h
+++ b/examples/dm_example/services/phase1.h
@@ -27,8 +27,12 @@
 #ifndef PHASE1_H_
 #define PHASE1_H_
 
-#define PHASE1_NAME     "PHASE1"
-#define PHASE1_VERSION  "1.0.0.0"
+#define PHASE1_NAME         "PHASE1"
+#define PHASE1_VERSION      "1.2.2.0"
+#define PHASE1_RANGE_ALL    "[1.2.2.0,4.5.6.x)"
+#define PHASE1_RANGE_EXACT  "[1.2.2.0,1.2.2.0]"
+
+
 
 struct phase1_struct {
 	void *handle;

http://git-wip-us.apache.org/repos/asf/celix/blob/d5a51766/utils/private/src/version_range.c
----------------------------------------------------------------------
diff --git a/utils/private/src/version_range.c b/utils/private/src/version_range.c
index bb3d82e..d73a522 100644
--- a/utils/private/src/version_range.c
+++ b/utils/private/src/version_range.c
@@ -124,6 +124,59 @@ celix_status_t versionRange_isInRange(version_range_pt versionRange,
version_pt
 	return status;
 }
 
+celix_status_t versionRange_getLowVersion(version_range_pt versionRange, version_pt *lowVersion)
{
+    celix_status_t status = CELIX_SUCCESS;
+
+    if (versionRange == NULL) {
+        status = CELIX_ILLEGAL_ARGUMENT;
+    }
+    else {
+        *lowVersion = versionRange->low;
+    }
+
+    return status;
+}
+
+celix_status_t versionRange_isLowInclusive(version_range_pt versionRange, bool *isLowInclusive)
{
+    celix_status_t status = CELIX_SUCCESS;
+
+    if (versionRange == NULL) {
+        status = CELIX_ILLEGAL_ARGUMENT;
+    }
+    else {
+        *isLowInclusive = versionRange->isLowInclusive;
+    }
+
+    return status;
+}
+
+celix_status_t versionRange_getHighVersion(version_range_pt versionRange, version_pt *highVersion)
{
+    celix_status_t status = CELIX_SUCCESS;
+
+    if (versionRange == NULL) {
+        status = CELIX_ILLEGAL_ARGUMENT;
+    }
+    else {
+        *highVersion = versionRange->high;
+    }
+
+    return status;
+}
+
+celix_status_t versionRange_isHighInclusive(version_range_pt versionRange, bool *isHighInclusive)
{
+    celix_status_t status = CELIX_SUCCESS;
+
+    if (versionRange == NULL) {
+        status = CELIX_ILLEGAL_ARGUMENT;
+    }
+    else {
+        *isHighInclusive = versionRange->isHighInclusive;
+    }
+
+    return status;
+}
+
+
 celix_status_t versionRange_parse(char * rangeStr, version_range_pt *range) {
 	celix_status_t status;
 	if (strchr(rangeStr, ',') != NULL) {
@@ -177,3 +230,4 @@ celix_status_t versionRange_parse(char * rangeStr, version_range_pt *range)
{
 
 	return status;
 }
+

http://git-wip-us.apache.org/repos/asf/celix/blob/d5a51766/utils/public/include/version_range.h
----------------------------------------------------------------------
diff --git a/utils/public/include/version_range.h b/utils/public/include/version_range.h
index a979eca..bf468a8 100644
--- a/utils/public/include/version_range.h
+++ b/utils/public/include/version_range.h
@@ -81,6 +81,50 @@ celix_status_t versionRange_destroy(version_range_pt range);
 celix_status_t versionRange_isInRange(version_range_pt versionRange, version_pt version,
bool *inRange);
 
 /**
+ * Determines whether the lower bound is included in the given range
+ *
+ * @param versionRange The range to check
+ * @param isLowInclusive is set to true in case, the lower bound the lower bound is included,
otherwise false
+ * @return Status code indication failure or success:
+ *      - CELIX_SUCCESS when no errors are encountered.
+ *      - CELIX_ILLEGAL_ARGUMENT in case the versionRange is NULL
+ */
+celix_status_t versionRange_isLowInclusive(version_range_pt versionRange, bool *isLowInclusive);
+
+/**
+ * Determines whether the higher bound is included in the given range
+ *
+ * @param versionRange The range to check
+ * @param isHighInclusive is set to true in case, the lower bound the higher bound is included,
otherwise false
+ * @return Status code indication failure or success:
+ *      - CELIX_SUCCESS when no errors are encountered.
+ *      - CELIX_ILLEGAL_ARGUMENT in case the versionRange is NULL
+ */
+celix_status_t versionRange_isHighInclusive(version_range_pt versionRange, bool *isHighInclusive);
+
+/**
+ * Retrieves whether the lower bound version from the given range
+ *
+ * @param versionRange The range
+ * @param highVersion is set to the lower bound version
+ * @return Status code indication failure or success:
+ *      - CELIX_SUCCESS when no errors are encountered.
+ *      - CELIX_ILLEGAL_ARGUMENT in case the versionRange is NULL
+ */
+celix_status_t versionRange_getLowVersion(version_range_pt versionRange, version_pt *lowVersion);
+
+/**
+ * Retrieves whether the upper bound version from the given range
+ *
+ * @param versionRange The range
+ * @param highVersion is set to the upper bound version
+ * @return Status code indication failure or success:
+ *      - CELIX_SUCCESS when no errors are encountered.
+ *      - CELIX_ILLEGAL_ARGUMENT in case the versionRange is NULL
+ */
+celix_status_t versionRange_getHighVersion(version_range_pt versionRange, version_pt *highVersion);
+
+/**
  * Parses a version range from the specified string.
  *
  * <p>


Mime
View raw message