celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [2/2] celix git commit: CELIX-237: fixed issue in dyn_type. Added support for uint8_t to json_serializer
Date Wed, 09 Sep 2015 18:33:30 GMT
CELIX-237: fixed issue in dyn_type. Added support for uint8_t to json_serializer


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

Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: b74a63b0640c452dfa793fefdfa20c9a2a94b7c1
Parents: 2c17460
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Wed Sep 9 20:32:46 2015 +0200
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Wed Sep 9 20:32:46 2015 +0200

----------------------------------------------------------------------
 .../dynamic_function_interface/dyn_type.c       |  9 +++--
 .../dynamic_function_interface/json_rpc.c       |  2 +-
 .../json_serializer.c                           | 14 ++++++--
 .../json_serializer_tests.cpp                   | 37 ++++++++++++++++++++
 4 files changed, 57 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/b74a63b0/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
index 3967e15..de00784 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
@@ -736,7 +736,8 @@ int dynType_sequence_locForIndex(dyn_type *type, void *seqLoc, int index,
void *
 
     struct generic_sequence *seq = seqLoc;
     char *valLoc = seq->buf;
-    size_t itemSize = type->sequence.itemType->ffiType->size;
+
+    size_t itemSize = dynType_size(type->sequence.itemType);
 
     if (index >= seq->cap) {
         status = ERROR;
@@ -921,7 +922,11 @@ static unsigned short dynType_getOffset(dyn_type *type, int index) {
 }
 
 size_t dynType_size(dyn_type *type) {
-    return type->ffiType->size;
+    dyn_type *rType = type;
+    if (type->type == DYN_TYPE_REF) {
+        rType = type->ref.ref;
+    }
+    return rType->ffiType->size;
 }
 
 int dynType_type(dyn_type *type) {

http://git-wip-us.apache.org/repos/asf/celix/blob/b74a63b0/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
index 4e498ca..d4c8f30 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
@@ -263,7 +263,7 @@ int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void
*args[]
                 dynType_typedPointer_getTypedType(argType, &subType);
                 dyn_type *subSubType = NULL;
                 dynType_typedPointer_getTypedType(subType, &subSubType);
-                void ***out = (void **)args[i];
+                void **out = (void **)args[i];
                 status = jsonSerializer_deserializeJson(subSubType, result, *out);
             } else {
                 //skip

http://git-wip-us.apache.org/repos/asf/celix/blob/b74a63b0/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
index 30f5296..aaf5cc3 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
@@ -28,7 +28,7 @@ static int ERROR = 1;
 DFI_SETUP_LOG(jsonSerializer);
 
 int jsonSerializer_deserialize(dyn_type *type, const char *input, void **result) {
-    assert(dynType_type(type) == DYN_TYPE_COMPLEX);
+    assert(dynType_type(type) == DYN_TYPE_COMPLEX || dynType_type(type) == DYN_TYPE_SEQUENCE);
     int status = 0;
 
     json_error_t error;
@@ -39,7 +39,7 @@ int jsonSerializer_deserialize(dyn_type *type, const char *input, void **result)
         json_decref(root);
     } else {
         status = ERROR;
-        LOG_ERROR("Error parsing json input '%s'. Error is %s\n", input, error.text);
+        LOG_ERROR("Error parsing json input '%s'. Error is: %s\n", input, error.text);
     }
 
     return status;
@@ -120,6 +120,7 @@ static int jsonSerializer_parseAny(dyn_type *type, void *loc, json_t *val)
{
     int16_t *s;         //S
     int32_t *i;         //I
     int64_t *l;         //J
+    uint8_t   *ub;      //b
     uint16_t  *us;      //s
     uint32_t  *ui;      //i
     uint64_t  *ul;      //j
@@ -153,6 +154,10 @@ static int jsonSerializer_parseAny(dyn_type *type, void *loc, json_t
*val) {
             l = loc;
             *l = (int64_t) json_integer_value(val);
             break;
+        case 'b' :
+            ub = loc;
+            *ub = (uint8_t) json_integer_value(val);
+            break;
         case 's' :
             us = loc;
             *us = (uint16_t) json_integer_value(val);
@@ -266,6 +271,7 @@ static int jsonSerializer_writeAny(dyn_type *type, void *input, json_t
**out) {
     int16_t *s;         //S
     int32_t *i;         //I
     int64_t *l;         //J
+    uint8_t   *ub;      //b
     uint16_t  *us;      //s
     uint32_t  *ui;      //i
     uint64_t  *ul;      //j
@@ -287,6 +293,10 @@ static int jsonSerializer_writeAny(dyn_type *type, void *input, json_t
**out) {
             l = input;
             val = json_integer((json_int_t)*l);
             break;
+        case 'b' :
+            ub = input;
+            val = json_integer((json_int_t)*ub);
+            break;
         case 's' :
             us = input;
             val = json_integer((json_int_t)*us);

http://git-wip-us.apache.org/repos/asf/celix/blob/b74a63b0/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_serializer_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_serializer_tests.cpp
b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_serializer_tests.cpp
index 5ee71ac..db81ade 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_serializer_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_serializer_tests.cpp
@@ -197,6 +197,33 @@ static void check_example5(void *data) {
     CHECK(ex->head->right->right == NULL);
 }
 
+static const char *example6_descriptor = "Tsample={DD v1 v2};[lsample;";
+
+static const char *example6_input = "[{\"v1\":0.1,\"v2\":0.2},{\"v1\":1.1,\"v2\":1.2},{\"v1\":2.1,\"v2\":2.2}]";
+
+struct ex6_sample {
+    double v1;
+    double v2;
+};
+
+struct ex6_sequence {
+    uint32_t cap;
+    uint32_t len;
+    struct ex6_sample *buf;
+};
+
+static void check_example6(struct ex6_sequence seq) {
+    CHECK_EQUAL(3, seq.cap);
+    CHECK_EQUAL(3, seq.len);
+    CHECK_EQUAL(0.1, seq.buf[0].v1);
+    CHECK_EQUAL(0.2, seq.buf[0].v2);
+    CHECK_EQUAL(1.1, seq.buf[1].v1);
+    CHECK_EQUAL(1.2, seq.buf[1].v2);
+    CHECK_EQUAL(2.1, seq.buf[2].v1);
+    CHECK_EQUAL(2.2, seq.buf[2].v2);
+}
+
+
 static void parseTests(void) {
     dyn_type *type;
     void *inst;
@@ -251,6 +278,16 @@ static void parseTests(void) {
     check_example5(inst);
     dynType_free(type, inst);
     dynType_destroy(type);
+
+    type = NULL;
+    struct ex6_sequence *seq;
+    rc = dynType_parseWithStr(example6_descriptor, NULL, NULL, &type);
+    CHECK_EQUAL(0, rc);
+    rc = jsonSerializer_deserialize(type, example6_input, (void **)&seq);
+    CHECK_EQUAL(0, rc);
+    check_example6((*seq));
+    dynType_free(type, seq);
+    dynType_destroy(type);
 }
 
 const char *write_example1_descriptor = "{BSIJsijFDN a b c d e f g h i j}";


Mime
View raw message