You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2015/11/27 15:56:30 UTC
[1/6] celix git commit: CELIX-309: Move dfi to top-level subdir
Repository: celix
Updated Branches:
refs/heads/develop d8e8fab41 -> 18a5bf743
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/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
deleted file mode 100644
index 70b0147..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_serializer_tests.cpp
+++ /dev/null
@@ -1,508 +0,0 @@
-/**
- *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.
- */
-#include <CppUTest/TestHarness.h>
-#include "CppUTest/CommandLineTestRunner.h"
-
-extern "C" {
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
-#include <ffi.h>
-
-#include "dyn_common.h"
-#include "dyn_type.h"
-#include "json_serializer.h"
-
-static void stdLog(void *handle, int level, const char *file, int line, const char *msg, ...) {
- va_list ap;
- const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
- fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
- va_start(ap, msg);
- vfprintf(stderr, msg, ap);
- fprintf(stderr, "\n");
-}
-
-/*********** example 1 ************************/
-/** struct type ******************************/
-const char *example1_descriptor = "{DJISF a b c d e}";
-
-const char *example1_input = "{ \
- \"a\" : 1.0, \
- \"b\" : 22, \
- \"c\" : 32, \
- \"d\" : 42, \
- \"e\" : 4.4 \
-}";
-
-struct example1 {
- double a; //0
- int64_t b; //1
- int32_t c; //2
- int16_t d; //3
- float e; //4
-};
-
-static void check_example1(void *data) {
- struct example1 *ex = (struct example1 *)data;
- CHECK_EQUAL(1.0, ex->a);
- LONGS_EQUAL(22, ex->b);
- LONGS_EQUAL(32, ex->c);
- LONGS_EQUAL(42, ex->d);
- CHECK_EQUAL(4.4f, ex->e);
-}
-
-/*********** example 2 ************************/
-const char *example2_descriptor = "{BJJDFD byte long1 long2 double1 float1 double2}";
-
-const char *example2_input = "{ \
- \"byte\" : 42, \
- \"long1\" : 232, \
- \"long2\" : 242, \
- \"double1\" : 4.2, \
- \"float1\" : 3.2, \
- \"double2\" : 4.4 \
-}";
-
-struct example2 {
- char byte; //0
- int64_t long1; //1
- int64_t long2; //2
- double double1; //3
- float float1; //4
- double double2; //5
-};
-
-static void check_example2(void *data) {
- struct example2 *ex = (struct example2 *)data;
- CHECK_EQUAL(42, ex->byte);
- LONGS_EQUAL(232, ex->long1);
- LONGS_EQUAL(242, ex->long2);
- CHECK_EQUAL(4.2, ex->double1);
- CHECK_EQUAL(3.2f, ex->float1);
- CHECK_EQUAL(4.4, ex->double2);
-}
-
-
-/*********** example 3 ************************/
-/** sequence with a simple type **************/
-const char *example3_descriptor = "{[I numbers}";
-
-const char *example3_input = "{ \
- \"numbers\" : [22,32,42] \
-}";
-
-struct example3 {
- struct {
- uint32_t cap;
- uint32_t len;
- int32_t *buf;
- } numbers;
-};
-
-static void check_example3(void *data) {
- struct example3 *ex = (struct example3 *)data;
- CHECK_EQUAL(3, ex->numbers.len);
- CHECK_EQUAL(22, ex->numbers.buf[0]);
- CHECK_EQUAL(32, ex->numbers.buf[1]);
- CHECK_EQUAL(42, ex->numbers.buf[2]);
-}
-
-/*********** example 4 ************************/
-/** structs within a struct (by reference)*******/
-const char *example4_descriptor = "{{IDD index val1 val2}{IDD index val1 val2} left right}";
-
-static const char *example4_input = "{ \
- \"left\" : {\"index\":1, \"val1\":1.0, \"val2\":2.0 }, \
- \"right\" : {\"index\":2, \"val1\":5.0, \"val2\":4.0 } \
-}";
-
-struct ex4_leaf {
- int32_t index;
- double val1;
- double val2;
-};
-
-struct example4 {
- struct ex4_leaf left;
- struct ex4_leaf right;
-};
-
-static void check_example4(void *data) {
- struct example4 *ex = (struct example4 *)data;
- CHECK_EQUAL(1, ex->left.index);
- CHECK_EQUAL(1.0, ex->left.val1);
- CHECK_EQUAL(2.0, ex->left.val2);
- CHECK_EQUAL(2, ex->right.index);
- CHECK_EQUAL(5.0, ex->right.val1);
- CHECK_EQUAL(4.0, ex->right.val2);
-}
-
-
-/*********** example 5 ************************/
-/** structs within a struct (by reference)*******/
-const char *example5_descriptor = "Tleaf={ts name age};Tnode={Lnode;Lnode;Lleaf; left right value};{Lnode; head}";
-
-static const char *example5_input = "{ \
- \"head\" : {\
- \"left\" : {\
- \"value\" : {\
- \"name\" : \"John\",\
- \"age\" : 44 \
- }\
- },\
- \"right\" : {\
- \"value\" : {\
- \"name\" : \"Peter\", \
- \"age\" : 55 \
- }\
- }\
- }\
-}";
-
-struct leaf {
- const char *name;
- uint16_t age;
-};
-
-struct node {
- struct node *left;
- struct node *right;
- struct leaf *value;
-};
-
-struct example5 {
- struct node *head;
-};
-
-static void check_example5(void *data) {
- struct example5 *ex = (struct example5 *)data;
- CHECK_TRUE(ex->head != NULL);
-
- CHECK(ex->head->left != NULL);
- CHECK(ex->head->left->value != NULL);
- STRCMP_EQUAL("John", ex->head->left->value->name);
- CHECK_EQUAL(44, ex->head->left->value->age);
- CHECK(ex->head->left->left == NULL);
- CHECK(ex->head->left->right == NULL);
-
- CHECK(ex->head->right != NULL);
- CHECK(ex->head->right->value != NULL);
- STRCMP_EQUAL("Peter", ex->head->right->value->name);
- CHECK_EQUAL(55, ex->head->right->value->age);
- CHECK(ex->head->right->left == NULL);
- 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);
-}
-
-
-/*********** example 7 ************************/
-const char *example7_descriptor = "{t a}";
-
-const char *example7_input = "{ \
- \"a\" : \"apache celix\" \
-}";
-
-struct example7 {
- char* a; //0
-};
-
-static void check_example7(void *data) {
- struct example7 *ex = (struct example7 *)data;
- STRCMP_EQUAL("apache celix", ex->a);
-}
-
-static void parseTests(void) {
- dyn_type *type;
- void *inst;
- int rc;
-
- type = NULL;
- inst = NULL;
- rc = dynType_parseWithStr(example1_descriptor, NULL, NULL, &type);
- CHECK_EQUAL(0, rc);
- rc = jsonSerializer_deserialize(type, example1_input, &inst);
- CHECK_EQUAL(0, rc);
- check_example1(inst);
- dynType_free(type, inst);
- dynType_destroy(type);
-
- type = NULL;
- inst = NULL;
- rc = dynType_parseWithStr(example2_descriptor, NULL, NULL, &type);
- CHECK_EQUAL(0, rc);
- rc = jsonSerializer_deserialize(type, example2_input, &inst);
- CHECK_EQUAL(0, rc);
- check_example2(inst);
- dynType_free(type, inst);
- dynType_destroy(type);
-
- type = NULL;
- inst = NULL;
- rc = dynType_parseWithStr(example3_descriptor, NULL, NULL, &type);
- CHECK_EQUAL(0, rc);
- rc = jsonSerializer_deserialize(type, example3_input, &inst);
- CHECK_EQUAL(0, rc);
- check_example3(inst);
- dynType_free(type, inst);
- dynType_destroy(type);
-
- type = NULL;
- inst = NULL;
- rc = dynType_parseWithStr(example4_descriptor, NULL, NULL, &type);
- CHECK_EQUAL(0, rc);
- rc = jsonSerializer_deserialize(type, example4_input, &inst);
- CHECK_EQUAL(0, rc);
- check_example4(inst);
- dynType_free(type, inst);
- dynType_destroy(type);
-
- type = NULL;
- inst = NULL;
- rc = dynType_parseWithStr(example5_descriptor, NULL, NULL, &type);
- CHECK_EQUAL(0, rc);
- rc = jsonSerializer_deserialize(type, example5_input, &inst);
- CHECK_EQUAL(0, rc);
- 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);
-
-
- type = NULL;
- inst = NULL;
- rc = dynType_parseWithStr(example7_descriptor, NULL, NULL, &type);
- CHECK_EQUAL(0, rc);
- rc = jsonSerializer_deserialize(type, example7_input, &inst);
- CHECK_EQUAL(0, rc);
- check_example7(inst);
- dynType_free(type, inst);
- dynType_destroy(type);
-}
-
-const char *write_example1_descriptor = "{BSIJsijFDN a b c d e f g h i j}";
-
-struct write_example1 {
- char a;
- int16_t b;
- int32_t c;
- int64_t d;
- uint16_t e;
- uint32_t f;
- uint64_t g;
- float h;
- double i;
- int j;
-};
-
-void writeTest1(void) {
- struct write_example1 ex1;
- ex1.a=1;
- ex1.b=2;
- ex1.c=3;
- ex1.d=4;
- ex1.e=5;
- ex1.f=6;
- ex1.g=7;
- ex1.h=8.8f;
- ex1.i=9.9;
- ex1.j=10;
-
- dyn_type *type = NULL;
- char *result = NULL;
- int rc = dynType_parseWithStr(write_example1_descriptor, "ex1", NULL, &type);
- CHECK_EQUAL(0, rc);
- rc = jsonSerializer_serialize(type, &ex1, &result);
- CHECK_EQUAL(0, rc);
- STRCMP_CONTAINS("\"a\":1", result);
- STRCMP_CONTAINS("\"b\":2", result);
- STRCMP_CONTAINS("\"c\":3", result);
- STRCMP_CONTAINS("\"d\":4", result);
- STRCMP_CONTAINS("\"e\":5", result);
- STRCMP_CONTAINS("\"f\":6", result);
- STRCMP_CONTAINS("\"g\":7", result);
- STRCMP_CONTAINS("\"h\":8.8", result);
- STRCMP_CONTAINS("\"i\":9.9", result);
- STRCMP_CONTAINS("\"j\":10", result);
- //printf("example 1 result: '%s'\n", result);
- dynType_destroy(type);
- free(result);
-}
-
-const char *write_example2_descriptor = "{*{JJ a b}{SS c d} sub1 sub2}";
-
-struct write_example2_sub {
- int64_t a;
- int64_t b;
-};
-
-struct write_example2 {
- struct write_example2_sub *sub1;
- struct {
- int16_t c;
- int16_t d;
- } sub2;
-};
-
-void writeTest2(void) {
- struct write_example2_sub sub1;
- sub1.a = 1;
- sub1.b = 2;
-
- struct write_example2 ex;
- ex.sub1=&sub1;
- ex.sub2.c = 3;
- ex.sub2.d = 4;
-
- dyn_type *type = NULL;
- char *result = NULL;
- int rc = dynType_parseWithStr(write_example2_descriptor, "ex2", NULL, &type);
- CHECK_EQUAL(0, rc);
- rc = jsonSerializer_serialize(type, &ex, &result);
- CHECK_EQUAL(0, rc);
- STRCMP_CONTAINS("\"a\":1", result);
- STRCMP_CONTAINS("\"b\":2", result);
- STRCMP_CONTAINS("\"c\":3", result);
- STRCMP_CONTAINS("\"d\":4", result);
- //printf("example 2 result: '%s'\n", result);
- dynType_destroy(type);
- free(result);
-}
-
-const char *write_example3_descriptor = "Tperson={ti name age};[Lperson;";
-
-struct write_example3_person {
- const char *name;
- uint32_t age;
-};
-
-struct write_example3 {
- uint32_t cap;
- uint32_t len;
- struct write_example3_person **buf;
-};
-
-void writeTest3(void) {
- struct write_example3_person p1;
- p1.name = "John";
- p1.age = 33;
-
- struct write_example3_person p2;
- p2.name = "Peter";
- p2.age = 44;
-
- struct write_example3_person p3;
- p3.name = "Carol";
- p3.age = 55;
-
- struct write_example3_person p4;
- p4.name = "Elton";
- p4.age = 66;
-
- struct write_example3 seq;
- seq.buf = (struct write_example3_person **) calloc(4, sizeof(void *));
- seq.len = seq.cap = 4;
- seq.buf[0] = &p1;
- seq.buf[1] = &p2;
- seq.buf[2] = &p3;
- seq.buf[3] = &p4;
-
- dyn_type *type = NULL;
- char *result = NULL;
- int rc = dynType_parseWithStr(write_example3_descriptor, "ex3", NULL, &type);
- CHECK_EQUAL(0, rc);
- rc = jsonSerializer_serialize(type, &seq, &result);
- CHECK_EQUAL(0, rc);
- STRCMP_CONTAINS("\"age\":33", result);
- STRCMP_CONTAINS("\"age\":44", result);
- STRCMP_CONTAINS("\"age\":55", result);
- STRCMP_CONTAINS("\"age\":66", result);
- //printf("example 3 result: '%s'\n", result);
- free(seq.buf);
- dynType_destroy(type);
- free(result);
-}
-
-
-
-}
-
-TEST_GROUP(JsonSerializerTests) {
- void setup() {
- int lvl = 1;
- dynCommon_logSetup(stdLog, NULL, lvl);
- dynType_logSetup(stdLog, NULL,lvl);
- jsonSerializer_logSetup(stdLog, NULL, lvl);
- }
-};
-
-TEST(JsonSerializerTests, ParseTests) {
- //TODO split up
- parseTests();
-}
-
-TEST(JsonSerializerTests, WriteTest1) {
- writeTest1();
-}
-
-TEST(JsonSerializerTests, WriteTest2) {
- writeTest2();
-}
-
-TEST(JsonSerializerTests, WriteTest3) {
- writeTest3();
-}
-
-
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/run_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/run_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/run_tests.cpp
deleted file mode 100644
index 786f4bf..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/run_tests.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- *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.
- */
-#include <CppUTest/TestHarness.h>
-#include "CppUTest/CommandLineTestRunner.h"
-
-int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/complex.avdl
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/complex.avdl b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/complex.avdl
deleted file mode 100644
index eff1fd8..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/complex.avdl
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- *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.
- */
-
-protocol Complex {
-
- record StatResult {
- double sum;
- double min;
- double max;
- array<double> input;
- }
-
- StatResult stats(array<double> input);
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/complex.avpr
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/complex.avpr b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/complex.avpr
deleted file mode 100644
index ca39b56..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/complex.avpr
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- *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.
- */
-
-{
- "protocol" : "Complex",
- "namespace" : null,
- "types" : [ {
- "type" : "record",
- "name" : "StatResult",
- "fields" : [ {
- "name" : "sum",
- "type" : "double"
- }, {
- "name" : "min",
- "type" : "double"
- }, {
- "name" : "max",
- "type" : "double"
- }, {
- "name" : "input",
- "type" : {
- "type" : "array",
- "items" : "double"
- }
- } ]
- } ],
- "messages" : {
- "stats" : {
- "request" : [ {
- "name" : "input",
- "type" : {
- "type" : "array",
- "items" : "double"
- }
- } ],
- "response" : "StatResult"
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/invalid1.avpr
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/invalid1.avpr b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/invalid1.avpr
deleted file mode 100644
index bbf77ee..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/invalid1.avpr
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- *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.
- */
-{
- "protocol" : "Complex",
- "namespace" : null,
- "types" : [ {
- "type" : "record",
- "name" : "StatResult",
- "fields" : [ {
- "name" : "sum",
- "type" : "double"
- }, {
- "name" : "min",
- "type" : "double"
- }, {
- "name" : "max",
- "type" : "double"
- }, {
- "name" : "input",
- "type" : {
- "type" : "array",
- "items" : "double"
- }
- } ]
- } ],
- "messages" : {
- "stats" : {
- "response" : "StatResult"
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/invalid2.avpr
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/invalid2.avpr b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/invalid2.avpr
deleted file mode 100644
index 9eb9209..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/invalid2.avpr
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- *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.
- */
- {
- "protocol" : "Simple",
- "types" : [ ],
- "messages" : {
- "sum" : {
- "request" : [ {
- "name" : "a"
- }, {
- "name" : "b",
- "type" : "double"
- } ],
- "response" : "double"
- },
- "sub" : {
- "request" : [ {
- "name" : "a",
- "type" : "double"
- }, {
- "name" : "b",
- "type" : "double"
- } ],
- "response" : "double"
- },
- "sqrt" : {
- "request" : [ {
- "name" : "a"
- } ],
- "response" : "double"
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/simple.avdl
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/simple.avdl b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/simple.avdl
deleted file mode 100644
index a03e352..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/simple.avdl
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- *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.
- */
- @namespace("org.apache.avro.test")
-protocol Simple {
- double sum(double a, double b);
- double sub(double a, double b);
- double sqrt(double a);
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/simple.avpr
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/simple.avpr b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/simple.avpr
deleted file mode 100644
index 4910346..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/simple.avpr
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- *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.
- */
- {
- "protocol" : "Simple",
- "types" : [ ],
- "messages" : {
- "sum" : {
- "request" : [ {
- "name" : "a",
- "type" : "double"
- }, {
- "name" : "b",
- "type" : "double"
- } ],
- "response" : "double"
- },
- "sub" : {
- "request" : [ {
- "name" : "a",
- "type" : "double"
- }, {
- "name" : "b",
- "type" : "double"
- } ],
- "response" : "double"
- },
- "sqrt" : {
- "request" : [ {
- "name" : "a",
- "type" : "double"
- } ],
- "response" : "double"
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/simple_min.avpr
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/simple_min.avpr b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/simple_min.avpr
deleted file mode 100644
index f5c6673..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/simple_min.avpr
+++ /dev/null
@@ -1,19 +0,0 @@
-/**
- *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.
- */
- {"protocol":"Simple","types":[],"messages":{"sum":{"request":[{"name":"a","type":"double"},{"name":"b","type":"double"}],"response":"double"},"sub":{"request":[{"name":"a","type":"double"},{"name":"b","type":"double"}],"response":"double"},"sqrt":{"request":[{"name":"a","type":"double"}],"response":"double"}}}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/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 3fdfd29..e4093b7 100644
--- a/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
@@ -23,9 +23,8 @@ include_directories(
${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}/dfi/public/include
${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include
- ../dynamic_function_interface
)
SET_HEADER(BUNDLE_SYMBOLICNAME "apache_celix_remote_service_admin_dfi")
@@ -43,6 +42,6 @@ bundle(remote_service_admin_dfi SOURCES
${PROJECT_SOURCE_DIR}/remote_services/utils/private/src/civetweb.c
${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
)
-target_link_libraries(remote_service_admin_dfi celix_framework celix_utils ${CURL_LIBRARIES} ${JANSSON_LIBRARIES} dfi)
+target_link_libraries(remote_service_admin_dfi celix_framework celix_utils celix_dfi ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
install_bundle(remote_service_admin_dfi)
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt b/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
index 299ccd6..140aa54 100644
--- a/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
@@ -28,7 +28,7 @@ add_subdirectory(bundle)
SET(CMAKE_SKIP_BUILD_RPATH FALSE) #TODO needed?
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) #TODO needed?
-SET(CMAKE_INSTALL_RPATH "${PROJECT_BINARY_DIR}/framework" "${PROJECT_BINARY_DIR}/utils" "${PROJECT_BINARY_DIR}/remote_services/remote_service_admin_dfi/dynamic_function_interface")
+SET(CMAKE_INSTALL_RPATH "${PROJECT_BINARY_DIR}/framework" "${PROJECT_BINARY_DIR}/utils" "${PROJECT_BINARY_DIR}/dfi")
add_executable(test_rsa_dfi
run_tests.cpp
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/topology_manager/tms_tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/tms_tst/CMakeLists.txt b/remote_services/topology_manager/tms_tst/CMakeLists.txt
index 098781f..37dc541 100644
--- a/remote_services/topology_manager/tms_tst/CMakeLists.txt
+++ b/remote_services/topology_manager/tms_tst/CMakeLists.txt
@@ -18,7 +18,7 @@ add_subdirectory(disc_mock)
SET(CMAKE_SKIP_BUILD_RPATH FALSE) #TODO needed?
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) #TODO needed?
-SET(CMAKE_INSTALL_RPATH "${PROJECT_BINARY_DIR}/framework" "${PROJECT_BINARY_DIR}/utils")
+SET(CMAKE_INSTALL_RPATH "${PROJECT_BINARY_DIR}/framework" "${PROJECT_BINARY_DIR}/utils" "${PROJECT_BINARY_DIR}/dfi")
add_executable(test_tm_scoped
run_tests.cpp
[3/6] celix git commit: CELIX-309: Move dfi to top-level subdir
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_interface.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_interface.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_interface.c
deleted file mode 100644
index d217d65..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_interface.c
+++ /dev/null
@@ -1,431 +0,0 @@
-/**
- *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.
- */
-#include "dyn_interface.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "dyn_common.h"
-#include "dyn_type.h"
-#include "dyn_interface.h"
-
-DFI_SETUP_LOG(dynInterface);
-
-struct _dyn_interface_type {
- struct namvals_head header;
- struct namvals_head annotations;
- struct types_head types;
- struct methods_head methods;
-};
-
-static const int OK = 0;
-static const int ERROR = 1;
-
-static int dynInterface_parseSection(dyn_interface_type *intf, FILE *stream);
-static int dynInterface_parseAnnotations(dyn_interface_type *intf, FILE *stream);
-static int dynInterface_parseTypes(dyn_interface_type *intf, FILE *stream);
-static int dynInterface_parseMethods(dyn_interface_type *intf, FILE *stream);
-static int dynInterface_parseHeader(dyn_interface_type *intf, FILE *stream);
-static int dynInterface_parseNameValueSection(dyn_interface_type *intf, FILE *stream, struct namvals_head *head);
-static int dynInterface_checkInterface(dyn_interface_type *intf);
-static int dynInterface_getEntryForHead(struct namvals_head *head, const char *name, char **value);
-
-int dynInterface_parse(FILE *descriptor, dyn_interface_type **out) {
- int status = OK;
-
- dyn_interface_type *intf = calloc(1, sizeof(*intf));
- if (intf != NULL) {
- TAILQ_INIT(&intf->header);
- TAILQ_INIT(&intf->annotations);
- TAILQ_INIT(&intf->types);
- TAILQ_INIT(&intf->methods);
-
- char peek = fgetc(descriptor);
- while (peek == ':') {
- ungetc(peek, descriptor);
- status = dynInterface_parseSection(intf, descriptor);
- if (status == OK) {
- peek = fgetc(descriptor);
- } else {
- break;
- }
- }
-
- if (status == OK) {
- status = dynCommon_eatChar(descriptor, EOF);
- }
-
- if (status == OK) {
- status = dynInterface_checkInterface(intf);
- }
- } else {
- status = ERROR;
- LOG_ERROR("Error allocating memory for dynamic interface\n");
- }
-
- if (status == OK) {
- *out = intf;
- } else if (intf != NULL) {
- dynInterface_destroy(intf);
- }
- return status;
-}
-
-static int dynInterface_checkInterface(dyn_interface_type *intf) {
- int status = OK;
-
- //check header section
- if (status == OK) {
- bool foundType = false;
- bool foundVersion = false;
- bool foundName = false;
- struct namval_entry *entry = NULL;
- TAILQ_FOREACH(entry, &intf->header, entries) {
- if (strcmp(entry->name, "type") == 0) {
- foundType = true;
- } else if (strcmp(entry->name, "version") == 0) {
- foundVersion = true;
- } else if (strcmp(entry->name, "name") == 0) {
- foundName = true;
- }
- }
-
- if (!foundType || !foundVersion || !foundName) {
- status = ERROR;
- LOG_ERROR("Parse Error. There must be a header section with a type, version and name entry");
- }
-
- struct method_entry *mEntry = NULL;
- TAILQ_FOREACH(mEntry, &intf->methods, entries) {
- dyn_type *type = dynFunction_returnType(mEntry->dynFunc);
- int descriptor = dynType_descriptorType(type);
- if (descriptor != 'N') {
- status = ERROR;
- LOG_ERROR("Parse Error. Only method with a return type 'N' (native int) are supported. Got return type '%c'\n", descriptor);
- break;
- }
- }
- }
-
- return status;
-}
-
-static int dynInterface_parseSection(dyn_interface_type *intf, FILE *stream) {
- int status = OK;
- char *sectionName = NULL;
-
- status = dynCommon_eatChar(stream, ':');
-
- if (status == OK) {
- status = dynCommon_parseName(stream, §ionName);
- }
-
- if (status == OK) {
- status = dynCommon_eatChar(stream, '\n');
- }
-
- if (status == OK) {
- if (strcmp("header", sectionName) == 0) {
- status = dynInterface_parseHeader(intf, stream);
- } else if (strcmp("annotations", sectionName) == 0) {
- status = dynInterface_parseAnnotations(intf, stream);
- } else if (strcmp("types", sectionName) == 0) {
- status = dynInterface_parseTypes(intf, stream);
- } else if (strcmp("methods", sectionName) == 0) {
- status = dynInterface_parseMethods(intf, stream);
- } else {
- status = ERROR;
- LOG_ERROR("unsupported section '%s'", sectionName);
- }
- }
-
- if (sectionName != NULL) {
- free(sectionName);
- }
-
- return status;
-}
-
-static int dynInterface_parseHeader(dyn_interface_type *intf, FILE *stream) {
- return dynInterface_parseNameValueSection(intf, stream, &intf->header);
-}
-
-static int dynInterface_parseAnnotations(dyn_interface_type *intf, FILE *stream) {
- return dynInterface_parseNameValueSection(intf, stream, &intf->annotations);
-}
-
-static int dynInterface_parseNameValueSection(dyn_interface_type *intf, FILE *stream, struct namvals_head *head) {
- int status = OK;
-
- int peek = fgetc(stream);
- while (peek != ':' && peek != EOF) {
- ungetc(peek, stream);
-
- char *name;
- char *value;
- status = dynCommon_parseNameValue(stream, &name, &value);
-
- if (status == OK) {
- status = dynCommon_eatChar(stream, '\n');
- }
-
- struct namval_entry *entry = NULL;
- if (status == OK) {
- entry = calloc(1, sizeof(*entry));
- if (entry != NULL) {
- entry->name = name;
- entry->value = value;
- TAILQ_INSERT_TAIL(head, entry, entries);
- } else {
- status = ERROR;
- LOG_ERROR("Error allocating memory for namval entry");
- }
- }
-
- if (status != OK) {
- if (name != NULL) {
- free(name);
- }
- if (value != NULL) {
- free(value);
- }
- if (entry != NULL) {
- free(entry);
- }
- break;
- }
- peek = fgetc(stream);
- }
- ungetc(peek, stream);
-
- return status;
-}
-
-static int dynInterface_parseTypes(dyn_interface_type *intf, FILE *stream) {
- int status = OK;
-
- //expected input (Name)=<Type>\n
- int peek = fgetc(stream);
- while (peek != ':' && peek != EOF) {
- ungetc(peek, stream);
-
- char *name;
- status = dynCommon_parseName(stream, &name);
-
- if (status == OK) {
- status = dynCommon_eatChar(stream, '=');
- }
-
- dyn_type *type = NULL;
- if (status == OK) {
- dynType_parse(stream, name, &intf->types, &type);
- }
- if (name != NULL) {
- free(name);
- }
-
- if (status == OK) {
- status = dynCommon_eatChar(stream, '\n');
- }
-
- struct type_entry *entry = NULL;
- if (status == OK) {
- entry = calloc(1, sizeof(*entry));
- if (entry != NULL) {
- entry->type = type;
- TAILQ_INSERT_TAIL(&intf->types, entry, entries);
- } else {
- status = ERROR;
- LOG_ERROR("Error allocating memory for type entry");
- }
- }
-
- if (status != OK) {
- if (type != NULL) {
- dynType_destroy(type);
- }
- if (entry != NULL) {
- free(entry);
- }
- break;
- }
- peek = fgetc(stream);
- }
- ungetc(peek, stream);
-
- return status;
-}
-
-static int dynInterface_parseMethods(dyn_interface_type *intf, FILE *stream) {
- int status = OK;
-
- //expected input (Name)=<Method>\n
- int peek = fgetc(stream);
- int index = 0;
- while (peek != ':' && peek != EOF) {
- ungetc(peek, stream);
-
- char *id;
- status = dynCommon_parseNameAlsoAccept(stream, "();[{}/", &id);
-
- if (status == OK) {
- status = dynCommon_eatChar(stream, '=');
- }
-
-
- dyn_function_type *func = NULL;
- if (status == OK) {
- status = dynFunction_parse(stream, &intf->types, &func);
- }
-
- if (status == OK) {
- status = dynCommon_eatChar(stream, '\n');
- }
-
- struct method_entry *entry = NULL;
- if (status == OK) {
- entry = calloc(1, sizeof(*entry));
- if (entry != NULL) {
- entry->index = index++;
- entry->id = id;
- entry->dynFunc = func;
- entry->name = strndup(id, 1024);
- if (entry->name != NULL) {
- int i;
- for (i = 0; i < 1024; i += 1) {
- if (entry->name[i] == '\0') {
- break;
- } else if (entry->name[i] == '(') {
- entry->name[i] = '\0';
- break;
- }
- }
- }
- TAILQ_INSERT_TAIL(&intf->methods, entry, entries);
- } else {
- status = ERROR;
- LOG_ERROR("Error allocating memory for method entry");
- }
- }
-
- if (status != OK) {
- if (id != NULL) {
- free(id);
- }
- if (func != NULL) {
- dynFunction_destroy(func);
- //TODO free strIdentier, name
- }
- if (entry != NULL) {
- free(entry);
- }
- break;
- }
- peek = fgetc(stream);
- }
- ungetc(peek, stream);
-
- return status;
-}
-
-void dynInterface_destroy(dyn_interface_type *intf) {
- if (intf != NULL) {
- dynCommon_clearNamValHead(&intf->header);
- dynCommon_clearNamValHead(&intf->annotations);
-
- struct method_entry *mTmp = NULL;
- struct method_entry *mInfo = TAILQ_FIRST(&intf->methods);
- while (mInfo != NULL) {
- mTmp = mInfo;
- mInfo = TAILQ_NEXT(mInfo, entries);
-
- if (mTmp->id != NULL) {
- free(mTmp->id);
- }
- if (mTmp->name != NULL) {
- free(mTmp->name);
- }
- if (mTmp->dynFunc != NULL) {
- dynFunction_destroy(mTmp->dynFunc);
- }
- free(mTmp);
- }
-
- struct type_entry *tmp = NULL;
- struct type_entry *tInfo = TAILQ_FIRST(&intf->types);
- while (tInfo != NULL) {
- tmp = tInfo;
- tInfo = TAILQ_NEXT(tInfo, entries);
- dynType_destroy(tmp->type);
- free(tmp);
- }
-
- free(intf);
- }
-}
-
-int dynInterface_getName(dyn_interface_type *intf, char **out) {
- return dynInterface_getEntryForHead(&intf->header, "name", out);
-}
-
-int dynInterface_getVersion(dyn_interface_type *intf, char **version) {
- return dynInterface_getEntryForHead(&intf->header, "version", version);
-}
-
-int dynInterface_getHeaderEntry(dyn_interface_type *intf, const char *name, char **value) {
- return dynInterface_getEntryForHead(&intf->header, name, value);
-}
-
-int dynInterface_getAnnotationEntry(dyn_interface_type *intf, const char *name, char **value) {
- return dynInterface_getEntryForHead(&intf->annotations, name, value);
-}
-
-static int dynInterface_getEntryForHead(struct namvals_head *head, const char *name, char **out) {
- int status = OK;
- char *value = NULL;
- struct namval_entry *entry = NULL;
- TAILQ_FOREACH(entry, head, entries) {
- if (strcmp(name, entry->name) == 0) {
- value = entry->value;
- break;
- }
- }
- if (value != NULL) {
- *out = value;
- } else {
- status = ERROR;
- LOG_WARNING("Cannot find '%s' in list", name);
- }
- return status;
-}
-
-int dynInterface_methods(dyn_interface_type *intf, struct methods_head **list) {
- int status = OK;
- *list = &intf->methods;
- return status;
-}
-
-int dynInterface_nrOfMethods(dyn_interface_type *intf) {
- int count = 0;
- struct method_entry *entry = NULL;
- TAILQ_FOREACH(entry, &intf->methods, entries) {
- count +=1;
- }
- return count;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_interface.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_interface.h b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_interface.h
deleted file mode 100644
index 51a2f41..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_interface.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- *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.
- */
-#ifndef __DYN_INTERFACE_H_
-#define __DYN_INTERFACE_H_
-
-#include "dyn_common.h"
-#include "dyn_type.h"
-#include "dyn_function.h"
-#include "dfi_log_util.h"
-
-DFI_SETUP_LOG_HEADER(dynInterface);
-
-/* Description string
- *
- * Descriptor (interface) = HeaderSection AnnotationSection TypesSection MethodsSection
- *
- * HeaderSection=
- * ':header\n' [NameValue]*
- * ':annotations\n' [NameValue]*
- * ':types\n' [TypeIdValue]*
- * ':methods\n' [MethodIdValue]
- *
- */
-typedef struct _dyn_interface_type dyn_interface_type;
-
-TAILQ_HEAD(methods_head, method_entry);
-struct method_entry {
- int index;
- char *id;
- char *name;
- dyn_function_type *dynFunc;
-
- TAILQ_ENTRY(method_entry) entries;
-};
-
-int dynInterface_parse(FILE *descriptor, dyn_interface_type **out);
-void dynInterface_destroy(dyn_interface_type *intf);
-
-int dynInterface_getName(dyn_interface_type *intf, char **name);
-int dynInterface_getVersion(dyn_interface_type *intf, char **version);
-int dynInterface_getHeaderEntry(dyn_interface_type *intf, const char *name, char **value);
-int dynInterface_getAnnotationEntry(dyn_interface_type *intf, const char *name, char **value);
-int dynInterface_methods(dyn_interface_type *intf, struct methods_head **list);
-int dynInterface_nrOfMethods(dyn_interface_type *intf);
-
-
-#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_message.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_message.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_message.c
deleted file mode 100644
index c43412a..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_message.c
+++ /dev/null
@@ -1,337 +0,0 @@
-/**
- *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.
- */
-#include "dyn_message.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "dyn_common.h"
-#include "dyn_type.h"
-
-DFI_SETUP_LOG(dynMessage);
-
-struct _dyn_message_type {
- struct namvals_head header;
- struct namvals_head annotations;
- struct types_head types;
- dyn_type *msgType;
-};
-
-static const int OK = 0;
-static const int ERROR = 1;
-
-static int dynMessage_parseSection(dyn_message_type *msg, FILE *stream);
-static int dynMessage_parseAnnotations(dyn_message_type *msg, FILE *stream);
-static int dynMessage_parseTypes(dyn_message_type *msg, FILE *stream);
-static int dynMessage_parseMessage(dyn_message_type *msg, FILE *stream);
-static int dynMessage_parseHeader(dyn_message_type *msg, FILE *stream);
-static int dynMessage_parseNameValueSection(dyn_message_type *msg, FILE *stream, struct namvals_head *head);
-static int dynMessage_checkMessage(dyn_message_type *msg);
-static int dynMessage_getEntryForHead(struct namvals_head *head, const char *name, char **value);
-
-int dynMessage_parse(FILE *descriptor, dyn_message_type **out) {
- int status = OK;
-
- dyn_message_type *msg = calloc(1, sizeof(*msg));
- if (msg != NULL) {
- TAILQ_INIT(&msg->header);
- TAILQ_INIT(&msg->annotations);
- TAILQ_INIT(&msg->types);
-
- char peek = fgetc(descriptor);
- while (peek == ':') {
- ungetc(peek, descriptor);
- status = dynMessage_parseSection(msg, descriptor);
- if (status == OK) {
- peek = fgetc(descriptor);
- } else {
- break;
- }
- }
-
- if (status == OK) {
- status = dynCommon_eatChar(descriptor, EOF);
- }
-
- if (status == OK) {
- status = dynMessage_checkMessage(msg);
- }
- } else {
- status = ERROR;
- LOG_ERROR("Error allocating memory for dynamic message\n");
- }
-
- if (status == OK) {
- *out = msg;
- } else if (msg != NULL) {
- dynMessage_destroy(msg);
- }
- return status;
-}
-
-static int dynMessage_checkMessage(dyn_message_type *msg) {
- int status = OK;
-
- //check header section
- if (status == OK) {
- bool foundType = false;
- bool foundVersion = false;
- bool foundName = false;
- struct namval_entry *entry = NULL;
- TAILQ_FOREACH(entry, &msg->header, entries) {
- if (strcmp(entry->name, "type") == 0) {
- foundType = true;
- } else if (strcmp(entry->name, "version") == 0) {
- foundVersion = true;
- } else if (strcmp(entry->name, "name") == 0) {
- foundName = true;
- }
- }
-
- if (!foundType || !foundVersion || !foundName) {
- status = ERROR;
- LOG_ERROR("Parse Error. There must be a header section with a type, version and name entry");
- }
- }
-
- return status;
-}
-
-static int dynMessage_parseSection(dyn_message_type *msg, FILE *stream) {
- int status = OK;
- char *sectionName = NULL;
-
- status = dynCommon_eatChar(stream, ':');
-
- if (status == OK) {
- status = dynCommon_parseName(stream, §ionName);
- }
-
- if (status == OK) {
- status = dynCommon_eatChar(stream, '\n');
- }
-
- if (status == OK) {
- if (strcmp("header", sectionName) == 0) {
- status = dynMessage_parseHeader(msg, stream);
- } else if (strcmp("annotations", sectionName) == 0) {
- status = dynMessage_parseAnnotations(msg, stream);
- } else if (strcmp("types", sectionName) == 0) {
- status = dynMessage_parseTypes(msg, stream);
- } else if (strcmp("message", sectionName) == 0) {
- status = dynMessage_parseMessage(msg, stream);
- } else {
- status = ERROR;
- LOG_ERROR("unsupported section '%s'", sectionName);
- }
- }
-
- if (sectionName != NULL) {
- free(sectionName);
- }
-
- return status;
-}
-
-static int dynMessage_parseHeader(dyn_message_type *msg, FILE *stream) {
- return dynMessage_parseNameValueSection(msg, stream, &msg->header);
-}
-
-static int dynMessage_parseAnnotations(dyn_message_type *msg, FILE *stream) {
- return dynMessage_parseNameValueSection(msg, stream, &msg->annotations);
-}
-
-static int dynMessage_parseNameValueSection(dyn_message_type *msg, FILE *stream, struct namvals_head *head) {
- int status = OK;
-
- int peek = fgetc(stream);
- while (peek != ':' && peek != EOF) {
- ungetc(peek, stream);
-
- char *name;
- char *value;
- status = dynCommon_parseNameValue(stream, &name, &value);
-
- if (status == OK) {
- status = dynCommon_eatChar(stream, '\n');
- }
-
- struct namval_entry *entry = NULL;
- if (status == OK) {
- entry = calloc(1, sizeof(*entry));
- if (entry != NULL) {
- entry->name = name;
- entry->value = value;
- TAILQ_INSERT_TAIL(head, entry, entries);
- } else {
- status = ERROR;
- LOG_ERROR("Error allocating memory for namval entry");
- }
- }
-
- if (status != OK) {
- if (name != NULL) {
- free(name);
- }
- if (value != NULL) {
- free(value);
- }
- if (entry != NULL) {
- free(entry);
- }
- break;
- }
- peek = fgetc(stream);
- }
- ungetc(peek, stream);
-
- return status;
-}
-
-static int dynMessage_parseTypes(dyn_message_type *msg, FILE *stream) {
- int status = OK;
-
- //expected input (Name)=<Type>\n
- int peek = fgetc(stream);
- while (peek != ':' && peek != EOF) {
- ungetc(peek, stream);
-
- char *name;
- status = dynCommon_parseName(stream, &name);
-
- if (status == OK) {
- status = dynCommon_eatChar(stream, '=');
- }
-
- dyn_type *type = NULL;
- if (status == OK) {
- dynType_parse(stream, name, &msg->types, &type);
- }
- if (name != NULL) {
- free(name);
- }
-
- if (status == OK) {
- status = dynCommon_eatChar(stream, '\n');
- }
-
- struct type_entry *entry = NULL;
- if (status == OK) {
- entry = calloc(1, sizeof(*entry));
- if (entry != NULL) {
- entry->type = type;
- TAILQ_INSERT_TAIL(&msg->types, entry, entries);
- } else {
- status = ERROR;
- LOG_ERROR("Error allocating memory for type entry");
- }
- }
-
- if (status != OK) {
- if (type != NULL) {
- dynType_destroy(type);
- }
- if (entry != NULL) {
- free(entry);
- }
- break;
- }
- peek = fgetc(stream);
- }
- ungetc(peek, stream);
-
- return status;
-}
-
-static int dynMessage_parseMessage(dyn_message_type *msg, FILE *stream) {
- int status = OK;
-
- //expected input <dynType>\n
- char *name = NULL;
- status = dynMessage_getName(msg, &name);
-
- if (status == OK) {
- status = dynType_parse(stream, name, &(msg->types), &(msg->msgType));
- }
-
- return status;
-}
-
-void dynMessage_destroy(dyn_message_type *msg) {
- if (msg != NULL) {
- dynCommon_clearNamValHead(&msg->header);
- dynCommon_clearNamValHead(&msg->annotations);
-
- struct type_entry *tmp = NULL;
- struct type_entry *tInfo = TAILQ_FIRST(&msg->types);
- while (tInfo != NULL) {
- tmp = tInfo;
- tInfo = TAILQ_NEXT(tInfo, entries);
- dynType_destroy(tmp->type);
- free(tmp);
- }
-
- if (msg->msgType != NULL) {
- dynType_destroy(msg->msgType);
- }
-
- free(msg);
- }
-}
-
-int dynMessage_getName(dyn_message_type *msg, char **out) {
- return dynMessage_getEntryForHead(&msg->header, "name", out);
-}
-
-int dynMessage_getVersion(dyn_message_type *msg, char **version) {
- return dynMessage_getEntryForHead(&msg->header, "version", version);
-}
-
-int dynMessage_getHeaderEntry(dyn_message_type *msg, const char *name, char **value) {
- return dynMessage_getEntryForHead(&msg->header, name, value);
-}
-
-int dynMessage_getAnnotationEntry(dyn_message_type *msg, const char *name, char **value) {
- return dynMessage_getEntryForHead(&msg->annotations, name, value);
-}
-
-static int dynMessage_getEntryForHead(struct namvals_head *head, const char *name, char **out) {
- int status = OK;
- char *value = NULL;
- struct namval_entry *entry = NULL;
- TAILQ_FOREACH(entry, head, entries) {
- if (strcmp(name, entry->name) == 0) {
- value = entry->value;
- break;
- }
- }
- if (value != NULL) {
- *out = value;
- } else {
- status = ERROR;
- LOG_WARNING("Cannot find '%s' in list", name);
- }
- return status;
-}
-
-int dynMessage_getMessageType(dyn_message_type *msg, dyn_type **type) {
- int status = OK;
- *type = msg->msgType;
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_message.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_message.h b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_message.h
deleted file mode 100644
index b2f5f0e..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_message.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- *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.
- */
-#ifndef __DYN_MESSAGE_H_
-#define __DYN_MESSAGE_H_
-
-#include "dyn_common.h"
-#include "dyn_type.h"
-#include "dfi_log_util.h"
-
-DFI_SETUP_LOG_HEADER(dynMessage);
-
-/* Description string
- *
- * Descriptor (message) = HeaderSection AnnotationSection TypesSection MessageSection
- *
- * HeaderSection=
- * ':header\n' [NameValue]*
- * ':annotations\n' [NameValue]*
- * ':types\n' [TypeIdValue]*
- * ':message\n' [MessageIdValue]
- *
- */
-typedef struct _dyn_message_type dyn_message_type;
-
-
-int dynMessage_parse(FILE *descriptor, dyn_message_type **out);
-void dynMessage_destroy(dyn_message_type *msg);
-
-int dynMessage_getName(dyn_message_type *msg, char **name);
-int dynMessage_getVersion(dyn_message_type *msg, char **version);
-int dynMessage_getHeaderEntry(dyn_message_type *msg, const char *name, char **value);
-int dynMessage_getAnnotationEntry(dyn_message_type *msg, const char *name, char **value);
-int dynMessage_getMessageType(dyn_message_type *msg, dyn_type **type);
-
-
-
-#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/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
deleted file mode 100644
index c47c8c6..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
+++ /dev/null
@@ -1,1144 +0,0 @@
-/**
- *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.
- */
-#include "dyn_type.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <errno.h>
-
-#include "dyn_common.h"
-
-DFI_SETUP_LOG(dynType)
-
-static int dynType_parseWithStream(FILE *stream, const char *name, dyn_type *parent, struct types_head *refTypes, dyn_type **result);
-static void dynType_clear(dyn_type *type);
-static void dynType_clearComplex(dyn_type *type);
-static void dynType_clearSequence(dyn_type *type);
-static void dynType_clearTypedPointer(dyn_type *type);
-
-static struct type_entry *dynType_allocTypeEntry(void);
-
-static ffi_type * dynType_ffiTypeFor(int c);
-static dyn_type * dynType_findType(dyn_type *type, char *name);
-static int dynType_parseAny(FILE *stream, dyn_type *type);
-static int dynType_parseComplex(FILE *stream, dyn_type *type);
-static int dynType_parseNestedType(FILE *stream, dyn_type *type);
-static int dynType_parseReference(FILE *stream, dyn_type *type);
-static int dynType_parseRefByValue(FILE *stream, dyn_type *type);
-static int dynType_parseSequence(FILE *stream, dyn_type *type);
-static int dynType_parseSimple(int c, dyn_type *type);
-static int dynType_parseTypedPointer(FILE *stream, dyn_type *type);
-static void dynType_prepCif(ffi_type *type);
-static unsigned short dynType_getOffset(dyn_type *type, int index);
-
-static void dynType_printAny(char *name, dyn_type *type, int depth, FILE *stream);
-static void dynType_printComplex(char *name, dyn_type *type, int depth, FILE *stream);
-static void dynType_printSequence(char *name, dyn_type *type, int depth, FILE *stream);
-static void dynType_printSimple(char *name, dyn_type *type, int depth, FILE *stream);
-static void dynType_printTypedPointer(char *name, dyn_type *type, int depth, FILE *stream);
-static void dynType_printDepth(int depth, FILE *stream);
-
-static void dynType_printTypes(dyn_type *type, FILE *stream);
-static void dynType_printComplexType(dyn_type *type, FILE *stream);
-static void dynType_printSimpleType(dyn_type *type, FILE *stream);
-
-static int dynType_parseText(FILE *stream, dyn_type *type);
-void dynType_freeComplexType(dyn_type *type, void *loc);
-void dynType_deepFree(dyn_type *type, void *loc, bool alsoDeleteSelf);
-void dynType_freeSequenceType(dyn_type *type, void *seqLoc);
-
-static int dynType_parseMetaInfo(FILE *stream, dyn_type *type);
-
-struct generic_sequence {
- uint32_t cap;
- uint32_t len;
- void *buf;
-};
-
-TAILQ_HEAD(meta_properties_head, meta_entry);
-struct meta_entry {
- char *name;
- char *value;
- TAILQ_ENTRY(meta_entry) entries;
-};
-
-
-struct _dyn_type {
- char *name;
- char descriptor;
- int type;
- ffi_type *ffiType;
- dyn_type *parent;
- struct types_head *referenceTypes; //NOTE: not owned
- struct types_head nestedTypesHead;
- struct meta_properties_head metaProperties;
- union {
- struct {
- struct complex_type_entries_head entriesHead;
- ffi_type structType; //dyn_type.ffiType points to this
- dyn_type **types; //based on entriesHead for fast access
- } complex;
- struct {
- ffi_type seqType; //dyn_type.ffiType points to this
- dyn_type *itemType;
- } sequence;
- struct {
- dyn_type *typedType;
- } typedPointer;
- struct {
- dyn_type *ref;
- } ref;
- };
-};
-
-static const int OK = 0;
-static const int ERROR = 1;
-static const int MEM_ERROR = 2;
-static const int PARSE_ERROR = 3;
-
-int dynType_parse(FILE *descriptorStream, const char *name, struct types_head *refTypes, dyn_type **type) {
- return dynType_parseWithStream(descriptorStream, name, NULL, refTypes, type);
-}
-
-int dynType_parseWithStr(const char *descriptor, const char *name, struct types_head *refTypes, dyn_type **type) {
- int status = OK;
- FILE *stream = fmemopen((char *)descriptor, strlen(descriptor), "r");
- if (stream != NULL) {
- status = dynType_parseWithStream(stream, name, NULL, refTypes, type);
- if (status == OK) {
- int c = fgetc(stream);
- if (c != '\0' && c != EOF) {
- status = PARSE_ERROR;
- LOG_ERROR("Expected EOF got %c", c);
- }
- }
- fclose(stream);
- } else {
- status = ERROR;
- LOG_ERROR("Error creating mem stream for descriptor string. %s", strerror(errno));
- }
- return status;
-}
-
-static int dynType_parseWithStream(FILE *stream, const char *name, dyn_type *parent, struct types_head *refTypes, dyn_type **result) {
- int status = OK;
- dyn_type *type = calloc(1, sizeof(*type));
- if (type != NULL) {
- type->parent = parent;
- type->type = DYN_TYPE_INVALID;
- type->referenceTypes = refTypes;
- TAILQ_INIT(&type->nestedTypesHead);
- TAILQ_INIT(&type->metaProperties);
- if (name != NULL) {
- type->name = strdup(name);
- if (type->name == NULL) {
- status = MEM_ERROR;
- LOG_ERROR("Error strdup'ing name '%s'\n", name);
- }
- }
- if (status == OK) {
- status = dynType_parseAny(stream, type);
- }
- if (status == OK) {
- *result = type;
- } else {
- dynType_destroy(type);
- }
- } else {
- status = MEM_ERROR;
- LOG_ERROR("Error allocating memory for type");
- }
- return status;
-}
-
-static int dynType_parseAny(FILE *stream, dyn_type *type) {
- int status = OK;
-
- int c = fgetc(stream);
- switch(c) {
- case 'T' :
- status = dynType_parseNestedType(stream, type);
- if (status == OK) {
- status = dynType_parseAny(stream, type);
- }
- break;
- case 'L' :
- status = dynType_parseReference(stream, type);
- break;
- case 'l' :
- status = dynType_parseRefByValue(stream, type);
- break;
- case '{' :
- status = dynType_parseComplex(stream, type);
- break;
- case '[' :
- status = dynType_parseSequence(stream, type);
- break;
- case '*' :
- status = dynType_parseTypedPointer(stream, type);
- break;
- case 't' :
- status = dynType_parseText(stream, type);
- break;
- case '#' :
- status = dynType_parseMetaInfo(stream, type);
- if (status == OK) {
- status = dynType_parseAny(stream, type);
- }
- break;
- default :
- status = dynType_parseSimple(c, type);
- break;
- }
-
- return status;
-}
-
-static int dynType_parseMetaInfo(FILE *stream, dyn_type *type) {
- int status = OK;
- char *name = NULL;
- char *value = NULL;
-
- struct meta_entry *entry = calloc(1, sizeof(*entry));
- if (entry == NULL) {
- status = ERROR;
- }
-
- if (status == OK) {
- status = dynCommon_parseName(stream, &name);
- }
-
- if (status == OK) {
- status = dynCommon_eatChar(stream, '=');
- }
-
- if (status == OK) {
- status = dynCommon_parseName(stream, &value);
- }
-
- if (status == OK) {
- status = dynCommon_eatChar(stream, ';');
- }
-
- if (status == OK) {
- entry->name = name;
- entry->value = value;
- TAILQ_INSERT_TAIL(&type->metaProperties, entry, entries);
- LOG_DEBUG("Added meta properties '%s':'%s'", name, value)
- } else {
- free(name);
- free(value);
- free(entry);
- }
-
- return status;
-}
-
-static int dynType_parseText(FILE *stream, dyn_type *type) {
- int status = OK;
- type->type = DYN_TYPE_TEXT;
- type->descriptor = 't';
- type->ffiType = &ffi_type_pointer;
- return status;
-}
-
-static int dynType_parseComplex(FILE *stream, dyn_type *type) {
- int status = OK;
- type->type = DYN_TYPE_COMPLEX;
- type->descriptor = '{';
- type->ffiType = &type->complex.structType;
- TAILQ_INIT(&type->complex.entriesHead);
-
- int c = fgetc(stream);
- struct complex_type_entry *entry = NULL;
- while (c != ' ' && c != '}') {
- ungetc(c,stream);
- entry = calloc(1, sizeof(*entry));
- if (entry != NULL) {
- entry->type = calloc(1, sizeof(*entry->type));
- }
- if (entry != NULL && entry->type != NULL) {
- entry->type->parent = type;
- entry->type->type = DYN_TYPE_INVALID;
- TAILQ_INIT(&entry->type->nestedTypesHead);
- TAILQ_INIT(&entry->type->metaProperties);
- TAILQ_INSERT_TAIL(&type->complex.entriesHead, entry, entries);
- status = dynType_parseAny(stream, entry->type);
- } else {
- if (entry != NULL) {
- free(entry);
- }
- status = MEM_ERROR;
- LOG_ERROR("Error allocating memory for type");
- }
- c = fgetc(stream);
- }
-
- entry = TAILQ_FIRST(&type->complex.entriesHead);
- char *name = NULL;
- while (c == ' ' && entry != NULL) {
- status = dynCommon_parseName(stream, &name);
- if (status == OK) {
- entry->name = name;
- entry = TAILQ_NEXT(entry, entries);
- } else {
- break;
- }
- c = getc(stream);
- }
-
- int count = 0;
- TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
- count +=1;
- }
-
- if (status == OK) {
- type->complex.structType.type = FFI_TYPE_STRUCT;
- type->complex.structType.elements = calloc(count + 1, sizeof(ffi_type));
- if (type->complex.structType.elements != NULL) {
- type->complex.structType.elements[count] = NULL;
- int index = 0;
- TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
- type->complex.structType.elements[index++] = dynType_ffiType(entry->type);
- }
- } else {
- status = MEM_ERROR;
- //T\nODO log: error allocating memory
- }
- }
-
- if (status == OK) {
- type->complex.types = calloc(count, sizeof(dyn_type *));
- if (type != NULL) {
- int index = 0;
- TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
- type->complex.types[index++] = entry->type;
- }
- } else {
- status = MEM_ERROR;
- LOG_ERROR("Error allocating memory for type")
- }
- }
-
- if (status == OK) {
- dynType_prepCif(type->ffiType);
- }
-
-
- return status;
-}
-
-static int dynType_parseNestedType(FILE *stream, dyn_type *type) {
- int status = OK;
- char *name = NULL;
- struct type_entry *entry = NULL;
-
- entry = dynType_allocTypeEntry();
- if (entry != NULL) {
- entry->type->parent = type;
- entry->type->type = DYN_TYPE_INVALID;
- TAILQ_INIT(&entry->type->nestedTypesHead);
- TAILQ_INIT(&entry->type->metaProperties);
- TAILQ_INSERT_TAIL(&type->nestedTypesHead, entry, entries);
- status = dynCommon_parseName(stream, &name);
- entry->type->name = name;
- } else {
- status = MEM_ERROR;
- LOG_ERROR("Error allocating entry");
- }
-
- if (status == OK) {
- int c = fgetc(stream);
- if (c != '=') {
- status = PARSE_ERROR;
- LOG_ERROR("Error parsing nested type expected '=' got '%c'", c);
- }
- }
-
- if (status == OK) {
- status = dynType_parseAny(stream, entry->type);
- int c = fgetc(stream);
- if (c != ';') {
- status = PARSE_ERROR;
- LOG_ERROR("Expected ';' got '%c'\n", c);
- }
- }
-
- return status;
-}
-
-static int dynType_parseReference(FILE *stream, dyn_type *type) {
- int status = OK;
- type->type = DYN_TYPE_TYPED_POINTER;
- type->descriptor = '*';
-
- type->ffiType = &ffi_type_pointer;
- type->typedPointer.typedType = NULL;
-
- dyn_type *subType = calloc(1, sizeof(*subType));
-
- if (subType != NULL) {
- type->typedPointer.typedType = subType;
- subType->parent = type;
- subType->type = DYN_TYPE_INVALID;
- TAILQ_INIT(&subType->nestedTypesHead);
- TAILQ_INIT(&subType->metaProperties);
- status = dynType_parseRefByValue(stream, subType);
- } else {
- status = MEM_ERROR;
- LOG_ERROR("Error allocating memory for subtype\n");
- }
-
- return status;
-}
-
-static int dynType_parseRefByValue(FILE *stream, dyn_type *type) {
- int status = OK;
- type->type = DYN_TYPE_REF;
- type->descriptor = 'l';
-
- char *name = NULL;
- status = dynCommon_parseName(stream, &name);
- if (status == OK) {
- dyn_type *ref = dynType_findType(type, name);
- if (ref != NULL) {
- type->ref.ref = ref;
- } else {
- status = PARSE_ERROR;
- LOG_ERROR("Error cannot find type '%s'", name);
- }
- free(name);
- }
-
- if (status == OK) {
- int c = fgetc(stream);
- if (c != ';') {
- status = PARSE_ERROR;
- LOG_ERROR("Error expected ';' got '%c'", c);
- }
- }
-
- return status;
-}
-
-static struct type_entry *dynType_allocTypeEntry(void) {
- struct type_entry *entry = calloc(1, sizeof(*entry));
- if (entry != NULL) {
- entry->type = calloc(1, sizeof(*entry->type));
- if (entry->type == NULL) {
- free(entry);
- entry = NULL;
- }
- }
- return entry;
-}
-
-static ffi_type *seq_types[] = {&ffi_type_uint32, &ffi_type_uint32, &ffi_type_pointer, NULL};
-
-static int dynType_parseSequence(FILE *stream, dyn_type *type) {
- int status = OK;
- type->type = DYN_TYPE_SEQUENCE;
- type->descriptor = '[';
-
- type->sequence.seqType.elements = seq_types;
- type->sequence.seqType.type = FFI_TYPE_STRUCT;
- type->sequence.seqType.size = 0;
- type->sequence.seqType.alignment = 0;
-
- status = dynType_parseWithStream(stream, NULL, type, NULL, &type->sequence.itemType);
-
- if (status == OK) {
- type->ffiType = &type->sequence.seqType;
- dynType_prepCif(&type->sequence.seqType);
- }
-
- return status;
-}
-
-static int dynType_parseSimple(int c, dyn_type *type) {
- int status = OK;
- ffi_type *ffiType = dynType_ffiTypeFor(c);
- if (ffiType != NULL) {
- type->type = DYN_TYPE_SIMPLE;
- type->descriptor = c;
- type->ffiType = ffiType;
- } else {
- status = PARSE_ERROR;
- LOG_ERROR("Error unsupported type '%c'", c);
- }
-
- return status;
-}
-
-static int dynType_parseTypedPointer(FILE *stream, dyn_type *type) {
- int status = OK;
- type->type = DYN_TYPE_TYPED_POINTER;
- type->descriptor = '*';
- type->ffiType = &ffi_type_pointer;
-
- status = dynType_parseWithStream(stream, NULL, type, NULL, &type->typedPointer.typedType);
-
- return status;
-}
-
-static void dynType_prepCif(ffi_type *type) {
- ffi_cif cif;
- ffi_type *args[1];
- args[0] = type;
- ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_uint, args);
-}
-
-void dynType_destroy(dyn_type *type) {
- if (type != NULL) {
- dynType_clear(type);
- free(type);
- }
-}
-
-static void dynType_clear(dyn_type *type) {
- struct type_entry *entry = TAILQ_FIRST(&type->nestedTypesHead);
- struct type_entry *tmp = NULL;
- while (entry != NULL) {
- tmp = entry;
- entry = TAILQ_NEXT(entry, entries);
- if (tmp->type != NULL) {
- dynType_destroy(tmp->type);
- tmp->type = NULL;
- }
- free(tmp);
- }
-
- struct meta_entry *mEntry = TAILQ_FIRST(&type->metaProperties);;
- struct meta_entry *next = NULL;
- while (mEntry != NULL) {
- next = TAILQ_NEXT(mEntry, entries);
- if (mEntry != NULL) {
- free(mEntry->name);
- free(mEntry->value);
- free(mEntry);
- }
- mEntry = next;
- }
-
- switch (type->type) {
- case DYN_TYPE_COMPLEX :
- dynType_clearComplex(type);
- break;
- case DYN_TYPE_SEQUENCE :
- dynType_clearSequence(type);
- break;
- case DYN_TYPE_TYPED_POINTER :
- dynType_clearTypedPointer(type);
- break;
- }
-
- if (type->name != NULL) {
- free(type->name);
- }
-}
-
-static void dynType_clearComplex(dyn_type *type) {
- assert(type->type == DYN_TYPE_COMPLEX);
- struct complex_type_entry *entry = TAILQ_FIRST(&type->complex.entriesHead);
- struct complex_type_entry *tmp = NULL;
- while (entry != NULL) {
- dynType_destroy(entry->type);
- if (entry->name != NULL) {
- free(entry->name);
- }
- tmp = entry;
- entry = TAILQ_NEXT(entry, entries);
- free(tmp);
- }
- if (type->complex.types != NULL) {
- free(type->complex.types);
- }
- if (type->complex.structType.elements != NULL) {
- free(type->complex.structType.elements);
- }
-}
-
-static void dynType_clearSequence(dyn_type *type) {
- assert(type->type == DYN_TYPE_SEQUENCE);
- if (type->sequence.itemType != NULL) {
- dynType_destroy(type->sequence.itemType);
- }
-}
-
-static void dynType_clearTypedPointer(dyn_type *type) {
- assert(type->type == DYN_TYPE_TYPED_POINTER);
- if (type->typedPointer.typedType != NULL) {
- dynType_destroy(type->typedPointer.typedType);
- }
-}
-
-int dynType_alloc(dyn_type *type, void **bufLoc) {
- assert(type->type != DYN_TYPE_REF);
- assert(type->ffiType->size != 0);
- int status = OK;
-
- void *inst = calloc(1, type->ffiType->size);
- if (inst != NULL) {
- if (type->type == DYN_TYPE_TYPED_POINTER) {
- void *ptr = NULL;
- dyn_type *sub = NULL;
- status = dynType_typedPointer_getTypedType(type, &sub);
- if (status == OK) {
- status = dynType_alloc(sub, &ptr);
- if (status == OK) {
- *(void **)inst = ptr;
- }
- }
- }
- *bufLoc = inst;
- } else {
- status = MEM_ERROR;
- LOG_ERROR("Error allocating memory for type '%c'", type->descriptor);
- }
-
- return status;
-}
-
-
-int dynType_complex_indexForName(dyn_type *type, const char *name) {
- assert(type->type == DYN_TYPE_COMPLEX);
- int i = 0;
- int index = -1;
- struct complex_type_entry *entry = NULL;
- TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
- if (strcmp(name, entry->name) == 0) {
- index = i;
- }
- i +=1;
- }
- return index;
-}
-
-int dynType_complex_dynTypeAt(dyn_type *type, int index, dyn_type **result) {
- assert(type->type == DYN_TYPE_COMPLEX);
- dyn_type *sub = type->complex.types[index];
- if (sub->type == DYN_TYPE_REF) {
- sub = sub->ref.ref;
- }
- *result = sub;
- return 0;
-}
-
-int dynType_complex_setValueAt(dyn_type *type, int index, void *start, void *in) {
- assert(type->type == DYN_TYPE_COMPLEX);
- char *loc = ((char *)start) + dynType_getOffset(type, index);
- size_t size = type->complex.structType.elements[index]->size;
- memcpy(loc, in, size);
- return 0;
-}
-
-int dynType_complex_valLocAt(dyn_type *type, int index, void *inst, void **result) {
- assert(type->type == DYN_TYPE_COMPLEX);
- char *l = (char *)inst;
- void *loc = (void *)(l + dynType_getOffset(type, index));
- *result = loc;
- return 0;
-}
-
-int dynType_complex_entries(dyn_type *type, struct complex_type_entries_head **entries) {
- assert(type->type == DYN_TYPE_COMPLEX);
- int status = OK;
- *entries = &type->complex.entriesHead;
- return status;
-}
-
-//sequence
-int dynType_sequence_alloc(dyn_type *type, void *inst, uint32_t cap) {
- assert(type->type == DYN_TYPE_SEQUENCE);
- int status = OK;
- struct generic_sequence *seq = inst;
- if (seq != NULL) {
- size_t size = dynType_size(type->sequence.itemType);
- seq->buf = calloc(cap, size);
- if (seq->buf != NULL) {
- seq->cap = cap;
- seq->len = 0;;
- } else {
- seq->cap = 0;
- status = MEM_ERROR;
- LOG_ERROR("Error allocating memory for buf")
- }
- } else {
- status = MEM_ERROR;
- LOG_ERROR("Error allocating memory for seq")
- }
- return status;
-}
-
-void dynType_free(dyn_type *type, void *loc) {
- dynType_deepFree(type, loc, true);
-}
-
-void dynType_deepFree(dyn_type *type, void *loc, bool alsoDeleteSelf) {
- if (loc != NULL) {
- dyn_type *subType = NULL;
- char *text = NULL;
- switch (type->type) {
- case DYN_TYPE_COMPLEX :
- dynType_freeComplexType(type, loc);
- break;
- case DYN_TYPE_SEQUENCE :
- dynType_freeSequenceType(type, loc);
- break;
- case DYN_TYPE_TYPED_POINTER:
- dynType_typedPointer_getTypedType(type, &subType);
- dynType_deepFree(subType, *(void **)loc, true);
- break;
- case DYN_TYPE_TEXT :
- text = *(char **)loc;
- free(text);
- break;
- }
-
- if (alsoDeleteSelf) {
- free(loc);
- }
- }
-}
-
-void dynType_freeSequenceType(dyn_type *type, void *seqLoc) {
- struct generic_sequence *seq = seqLoc;
- dyn_type *itemType = dynType_sequence_itemType(type);
- void *itemLoc = NULL;
- int i;
- for (i = 0; i < seq->len; i += 1) {
- dynType_sequence_locForIndex(type, seqLoc, i, &itemLoc);
- dynType_deepFree(itemType, itemLoc, false);
- }
- free(seq->buf);
-}
-
-void dynType_freeComplexType(dyn_type *type, void *loc) {
- struct complex_type_entry *entry = NULL;
- int index = 0;
- void *entryLoc = NULL;
- TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
- dynType_complex_valLocAt(type, index++, loc, &entryLoc);
- dynType_deepFree(entry->type, entryLoc, false);
- }
-}
-
-
-uint32_t dynType_sequence_length(void *seqLoc) {
- struct generic_sequence *seq = seqLoc;
- return seq->len;
-}
-
-int dynType_sequence_locForIndex(dyn_type *type, void *seqLoc, int index, void **out) {
- assert(type->type == DYN_TYPE_SEQUENCE);
- int status = OK;
-
- struct generic_sequence *seq = seqLoc;
- char *valLoc = seq->buf;
-
- size_t itemSize = dynType_size(type->sequence.itemType);
-
- if (index >= seq->cap) {
- status = ERROR;
- LOG_ERROR("Requested index (%i) is greater than capacity (%u) of sequence", index, seq->cap);
- }
-
- if (index >= seq->len) {
- LOG_WARNING("Requesting index (%i) outsize defined length (%u) but within capacity", index, seq->len);
- }
-
- if (status == OK) { }
- int i;
- for (i = 0; i < seq->cap; i += 1) {
- if (index == i) {
- break;
- } else {
- valLoc += itemSize;
- }
- }
-
- (*out) = valLoc;
-
- return status;
-}
-
-int dynType_sequence_increaseLengthAndReturnLastLoc(dyn_type *type, void *seqLoc, void **valLoc) {
- assert(type->type == DYN_TYPE_SEQUENCE);
- int status = OK;
- struct generic_sequence *seq = seqLoc;
-
- int lastIndex = seq->len;
- if (seq->len < seq->cap) {
- seq->len += 1;
- } else {
- status = ERROR;
- LOG_ERROR("Cannot increase sequence length beyond capacity (%u)", seq->cap);
- }
-
- if (status == OK) {
- status = dynType_sequence_locForIndex(type, seqLoc, lastIndex, valLoc);
- }
-
- return status;
-}
-
-dyn_type * dynType_sequence_itemType(dyn_type *type) {
- assert(type->type == DYN_TYPE_SEQUENCE);
- dyn_type *itemType = type->sequence.itemType;
- if (itemType->type == DYN_TYPE_REF) {
- itemType = itemType->ref.ref;
- }
- return itemType;
-}
-
-void dynType_simple_setValue(dyn_type *type, void *inst, void *in) {
- size_t size = dynType_size(type);
- memcpy(inst, in, size);
-}
-
-
-int dynType_descriptorType(dyn_type *type) {
- return type->descriptor;
-}
-
-const char * dynType_getMetaInfo(dyn_type *type, const char *name) {
- const char *result = NULL;
- struct meta_entry *entry = NULL;
- TAILQ_FOREACH(entry, &type->metaProperties, entries) {
- LOG_DEBUG("Checking '%s'", entry->name);
- if (strcmp(entry->name, name) == 0) {
- result = entry->value;
- break;
- }
- }
- return result;
-}
-
-ffi_type *dynType_ffiType(dyn_type *type) {
- if (type->type == DYN_TYPE_REF) {
- return type->ref.ref->ffiType;
- }
- return type->ffiType;
-}
-
-static ffi_type * dynType_ffiTypeFor(int c) {
- ffi_type *type = NULL;
- switch (c) {
- case 'Z' :
- type = &ffi_type_uint8;
- break;
- case 'F' :
- type = &ffi_type_float;
- break;
- case 'D' :
- type = &ffi_type_double;
- break;
- case 'B' :
- type = &ffi_type_sint8;
- break;
- case 'b' :
- type = &ffi_type_uint8;
- break;
- case 'S' :
- type = &ffi_type_sint16;
- break;
- case 's' :
- type = &ffi_type_uint16;
- break;
- case 'I' :
- type = &ffi_type_sint32;
- break;
- case 'i' :
- type = &ffi_type_uint32;
- break;
- case 'J' :
- type = &ffi_type_sint64;
- break;
- case 'j' :
- type = &ffi_type_sint64;
- break;
- case 'N' :
- type = &ffi_type_sint;
- break;
- case 'P' :
- type = &ffi_type_pointer;
- break;
- case 'V' :
- type = &ffi_type_void;
- break;
- }
- return type;
-}
-
-static dyn_type * dynType_findType(dyn_type *type, char *name) {
- dyn_type *result = NULL;
-
- struct type_entry *entry = NULL;
- if (type->referenceTypes != NULL) {
- TAILQ_FOREACH(entry, type->referenceTypes, entries) {
- LOG_DEBUG("checking ref type '%s' with name '%s'", entry->type->name, name);
- if (strcmp(name, entry->type->name) == 0) {
- result = entry->type;
- break;
- }
- }
- }
-
- if (result == NULL) {
- struct type_entry *nEntry = NULL;
- TAILQ_FOREACH(nEntry, &type->nestedTypesHead, entries) {
- LOG_DEBUG("checking nested type '%s' with name '%s'", nEntry->type->name, name);
- if (strcmp(name, nEntry->type->name) == 0) {
- result = nEntry->type;
- break;
- }
- }
- }
-
- if (result == NULL && type->parent != NULL) {
- result = dynType_findType(type->parent, name);
- }
-
- return result;
-}
-
-static unsigned short dynType_getOffset(dyn_type *type, int index) {
- assert(type->type == DYN_TYPE_COMPLEX);
- unsigned short offset = 0;
-
- ffi_type *ffiType = &type->complex.structType;
- int i;
- for (i = 0; i <= index && ffiType->elements[i] != NULL; i += 1) {
- size_t size = ffiType->elements[i]->size;
- unsigned short alignment = ffiType->elements[i]->alignment;
- int alignment_diff = offset % alignment;
- if (alignment_diff > 0) {
- offset += (alignment - alignment_diff);
- }
- if (i < index) {
- offset += size;
- }
- }
-
- return offset;
-}
-
-size_t dynType_size(dyn_type *type) {
- dyn_type *rType = type;
- if (type->type == DYN_TYPE_REF) {
- rType = type->ref.ref;
- }
- return rType->ffiType->size;
-}
-
-int dynType_type(dyn_type *type) {
- return type->type;
-}
-
-
-int dynType_typedPointer_getTypedType(dyn_type *type, dyn_type **out) {
- assert(type->type == DYN_TYPE_TYPED_POINTER);
- int status = 0;
-
- dyn_type *typedType = type->typedPointer.typedType;
- if (typedType->type == DYN_TYPE_REF) {
- typedType = typedType->ref.ref;
- }
-
- *out = typedType;
- return status;
-}
-
-
-int dynType_text_allocAndInit(dyn_type *type, void *textLoc, const char *value) {
- assert(type->type == DYN_TYPE_TEXT);
- int status = 0;
- const char *str = strdup(value);
- char const **loc = textLoc;
- if (str != NULL) {
- *loc = str;
- } else {
- status = ERROR;
- LOG_ERROR("Cannot allocate memory for string");
- }
- return status;
-}
-
-
-
-
-
-void dynType_print(dyn_type *type, FILE *stream) {
- if (type != NULL) {
- dynType_printTypes(type, stream);
-
- fprintf(stream, "main type:\n");
- dynType_printAny("root", type, 0, stream);
- } else {
- fprintf(stream, "invalid type\n");
- }
-}
-
-static void dynType_printDepth(int depth, FILE *stream) {
- int i;
- for (i = 0; i < depth; i +=1 ) {
- fprintf(stream, "\t");
- }
-}
-
-static void dynType_printAny(char *name, dyn_type *type, int depth, FILE *stream) {
- dyn_type *toPrint = type;
- if (toPrint->type == DYN_TYPE_REF) {
- toPrint = toPrint->ref.ref;
- }
- switch(toPrint->type) {
- case DYN_TYPE_COMPLEX :
- dynType_printComplex(name, toPrint, depth, stream);
- break;
- case DYN_TYPE_SIMPLE :
- dynType_printSimple(name, toPrint, depth, stream);
- break;
- case DYN_TYPE_SEQUENCE :
- dynType_printSequence(name, toPrint, depth, stream);
- break;
- case DYN_TYPE_TYPED_POINTER :
- dynType_printTypedPointer(name, toPrint, depth, stream);
- break;
- default :
- fprintf(stream, "TODO Unsupported type %i\n", toPrint->type);
- break;
- }
-}
-
-static void dynType_printComplex(char *name, dyn_type *type, int depth, FILE *stream) {
- if (type->name == NULL) {
- dynType_printDepth(depth, stream);
- fprintf(stream, "%s: complex type (anon), size is %zu, alignment is %i, descriptor is '%c'. fields:\n", name, type->ffiType->size, type->ffiType->alignment, type->descriptor);
-
- struct complex_type_entry *entry = NULL;
- TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
- dynType_printAny(entry->name, entry->type, depth + 1, stream);
- }
-
- dynType_printDepth(depth, stream);
- fprintf(stream, "}\n");
- } else {
- dynType_printDepth(depth, stream);
- fprintf(stream, "%s: complex type ('%s'), size is %zu, alignment is %i, descriptor is '%c'.\n", name, type->name, type->ffiType->size, type->ffiType->alignment, type->descriptor);
- }
-}
-
-static void dynType_printSequence(char *name, dyn_type *type, int depth, FILE *stream) {
- dynType_printDepth(depth, stream);
- fprintf(stream, "sequence, size is %zu, alignment is %i, descriptor is '%c'. fields:\n", type->ffiType->size, type->ffiType->alignment, type->descriptor);
-
- dynType_printDepth(depth + 1, stream);
- fprintf(stream, "cap: simple type, size is %zu, alignment is %i.\n", type->sequence.seqType.elements[0]->size, type->sequence.seqType.elements[0]->alignment);
-
- dynType_printDepth(depth + 1, stream);
- fprintf(stream, "len: simple type, size is %zu, alignment is %i.\n", type->sequence.seqType.elements[1]->size, type->sequence.seqType.elements[1]->alignment);
-
- dynType_printDepth(depth + 1, stream);
- fprintf(stream, "buf: array, size is %zu, alignment is %i. points to ->\n", type->sequence.seqType.elements[2]->size, type->sequence.seqType.elements[2]->alignment);
- dynType_printAny("element", type->sequence.itemType, depth + 1, stream);
-}
-
-static void dynType_printSimple(char *name, dyn_type *type, int depth, FILE *stream) {
- dynType_printDepth(depth, stream);
- fprintf(stream, "%s: simple type, size is %zu, alignment is %i, descriptor is '%c'.\n", name, type->ffiType->size, type->ffiType->alignment, type->descriptor);
-}
-
-static void dynType_printTypedPointer(char *name, dyn_type *type, int depth, FILE *stream) {
- dynType_printDepth(depth, stream);
- fprintf(stream, "%s: typed pointer, size is %zu, alignment is %i, points to ->\n", name, type->ffiType->size, type->ffiType->alignment);
- char *subName = NULL;
- if (name != NULL) {
- char buf[128];
- snprintf(buf, 128, "*%s", name);
- subName = buf;
- }
- dynType_printAny(subName, type->typedPointer.typedType, depth + 1, stream);
-}
-
-static void dynType_printTypes(dyn_type *type, FILE *stream) {
-
- dyn_type *parent = type->parent;
- struct type_entry *pentry = NULL;
- while (parent != NULL) {
- TAILQ_FOREACH(pentry, &parent->nestedTypesHead, entries) {
- if (pentry->type == type) {
- return;
- }
- }
- parent = parent->parent;
- }
-
- struct type_entry *entry = NULL;
- TAILQ_FOREACH(entry, &type->nestedTypesHead, entries) {
- dyn_type *toPrint = entry->type;
- if (toPrint->type == DYN_TYPE_REF) {
- toPrint = toPrint->ref.ref;
- }
-
- switch(toPrint->type) {
- case DYN_TYPE_COMPLEX :
- dynType_printComplexType(toPrint, stream);
- break;
- case DYN_TYPE_SIMPLE :
- dynType_printSimpleType(toPrint, stream);
- break;
- default :
- printf("TODO Print Type\n");
- break;
- }
- }
-
-
- struct complex_type_entry *centry = NULL;
- switch(type->type) {
- case DYN_TYPE_COMPLEX :
- TAILQ_FOREACH(centry, &type->complex.entriesHead, entries) {
- dynType_printTypes(centry->type, stream);
- }
- break;
- case DYN_TYPE_SEQUENCE :
- dynType_printTypes(type->sequence.itemType, stream);
- break;
- case DYN_TYPE_TYPED_POINTER :
- dynType_printTypes(type->typedPointer.typedType, stream);
- break;
- }
-}
-
-static void dynType_printComplexType(dyn_type *type, FILE *stream) {
- fprintf(stream, "type '%s': complex type, size is %zu, alignment is %i, descriptor is '%c'. fields:\n", type->name, type->ffiType->size, type->ffiType->alignment, type->descriptor);
-
- struct complex_type_entry *entry = NULL;
- TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
- dynType_printAny(entry->name, entry->type, 2, stream);
- }
-
- fprintf(stream, "}\n");
-}
-
-static void dynType_printSimpleType(dyn_type *type, FILE *stream) {
- fprintf(stream, "\ttype '%s': simple type, size is %zu, alignment is %i, descriptor is '%c'\n", type->name, type->ffiType->size, type->ffiType->alignment, type->descriptor);
-}
-
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.h b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.h
deleted file mode 100644
index b2b84ef..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.h
+++ /dev/null
@@ -1,157 +0,0 @@
-/**
- *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.
- */
-
-#ifndef _DYN_TYPE_H_
-#define _DYN_TYPE_H_
-
-#include <stdio.h>
-#include <sys/queue.h>
-#include <stdbool.h>
-
-#include <ffi.h>
-#include <stdint.h>
-
-#include "dfi_log_util.h"
-
-#if defined(BSD) || defined(__APPLE__)
-#include "memstream/open_memstream.h"
-#include "memstream/fmemopen.h"
-#endif
-
-/* Description string
- *
- * Type = [TypeDef]* (MetaInfo)* (SimpleType | ComplexType | SequenceType | TypedPointer | PointerReference ) [TypeDef]*
- * Name = alpha[(alpha|numeric)*]
- * SPACE = ' '
- *
- * SimplesTypes (based on java bytecode method signatures)
- * //Java based:
- * B char
- * C (not supported)
- * D double
- * F float
- * I int32_t
- * J int64_t
- * S int16_t
- * V void
- * Z boolean
- * //Extended
- * b unsigned char
- * i uint32_t
- * j uint62_t
- * s uint64_t
- * P untyped pointer (void *)
- * t char* string
- * N native int
- *
- * ComplexTypes (Struct)
- * {[Type]+ [(Name)(SPACE)]+}
- *
- * ReferenceByValue
- * l(name);
- *
- * PointerReference -> note shortcut for *l(name);
- * L(Name);
- *
- * TypeDef
- * T(Name)=Type;
- *
- * SequenceType
- * [(Type)
- *
- * TypedPointer
- * *(Type)
- *
- * MetaInfo TODO
- * #Name=Value;
- *
- *
- *
- * examples
- * "{DDII a b c d}" -> struct { double a; double b; int c; int d; };
- * "{DD{FF c1 c2} a b c}" -> struct { double a; double b; struct c { float c1; float c2; }; };
- *
- *
- */
-
-#define DYN_TYPE_INVALID 0
-#define DYN_TYPE_SIMPLE 1
-#define DYN_TYPE_COMPLEX 2
-#define DYN_TYPE_SEQUENCE 3
-#define DYN_TYPE_TYPED_POINTER 4
-#define DYN_TYPE_TEXT 5
-#define DYN_TYPE_REF 6
-
-typedef struct _dyn_type dyn_type;
-
-TAILQ_HEAD(types_head, type_entry);
-struct type_entry {
- dyn_type *type;
- TAILQ_ENTRY(type_entry) entries;
-};
-
-TAILQ_HEAD(complex_type_entries_head, complex_type_entry);
-struct complex_type_entry {
- dyn_type *type;
- char *name;
- TAILQ_ENTRY(complex_type_entry) entries;
-};
-
-//logging
-DFI_SETUP_LOG_HEADER(dynType);
-
-//generic
-int dynType_parse(FILE *descriptorStream, const char *name, struct types_head *refTypes, dyn_type **type);
-int dynType_parseWithStr(const char *descriptor, const char *name, struct types_head *refTypes, dyn_type **type);
-void dynType_destroy(dyn_type *type);
-
-int dynType_alloc(dyn_type *type, void **bufLoc);
-void dynType_free(dyn_type *type, void *loc);
-
-void dynType_print(dyn_type *type, FILE *stream);
-size_t dynType_size(dyn_type *type);
-int dynType_type(dyn_type *type);
-int dynType_descriptorType(dyn_type *type);
-ffi_type * dynType_ffiType(dyn_type *type);
-const char * dynType_getMetaInfo(dyn_type *type, const char *name);
-
-//complexType
-int dynType_complex_indexForName(dyn_type *type, const char *name);
-int dynType_complex_dynTypeAt(dyn_type *type, int index, dyn_type **subType);
-int dynType_complex_setValueAt(dyn_type *type, int index, void *inst, void *in);
-int dynType_complex_valLocAt(dyn_type *type, int index, void *inst, void **valLoc);
-int dynType_complex_entries(dyn_type *type, struct complex_type_entries_head **entries);
-
-//sequence
-int dynType_sequence_alloc(dyn_type *type, void *inst, uint32_t cap);
-int dynType_sequence_locForIndex(dyn_type *type, void *seqLoc, int index, void **valLoc);
-int dynType_sequence_increaseLengthAndReturnLastLoc(dyn_type *type, void *seqLoc, void **valLoc);
-dyn_type * dynType_sequence_itemType(dyn_type *type);
-uint32_t dynType_sequence_length(void *seqLoc);
-
-//typed pointer
-int dynType_typedPointer_getTypedType(dyn_type *type, dyn_type **typedType);
-
-//text
-int dynType_text_allocAndInit(dyn_type *type, void *textLoc, const char *value);
-
-//simple
-void dynType_simple_setValue(dyn_type *type, void *inst, void *in);
-
-#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/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
deleted file mode 100644
index e13c8ef..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
+++ /dev/null
@@ -1,335 +0,0 @@
-/**
- *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.
- */
-#include "json_rpc.h"
-#include "json_serializer.h"
-#include "dyn_type.h"
-#include "dyn_interface.h"
-#include <jansson.h>
-#include <assert.h>
-#include <stdint.h>
-#include <string.h>
-
-
-static int OK = 0;
-static int ERROR = 1;
-
-DFI_SETUP_LOG(jsonRpc);
-
-typedef void (*gen_func_type)(void);
-
-struct generic_service_layout {
- void *handle;
- gen_func_type methods[];
-};
-
-int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request, char **out) {
- int status = OK;
-
- dyn_type* returnType = NULL;
-
- LOG_DEBUG("Parsing data: %s\n", request);
- json_error_t error;
- json_t *js_request = json_loads(request, 0, &error);
- json_t *arguments = NULL;
- const char *sig;
- if (js_request) {
- if (json_unpack(js_request, "{s:s}", "m", &sig) != 0) {
- LOG_ERROR("Got json error '%s'\n", error.text);
- } else {
- arguments = json_object_get(js_request, "a");
- }
- } else {
- LOG_ERROR("Got json error '%s' for '%s'\n", error.text, request);
- return 0;
- }
-
- LOG_DEBUG("Looking for method %s\n", sig);
- struct methods_head *methods = NULL;
- dynInterface_methods(intf, &methods);
- struct method_entry *entry = NULL;
- struct method_entry *method = NULL;
- TAILQ_FOREACH(entry, methods, entries) {
- if (strcmp(sig, entry->id) == 0) {
- method = entry;
- break;
- }
- }
-
- if (method == NULL) {
- status = ERROR;
- LOG_ERROR("Cannot find method with sig '%s'", sig);
- }
-
- if (status == OK) {
- LOG_DEBUG("RSA: found method '%s'\n", entry->id);
- returnType = dynFunction_returnType(method->dynFunc);
- }
-
- void (*fp)(void) = NULL;
- void *handle = NULL;
- if (status == OK) {
- struct generic_service_layout *serv = service;
- handle = serv->handle;
- fp = serv->methods[method->index];
- }
-
- dyn_function_type *func = NULL;
- int nrOfArgs = 0;
- if (status == OK) {
- nrOfArgs = dynFunction_nrOfArguments(entry->dynFunc);
- func = entry->dynFunc;
- }
-
- void *args[nrOfArgs];
-
- json_t *value = NULL;
-
- int i;
- int index = 0;
-
- void *ptr = NULL;
- void *ptrToPtr = &ptr;
-
- for (i = 0; i < nrOfArgs; i += 1) {
- dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
- enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
- if (meta == DYN_FUNCTION_ARGUMENT_META__STD) {
- value = json_array_get(arguments, index++);
- status = jsonSerializer_deserializeJson(argType, value, &(args[i]));
- } else if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
- dynType_alloc(argType, &args[i]);
- } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) {
- args[i] = &ptrToPtr;
- } else if (meta == DYN_FUNCTION_ARGUMENT_META__HANDLE) {
- args[i] = &handle;
- }
-
- if (status != OK) {
- break;
- }
- }
- json_decref(js_request);
-
- if (status == OK) {
- if (dynType_descriptorType(returnType) != 'N') {
- //NOTE To be able to handle exception only N as returnType is supported
- LOG_ERROR("Only interface methods with a native int are supported. Found type '%c'", (char)dynType_descriptorType(returnType));
- status = ERROR;
- }
- }
-
- ffi_sarg returnVal = 1;
-
- if (status == OK) {
- dynFunction_call(func, fp, (void *) &returnVal, args);
- }
-
- int funcCallStatus = (int)returnVal;
- if (funcCallStatus != 0) {
- LOG_WARNING("Error calling remote endpoint function, got error code %i", funcCallStatus);
- }
-
- json_t *jsonResult = NULL;
- for(i = 0; i < nrOfArgs; i += 1) {
- dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
- enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
- if (meta == DYN_FUNCTION_ARGUMENT_META__STD) {
- dynType_free(argType, args[i]);
- }
- }
-
- if (funcCallStatus == 0 && status == OK) {
- for (i = 0; i < nrOfArgs; i += 1) {
- dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
- enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
- if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
- if (status == OK) {
- status = jsonSerializer_serializeJson(argType, args[i], &jsonResult);
- }
- dynType_free(argType, args[i]);
- } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) {
- if (ptr != NULL) {
- dyn_type *typedType = NULL;
- if (status == OK) {
- status = dynType_typedPointer_getTypedType(argType, &typedType);
- }
- if (dynType_descriptorType(typedType) == 't') {
- status = jsonSerializer_serializeJson(typedType, (void*) &ptr, &jsonResult);
- free(ptr);
- } else {
- dyn_type *typedTypedType = NULL;
- if (status == OK) {
- status = dynType_typedPointer_getTypedType(typedType, &typedTypedType);
- }
-
- status = jsonSerializer_serializeJson(typedTypedType, ptr, &jsonResult);
-
- if (status == OK) {
- dynType_free(typedTypedType, ptr);
- }
- }
-
- } else {
- LOG_DEBUG("Output ptr is null");
- }
- }
-
- if (status != OK) {
- break;
- }
- }
- }
-
- char *response = NULL;
- if (status == OK) {
- LOG_DEBUG("creating payload\n");
- json_t *payload = json_object();
- if (funcCallStatus == 0) {
- if (jsonResult == NULL) {
- //ignore -> no result
- } else {
- LOG_DEBUG("Setting result payload");
- json_object_set_new(payload, "r", jsonResult);
- }
- } else {
- LOG_DEBUG("Setting error payload");
- json_object_set_new(payload, "e", json_integer(funcCallStatus));
- }
- response = json_dumps(payload, JSON_DECODE_ANY);
- json_decref(payload);
- LOG_DEBUG("status ptr is %p. response is '%s'\n", status, response);
- }
-
- if (status == OK) {
- *out = response;
- } else {
- free(response);
- }
-
- return status;
-}
-
-int jsonRpc_prepareInvokeRequest(dyn_function_type *func, const char *id, void *args[], char **out) {
- int status = OK;
-
-
- LOG_DEBUG("Calling remote function '%s'\n", id);
- json_t *invoke = json_object();
- json_object_set_new(invoke, "m", json_string(id));
-
- json_t *arguments = json_array();
- json_object_set_new(invoke, "a", arguments);
-
- int i;
- int nrOfArgs = dynFunction_nrOfArguments(func);
- for (i = 0; i < nrOfArgs; i +=1) {
- dyn_type *type = dynFunction_argumentTypeForIndex(func, i);
- enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
- if (meta == DYN_FUNCTION_ARGUMENT_META__STD) {
- json_t *val = NULL;
-
- int rc = jsonSerializer_serializeJson(type, args[i], &val);
- if (rc == 0) {
- json_array_append_new(arguments, val);
- } else {
- status = ERROR;
- break;
- }
- } else {
- //skip handle / output types
- }
- }
-
- char *invokeStr = json_dumps(invoke, JSON_DECODE_ANY);
- json_decref(invoke);
-
- if (status == OK) {
- *out = invokeStr;
- }
-
- return status;
-}
-
-int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void *args[]) {
- int status = OK;
-
- json_error_t error;
- json_t *replyJson = json_loads(reply, JSON_DECODE_ANY, &error);
- if (replyJson == NULL) {
- status = ERROR;
- LOG_ERROR("Error parsing json '%s', got error '%s'", reply, error.text);
- }
-
- json_t *result = NULL;
- if (status == OK) {
- result = json_object_get(replyJson, "r"); //TODO check
- if (result == NULL) {
- status = ERROR;
- LOG_ERROR("Cannot find r entry in json reply '%s'", reply);
- }
- }
-
- if (status == OK) {
- int nrOfArgs = dynFunction_nrOfArguments(func);
- int i;
- for (i = 0; i < nrOfArgs; i += 1) {
- dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
- enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
- if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
- void *tmp = NULL;
- void **out = (void **) args[i];
-
- size_t size = 0;
-
- if (dynType_descriptorType(argType) == 't') {
- status = jsonSerializer_deserializeJson(argType, result, &tmp);
- size = strnlen(((char *) *(char**) tmp), 1024 * 1024);
- memcpy(*out, *(void**) tmp, size);
- } else {
- dynType_typedPointer_getTypedType(argType, &argType);
- status = jsonSerializer_deserializeJson(argType, result, &tmp);
- size = dynType_size(argType);
- memcpy(*out, tmp, size);
- }
-
- dynType_free(argType, tmp);
- } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) {
- dyn_type *subType = NULL;
-
- dynType_typedPointer_getTypedType(argType, &subType);
-
- if (dynType_descriptorType(subType) == 't') {
- void ***out = (void ***) args[i];
- status = jsonSerializer_deserializeJson(subType, result, *out);
- } else {
- dyn_type *subSubType = NULL;
- dynType_typedPointer_getTypedType(subType, &subSubType);
- void ***out = (void ***) args[i];
- status = jsonSerializer_deserializeJson(subSubType, result, *out);
- }
- } else {
- //skip
- }
- }
- }
-
- json_decref(replyJson);
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.h b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.h
deleted file mode 100644
index 1cc1464..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- *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.
- */
-#ifndef __JSON_RPC_H_
-#define __JSON_RPC_H_
-
-#include <jansson.h>
-#include "dfi_log_util.h"
-#include "dyn_type.h"
-#include "dyn_function.h"
-#include "dyn_interface.h"
-
-//logging
-DFI_SETUP_LOG_HEADER(jsonRpc);
-
-int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request, char **out);
-
-
-int jsonRpc_prepareInvokeRequest(dyn_function_type *func, const char *id, void *args[], char **out);
-int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void *args[]);
-
-#endif
[4/6] celix git commit: CELIX-309: Move dfi to top-level subdir
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/json_serializer_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/json_serializer_tests.cpp b/dfi/private/test/json_serializer_tests.cpp
new file mode 100644
index 0000000..70b0147
--- /dev/null
+++ b/dfi/private/test/json_serializer_tests.cpp
@@ -0,0 +1,508 @@
+/**
+ *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.
+ */
+#include <CppUTest/TestHarness.h>
+#include "CppUTest/CommandLineTestRunner.h"
+
+extern "C" {
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include <ffi.h>
+
+#include "dyn_common.h"
+#include "dyn_type.h"
+#include "json_serializer.h"
+
+static void stdLog(void *handle, int level, const char *file, int line, const char *msg, ...) {
+ va_list ap;
+ const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
+ fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
+ va_start(ap, msg);
+ vfprintf(stderr, msg, ap);
+ fprintf(stderr, "\n");
+}
+
+/*********** example 1 ************************/
+/** struct type ******************************/
+const char *example1_descriptor = "{DJISF a b c d e}";
+
+const char *example1_input = "{ \
+ \"a\" : 1.0, \
+ \"b\" : 22, \
+ \"c\" : 32, \
+ \"d\" : 42, \
+ \"e\" : 4.4 \
+}";
+
+struct example1 {
+ double a; //0
+ int64_t b; //1
+ int32_t c; //2
+ int16_t d; //3
+ float e; //4
+};
+
+static void check_example1(void *data) {
+ struct example1 *ex = (struct example1 *)data;
+ CHECK_EQUAL(1.0, ex->a);
+ LONGS_EQUAL(22, ex->b);
+ LONGS_EQUAL(32, ex->c);
+ LONGS_EQUAL(42, ex->d);
+ CHECK_EQUAL(4.4f, ex->e);
+}
+
+/*********** example 2 ************************/
+const char *example2_descriptor = "{BJJDFD byte long1 long2 double1 float1 double2}";
+
+const char *example2_input = "{ \
+ \"byte\" : 42, \
+ \"long1\" : 232, \
+ \"long2\" : 242, \
+ \"double1\" : 4.2, \
+ \"float1\" : 3.2, \
+ \"double2\" : 4.4 \
+}";
+
+struct example2 {
+ char byte; //0
+ int64_t long1; //1
+ int64_t long2; //2
+ double double1; //3
+ float float1; //4
+ double double2; //5
+};
+
+static void check_example2(void *data) {
+ struct example2 *ex = (struct example2 *)data;
+ CHECK_EQUAL(42, ex->byte);
+ LONGS_EQUAL(232, ex->long1);
+ LONGS_EQUAL(242, ex->long2);
+ CHECK_EQUAL(4.2, ex->double1);
+ CHECK_EQUAL(3.2f, ex->float1);
+ CHECK_EQUAL(4.4, ex->double2);
+}
+
+
+/*********** example 3 ************************/
+/** sequence with a simple type **************/
+const char *example3_descriptor = "{[I numbers}";
+
+const char *example3_input = "{ \
+ \"numbers\" : [22,32,42] \
+}";
+
+struct example3 {
+ struct {
+ uint32_t cap;
+ uint32_t len;
+ int32_t *buf;
+ } numbers;
+};
+
+static void check_example3(void *data) {
+ struct example3 *ex = (struct example3 *)data;
+ CHECK_EQUAL(3, ex->numbers.len);
+ CHECK_EQUAL(22, ex->numbers.buf[0]);
+ CHECK_EQUAL(32, ex->numbers.buf[1]);
+ CHECK_EQUAL(42, ex->numbers.buf[2]);
+}
+
+/*********** example 4 ************************/
+/** structs within a struct (by reference)*******/
+const char *example4_descriptor = "{{IDD index val1 val2}{IDD index val1 val2} left right}";
+
+static const char *example4_input = "{ \
+ \"left\" : {\"index\":1, \"val1\":1.0, \"val2\":2.0 }, \
+ \"right\" : {\"index\":2, \"val1\":5.0, \"val2\":4.0 } \
+}";
+
+struct ex4_leaf {
+ int32_t index;
+ double val1;
+ double val2;
+};
+
+struct example4 {
+ struct ex4_leaf left;
+ struct ex4_leaf right;
+};
+
+static void check_example4(void *data) {
+ struct example4 *ex = (struct example4 *)data;
+ CHECK_EQUAL(1, ex->left.index);
+ CHECK_EQUAL(1.0, ex->left.val1);
+ CHECK_EQUAL(2.0, ex->left.val2);
+ CHECK_EQUAL(2, ex->right.index);
+ CHECK_EQUAL(5.0, ex->right.val1);
+ CHECK_EQUAL(4.0, ex->right.val2);
+}
+
+
+/*********** example 5 ************************/
+/** structs within a struct (by reference)*******/
+const char *example5_descriptor = "Tleaf={ts name age};Tnode={Lnode;Lnode;Lleaf; left right value};{Lnode; head}";
+
+static const char *example5_input = "{ \
+ \"head\" : {\
+ \"left\" : {\
+ \"value\" : {\
+ \"name\" : \"John\",\
+ \"age\" : 44 \
+ }\
+ },\
+ \"right\" : {\
+ \"value\" : {\
+ \"name\" : \"Peter\", \
+ \"age\" : 55 \
+ }\
+ }\
+ }\
+}";
+
+struct leaf {
+ const char *name;
+ uint16_t age;
+};
+
+struct node {
+ struct node *left;
+ struct node *right;
+ struct leaf *value;
+};
+
+struct example5 {
+ struct node *head;
+};
+
+static void check_example5(void *data) {
+ struct example5 *ex = (struct example5 *)data;
+ CHECK_TRUE(ex->head != NULL);
+
+ CHECK(ex->head->left != NULL);
+ CHECK(ex->head->left->value != NULL);
+ STRCMP_EQUAL("John", ex->head->left->value->name);
+ CHECK_EQUAL(44, ex->head->left->value->age);
+ CHECK(ex->head->left->left == NULL);
+ CHECK(ex->head->left->right == NULL);
+
+ CHECK(ex->head->right != NULL);
+ CHECK(ex->head->right->value != NULL);
+ STRCMP_EQUAL("Peter", ex->head->right->value->name);
+ CHECK_EQUAL(55, ex->head->right->value->age);
+ CHECK(ex->head->right->left == NULL);
+ 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);
+}
+
+
+/*********** example 7 ************************/
+const char *example7_descriptor = "{t a}";
+
+const char *example7_input = "{ \
+ \"a\" : \"apache celix\" \
+}";
+
+struct example7 {
+ char* a; //0
+};
+
+static void check_example7(void *data) {
+ struct example7 *ex = (struct example7 *)data;
+ STRCMP_EQUAL("apache celix", ex->a);
+}
+
+static void parseTests(void) {
+ dyn_type *type;
+ void *inst;
+ int rc;
+
+ type = NULL;
+ inst = NULL;
+ rc = dynType_parseWithStr(example1_descriptor, NULL, NULL, &type);
+ CHECK_EQUAL(0, rc);
+ rc = jsonSerializer_deserialize(type, example1_input, &inst);
+ CHECK_EQUAL(0, rc);
+ check_example1(inst);
+ dynType_free(type, inst);
+ dynType_destroy(type);
+
+ type = NULL;
+ inst = NULL;
+ rc = dynType_parseWithStr(example2_descriptor, NULL, NULL, &type);
+ CHECK_EQUAL(0, rc);
+ rc = jsonSerializer_deserialize(type, example2_input, &inst);
+ CHECK_EQUAL(0, rc);
+ check_example2(inst);
+ dynType_free(type, inst);
+ dynType_destroy(type);
+
+ type = NULL;
+ inst = NULL;
+ rc = dynType_parseWithStr(example3_descriptor, NULL, NULL, &type);
+ CHECK_EQUAL(0, rc);
+ rc = jsonSerializer_deserialize(type, example3_input, &inst);
+ CHECK_EQUAL(0, rc);
+ check_example3(inst);
+ dynType_free(type, inst);
+ dynType_destroy(type);
+
+ type = NULL;
+ inst = NULL;
+ rc = dynType_parseWithStr(example4_descriptor, NULL, NULL, &type);
+ CHECK_EQUAL(0, rc);
+ rc = jsonSerializer_deserialize(type, example4_input, &inst);
+ CHECK_EQUAL(0, rc);
+ check_example4(inst);
+ dynType_free(type, inst);
+ dynType_destroy(type);
+
+ type = NULL;
+ inst = NULL;
+ rc = dynType_parseWithStr(example5_descriptor, NULL, NULL, &type);
+ CHECK_EQUAL(0, rc);
+ rc = jsonSerializer_deserialize(type, example5_input, &inst);
+ CHECK_EQUAL(0, rc);
+ 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);
+
+
+ type = NULL;
+ inst = NULL;
+ rc = dynType_parseWithStr(example7_descriptor, NULL, NULL, &type);
+ CHECK_EQUAL(0, rc);
+ rc = jsonSerializer_deserialize(type, example7_input, &inst);
+ CHECK_EQUAL(0, rc);
+ check_example7(inst);
+ dynType_free(type, inst);
+ dynType_destroy(type);
+}
+
+const char *write_example1_descriptor = "{BSIJsijFDN a b c d e f g h i j}";
+
+struct write_example1 {
+ char a;
+ int16_t b;
+ int32_t c;
+ int64_t d;
+ uint16_t e;
+ uint32_t f;
+ uint64_t g;
+ float h;
+ double i;
+ int j;
+};
+
+void writeTest1(void) {
+ struct write_example1 ex1;
+ ex1.a=1;
+ ex1.b=2;
+ ex1.c=3;
+ ex1.d=4;
+ ex1.e=5;
+ ex1.f=6;
+ ex1.g=7;
+ ex1.h=8.8f;
+ ex1.i=9.9;
+ ex1.j=10;
+
+ dyn_type *type = NULL;
+ char *result = NULL;
+ int rc = dynType_parseWithStr(write_example1_descriptor, "ex1", NULL, &type);
+ CHECK_EQUAL(0, rc);
+ rc = jsonSerializer_serialize(type, &ex1, &result);
+ CHECK_EQUAL(0, rc);
+ STRCMP_CONTAINS("\"a\":1", result);
+ STRCMP_CONTAINS("\"b\":2", result);
+ STRCMP_CONTAINS("\"c\":3", result);
+ STRCMP_CONTAINS("\"d\":4", result);
+ STRCMP_CONTAINS("\"e\":5", result);
+ STRCMP_CONTAINS("\"f\":6", result);
+ STRCMP_CONTAINS("\"g\":7", result);
+ STRCMP_CONTAINS("\"h\":8.8", result);
+ STRCMP_CONTAINS("\"i\":9.9", result);
+ STRCMP_CONTAINS("\"j\":10", result);
+ //printf("example 1 result: '%s'\n", result);
+ dynType_destroy(type);
+ free(result);
+}
+
+const char *write_example2_descriptor = "{*{JJ a b}{SS c d} sub1 sub2}";
+
+struct write_example2_sub {
+ int64_t a;
+ int64_t b;
+};
+
+struct write_example2 {
+ struct write_example2_sub *sub1;
+ struct {
+ int16_t c;
+ int16_t d;
+ } sub2;
+};
+
+void writeTest2(void) {
+ struct write_example2_sub sub1;
+ sub1.a = 1;
+ sub1.b = 2;
+
+ struct write_example2 ex;
+ ex.sub1=&sub1;
+ ex.sub2.c = 3;
+ ex.sub2.d = 4;
+
+ dyn_type *type = NULL;
+ char *result = NULL;
+ int rc = dynType_parseWithStr(write_example2_descriptor, "ex2", NULL, &type);
+ CHECK_EQUAL(0, rc);
+ rc = jsonSerializer_serialize(type, &ex, &result);
+ CHECK_EQUAL(0, rc);
+ STRCMP_CONTAINS("\"a\":1", result);
+ STRCMP_CONTAINS("\"b\":2", result);
+ STRCMP_CONTAINS("\"c\":3", result);
+ STRCMP_CONTAINS("\"d\":4", result);
+ //printf("example 2 result: '%s'\n", result);
+ dynType_destroy(type);
+ free(result);
+}
+
+const char *write_example3_descriptor = "Tperson={ti name age};[Lperson;";
+
+struct write_example3_person {
+ const char *name;
+ uint32_t age;
+};
+
+struct write_example3 {
+ uint32_t cap;
+ uint32_t len;
+ struct write_example3_person **buf;
+};
+
+void writeTest3(void) {
+ struct write_example3_person p1;
+ p1.name = "John";
+ p1.age = 33;
+
+ struct write_example3_person p2;
+ p2.name = "Peter";
+ p2.age = 44;
+
+ struct write_example3_person p3;
+ p3.name = "Carol";
+ p3.age = 55;
+
+ struct write_example3_person p4;
+ p4.name = "Elton";
+ p4.age = 66;
+
+ struct write_example3 seq;
+ seq.buf = (struct write_example3_person **) calloc(4, sizeof(void *));
+ seq.len = seq.cap = 4;
+ seq.buf[0] = &p1;
+ seq.buf[1] = &p2;
+ seq.buf[2] = &p3;
+ seq.buf[3] = &p4;
+
+ dyn_type *type = NULL;
+ char *result = NULL;
+ int rc = dynType_parseWithStr(write_example3_descriptor, "ex3", NULL, &type);
+ CHECK_EQUAL(0, rc);
+ rc = jsonSerializer_serialize(type, &seq, &result);
+ CHECK_EQUAL(0, rc);
+ STRCMP_CONTAINS("\"age\":33", result);
+ STRCMP_CONTAINS("\"age\":44", result);
+ STRCMP_CONTAINS("\"age\":55", result);
+ STRCMP_CONTAINS("\"age\":66", result);
+ //printf("example 3 result: '%s'\n", result);
+ free(seq.buf);
+ dynType_destroy(type);
+ free(result);
+}
+
+
+
+}
+
+TEST_GROUP(JsonSerializerTests) {
+ void setup() {
+ int lvl = 1;
+ dynCommon_logSetup(stdLog, NULL, lvl);
+ dynType_logSetup(stdLog, NULL,lvl);
+ jsonSerializer_logSetup(stdLog, NULL, lvl);
+ }
+};
+
+TEST(JsonSerializerTests, ParseTests) {
+ //TODO split up
+ parseTests();
+}
+
+TEST(JsonSerializerTests, WriteTest1) {
+ writeTest1();
+}
+
+TEST(JsonSerializerTests, WriteTest2) {
+ writeTest2();
+}
+
+TEST(JsonSerializerTests, WriteTest3) {
+ writeTest3();
+}
+
+
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/run_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/run_tests.cpp b/dfi/private/test/run_tests.cpp
new file mode 100644
index 0000000..786f4bf
--- /dev/null
+++ b/dfi/private/test/run_tests.cpp
@@ -0,0 +1,24 @@
+/**
+ *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.
+ */
+#include <CppUTest/TestHarness.h>
+#include "CppUTest/CommandLineTestRunner.h"
+
+int main(int argc, char** argv) {
+ return RUN_ALL_TESTS(argc, argv);
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/schemas/complex.avdl
----------------------------------------------------------------------
diff --git a/dfi/private/test/schemas/complex.avdl b/dfi/private/test/schemas/complex.avdl
new file mode 100644
index 0000000..eff1fd8
--- /dev/null
+++ b/dfi/private/test/schemas/complex.avdl
@@ -0,0 +1,30 @@
+/**
+ *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.
+ */
+
+protocol Complex {
+
+ record StatResult {
+ double sum;
+ double min;
+ double max;
+ array<double> input;
+ }
+
+ StatResult stats(array<double> input);
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/schemas/complex.avpr
----------------------------------------------------------------------
diff --git a/dfi/private/test/schemas/complex.avpr b/dfi/private/test/schemas/complex.avpr
new file mode 100644
index 0000000..ca39b56
--- /dev/null
+++ b/dfi/private/test/schemas/complex.avpr
@@ -0,0 +1,55 @@
+/**
+ *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.
+ */
+
+{
+ "protocol" : "Complex",
+ "namespace" : null,
+ "types" : [ {
+ "type" : "record",
+ "name" : "StatResult",
+ "fields" : [ {
+ "name" : "sum",
+ "type" : "double"
+ }, {
+ "name" : "min",
+ "type" : "double"
+ }, {
+ "name" : "max",
+ "type" : "double"
+ }, {
+ "name" : "input",
+ "type" : {
+ "type" : "array",
+ "items" : "double"
+ }
+ } ]
+ } ],
+ "messages" : {
+ "stats" : {
+ "request" : [ {
+ "name" : "input",
+ "type" : {
+ "type" : "array",
+ "items" : "double"
+ }
+ } ],
+ "response" : "StatResult"
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/schemas/invalid1.avpr
----------------------------------------------------------------------
diff --git a/dfi/private/test/schemas/invalid1.avpr b/dfi/private/test/schemas/invalid1.avpr
new file mode 100644
index 0000000..bbf77ee
--- /dev/null
+++ b/dfi/private/test/schemas/invalid1.avpr
@@ -0,0 +1,47 @@
+/**
+ *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.
+ */
+{
+ "protocol" : "Complex",
+ "namespace" : null,
+ "types" : [ {
+ "type" : "record",
+ "name" : "StatResult",
+ "fields" : [ {
+ "name" : "sum",
+ "type" : "double"
+ }, {
+ "name" : "min",
+ "type" : "double"
+ }, {
+ "name" : "max",
+ "type" : "double"
+ }, {
+ "name" : "input",
+ "type" : {
+ "type" : "array",
+ "items" : "double"
+ }
+ } ]
+ } ],
+ "messages" : {
+ "stats" : {
+ "response" : "StatResult"
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/schemas/invalid2.avpr
----------------------------------------------------------------------
diff --git a/dfi/private/test/schemas/invalid2.avpr b/dfi/private/test/schemas/invalid2.avpr
new file mode 100644
index 0000000..9eb9209
--- /dev/null
+++ b/dfi/private/test/schemas/invalid2.avpr
@@ -0,0 +1,49 @@
+/**
+ *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.
+ */
+ {
+ "protocol" : "Simple",
+ "types" : [ ],
+ "messages" : {
+ "sum" : {
+ "request" : [ {
+ "name" : "a"
+ }, {
+ "name" : "b",
+ "type" : "double"
+ } ],
+ "response" : "double"
+ },
+ "sub" : {
+ "request" : [ {
+ "name" : "a",
+ "type" : "double"
+ }, {
+ "name" : "b",
+ "type" : "double"
+ } ],
+ "response" : "double"
+ },
+ "sqrt" : {
+ "request" : [ {
+ "name" : "a"
+ } ],
+ "response" : "double"
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/schemas/simple.avdl
----------------------------------------------------------------------
diff --git a/dfi/private/test/schemas/simple.avdl b/dfi/private/test/schemas/simple.avdl
new file mode 100644
index 0000000..a03e352
--- /dev/null
+++ b/dfi/private/test/schemas/simple.avdl
@@ -0,0 +1,24 @@
+/**
+ *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.
+ */
+ @namespace("org.apache.avro.test")
+protocol Simple {
+ double sum(double a, double b);
+ double sub(double a, double b);
+ double sqrt(double a);
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/schemas/simple.avpr
----------------------------------------------------------------------
diff --git a/dfi/private/test/schemas/simple.avpr b/dfi/private/test/schemas/simple.avpr
new file mode 100644
index 0000000..4910346
--- /dev/null
+++ b/dfi/private/test/schemas/simple.avpr
@@ -0,0 +1,51 @@
+/**
+ *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.
+ */
+ {
+ "protocol" : "Simple",
+ "types" : [ ],
+ "messages" : {
+ "sum" : {
+ "request" : [ {
+ "name" : "a",
+ "type" : "double"
+ }, {
+ "name" : "b",
+ "type" : "double"
+ } ],
+ "response" : "double"
+ },
+ "sub" : {
+ "request" : [ {
+ "name" : "a",
+ "type" : "double"
+ }, {
+ "name" : "b",
+ "type" : "double"
+ } ],
+ "response" : "double"
+ },
+ "sqrt" : {
+ "request" : [ {
+ "name" : "a",
+ "type" : "double"
+ } ],
+ "response" : "double"
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/schemas/simple_min.avpr
----------------------------------------------------------------------
diff --git a/dfi/private/test/schemas/simple_min.avpr b/dfi/private/test/schemas/simple_min.avpr
new file mode 100644
index 0000000..f5c6673
--- /dev/null
+++ b/dfi/private/test/schemas/simple_min.avpr
@@ -0,0 +1,19 @@
+/**
+ *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.
+ */
+ {"protocol":"Simple","types":[],"messages":{"sum":{"request":[{"name":"a","type":"double"},{"name":"b","type":"double"}],"response":"double"},"sub":{"request":[{"name":"a","type":"double"},{"name":"b","type":"double"}],"response":"double"},"sqrt":{"request":[{"name":"a","type":"double"}],"response":"double"}}}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/public/include/dfi_log_util.h
----------------------------------------------------------------------
diff --git a/dfi/public/include/dfi_log_util.h b/dfi/public/include/dfi_log_util.h
new file mode 100644
index 0000000..2bcd8fa
--- /dev/null
+++ b/dfi/public/include/dfi_log_util.h
@@ -0,0 +1,63 @@
+/**
+ *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.
+ */
+#ifndef _DFI_LOG_UTIL_H_
+#define _DFI_LOG_UTIL_H_
+
+typedef void (*logf_ft)(void *handle, int level, const char *file, int line, const char *format, ...);
+
+#define DFI_SETUP_LOG_HEADER(cmp) \
+ void cmp ## _logSetup(logf_ft logf, void *handle, int currentLogLevel);
+
+#define DFI_SETUP_LOG(cmp) \
+ static logf_ft g_logf = NULL; \
+ static void *g_logHandle = NULL; \
+ static int g_currentLogLevel = 1; \
+ \
+ void cmp ## _logSetup(logf_ft logf, void *handle, int currentLogLevel) { \
+ g_currentLogLevel = currentLogLevel; \
+ g_logHandle = handle; \
+ g_logf = logf; \
+ }
+
+#define LOG_LVL_ERROR 1
+#define LOG_LVL_WARNING 2
+#define LOG_LVL_INFO 3
+#define LOG_LVL_DEBUG 4
+
+#define LOG_ERROR(msg, ...) \
+ if (g_logf != NULL && g_currentLogLevel >= LOG_LVL_ERROR) { \
+ g_logf(g_logHandle, LOG_LVL_ERROR, __FILE__, __LINE__, (msg), ##__VA_ARGS__); \
+ }
+
+#define LOG_WARNING(msg, ...) \
+ if (g_logf != NULL && g_currentLogLevel >= LOG_LVL_WARNING) { \
+ g_logf(g_logHandle, LOG_LVL_WARNING, __FILE__, __LINE__, (msg), ##__VA_ARGS__); \
+ }
+
+#define LOG_INFO(msg, ...) \
+ if (g_logf != NULL && g_currentLogLevel >= LOG_LVL_INFO) { \
+ g_logf(g_logHandle, LOG_LVL_INFO, __FILE__, __LINE__, (msg), ##__VA_ARGS__); \
+ }
+
+#define LOG_DEBUG(msg, ...) \
+ if (g_logf != NULL && g_currentLogLevel >= LOG_LVL_DEBUG) { \
+ g_logf(g_logHandle, LOG_LVL_DEBUG, __FILE__, __LINE__, (msg), ##__VA_ARGS__); \
+ }
+
+#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/public/include/dyn_common.h
----------------------------------------------------------------------
diff --git a/dfi/public/include/dyn_common.h b/dfi/public/include/dyn_common.h
new file mode 100644
index 0000000..6ec236f
--- /dev/null
+++ b/dfi/public/include/dyn_common.h
@@ -0,0 +1,47 @@
+/**
+ *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.
+ */
+#ifndef _DYN_COMMON_H_
+#define _DYN_COMMON_H_
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/queue.h>
+
+#include "dfi_log_util.h"
+
+//logging
+DFI_SETUP_LOG_HEADER(dynCommon);
+
+TAILQ_HEAD(namvals_head, namval_entry);
+
+struct namval_entry {
+ char *name;
+ char *value;
+ TAILQ_ENTRY(namval_entry) entries;
+};
+
+int dynCommon_parseName(FILE *stream, char **result);
+int dynCommon_parseNameAlsoAccept(FILE *stream, const char *acceptedChars, char **result);
+int dynCommon_parseNameValue(FILE *stream, char **name, char **value);
+int dynCommon_eatChar(FILE *stream, int c);
+
+void dynCommon_clearNamValHead(struct namvals_head *head);
+
+#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/public/include/dyn_function.h
----------------------------------------------------------------------
diff --git a/dfi/public/include/dyn_function.h b/dfi/public/include/dyn_function.h
new file mode 100644
index 0000000..792691e
--- /dev/null
+++ b/dfi/public/include/dyn_function.h
@@ -0,0 +1,61 @@
+/**
+ *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.
+ */
+#ifndef __DYN_FUNCTION_H_
+#define __DYN_FUNCTION_H_
+
+#include <ffi.h>
+#include "dyn_type.h"
+#include "dfi_log_util.h"
+
+/**
+ * Uses the following schema
+ * (Name)([Type]*)Type
+ *
+ * Dyn fynction argument meta (am) as meta info, with the following possible values
+ * am=handle #void pointer for the handle
+ * am=pre #output pointer with memory preallocated
+ * am=out #output pointer
+ */
+
+typedef struct _dyn_function_type dyn_function_type;
+
+DFI_SETUP_LOG_HEADER(dynFunction);
+
+enum dyn_function_argument_meta {
+ DYN_FUNCTION_ARGUMENT_META__STD = 0,
+ DYN_FUNCTION_ARGUMENT_META__HANDLE = 1,
+ DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT = 2,
+ DYN_FUNCTION_ARGUMENT_META__OUTPUT = 3
+};
+
+int dynFunction_parse(FILE *descriptorStream, struct types_head *refTypes, dyn_function_type **dynFunc);
+int dynFunction_parseWithStr(const char *descriptor, struct types_head *refTypes, dyn_function_type **dynFunc);
+
+int dynFunction_nrOfArguments(dyn_function_type *dynFunc);
+dyn_type *dynFunction_argumentTypeForIndex(dyn_function_type *dynFunc, int argumentNr);
+enum dyn_function_argument_meta dynFunction_argumentMetaForIndex(dyn_function_type *dynFunc, int argumentNr);
+dyn_type * dynFunction_returnType(dyn_function_type *dynFunction);
+
+void dynFunction_destroy(dyn_function_type *dynFunc);
+int dynFunction_call(dyn_function_type *dynFunc, void(*fn)(void), void *returnValue, void **argValues);
+
+int dynFunction_createClosure(dyn_function_type *func, void (*bind)(void *, void **, void*), void *userData, void(**fn)(void));
+int dynFunction_getFnPointer(dyn_function_type *func, void (**fn)(void));
+
+#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/public/include/dyn_interface.h
----------------------------------------------------------------------
diff --git a/dfi/public/include/dyn_interface.h b/dfi/public/include/dyn_interface.h
new file mode 100644
index 0000000..51a2f41
--- /dev/null
+++ b/dfi/public/include/dyn_interface.h
@@ -0,0 +1,63 @@
+/**
+ *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.
+ */
+#ifndef __DYN_INTERFACE_H_
+#define __DYN_INTERFACE_H_
+
+#include "dyn_common.h"
+#include "dyn_type.h"
+#include "dyn_function.h"
+#include "dfi_log_util.h"
+
+DFI_SETUP_LOG_HEADER(dynInterface);
+
+/* Description string
+ *
+ * Descriptor (interface) = HeaderSection AnnotationSection TypesSection MethodsSection
+ *
+ * HeaderSection=
+ * ':header\n' [NameValue]*
+ * ':annotations\n' [NameValue]*
+ * ':types\n' [TypeIdValue]*
+ * ':methods\n' [MethodIdValue]
+ *
+ */
+typedef struct _dyn_interface_type dyn_interface_type;
+
+TAILQ_HEAD(methods_head, method_entry);
+struct method_entry {
+ int index;
+ char *id;
+ char *name;
+ dyn_function_type *dynFunc;
+
+ TAILQ_ENTRY(method_entry) entries;
+};
+
+int dynInterface_parse(FILE *descriptor, dyn_interface_type **out);
+void dynInterface_destroy(dyn_interface_type *intf);
+
+int dynInterface_getName(dyn_interface_type *intf, char **name);
+int dynInterface_getVersion(dyn_interface_type *intf, char **version);
+int dynInterface_getHeaderEntry(dyn_interface_type *intf, const char *name, char **value);
+int dynInterface_getAnnotationEntry(dyn_interface_type *intf, const char *name, char **value);
+int dynInterface_methods(dyn_interface_type *intf, struct methods_head **list);
+int dynInterface_nrOfMethods(dyn_interface_type *intf);
+
+
+#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/public/include/dyn_message.h
----------------------------------------------------------------------
diff --git a/dfi/public/include/dyn_message.h b/dfi/public/include/dyn_message.h
new file mode 100644
index 0000000..b2f5f0e
--- /dev/null
+++ b/dfi/public/include/dyn_message.h
@@ -0,0 +1,53 @@
+/**
+ *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.
+ */
+#ifndef __DYN_MESSAGE_H_
+#define __DYN_MESSAGE_H_
+
+#include "dyn_common.h"
+#include "dyn_type.h"
+#include "dfi_log_util.h"
+
+DFI_SETUP_LOG_HEADER(dynMessage);
+
+/* Description string
+ *
+ * Descriptor (message) = HeaderSection AnnotationSection TypesSection MessageSection
+ *
+ * HeaderSection=
+ * ':header\n' [NameValue]*
+ * ':annotations\n' [NameValue]*
+ * ':types\n' [TypeIdValue]*
+ * ':message\n' [MessageIdValue]
+ *
+ */
+typedef struct _dyn_message_type dyn_message_type;
+
+
+int dynMessage_parse(FILE *descriptor, dyn_message_type **out);
+void dynMessage_destroy(dyn_message_type *msg);
+
+int dynMessage_getName(dyn_message_type *msg, char **name);
+int dynMessage_getVersion(dyn_message_type *msg, char **version);
+int dynMessage_getHeaderEntry(dyn_message_type *msg, const char *name, char **value);
+int dynMessage_getAnnotationEntry(dyn_message_type *msg, const char *name, char **value);
+int dynMessage_getMessageType(dyn_message_type *msg, dyn_type **type);
+
+
+
+#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/public/include/dyn_type.h
----------------------------------------------------------------------
diff --git a/dfi/public/include/dyn_type.h b/dfi/public/include/dyn_type.h
new file mode 100644
index 0000000..b2b84ef
--- /dev/null
+++ b/dfi/public/include/dyn_type.h
@@ -0,0 +1,157 @@
+/**
+ *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.
+ */
+
+#ifndef _DYN_TYPE_H_
+#define _DYN_TYPE_H_
+
+#include <stdio.h>
+#include <sys/queue.h>
+#include <stdbool.h>
+
+#include <ffi.h>
+#include <stdint.h>
+
+#include "dfi_log_util.h"
+
+#if defined(BSD) || defined(__APPLE__)
+#include "memstream/open_memstream.h"
+#include "memstream/fmemopen.h"
+#endif
+
+/* Description string
+ *
+ * Type = [TypeDef]* (MetaInfo)* (SimpleType | ComplexType | SequenceType | TypedPointer | PointerReference ) [TypeDef]*
+ * Name = alpha[(alpha|numeric)*]
+ * SPACE = ' '
+ *
+ * SimplesTypes (based on java bytecode method signatures)
+ * //Java based:
+ * B char
+ * C (not supported)
+ * D double
+ * F float
+ * I int32_t
+ * J int64_t
+ * S int16_t
+ * V void
+ * Z boolean
+ * //Extended
+ * b unsigned char
+ * i uint32_t
+ * j uint62_t
+ * s uint64_t
+ * P untyped pointer (void *)
+ * t char* string
+ * N native int
+ *
+ * ComplexTypes (Struct)
+ * {[Type]+ [(Name)(SPACE)]+}
+ *
+ * ReferenceByValue
+ * l(name);
+ *
+ * PointerReference -> note shortcut for *l(name);
+ * L(Name);
+ *
+ * TypeDef
+ * T(Name)=Type;
+ *
+ * SequenceType
+ * [(Type)
+ *
+ * TypedPointer
+ * *(Type)
+ *
+ * MetaInfo TODO
+ * #Name=Value;
+ *
+ *
+ *
+ * examples
+ * "{DDII a b c d}" -> struct { double a; double b; int c; int d; };
+ * "{DD{FF c1 c2} a b c}" -> struct { double a; double b; struct c { float c1; float c2; }; };
+ *
+ *
+ */
+
+#define DYN_TYPE_INVALID 0
+#define DYN_TYPE_SIMPLE 1
+#define DYN_TYPE_COMPLEX 2
+#define DYN_TYPE_SEQUENCE 3
+#define DYN_TYPE_TYPED_POINTER 4
+#define DYN_TYPE_TEXT 5
+#define DYN_TYPE_REF 6
+
+typedef struct _dyn_type dyn_type;
+
+TAILQ_HEAD(types_head, type_entry);
+struct type_entry {
+ dyn_type *type;
+ TAILQ_ENTRY(type_entry) entries;
+};
+
+TAILQ_HEAD(complex_type_entries_head, complex_type_entry);
+struct complex_type_entry {
+ dyn_type *type;
+ char *name;
+ TAILQ_ENTRY(complex_type_entry) entries;
+};
+
+//logging
+DFI_SETUP_LOG_HEADER(dynType);
+
+//generic
+int dynType_parse(FILE *descriptorStream, const char *name, struct types_head *refTypes, dyn_type **type);
+int dynType_parseWithStr(const char *descriptor, const char *name, struct types_head *refTypes, dyn_type **type);
+void dynType_destroy(dyn_type *type);
+
+int dynType_alloc(dyn_type *type, void **bufLoc);
+void dynType_free(dyn_type *type, void *loc);
+
+void dynType_print(dyn_type *type, FILE *stream);
+size_t dynType_size(dyn_type *type);
+int dynType_type(dyn_type *type);
+int dynType_descriptorType(dyn_type *type);
+ffi_type * dynType_ffiType(dyn_type *type);
+const char * dynType_getMetaInfo(dyn_type *type, const char *name);
+
+//complexType
+int dynType_complex_indexForName(dyn_type *type, const char *name);
+int dynType_complex_dynTypeAt(dyn_type *type, int index, dyn_type **subType);
+int dynType_complex_setValueAt(dyn_type *type, int index, void *inst, void *in);
+int dynType_complex_valLocAt(dyn_type *type, int index, void *inst, void **valLoc);
+int dynType_complex_entries(dyn_type *type, struct complex_type_entries_head **entries);
+
+//sequence
+int dynType_sequence_alloc(dyn_type *type, void *inst, uint32_t cap);
+int dynType_sequence_locForIndex(dyn_type *type, void *seqLoc, int index, void **valLoc);
+int dynType_sequence_increaseLengthAndReturnLastLoc(dyn_type *type, void *seqLoc, void **valLoc);
+dyn_type * dynType_sequence_itemType(dyn_type *type);
+uint32_t dynType_sequence_length(void *seqLoc);
+
+//typed pointer
+int dynType_typedPointer_getTypedType(dyn_type *type, dyn_type **typedType);
+
+//text
+int dynType_text_allocAndInit(dyn_type *type, void *textLoc, const char *value);
+
+//simple
+void dynType_simple_setValue(dyn_type *type, void *inst, void *in);
+
+#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/public/include/json_rpc.h
----------------------------------------------------------------------
diff --git a/dfi/public/include/json_rpc.h b/dfi/public/include/json_rpc.h
new file mode 100644
index 0000000..1cc1464
--- /dev/null
+++ b/dfi/public/include/json_rpc.h
@@ -0,0 +1,37 @@
+/**
+ *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.
+ */
+#ifndef __JSON_RPC_H_
+#define __JSON_RPC_H_
+
+#include <jansson.h>
+#include "dfi_log_util.h"
+#include "dyn_type.h"
+#include "dyn_function.h"
+#include "dyn_interface.h"
+
+//logging
+DFI_SETUP_LOG_HEADER(jsonRpc);
+
+int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request, char **out);
+
+
+int jsonRpc_prepareInvokeRequest(dyn_function_type *func, const char *id, void *args[], char **out);
+int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void *args[]);
+
+#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/public/include/json_serializer.h
----------------------------------------------------------------------
diff --git a/dfi/public/include/json_serializer.h b/dfi/public/include/json_serializer.h
new file mode 100644
index 0000000..c785b01
--- /dev/null
+++ b/dfi/public/include/json_serializer.h
@@ -0,0 +1,37 @@
+/**
+ *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.
+ */
+#ifndef __JSON_SERIALIZER_H_
+#define __JSON_SERIALIZER_H_
+
+#include <jansson.h>
+#include "dfi_log_util.h"
+#include "dyn_type.h"
+#include "dyn_function.h"
+#include "dyn_interface.h"
+
+//logging
+DFI_SETUP_LOG_HEADER(jsonSerializer);
+
+int jsonSerializer_deserialize(dyn_type *type, const char *input, void **result);
+int jsonSerializer_deserializeJson(dyn_type *type, json_t *input, void **result);
+
+int jsonSerializer_serialize(dyn_type *type, void *input, char **output);
+int jsonSerializer_serializeJson(dyn_type *type, void *input, json_t **out);
+
+#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/public/include/memstream/README.md
----------------------------------------------------------------------
diff --git a/dfi/public/include/memstream/README.md b/dfi/public/include/memstream/README.md
new file mode 100644
index 0000000..476810e
--- /dev/null
+++ b/dfi/public/include/memstream/README.md
@@ -0,0 +1,49 @@
+fmemopen for Mac OS and iOS
+===========================
+
+Originally ported from [ingenuitas python-tesseract](https://github.com/ingenuitas/python-tesseract/blob/master/fmemopen.c). Ported by Jeff Verkoeyen under the Apache 2.0 License.
+
+From the fmemopen man page:
+
+> FILE *fmemopen(void *buf, size_t size, const char *mode);
+>
+> The fmemopen() function opens a stream that permits the access specified by mode. The stream
+> allows I/O to be performed on the string or memory buffer pointed to by buf. This buffer must be
+> at least size bytes long.
+
+Alas, this method does not exist on BSD operating systems (specifically Mac OS X and iOS). It is
+possible to recreate this functionality using a BSD-specific method called `funopen`.
+
+From the funopen man page:
+
+> FILE * funopen(const void *cookie, int (*readfn)(void *, char *, int),
+> int (*writefn)(void *, const char *, int), fpos_t (*seekfn)(void *, fpos_t, int),
+> int (*closefn)(void *));
+>
+> The funopen() function associates a stream with up to four ``I/O functions''. Either readfn or
+> writefn must be specified; the others can be given as an appropriately-typed NULL pointer. These
+> I/O functions will be used to read, write, seek and close the new stream.
+
+fmemopen.c provides a simple implementation of fmemopen using funopen so that you can create FILE
+pointers to blocks of memory.
+
+Adding it to your Project
+=========================
+
+Drag fmemopen.h and fmemopen.c to your project and add them to your target. `#include "fmemopen.h"`
+wherever you need to use `fmemopen`.
+
+Examples
+========
+
+```obj-c
+#import "fmemopen.h"
+
+NSString* string = @"fmemopen in Objective-C";
+const char* cstr = [string UTF8String];
+FILE* file = fmemopen((void *)cstr, sizeof(char) * (string.length + 1), "r");
+
+// fread on file will now read the contents of the NSString
+
+fclose(file);
+```
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/public/include/memstream/fmemopen.h
----------------------------------------------------------------------
diff --git a/dfi/public/include/memstream/fmemopen.h b/dfi/public/include/memstream/fmemopen.h
new file mode 100644
index 0000000..3d06b20
--- /dev/null
+++ b/dfi/public/include/memstream/fmemopen.h
@@ -0,0 +1,52 @@
+//
+// Copyright 2012 Jeff Verkoeyen
+// Originally ported from https://github.com/ingenuitas/python-tesseract/blob/master/fmemopen.c
+//
+// Licensed 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.
+//
+
+#ifndef FMEMOPEN_H_
+#define FMEMOPEN_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * A BSD port of the fmemopen Linux method using funopen.
+ *
+ * man docs for fmemopen:
+ * http://linux.die.net/man/3/fmemopen
+ *
+ * man docs for funopen:
+ * https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/funopen.3.html
+ *
+ * This method is ported from ingenuitas' python-tesseract project.
+ *
+ * You must call fclose on the returned file pointer or memory will be leaked.
+ *
+ * @param buf The data that will be used to back the FILE* methods. Must be at least
+ * @c size bytes.
+ * @param size The size of the @c buf data.
+ * @param mode The permitted stream operation modes.
+ * @returns A pointer that can be used in the fread/fwrite/fseek/fclose family of methods.
+ * If a failure occurred NULL will be returned.
+ */
+FILE *fmemopen(void *buf, size_t size, const char *mode);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // #ifndef FMEMOPEN_H_
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/public/include/memstream/open_memstream.h
----------------------------------------------------------------------
diff --git a/dfi/public/include/memstream/open_memstream.h b/dfi/public/include/memstream/open_memstream.h
new file mode 100644
index 0000000..e87bb0a
--- /dev/null
+++ b/dfi/public/include/memstream/open_memstream.h
@@ -0,0 +1,15 @@
+#ifndef OPEN_MEMSTREAM_H_
+#define OPEN_MEMSTREAM_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+FILE *open_memstream(char **cp, size_t *lenp);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // #ifndef FMEMOPEN_H_
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/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 b25909d..c3b3449 100644
--- a/remote_services/remote_service_admin_dfi/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/CMakeLists.txt
@@ -22,25 +22,21 @@ if (RSA_REMOTE_SERVICE_ADMIN_DFI)
find_package(CURL REQUIRED)
find_package(Jansson REQUIRED)
- find_package(FFI REQUIRED)
include_directories(
${CURL_INCLUDE_DIRS}
${JANSSON_INCLUDE_DIRS}
- ${FFI_INCLUDE_DIRS}
)
if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
include_directories(dynamic_function_interface/memstream)
endif()
- add_subdirectory(dynamic_function_interface)
add_subdirectory(rsa)
if (ENABLE_TESTING)
find_package(CppUTest REQUIRED)
include_directories(${CPPUTEST_INCLUDE_DIR})
- add_subdirectory(dynamic_function_interface_tst)
add_subdirectory(rsa_tst)
endif()
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt b/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt
deleted file mode 100644
index db9ed65..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt
+++ /dev/null
@@ -1,41 +0,0 @@
-# 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.
-
-include_directories(
- .
-)
-
-set(MEMSTREAM_SOURCES "")
-if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
- set(MEMSTREAM_SOURCES memstream/open_memstream.c memstream/fmemopen.c)
-endif()
-
-add_library(dfi SHARED
- dyn_common.c
- dyn_type.c
- dyn_function.c
- dyn_interface.c
- dyn_message.c
- json_serializer.c
- json_rpc.c
- ${MEMSTREAM_SOURCES}
-)
-target_link_libraries(dfi ${FFI_LIBRARIES} ${JANSSON_LIBRARY})
-
-install(TARGETS dfi DESTINATION lib COMPONENT framework)
-FILE(GLOB files "*.h")
-INSTALL(FILES ${files} DESTINATION include/celix/dfi)
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/dfi_log_util.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dfi_log_util.h b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dfi_log_util.h
deleted file mode 100644
index 2bcd8fa..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dfi_log_util.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- *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.
- */
-#ifndef _DFI_LOG_UTIL_H_
-#define _DFI_LOG_UTIL_H_
-
-typedef void (*logf_ft)(void *handle, int level, const char *file, int line, const char *format, ...);
-
-#define DFI_SETUP_LOG_HEADER(cmp) \
- void cmp ## _logSetup(logf_ft logf, void *handle, int currentLogLevel);
-
-#define DFI_SETUP_LOG(cmp) \
- static logf_ft g_logf = NULL; \
- static void *g_logHandle = NULL; \
- static int g_currentLogLevel = 1; \
- \
- void cmp ## _logSetup(logf_ft logf, void *handle, int currentLogLevel) { \
- g_currentLogLevel = currentLogLevel; \
- g_logHandle = handle; \
- g_logf = logf; \
- }
-
-#define LOG_LVL_ERROR 1
-#define LOG_LVL_WARNING 2
-#define LOG_LVL_INFO 3
-#define LOG_LVL_DEBUG 4
-
-#define LOG_ERROR(msg, ...) \
- if (g_logf != NULL && g_currentLogLevel >= LOG_LVL_ERROR) { \
- g_logf(g_logHandle, LOG_LVL_ERROR, __FILE__, __LINE__, (msg), ##__VA_ARGS__); \
- }
-
-#define LOG_WARNING(msg, ...) \
- if (g_logf != NULL && g_currentLogLevel >= LOG_LVL_WARNING) { \
- g_logf(g_logHandle, LOG_LVL_WARNING, __FILE__, __LINE__, (msg), ##__VA_ARGS__); \
- }
-
-#define LOG_INFO(msg, ...) \
- if (g_logf != NULL && g_currentLogLevel >= LOG_LVL_INFO) { \
- g_logf(g_logHandle, LOG_LVL_INFO, __FILE__, __LINE__, (msg), ##__VA_ARGS__); \
- }
-
-#define LOG_DEBUG(msg, ...) \
- if (g_logf != NULL && g_currentLogLevel >= LOG_LVL_DEBUG) { \
- g_logf(g_logHandle, LOG_LVL_DEBUG, __FILE__, __LINE__, (msg), ##__VA_ARGS__); \
- }
-
-#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_common.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_common.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_common.c
deleted file mode 100644
index 6934e17..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_common.c
+++ /dev/null
@@ -1,151 +0,0 @@
-/**
- *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.
- */
-#include "dyn_common.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <stdbool.h>
-
-#if defined(BSD) || defined(__APPLE__)
-#include "open_memstream.h"
-#include "fmemopen.h"
-#endif
-
-static const int OK = 0;
-static const int ERROR = 1;
-
-DFI_SETUP_LOG(dynCommon)
-
-static bool dynCommon_charIn(int c, const char *acceptedChars);
-
-int dynCommon_parseName(FILE *stream, char **result) {
- return dynCommon_parseNameAlsoAccept(stream, NULL, result);
-}
-
-int dynCommon_parseNameAlsoAccept(FILE *stream, const char *acceptedChars, char **result) {
- int status = OK;
-
- char *buf = NULL;
- size_t size = 0;
- int strLen = 0;
- FILE *name = open_memstream(&buf, &size);
-
- if (name != NULL) {
- int c = getc(stream);
- while (isalnum(c) || c == '_' || dynCommon_charIn(c, acceptedChars)) {
- fputc(c, name);
- c = getc(stream);
- strLen += 1;
- }
- fflush(name);
- fclose(name);
- ungetc(c, stream);
- } else {
- status = ERROR;
- LOG_ERROR("Error creating mem stream for name. %s", strerror(errno));
- }
-
- if (status == OK) {
- if (strLen == 0) {
- status = ERROR;
- LOG_ERROR("Parsed empty name");
- }
- }
-
- if (status == OK) {
- LOG_DEBUG("Parsed name '%s'", buf);
- *result = buf;
- } else if (buf != NULL) {
- free(buf);
- }
-
- return status;
-}
-
-int dynCommon_parseNameValue(FILE *stream, char **outName, char **outValue) {
- int status = OK;
- char *name = NULL;
- char *value = NULL;
- const char *valueAcceptedChars = ".<>{}[]?;:~!@#$%^&*()_+-=,./\\'\"";
-
- status = dynCommon_parseName(stream, &name);
- if (status == OK) {
- status = dynCommon_eatChar(stream, '=');
- }
- if (status == OK) {
- status = dynCommon_parseNameAlsoAccept(stream, valueAcceptedChars, &value); //NOTE use different more lenient function e.g. only stop at '\n' ?
- }
-
- if (status == OK) {
- *outName = name;
- *outValue = value;
- } else {
- if (name != NULL) {
- free(name);
- }
- if (value != NULL) {
- free(value);
- }
- }
- return status;
-}
-
-int dynCommon_eatChar(FILE *stream, int expected) {
- int status = OK;
- long loc = ftell(stream);
- int c = fgetc(stream);
- if (c != expected) {
- status = ERROR;
- LOG_ERROR("Error parsing, expected token '%c' got '%c' at position %li", expected, loc);
- }
- return status;
-}
-
-static bool dynCommon_charIn(int c, const char *acceptedChars) {
- bool status = false;
- if (acceptedChars != NULL) {
- int i;
- for (i = 0; acceptedChars[i] != '\0'; i += 1) {
- if (c == acceptedChars[i]) {
- status = true;
- break;
- }
- }
- }
-
- return status;
-}
-
-void dynCommon_clearNamValHead(struct namvals_head *head) {
- struct namval_entry *tmp = NULL;
- struct namval_entry *entry = TAILQ_FIRST(head);
- while (entry != NULL) {
- tmp = entry;
-
- if (entry->name != NULL) {
- free(entry->name);
- }
- if (entry->value != NULL) {
- free(entry->value);
- }
- entry = TAILQ_NEXT(entry, entries);
- free(tmp);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_common.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_common.h b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_common.h
deleted file mode 100644
index 6ec236f..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_common.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- *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.
- */
-#ifndef _DYN_COMMON_H_
-#define _DYN_COMMON_H_
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/queue.h>
-
-#include "dfi_log_util.h"
-
-//logging
-DFI_SETUP_LOG_HEADER(dynCommon);
-
-TAILQ_HEAD(namvals_head, namval_entry);
-
-struct namval_entry {
- char *name;
- char *value;
- TAILQ_ENTRY(namval_entry) entries;
-};
-
-int dynCommon_parseName(FILE *stream, char **result);
-int dynCommon_parseNameAlsoAccept(FILE *stream, const char *acceptedChars, char **result);
-int dynCommon_parseNameValue(FILE *stream, char **name, char **value);
-int dynCommon_eatChar(FILE *stream, int c);
-
-void dynCommon_clearNamValHead(struct namvals_head *head);
-
-#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_function.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_function.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_function.c
deleted file mode 100644
index 9ef7aa0..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_function.c
+++ /dev/null
@@ -1,335 +0,0 @@
-/**
- *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.
- */
-#include "dyn_function.h"
-
-#include <strings.h>
-#include <stdlib.h>
-
-#include "dyn_common.h"
-
-struct _dyn_function_type {
- char *name;
- struct types_head *refTypes; //NOTE not owned
- TAILQ_HEAD(,_dyn_function_argument_type) arguments;
- ffi_type **ffiArguments;
- dyn_type *funcReturn;
- ffi_cif cif;
-
- //closure part
- ffi_closure *ffiClosure;
- void (*fn)(void);
- void *userData;
- void (*bind)(void *userData, void *args[], void *ret);
-};
-
-typedef struct _dyn_function_argument_type dyn_function_argument_type;
-struct _dyn_function_argument_type {
- int index;
- char *name;
- enum dyn_function_argument_meta argumentMeta;
- dyn_type *type;
- TAILQ_ENTRY(_dyn_function_argument_type) entries;
-};
-
-static const int OK = 0;
-static const int MEM_ERROR = 1;
-static const int PARSE_ERROR = 2;
-static const int ERROR = 2;
-
-DFI_SETUP_LOG(dynFunction)
-
-static int dynFunction_initCif(dyn_function_type *dynFunc);
-static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descriptor);
-static void dynFunction_ffiBind(ffi_cif *cif, void *ret, void *args[], void *userData);
-
-int dynFunction_parse(FILE *descriptor, struct types_head *refTypes, dyn_function_type **out) {
- int status = OK;
- dyn_function_type *dynFunc = NULL;
- LOG_DEBUG("Creating dyn function", descriptor);
-
- dynFunc = calloc(1, sizeof(*dynFunc));
-
- if (dynFunc != NULL) {
- TAILQ_INIT(&dynFunc->arguments);
- dynFunc->refTypes = refTypes;
- status = dynFunction_parseDescriptor(dynFunc, descriptor);
- if (status == 0) {
- int rc = dynFunction_initCif(dynFunc);
- if (rc != 0) {
- LOG_ERROR("Error initializing cif");
- status = ERROR;
- }
- }
- } else {
- LOG_ERROR("Error allocationg memory for dyn functipn\n");
- status = MEM_ERROR;
- }
-
- if (status == OK) {
- dyn_function_argument_type *arg = NULL;
- TAILQ_FOREACH(arg, &dynFunc->arguments, entries) {
- const char *meta = dynType_getMetaInfo(arg->type, "am");
- if (meta == NULL) {
- arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__STD;
- } else if (strcmp(meta, "handle") == 0) {
- arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__HANDLE;
- } else if (strcmp(meta, "pre") == 0) {
- arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT;
- } else if (strcmp(meta, "out") == 0) {
- arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__OUTPUT;
- } else {
- LOG_WARNING("unknown argument meta '%s' encountered", meta);
- arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__STD;
- }
- }
- }
-
- if (status == OK) {
- *out = dynFunc;
- } else {
- if (dynFunc != NULL) {
- dynFunction_destroy(dynFunc);
- }
-
- }
-
- return status;
-}
-
-int dynFunction_parseWithStr(const char *descriptor, struct types_head *refTypes, dyn_function_type **out) {
- int status = OK;
- FILE *stream = fmemopen((char *)descriptor, strlen(descriptor), "r");
- if (stream != NULL) {
- status = dynFunction_parse(stream, refTypes, out);
- fclose(stream);
- } else {
- status = MEM_ERROR;
- LOG_ERROR("Error creating mem stream for descriptor string. %s", strerror(errno));
- }
- return status;
-}
-
-static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descriptor) {
- int status = OK;
- char *name = NULL;
-
- status = dynCommon_parseName(descriptor, &name);
-
- if (status == OK) {
- dynFunc->name = name;
- }
-
- if (status == OK) {
- int c = fgetc(descriptor);
- if ( c != '(') {
- status = PARSE_ERROR;
- LOG_ERROR("Expected '(' token got '%c'", c);
- }
- }
-
- int nextChar = fgetc(descriptor);
- int index = 0;
- dyn_type *type = NULL;
- char argName[32];
- while (nextChar != ')' && status == 0) {
- ungetc(nextChar, descriptor);
- type = NULL;
-
- dyn_function_argument_type *arg = NULL;
-
- status = dynType_parse(descriptor, NULL, dynFunc->refTypes, &type);
- if (status == 0) {
- arg = calloc(1, sizeof(*arg));
- if (arg != NULL) {
- arg->index = index;
- arg->type = type;
- snprintf(argName, 32, "arg%04i", index);
- arg->name = strdup(argName);
-
- index += 1;
- } else {
- LOG_ERROR("Error allocating memory");
- status = MEM_ERROR;
- }
- }
-
- if (status == OK) {
- TAILQ_INSERT_TAIL(&dynFunc->arguments, arg, entries);
- } else {
- if (arg != NULL) {
- free(arg->name);
- if (arg->type != NULL) {
- dynType_destroy(arg->type);
- }
- free(arg);
- }
- }
- nextChar = fgetc(descriptor);
- }
-
- if (status == 0) {
- status = dynType_parse(descriptor, NULL, dynFunc->refTypes, &dynFunc->funcReturn);
- }
-
- return status;
-}
-
-enum dyn_function_argument_meta dynFunction_argumentMetaForIndex(dyn_function_type *dynFunc, int argumentNr) {
- enum dyn_function_argument_meta result = 0;
- dyn_function_argument_type *arg = NULL;
- int index = 0;
- TAILQ_FOREACH(arg, &dynFunc->arguments, entries) {
- if (index == argumentNr) {
- result = arg->argumentMeta;
- break;
- }
- index += 1;
- }
- return result;
-}
-
-
-static int dynFunction_initCif(dyn_function_type *dynFunc) {
- int status = 0;
-
- int count = 0;
- dyn_function_argument_type *entry = NULL;
- TAILQ_FOREACH(entry, &dynFunc->arguments, entries) {
- count +=1;
- }
-
- dynFunc->ffiArguments = calloc(count, sizeof(ffi_type));
-
- TAILQ_FOREACH(entry, &dynFunc->arguments, entries) {
- dynFunc->ffiArguments[entry->index] = dynType_ffiType(entry->type);
- }
-
- ffi_type **args = dynFunc->ffiArguments;
- ffi_type *returnType = dynType_ffiType(dynFunc->funcReturn);
-
- int ffiResult = ffi_prep_cif(&dynFunc->cif, FFI_DEFAULT_ABI, count, returnType, args);
- if (ffiResult != FFI_OK) {
- status = 1;
- }
-
- return status;
-}
-
-void dynFunction_destroy(dyn_function_type *dynFunc) {
- if (dynFunc != NULL) {
- if (dynFunc->funcReturn != NULL) {
- dynType_destroy(dynFunc->funcReturn);
- }
- if (dynFunc->ffiClosure != NULL) {
- ffi_closure_free(dynFunc->ffiClosure);
- }
- if (dynFunc->name != NULL) {
- free(dynFunc->name);
- }
- if (dynFunc->ffiArguments != NULL) {
- free(dynFunc->ffiArguments);
- }
-
- dyn_function_argument_type *entry = NULL;
- dyn_function_argument_type *tmp = NULL;
- entry = TAILQ_FIRST(&dynFunc->arguments);
- while (entry != NULL) {
- if (entry->name != NULL) {
- free(entry->name);
- }
- dynType_destroy(entry->type);
- tmp = entry;
- entry = TAILQ_NEXT(entry, entries);
- free(tmp);
- }
-
- free(dynFunc);
- }
-}
-
-int dynFunction_call(dyn_function_type *dynFunc, void(*fn)(void), void *returnValue, void **argValues) {
- ffi_call(&dynFunc->cif, fn, returnValue, argValues);
- return 0;
-}
-
-static void dynFunction_ffiBind(ffi_cif *cif, void *ret, void *args[], void *userData) {
- dyn_function_type *dynFunc = userData;
- dynFunc->bind(dynFunc->userData, args, ret);
-}
-
-int dynFunction_createClosure(dyn_function_type *dynFunc, void (*bind)(void *, void **, void*), void *userData, void(**out)(void)) {
- int status = 0;
- void (*fn)(void);
- dynFunc->ffiClosure = ffi_closure_alloc(sizeof(ffi_closure), (void **)&fn);
- if (dynFunc->ffiClosure != NULL) {
- int rc = ffi_prep_closure_loc(dynFunc->ffiClosure, &dynFunc->cif, dynFunction_ffiBind, dynFunc, fn);
- if (rc != FFI_OK) {
- status = 1;
- }
- } else {
- status = 2;
- }
-
- if (status == 0) {
- dynFunc->userData = userData;
- dynFunc->bind = bind;
- dynFunc->fn = fn;
- *out =fn;
- }
-
- return status;
-}
-
-int dynFunction_getFnPointer(dyn_function_type *dynFunc, void (**fn)(void)) {
- int status = 0;
- if (dynFunc != NULL && dynFunc->fn != NULL) {
- (*fn) = dynFunc->fn;
- } else {
- status = 1;
- }
- return status;
-}
-
-int dynFunction_nrOfArguments(dyn_function_type *dynFunc) {
- int count = 0;
- dyn_function_argument_type *entry = NULL;
- TAILQ_FOREACH(entry, &dynFunc->arguments, entries) {
- count += 1;
- }
- return count;
-}
-
-dyn_type *dynFunction_argumentTypeForIndex(dyn_function_type *dynFunc, int argumentNr) {
- dyn_type *result = NULL;
- int index = 0;
- dyn_function_argument_type *entry = NULL;
- TAILQ_FOREACH(entry, &dynFunc->arguments, entries) {
- if (index == argumentNr) {
- result = entry->type;
- break;
- }
- index +=1;
- }
- return result;
-}
-
-dyn_type * dynFunction_returnType(dyn_function_type *dynFunction) {
- return dynFunction->funcReturn;
-}
-
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_function.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_function.h b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_function.h
deleted file mode 100644
index 792691e..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_function.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- *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.
- */
-#ifndef __DYN_FUNCTION_H_
-#define __DYN_FUNCTION_H_
-
-#include <ffi.h>
-#include "dyn_type.h"
-#include "dfi_log_util.h"
-
-/**
- * Uses the following schema
- * (Name)([Type]*)Type
- *
- * Dyn fynction argument meta (am) as meta info, with the following possible values
- * am=handle #void pointer for the handle
- * am=pre #output pointer with memory preallocated
- * am=out #output pointer
- */
-
-typedef struct _dyn_function_type dyn_function_type;
-
-DFI_SETUP_LOG_HEADER(dynFunction);
-
-enum dyn_function_argument_meta {
- DYN_FUNCTION_ARGUMENT_META__STD = 0,
- DYN_FUNCTION_ARGUMENT_META__HANDLE = 1,
- DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT = 2,
- DYN_FUNCTION_ARGUMENT_META__OUTPUT = 3
-};
-
-int dynFunction_parse(FILE *descriptorStream, struct types_head *refTypes, dyn_function_type **dynFunc);
-int dynFunction_parseWithStr(const char *descriptor, struct types_head *refTypes, dyn_function_type **dynFunc);
-
-int dynFunction_nrOfArguments(dyn_function_type *dynFunc);
-dyn_type *dynFunction_argumentTypeForIndex(dyn_function_type *dynFunc, int argumentNr);
-enum dyn_function_argument_meta dynFunction_argumentMetaForIndex(dyn_function_type *dynFunc, int argumentNr);
-dyn_type * dynFunction_returnType(dyn_function_type *dynFunction);
-
-void dynFunction_destroy(dyn_function_type *dynFunc);
-int dynFunction_call(dyn_function_type *dynFunc, void(*fn)(void), void *returnValue, void **argValues);
-
-int dynFunction_createClosure(dyn_function_type *func, void (*bind)(void *, void **, void*), void *userData, void(**fn)(void));
-int dynFunction_getFnPointer(dyn_function_type *func, void (**fn)(void));
-
-#endif
[5/6] celix git commit: CELIX-309: Move dfi to top-level subdir
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/src/json_rpc.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/json_rpc.c b/dfi/private/src/json_rpc.c
new file mode 100644
index 0000000..e13c8ef
--- /dev/null
+++ b/dfi/private/src/json_rpc.c
@@ -0,0 +1,335 @@
+/**
+ *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.
+ */
+#include "json_rpc.h"
+#include "json_serializer.h"
+#include "dyn_type.h"
+#include "dyn_interface.h"
+#include <jansson.h>
+#include <assert.h>
+#include <stdint.h>
+#include <string.h>
+
+
+static int OK = 0;
+static int ERROR = 1;
+
+DFI_SETUP_LOG(jsonRpc);
+
+typedef void (*gen_func_type)(void);
+
+struct generic_service_layout {
+ void *handle;
+ gen_func_type methods[];
+};
+
+int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request, char **out) {
+ int status = OK;
+
+ dyn_type* returnType = NULL;
+
+ LOG_DEBUG("Parsing data: %s\n", request);
+ json_error_t error;
+ json_t *js_request = json_loads(request, 0, &error);
+ json_t *arguments = NULL;
+ const char *sig;
+ if (js_request) {
+ if (json_unpack(js_request, "{s:s}", "m", &sig) != 0) {
+ LOG_ERROR("Got json error '%s'\n", error.text);
+ } else {
+ arguments = json_object_get(js_request, "a");
+ }
+ } else {
+ LOG_ERROR("Got json error '%s' for '%s'\n", error.text, request);
+ return 0;
+ }
+
+ LOG_DEBUG("Looking for method %s\n", sig);
+ struct methods_head *methods = NULL;
+ dynInterface_methods(intf, &methods);
+ struct method_entry *entry = NULL;
+ struct method_entry *method = NULL;
+ TAILQ_FOREACH(entry, methods, entries) {
+ if (strcmp(sig, entry->id) == 0) {
+ method = entry;
+ break;
+ }
+ }
+
+ if (method == NULL) {
+ status = ERROR;
+ LOG_ERROR("Cannot find method with sig '%s'", sig);
+ }
+
+ if (status == OK) {
+ LOG_DEBUG("RSA: found method '%s'\n", entry->id);
+ returnType = dynFunction_returnType(method->dynFunc);
+ }
+
+ void (*fp)(void) = NULL;
+ void *handle = NULL;
+ if (status == OK) {
+ struct generic_service_layout *serv = service;
+ handle = serv->handle;
+ fp = serv->methods[method->index];
+ }
+
+ dyn_function_type *func = NULL;
+ int nrOfArgs = 0;
+ if (status == OK) {
+ nrOfArgs = dynFunction_nrOfArguments(entry->dynFunc);
+ func = entry->dynFunc;
+ }
+
+ void *args[nrOfArgs];
+
+ json_t *value = NULL;
+
+ int i;
+ int index = 0;
+
+ void *ptr = NULL;
+ void *ptrToPtr = &ptr;
+
+ for (i = 0; i < nrOfArgs; i += 1) {
+ dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
+ enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
+ if (meta == DYN_FUNCTION_ARGUMENT_META__STD) {
+ value = json_array_get(arguments, index++);
+ status = jsonSerializer_deserializeJson(argType, value, &(args[i]));
+ } else if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
+ dynType_alloc(argType, &args[i]);
+ } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) {
+ args[i] = &ptrToPtr;
+ } else if (meta == DYN_FUNCTION_ARGUMENT_META__HANDLE) {
+ args[i] = &handle;
+ }
+
+ if (status != OK) {
+ break;
+ }
+ }
+ json_decref(js_request);
+
+ if (status == OK) {
+ if (dynType_descriptorType(returnType) != 'N') {
+ //NOTE To be able to handle exception only N as returnType is supported
+ LOG_ERROR("Only interface methods with a native int are supported. Found type '%c'", (char)dynType_descriptorType(returnType));
+ status = ERROR;
+ }
+ }
+
+ ffi_sarg returnVal = 1;
+
+ if (status == OK) {
+ dynFunction_call(func, fp, (void *) &returnVal, args);
+ }
+
+ int funcCallStatus = (int)returnVal;
+ if (funcCallStatus != 0) {
+ LOG_WARNING("Error calling remote endpoint function, got error code %i", funcCallStatus);
+ }
+
+ json_t *jsonResult = NULL;
+ for(i = 0; i < nrOfArgs; i += 1) {
+ dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
+ enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
+ if (meta == DYN_FUNCTION_ARGUMENT_META__STD) {
+ dynType_free(argType, args[i]);
+ }
+ }
+
+ if (funcCallStatus == 0 && status == OK) {
+ for (i = 0; i < nrOfArgs; i += 1) {
+ dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
+ enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
+ if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
+ if (status == OK) {
+ status = jsonSerializer_serializeJson(argType, args[i], &jsonResult);
+ }
+ dynType_free(argType, args[i]);
+ } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) {
+ if (ptr != NULL) {
+ dyn_type *typedType = NULL;
+ if (status == OK) {
+ status = dynType_typedPointer_getTypedType(argType, &typedType);
+ }
+ if (dynType_descriptorType(typedType) == 't') {
+ status = jsonSerializer_serializeJson(typedType, (void*) &ptr, &jsonResult);
+ free(ptr);
+ } else {
+ dyn_type *typedTypedType = NULL;
+ if (status == OK) {
+ status = dynType_typedPointer_getTypedType(typedType, &typedTypedType);
+ }
+
+ status = jsonSerializer_serializeJson(typedTypedType, ptr, &jsonResult);
+
+ if (status == OK) {
+ dynType_free(typedTypedType, ptr);
+ }
+ }
+
+ } else {
+ LOG_DEBUG("Output ptr is null");
+ }
+ }
+
+ if (status != OK) {
+ break;
+ }
+ }
+ }
+
+ char *response = NULL;
+ if (status == OK) {
+ LOG_DEBUG("creating payload\n");
+ json_t *payload = json_object();
+ if (funcCallStatus == 0) {
+ if (jsonResult == NULL) {
+ //ignore -> no result
+ } else {
+ LOG_DEBUG("Setting result payload");
+ json_object_set_new(payload, "r", jsonResult);
+ }
+ } else {
+ LOG_DEBUG("Setting error payload");
+ json_object_set_new(payload, "e", json_integer(funcCallStatus));
+ }
+ response = json_dumps(payload, JSON_DECODE_ANY);
+ json_decref(payload);
+ LOG_DEBUG("status ptr is %p. response is '%s'\n", status, response);
+ }
+
+ if (status == OK) {
+ *out = response;
+ } else {
+ free(response);
+ }
+
+ return status;
+}
+
+int jsonRpc_prepareInvokeRequest(dyn_function_type *func, const char *id, void *args[], char **out) {
+ int status = OK;
+
+
+ LOG_DEBUG("Calling remote function '%s'\n", id);
+ json_t *invoke = json_object();
+ json_object_set_new(invoke, "m", json_string(id));
+
+ json_t *arguments = json_array();
+ json_object_set_new(invoke, "a", arguments);
+
+ int i;
+ int nrOfArgs = dynFunction_nrOfArguments(func);
+ for (i = 0; i < nrOfArgs; i +=1) {
+ dyn_type *type = dynFunction_argumentTypeForIndex(func, i);
+ enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
+ if (meta == DYN_FUNCTION_ARGUMENT_META__STD) {
+ json_t *val = NULL;
+
+ int rc = jsonSerializer_serializeJson(type, args[i], &val);
+ if (rc == 0) {
+ json_array_append_new(arguments, val);
+ } else {
+ status = ERROR;
+ break;
+ }
+ } else {
+ //skip handle / output types
+ }
+ }
+
+ char *invokeStr = json_dumps(invoke, JSON_DECODE_ANY);
+ json_decref(invoke);
+
+ if (status == OK) {
+ *out = invokeStr;
+ }
+
+ return status;
+}
+
+int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void *args[]) {
+ int status = OK;
+
+ json_error_t error;
+ json_t *replyJson = json_loads(reply, JSON_DECODE_ANY, &error);
+ if (replyJson == NULL) {
+ status = ERROR;
+ LOG_ERROR("Error parsing json '%s', got error '%s'", reply, error.text);
+ }
+
+ json_t *result = NULL;
+ if (status == OK) {
+ result = json_object_get(replyJson, "r"); //TODO check
+ if (result == NULL) {
+ status = ERROR;
+ LOG_ERROR("Cannot find r entry in json reply '%s'", reply);
+ }
+ }
+
+ if (status == OK) {
+ int nrOfArgs = dynFunction_nrOfArguments(func);
+ int i;
+ for (i = 0; i < nrOfArgs; i += 1) {
+ dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
+ enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
+ if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
+ void *tmp = NULL;
+ void **out = (void **) args[i];
+
+ size_t size = 0;
+
+ if (dynType_descriptorType(argType) == 't') {
+ status = jsonSerializer_deserializeJson(argType, result, &tmp);
+ size = strnlen(((char *) *(char**) tmp), 1024 * 1024);
+ memcpy(*out, *(void**) tmp, size);
+ } else {
+ dynType_typedPointer_getTypedType(argType, &argType);
+ status = jsonSerializer_deserializeJson(argType, result, &tmp);
+ size = dynType_size(argType);
+ memcpy(*out, tmp, size);
+ }
+
+ dynType_free(argType, tmp);
+ } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) {
+ dyn_type *subType = NULL;
+
+ dynType_typedPointer_getTypedType(argType, &subType);
+
+ if (dynType_descriptorType(subType) == 't') {
+ void ***out = (void ***) args[i];
+ status = jsonSerializer_deserializeJson(subType, result, *out);
+ } else {
+ dyn_type *subSubType = NULL;
+ dynType_typedPointer_getTypedType(subType, &subSubType);
+ void ***out = (void ***) args[i];
+ status = jsonSerializer_deserializeJson(subSubType, result, *out);
+ }
+ } else {
+ //skip
+ }
+ }
+ }
+
+ json_decref(replyJson);
+
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/src/json_serializer.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/json_serializer.c b/dfi/private/src/json_serializer.c
new file mode 100644
index 0000000..8d42bb4
--- /dev/null
+++ b/dfi/private/src/json_serializer.c
@@ -0,0 +1,477 @@
+/**
+ *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.
+ */
+#include "json_serializer.h"
+#include "dyn_type.h"
+#include "dyn_interface.h"
+
+#include <jansson.h>
+#include <assert.h>
+#include <stdint.h>
+#include <string.h>
+
+static int jsonSerializer_createType(dyn_type *type, json_t *object, void **result);
+static int jsonSerializer_parseObject(dyn_type *type, json_t *object, void *inst);
+static int jsonSerializer_parseObjectMember(dyn_type *type, const char *name, json_t *val, void *inst);
+static int jsonSerializer_parseSequence(dyn_type *seq, json_t *array, void *seqLoc);
+static int jsonSerializer_parseAny(dyn_type *type, void *input, json_t *val);
+
+static int jsonSerializer_writeAny(dyn_type *type, void *input, json_t **val);
+
+static int jsonSerializer_writeComplex(dyn_type *type, void *input, json_t **val);
+
+static int jsonSerializer_writeSequence(dyn_type *type, void *input, json_t **out);
+
+static int OK = 0;
+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 || dynType_type(type) == DYN_TYPE_SEQUENCE);
+ int status = 0;
+
+ json_error_t error;
+ json_t *root = json_loads(input, JSON_DECODE_ANY, &error);
+
+ if (root != NULL) {
+ status = jsonSerializer_deserializeJson(type, root, result);
+ json_decref(root);
+ } else {
+ status = ERROR;
+ LOG_ERROR("Error parsing json input '%s'. Error is: %s\n", input, error.text);
+ }
+
+ return status;
+}
+
+int jsonSerializer_deserializeJson(dyn_type *type, json_t *input, void **out) {
+ return jsonSerializer_createType(type, input, out);
+}
+
+static int jsonSerializer_createType(dyn_type *type, json_t *val, void **result) {
+ assert(val != NULL);
+ int status = OK;
+ void *inst = NULL;
+
+ if (dynType_descriptorType(type) == 't') {
+ if (json_typeof(val) == JSON_STRING) {
+ inst = strdup(json_string_value(val));
+ } else {
+ status = ERROR;
+ LOG_ERROR("Expected json_string type got %i\n", json_typeof(val));
+ }
+ } else {
+ status = dynType_alloc(type, &inst);
+
+ if (status == OK) {
+ assert(inst != NULL);
+ status = jsonSerializer_parseAny(type, inst, val);
+
+ if (status != OK) {
+ dynType_free(type, inst);
+ }
+ }
+ }
+
+
+ if (status == OK) {
+ *result = inst;
+ }
+
+ return status;
+}
+
+static int jsonSerializer_parseObject(dyn_type *type, json_t *object, void *inst) {
+ assert(object != NULL);
+ int status = 0;
+ json_t *value;
+ const char *key;
+
+ json_object_foreach(object, key, value) {
+ status = jsonSerializer_parseObjectMember(type, key, value, inst);
+ if (status != OK) {
+ break;
+ }
+ }
+
+ return status;
+}
+
+static int jsonSerializer_parseObjectMember(dyn_type *type, const char *name, json_t *val, void *inst) {
+ int status = OK;
+ void *valp = NULL;
+ dyn_type *valType = NULL;
+
+ int index = dynType_complex_indexForName(type, name);
+ if (index < 0) {
+ LOG_ERROR("Cannot find index for member '%s'", name);
+ status = ERROR;
+ }
+
+ if (status == OK) {
+ status = dynType_complex_valLocAt(type, index, inst, &valp);
+ }
+
+ if (status == OK ) {
+ status = dynType_complex_dynTypeAt(type, index, &valType);
+ }
+
+ if (status == OK) {
+ status = jsonSerializer_parseAny(valType, valp, val);
+ }
+
+ return status;
+}
+
+static int jsonSerializer_parseAny(dyn_type *type, void *loc, json_t *val) {
+ int status = OK;
+
+ dyn_type *subType = NULL;
+ char c = dynType_descriptorType(type);
+
+ /*
+ printf("parseAny with descriptor '%c' :", c);
+ json_dumpf(val, stdout, 0); //TODO remove
+ printf("\n");
+ */
+
+ bool *z; //Z
+ float *f; //F
+ double *d; //D
+ char *b; //B
+ int *n; //N
+ 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
+
+ switch (c) {
+ case 'Z' :
+ z = loc;
+ *z = (bool) json_is_true(val);
+ break;
+ case 'F' :
+ f = loc;
+ *f = (float) json_real_value(val);
+ break;
+ case 'D' :
+ d = loc;
+ *d = json_real_value(val);
+ break;
+ case 'N' :
+ n = loc;
+ *n = (int) json_real_value(val);
+ break;
+ case 'B' :
+ b = loc;
+ *b = (char) json_integer_value(val);
+ break;
+ case 'S' :
+ s = loc;
+ *s = (int16_t) json_integer_value(val);
+ break;
+ case 'I' :
+ i = loc;
+ *i = (int32_t) json_integer_value(val);
+ break;
+ case 'J' :
+ 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);
+ break;
+ case 'i' :
+ ui = loc;
+ *ui = (uint32_t) json_integer_value(val);
+ break;
+ case 'j' :
+ ul = loc;
+ *ul = (uint64_t) json_integer_value(val);
+ break;
+ case 't' :
+ if (json_is_string(val)) {
+ dynType_text_allocAndInit(type, loc, json_string_value(val));
+ } else {
+ status = ERROR;
+ LOG_ERROR("Expected json string type got %i", json_typeof(val));
+ }
+ break;
+ case '[' :
+ if (json_is_array(val)) {
+ status = jsonSerializer_parseSequence(type, val, loc);
+ } else {
+ status = ERROR;
+ LOG_ERROR("Expected json array type got '%i'", json_typeof(val));
+ }
+ break;
+ case '{' :
+ if (status == OK) {
+ status = jsonSerializer_parseObject(type, val, loc);
+ }
+ break;
+ case '*' :
+ status = dynType_typedPointer_getTypedType(type, &subType);
+ if (status == OK) {
+ status = jsonSerializer_createType(subType, val, (void **) loc);
+ }
+ break;
+ case 'P' :
+ status = ERROR;
+ LOG_WARNING("Untyped pointer are not supported for serialization");
+ break;
+ default :
+ status = ERROR;
+ LOG_ERROR("Error provided type '%c' not supported for JSON\n", dynType_descriptorType(type));
+ break;
+ }
+
+ return status;
+}
+
+static int jsonSerializer_parseSequence(dyn_type *seq, json_t *array, void *seqLoc) {
+ assert(dynType_type(seq) == DYN_TYPE_SEQUENCE);
+ int status = OK;
+
+ size_t size = json_array_size(array);
+ //LOG_DEBUG("Allocating sequence with capacity %zu", size);
+ status = dynType_sequence_alloc(seq, seqLoc, (int) size);
+
+ if (status == OK) {
+ dyn_type *itemType = dynType_sequence_itemType(seq);
+ size_t index;
+ json_t *val;
+ json_array_foreach(array, index, val) {
+ void *valLoc = NULL;
+ status = dynType_sequence_increaseLengthAndReturnLastLoc(seq, seqLoc, &valLoc);
+ //LOG_DEBUG("Got sequence loc %p for index %zu", valLoc, index);
+
+ if (status == OK) {
+ status = jsonSerializer_parseAny(itemType, valLoc, val);
+ if (status != OK) {
+ break;
+ }
+ }
+ }
+ }
+
+ return status;
+}
+
+int jsonSerializer_serialize(dyn_type *type, void *input, char **output) {
+ int status = OK;
+
+ json_t *root = NULL;
+ status = jsonSerializer_serializeJson(type, input, &root);
+
+ if (status == OK) {
+ *output = json_dumps(root, JSON_COMPACT);
+ json_decref(root);
+ }
+
+ return status;
+}
+
+int jsonSerializer_serializeJson(dyn_type *type, void *input, json_t **out) {
+ return jsonSerializer_writeAny(type, input, out);
+}
+
+static int jsonSerializer_writeAny(dyn_type *type, void *input, json_t **out) {
+ int status = OK;
+
+ int descriptor = dynType_descriptorType(type);
+ json_t *val = NULL;
+ dyn_type *subType = NULL;
+
+ bool *z; //Z
+ float *f; //F
+ double *d; //D
+ char *b; //B
+ int *n; //N
+ 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
+
+ switch (descriptor) {
+ case 'Z' :
+ z = input;
+ val = json_boolean((bool)*z);
+ break;
+ case 'B' :
+ b = input;
+ val = json_integer((json_int_t)*b);
+ break;
+ case 'S' :
+ s = input;
+ val = json_integer((json_int_t)*s);
+ break;
+ case 'I' :
+ i = input;
+ val = json_integer((json_int_t)*i);
+ break;
+ case 'J' :
+ 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);
+ break;
+ case 'i' :
+ ui = input;
+ val = json_integer((json_int_t)*ui);
+ break;
+ case 'j' :
+ ul = input;
+ val = json_integer((json_int_t)*ul);
+ break;
+ case 'N' :
+ n = input;
+ val = json_integer((json_int_t)*n);
+ break;
+ case 'F' :
+ f = input;
+ val = json_real((double) *f);
+ break;
+ case 'D' :
+ d = input;
+ val = json_real(*d);
+ break;
+ case 't' :
+ val = json_string(*(const char **) input);
+ break;
+ case '*' :
+ status = dynType_typedPointer_getTypedType(type, &subType);
+ if (status == OK) {
+ status = jsonSerializer_writeAny(subType, *(void **)input, &val);
+ }
+ break;
+ case '{' :
+ status = jsonSerializer_writeComplex(type, input, &val);
+ break;
+ case '[' :
+ status = jsonSerializer_writeSequence(type, input, &val);
+ break;
+ case 'P' :
+ LOG_WARNING("Untyped pointer not supported for serialization. ignoring");
+ break;
+ default :
+ LOG_ERROR("Unsupported descriptor '%c'", descriptor);
+ status = ERROR;
+ break;
+ }
+
+ if (status == OK && val != NULL) {
+ *out = val;
+ }
+
+ return status;
+}
+
+static int jsonSerializer_writeSequence(dyn_type *type, void *input, json_t **out) {
+ assert(dynType_type(type) == DYN_TYPE_SEQUENCE);
+ int status = OK;
+
+ json_t *array = json_array();
+ dyn_type *itemType = dynType_sequence_itemType(type);
+ uint32_t len = dynType_sequence_length(input);
+
+ int i = 0;
+ void *itemLoc = NULL;
+ json_t *item = NULL;
+ for (i = 0; i < len; i += 1) {
+ item = NULL;
+ status = dynType_sequence_locForIndex(type, input, i, &itemLoc);
+ if (status == OK) {
+ status = jsonSerializer_writeAny(itemType, itemLoc, &item);
+ if (status == OK) {
+ json_array_append(array, item);
+ json_decref(item);
+ }
+ }
+
+ if (status != OK) {
+ break;
+ }
+ }
+
+ if (status == OK && array != NULL) {
+ *out = array;
+ }
+
+ return status;
+}
+
+static int jsonSerializer_writeComplex(dyn_type *type, void *input, json_t **out) {
+ assert(dynType_type(type) == DYN_TYPE_COMPLEX);
+ int status = OK;
+
+ json_t *val = json_object();
+ struct complex_type_entry *entry = NULL;
+ struct complex_type_entries_head *entries = NULL;
+ int index = -1;
+
+ status = dynType_complex_entries(type, &entries);
+ if (status == OK) {
+ TAILQ_FOREACH(entry, entries, entries) {
+ void *subLoc = NULL;
+ json_t *subVal = NULL;
+ dyn_type *subType = NULL;
+ index = dynType_complex_indexForName(type, entry->name);
+ status = dynType_complex_valLocAt(type, index, input, &subLoc);
+ if (status == OK ) {
+ status = dynType_complex_dynTypeAt(type, index, &subType);
+ }
+ if (status == OK) {
+ status = jsonSerializer_writeAny(subType, subLoc, &subVal);
+ }
+ if (status == OK) {
+ json_object_set(val, entry->name, subVal);
+ json_decref(subVal);
+ }
+
+ if (status != OK) {
+ break;
+ }
+ }
+ }
+
+ if (status == OK && val != NULL) {
+ *out = val;
+ }
+
+ return status;
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/src/memstream/fmemopen.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/memstream/fmemopen.c b/dfi/private/src/memstream/fmemopen.c
new file mode 100644
index 0000000..66fc9c5
--- /dev/null
+++ b/dfi/private/src/memstream/fmemopen.c
@@ -0,0 +1,78 @@
+
+/*
+ * fmem.c : fmemopen() on top of BSD's funopen()
+ * 20081017 AF
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef linux
+struct fmem {
+ size_t pos;
+ size_t size;
+ char *buffer;
+};
+typedef struct fmem fmem_t;
+
+static int readfn(void *handler, char *buf, int size)
+{
+ int count = 0;
+ fmem_t *mem = handler;
+ size_t available = mem->size - mem->pos;
+
+ if(size > available) size = available;
+ for(count=0; count < size; mem->pos++, count++)
+ buf[count] = mem->buffer[mem->pos];
+
+ return count;
+}
+
+static int writefn(void *handler, const char *buf, int size)
+{
+ int count = 0;
+ fmem_t *mem = handler;
+ size_t available = mem->size - mem->pos;
+
+ if(size > available) size = available;
+ for(count=0; count < size; mem->pos++, count++)
+ mem->buffer[mem->pos] = buf[count];
+
+ return count; // ? count : size;
+}
+
+static fpos_t seekfn(void *handler, fpos_t offset, int whence)
+{
+ size_t pos;
+ fmem_t *mem = handler;
+
+ switch(whence) {
+ case SEEK_SET: pos = offset; break;
+ case SEEK_CUR: pos = mem->pos + offset; break;
+ case SEEK_END: pos = mem->size + offset; break;
+ default: return -1;
+ }
+
+ if(pos > mem->size) return -1;
+
+ mem->pos = pos;
+ return (fpos_t) pos;
+}
+
+static int closefn(void *handler)
+{
+ free(handler);
+ return 0;
+}
+
+/* simple, but portable version of fmemopen for OS X / BSD */
+FILE *fmemopen(void *buf, size_t size, const char *mode)
+{
+ fmem_t *mem = (fmem_t *) malloc(sizeof(fmem_t));
+
+ memset(mem, 0, sizeof(fmem_t));
+ mem->size = size, mem->buffer = buf;
+ return funopen(mem, readfn, writefn, seekfn, closefn);
+}
+#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/src/memstream/open_memstream.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/memstream/open_memstream.c b/dfi/private/src/memstream/open_memstream.c
new file mode 100644
index 0000000..6bc4f01
--- /dev/null
+++ b/dfi/private/src/memstream/open_memstream.c
@@ -0,0 +1,130 @@
+/* Use funopen(3) to provide open_memstream(3) like functionality. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+struct memstream {
+ char **cp;
+ size_t *lenp;
+ size_t offset;
+};
+
+static void
+memstream_grow(struct memstream *ms, size_t newsize)
+{
+ char *buf;
+
+ if (newsize > *ms->lenp) {
+ buf = realloc(*ms->cp, newsize + 1);
+ if (buf != NULL) {
+#ifdef DEBUG
+ fprintf(stderr, "MS: %p growing from %zd to %zd\n",
+ ms, *ms->lenp, newsize);
+#endif
+ memset(buf + *ms->lenp + 1, 0, newsize - *ms->lenp);
+ *ms->cp = buf;
+ *ms->lenp = newsize;
+ }
+ }
+}
+
+static int
+memstream_read(void *cookie, char *buf, int len)
+{
+ struct memstream *ms;
+ int tocopy;
+
+ ms = cookie;
+ memstream_grow(ms, ms->offset + len);
+ tocopy = *ms->lenp - ms->offset;
+ if (len < tocopy)
+ tocopy = len;
+ memcpy(buf, *ms->cp + ms->offset, tocopy);
+ ms->offset += tocopy;
+#ifdef DEBUG
+ fprintf(stderr, "MS: read(%p, %d) = %d\n", ms, len, tocopy);
+#endif
+ return (tocopy);
+}
+
+static int
+memstream_write(void *cookie, const char *buf, int len)
+{
+ struct memstream *ms;
+ int tocopy;
+
+ ms = cookie;
+ memstream_grow(ms, ms->offset + len);
+ tocopy = *ms->lenp - ms->offset;
+ if (len < tocopy)
+ tocopy = len;
+ memcpy(*ms->cp + ms->offset, buf, tocopy);
+ ms->offset += tocopy;
+#ifdef DEBUG
+ fprintf(stderr, "MS: write(%p, %d) = %d\n", ms, len, tocopy);
+#endif
+ return (tocopy);
+}
+
+static fpos_t
+memstream_seek(void *cookie, fpos_t pos, int whence)
+{
+ struct memstream *ms;
+#ifdef DEBUG
+ size_t old;
+#endif
+
+ ms = cookie;
+#ifdef DEBUG
+ old = ms->offset;
+#endif
+ switch (whence) {
+ case SEEK_SET:
+ ms->offset = pos;
+ break;
+ case SEEK_CUR:
+ ms->offset += pos;
+ break;
+ case SEEK_END:
+ ms->offset = *ms->lenp + pos;
+ break;
+ }
+#ifdef DEBUG
+ fprintf(stderr, "MS: seek(%p, %zd, %d) %zd -> %zd\n", ms, pos, whence,
+ old, ms->offset);
+#endif
+ return (ms->offset);
+}
+
+static int
+memstream_close(void *cookie)
+{
+
+ free(cookie);
+ return (0);
+}
+
+FILE *
+open_memstream(char **cp, size_t *lenp)
+{
+ struct memstream *ms;
+ int save_errno;
+ FILE *fp;
+
+ *cp = NULL;
+ *lenp = 0;
+ ms = malloc(sizeof(*ms));
+ ms->cp = cp;
+ ms->lenp = lenp;
+ ms->offset = 0;
+ fp = funopen(ms, memstream_read, memstream_write, memstream_seek,
+ memstream_close);
+ if (fp == NULL) {
+ save_errno = errno;
+ free(ms);
+ errno = save_errno;
+ }
+ return (fp);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/avro_descriptor_translator_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/avro_descriptor_translator_tests.cpp b/dfi/private/test/avro_descriptor_translator_tests.cpp
new file mode 100644
index 0000000..c29932e
--- /dev/null
+++ b/dfi/private/test/avro_descriptor_translator_tests.cpp
@@ -0,0 +1,179 @@
+/**
+ *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.
+ */
+#include <CppUTest/TestHarness.h>
+#include "CppUTest/CommandLineTestRunner.h"
+
+extern "C" {
+
+#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+
+#include "dyn_common.h"
+#include "descriptor_translator.h"
+
+#if defined(BSD) || defined(__APPLE__)
+#include "open_memstream.h"
+#include "fmemopen.h"
+#endif
+
+ static void stdLog(void *handle, int level, const char *file, int line, const char *msg, ...) {
+ va_list ap;
+ const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
+ fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
+ va_start(ap, msg);
+ vfprintf(stderr, msg, ap);
+ fprintf(stderr, "\n");
+ }
+
+
+ static char *readSchema(const char *file) {
+ size_t size = 0;
+ char *ptr = NULL;
+
+ FILE *schema = fopen(file, "r");
+ FILE *stream = open_memstream(&ptr, &size);
+
+ assert(schema != NULL);
+ assert(stream != NULL);
+
+ int c = fgetc(schema);
+ while (c != EOF ) {
+ fputc(c, stream);
+ c = fgetc(schema);
+ }
+ fclose(schema);
+ fclose(stream);
+
+ assert(ptr != NULL);
+ return ptr;
+ }
+
+ static dyn_interface_type *createInterfaceInfo(const char *schemaFile) {
+ char *schema = readSchema(schemaFile);
+ dyn_interface_type *ift= NULL;
+
+ int status = descriptorTranslator_translate(schema, &ift);
+ CHECK_EQUAL(0, status);
+
+ free(schema);
+ return ift;
+ }
+
+ static int countMethodInfos(dyn_interface_type *info) {
+ int count = 0;
+ method_info_type *mInfo = NULL;
+ TAILQ_FOREACH(mInfo, &info->methodInfos, entries) {
+ count +=1;
+ }
+ return count;
+ }
+
+ static int countTypeInfos(dyn_interface_type *info) {
+ int count = 0;
+ type_info_type *tInfo = NULL;
+ TAILQ_FOREACH(tInfo, &info->typeInfos, entries) {
+ count +=1;
+ }
+ return count;
+ }
+
+ static void simple(void) {
+ //first argument void *handle, last argument output pointer for result and return int with status for exception handling
+ //sum(DD)D -> sum(PDD*D)N
+ //sub(DD)D -> sub(PDD*D)N
+ //sqrt(D)D -> sqrt(PD*D)N
+
+ dyn_interface_type *intf = createInterfaceInfo("schemas/simple.avpr");
+
+ int count = countMethodInfos(intf);
+ CHECK_EQUAL(3, count);
+
+ count = countTypeInfos(intf);
+ CHECK_EQUAL(0, count);
+
+ method_info_type *mInfo = NULL;
+ TAILQ_FOREACH(mInfo, &intf->methodInfos, entries) {
+ if (strcmp("sum", mInfo->name) == 0) {
+ STRCMP_EQUAL("sum(PDD*D)N", mInfo->descriptor);
+ } else if (strcmp("add", mInfo->name) == 0) {
+ STRCMP_EQUAL("add(PDD*D)N", mInfo->descriptor);
+ } else if (strcmp("sqrt", mInfo->name) == 0) {
+ STRCMP_EQUAL("sqrt(PD*D)N", mInfo->descriptor);
+ }
+ }
+
+ dynInterface_destroy(intf);
+ }
+
+ static void complex(void) {
+ dyn_interface_type *intf = createInterfaceInfo("schemas/complex.avpr");
+
+ int count = countMethodInfos(intf);
+ CHECK_EQUAL(1, count);
+
+ method_info_type *mInfo = TAILQ_FIRST(&intf->methodInfos);
+ STRCMP_EQUAL("stats", mInfo->name);
+ STRCMP_EQUAL("stats(P[D*LStatResult;)N", mInfo->descriptor);
+
+ count = countTypeInfos(intf);
+ CHECK_EQUAL(1, count);
+
+ type_info_type *tInfo = TAILQ_FIRST(&intf->typeInfos);
+ STRCMP_EQUAL("StatResult", tInfo->name);
+ STRCMP_EQUAL("{DDD[D sum min max input}", tInfo->descriptor);
+
+ dynInterface_destroy(intf);
+ }
+
+ static void invalid(const char *file) {
+ char *schema = readSchema(file);
+ dyn_interface_type *ift= NULL;
+
+ int status = descriptorTranslator_translate(schema, &ift);
+ CHECK(status != 0);
+
+ free(schema);
+ }
+}
+
+TEST_GROUP(AvroDescTranslatorTest) {
+ void setup() {
+ descriptorTranslator_logSetup(stdLog, NULL, 3);
+ dynInterface_logSetup(stdLog, NULL, 3);
+ dynType_logSetup(stdLog, NULL, 3);
+ dynCommon_logSetup(stdLog, NULL, 3);
+ }
+};
+
+TEST(AvroDescTranslatorTest, simple) {
+ simple();
+}
+
+TEST(AvroDescTranslatorTest, complex) {
+ complex();
+}
+
+TEST(AvroDescTranslatorTest, invalid1) {
+ invalid("schemas/invalid1.avpr");
+}
+
+TEST(AvroDescTranslatorTest, invalid2) {
+ invalid("schemas/invalid2.avpr");
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/descriptors/example1.descriptor
----------------------------------------------------------------------
diff --git a/dfi/private/test/descriptors/example1.descriptor b/dfi/private/test/descriptors/example1.descriptor
new file mode 100644
index 0000000..771dc5e
--- /dev/null
+++ b/dfi/private/test/descriptors/example1.descriptor
@@ -0,0 +1,13 @@
+:header
+type=interface
+name=calculator
+version=1.0.0
+:annotations
+classname=org.example.Calculator
+:types
+StatsResult={DDD[D average min max input}
+: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
+stats([D)LStatsResult;=stats(#am=handle;P[D#am=out;*LStatsResult;)N
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/descriptors/example2.descriptor
----------------------------------------------------------------------
diff --git a/dfi/private/test/descriptors/example2.descriptor b/dfi/private/test/descriptors/example2.descriptor
new file mode 100644
index 0000000..38bf442
--- /dev/null
+++ b/dfi/private/test/descriptors/example2.descriptor
@@ -0,0 +1,9 @@
+:header
+type=interface
+name=example
+version=1.0.0
+:annotations
+:types
+item={DD a b}
+:methods
+example1=items(#am=handle;P#am=out;**[Litem;)N
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/descriptors/example3.descriptor
----------------------------------------------------------------------
diff --git a/dfi/private/test/descriptors/example3.descriptor b/dfi/private/test/descriptors/example3.descriptor
new file mode 100644
index 0000000..c89d969
--- /dev/null
+++ b/dfi/private/test/descriptors/example3.descriptor
@@ -0,0 +1,11 @@
+:header
+type=interface
+name=detection_provider
+version=1.0.0
+:annotations
+:types
+location={DD lat lon}
+target={Jllocation;DDJ id location speed heading lastUpdated}
+detection={Jllocation;Dltarget; id center range simulated}
+:methods
+getDetections()Ljava/util/List;=getDetections(#am=handle;P#am=out;**[Ldetection;)N
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/descriptors/example4.descriptor
----------------------------------------------------------------------
diff --git a/dfi/private/test/descriptors/example4.descriptor b/dfi/private/test/descriptors/example4.descriptor
new file mode 100644
index 0000000..4c959c4
--- /dev/null
+++ b/dfi/private/test/descriptors/example4.descriptor
@@ -0,0 +1,8 @@
+:header
+type=interface
+name=example4
+version=1.0.0
+:annotations
+:types
+:methods
+getName(V)t=getName(#am=handle;P#am=out;*t)N
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/descriptors/msg_example1.descriptor
----------------------------------------------------------------------
diff --git a/dfi/private/test/descriptors/msg_example1.descriptor b/dfi/private/test/descriptors/msg_example1.descriptor
new file mode 100644
index 0000000..576523a
--- /dev/null
+++ b/dfi/private/test/descriptors/msg_example1.descriptor
@@ -0,0 +1,10 @@
+:header
+type=message
+name=poi
+version=1.0.0
+:annotations
+classname=org.example.PointOfInterest
+:types
+location={DD lat long}
+:message
+{llocation;tt location name description}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/descriptors/msg_example2.descriptor
----------------------------------------------------------------------
diff --git a/dfi/private/test/descriptors/msg_example2.descriptor b/dfi/private/test/descriptors/msg_example2.descriptor
new file mode 100644
index 0000000..128049d
--- /dev/null
+++ b/dfi/private/test/descriptors/msg_example2.descriptor
@@ -0,0 +1,12 @@
+:header
+type=message
+name=track
+version=0.0.1
+:annotations
+classname=org.example.Track
+:types
+timestamp={SSSSSSI day month year hour minute second microseconds}
+latlonpos={DD lat lon}
+polarpos={DDD azimuth elevation range}
+:message
+{Iltimestamp;llatlonpos;lpolarpos;SS trackid lastupdate abspos relpos classification identity}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/descriptors/msg_example3.descriptor
----------------------------------------------------------------------
diff --git a/dfi/private/test/descriptors/msg_example3.descriptor b/dfi/private/test/descriptors/msg_example3.descriptor
new file mode 100644
index 0000000..7b69380
--- /dev/null
+++ b/dfi/private/test/descriptors/msg_example3.descriptor
@@ -0,0 +1,10 @@
+:header
+type=message
+name=logEntry
+version=1.0.0
+:annotations
+classname=org.example.LogEntry
+:types
+timestamp={SSSSSSI day month year hour minute second microseconds}
+:message
+{ltimestamp;St timestamp severity eventdescription}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/dyn_closure_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/dyn_closure_tests.cpp b/dfi/private/test/dyn_closure_tests.cpp
new file mode 100644
index 0000000..ce70f93
--- /dev/null
+++ b/dfi/private/test/dyn_closure_tests.cpp
@@ -0,0 +1,161 @@
+/**
+ *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.
+ */
+#include <CppUTest/TestHarness.h>
+#include "CppUTest/CommandLineTestRunner.h"
+
+extern "C" {
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "dyn_common.h"
+#include "dyn_function.h"
+
+static int g_count;
+
+static void stdLog(void *handle, int level, const char *file, int line, const char *msg, ...) {
+ va_list ap;
+ const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
+ fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
+ va_start(ap, msg);
+ vfprintf(stderr, msg, ap);
+ fprintf(stderr, "\n");
+}
+
+#define EXAMPLE1_DESCRIPTOR "example(III)I"
+static void example1_binding(void *userData, void* args[], void *out) {
+ int32_t a = *((int32_t *)args[0]);
+ int32_t b = *((int32_t *)args[1]);
+ int32_t c = *((int32_t *)args[2]);
+ int32_t *ret = (int32_t *)out;
+ *ret = a + b + c;
+ g_count += 1;
+}
+
+#define EXAMPLE2_DESCRIPTOR "example(I{DDD val1 val2 val3}I)D"
+struct example2_arg2 {
+ double val1;
+ double val2;
+ double val3;
+};
+void example2_binding(void *userData, void* args[], void *out) {
+ int32_t a = *((int32_t *)args[0]);
+ struct example2_arg2 b = *((struct example2_arg2 *)args[1]);
+ int32_t c = *((int32_t *)args[2]);
+ double *ret = (double *)out;
+ *ret = a + b.val1 + b.val2 + b.val3 + c;
+ g_count += 1;
+}
+
+
+#define EXAMPLE3_DESCRIPTOR "example(III){III sum max min}"
+struct example3_ret {
+ int32_t sum;
+ int32_t max;
+ int32_t min;
+};
+
+static void example3_binding(void *userData, void* args[], void *out) {
+ int32_t a = *((int32_t *)args[0]);
+ int32_t b = *((int32_t *)args[1]);
+ int32_t c = *((int32_t *)args[2]);
+ struct example3_ret *result = (struct example3_ret *)calloc(1,sizeof(struct example3_ret));
+ result->sum = a + b + c;
+ result->min = a <= b ? a : b;
+ result->max = a >= b ? a : b;
+ result->min = result->min <= c ? result->min : c;
+ result->max = result->max >= c ? result->max : c;
+
+ struct example3_ret **ret = (struct example3_ret **)out;
+ (*ret) = result;
+ g_count += 1;
+}
+
+static void tests() {
+ dyn_function_type *dynFunction = NULL;
+ int rc = 0;
+
+ {
+ int32_t (*func)(int32_t a, int32_t b, int32_t c) = NULL;
+ rc = dynFunction_parseWithStr(EXAMPLE1_DESCRIPTOR, NULL, &dynFunction);
+ CHECK_EQUAL(0, rc);
+ rc = dynFunction_createClosure(dynFunction, example1_binding, NULL, (void(**)(void))&func);
+ CHECK_EQUAL(0, rc);
+ int32_t ret = func(2,3,4);
+ CHECK_EQUAL(1, g_count);
+ CHECK_EQUAL(9, ret);
+ dynFunction_destroy(dynFunction);
+ }
+
+ {
+ double (*func)(int32_t a, struct example2_arg2 b, int32_t c) = NULL;
+ double (*func2)(int32_t a, struct example2_arg2 b, int32_t c) = NULL;
+ dynFunction = NULL;
+ rc = dynFunction_parseWithStr(EXAMPLE2_DESCRIPTOR, NULL, &dynFunction);
+ CHECK_EQUAL(0, rc);
+ rc = dynFunction_createClosure(dynFunction, example2_binding, NULL, (void(**)(void))&func);
+ CHECK_EQUAL(0, rc);
+ rc = dynFunction_getFnPointer(dynFunction, (void(**)(void))&func2);
+ CHECK_EQUAL(0, rc);
+ CHECK(func == func2);
+ struct example2_arg2 b;
+ b.val1 = 1.0;
+ b.val2 = 1.5;
+ b.val3 = 2.0;
+ double ret = func(2,b,4);
+ CHECK_EQUAL(2, g_count);
+ CHECK_EQUAL(10.5, ret);
+ dynFunction_destroy(dynFunction);
+ }
+
+ {
+ struct example3_ret * (*func)(int32_t a, int32_t b, int32_t c) = NULL;
+ dynFunction = NULL;
+ rc = dynFunction_parseWithStr(EXAMPLE3_DESCRIPTOR, NULL, &dynFunction);
+ CHECK_EQUAL(0, rc);
+ rc = dynFunction_createClosure(dynFunction, example3_binding, NULL, (void(**)(void))&func);
+ CHECK_EQUAL(0, rc);
+ struct example3_ret *ret = func(2,8,4);
+ CHECK_EQUAL(3, g_count);
+ CHECK_EQUAL(14, ret->sum);
+ dynFunction_destroy(dynFunction);
+ free(ret);
+ }
+}
+
+}
+
+
+TEST_GROUP(DynClosureTests) {
+ void setup() {
+ int lvl = 1;
+ dynFunction_logSetup(stdLog, NULL, lvl);
+ dynType_logSetup(stdLog, NULL, lvl);
+ dynCommon_logSetup(stdLog, NULL, lvl);
+ g_count = 0;
+ }
+};
+
+TEST(DynClosureTests, DynCLosureTest1) {
+ //TODO split up
+ tests();
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/dyn_function_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/dyn_function_tests.cpp b/dfi/private/test/dyn_function_tests.cpp
new file mode 100644
index 0000000..2279331
--- /dev/null
+++ b/dfi/private/test/dyn_function_tests.cpp
@@ -0,0 +1,252 @@
+/**
+ *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.
+ */
+#include <CppUTest/TestHarness.h>
+#include "CppUTest/CommandLineTestRunner.h"
+
+extern "C" {
+ #include <stdio.h>
+ #include <stdint.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <ctype.h>
+
+
+ #include "dyn_common.h"
+ #include "dyn_function.h"
+
+ static void stdLog(void *handle, int level, const char *file, int line, const char *msg, ...) {
+ va_list ap;
+ const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
+ fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
+ va_start(ap, msg);
+ vfprintf(stderr, msg, ap);
+ fprintf(stderr, "\n");
+ }
+
+ #define EXAMPLE1_DESCRIPTOR "example(III)I"
+ int32_t example1(int32_t a, int32_t b, int32_t c) {
+ CHECK_EQUAL(2, a);
+ CHECK_EQUAL(4, b);
+ CHECK_EQUAL(8, c);
+ return 1;
+ }
+
+ void test_example1(void) {
+ dyn_function_type *dynFunc = NULL;
+ int rc;
+ void (*fp)(void) = (void (*)(void)) example1;
+
+ rc = dynFunction_parseWithStr(EXAMPLE1_DESCRIPTOR, NULL, &dynFunc);
+ CHECK_EQUAL(0, rc);
+
+ int32_t a = 2;
+ int32_t b = 4;
+ int32_t c = 8;
+ void *values[3];
+ int32_t rVal = 0;
+ values[0] = &a;
+ values[1] = &b;
+ values[2] = &c;
+
+ rc = dynFunction_call(dynFunc, fp, &rVal, values);
+ CHECK_EQUAL(0, rc);
+ CHECK_EQUAL(1, rVal);
+ dynFunction_destroy(dynFunc);
+ }
+
+ #define EXAMPLE2_DESCRIPTOR "example(I{IID val1 val2 val3}D)D"
+ struct example2_arg {
+ int32_t val1;
+ int32_t val2;
+ double val3;
+ };
+
+ double example2(int32_t arg1, struct example2_arg arg2, double arg3) {
+ CHECK_EQUAL(2, arg1);
+ CHECK_EQUAL(2, arg2.val1);
+ CHECK_EQUAL(3, arg2.val2);
+ CHECK_EQUAL(4.1, arg2.val3);
+ CHECK_EQUAL(8.1, arg3);
+ return 2.2;
+ }
+
+ void test_example2(void) {
+ dyn_function_type *dynFunc = NULL;
+ int rc;
+ void (*fp)(void) = (void (*)(void)) example2;
+
+ rc = dynFunction_parseWithStr(EXAMPLE2_DESCRIPTOR, NULL, &dynFunc);
+ CHECK_EQUAL(0, rc);
+
+ int32_t arg1 = 2;
+ struct example2_arg arg2;
+ arg2.val1 = 2;
+ arg2.val2 = 3;
+ arg2.val3 = 4.1;
+ double arg3 = 8.1;
+ double returnVal = 0;
+ void *values[3];
+ values[0] = &arg1;
+ values[1] = &arg2;
+ values[2] = &arg3;
+
+ rc = dynFunction_call(dynFunc, fp, &returnVal, values);
+ CHECK_EQUAL(0, rc);
+ CHECK_EQUAL(2.2, returnVal);
+ dynFunction_destroy(dynFunc);
+ }
+
+ static void test_access_functions(void) {
+ dyn_function_type *dynFunc = NULL;
+ int rc;
+ rc = dynFunction_parseWithStr("add(D{DD a b}*D)V", NULL, &dynFunc);
+
+ CHECK_EQUAL(0, rc);
+
+ int nrOfArgs = dynFunction_nrOfArguments(dynFunc);
+ CHECK_EQUAL(3, nrOfArgs);
+
+ dyn_type *arg1 = dynFunction_argumentTypeForIndex(dynFunc, 1);
+ CHECK(arg1 != NULL);
+ CHECK_EQUAL('{', (char) dynType_descriptorType(arg1));
+
+ dyn_type *nonExist = dynFunction_argumentTypeForIndex(dynFunc, 10);
+ CHECK(nonExist == NULL);
+
+ dyn_type *returnType = dynFunction_returnType(dynFunc);
+ CHECK_EQUAL('V', (char) dynType_descriptorType(returnType));
+
+ dynFunction_destroy(dynFunc);
+ }
+
+ //example with gen pointer and output
+ #define EXAMPLE3_DESCRIPTOR "example(PD*D)N"
+
+ static int testExample3(void *ptr, double a, double *out) {
+ double *b = (double *)ptr;
+ CHECK_EQUAL(2.0, *b)
+ CHECK_EQUAL(a, 2.0);
+ *out = *b * a;
+ return 0;
+ }
+
+ static void test_example3(void) {
+ dyn_function_type *dynFunc = NULL;
+ void (*fp)(void) = (void(*)(void)) testExample3;
+ int rc;
+
+ rc = dynFunction_parseWithStr(EXAMPLE3_DESCRIPTOR, NULL, &dynFunc);
+ CHECK_EQUAL(0, rc);
+ double result = -1.0;
+ double *input = &result;
+ double a = 2.0;
+ void *ptr = &a;
+ void *args[3];
+ args[0] = &ptr;
+ args[1] = &a;
+ args[2] = &input;
+ int rVal = 0;
+ rc = dynFunction_call(dynFunc, fp, &rVal, args);
+ CHECK_EQUAL(0, rc);
+ CHECK_EQUAL(4.0, result);
+
+
+ double *inMemResult = (double *)calloc(1, sizeof(double));
+ a = 2.0;
+ ptr = &a;
+ args[0] = &ptr;
+ args[1] = &a;
+ args[2] = &inMemResult;
+ rVal = 0;
+ rc = dynFunction_call(dynFunc, fp, &rVal, args);
+ CHECK_EQUAL(0, rc);
+ CHECK_EQUAL(4.0, result);
+ free(inMemResult);
+
+ dynFunction_destroy(dynFunc);
+ }
+
+ struct tst_seq {
+ uint32_t cap;
+ uint32_t len;
+ double *buf;
+ };
+
+ #define EXAMPLE4_DESCRIPTOR "example([D)V"
+
+ static void example4Func(struct tst_seq seq) {
+ CHECK_EQUAL(4, seq.cap);
+ CHECK_EQUAL(2, seq.len);
+ CHECK_EQUAL(1.1, seq.buf[0]);
+ CHECK_EQUAL(2.2, seq.buf[1]);
+ }
+
+ static void test_example4(void) {
+ dyn_function_type *dynFunc = NULL;
+ void (*fp)(void) = (void(*)(void)) example4Func;
+ int rc;
+
+ rc = dynFunction_parseWithStr(EXAMPLE4_DESCRIPTOR, NULL, &dynFunc);
+ CHECK_EQUAL(0, rc);
+
+ double buf[4];
+ buf[0] = 1.1;
+ buf[1] = 2.2;
+ struct tst_seq seq;
+ seq.cap = 4;
+ seq.len = 2;
+ seq.buf = buf;
+
+ void *args[1];
+ args[0] = &seq;
+ rc = dynFunction_call(dynFunc, fp, NULL, args);
+ CHECK_EQUAL(0, rc);
+
+ dynFunction_destroy(dynFunc);
+ }
+}
+
+TEST_GROUP(DynFunctionTests) {
+ void setup() {
+ int lvl = 1;
+ dynFunction_logSetup(stdLog, NULL, lvl);
+ dynType_logSetup(stdLog, NULL, lvl);
+ dynCommon_logSetup(stdLog, NULL, lvl);
+ }
+};
+
+TEST(DynFunctionTests, DynFuncTest1) {
+ test_example1();
+}
+
+TEST(DynFunctionTests, DynFuncTest2) {
+ test_example2();
+}
+
+TEST(DynFunctionTests, DynFuncAccTest) {
+ test_access_functions();
+}
+
+TEST(DynFunctionTests, DynFuncTest3) {
+ test_example3();
+}
+
+TEST(DynFunctionTests, DynFuncTest4) {
+ test_example4();
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/dyn_interface_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/dyn_interface_tests.cpp b/dfi/private/test/dyn_interface_tests.cpp
new file mode 100644
index 0000000..83afb9b
--- /dev/null
+++ b/dfi/private/test/dyn_interface_tests.cpp
@@ -0,0 +1,118 @@
+/**
+ *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.
+ */
+#include <CppUTest/TestHarness.h>
+#include "CppUTest/CommandLineTestRunner.h"
+extern "C" {
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <assert.h>
+
+#include "dyn_common.h"
+#include "dyn_interface.h"
+
+#if defined(BSD) || defined(__APPLE__)
+#include "open_memstream.h"
+#include "fmemopen.h"
+#endif
+
+ static void stdLog(void *handle, int level, const char *file, int line, const char *msg, ...) {
+ va_list ap;
+ const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
+ fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
+ va_start(ap, msg);
+ vfprintf(stderr, msg, ap);
+ fprintf(stderr, "\n");
+ }
+
+ static void test1(void) {
+ int status = 0;
+ dyn_interface_type *dynIntf = NULL;
+ FILE *desc = fopen("descriptors/example1.descriptor", "r");
+ assert(desc != NULL);
+ status = dynInterface_parse(desc, &dynIntf);
+ CHECK_EQUAL(0, status);
+ fclose(desc);
+
+ char *name = NULL;
+ status = dynInterface_getName(dynIntf, &name);
+ CHECK_EQUAL(0, status);
+ STRCMP_EQUAL("calculator", name);
+
+ char *version = NULL;
+ status = dynInterface_getVersion(dynIntf, &version);
+ CHECK_EQUAL(0, status);
+ STRCMP_EQUAL("1.0.0", version);
+
+ char *annVal = NULL;
+ status = dynInterface_getAnnotationEntry(dynIntf, "classname", &annVal);
+ CHECK_EQUAL(0, status);
+ STRCMP_EQUAL("org.example.Calculator", annVal);
+
+ char *nonExist = NULL;
+ status = dynInterface_getHeaderEntry(dynIntf, "nonExisting", &nonExist);
+ CHECK(status != 0);
+ CHECK(nonExist == NULL);
+
+ struct methods_head *list = NULL;
+ status = dynInterface_methods(dynIntf, &list);
+ CHECK(status == 0);
+ CHECK(list != NULL);
+
+ int count = dynInterface_nrOfMethods(dynIntf);
+ CHECK_EQUAL(4, count);
+
+ dynInterface_destroy(dynIntf);
+ }
+
+ static void test2(void) {
+ int status = 0;
+ dyn_interface_type *dynIntf = NULL;
+ FILE *desc = fopen("descriptors/example3.descriptor", "r");
+ assert(desc != NULL);
+ status = dynInterface_parse(desc, &dynIntf);
+ CHECK_EQUAL(0, status);
+ fclose(desc);
+
+ dynInterface_destroy(dynIntf);
+ }
+
+}
+
+
+TEST_GROUP(DynInterfaceTests) {
+ void setup() {
+ int level = 1;
+ dynCommon_logSetup(stdLog, NULL, level);
+ dynType_logSetup(stdLog, NULL, level);
+ dynFunction_logSetup(stdLog, NULL, level);
+ dynInterface_logSetup(stdLog, NULL, level);
+ }
+};
+
+TEST(DynInterfaceTests, test1) {
+ test1();
+}
+
+TEST(DynInterfaceTests, test2) {
+ test2();
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/dyn_message_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/dyn_message_tests.cpp b/dfi/private/test/dyn_message_tests.cpp
new file mode 100644
index 0000000..e30d16e
--- /dev/null
+++ b/dfi/private/test/dyn_message_tests.cpp
@@ -0,0 +1,184 @@
+/**
+ *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.
+ */
+#include <CppUTest/TestHarness.h>
+#include "CppUTest/CommandLineTestRunner.h"
+
+extern "C" {
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <assert.h>
+
+#include "dyn_common.h"
+#include "dyn_message.h"
+
+#if defined(BSD) || defined(__APPLE__)
+#include "open_memstream.h"
+#include "fmemopen.h"
+#endif
+
+static void stdLog(void *handle, int level, const char *file, int line, const char *msg, ...) {
+ va_list ap;
+ const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
+ fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
+ va_start(ap, msg);
+ vfprintf(stderr, msg, ap);
+ fprintf(stderr, "\n");
+}
+
+
+static void msg_test1(void) {
+ int status = 0;
+ dyn_message_type *dynMsg = NULL;
+ FILE *desc = fopen("descriptors/msg_example1.descriptor", "r");
+ assert(desc != NULL);
+ status = dynMessage_parse(desc, &dynMsg);
+ CHECK_EQUAL(0, status);
+ fclose(desc);
+
+ char *name = NULL;
+ status = dynMessage_getName(dynMsg, &name);
+ CHECK_EQUAL(0, status);
+ STRCMP_EQUAL("poi", name);
+
+ char *version = NULL;
+ status = dynMessage_getVersion(dynMsg, &version);
+ CHECK_EQUAL(0, status);
+ STRCMP_EQUAL("1.0.0", version);
+
+ char *annVal = NULL;
+ status = dynMessage_getAnnotationEntry(dynMsg, "classname", &annVal);
+ CHECK_EQUAL(0, status);
+ STRCMP_EQUAL("org.example.PointOfInterest", annVal);
+
+ char *nonExist = NULL;
+ status = dynMessage_getHeaderEntry(dynMsg, "nonExisting", &nonExist);
+ CHECK(status != 0);
+ CHECK(nonExist == NULL);
+
+ dyn_type *msgType = NULL;
+ status = dynMessage_getMessageType(dynMsg, &msgType);
+ CHECK_EQUAL(0, status);
+ CHECK(msgType != NULL);
+
+ dynMessage_destroy(dynMsg);
+}
+
+
+static void msg_test2(void) {
+ int status = 0;
+ dyn_message_type *dynMsg = NULL;
+ FILE *desc = fopen("descriptors/msg_example2.descriptor", "r");
+ assert(desc != NULL);
+ status = dynMessage_parse(desc, &dynMsg);
+ CHECK_EQUAL(0, status);
+ fclose(desc);
+
+ char *name = NULL;
+ status = dynMessage_getName(dynMsg, &name);
+ CHECK_EQUAL(0, status);
+ STRCMP_EQUAL("track", name);
+
+ char *version = NULL;
+ status = dynMessage_getVersion(dynMsg, &version);
+ CHECK_EQUAL(0, status);
+ STRCMP_EQUAL("0.0.1", version);
+
+ char *annVal = NULL;
+ status = dynMessage_getAnnotationEntry(dynMsg, "classname", &annVal);
+ CHECK_EQUAL(0, status);
+ STRCMP_EQUAL("org.example.Track", annVal);
+
+ char *nonExist = NULL;
+ status = dynMessage_getHeaderEntry(dynMsg, "nonExisting", &nonExist);
+ CHECK(status != 0);
+ CHECK(nonExist == NULL);
+
+ dyn_type *msgType = NULL;
+ status = dynMessage_getMessageType(dynMsg, &msgType);
+ CHECK_EQUAL(0, status);
+ CHECK(msgType != NULL);
+
+ dynMessage_destroy(dynMsg);
+}
+
+static void msg_test3(void) {
+ int status = 0;
+ dyn_message_type *dynMsg = NULL;
+ FILE *desc = fopen("descriptors/msg_example3.descriptor", "r");
+ assert(desc != NULL);
+ status = dynMessage_parse(desc, &dynMsg);
+ CHECK_EQUAL(0, status);
+ fclose(desc);
+
+ char *name = NULL;
+ status = dynMessage_getName(dynMsg, &name);
+ CHECK_EQUAL(0, status);
+ STRCMP_EQUAL("logEntry", name);
+
+ char *version = NULL;
+ status = dynMessage_getVersion(dynMsg, &version);
+ CHECK_EQUAL(0, status);
+ STRCMP_EQUAL("1.0.0", version);
+
+ char *annVal = NULL;
+ status = dynMessage_getAnnotationEntry(dynMsg, "classname", &annVal);
+ CHECK_EQUAL(0, status);
+ STRCMP_EQUAL("org.example.LogEntry", annVal);
+
+ char *nonExist = NULL;
+ status = dynMessage_getHeaderEntry(dynMsg, "nonExisting", &nonExist);
+ CHECK(status != 0);
+ CHECK(nonExist == NULL);
+
+ dyn_type *msgType = NULL;
+ status = dynMessage_getMessageType(dynMsg, &msgType);
+ CHECK_EQUAL(0, status);
+ CHECK(msgType != NULL);
+
+ dynMessage_destroy(dynMsg);
+}
+
+}
+
+
+TEST_GROUP(DynMessageTests) {
+ void setup() {
+ int level = 1;
+ dynCommon_logSetup(stdLog, NULL, level);
+ dynType_logSetup(stdLog, NULL, level);
+ dynMessage_logSetup(stdLog, NULL, level);
+ }
+};
+
+
+TEST(DynMessageTests, msg_test1) {
+ msg_test1();
+}
+
+TEST(DynMessageTests, msg_test2) {
+ msg_test2();
+}
+
+TEST(DynMessageTests, msg_test3) {
+ msg_test3();
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/dyn_type_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/dyn_type_tests.cpp b/dfi/private/test/dyn_type_tests.cpp
new file mode 100644
index 0000000..db95da4
--- /dev/null
+++ b/dfi/private/test/dyn_type_tests.cpp
@@ -0,0 +1,296 @@
+/**
+ *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.
+ */
+#include <CppUTest/TestHarness.h>
+#include "CppUTest/CommandLineTestRunner.h"
+
+extern "C" {
+ #include <stdarg.h>
+
+ #include "dyn_common.h"
+ #include "dyn_type.h"
+
+ static void stdLog(void *handle, int level, const char *file, int line, const char *msg, ...) {
+ va_list ap;
+ const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
+ fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
+ va_start(ap, msg);
+ vfprintf(stderr, msg, ap);
+ fprintf(stderr, "\n");
+ }
+
+ static void runTest(const char *descriptorStr, const char *exName) {
+ dyn_type *type;
+ type = NULL;
+ //printf("\n-- example %s with descriptor string '%s' --\n", exName, descriptorStr);
+ int status = dynType_parseWithStr(descriptorStr, exName, NULL, &type);
+ CHECK_EQUAL(0, status);
+
+ //MEM check, to try to ensure no mem leaks/corruptions occur.
+ int i;
+ int j;
+ int nrOfBurst = 10;
+ int burst = 50;
+ void *pointers[burst];
+ for (j = 0; j < nrOfBurst; j += 1) {
+ for (i = 0; i < burst ; i +=1 ) {
+ pointers[i] = NULL;
+ dynType_alloc(type, &pointers[i]);
+ }
+ for (i = 0; i < burst ; i +=1 ) {
+ dynType_free(type, pointers[i]);
+ }
+ }
+
+ FILE *stream = fopen("/dev/null", "w");
+ dynType_print(type, stream);
+ fclose(stream);
+ dynType_destroy(type);
+ //printf("--\n\n");
+ }
+}
+
+TEST_GROUP(DynTypeTests) {
+ void setup() {
+ dynType_logSetup(stdLog, NULL, 1);
+ }
+};
+
+#define EX1 "{BbJjIiSsDFNN arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 arg10 arg11 arg12}"
+#define EX2 "{D{DD b_1 b_2}I a b c}"
+#define EX3 "Tsub={DD b_1 b_2};{DLsub;I a b c}"
+#define EX4 "{[I numbers}"
+#define EX5 "[[{DD{iii val3_1 val3_2 val3_3} val1 val2 val3}"
+#define EX6 "Tsample={DD vala valb};Lsample;"
+#define EX7 "Tsample={DD vala valb};[Lsample;"
+#define EX8 "[Tsample={DD a b};Lsample;"
+#define EX9 "*D"
+#define EX10 "Tsample={DD a b};******Lsample;"
+#define EX11 "Tsample=D;Lsample;"
+#define EX12 "Tnode={Lnode;Lnode; left right};{Lnode; head}" //note recursive example
+#define EX13 "Ttype={DDDDD a b c d e};{ltype;Ltype;ltype;Ltype; byVal1 byRef1 byVal2 ByRef2}"
+#define EX14 "{DD{FF{JJ}{II*{ss}}}}" //unnamed fields
+#define EX15 "Tsample={jDD time val1 val2};Tresult={jDlsample; time result sample};Lresult;"
+#define EX16 "Tpoi={BDD id lat lon};Lpoi;"
+
+#define CREATE_EXAMPLES_TEST(DESC) \
+ TEST(DynTypeTests, ParseTestExample ## DESC) { \
+ runTest(DESC, #DESC); \
+ }
+
+CREATE_EXAMPLES_TEST(EX1)
+CREATE_EXAMPLES_TEST(EX2)
+CREATE_EXAMPLES_TEST(EX3)
+CREATE_EXAMPLES_TEST(EX4)
+CREATE_EXAMPLES_TEST(EX5)
+CREATE_EXAMPLES_TEST(EX6)
+CREATE_EXAMPLES_TEST(EX7)
+CREATE_EXAMPLES_TEST(EX8)
+CREATE_EXAMPLES_TEST(EX9)
+CREATE_EXAMPLES_TEST(EX10)
+CREATE_EXAMPLES_TEST(EX11)
+CREATE_EXAMPLES_TEST(EX12)
+CREATE_EXAMPLES_TEST(EX13)
+CREATE_EXAMPLES_TEST(EX14)
+CREATE_EXAMPLES_TEST(EX15)
+CREATE_EXAMPLES_TEST(EX16)
+
+TEST(DynTypeTests, ParseRandomGarbageTest) {
+ /*
+ unsigned int seed = 4148;
+ char *testRandom = getenv("DYN_TYPE_TEST_RANDOM");
+ if (testRandom != NULL && strcmp("true", testRandom) == 0) {
+ seed = (unsigned int) time(NULL);
+ }
+ srandom(seed);
+ size_t nrOfTests = 100;
+
+ printf("\nStarting test with random seed %i and nrOfTests %zu.\n", seed, nrOfTests);
+
+ int i;
+ int k;
+ int c;
+ int sucesses = 0;
+ char descriptorStr[32];
+ descriptorStr[31] = '\0';
+ for(i = 0; i < nrOfTests; i += 1) {
+ for(k = 0; k < 31; k += 1) {
+ do {
+ c = (char) (((random() * 128) / RAND_MAX) - 1);
+ } while (!isprint(c));
+ descriptorStr[k] = c;
+ if (c == '\0') {
+ break;
+ }
+ }
+
+ //printf("ParseRandomGarbageTest iteration %i with descriptor string '%s'\n", k, descriptorStr);
+ dyn_type *type = NULL;
+ int status = dynType_parseWithStr(descriptorStr, NULL, NULL, &type);
+ if (status == 0) {
+ dynType_destroy(type);
+ }
+ }
+ */
+}
+
+TEST(DynTypeTests, AssignTest1) {
+ struct ex1 {
+ int32_t a;
+ int32_t b;
+ int32_t c;
+ };
+ struct ex1 inst;
+ const char *desc = "{III a b c}";
+ dyn_type *type = NULL;
+ int status = dynType_parseWithStr(desc, NULL, NULL, &type);
+ CHECK_EQUAL(0, status);
+ int32_t val1 = 2;
+ int32_t val2 = 4;
+ int32_t val3 = 8;
+ dynType_complex_setValueAt(type, 0, &inst, &val1);
+ CHECK_EQUAL(2, inst.a);
+ dynType_complex_setValueAt(type, 1, &inst, &val2);
+ CHECK_EQUAL(4, inst.b);
+ dynType_complex_setValueAt(type, 2, &inst, &val3);
+ CHECK_EQUAL(8, inst.c);
+
+ dynType_destroy(type);
+}
+
+TEST(DynTypeTests, AssignTest2) {
+ struct ex {
+ int32_t a;
+ struct {
+ double a;
+ double b;
+ } b;
+ };
+ struct ex inst;
+ const char *desc = "{I{DD a b} a b}";
+ dyn_type *type = NULL;
+ int status = dynType_parseWithStr(desc, NULL, NULL, &type);
+ CHECK_EQUAL(0, status);
+ int32_t a = 2;
+ double b_a = 1.1;
+ double b_b = 1.2;
+
+ dynType_complex_setValueAt(type, 0, &inst, &a);
+ CHECK_EQUAL(2, inst.a);
+
+ void *loc = NULL;
+ dyn_type *subType = NULL;
+ dynType_complex_valLocAt(type, 1, (void *)&inst, &loc);
+ dynType_complex_dynTypeAt(type, 1, &subType);
+
+ dynType_complex_setValueAt(subType, 0, &inst.b, &b_a);
+ CHECK_EQUAL(1.1, inst.b.a);
+
+ dynType_complex_setValueAt(subType, 1, &inst.b, &b_b);
+ CHECK_EQUAL(1.2, inst.b.b);
+
+ dynType_destroy(type);
+}
+
+TEST(DynTypeTests, AssignTest3) {
+ int simple = 1;
+ dyn_type *type = NULL;
+ int rc = dynType_parseWithStr("N", NULL, NULL, &type);
+ CHECK_EQUAL(0, rc);
+
+ int newValue = 42;
+ void *loc = &simple;
+ void *input = &newValue;
+ dynType_simple_setValue(type, loc, input);
+ CHECK_EQUAL(42, simple);
+ dynType_destroy(type);
+}
+
+TEST(DynTypeTests, MetaInfoTest) {
+ dyn_type *type = NULL;
+ int rc = 0;
+ rc = dynType_parseWithStr("#a=t;{DD#longname=longvalue;D a b c}", NULL, NULL, &type);
+ //rc = dynType_parseWithStr("{DDD a b c}", NULL, NULL, &type);
+
+ CHECK_EQUAL(0, rc);
+
+ const char *val = NULL;
+ val = dynType_getMetaInfo(type, "a");
+ CHECK(val != NULL);
+ CHECK(strcmp("t", val) == 0);
+
+ val = dynType_getMetaInfo(type, "longname");
+ CHECK(val == NULL);
+
+ val = dynType_getMetaInfo(type, "nonexisting");
+ CHECK(val == NULL);
+
+ dynType_destroy(type);
+}
+
+TEST(DynTypeTests, SequenceWithPointerTest) {
+ struct val {
+ double a;
+ double b;
+ };
+
+ struct item {
+ int64_t a;
+ const char *text;
+ struct val val;
+ double c;
+ double d;
+ long e;
+ };
+
+ struct item_sequence {
+ uint32_t cap;
+ uint32_t len;
+ struct item **buf;
+ };
+
+ dyn_type *type = NULL;
+ int rc = 0;
+ rc = dynType_parseWithStr("Tval={DD a b};Titem={Jtlval;DDJ a text val c d e};**[Litem;", NULL, NULL, &type);
+ CHECK_EQUAL(0, rc);
+
+ struct item_sequence *seq = NULL;
+ rc = dynType_alloc(type, (void **)&seq);
+ CHECK_EQUAL(0, rc);
+ CHECK(seq != NULL);
+
+ dynType_free(type, seq);
+
+ /*
+
+
+ struct item_sequence *items = (struct item_sequence *) calloc(1,sizeof(struct item_sequence));
+ items->buf = (struct item **) calloc(2, sizeof(struct item *));
+ items->cap = 2;
+ items->len = 2;
+ items->buf[0] = (struct item *)calloc(1, sizeof(struct item));
+ items->buf[0]->text = strdup("boe");
+ items->buf[1] = (struct item *)calloc(1, sizeof(struct item));
+ items->buf[1]->text = strdup("boe2");
+
+ dynType_free(type, items);
+ */
+
+ dynType_destroy(type);
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/test/json_rpc_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/json_rpc_tests.cpp b/dfi/private/test/json_rpc_tests.cpp
new file mode 100644
index 0000000..8b4044d
--- /dev/null
+++ b/dfi/private/test/json_rpc_tests.cpp
@@ -0,0 +1,428 @@
+/**
+ *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.
+ */
+#include <CppUTest/TestHarness.h>
+#include <float.h>
+#include <assert.h>
+#include "CppUTest/CommandLineTestRunner.h"
+
+extern "C" {
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include <ffi.h>
+
+#include "dyn_common.h"
+#include "dyn_type.h"
+#include "json_serializer.h"
+#include "json_rpc.h"
+
+static void stdLog(void *handle, int level, const char *file, int line, const char *msg, ...) {
+ va_list ap;
+ const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
+ fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
+ va_start(ap, msg);
+ vfprintf(stderr, msg, ap);
+ fprintf(stderr, "\n");
+}
+
+
+ void prepareTest(void) {
+ dyn_function_type *dynFunc = NULL;
+ int rc = dynFunction_parseWithStr("add(#am=handle;PDD#am=pre;*D)N", NULL, &dynFunc);
+ CHECK_EQUAL(0, rc);
+
+ char *result = NULL;
+
+ void *handle = NULL;
+ double arg1 = 1.0;
+ double arg2 = 2.0;
+
+ void *args[4];
+ args[0] = &handle;
+ args[1] = &arg1;
+ args[2] = &arg2;
+
+ rc = jsonRpc_prepareInvokeRequest(dynFunc, "add", args, &result);
+ CHECK_EQUAL(0, rc);
+
+ //printf("result is %s\n", result);
+
+ STRCMP_CONTAINS("\"add\"", result);
+ STRCMP_CONTAINS("1.0", result);
+ STRCMP_CONTAINS("2.0", result);
+
+ free(result);
+ dynFunction_destroy(dynFunc);
+ }
+
+ void handleTestPre(void) {
+ dyn_function_type *dynFunc = NULL;
+ int rc = dynFunction_parseWithStr("add(#am=handle;PDD#am=pre;*D)N", NULL, &dynFunc);
+ CHECK_EQUAL(0, rc);
+
+ const char *reply = "{\"r\":2.2}";
+ double result = -1.0;
+ double *out = &result;
+ void *args[4];
+ args[3] = &out;
+ rc = jsonRpc_handleReply(dynFunc, reply, args);
+ CHECK_EQUAL(0, rc);
+ //CHECK_EQUAL(2.2, result);
+
+ dynFunction_destroy(dynFunc);
+ }
+
+ int add(void *handle, double a, double b, double *result) {
+ *result = a + b;
+ return 0;
+ }
+
+ int getName_example4(void *handle, char** result) {
+ *result = strdup("allocatedInFunction");
+ return 0;
+ }
+
+ struct tst_seq {
+ uint32_t cap;
+ uint32_t len;
+ double *buf;
+ };
+
+
+ //StatsResult={DDD[D average min max input}
+ struct tst_StatsResult {
+ double average;
+ double min;
+ double max;
+ struct tst_seq input;
+ };
+
+
+ int stats(void *handle, struct tst_seq input, struct tst_StatsResult **out) {
+ assert(out != NULL);
+ assert(*out == NULL);
+ double total = 0.0;
+ unsigned int count = 0;
+ double max = DBL_MIN;
+ double min = DBL_MAX;
+
+ unsigned int i;
+ for (i = 0; i<input.len; i += 1) {
+ total += input.buf[i];
+ count += 1;
+ if (input.buf[i] > max) {
+ max = input.buf[i];
+ }
+ if (input.buf[i] < min) {
+ min = input.buf[i];
+ }
+ }
+
+ struct tst_StatsResult *result = (struct tst_StatsResult *) calloc(1, sizeof(*result));
+ result->average = total / count;
+ result->min = min;
+ result->max = max;
+ double *buf = (double *)calloc(input.len, sizeof(double));
+ memcpy(buf, input.buf, input.len * sizeof(double));
+ result->input.len = input.len;
+ result->input.cap = input.len;
+ result->input.buf = buf;
+
+ *out = result;
+ return 0;
+ }
+
+ struct item {
+ double a;
+ double b;
+ };
+
+ struct item_seq {
+ uint32_t cap;
+ uint32_t len;
+ struct item **buf;
+ };
+
+ struct tst_serv {
+ void *handle;
+ int (*add)(void *, double, double, double *);
+ int (*sub)(void *, double, double, double *);
+ int (*sqrt)(void *, double, double *);
+ int (*stats)(void *, struct tst_seq, struct tst_StatsResult **);
+ };
+
+ struct tst_serv_example4 {
+ void *handle;
+ int (*getName_example4)(void *, char** name);
+ };
+
+ void callTestPreAllocated(void) {
+ dyn_interface_type *intf = NULL;
+ FILE *desc = fopen("descriptors/example1.descriptor", "r");
+ CHECK(desc != NULL);
+ int rc = dynInterface_parse(desc, &intf);
+ CHECK_EQUAL(0, rc);
+ fclose(desc);
+
+ char *result = NULL;
+
+ struct tst_serv serv;
+ serv.handle = NULL;
+ serv.add = add;
+
+
+ rc = jsonRpc_call(intf, &serv, "{\"m\":\"add(DD)D\", \"a\": [1.0,2.0]}", &result);
+ CHECK_EQUAL(0, rc);
+ STRCMP_CONTAINS("3.0", result);
+
+ free(result);
+ dynInterface_destroy(intf);
+ }
+
+ void callTestOutput(void) {
+ dyn_interface_type *intf = NULL;
+ FILE *desc = fopen("descriptors/example1.descriptor", "r");
+ CHECK(desc != NULL);
+ int rc = dynInterface_parse(desc, &intf);
+ CHECK_EQUAL(0, rc);
+ fclose(desc);
+
+ char *result = NULL;
+
+ struct tst_serv serv;
+ serv.handle = NULL;
+ serv.stats = stats;
+
+ rc = jsonRpc_call(intf, &serv, "{\"m\":\"stats([D)LStatsResult;\", \"a\": [[1.0,2.0]]}", &result);
+ CHECK_EQUAL(0, rc);
+ STRCMP_CONTAINS("1.5", result); //avg
+
+ free(result);
+ dynInterface_destroy(intf);
+ }
+
+ void handleTestOut(void) {
+ dyn_interface_type *intf = NULL;
+ FILE *desc = fopen("descriptors/example1.descriptor", "r");
+ CHECK(desc != NULL);
+ int rc = dynInterface_parse(desc, &intf);
+ CHECK_EQUAL(0, rc);
+ fclose(desc);
+
+ struct methods_head *head;
+ dynInterface_methods(intf, &head);
+ dyn_function_type *func = NULL;
+ struct method_entry *entry = NULL;
+ TAILQ_FOREACH(entry, head, entries) {
+ if (strcmp(entry->name, "stats") == 0) {
+ func = entry->dynFunc;
+ break;
+ }
+ }
+ CHECK(func != NULL);
+
+ const char *reply = "{\"r\":{\"input\":[1.0,2.0],\"max\":2.0,\"average\":1.5,\"min\":1.0}}";
+
+ void *args[3];
+ args[0] = NULL;
+ args[1] = NULL;
+ args[2] = NULL;
+
+ struct tst_StatsResult *result = NULL;
+ void *out = &result;
+ args[2] = &out;
+
+ rc = jsonRpc_handleReply(func, reply, args);
+ CHECK_EQUAL(0, rc);
+ CHECK_EQUAL(1.5, result->average);
+
+ free(result->input.buf);
+ free(result);
+ dynInterface_destroy(intf);
+ }
+
+ static void handleTestOutputSequence(void) {
+ dyn_interface_type *intf = NULL;
+ FILE *desc = fopen("descriptors/example2.descriptor", "r");
+ CHECK(desc != NULL);
+ int rc = dynInterface_parse(desc, &intf);
+ CHECK_EQUAL(0, rc);
+ fclose(desc);
+
+ struct methods_head *head;
+ dynInterface_methods(intf, &head);
+ dyn_function_type *func = NULL;
+ struct method_entry *entry = NULL;
+ TAILQ_FOREACH(entry, head, entries) {
+ if (strcmp(entry->name, "example1") == 0) {
+ func = entry->dynFunc;
+ break;
+ }
+ }
+ CHECK(func != NULL);
+
+ //dyn_type *arg = dynFunction_argumentTypeForIndex(func, 1);
+ //dynType_print(arg, stdout);
+
+ const char *reply = "{\"r\":[{\"a\":1.0,\"b\":1.5},{\"a\":2.0,\"b\":2.5}]}";
+
+ void *args[2];
+ args[0] = NULL;
+ args[1] = NULL;
+
+ struct item_seq *result = NULL;
+ void *out = &result;
+ args[1] = &out;
+
+ rc = jsonRpc_handleReply(func, reply, args);
+ CHECK_EQUAL(0, rc);
+ CHECK_EQUAL(2, result->len);
+ CHECK_EQUAL(1.0, result->buf[0]->a);
+ CHECK_EQUAL(1.5, result->buf[0]->b);
+ CHECK_EQUAL(2.0, result->buf[1]->a);
+ CHECK_EQUAL(2.5, result->buf[1]->b);
+
+
+ unsigned int i;
+ for (i = 0; i < result->len; i +=1 ) {
+ free(result->buf[i]);
+ }
+ free(result->buf);
+ free(result);
+ dynInterface_destroy(intf);
+ }
+
+
+
+
+ void callTestOutChar(void) {
+ dyn_interface_type *intf = NULL;
+ FILE *desc = fopen("descriptors/example4.descriptor", "r");
+ CHECK(desc != NULL);
+ int rc = dynInterface_parse(desc, &intf);
+ CHECK_EQUAL(0, rc);
+ fclose(desc);
+
+ char *result = NULL;
+
+ struct tst_serv_example4 serv;
+ serv.handle = NULL;
+ serv.getName_example4 = getName_example4;
+
+ rc = jsonRpc_call(intf, &serv, "{\"m\":\"getName(V)t\", \"a\": []}", &result);
+ CHECK_EQUAL(0, rc);
+
+ STRCMP_CONTAINS("allocatedInFunction", result);
+
+ free(result);
+ dynInterface_destroy(intf);
+ }
+
+
+ void handleTestOutChar(void) {
+ dyn_interface_type *intf = NULL;
+ FILE *desc = fopen("descriptors/example4.descriptor", "r");
+ CHECK(desc != NULL);
+ int rc = dynInterface_parse(desc, &intf);
+ CHECK_EQUAL(0, rc);
+ fclose(desc);
+
+ struct methods_head *head;
+ dynInterface_methods(intf, &head);
+ dyn_function_type *func = NULL;
+ struct method_entry *entry = NULL;
+ TAILQ_FOREACH(entry, head, entries) {
+ if (strcmp(entry->name, "getName") == 0) {
+ func = entry->dynFunc;
+ break;
+ }
+ }
+
+ CHECK(func != NULL);
+
+ const char *reply = "{\"r\": \"this is a test string\" }";
+ char *result = NULL;
+ void *out = &result;
+
+ void *args[2];
+ args[0] = NULL;
+ args[1] = &out;
+
+ rc = jsonRpc_handleReply(func, reply, args);
+
+ STRCMP_EQUAL("this is a test string", result);
+
+ free(result);
+ dynInterface_destroy(intf);
+ }
+
+
+}
+
+TEST_GROUP(JsonRpcTests) {
+ void setup() {
+ int lvl = 1;
+ dynCommon_logSetup(stdLog, NULL, lvl);
+ dynType_logSetup(stdLog, NULL,lvl);
+ dynFunction_logSetup(stdLog, NULL,lvl);
+ dynInterface_logSetup(stdLog, NULL,lvl);
+ jsonSerializer_logSetup(stdLog, NULL, lvl);
+ jsonRpc_logSetup(stdLog, NULL, lvl);
+
+ }
+};
+
+
+TEST(JsonRpcTests, prepareTest) {
+ prepareTest();
+}
+
+TEST(JsonRpcTests, handleTestPre) {
+ handleTestPre();
+}
+
+TEST(JsonRpcTests, handleTestOut) {
+ handleTestOut();
+}
+
+TEST(JsonRpcTests, callPre) {
+ callTestPreAllocated();
+}
+
+TEST(JsonRpcTests, callOut) {
+ callTestOutput();
+}
+
+TEST(JsonRpcTests, handleOutSeq) {
+ handleTestOutputSequence();
+}
+
+
+
+TEST(JsonRpcTests, callTestOutChar) {
+ callTestOutChar();
+}
+
+TEST(JsonRpcTests, handleOutChar) {
+ handleTestOutChar();
+}
+
[2/6] celix git commit: CELIX-309: Move dfi to top-level subdir
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/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
deleted file mode 100644
index 8d42bb4..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
+++ /dev/null
@@ -1,477 +0,0 @@
-/**
- *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.
- */
-#include "json_serializer.h"
-#include "dyn_type.h"
-#include "dyn_interface.h"
-
-#include <jansson.h>
-#include <assert.h>
-#include <stdint.h>
-#include <string.h>
-
-static int jsonSerializer_createType(dyn_type *type, json_t *object, void **result);
-static int jsonSerializer_parseObject(dyn_type *type, json_t *object, void *inst);
-static int jsonSerializer_parseObjectMember(dyn_type *type, const char *name, json_t *val, void *inst);
-static int jsonSerializer_parseSequence(dyn_type *seq, json_t *array, void *seqLoc);
-static int jsonSerializer_parseAny(dyn_type *type, void *input, json_t *val);
-
-static int jsonSerializer_writeAny(dyn_type *type, void *input, json_t **val);
-
-static int jsonSerializer_writeComplex(dyn_type *type, void *input, json_t **val);
-
-static int jsonSerializer_writeSequence(dyn_type *type, void *input, json_t **out);
-
-static int OK = 0;
-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 || dynType_type(type) == DYN_TYPE_SEQUENCE);
- int status = 0;
-
- json_error_t error;
- json_t *root = json_loads(input, JSON_DECODE_ANY, &error);
-
- if (root != NULL) {
- status = jsonSerializer_deserializeJson(type, root, result);
- json_decref(root);
- } else {
- status = ERROR;
- LOG_ERROR("Error parsing json input '%s'. Error is: %s\n", input, error.text);
- }
-
- return status;
-}
-
-int jsonSerializer_deserializeJson(dyn_type *type, json_t *input, void **out) {
- return jsonSerializer_createType(type, input, out);
-}
-
-static int jsonSerializer_createType(dyn_type *type, json_t *val, void **result) {
- assert(val != NULL);
- int status = OK;
- void *inst = NULL;
-
- if (dynType_descriptorType(type) == 't') {
- if (json_typeof(val) == JSON_STRING) {
- inst = strdup(json_string_value(val));
- } else {
- status = ERROR;
- LOG_ERROR("Expected json_string type got %i\n", json_typeof(val));
- }
- } else {
- status = dynType_alloc(type, &inst);
-
- if (status == OK) {
- assert(inst != NULL);
- status = jsonSerializer_parseAny(type, inst, val);
-
- if (status != OK) {
- dynType_free(type, inst);
- }
- }
- }
-
-
- if (status == OK) {
- *result = inst;
- }
-
- return status;
-}
-
-static int jsonSerializer_parseObject(dyn_type *type, json_t *object, void *inst) {
- assert(object != NULL);
- int status = 0;
- json_t *value;
- const char *key;
-
- json_object_foreach(object, key, value) {
- status = jsonSerializer_parseObjectMember(type, key, value, inst);
- if (status != OK) {
- break;
- }
- }
-
- return status;
-}
-
-static int jsonSerializer_parseObjectMember(dyn_type *type, const char *name, json_t *val, void *inst) {
- int status = OK;
- void *valp = NULL;
- dyn_type *valType = NULL;
-
- int index = dynType_complex_indexForName(type, name);
- if (index < 0) {
- LOG_ERROR("Cannot find index for member '%s'", name);
- status = ERROR;
- }
-
- if (status == OK) {
- status = dynType_complex_valLocAt(type, index, inst, &valp);
- }
-
- if (status == OK ) {
- status = dynType_complex_dynTypeAt(type, index, &valType);
- }
-
- if (status == OK) {
- status = jsonSerializer_parseAny(valType, valp, val);
- }
-
- return status;
-}
-
-static int jsonSerializer_parseAny(dyn_type *type, void *loc, json_t *val) {
- int status = OK;
-
- dyn_type *subType = NULL;
- char c = dynType_descriptorType(type);
-
- /*
- printf("parseAny with descriptor '%c' :", c);
- json_dumpf(val, stdout, 0); //TODO remove
- printf("\n");
- */
-
- bool *z; //Z
- float *f; //F
- double *d; //D
- char *b; //B
- int *n; //N
- 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
-
- switch (c) {
- case 'Z' :
- z = loc;
- *z = (bool) json_is_true(val);
- break;
- case 'F' :
- f = loc;
- *f = (float) json_real_value(val);
- break;
- case 'D' :
- d = loc;
- *d = json_real_value(val);
- break;
- case 'N' :
- n = loc;
- *n = (int) json_real_value(val);
- break;
- case 'B' :
- b = loc;
- *b = (char) json_integer_value(val);
- break;
- case 'S' :
- s = loc;
- *s = (int16_t) json_integer_value(val);
- break;
- case 'I' :
- i = loc;
- *i = (int32_t) json_integer_value(val);
- break;
- case 'J' :
- 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);
- break;
- case 'i' :
- ui = loc;
- *ui = (uint32_t) json_integer_value(val);
- break;
- case 'j' :
- ul = loc;
- *ul = (uint64_t) json_integer_value(val);
- break;
- case 't' :
- if (json_is_string(val)) {
- dynType_text_allocAndInit(type, loc, json_string_value(val));
- } else {
- status = ERROR;
- LOG_ERROR("Expected json string type got %i", json_typeof(val));
- }
- break;
- case '[' :
- if (json_is_array(val)) {
- status = jsonSerializer_parseSequence(type, val, loc);
- } else {
- status = ERROR;
- LOG_ERROR("Expected json array type got '%i'", json_typeof(val));
- }
- break;
- case '{' :
- if (status == OK) {
- status = jsonSerializer_parseObject(type, val, loc);
- }
- break;
- case '*' :
- status = dynType_typedPointer_getTypedType(type, &subType);
- if (status == OK) {
- status = jsonSerializer_createType(subType, val, (void **) loc);
- }
- break;
- case 'P' :
- status = ERROR;
- LOG_WARNING("Untyped pointer are not supported for serialization");
- break;
- default :
- status = ERROR;
- LOG_ERROR("Error provided type '%c' not supported for JSON\n", dynType_descriptorType(type));
- break;
- }
-
- return status;
-}
-
-static int jsonSerializer_parseSequence(dyn_type *seq, json_t *array, void *seqLoc) {
- assert(dynType_type(seq) == DYN_TYPE_SEQUENCE);
- int status = OK;
-
- size_t size = json_array_size(array);
- //LOG_DEBUG("Allocating sequence with capacity %zu", size);
- status = dynType_sequence_alloc(seq, seqLoc, (int) size);
-
- if (status == OK) {
- dyn_type *itemType = dynType_sequence_itemType(seq);
- size_t index;
- json_t *val;
- json_array_foreach(array, index, val) {
- void *valLoc = NULL;
- status = dynType_sequence_increaseLengthAndReturnLastLoc(seq, seqLoc, &valLoc);
- //LOG_DEBUG("Got sequence loc %p for index %zu", valLoc, index);
-
- if (status == OK) {
- status = jsonSerializer_parseAny(itemType, valLoc, val);
- if (status != OK) {
- break;
- }
- }
- }
- }
-
- return status;
-}
-
-int jsonSerializer_serialize(dyn_type *type, void *input, char **output) {
- int status = OK;
-
- json_t *root = NULL;
- status = jsonSerializer_serializeJson(type, input, &root);
-
- if (status == OK) {
- *output = json_dumps(root, JSON_COMPACT);
- json_decref(root);
- }
-
- return status;
-}
-
-int jsonSerializer_serializeJson(dyn_type *type, void *input, json_t **out) {
- return jsonSerializer_writeAny(type, input, out);
-}
-
-static int jsonSerializer_writeAny(dyn_type *type, void *input, json_t **out) {
- int status = OK;
-
- int descriptor = dynType_descriptorType(type);
- json_t *val = NULL;
- dyn_type *subType = NULL;
-
- bool *z; //Z
- float *f; //F
- double *d; //D
- char *b; //B
- int *n; //N
- 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
-
- switch (descriptor) {
- case 'Z' :
- z = input;
- val = json_boolean((bool)*z);
- break;
- case 'B' :
- b = input;
- val = json_integer((json_int_t)*b);
- break;
- case 'S' :
- s = input;
- val = json_integer((json_int_t)*s);
- break;
- case 'I' :
- i = input;
- val = json_integer((json_int_t)*i);
- break;
- case 'J' :
- 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);
- break;
- case 'i' :
- ui = input;
- val = json_integer((json_int_t)*ui);
- break;
- case 'j' :
- ul = input;
- val = json_integer((json_int_t)*ul);
- break;
- case 'N' :
- n = input;
- val = json_integer((json_int_t)*n);
- break;
- case 'F' :
- f = input;
- val = json_real((double) *f);
- break;
- case 'D' :
- d = input;
- val = json_real(*d);
- break;
- case 't' :
- val = json_string(*(const char **) input);
- break;
- case '*' :
- status = dynType_typedPointer_getTypedType(type, &subType);
- if (status == OK) {
- status = jsonSerializer_writeAny(subType, *(void **)input, &val);
- }
- break;
- case '{' :
- status = jsonSerializer_writeComplex(type, input, &val);
- break;
- case '[' :
- status = jsonSerializer_writeSequence(type, input, &val);
- break;
- case 'P' :
- LOG_WARNING("Untyped pointer not supported for serialization. ignoring");
- break;
- default :
- LOG_ERROR("Unsupported descriptor '%c'", descriptor);
- status = ERROR;
- break;
- }
-
- if (status == OK && val != NULL) {
- *out = val;
- }
-
- return status;
-}
-
-static int jsonSerializer_writeSequence(dyn_type *type, void *input, json_t **out) {
- assert(dynType_type(type) == DYN_TYPE_SEQUENCE);
- int status = OK;
-
- json_t *array = json_array();
- dyn_type *itemType = dynType_sequence_itemType(type);
- uint32_t len = dynType_sequence_length(input);
-
- int i = 0;
- void *itemLoc = NULL;
- json_t *item = NULL;
- for (i = 0; i < len; i += 1) {
- item = NULL;
- status = dynType_sequence_locForIndex(type, input, i, &itemLoc);
- if (status == OK) {
- status = jsonSerializer_writeAny(itemType, itemLoc, &item);
- if (status == OK) {
- json_array_append(array, item);
- json_decref(item);
- }
- }
-
- if (status != OK) {
- break;
- }
- }
-
- if (status == OK && array != NULL) {
- *out = array;
- }
-
- return status;
-}
-
-static int jsonSerializer_writeComplex(dyn_type *type, void *input, json_t **out) {
- assert(dynType_type(type) == DYN_TYPE_COMPLEX);
- int status = OK;
-
- json_t *val = json_object();
- struct complex_type_entry *entry = NULL;
- struct complex_type_entries_head *entries = NULL;
- int index = -1;
-
- status = dynType_complex_entries(type, &entries);
- if (status == OK) {
- TAILQ_FOREACH(entry, entries, entries) {
- void *subLoc = NULL;
- json_t *subVal = NULL;
- dyn_type *subType = NULL;
- index = dynType_complex_indexForName(type, entry->name);
- status = dynType_complex_valLocAt(type, index, input, &subLoc);
- if (status == OK ) {
- status = dynType_complex_dynTypeAt(type, index, &subType);
- }
- if (status == OK) {
- status = jsonSerializer_writeAny(subType, subLoc, &subVal);
- }
- if (status == OK) {
- json_object_set(val, entry->name, subVal);
- json_decref(subVal);
- }
-
- if (status != OK) {
- break;
- }
- }
- }
-
- if (status == OK && val != NULL) {
- *out = val;
- }
-
- return status;
-}
-
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.h b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.h
deleted file mode 100644
index c785b01..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- *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.
- */
-#ifndef __JSON_SERIALIZER_H_
-#define __JSON_SERIALIZER_H_
-
-#include <jansson.h>
-#include "dfi_log_util.h"
-#include "dyn_type.h"
-#include "dyn_function.h"
-#include "dyn_interface.h"
-
-//logging
-DFI_SETUP_LOG_HEADER(jsonSerializer);
-
-int jsonSerializer_deserialize(dyn_type *type, const char *input, void **result);
-int jsonSerializer_deserializeJson(dyn_type *type, json_t *input, void **result);
-
-int jsonSerializer_serialize(dyn_type *type, void *input, char **output);
-int jsonSerializer_serializeJson(dyn_type *type, void *input, json_t **out);
-
-#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/README.md
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/README.md b/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/README.md
deleted file mode 100644
index 476810e..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/README.md
+++ /dev/null
@@ -1,49 +0,0 @@
-fmemopen for Mac OS and iOS
-===========================
-
-Originally ported from [ingenuitas python-tesseract](https://github.com/ingenuitas/python-tesseract/blob/master/fmemopen.c). Ported by Jeff Verkoeyen under the Apache 2.0 License.
-
-From the fmemopen man page:
-
-> FILE *fmemopen(void *buf, size_t size, const char *mode);
->
-> The fmemopen() function opens a stream that permits the access specified by mode. The stream
-> allows I/O to be performed on the string or memory buffer pointed to by buf. This buffer must be
-> at least size bytes long.
-
-Alas, this method does not exist on BSD operating systems (specifically Mac OS X and iOS). It is
-possible to recreate this functionality using a BSD-specific method called `funopen`.
-
-From the funopen man page:
-
-> FILE * funopen(const void *cookie, int (*readfn)(void *, char *, int),
-> int (*writefn)(void *, const char *, int), fpos_t (*seekfn)(void *, fpos_t, int),
-> int (*closefn)(void *));
->
-> The funopen() function associates a stream with up to four ``I/O functions''. Either readfn or
-> writefn must be specified; the others can be given as an appropriately-typed NULL pointer. These
-> I/O functions will be used to read, write, seek and close the new stream.
-
-fmemopen.c provides a simple implementation of fmemopen using funopen so that you can create FILE
-pointers to blocks of memory.
-
-Adding it to your Project
-=========================
-
-Drag fmemopen.h and fmemopen.c to your project and add them to your target. `#include "fmemopen.h"`
-wherever you need to use `fmemopen`.
-
-Examples
-========
-
-```obj-c
-#import "fmemopen.h"
-
-NSString* string = @"fmemopen in Objective-C";
-const char* cstr = [string UTF8String];
-FILE* file = fmemopen((void *)cstr, sizeof(char) * (string.length + 1), "r");
-
-// fread on file will now read the contents of the NSString
-
-fclose(file);
-```
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/fmemopen.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/fmemopen.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/fmemopen.c
deleted file mode 100644
index 66fc9c5..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/fmemopen.c
+++ /dev/null
@@ -1,78 +0,0 @@
-
-/*
- * fmem.c : fmemopen() on top of BSD's funopen()
- * 20081017 AF
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifndef linux
-struct fmem {
- size_t pos;
- size_t size;
- char *buffer;
-};
-typedef struct fmem fmem_t;
-
-static int readfn(void *handler, char *buf, int size)
-{
- int count = 0;
- fmem_t *mem = handler;
- size_t available = mem->size - mem->pos;
-
- if(size > available) size = available;
- for(count=0; count < size; mem->pos++, count++)
- buf[count] = mem->buffer[mem->pos];
-
- return count;
-}
-
-static int writefn(void *handler, const char *buf, int size)
-{
- int count = 0;
- fmem_t *mem = handler;
- size_t available = mem->size - mem->pos;
-
- if(size > available) size = available;
- for(count=0; count < size; mem->pos++, count++)
- mem->buffer[mem->pos] = buf[count];
-
- return count; // ? count : size;
-}
-
-static fpos_t seekfn(void *handler, fpos_t offset, int whence)
-{
- size_t pos;
- fmem_t *mem = handler;
-
- switch(whence) {
- case SEEK_SET: pos = offset; break;
- case SEEK_CUR: pos = mem->pos + offset; break;
- case SEEK_END: pos = mem->size + offset; break;
- default: return -1;
- }
-
- if(pos > mem->size) return -1;
-
- mem->pos = pos;
- return (fpos_t) pos;
-}
-
-static int closefn(void *handler)
-{
- free(handler);
- return 0;
-}
-
-/* simple, but portable version of fmemopen for OS X / BSD */
-FILE *fmemopen(void *buf, size_t size, const char *mode)
-{
- fmem_t *mem = (fmem_t *) malloc(sizeof(fmem_t));
-
- memset(mem, 0, sizeof(fmem_t));
- mem->size = size, mem->buffer = buf;
- return funopen(mem, readfn, writefn, seekfn, closefn);
-}
-#endif
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/fmemopen.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/fmemopen.h b/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/fmemopen.h
deleted file mode 100644
index 3d06b20..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/fmemopen.h
+++ /dev/null
@@ -1,52 +0,0 @@
-//
-// Copyright 2012 Jeff Verkoeyen
-// Originally ported from https://github.com/ingenuitas/python-tesseract/blob/master/fmemopen.c
-//
-// Licensed 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.
-//
-
-#ifndef FMEMOPEN_H_
-#define FMEMOPEN_H_
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/**
- * A BSD port of the fmemopen Linux method using funopen.
- *
- * man docs for fmemopen:
- * http://linux.die.net/man/3/fmemopen
- *
- * man docs for funopen:
- * https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/funopen.3.html
- *
- * This method is ported from ingenuitas' python-tesseract project.
- *
- * You must call fclose on the returned file pointer or memory will be leaked.
- *
- * @param buf The data that will be used to back the FILE* methods. Must be at least
- * @c size bytes.
- * @param size The size of the @c buf data.
- * @param mode The permitted stream operation modes.
- * @returns A pointer that can be used in the fread/fwrite/fseek/fclose family of methods.
- * If a failure occurred NULL will be returned.
- */
-FILE *fmemopen(void *buf, size_t size, const char *mode);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // #ifndef FMEMOPEN_H_
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/open_memstream.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/open_memstream.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/open_memstream.c
deleted file mode 100644
index 6bc4f01..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/open_memstream.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/* Use funopen(3) to provide open_memstream(3) like functionality. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-struct memstream {
- char **cp;
- size_t *lenp;
- size_t offset;
-};
-
-static void
-memstream_grow(struct memstream *ms, size_t newsize)
-{
- char *buf;
-
- if (newsize > *ms->lenp) {
- buf = realloc(*ms->cp, newsize + 1);
- if (buf != NULL) {
-#ifdef DEBUG
- fprintf(stderr, "MS: %p growing from %zd to %zd\n",
- ms, *ms->lenp, newsize);
-#endif
- memset(buf + *ms->lenp + 1, 0, newsize - *ms->lenp);
- *ms->cp = buf;
- *ms->lenp = newsize;
- }
- }
-}
-
-static int
-memstream_read(void *cookie, char *buf, int len)
-{
- struct memstream *ms;
- int tocopy;
-
- ms = cookie;
- memstream_grow(ms, ms->offset + len);
- tocopy = *ms->lenp - ms->offset;
- if (len < tocopy)
- tocopy = len;
- memcpy(buf, *ms->cp + ms->offset, tocopy);
- ms->offset += tocopy;
-#ifdef DEBUG
- fprintf(stderr, "MS: read(%p, %d) = %d\n", ms, len, tocopy);
-#endif
- return (tocopy);
-}
-
-static int
-memstream_write(void *cookie, const char *buf, int len)
-{
- struct memstream *ms;
- int tocopy;
-
- ms = cookie;
- memstream_grow(ms, ms->offset + len);
- tocopy = *ms->lenp - ms->offset;
- if (len < tocopy)
- tocopy = len;
- memcpy(*ms->cp + ms->offset, buf, tocopy);
- ms->offset += tocopy;
-#ifdef DEBUG
- fprintf(stderr, "MS: write(%p, %d) = %d\n", ms, len, tocopy);
-#endif
- return (tocopy);
-}
-
-static fpos_t
-memstream_seek(void *cookie, fpos_t pos, int whence)
-{
- struct memstream *ms;
-#ifdef DEBUG
- size_t old;
-#endif
-
- ms = cookie;
-#ifdef DEBUG
- old = ms->offset;
-#endif
- switch (whence) {
- case SEEK_SET:
- ms->offset = pos;
- break;
- case SEEK_CUR:
- ms->offset += pos;
- break;
- case SEEK_END:
- ms->offset = *ms->lenp + pos;
- break;
- }
-#ifdef DEBUG
- fprintf(stderr, "MS: seek(%p, %zd, %d) %zd -> %zd\n", ms, pos, whence,
- old, ms->offset);
-#endif
- return (ms->offset);
-}
-
-static int
-memstream_close(void *cookie)
-{
-
- free(cookie);
- return (0);
-}
-
-FILE *
-open_memstream(char **cp, size_t *lenp)
-{
- struct memstream *ms;
- int save_errno;
- FILE *fp;
-
- *cp = NULL;
- *lenp = 0;
- ms = malloc(sizeof(*ms));
- ms->cp = cp;
- ms->lenp = lenp;
- ms->offset = 0;
- fp = funopen(ms, memstream_read, memstream_write, memstream_seek,
- memstream_close);
- if (fp == NULL) {
- save_errno = errno;
- free(ms);
- errno = save_errno;
- }
- return (fp);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/open_memstream.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/open_memstream.h b/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/open_memstream.h
deleted file mode 100644
index e87bb0a..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/memstream/open_memstream.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef OPEN_MEMSTREAM_H_
-#define OPEN_MEMSTREAM_H_
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-FILE *open_memstream(char **cp, size_t *lenp);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // #ifndef FMEMOPEN_H_
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/CMakeLists.txt b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/CMakeLists.txt
deleted file mode 100644
index d42b606..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/CMakeLists.txt
+++ /dev/null
@@ -1,47 +0,0 @@
-# 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.
-
-include_directories(
- ../dynamic_function_interface
-)
-
-SET(CMAKE_SKIP_BUILD_RPATH FALSE) #TODO needed?
-SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) #TODO needed?
-SET(CMAKE_INSTALL_RPATH "${PROJECT_BINARY_DIR}/remote_services/remote_service_admin_dfi/dynamic_function_interface")
-
-
-add_executable(test_dfi
- dyn_type_tests.cpp
- dyn_function_tests.cpp
- dyn_closure_tests.cpp
- dyn_interface_tests.cpp
- dyn_message_tests.cpp
- json_serializer_tests.cpp
- json_rpc_tests.cpp
- run_tests.cpp
-)
-target_link_libraries(test_dfi dfi ${CPPUTEST_LIBRARY})
-
-add_custom_target(copy-input
- COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/schemas schemas
- COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/descriptors descriptors
-)
-add_dependencies(test_dfi copy-input)
-
-add_test(NAME run_test_dfi COMMAND test_dfi)
-SETUP_TARGET_FOR_COVERAGE(test_dfi_cov test_dfi ${CMAKE_BINARY_DIR}/coverage/test_dfi/test_dfi)
-
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/avro_descriptor_translator_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/avro_descriptor_translator_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/avro_descriptor_translator_tests.cpp
deleted file mode 100644
index c29932e..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/avro_descriptor_translator_tests.cpp
+++ /dev/null
@@ -1,179 +0,0 @@
-/**
- *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.
- */
-#include <CppUTest/TestHarness.h>
-#include "CppUTest/CommandLineTestRunner.h"
-
-extern "C" {
-
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-
-#include "dyn_common.h"
-#include "descriptor_translator.h"
-
-#if defined(BSD) || defined(__APPLE__)
-#include "open_memstream.h"
-#include "fmemopen.h"
-#endif
-
- static void stdLog(void *handle, int level, const char *file, int line, const char *msg, ...) {
- va_list ap;
- const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
- fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
- va_start(ap, msg);
- vfprintf(stderr, msg, ap);
- fprintf(stderr, "\n");
- }
-
-
- static char *readSchema(const char *file) {
- size_t size = 0;
- char *ptr = NULL;
-
- FILE *schema = fopen(file, "r");
- FILE *stream = open_memstream(&ptr, &size);
-
- assert(schema != NULL);
- assert(stream != NULL);
-
- int c = fgetc(schema);
- while (c != EOF ) {
- fputc(c, stream);
- c = fgetc(schema);
- }
- fclose(schema);
- fclose(stream);
-
- assert(ptr != NULL);
- return ptr;
- }
-
- static dyn_interface_type *createInterfaceInfo(const char *schemaFile) {
- char *schema = readSchema(schemaFile);
- dyn_interface_type *ift= NULL;
-
- int status = descriptorTranslator_translate(schema, &ift);
- CHECK_EQUAL(0, status);
-
- free(schema);
- return ift;
- }
-
- static int countMethodInfos(dyn_interface_type *info) {
- int count = 0;
- method_info_type *mInfo = NULL;
- TAILQ_FOREACH(mInfo, &info->methodInfos, entries) {
- count +=1;
- }
- return count;
- }
-
- static int countTypeInfos(dyn_interface_type *info) {
- int count = 0;
- type_info_type *tInfo = NULL;
- TAILQ_FOREACH(tInfo, &info->typeInfos, entries) {
- count +=1;
- }
- return count;
- }
-
- static void simple(void) {
- //first argument void *handle, last argument output pointer for result and return int with status for exception handling
- //sum(DD)D -> sum(PDD*D)N
- //sub(DD)D -> sub(PDD*D)N
- //sqrt(D)D -> sqrt(PD*D)N
-
- dyn_interface_type *intf = createInterfaceInfo("schemas/simple.avpr");
-
- int count = countMethodInfos(intf);
- CHECK_EQUAL(3, count);
-
- count = countTypeInfos(intf);
- CHECK_EQUAL(0, count);
-
- method_info_type *mInfo = NULL;
- TAILQ_FOREACH(mInfo, &intf->methodInfos, entries) {
- if (strcmp("sum", mInfo->name) == 0) {
- STRCMP_EQUAL("sum(PDD*D)N", mInfo->descriptor);
- } else if (strcmp("add", mInfo->name) == 0) {
- STRCMP_EQUAL("add(PDD*D)N", mInfo->descriptor);
- } else if (strcmp("sqrt", mInfo->name) == 0) {
- STRCMP_EQUAL("sqrt(PD*D)N", mInfo->descriptor);
- }
- }
-
- dynInterface_destroy(intf);
- }
-
- static void complex(void) {
- dyn_interface_type *intf = createInterfaceInfo("schemas/complex.avpr");
-
- int count = countMethodInfos(intf);
- CHECK_EQUAL(1, count);
-
- method_info_type *mInfo = TAILQ_FIRST(&intf->methodInfos);
- STRCMP_EQUAL("stats", mInfo->name);
- STRCMP_EQUAL("stats(P[D*LStatResult;)N", mInfo->descriptor);
-
- count = countTypeInfos(intf);
- CHECK_EQUAL(1, count);
-
- type_info_type *tInfo = TAILQ_FIRST(&intf->typeInfos);
- STRCMP_EQUAL("StatResult", tInfo->name);
- STRCMP_EQUAL("{DDD[D sum min max input}", tInfo->descriptor);
-
- dynInterface_destroy(intf);
- }
-
- static void invalid(const char *file) {
- char *schema = readSchema(file);
- dyn_interface_type *ift= NULL;
-
- int status = descriptorTranslator_translate(schema, &ift);
- CHECK(status != 0);
-
- free(schema);
- }
-}
-
-TEST_GROUP(AvroDescTranslatorTest) {
- void setup() {
- descriptorTranslator_logSetup(stdLog, NULL, 3);
- dynInterface_logSetup(stdLog, NULL, 3);
- dynType_logSetup(stdLog, NULL, 3);
- dynCommon_logSetup(stdLog, NULL, 3);
- }
-};
-
-TEST(AvroDescTranslatorTest, simple) {
- simple();
-}
-
-TEST(AvroDescTranslatorTest, complex) {
- complex();
-}
-
-TEST(AvroDescTranslatorTest, invalid1) {
- invalid("schemas/invalid1.avpr");
-}
-
-TEST(AvroDescTranslatorTest, invalid2) {
- invalid("schemas/invalid2.avpr");
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example1.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example1.descriptor b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example1.descriptor
deleted file mode 100644
index 771dc5e..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example1.descriptor
+++ /dev/null
@@ -1,13 +0,0 @@
-:header
-type=interface
-name=calculator
-version=1.0.0
-:annotations
-classname=org.example.Calculator
-:types
-StatsResult={DDD[D average min max input}
-: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
-stats([D)LStatsResult;=stats(#am=handle;P[D#am=out;*LStatsResult;)N
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example2.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example2.descriptor b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example2.descriptor
deleted file mode 100644
index 38bf442..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example2.descriptor
+++ /dev/null
@@ -1,9 +0,0 @@
-:header
-type=interface
-name=example
-version=1.0.0
-:annotations
-:types
-item={DD a b}
-:methods
-example1=items(#am=handle;P#am=out;**[Litem;)N
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example3.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example3.descriptor b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example3.descriptor
deleted file mode 100644
index c89d969..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example3.descriptor
+++ /dev/null
@@ -1,11 +0,0 @@
-:header
-type=interface
-name=detection_provider
-version=1.0.0
-:annotations
-:types
-location={DD lat lon}
-target={Jllocation;DDJ id location speed heading lastUpdated}
-detection={Jllocation;Dltarget; id center range simulated}
-:methods
-getDetections()Ljava/util/List;=getDetections(#am=handle;P#am=out;**[Ldetection;)N
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example4.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example4.descriptor b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example4.descriptor
deleted file mode 100644
index 4c959c4..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example4.descriptor
+++ /dev/null
@@ -1,8 +0,0 @@
-:header
-type=interface
-name=example4
-version=1.0.0
-:annotations
-:types
-:methods
-getName(V)t=getName(#am=handle;P#am=out;*t)N
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/msg_example1.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/msg_example1.descriptor b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/msg_example1.descriptor
deleted file mode 100644
index 576523a..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/msg_example1.descriptor
+++ /dev/null
@@ -1,10 +0,0 @@
-:header
-type=message
-name=poi
-version=1.0.0
-:annotations
-classname=org.example.PointOfInterest
-:types
-location={DD lat long}
-:message
-{llocation;tt location name description}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/msg_example2.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/msg_example2.descriptor b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/msg_example2.descriptor
deleted file mode 100644
index 128049d..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/msg_example2.descriptor
+++ /dev/null
@@ -1,12 +0,0 @@
-:header
-type=message
-name=track
-version=0.0.1
-:annotations
-classname=org.example.Track
-:types
-timestamp={SSSSSSI day month year hour minute second microseconds}
-latlonpos={DD lat lon}
-polarpos={DDD azimuth elevation range}
-:message
-{Iltimestamp;llatlonpos;lpolarpos;SS trackid lastupdate abspos relpos classification identity}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/msg_example3.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/msg_example3.descriptor b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/msg_example3.descriptor
deleted file mode 100644
index 7b69380..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/msg_example3.descriptor
+++ /dev/null
@@ -1,10 +0,0 @@
-:header
-type=message
-name=logEntry
-version=1.0.0
-:annotations
-classname=org.example.LogEntry
-:types
-timestamp={SSSSSSI day month year hour minute second microseconds}
-:message
-{ltimestamp;St timestamp severity eventdescription}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_closure_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_closure_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_closure_tests.cpp
deleted file mode 100644
index ce70f93..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_closure_tests.cpp
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- *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.
- */
-#include <CppUTest/TestHarness.h>
-#include "CppUTest/CommandLineTestRunner.h"
-
-extern "C" {
-
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "dyn_common.h"
-#include "dyn_function.h"
-
-static int g_count;
-
-static void stdLog(void *handle, int level, const char *file, int line, const char *msg, ...) {
- va_list ap;
- const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
- fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
- va_start(ap, msg);
- vfprintf(stderr, msg, ap);
- fprintf(stderr, "\n");
-}
-
-#define EXAMPLE1_DESCRIPTOR "example(III)I"
-static void example1_binding(void *userData, void* args[], void *out) {
- int32_t a = *((int32_t *)args[0]);
- int32_t b = *((int32_t *)args[1]);
- int32_t c = *((int32_t *)args[2]);
- int32_t *ret = (int32_t *)out;
- *ret = a + b + c;
- g_count += 1;
-}
-
-#define EXAMPLE2_DESCRIPTOR "example(I{DDD val1 val2 val3}I)D"
-struct example2_arg2 {
- double val1;
- double val2;
- double val3;
-};
-void example2_binding(void *userData, void* args[], void *out) {
- int32_t a = *((int32_t *)args[0]);
- struct example2_arg2 b = *((struct example2_arg2 *)args[1]);
- int32_t c = *((int32_t *)args[2]);
- double *ret = (double *)out;
- *ret = a + b.val1 + b.val2 + b.val3 + c;
- g_count += 1;
-}
-
-
-#define EXAMPLE3_DESCRIPTOR "example(III){III sum max min}"
-struct example3_ret {
- int32_t sum;
- int32_t max;
- int32_t min;
-};
-
-static void example3_binding(void *userData, void* args[], void *out) {
- int32_t a = *((int32_t *)args[0]);
- int32_t b = *((int32_t *)args[1]);
- int32_t c = *((int32_t *)args[2]);
- struct example3_ret *result = (struct example3_ret *)calloc(1,sizeof(struct example3_ret));
- result->sum = a + b + c;
- result->min = a <= b ? a : b;
- result->max = a >= b ? a : b;
- result->min = result->min <= c ? result->min : c;
- result->max = result->max >= c ? result->max : c;
-
- struct example3_ret **ret = (struct example3_ret **)out;
- (*ret) = result;
- g_count += 1;
-}
-
-static void tests() {
- dyn_function_type *dynFunction = NULL;
- int rc = 0;
-
- {
- int32_t (*func)(int32_t a, int32_t b, int32_t c) = NULL;
- rc = dynFunction_parseWithStr(EXAMPLE1_DESCRIPTOR, NULL, &dynFunction);
- CHECK_EQUAL(0, rc);
- rc = dynFunction_createClosure(dynFunction, example1_binding, NULL, (void(**)(void))&func);
- CHECK_EQUAL(0, rc);
- int32_t ret = func(2,3,4);
- CHECK_EQUAL(1, g_count);
- CHECK_EQUAL(9, ret);
- dynFunction_destroy(dynFunction);
- }
-
- {
- double (*func)(int32_t a, struct example2_arg2 b, int32_t c) = NULL;
- double (*func2)(int32_t a, struct example2_arg2 b, int32_t c) = NULL;
- dynFunction = NULL;
- rc = dynFunction_parseWithStr(EXAMPLE2_DESCRIPTOR, NULL, &dynFunction);
- CHECK_EQUAL(0, rc);
- rc = dynFunction_createClosure(dynFunction, example2_binding, NULL, (void(**)(void))&func);
- CHECK_EQUAL(0, rc);
- rc = dynFunction_getFnPointer(dynFunction, (void(**)(void))&func2);
- CHECK_EQUAL(0, rc);
- CHECK(func == func2);
- struct example2_arg2 b;
- b.val1 = 1.0;
- b.val2 = 1.5;
- b.val3 = 2.0;
- double ret = func(2,b,4);
- CHECK_EQUAL(2, g_count);
- CHECK_EQUAL(10.5, ret);
- dynFunction_destroy(dynFunction);
- }
-
- {
- struct example3_ret * (*func)(int32_t a, int32_t b, int32_t c) = NULL;
- dynFunction = NULL;
- rc = dynFunction_parseWithStr(EXAMPLE3_DESCRIPTOR, NULL, &dynFunction);
- CHECK_EQUAL(0, rc);
- rc = dynFunction_createClosure(dynFunction, example3_binding, NULL, (void(**)(void))&func);
- CHECK_EQUAL(0, rc);
- struct example3_ret *ret = func(2,8,4);
- CHECK_EQUAL(3, g_count);
- CHECK_EQUAL(14, ret->sum);
- dynFunction_destroy(dynFunction);
- free(ret);
- }
-}
-
-}
-
-
-TEST_GROUP(DynClosureTests) {
- void setup() {
- int lvl = 1;
- dynFunction_logSetup(stdLog, NULL, lvl);
- dynType_logSetup(stdLog, NULL, lvl);
- dynCommon_logSetup(stdLog, NULL, lvl);
- g_count = 0;
- }
-};
-
-TEST(DynClosureTests, DynCLosureTest1) {
- //TODO split up
- tests();
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_function_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_function_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_function_tests.cpp
deleted file mode 100644
index 2279331..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_function_tests.cpp
+++ /dev/null
@@ -1,252 +0,0 @@
-/**
- *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.
- */
-#include <CppUTest/TestHarness.h>
-#include "CppUTest/CommandLineTestRunner.h"
-
-extern "C" {
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
-
-
- #include "dyn_common.h"
- #include "dyn_function.h"
-
- static void stdLog(void *handle, int level, const char *file, int line, const char *msg, ...) {
- va_list ap;
- const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
- fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
- va_start(ap, msg);
- vfprintf(stderr, msg, ap);
- fprintf(stderr, "\n");
- }
-
- #define EXAMPLE1_DESCRIPTOR "example(III)I"
- int32_t example1(int32_t a, int32_t b, int32_t c) {
- CHECK_EQUAL(2, a);
- CHECK_EQUAL(4, b);
- CHECK_EQUAL(8, c);
- return 1;
- }
-
- void test_example1(void) {
- dyn_function_type *dynFunc = NULL;
- int rc;
- void (*fp)(void) = (void (*)(void)) example1;
-
- rc = dynFunction_parseWithStr(EXAMPLE1_DESCRIPTOR, NULL, &dynFunc);
- CHECK_EQUAL(0, rc);
-
- int32_t a = 2;
- int32_t b = 4;
- int32_t c = 8;
- void *values[3];
- int32_t rVal = 0;
- values[0] = &a;
- values[1] = &b;
- values[2] = &c;
-
- rc = dynFunction_call(dynFunc, fp, &rVal, values);
- CHECK_EQUAL(0, rc);
- CHECK_EQUAL(1, rVal);
- dynFunction_destroy(dynFunc);
- }
-
- #define EXAMPLE2_DESCRIPTOR "example(I{IID val1 val2 val3}D)D"
- struct example2_arg {
- int32_t val1;
- int32_t val2;
- double val3;
- };
-
- double example2(int32_t arg1, struct example2_arg arg2, double arg3) {
- CHECK_EQUAL(2, arg1);
- CHECK_EQUAL(2, arg2.val1);
- CHECK_EQUAL(3, arg2.val2);
- CHECK_EQUAL(4.1, arg2.val3);
- CHECK_EQUAL(8.1, arg3);
- return 2.2;
- }
-
- void test_example2(void) {
- dyn_function_type *dynFunc = NULL;
- int rc;
- void (*fp)(void) = (void (*)(void)) example2;
-
- rc = dynFunction_parseWithStr(EXAMPLE2_DESCRIPTOR, NULL, &dynFunc);
- CHECK_EQUAL(0, rc);
-
- int32_t arg1 = 2;
- struct example2_arg arg2;
- arg2.val1 = 2;
- arg2.val2 = 3;
- arg2.val3 = 4.1;
- double arg3 = 8.1;
- double returnVal = 0;
- void *values[3];
- values[0] = &arg1;
- values[1] = &arg2;
- values[2] = &arg3;
-
- rc = dynFunction_call(dynFunc, fp, &returnVal, values);
- CHECK_EQUAL(0, rc);
- CHECK_EQUAL(2.2, returnVal);
- dynFunction_destroy(dynFunc);
- }
-
- static void test_access_functions(void) {
- dyn_function_type *dynFunc = NULL;
- int rc;
- rc = dynFunction_parseWithStr("add(D{DD a b}*D)V", NULL, &dynFunc);
-
- CHECK_EQUAL(0, rc);
-
- int nrOfArgs = dynFunction_nrOfArguments(dynFunc);
- CHECK_EQUAL(3, nrOfArgs);
-
- dyn_type *arg1 = dynFunction_argumentTypeForIndex(dynFunc, 1);
- CHECK(arg1 != NULL);
- CHECK_EQUAL('{', (char) dynType_descriptorType(arg1));
-
- dyn_type *nonExist = dynFunction_argumentTypeForIndex(dynFunc, 10);
- CHECK(nonExist == NULL);
-
- dyn_type *returnType = dynFunction_returnType(dynFunc);
- CHECK_EQUAL('V', (char) dynType_descriptorType(returnType));
-
- dynFunction_destroy(dynFunc);
- }
-
- //example with gen pointer and output
- #define EXAMPLE3_DESCRIPTOR "example(PD*D)N"
-
- static int testExample3(void *ptr, double a, double *out) {
- double *b = (double *)ptr;
- CHECK_EQUAL(2.0, *b)
- CHECK_EQUAL(a, 2.0);
- *out = *b * a;
- return 0;
- }
-
- static void test_example3(void) {
- dyn_function_type *dynFunc = NULL;
- void (*fp)(void) = (void(*)(void)) testExample3;
- int rc;
-
- rc = dynFunction_parseWithStr(EXAMPLE3_DESCRIPTOR, NULL, &dynFunc);
- CHECK_EQUAL(0, rc);
- double result = -1.0;
- double *input = &result;
- double a = 2.0;
- void *ptr = &a;
- void *args[3];
- args[0] = &ptr;
- args[1] = &a;
- args[2] = &input;
- int rVal = 0;
- rc = dynFunction_call(dynFunc, fp, &rVal, args);
- CHECK_EQUAL(0, rc);
- CHECK_EQUAL(4.0, result);
-
-
- double *inMemResult = (double *)calloc(1, sizeof(double));
- a = 2.0;
- ptr = &a;
- args[0] = &ptr;
- args[1] = &a;
- args[2] = &inMemResult;
- rVal = 0;
- rc = dynFunction_call(dynFunc, fp, &rVal, args);
- CHECK_EQUAL(0, rc);
- CHECK_EQUAL(4.0, result);
- free(inMemResult);
-
- dynFunction_destroy(dynFunc);
- }
-
- struct tst_seq {
- uint32_t cap;
- uint32_t len;
- double *buf;
- };
-
- #define EXAMPLE4_DESCRIPTOR "example([D)V"
-
- static void example4Func(struct tst_seq seq) {
- CHECK_EQUAL(4, seq.cap);
- CHECK_EQUAL(2, seq.len);
- CHECK_EQUAL(1.1, seq.buf[0]);
- CHECK_EQUAL(2.2, seq.buf[1]);
- }
-
- static void test_example4(void) {
- dyn_function_type *dynFunc = NULL;
- void (*fp)(void) = (void(*)(void)) example4Func;
- int rc;
-
- rc = dynFunction_parseWithStr(EXAMPLE4_DESCRIPTOR, NULL, &dynFunc);
- CHECK_EQUAL(0, rc);
-
- double buf[4];
- buf[0] = 1.1;
- buf[1] = 2.2;
- struct tst_seq seq;
- seq.cap = 4;
- seq.len = 2;
- seq.buf = buf;
-
- void *args[1];
- args[0] = &seq;
- rc = dynFunction_call(dynFunc, fp, NULL, args);
- CHECK_EQUAL(0, rc);
-
- dynFunction_destroy(dynFunc);
- }
-}
-
-TEST_GROUP(DynFunctionTests) {
- void setup() {
- int lvl = 1;
- dynFunction_logSetup(stdLog, NULL, lvl);
- dynType_logSetup(stdLog, NULL, lvl);
- dynCommon_logSetup(stdLog, NULL, lvl);
- }
-};
-
-TEST(DynFunctionTests, DynFuncTest1) {
- test_example1();
-}
-
-TEST(DynFunctionTests, DynFuncTest2) {
- test_example2();
-}
-
-TEST(DynFunctionTests, DynFuncAccTest) {
- test_access_functions();
-}
-
-TEST(DynFunctionTests, DynFuncTest3) {
- test_example3();
-}
-
-TEST(DynFunctionTests, DynFuncTest4) {
- test_example4();
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_interface_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_interface_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_interface_tests.cpp
deleted file mode 100644
index 83afb9b..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_interface_tests.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-/**
- *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.
- */
-#include <CppUTest/TestHarness.h>
-#include "CppUTest/CommandLineTestRunner.h"
-extern "C" {
-
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <assert.h>
-
-#include "dyn_common.h"
-#include "dyn_interface.h"
-
-#if defined(BSD) || defined(__APPLE__)
-#include "open_memstream.h"
-#include "fmemopen.h"
-#endif
-
- static void stdLog(void *handle, int level, const char *file, int line, const char *msg, ...) {
- va_list ap;
- const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
- fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
- va_start(ap, msg);
- vfprintf(stderr, msg, ap);
- fprintf(stderr, "\n");
- }
-
- static void test1(void) {
- int status = 0;
- dyn_interface_type *dynIntf = NULL;
- FILE *desc = fopen("descriptors/example1.descriptor", "r");
- assert(desc != NULL);
- status = dynInterface_parse(desc, &dynIntf);
- CHECK_EQUAL(0, status);
- fclose(desc);
-
- char *name = NULL;
- status = dynInterface_getName(dynIntf, &name);
- CHECK_EQUAL(0, status);
- STRCMP_EQUAL("calculator", name);
-
- char *version = NULL;
- status = dynInterface_getVersion(dynIntf, &version);
- CHECK_EQUAL(0, status);
- STRCMP_EQUAL("1.0.0", version);
-
- char *annVal = NULL;
- status = dynInterface_getAnnotationEntry(dynIntf, "classname", &annVal);
- CHECK_EQUAL(0, status);
- STRCMP_EQUAL("org.example.Calculator", annVal);
-
- char *nonExist = NULL;
- status = dynInterface_getHeaderEntry(dynIntf, "nonExisting", &nonExist);
- CHECK(status != 0);
- CHECK(nonExist == NULL);
-
- struct methods_head *list = NULL;
- status = dynInterface_methods(dynIntf, &list);
- CHECK(status == 0);
- CHECK(list != NULL);
-
- int count = dynInterface_nrOfMethods(dynIntf);
- CHECK_EQUAL(4, count);
-
- dynInterface_destroy(dynIntf);
- }
-
- static void test2(void) {
- int status = 0;
- dyn_interface_type *dynIntf = NULL;
- FILE *desc = fopen("descriptors/example3.descriptor", "r");
- assert(desc != NULL);
- status = dynInterface_parse(desc, &dynIntf);
- CHECK_EQUAL(0, status);
- fclose(desc);
-
- dynInterface_destroy(dynIntf);
- }
-
-}
-
-
-TEST_GROUP(DynInterfaceTests) {
- void setup() {
- int level = 1;
- dynCommon_logSetup(stdLog, NULL, level);
- dynType_logSetup(stdLog, NULL, level);
- dynFunction_logSetup(stdLog, NULL, level);
- dynInterface_logSetup(stdLog, NULL, level);
- }
-};
-
-TEST(DynInterfaceTests, test1) {
- test1();
-}
-
-TEST(DynInterfaceTests, test2) {
- test2();
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_message_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_message_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_message_tests.cpp
deleted file mode 100644
index e30d16e..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_message_tests.cpp
+++ /dev/null
@@ -1,184 +0,0 @@
-/**
- *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.
- */
-#include <CppUTest/TestHarness.h>
-#include "CppUTest/CommandLineTestRunner.h"
-
-extern "C" {
-
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <assert.h>
-
-#include "dyn_common.h"
-#include "dyn_message.h"
-
-#if defined(BSD) || defined(__APPLE__)
-#include "open_memstream.h"
-#include "fmemopen.h"
-#endif
-
-static void stdLog(void *handle, int level, const char *file, int line, const char *msg, ...) {
- va_list ap;
- const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
- fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
- va_start(ap, msg);
- vfprintf(stderr, msg, ap);
- fprintf(stderr, "\n");
-}
-
-
-static void msg_test1(void) {
- int status = 0;
- dyn_message_type *dynMsg = NULL;
- FILE *desc = fopen("descriptors/msg_example1.descriptor", "r");
- assert(desc != NULL);
- status = dynMessage_parse(desc, &dynMsg);
- CHECK_EQUAL(0, status);
- fclose(desc);
-
- char *name = NULL;
- status = dynMessage_getName(dynMsg, &name);
- CHECK_EQUAL(0, status);
- STRCMP_EQUAL("poi", name);
-
- char *version = NULL;
- status = dynMessage_getVersion(dynMsg, &version);
- CHECK_EQUAL(0, status);
- STRCMP_EQUAL("1.0.0", version);
-
- char *annVal = NULL;
- status = dynMessage_getAnnotationEntry(dynMsg, "classname", &annVal);
- CHECK_EQUAL(0, status);
- STRCMP_EQUAL("org.example.PointOfInterest", annVal);
-
- char *nonExist = NULL;
- status = dynMessage_getHeaderEntry(dynMsg, "nonExisting", &nonExist);
- CHECK(status != 0);
- CHECK(nonExist == NULL);
-
- dyn_type *msgType = NULL;
- status = dynMessage_getMessageType(dynMsg, &msgType);
- CHECK_EQUAL(0, status);
- CHECK(msgType != NULL);
-
- dynMessage_destroy(dynMsg);
-}
-
-
-static void msg_test2(void) {
- int status = 0;
- dyn_message_type *dynMsg = NULL;
- FILE *desc = fopen("descriptors/msg_example2.descriptor", "r");
- assert(desc != NULL);
- status = dynMessage_parse(desc, &dynMsg);
- CHECK_EQUAL(0, status);
- fclose(desc);
-
- char *name = NULL;
- status = dynMessage_getName(dynMsg, &name);
- CHECK_EQUAL(0, status);
- STRCMP_EQUAL("track", name);
-
- char *version = NULL;
- status = dynMessage_getVersion(dynMsg, &version);
- CHECK_EQUAL(0, status);
- STRCMP_EQUAL("0.0.1", version);
-
- char *annVal = NULL;
- status = dynMessage_getAnnotationEntry(dynMsg, "classname", &annVal);
- CHECK_EQUAL(0, status);
- STRCMP_EQUAL("org.example.Track", annVal);
-
- char *nonExist = NULL;
- status = dynMessage_getHeaderEntry(dynMsg, "nonExisting", &nonExist);
- CHECK(status != 0);
- CHECK(nonExist == NULL);
-
- dyn_type *msgType = NULL;
- status = dynMessage_getMessageType(dynMsg, &msgType);
- CHECK_EQUAL(0, status);
- CHECK(msgType != NULL);
-
- dynMessage_destroy(dynMsg);
-}
-
-static void msg_test3(void) {
- int status = 0;
- dyn_message_type *dynMsg = NULL;
- FILE *desc = fopen("descriptors/msg_example3.descriptor", "r");
- assert(desc != NULL);
- status = dynMessage_parse(desc, &dynMsg);
- CHECK_EQUAL(0, status);
- fclose(desc);
-
- char *name = NULL;
- status = dynMessage_getName(dynMsg, &name);
- CHECK_EQUAL(0, status);
- STRCMP_EQUAL("logEntry", name);
-
- char *version = NULL;
- status = dynMessage_getVersion(dynMsg, &version);
- CHECK_EQUAL(0, status);
- STRCMP_EQUAL("1.0.0", version);
-
- char *annVal = NULL;
- status = dynMessage_getAnnotationEntry(dynMsg, "classname", &annVal);
- CHECK_EQUAL(0, status);
- STRCMP_EQUAL("org.example.LogEntry", annVal);
-
- char *nonExist = NULL;
- status = dynMessage_getHeaderEntry(dynMsg, "nonExisting", &nonExist);
- CHECK(status != 0);
- CHECK(nonExist == NULL);
-
- dyn_type *msgType = NULL;
- status = dynMessage_getMessageType(dynMsg, &msgType);
- CHECK_EQUAL(0, status);
- CHECK(msgType != NULL);
-
- dynMessage_destroy(dynMsg);
-}
-
-}
-
-
-TEST_GROUP(DynMessageTests) {
- void setup() {
- int level = 1;
- dynCommon_logSetup(stdLog, NULL, level);
- dynType_logSetup(stdLog, NULL, level);
- dynMessage_logSetup(stdLog, NULL, level);
- }
-};
-
-
-TEST(DynMessageTests, msg_test1) {
- msg_test1();
-}
-
-TEST(DynMessageTests, msg_test2) {
- msg_test2();
-}
-
-TEST(DynMessageTests, msg_test3) {
- msg_test3();
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_type_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_type_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_type_tests.cpp
deleted file mode 100644
index db95da4..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_type_tests.cpp
+++ /dev/null
@@ -1,296 +0,0 @@
-/**
- *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.
- */
-#include <CppUTest/TestHarness.h>
-#include "CppUTest/CommandLineTestRunner.h"
-
-extern "C" {
- #include <stdarg.h>
-
- #include "dyn_common.h"
- #include "dyn_type.h"
-
- static void stdLog(void *handle, int level, const char *file, int line, const char *msg, ...) {
- va_list ap;
- const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
- fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
- va_start(ap, msg);
- vfprintf(stderr, msg, ap);
- fprintf(stderr, "\n");
- }
-
- static void runTest(const char *descriptorStr, const char *exName) {
- dyn_type *type;
- type = NULL;
- //printf("\n-- example %s with descriptor string '%s' --\n", exName, descriptorStr);
- int status = dynType_parseWithStr(descriptorStr, exName, NULL, &type);
- CHECK_EQUAL(0, status);
-
- //MEM check, to try to ensure no mem leaks/corruptions occur.
- int i;
- int j;
- int nrOfBurst = 10;
- int burst = 50;
- void *pointers[burst];
- for (j = 0; j < nrOfBurst; j += 1) {
- for (i = 0; i < burst ; i +=1 ) {
- pointers[i] = NULL;
- dynType_alloc(type, &pointers[i]);
- }
- for (i = 0; i < burst ; i +=1 ) {
- dynType_free(type, pointers[i]);
- }
- }
-
- FILE *stream = fopen("/dev/null", "w");
- dynType_print(type, stream);
- fclose(stream);
- dynType_destroy(type);
- //printf("--\n\n");
- }
-}
-
-TEST_GROUP(DynTypeTests) {
- void setup() {
- dynType_logSetup(stdLog, NULL, 1);
- }
-};
-
-#define EX1 "{BbJjIiSsDFNN arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 arg10 arg11 arg12}"
-#define EX2 "{D{DD b_1 b_2}I a b c}"
-#define EX3 "Tsub={DD b_1 b_2};{DLsub;I a b c}"
-#define EX4 "{[I numbers}"
-#define EX5 "[[{DD{iii val3_1 val3_2 val3_3} val1 val2 val3}"
-#define EX6 "Tsample={DD vala valb};Lsample;"
-#define EX7 "Tsample={DD vala valb};[Lsample;"
-#define EX8 "[Tsample={DD a b};Lsample;"
-#define EX9 "*D"
-#define EX10 "Tsample={DD a b};******Lsample;"
-#define EX11 "Tsample=D;Lsample;"
-#define EX12 "Tnode={Lnode;Lnode; left right};{Lnode; head}" //note recursive example
-#define EX13 "Ttype={DDDDD a b c d e};{ltype;Ltype;ltype;Ltype; byVal1 byRef1 byVal2 ByRef2}"
-#define EX14 "{DD{FF{JJ}{II*{ss}}}}" //unnamed fields
-#define EX15 "Tsample={jDD time val1 val2};Tresult={jDlsample; time result sample};Lresult;"
-#define EX16 "Tpoi={BDD id lat lon};Lpoi;"
-
-#define CREATE_EXAMPLES_TEST(DESC) \
- TEST(DynTypeTests, ParseTestExample ## DESC) { \
- runTest(DESC, #DESC); \
- }
-
-CREATE_EXAMPLES_TEST(EX1)
-CREATE_EXAMPLES_TEST(EX2)
-CREATE_EXAMPLES_TEST(EX3)
-CREATE_EXAMPLES_TEST(EX4)
-CREATE_EXAMPLES_TEST(EX5)
-CREATE_EXAMPLES_TEST(EX6)
-CREATE_EXAMPLES_TEST(EX7)
-CREATE_EXAMPLES_TEST(EX8)
-CREATE_EXAMPLES_TEST(EX9)
-CREATE_EXAMPLES_TEST(EX10)
-CREATE_EXAMPLES_TEST(EX11)
-CREATE_EXAMPLES_TEST(EX12)
-CREATE_EXAMPLES_TEST(EX13)
-CREATE_EXAMPLES_TEST(EX14)
-CREATE_EXAMPLES_TEST(EX15)
-CREATE_EXAMPLES_TEST(EX16)
-
-TEST(DynTypeTests, ParseRandomGarbageTest) {
- /*
- unsigned int seed = 4148;
- char *testRandom = getenv("DYN_TYPE_TEST_RANDOM");
- if (testRandom != NULL && strcmp("true", testRandom) == 0) {
- seed = (unsigned int) time(NULL);
- }
- srandom(seed);
- size_t nrOfTests = 100;
-
- printf("\nStarting test with random seed %i and nrOfTests %zu.\n", seed, nrOfTests);
-
- int i;
- int k;
- int c;
- int sucesses = 0;
- char descriptorStr[32];
- descriptorStr[31] = '\0';
- for(i = 0; i < nrOfTests; i += 1) {
- for(k = 0; k < 31; k += 1) {
- do {
- c = (char) (((random() * 128) / RAND_MAX) - 1);
- } while (!isprint(c));
- descriptorStr[k] = c;
- if (c == '\0') {
- break;
- }
- }
-
- //printf("ParseRandomGarbageTest iteration %i with descriptor string '%s'\n", k, descriptorStr);
- dyn_type *type = NULL;
- int status = dynType_parseWithStr(descriptorStr, NULL, NULL, &type);
- if (status == 0) {
- dynType_destroy(type);
- }
- }
- */
-}
-
-TEST(DynTypeTests, AssignTest1) {
- struct ex1 {
- int32_t a;
- int32_t b;
- int32_t c;
- };
- struct ex1 inst;
- const char *desc = "{III a b c}";
- dyn_type *type = NULL;
- int status = dynType_parseWithStr(desc, NULL, NULL, &type);
- CHECK_EQUAL(0, status);
- int32_t val1 = 2;
- int32_t val2 = 4;
- int32_t val3 = 8;
- dynType_complex_setValueAt(type, 0, &inst, &val1);
- CHECK_EQUAL(2, inst.a);
- dynType_complex_setValueAt(type, 1, &inst, &val2);
- CHECK_EQUAL(4, inst.b);
- dynType_complex_setValueAt(type, 2, &inst, &val3);
- CHECK_EQUAL(8, inst.c);
-
- dynType_destroy(type);
-}
-
-TEST(DynTypeTests, AssignTest2) {
- struct ex {
- int32_t a;
- struct {
- double a;
- double b;
- } b;
- };
- struct ex inst;
- const char *desc = "{I{DD a b} a b}";
- dyn_type *type = NULL;
- int status = dynType_parseWithStr(desc, NULL, NULL, &type);
- CHECK_EQUAL(0, status);
- int32_t a = 2;
- double b_a = 1.1;
- double b_b = 1.2;
-
- dynType_complex_setValueAt(type, 0, &inst, &a);
- CHECK_EQUAL(2, inst.a);
-
- void *loc = NULL;
- dyn_type *subType = NULL;
- dynType_complex_valLocAt(type, 1, (void *)&inst, &loc);
- dynType_complex_dynTypeAt(type, 1, &subType);
-
- dynType_complex_setValueAt(subType, 0, &inst.b, &b_a);
- CHECK_EQUAL(1.1, inst.b.a);
-
- dynType_complex_setValueAt(subType, 1, &inst.b, &b_b);
- CHECK_EQUAL(1.2, inst.b.b);
-
- dynType_destroy(type);
-}
-
-TEST(DynTypeTests, AssignTest3) {
- int simple = 1;
- dyn_type *type = NULL;
- int rc = dynType_parseWithStr("N", NULL, NULL, &type);
- CHECK_EQUAL(0, rc);
-
- int newValue = 42;
- void *loc = &simple;
- void *input = &newValue;
- dynType_simple_setValue(type, loc, input);
- CHECK_EQUAL(42, simple);
- dynType_destroy(type);
-}
-
-TEST(DynTypeTests, MetaInfoTest) {
- dyn_type *type = NULL;
- int rc = 0;
- rc = dynType_parseWithStr("#a=t;{DD#longname=longvalue;D a b c}", NULL, NULL, &type);
- //rc = dynType_parseWithStr("{DDD a b c}", NULL, NULL, &type);
-
- CHECK_EQUAL(0, rc);
-
- const char *val = NULL;
- val = dynType_getMetaInfo(type, "a");
- CHECK(val != NULL);
- CHECK(strcmp("t", val) == 0);
-
- val = dynType_getMetaInfo(type, "longname");
- CHECK(val == NULL);
-
- val = dynType_getMetaInfo(type, "nonexisting");
- CHECK(val == NULL);
-
- dynType_destroy(type);
-}
-
-TEST(DynTypeTests, SequenceWithPointerTest) {
- struct val {
- double a;
- double b;
- };
-
- struct item {
- int64_t a;
- const char *text;
- struct val val;
- double c;
- double d;
- long e;
- };
-
- struct item_sequence {
- uint32_t cap;
- uint32_t len;
- struct item **buf;
- };
-
- dyn_type *type = NULL;
- int rc = 0;
- rc = dynType_parseWithStr("Tval={DD a b};Titem={Jtlval;DDJ a text val c d e};**[Litem;", NULL, NULL, &type);
- CHECK_EQUAL(0, rc);
-
- struct item_sequence *seq = NULL;
- rc = dynType_alloc(type, (void **)&seq);
- CHECK_EQUAL(0, rc);
- CHECK(seq != NULL);
-
- dynType_free(type, seq);
-
- /*
-
-
- struct item_sequence *items = (struct item_sequence *) calloc(1,sizeof(struct item_sequence));
- items->buf = (struct item **) calloc(2, sizeof(struct item *));
- items->cap = 2;
- items->len = 2;
- items->buf[0] = (struct item *)calloc(1, sizeof(struct item));
- items->buf[0]->text = strdup("boe");
- items->buf[1] = (struct item *)calloc(1, sizeof(struct item));
- items->buf[1]->text = strdup("boe2");
-
- dynType_free(type, items);
- */
-
- dynType_destroy(type);
-}
-
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp
deleted file mode 100644
index 8b4044d..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp
+++ /dev/null
@@ -1,428 +0,0 @@
-/**
- *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.
- */
-#include <CppUTest/TestHarness.h>
-#include <float.h>
-#include <assert.h>
-#include "CppUTest/CommandLineTestRunner.h"
-
-extern "C" {
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
-#include <ffi.h>
-
-#include "dyn_common.h"
-#include "dyn_type.h"
-#include "json_serializer.h"
-#include "json_rpc.h"
-
-static void stdLog(void *handle, int level, const char *file, int line, const char *msg, ...) {
- va_list ap;
- const char *levels[5] = {"NIL", "ERROR", "WARNING", "INFO", "DEBUG"};
- fprintf(stderr, "%s: FILE:%s, LINE:%i, MSG:",levels[level], file, line);
- va_start(ap, msg);
- vfprintf(stderr, msg, ap);
- fprintf(stderr, "\n");
-}
-
-
- void prepareTest(void) {
- dyn_function_type *dynFunc = NULL;
- int rc = dynFunction_parseWithStr("add(#am=handle;PDD#am=pre;*D)N", NULL, &dynFunc);
- CHECK_EQUAL(0, rc);
-
- char *result = NULL;
-
- void *handle = NULL;
- double arg1 = 1.0;
- double arg2 = 2.0;
-
- void *args[4];
- args[0] = &handle;
- args[1] = &arg1;
- args[2] = &arg2;
-
- rc = jsonRpc_prepareInvokeRequest(dynFunc, "add", args, &result);
- CHECK_EQUAL(0, rc);
-
- //printf("result is %s\n", result);
-
- STRCMP_CONTAINS("\"add\"", result);
- STRCMP_CONTAINS("1.0", result);
- STRCMP_CONTAINS("2.0", result);
-
- free(result);
- dynFunction_destroy(dynFunc);
- }
-
- void handleTestPre(void) {
- dyn_function_type *dynFunc = NULL;
- int rc = dynFunction_parseWithStr("add(#am=handle;PDD#am=pre;*D)N", NULL, &dynFunc);
- CHECK_EQUAL(0, rc);
-
- const char *reply = "{\"r\":2.2}";
- double result = -1.0;
- double *out = &result;
- void *args[4];
- args[3] = &out;
- rc = jsonRpc_handleReply(dynFunc, reply, args);
- CHECK_EQUAL(0, rc);
- //CHECK_EQUAL(2.2, result);
-
- dynFunction_destroy(dynFunc);
- }
-
- int add(void *handle, double a, double b, double *result) {
- *result = a + b;
- return 0;
- }
-
- int getName_example4(void *handle, char** result) {
- *result = strdup("allocatedInFunction");
- return 0;
- }
-
- struct tst_seq {
- uint32_t cap;
- uint32_t len;
- double *buf;
- };
-
-
- //StatsResult={DDD[D average min max input}
- struct tst_StatsResult {
- double average;
- double min;
- double max;
- struct tst_seq input;
- };
-
-
- int stats(void *handle, struct tst_seq input, struct tst_StatsResult **out) {
- assert(out != NULL);
- assert(*out == NULL);
- double total = 0.0;
- unsigned int count = 0;
- double max = DBL_MIN;
- double min = DBL_MAX;
-
- unsigned int i;
- for (i = 0; i<input.len; i += 1) {
- total += input.buf[i];
- count += 1;
- if (input.buf[i] > max) {
- max = input.buf[i];
- }
- if (input.buf[i] < min) {
- min = input.buf[i];
- }
- }
-
- struct tst_StatsResult *result = (struct tst_StatsResult *) calloc(1, sizeof(*result));
- result->average = total / count;
- result->min = min;
- result->max = max;
- double *buf = (double *)calloc(input.len, sizeof(double));
- memcpy(buf, input.buf, input.len * sizeof(double));
- result->input.len = input.len;
- result->input.cap = input.len;
- result->input.buf = buf;
-
- *out = result;
- return 0;
- }
-
- struct item {
- double a;
- double b;
- };
-
- struct item_seq {
- uint32_t cap;
- uint32_t len;
- struct item **buf;
- };
-
- struct tst_serv {
- void *handle;
- int (*add)(void *, double, double, double *);
- int (*sub)(void *, double, double, double *);
- int (*sqrt)(void *, double, double *);
- int (*stats)(void *, struct tst_seq, struct tst_StatsResult **);
- };
-
- struct tst_serv_example4 {
- void *handle;
- int (*getName_example4)(void *, char** name);
- };
-
- void callTestPreAllocated(void) {
- dyn_interface_type *intf = NULL;
- FILE *desc = fopen("descriptors/example1.descriptor", "r");
- CHECK(desc != NULL);
- int rc = dynInterface_parse(desc, &intf);
- CHECK_EQUAL(0, rc);
- fclose(desc);
-
- char *result = NULL;
-
- struct tst_serv serv;
- serv.handle = NULL;
- serv.add = add;
-
-
- rc = jsonRpc_call(intf, &serv, "{\"m\":\"add(DD)D\", \"a\": [1.0,2.0]}", &result);
- CHECK_EQUAL(0, rc);
- STRCMP_CONTAINS("3.0", result);
-
- free(result);
- dynInterface_destroy(intf);
- }
-
- void callTestOutput(void) {
- dyn_interface_type *intf = NULL;
- FILE *desc = fopen("descriptors/example1.descriptor", "r");
- CHECK(desc != NULL);
- int rc = dynInterface_parse(desc, &intf);
- CHECK_EQUAL(0, rc);
- fclose(desc);
-
- char *result = NULL;
-
- struct tst_serv serv;
- serv.handle = NULL;
- serv.stats = stats;
-
- rc = jsonRpc_call(intf, &serv, "{\"m\":\"stats([D)LStatsResult;\", \"a\": [[1.0,2.0]]}", &result);
- CHECK_EQUAL(0, rc);
- STRCMP_CONTAINS("1.5", result); //avg
-
- free(result);
- dynInterface_destroy(intf);
- }
-
- void handleTestOut(void) {
- dyn_interface_type *intf = NULL;
- FILE *desc = fopen("descriptors/example1.descriptor", "r");
- CHECK(desc != NULL);
- int rc = dynInterface_parse(desc, &intf);
- CHECK_EQUAL(0, rc);
- fclose(desc);
-
- struct methods_head *head;
- dynInterface_methods(intf, &head);
- dyn_function_type *func = NULL;
- struct method_entry *entry = NULL;
- TAILQ_FOREACH(entry, head, entries) {
- if (strcmp(entry->name, "stats") == 0) {
- func = entry->dynFunc;
- break;
- }
- }
- CHECK(func != NULL);
-
- const char *reply = "{\"r\":{\"input\":[1.0,2.0],\"max\":2.0,\"average\":1.5,\"min\":1.0}}";
-
- void *args[3];
- args[0] = NULL;
- args[1] = NULL;
- args[2] = NULL;
-
- struct tst_StatsResult *result = NULL;
- void *out = &result;
- args[2] = &out;
-
- rc = jsonRpc_handleReply(func, reply, args);
- CHECK_EQUAL(0, rc);
- CHECK_EQUAL(1.5, result->average);
-
- free(result->input.buf);
- free(result);
- dynInterface_destroy(intf);
- }
-
- static void handleTestOutputSequence(void) {
- dyn_interface_type *intf = NULL;
- FILE *desc = fopen("descriptors/example2.descriptor", "r");
- CHECK(desc != NULL);
- int rc = dynInterface_parse(desc, &intf);
- CHECK_EQUAL(0, rc);
- fclose(desc);
-
- struct methods_head *head;
- dynInterface_methods(intf, &head);
- dyn_function_type *func = NULL;
- struct method_entry *entry = NULL;
- TAILQ_FOREACH(entry, head, entries) {
- if (strcmp(entry->name, "example1") == 0) {
- func = entry->dynFunc;
- break;
- }
- }
- CHECK(func != NULL);
-
- //dyn_type *arg = dynFunction_argumentTypeForIndex(func, 1);
- //dynType_print(arg, stdout);
-
- const char *reply = "{\"r\":[{\"a\":1.0,\"b\":1.5},{\"a\":2.0,\"b\":2.5}]}";
-
- void *args[2];
- args[0] = NULL;
- args[1] = NULL;
-
- struct item_seq *result = NULL;
- void *out = &result;
- args[1] = &out;
-
- rc = jsonRpc_handleReply(func, reply, args);
- CHECK_EQUAL(0, rc);
- CHECK_EQUAL(2, result->len);
- CHECK_EQUAL(1.0, result->buf[0]->a);
- CHECK_EQUAL(1.5, result->buf[0]->b);
- CHECK_EQUAL(2.0, result->buf[1]->a);
- CHECK_EQUAL(2.5, result->buf[1]->b);
-
-
- unsigned int i;
- for (i = 0; i < result->len; i +=1 ) {
- free(result->buf[i]);
- }
- free(result->buf);
- free(result);
- dynInterface_destroy(intf);
- }
-
-
-
-
- void callTestOutChar(void) {
- dyn_interface_type *intf = NULL;
- FILE *desc = fopen("descriptors/example4.descriptor", "r");
- CHECK(desc != NULL);
- int rc = dynInterface_parse(desc, &intf);
- CHECK_EQUAL(0, rc);
- fclose(desc);
-
- char *result = NULL;
-
- struct tst_serv_example4 serv;
- serv.handle = NULL;
- serv.getName_example4 = getName_example4;
-
- rc = jsonRpc_call(intf, &serv, "{\"m\":\"getName(V)t\", \"a\": []}", &result);
- CHECK_EQUAL(0, rc);
-
- STRCMP_CONTAINS("allocatedInFunction", result);
-
- free(result);
- dynInterface_destroy(intf);
- }
-
-
- void handleTestOutChar(void) {
- dyn_interface_type *intf = NULL;
- FILE *desc = fopen("descriptors/example4.descriptor", "r");
- CHECK(desc != NULL);
- int rc = dynInterface_parse(desc, &intf);
- CHECK_EQUAL(0, rc);
- fclose(desc);
-
- struct methods_head *head;
- dynInterface_methods(intf, &head);
- dyn_function_type *func = NULL;
- struct method_entry *entry = NULL;
- TAILQ_FOREACH(entry, head, entries) {
- if (strcmp(entry->name, "getName") == 0) {
- func = entry->dynFunc;
- break;
- }
- }
-
- CHECK(func != NULL);
-
- const char *reply = "{\"r\": \"this is a test string\" }";
- char *result = NULL;
- void *out = &result;
-
- void *args[2];
- args[0] = NULL;
- args[1] = &out;
-
- rc = jsonRpc_handleReply(func, reply, args);
-
- STRCMP_EQUAL("this is a test string", result);
-
- free(result);
- dynInterface_destroy(intf);
- }
-
-
-}
-
-TEST_GROUP(JsonRpcTests) {
- void setup() {
- int lvl = 1;
- dynCommon_logSetup(stdLog, NULL, lvl);
- dynType_logSetup(stdLog, NULL,lvl);
- dynFunction_logSetup(stdLog, NULL,lvl);
- dynInterface_logSetup(stdLog, NULL,lvl);
- jsonSerializer_logSetup(stdLog, NULL, lvl);
- jsonRpc_logSetup(stdLog, NULL, lvl);
-
- }
-};
-
-
-TEST(JsonRpcTests, prepareTest) {
- prepareTest();
-}
-
-TEST(JsonRpcTests, handleTestPre) {
- handleTestPre();
-}
-
-TEST(JsonRpcTests, handleTestOut) {
- handleTestOut();
-}
-
-TEST(JsonRpcTests, callPre) {
- callTestPreAllocated();
-}
-
-TEST(JsonRpcTests, callOut) {
- callTestOutput();
-}
-
-TEST(JsonRpcTests, handleOutSeq) {
- handleTestOutputSequence();
-}
-
-
-
-TEST(JsonRpcTests, callTestOutChar) {
- callTestOutChar();
-}
-
-TEST(JsonRpcTests, handleOutChar) {
- handleTestOutChar();
-}
-
[6/6] celix git commit: CELIX-309: Move dfi to top-level subdir
Posted by pn...@apache.org.
CELIX-309: Move dfi to top-level subdir
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/18a5bf74
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/18a5bf74
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/18a5bf74
Branch: refs/heads/develop
Commit: 18a5bf743a3db0a198dd8cb693351d7dc89629be
Parents: d8e8fab
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Nov 27 15:55:40 2015 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Fri Nov 27 15:55:40 2015 +0100
----------------------------------------------------------------------
.travis.yml | 2 +-
CMakeLists.txt | 1 +
dfi/CMakeLists.txt | 92 ++
dfi/private/src/dyn_common.c | 151 +++
dfi/private/src/dyn_function.c | 335 +++++
dfi/private/src/dyn_interface.c | 431 +++++++
dfi/private/src/dyn_message.c | 337 ++++++
dfi/private/src/dyn_type.c | 1144 ++++++++++++++++++
dfi/private/src/json_rpc.c | 335 +++++
dfi/private/src/json_serializer.c | 477 ++++++++
dfi/private/src/memstream/fmemopen.c | 78 ++
dfi/private/src/memstream/open_memstream.c | 130 ++
.../test/avro_descriptor_translator_tests.cpp | 179 +++
.../test/descriptors/example1.descriptor | 13 +
.../test/descriptors/example2.descriptor | 9 +
.../test/descriptors/example3.descriptor | 11 +
.../test/descriptors/example4.descriptor | 8 +
.../test/descriptors/msg_example1.descriptor | 10 +
.../test/descriptors/msg_example2.descriptor | 12 +
.../test/descriptors/msg_example3.descriptor | 10 +
dfi/private/test/dyn_closure_tests.cpp | 161 +++
dfi/private/test/dyn_function_tests.cpp | 252 ++++
dfi/private/test/dyn_interface_tests.cpp | 118 ++
dfi/private/test/dyn_message_tests.cpp | 184 +++
dfi/private/test/dyn_type_tests.cpp | 296 +++++
dfi/private/test/json_rpc_tests.cpp | 428 +++++++
dfi/private/test/json_serializer_tests.cpp | 508 ++++++++
dfi/private/test/run_tests.cpp | 24 +
dfi/private/test/schemas/complex.avdl | 30 +
dfi/private/test/schemas/complex.avpr | 55 +
dfi/private/test/schemas/invalid1.avpr | 47 +
dfi/private/test/schemas/invalid2.avpr | 49 +
dfi/private/test/schemas/simple.avdl | 24 +
dfi/private/test/schemas/simple.avpr | 51 +
dfi/private/test/schemas/simple_min.avpr | 19 +
dfi/public/include/dfi_log_util.h | 63 +
dfi/public/include/dyn_common.h | 47 +
dfi/public/include/dyn_function.h | 61 +
dfi/public/include/dyn_interface.h | 63 +
dfi/public/include/dyn_message.h | 53 +
dfi/public/include/dyn_type.h | 157 +++
dfi/public/include/json_rpc.h | 37 +
dfi/public/include/json_serializer.h | 37 +
dfi/public/include/memstream/README.md | 49 +
dfi/public/include/memstream/fmemopen.h | 52 +
dfi/public/include/memstream/open_memstream.h | 15 +
.../remote_service_admin_dfi/CMakeLists.txt | 4 -
.../dynamic_function_interface/CMakeLists.txt | 41 -
.../dynamic_function_interface/dfi_log_util.h | 63 -
.../dynamic_function_interface/dyn_common.c | 151 ---
.../dynamic_function_interface/dyn_common.h | 47 -
.../dynamic_function_interface/dyn_function.c | 335 -----
.../dynamic_function_interface/dyn_function.h | 61 -
.../dynamic_function_interface/dyn_interface.c | 431 -------
.../dynamic_function_interface/dyn_interface.h | 63 -
.../dynamic_function_interface/dyn_message.c | 337 ------
.../dynamic_function_interface/dyn_message.h | 53 -
.../dynamic_function_interface/dyn_type.c | 1144 ------------------
.../dynamic_function_interface/dyn_type.h | 157 ---
.../dynamic_function_interface/json_rpc.c | 335 -----
.../dynamic_function_interface/json_rpc.h | 37 -
.../json_serializer.c | 477 --------
.../json_serializer.h | 37 -
.../memstream/README.md | 49 -
.../memstream/fmemopen.c | 78 --
.../memstream/fmemopen.h | 52 -
.../memstream/open_memstream.c | 130 --
.../memstream/open_memstream.h | 15 -
.../CMakeLists.txt | 47 -
.../avro_descriptor_translator_tests.cpp | 179 ---
.../descriptors/example1.descriptor | 13 -
.../descriptors/example2.descriptor | 9 -
.../descriptors/example3.descriptor | 11 -
.../descriptors/example4.descriptor | 8 -
.../descriptors/msg_example1.descriptor | 10 -
.../descriptors/msg_example2.descriptor | 12 -
.../descriptors/msg_example3.descriptor | 10 -
.../dyn_closure_tests.cpp | 161 ---
.../dyn_function_tests.cpp | 252 ----
.../dyn_interface_tests.cpp | 118 --
.../dyn_message_tests.cpp | 184 ---
.../dyn_type_tests.cpp | 296 -----
.../json_rpc_tests.cpp | 428 -------
.../json_serializer_tests.cpp | 508 --------
.../run_tests.cpp | 24 -
.../schemas/complex.avdl | 30 -
.../schemas/complex.avpr | 55 -
.../schemas/invalid1.avpr | 47 -
.../schemas/invalid2.avpr | 49 -
.../schemas/simple.avdl | 24 -
.../schemas/simple.avpr | 51 -
.../schemas/simple_min.avpr | 19 -
.../remote_service_admin_dfi/rsa/CMakeLists.txt | 5 +-
.../rsa_tst/CMakeLists.txt | 2 +-
.../topology_manager/tms_tst/CMakeLists.txt | 2 +-
95 files changed, 6648 insertions(+), 6648 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index 087432e..5bcddf7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -34,7 +34,7 @@ script:
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then cmake -DBUILD_RSA_REMOTE_SERVICE_ADMIN_DFI=ON -DBUILD_DEPLOYMENT_ADMIN=ON -DBUILD_DEPENDENCY_MANAGER=ON -DBUILD_EXAMPLES=ON -DBUILD_LOG_SERVICE=ON -DBUILD_LOG_WRITER=ON -DBUILD_REMOTE_SERVICE_ADMIN=ON -DBUILD_RSA_DISCOVERY_CONFIGURED=ON -DBUILD_RSA_DISCOVERY_ETCD=ON -DBUILD_RSA_DISCOVERY_SHM=ON -DBUILD_RSA_EXAMPLES=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_SHM=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_HTTP=ON -DBUILD_REMOTE_SHELL=ON -DBUILD_SHELL=ON -DBUILD_SHELL_TUI=ON -DBUILD_DEVICE_ACCESS=ON -DBUILD_DEVICE_ACCESS_EXAMPLE=ON -DBUILD_FRAMEWORK_TESTS=OFF -DENABLE_TESTING=ON ${BUILD_OPTS} -DCMAKE_INSTALL_PREFIX=../install ..; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then cmake -DBUILD_RSA_REMOTE_SERVICE_ADMIN_DFI=ON -DBUILD_DEPLOYMENT_ADMIN=ON -DBUILD_DEPENDENCY_MANAGER=ON -DBUILD_EXAMPLES=ON -DBUILD_LOG_SERVICE=ON -DBUILD_LOG_WRITER=ON -DBUILD_REMOTE_SERVICE_ADMIN=ON -DBUILD_RSA_DISCOVERY_CONFIGURED=ON -DBUILD_RSA_DISCOVERY_ETCD=ON -DBUILD_RSA_DISCOVERY_SHM=OFF -DBUILD_RSA_EXAMPLES=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_SHM=OFF -DBUILD_RSA_REMOTE_SERVICE_ADMIN_HTTP=ON -DBUILD_REMOTE_SHELL=ON -DBUILD_SHELL=ON -DBUILD_SHELL_TUI=ON -DBUILD_DEVICE_ACCESS=ON -DBUILD_DEVICE_ACCESS_EXAMPLE=ON -DBUILD_FRAMEWORK_TESTS=OFF -DENABLE_TESTING=ON -DFFI_LIBRARY=/usr/local/opt/libffi/lib/libffi.dylib ${BUILD_OPTS} -DCMAKE_INSTALL_PREFIX=../install ..; fi
- make all && make deploy && make install-all
- - export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH:`pwd`/utils:`pwd`/framework:`pwd`/remote_services/remote_service_admin_dfi/dynamic_function_interface && make test ARGS="-V"
+ - export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH:`pwd`/utils:`pwd`/framework:`pwd`/dfi && make test ARGS="-V"
after_success:
- if [ "$CC" = "gcc" ] && [ "$TRAVIS_OS_NAME" = "linux" ]; then
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 014621c..592983c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -86,5 +86,6 @@ add_subdirectory(dependency_manager)
add_subdirectory(launcher)
add_subdirectory(framework)
add_subdirectory(utils)
+add_subdirectory(dfi)
deploy_targets()
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/dfi/CMakeLists.txt b/dfi/CMakeLists.txt
new file mode 100644
index 0000000..b9b5886
--- /dev/null
+++ b/dfi/CMakeLists.txt
@@ -0,0 +1,92 @@
+# 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.
+
+find_package(FFI REQUIRED)
+find_package(Jansson REQUIRED)
+
+include_directories(
+ ${FFI_INCLUDE_DIRS}
+ ${JANSSON_INCLUDE_DIRS}
+ private/include
+ public/include
+)
+
+set(MEMSTREAM_SOURCES "")
+set(MEMSTREAM_INCLUDES "")
+if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+ set(MEMSTREAM_SOURCES private/src/memstream/open_memstream.c private/src/memstream/fmemopen.c)
+ set(MEMSTREAM_INCLUDES public/include/memstream/open_memstream.h public/include/memstream/fmemopen.h)
+endif()
+
+add_library(celix_dfi SHARED
+ private/src/dyn_common.c
+ private/src/dyn_type.c
+ private/src/dyn_function.c
+ private/src/dyn_interface.c
+ private/src/dyn_message.c
+ private/src/json_serializer.c
+ private/src/json_rpc.c
+ ${MEMSTREAM_SOURCES}
+
+ public/include/dyn_common.h
+ public/include/dyn_type.h
+ public/include/dyn_function.h
+ public/include/dyn_interface.h
+ public/include/dyn_message.h
+ public/include/json_serializer.h
+ public/include/json_rpc.h
+ ${MEMSTREAM_INCLUDES}
+)
+target_link_libraries(celix_dfi ${FFI_LIBRARIES} ${JANSSON_LIBRARY})
+
+install(TARGETS celix_dfi DESTINATION lib COMPONENT framework)
+FILE(GLOB files "public/include/*.h" ${MEMSTREAM_INCLUDES})
+INSTALL(FILES ${files} DESTINATION include/celix/dfi COMPONENT framework)
+
+
+if (ENABLE_TESTING)
+ find_package(CppUTest REQUIRED)
+
+ include_directories(${CPPUTEST_INCLUDE_DIR})
+
+ SET(CMAKE_SKIP_BUILD_RPATH FALSE) #TODO needed?
+ SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) #TODO needed?
+ SET(CMAKE_INSTALL_RPATH "${PROJECT_BINARY_DIR}/dfi")
+
+
+ add_executable(test_dfi
+ private/test/dyn_type_tests.cpp
+ private/test/dyn_function_tests.cpp
+ private/test/dyn_closure_tests.cpp
+ private/test/dyn_interface_tests.cpp
+ private/test/dyn_message_tests.cpp
+ private/test/json_serializer_tests.cpp
+ private/test/json_rpc_tests.cpp
+ private/test/run_tests.cpp
+ )
+ target_link_libraries(test_dfi celix_dfi ${FFI_LIBRARIES} ${CPPUTEST_LIBRARY})
+
+ add_custom_target(copy-input
+ COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/private/test/schemas schemas
+ COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/private/test/descriptors descriptors
+ )
+ add_dependencies(test_dfi copy-input)
+
+ add_test(NAME run_test_dfi COMMAND test_dfi)
+ SETUP_TARGET_FOR_COVERAGE(test_dfi_cov test_dfi ${CMAKE_BINARY_DIR}/coverage/test_dfi/test_dfi)
+endif(ENABLE_TESTING)
+
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/src/dyn_common.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/dyn_common.c b/dfi/private/src/dyn_common.c
new file mode 100644
index 0000000..6934e17
--- /dev/null
+++ b/dfi/private/src/dyn_common.c
@@ -0,0 +1,151 @@
+/**
+ *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.
+ */
+#include "dyn_common.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <stdbool.h>
+
+#if defined(BSD) || defined(__APPLE__)
+#include "open_memstream.h"
+#include "fmemopen.h"
+#endif
+
+static const int OK = 0;
+static const int ERROR = 1;
+
+DFI_SETUP_LOG(dynCommon)
+
+static bool dynCommon_charIn(int c, const char *acceptedChars);
+
+int dynCommon_parseName(FILE *stream, char **result) {
+ return dynCommon_parseNameAlsoAccept(stream, NULL, result);
+}
+
+int dynCommon_parseNameAlsoAccept(FILE *stream, const char *acceptedChars, char **result) {
+ int status = OK;
+
+ char *buf = NULL;
+ size_t size = 0;
+ int strLen = 0;
+ FILE *name = open_memstream(&buf, &size);
+
+ if (name != NULL) {
+ int c = getc(stream);
+ while (isalnum(c) || c == '_' || dynCommon_charIn(c, acceptedChars)) {
+ fputc(c, name);
+ c = getc(stream);
+ strLen += 1;
+ }
+ fflush(name);
+ fclose(name);
+ ungetc(c, stream);
+ } else {
+ status = ERROR;
+ LOG_ERROR("Error creating mem stream for name. %s", strerror(errno));
+ }
+
+ if (status == OK) {
+ if (strLen == 0) {
+ status = ERROR;
+ LOG_ERROR("Parsed empty name");
+ }
+ }
+
+ if (status == OK) {
+ LOG_DEBUG("Parsed name '%s'", buf);
+ *result = buf;
+ } else if (buf != NULL) {
+ free(buf);
+ }
+
+ return status;
+}
+
+int dynCommon_parseNameValue(FILE *stream, char **outName, char **outValue) {
+ int status = OK;
+ char *name = NULL;
+ char *value = NULL;
+ const char *valueAcceptedChars = ".<>{}[]?;:~!@#$%^&*()_+-=,./\\'\"";
+
+ status = dynCommon_parseName(stream, &name);
+ if (status == OK) {
+ status = dynCommon_eatChar(stream, '=');
+ }
+ if (status == OK) {
+ status = dynCommon_parseNameAlsoAccept(stream, valueAcceptedChars, &value); //NOTE use different more lenient function e.g. only stop at '\n' ?
+ }
+
+ if (status == OK) {
+ *outName = name;
+ *outValue = value;
+ } else {
+ if (name != NULL) {
+ free(name);
+ }
+ if (value != NULL) {
+ free(value);
+ }
+ }
+ return status;
+}
+
+int dynCommon_eatChar(FILE *stream, int expected) {
+ int status = OK;
+ long loc = ftell(stream);
+ int c = fgetc(stream);
+ if (c != expected) {
+ status = ERROR;
+ LOG_ERROR("Error parsing, expected token '%c' got '%c' at position %li", expected, loc);
+ }
+ return status;
+}
+
+static bool dynCommon_charIn(int c, const char *acceptedChars) {
+ bool status = false;
+ if (acceptedChars != NULL) {
+ int i;
+ for (i = 0; acceptedChars[i] != '\0'; i += 1) {
+ if (c == acceptedChars[i]) {
+ status = true;
+ break;
+ }
+ }
+ }
+
+ return status;
+}
+
+void dynCommon_clearNamValHead(struct namvals_head *head) {
+ struct namval_entry *tmp = NULL;
+ struct namval_entry *entry = TAILQ_FIRST(head);
+ while (entry != NULL) {
+ tmp = entry;
+
+ if (entry->name != NULL) {
+ free(entry->name);
+ }
+ if (entry->value != NULL) {
+ free(entry->value);
+ }
+ entry = TAILQ_NEXT(entry, entries);
+ free(tmp);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/src/dyn_function.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/dyn_function.c b/dfi/private/src/dyn_function.c
new file mode 100644
index 0000000..9ef7aa0
--- /dev/null
+++ b/dfi/private/src/dyn_function.c
@@ -0,0 +1,335 @@
+/**
+ *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.
+ */
+#include "dyn_function.h"
+
+#include <strings.h>
+#include <stdlib.h>
+
+#include "dyn_common.h"
+
+struct _dyn_function_type {
+ char *name;
+ struct types_head *refTypes; //NOTE not owned
+ TAILQ_HEAD(,_dyn_function_argument_type) arguments;
+ ffi_type **ffiArguments;
+ dyn_type *funcReturn;
+ ffi_cif cif;
+
+ //closure part
+ ffi_closure *ffiClosure;
+ void (*fn)(void);
+ void *userData;
+ void (*bind)(void *userData, void *args[], void *ret);
+};
+
+typedef struct _dyn_function_argument_type dyn_function_argument_type;
+struct _dyn_function_argument_type {
+ int index;
+ char *name;
+ enum dyn_function_argument_meta argumentMeta;
+ dyn_type *type;
+ TAILQ_ENTRY(_dyn_function_argument_type) entries;
+};
+
+static const int OK = 0;
+static const int MEM_ERROR = 1;
+static const int PARSE_ERROR = 2;
+static const int ERROR = 2;
+
+DFI_SETUP_LOG(dynFunction)
+
+static int dynFunction_initCif(dyn_function_type *dynFunc);
+static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descriptor);
+static void dynFunction_ffiBind(ffi_cif *cif, void *ret, void *args[], void *userData);
+
+int dynFunction_parse(FILE *descriptor, struct types_head *refTypes, dyn_function_type **out) {
+ int status = OK;
+ dyn_function_type *dynFunc = NULL;
+ LOG_DEBUG("Creating dyn function", descriptor);
+
+ dynFunc = calloc(1, sizeof(*dynFunc));
+
+ if (dynFunc != NULL) {
+ TAILQ_INIT(&dynFunc->arguments);
+ dynFunc->refTypes = refTypes;
+ status = dynFunction_parseDescriptor(dynFunc, descriptor);
+ if (status == 0) {
+ int rc = dynFunction_initCif(dynFunc);
+ if (rc != 0) {
+ LOG_ERROR("Error initializing cif");
+ status = ERROR;
+ }
+ }
+ } else {
+ LOG_ERROR("Error allocationg memory for dyn functipn\n");
+ status = MEM_ERROR;
+ }
+
+ if (status == OK) {
+ dyn_function_argument_type *arg = NULL;
+ TAILQ_FOREACH(arg, &dynFunc->arguments, entries) {
+ const char *meta = dynType_getMetaInfo(arg->type, "am");
+ if (meta == NULL) {
+ arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__STD;
+ } else if (strcmp(meta, "handle") == 0) {
+ arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__HANDLE;
+ } else if (strcmp(meta, "pre") == 0) {
+ arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT;
+ } else if (strcmp(meta, "out") == 0) {
+ arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__OUTPUT;
+ } else {
+ LOG_WARNING("unknown argument meta '%s' encountered", meta);
+ arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__STD;
+ }
+ }
+ }
+
+ if (status == OK) {
+ *out = dynFunc;
+ } else {
+ if (dynFunc != NULL) {
+ dynFunction_destroy(dynFunc);
+ }
+
+ }
+
+ return status;
+}
+
+int dynFunction_parseWithStr(const char *descriptor, struct types_head *refTypes, dyn_function_type **out) {
+ int status = OK;
+ FILE *stream = fmemopen((char *)descriptor, strlen(descriptor), "r");
+ if (stream != NULL) {
+ status = dynFunction_parse(stream, refTypes, out);
+ fclose(stream);
+ } else {
+ status = MEM_ERROR;
+ LOG_ERROR("Error creating mem stream for descriptor string. %s", strerror(errno));
+ }
+ return status;
+}
+
+static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descriptor) {
+ int status = OK;
+ char *name = NULL;
+
+ status = dynCommon_parseName(descriptor, &name);
+
+ if (status == OK) {
+ dynFunc->name = name;
+ }
+
+ if (status == OK) {
+ int c = fgetc(descriptor);
+ if ( c != '(') {
+ status = PARSE_ERROR;
+ LOG_ERROR("Expected '(' token got '%c'", c);
+ }
+ }
+
+ int nextChar = fgetc(descriptor);
+ int index = 0;
+ dyn_type *type = NULL;
+ char argName[32];
+ while (nextChar != ')' && status == 0) {
+ ungetc(nextChar, descriptor);
+ type = NULL;
+
+ dyn_function_argument_type *arg = NULL;
+
+ status = dynType_parse(descriptor, NULL, dynFunc->refTypes, &type);
+ if (status == 0) {
+ arg = calloc(1, sizeof(*arg));
+ if (arg != NULL) {
+ arg->index = index;
+ arg->type = type;
+ snprintf(argName, 32, "arg%04i", index);
+ arg->name = strdup(argName);
+
+ index += 1;
+ } else {
+ LOG_ERROR("Error allocating memory");
+ status = MEM_ERROR;
+ }
+ }
+
+ if (status == OK) {
+ TAILQ_INSERT_TAIL(&dynFunc->arguments, arg, entries);
+ } else {
+ if (arg != NULL) {
+ free(arg->name);
+ if (arg->type != NULL) {
+ dynType_destroy(arg->type);
+ }
+ free(arg);
+ }
+ }
+ nextChar = fgetc(descriptor);
+ }
+
+ if (status == 0) {
+ status = dynType_parse(descriptor, NULL, dynFunc->refTypes, &dynFunc->funcReturn);
+ }
+
+ return status;
+}
+
+enum dyn_function_argument_meta dynFunction_argumentMetaForIndex(dyn_function_type *dynFunc, int argumentNr) {
+ enum dyn_function_argument_meta result = 0;
+ dyn_function_argument_type *arg = NULL;
+ int index = 0;
+ TAILQ_FOREACH(arg, &dynFunc->arguments, entries) {
+ if (index == argumentNr) {
+ result = arg->argumentMeta;
+ break;
+ }
+ index += 1;
+ }
+ return result;
+}
+
+
+static int dynFunction_initCif(dyn_function_type *dynFunc) {
+ int status = 0;
+
+ int count = 0;
+ dyn_function_argument_type *entry = NULL;
+ TAILQ_FOREACH(entry, &dynFunc->arguments, entries) {
+ count +=1;
+ }
+
+ dynFunc->ffiArguments = calloc(count, sizeof(ffi_type));
+
+ TAILQ_FOREACH(entry, &dynFunc->arguments, entries) {
+ dynFunc->ffiArguments[entry->index] = dynType_ffiType(entry->type);
+ }
+
+ ffi_type **args = dynFunc->ffiArguments;
+ ffi_type *returnType = dynType_ffiType(dynFunc->funcReturn);
+
+ int ffiResult = ffi_prep_cif(&dynFunc->cif, FFI_DEFAULT_ABI, count, returnType, args);
+ if (ffiResult != FFI_OK) {
+ status = 1;
+ }
+
+ return status;
+}
+
+void dynFunction_destroy(dyn_function_type *dynFunc) {
+ if (dynFunc != NULL) {
+ if (dynFunc->funcReturn != NULL) {
+ dynType_destroy(dynFunc->funcReturn);
+ }
+ if (dynFunc->ffiClosure != NULL) {
+ ffi_closure_free(dynFunc->ffiClosure);
+ }
+ if (dynFunc->name != NULL) {
+ free(dynFunc->name);
+ }
+ if (dynFunc->ffiArguments != NULL) {
+ free(dynFunc->ffiArguments);
+ }
+
+ dyn_function_argument_type *entry = NULL;
+ dyn_function_argument_type *tmp = NULL;
+ entry = TAILQ_FIRST(&dynFunc->arguments);
+ while (entry != NULL) {
+ if (entry->name != NULL) {
+ free(entry->name);
+ }
+ dynType_destroy(entry->type);
+ tmp = entry;
+ entry = TAILQ_NEXT(entry, entries);
+ free(tmp);
+ }
+
+ free(dynFunc);
+ }
+}
+
+int dynFunction_call(dyn_function_type *dynFunc, void(*fn)(void), void *returnValue, void **argValues) {
+ ffi_call(&dynFunc->cif, fn, returnValue, argValues);
+ return 0;
+}
+
+static void dynFunction_ffiBind(ffi_cif *cif, void *ret, void *args[], void *userData) {
+ dyn_function_type *dynFunc = userData;
+ dynFunc->bind(dynFunc->userData, args, ret);
+}
+
+int dynFunction_createClosure(dyn_function_type *dynFunc, void (*bind)(void *, void **, void*), void *userData, void(**out)(void)) {
+ int status = 0;
+ void (*fn)(void);
+ dynFunc->ffiClosure = ffi_closure_alloc(sizeof(ffi_closure), (void **)&fn);
+ if (dynFunc->ffiClosure != NULL) {
+ int rc = ffi_prep_closure_loc(dynFunc->ffiClosure, &dynFunc->cif, dynFunction_ffiBind, dynFunc, fn);
+ if (rc != FFI_OK) {
+ status = 1;
+ }
+ } else {
+ status = 2;
+ }
+
+ if (status == 0) {
+ dynFunc->userData = userData;
+ dynFunc->bind = bind;
+ dynFunc->fn = fn;
+ *out =fn;
+ }
+
+ return status;
+}
+
+int dynFunction_getFnPointer(dyn_function_type *dynFunc, void (**fn)(void)) {
+ int status = 0;
+ if (dynFunc != NULL && dynFunc->fn != NULL) {
+ (*fn) = dynFunc->fn;
+ } else {
+ status = 1;
+ }
+ return status;
+}
+
+int dynFunction_nrOfArguments(dyn_function_type *dynFunc) {
+ int count = 0;
+ dyn_function_argument_type *entry = NULL;
+ TAILQ_FOREACH(entry, &dynFunc->arguments, entries) {
+ count += 1;
+ }
+ return count;
+}
+
+dyn_type *dynFunction_argumentTypeForIndex(dyn_function_type *dynFunc, int argumentNr) {
+ dyn_type *result = NULL;
+ int index = 0;
+ dyn_function_argument_type *entry = NULL;
+ TAILQ_FOREACH(entry, &dynFunc->arguments, entries) {
+ if (index == argumentNr) {
+ result = entry->type;
+ break;
+ }
+ index +=1;
+ }
+ return result;
+}
+
+dyn_type * dynFunction_returnType(dyn_function_type *dynFunction) {
+ return dynFunction->funcReturn;
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/src/dyn_interface.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/dyn_interface.c b/dfi/private/src/dyn_interface.c
new file mode 100644
index 0000000..d217d65
--- /dev/null
+++ b/dfi/private/src/dyn_interface.c
@@ -0,0 +1,431 @@
+/**
+ *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.
+ */
+#include "dyn_interface.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "dyn_common.h"
+#include "dyn_type.h"
+#include "dyn_interface.h"
+
+DFI_SETUP_LOG(dynInterface);
+
+struct _dyn_interface_type {
+ struct namvals_head header;
+ struct namvals_head annotations;
+ struct types_head types;
+ struct methods_head methods;
+};
+
+static const int OK = 0;
+static const int ERROR = 1;
+
+static int dynInterface_parseSection(dyn_interface_type *intf, FILE *stream);
+static int dynInterface_parseAnnotations(dyn_interface_type *intf, FILE *stream);
+static int dynInterface_parseTypes(dyn_interface_type *intf, FILE *stream);
+static int dynInterface_parseMethods(dyn_interface_type *intf, FILE *stream);
+static int dynInterface_parseHeader(dyn_interface_type *intf, FILE *stream);
+static int dynInterface_parseNameValueSection(dyn_interface_type *intf, FILE *stream, struct namvals_head *head);
+static int dynInterface_checkInterface(dyn_interface_type *intf);
+static int dynInterface_getEntryForHead(struct namvals_head *head, const char *name, char **value);
+
+int dynInterface_parse(FILE *descriptor, dyn_interface_type **out) {
+ int status = OK;
+
+ dyn_interface_type *intf = calloc(1, sizeof(*intf));
+ if (intf != NULL) {
+ TAILQ_INIT(&intf->header);
+ TAILQ_INIT(&intf->annotations);
+ TAILQ_INIT(&intf->types);
+ TAILQ_INIT(&intf->methods);
+
+ char peek = fgetc(descriptor);
+ while (peek == ':') {
+ ungetc(peek, descriptor);
+ status = dynInterface_parseSection(intf, descriptor);
+ if (status == OK) {
+ peek = fgetc(descriptor);
+ } else {
+ break;
+ }
+ }
+
+ if (status == OK) {
+ status = dynCommon_eatChar(descriptor, EOF);
+ }
+
+ if (status == OK) {
+ status = dynInterface_checkInterface(intf);
+ }
+ } else {
+ status = ERROR;
+ LOG_ERROR("Error allocating memory for dynamic interface\n");
+ }
+
+ if (status == OK) {
+ *out = intf;
+ } else if (intf != NULL) {
+ dynInterface_destroy(intf);
+ }
+ return status;
+}
+
+static int dynInterface_checkInterface(dyn_interface_type *intf) {
+ int status = OK;
+
+ //check header section
+ if (status == OK) {
+ bool foundType = false;
+ bool foundVersion = false;
+ bool foundName = false;
+ struct namval_entry *entry = NULL;
+ TAILQ_FOREACH(entry, &intf->header, entries) {
+ if (strcmp(entry->name, "type") == 0) {
+ foundType = true;
+ } else if (strcmp(entry->name, "version") == 0) {
+ foundVersion = true;
+ } else if (strcmp(entry->name, "name") == 0) {
+ foundName = true;
+ }
+ }
+
+ if (!foundType || !foundVersion || !foundName) {
+ status = ERROR;
+ LOG_ERROR("Parse Error. There must be a header section with a type, version and name entry");
+ }
+
+ struct method_entry *mEntry = NULL;
+ TAILQ_FOREACH(mEntry, &intf->methods, entries) {
+ dyn_type *type = dynFunction_returnType(mEntry->dynFunc);
+ int descriptor = dynType_descriptorType(type);
+ if (descriptor != 'N') {
+ status = ERROR;
+ LOG_ERROR("Parse Error. Only method with a return type 'N' (native int) are supported. Got return type '%c'\n", descriptor);
+ break;
+ }
+ }
+ }
+
+ return status;
+}
+
+static int dynInterface_parseSection(dyn_interface_type *intf, FILE *stream) {
+ int status = OK;
+ char *sectionName = NULL;
+
+ status = dynCommon_eatChar(stream, ':');
+
+ if (status == OK) {
+ status = dynCommon_parseName(stream, §ionName);
+ }
+
+ if (status == OK) {
+ status = dynCommon_eatChar(stream, '\n');
+ }
+
+ if (status == OK) {
+ if (strcmp("header", sectionName) == 0) {
+ status = dynInterface_parseHeader(intf, stream);
+ } else if (strcmp("annotations", sectionName) == 0) {
+ status = dynInterface_parseAnnotations(intf, stream);
+ } else if (strcmp("types", sectionName) == 0) {
+ status = dynInterface_parseTypes(intf, stream);
+ } else if (strcmp("methods", sectionName) == 0) {
+ status = dynInterface_parseMethods(intf, stream);
+ } else {
+ status = ERROR;
+ LOG_ERROR("unsupported section '%s'", sectionName);
+ }
+ }
+
+ if (sectionName != NULL) {
+ free(sectionName);
+ }
+
+ return status;
+}
+
+static int dynInterface_parseHeader(dyn_interface_type *intf, FILE *stream) {
+ return dynInterface_parseNameValueSection(intf, stream, &intf->header);
+}
+
+static int dynInterface_parseAnnotations(dyn_interface_type *intf, FILE *stream) {
+ return dynInterface_parseNameValueSection(intf, stream, &intf->annotations);
+}
+
+static int dynInterface_parseNameValueSection(dyn_interface_type *intf, FILE *stream, struct namvals_head *head) {
+ int status = OK;
+
+ int peek = fgetc(stream);
+ while (peek != ':' && peek != EOF) {
+ ungetc(peek, stream);
+
+ char *name;
+ char *value;
+ status = dynCommon_parseNameValue(stream, &name, &value);
+
+ if (status == OK) {
+ status = dynCommon_eatChar(stream, '\n');
+ }
+
+ struct namval_entry *entry = NULL;
+ if (status == OK) {
+ entry = calloc(1, sizeof(*entry));
+ if (entry != NULL) {
+ entry->name = name;
+ entry->value = value;
+ TAILQ_INSERT_TAIL(head, entry, entries);
+ } else {
+ status = ERROR;
+ LOG_ERROR("Error allocating memory for namval entry");
+ }
+ }
+
+ if (status != OK) {
+ if (name != NULL) {
+ free(name);
+ }
+ if (value != NULL) {
+ free(value);
+ }
+ if (entry != NULL) {
+ free(entry);
+ }
+ break;
+ }
+ peek = fgetc(stream);
+ }
+ ungetc(peek, stream);
+
+ return status;
+}
+
+static int dynInterface_parseTypes(dyn_interface_type *intf, FILE *stream) {
+ int status = OK;
+
+ //expected input (Name)=<Type>\n
+ int peek = fgetc(stream);
+ while (peek != ':' && peek != EOF) {
+ ungetc(peek, stream);
+
+ char *name;
+ status = dynCommon_parseName(stream, &name);
+
+ if (status == OK) {
+ status = dynCommon_eatChar(stream, '=');
+ }
+
+ dyn_type *type = NULL;
+ if (status == OK) {
+ dynType_parse(stream, name, &intf->types, &type);
+ }
+ if (name != NULL) {
+ free(name);
+ }
+
+ if (status == OK) {
+ status = dynCommon_eatChar(stream, '\n');
+ }
+
+ struct type_entry *entry = NULL;
+ if (status == OK) {
+ entry = calloc(1, sizeof(*entry));
+ if (entry != NULL) {
+ entry->type = type;
+ TAILQ_INSERT_TAIL(&intf->types, entry, entries);
+ } else {
+ status = ERROR;
+ LOG_ERROR("Error allocating memory for type entry");
+ }
+ }
+
+ if (status != OK) {
+ if (type != NULL) {
+ dynType_destroy(type);
+ }
+ if (entry != NULL) {
+ free(entry);
+ }
+ break;
+ }
+ peek = fgetc(stream);
+ }
+ ungetc(peek, stream);
+
+ return status;
+}
+
+static int dynInterface_parseMethods(dyn_interface_type *intf, FILE *stream) {
+ int status = OK;
+
+ //expected input (Name)=<Method>\n
+ int peek = fgetc(stream);
+ int index = 0;
+ while (peek != ':' && peek != EOF) {
+ ungetc(peek, stream);
+
+ char *id;
+ status = dynCommon_parseNameAlsoAccept(stream, "();[{}/", &id);
+
+ if (status == OK) {
+ status = dynCommon_eatChar(stream, '=');
+ }
+
+
+ dyn_function_type *func = NULL;
+ if (status == OK) {
+ status = dynFunction_parse(stream, &intf->types, &func);
+ }
+
+ if (status == OK) {
+ status = dynCommon_eatChar(stream, '\n');
+ }
+
+ struct method_entry *entry = NULL;
+ if (status == OK) {
+ entry = calloc(1, sizeof(*entry));
+ if (entry != NULL) {
+ entry->index = index++;
+ entry->id = id;
+ entry->dynFunc = func;
+ entry->name = strndup(id, 1024);
+ if (entry->name != NULL) {
+ int i;
+ for (i = 0; i < 1024; i += 1) {
+ if (entry->name[i] == '\0') {
+ break;
+ } else if (entry->name[i] == '(') {
+ entry->name[i] = '\0';
+ break;
+ }
+ }
+ }
+ TAILQ_INSERT_TAIL(&intf->methods, entry, entries);
+ } else {
+ status = ERROR;
+ LOG_ERROR("Error allocating memory for method entry");
+ }
+ }
+
+ if (status != OK) {
+ if (id != NULL) {
+ free(id);
+ }
+ if (func != NULL) {
+ dynFunction_destroy(func);
+ //TODO free strIdentier, name
+ }
+ if (entry != NULL) {
+ free(entry);
+ }
+ break;
+ }
+ peek = fgetc(stream);
+ }
+ ungetc(peek, stream);
+
+ return status;
+}
+
+void dynInterface_destroy(dyn_interface_type *intf) {
+ if (intf != NULL) {
+ dynCommon_clearNamValHead(&intf->header);
+ dynCommon_clearNamValHead(&intf->annotations);
+
+ struct method_entry *mTmp = NULL;
+ struct method_entry *mInfo = TAILQ_FIRST(&intf->methods);
+ while (mInfo != NULL) {
+ mTmp = mInfo;
+ mInfo = TAILQ_NEXT(mInfo, entries);
+
+ if (mTmp->id != NULL) {
+ free(mTmp->id);
+ }
+ if (mTmp->name != NULL) {
+ free(mTmp->name);
+ }
+ if (mTmp->dynFunc != NULL) {
+ dynFunction_destroy(mTmp->dynFunc);
+ }
+ free(mTmp);
+ }
+
+ struct type_entry *tmp = NULL;
+ struct type_entry *tInfo = TAILQ_FIRST(&intf->types);
+ while (tInfo != NULL) {
+ tmp = tInfo;
+ tInfo = TAILQ_NEXT(tInfo, entries);
+ dynType_destroy(tmp->type);
+ free(tmp);
+ }
+
+ free(intf);
+ }
+}
+
+int dynInterface_getName(dyn_interface_type *intf, char **out) {
+ return dynInterface_getEntryForHead(&intf->header, "name", out);
+}
+
+int dynInterface_getVersion(dyn_interface_type *intf, char **version) {
+ return dynInterface_getEntryForHead(&intf->header, "version", version);
+}
+
+int dynInterface_getHeaderEntry(dyn_interface_type *intf, const char *name, char **value) {
+ return dynInterface_getEntryForHead(&intf->header, name, value);
+}
+
+int dynInterface_getAnnotationEntry(dyn_interface_type *intf, const char *name, char **value) {
+ return dynInterface_getEntryForHead(&intf->annotations, name, value);
+}
+
+static int dynInterface_getEntryForHead(struct namvals_head *head, const char *name, char **out) {
+ int status = OK;
+ char *value = NULL;
+ struct namval_entry *entry = NULL;
+ TAILQ_FOREACH(entry, head, entries) {
+ if (strcmp(name, entry->name) == 0) {
+ value = entry->value;
+ break;
+ }
+ }
+ if (value != NULL) {
+ *out = value;
+ } else {
+ status = ERROR;
+ LOG_WARNING("Cannot find '%s' in list", name);
+ }
+ return status;
+}
+
+int dynInterface_methods(dyn_interface_type *intf, struct methods_head **list) {
+ int status = OK;
+ *list = &intf->methods;
+ return status;
+}
+
+int dynInterface_nrOfMethods(dyn_interface_type *intf) {
+ int count = 0;
+ struct method_entry *entry = NULL;
+ TAILQ_FOREACH(entry, &intf->methods, entries) {
+ count +=1;
+ }
+ return count;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/src/dyn_message.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/dyn_message.c b/dfi/private/src/dyn_message.c
new file mode 100644
index 0000000..c43412a
--- /dev/null
+++ b/dfi/private/src/dyn_message.c
@@ -0,0 +1,337 @@
+/**
+ *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.
+ */
+#include "dyn_message.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "dyn_common.h"
+#include "dyn_type.h"
+
+DFI_SETUP_LOG(dynMessage);
+
+struct _dyn_message_type {
+ struct namvals_head header;
+ struct namvals_head annotations;
+ struct types_head types;
+ dyn_type *msgType;
+};
+
+static const int OK = 0;
+static const int ERROR = 1;
+
+static int dynMessage_parseSection(dyn_message_type *msg, FILE *stream);
+static int dynMessage_parseAnnotations(dyn_message_type *msg, FILE *stream);
+static int dynMessage_parseTypes(dyn_message_type *msg, FILE *stream);
+static int dynMessage_parseMessage(dyn_message_type *msg, FILE *stream);
+static int dynMessage_parseHeader(dyn_message_type *msg, FILE *stream);
+static int dynMessage_parseNameValueSection(dyn_message_type *msg, FILE *stream, struct namvals_head *head);
+static int dynMessage_checkMessage(dyn_message_type *msg);
+static int dynMessage_getEntryForHead(struct namvals_head *head, const char *name, char **value);
+
+int dynMessage_parse(FILE *descriptor, dyn_message_type **out) {
+ int status = OK;
+
+ dyn_message_type *msg = calloc(1, sizeof(*msg));
+ if (msg != NULL) {
+ TAILQ_INIT(&msg->header);
+ TAILQ_INIT(&msg->annotations);
+ TAILQ_INIT(&msg->types);
+
+ char peek = fgetc(descriptor);
+ while (peek == ':') {
+ ungetc(peek, descriptor);
+ status = dynMessage_parseSection(msg, descriptor);
+ if (status == OK) {
+ peek = fgetc(descriptor);
+ } else {
+ break;
+ }
+ }
+
+ if (status == OK) {
+ status = dynCommon_eatChar(descriptor, EOF);
+ }
+
+ if (status == OK) {
+ status = dynMessage_checkMessage(msg);
+ }
+ } else {
+ status = ERROR;
+ LOG_ERROR("Error allocating memory for dynamic message\n");
+ }
+
+ if (status == OK) {
+ *out = msg;
+ } else if (msg != NULL) {
+ dynMessage_destroy(msg);
+ }
+ return status;
+}
+
+static int dynMessage_checkMessage(dyn_message_type *msg) {
+ int status = OK;
+
+ //check header section
+ if (status == OK) {
+ bool foundType = false;
+ bool foundVersion = false;
+ bool foundName = false;
+ struct namval_entry *entry = NULL;
+ TAILQ_FOREACH(entry, &msg->header, entries) {
+ if (strcmp(entry->name, "type") == 0) {
+ foundType = true;
+ } else if (strcmp(entry->name, "version") == 0) {
+ foundVersion = true;
+ } else if (strcmp(entry->name, "name") == 0) {
+ foundName = true;
+ }
+ }
+
+ if (!foundType || !foundVersion || !foundName) {
+ status = ERROR;
+ LOG_ERROR("Parse Error. There must be a header section with a type, version and name entry");
+ }
+ }
+
+ return status;
+}
+
+static int dynMessage_parseSection(dyn_message_type *msg, FILE *stream) {
+ int status = OK;
+ char *sectionName = NULL;
+
+ status = dynCommon_eatChar(stream, ':');
+
+ if (status == OK) {
+ status = dynCommon_parseName(stream, §ionName);
+ }
+
+ if (status == OK) {
+ status = dynCommon_eatChar(stream, '\n');
+ }
+
+ if (status == OK) {
+ if (strcmp("header", sectionName) == 0) {
+ status = dynMessage_parseHeader(msg, stream);
+ } else if (strcmp("annotations", sectionName) == 0) {
+ status = dynMessage_parseAnnotations(msg, stream);
+ } else if (strcmp("types", sectionName) == 0) {
+ status = dynMessage_parseTypes(msg, stream);
+ } else if (strcmp("message", sectionName) == 0) {
+ status = dynMessage_parseMessage(msg, stream);
+ } else {
+ status = ERROR;
+ LOG_ERROR("unsupported section '%s'", sectionName);
+ }
+ }
+
+ if (sectionName != NULL) {
+ free(sectionName);
+ }
+
+ return status;
+}
+
+static int dynMessage_parseHeader(dyn_message_type *msg, FILE *stream) {
+ return dynMessage_parseNameValueSection(msg, stream, &msg->header);
+}
+
+static int dynMessage_parseAnnotations(dyn_message_type *msg, FILE *stream) {
+ return dynMessage_parseNameValueSection(msg, stream, &msg->annotations);
+}
+
+static int dynMessage_parseNameValueSection(dyn_message_type *msg, FILE *stream, struct namvals_head *head) {
+ int status = OK;
+
+ int peek = fgetc(stream);
+ while (peek != ':' && peek != EOF) {
+ ungetc(peek, stream);
+
+ char *name;
+ char *value;
+ status = dynCommon_parseNameValue(stream, &name, &value);
+
+ if (status == OK) {
+ status = dynCommon_eatChar(stream, '\n');
+ }
+
+ struct namval_entry *entry = NULL;
+ if (status == OK) {
+ entry = calloc(1, sizeof(*entry));
+ if (entry != NULL) {
+ entry->name = name;
+ entry->value = value;
+ TAILQ_INSERT_TAIL(head, entry, entries);
+ } else {
+ status = ERROR;
+ LOG_ERROR("Error allocating memory for namval entry");
+ }
+ }
+
+ if (status != OK) {
+ if (name != NULL) {
+ free(name);
+ }
+ if (value != NULL) {
+ free(value);
+ }
+ if (entry != NULL) {
+ free(entry);
+ }
+ break;
+ }
+ peek = fgetc(stream);
+ }
+ ungetc(peek, stream);
+
+ return status;
+}
+
+static int dynMessage_parseTypes(dyn_message_type *msg, FILE *stream) {
+ int status = OK;
+
+ //expected input (Name)=<Type>\n
+ int peek = fgetc(stream);
+ while (peek != ':' && peek != EOF) {
+ ungetc(peek, stream);
+
+ char *name;
+ status = dynCommon_parseName(stream, &name);
+
+ if (status == OK) {
+ status = dynCommon_eatChar(stream, '=');
+ }
+
+ dyn_type *type = NULL;
+ if (status == OK) {
+ dynType_parse(stream, name, &msg->types, &type);
+ }
+ if (name != NULL) {
+ free(name);
+ }
+
+ if (status == OK) {
+ status = dynCommon_eatChar(stream, '\n');
+ }
+
+ struct type_entry *entry = NULL;
+ if (status == OK) {
+ entry = calloc(1, sizeof(*entry));
+ if (entry != NULL) {
+ entry->type = type;
+ TAILQ_INSERT_TAIL(&msg->types, entry, entries);
+ } else {
+ status = ERROR;
+ LOG_ERROR("Error allocating memory for type entry");
+ }
+ }
+
+ if (status != OK) {
+ if (type != NULL) {
+ dynType_destroy(type);
+ }
+ if (entry != NULL) {
+ free(entry);
+ }
+ break;
+ }
+ peek = fgetc(stream);
+ }
+ ungetc(peek, stream);
+
+ return status;
+}
+
+static int dynMessage_parseMessage(dyn_message_type *msg, FILE *stream) {
+ int status = OK;
+
+ //expected input <dynType>\n
+ char *name = NULL;
+ status = dynMessage_getName(msg, &name);
+
+ if (status == OK) {
+ status = dynType_parse(stream, name, &(msg->types), &(msg->msgType));
+ }
+
+ return status;
+}
+
+void dynMessage_destroy(dyn_message_type *msg) {
+ if (msg != NULL) {
+ dynCommon_clearNamValHead(&msg->header);
+ dynCommon_clearNamValHead(&msg->annotations);
+
+ struct type_entry *tmp = NULL;
+ struct type_entry *tInfo = TAILQ_FIRST(&msg->types);
+ while (tInfo != NULL) {
+ tmp = tInfo;
+ tInfo = TAILQ_NEXT(tInfo, entries);
+ dynType_destroy(tmp->type);
+ free(tmp);
+ }
+
+ if (msg->msgType != NULL) {
+ dynType_destroy(msg->msgType);
+ }
+
+ free(msg);
+ }
+}
+
+int dynMessage_getName(dyn_message_type *msg, char **out) {
+ return dynMessage_getEntryForHead(&msg->header, "name", out);
+}
+
+int dynMessage_getVersion(dyn_message_type *msg, char **version) {
+ return dynMessage_getEntryForHead(&msg->header, "version", version);
+}
+
+int dynMessage_getHeaderEntry(dyn_message_type *msg, const char *name, char **value) {
+ return dynMessage_getEntryForHead(&msg->header, name, value);
+}
+
+int dynMessage_getAnnotationEntry(dyn_message_type *msg, const char *name, char **value) {
+ return dynMessage_getEntryForHead(&msg->annotations, name, value);
+}
+
+static int dynMessage_getEntryForHead(struct namvals_head *head, const char *name, char **out) {
+ int status = OK;
+ char *value = NULL;
+ struct namval_entry *entry = NULL;
+ TAILQ_FOREACH(entry, head, entries) {
+ if (strcmp(name, entry->name) == 0) {
+ value = entry->value;
+ break;
+ }
+ }
+ if (value != NULL) {
+ *out = value;
+ } else {
+ status = ERROR;
+ LOG_WARNING("Cannot find '%s' in list", name);
+ }
+ return status;
+}
+
+int dynMessage_getMessageType(dyn_message_type *msg, dyn_type **type) {
+ int status = OK;
+ *type = msg->msgType;
+ return status;
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/18a5bf74/dfi/private/src/dyn_type.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/dyn_type.c b/dfi/private/src/dyn_type.c
new file mode 100644
index 0000000..c47c8c6
--- /dev/null
+++ b/dfi/private/src/dyn_type.c
@@ -0,0 +1,1144 @@
+/**
+ *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.
+ */
+#include "dyn_type.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+
+#include "dyn_common.h"
+
+DFI_SETUP_LOG(dynType)
+
+static int dynType_parseWithStream(FILE *stream, const char *name, dyn_type *parent, struct types_head *refTypes, dyn_type **result);
+static void dynType_clear(dyn_type *type);
+static void dynType_clearComplex(dyn_type *type);
+static void dynType_clearSequence(dyn_type *type);
+static void dynType_clearTypedPointer(dyn_type *type);
+
+static struct type_entry *dynType_allocTypeEntry(void);
+
+static ffi_type * dynType_ffiTypeFor(int c);
+static dyn_type * dynType_findType(dyn_type *type, char *name);
+static int dynType_parseAny(FILE *stream, dyn_type *type);
+static int dynType_parseComplex(FILE *stream, dyn_type *type);
+static int dynType_parseNestedType(FILE *stream, dyn_type *type);
+static int dynType_parseReference(FILE *stream, dyn_type *type);
+static int dynType_parseRefByValue(FILE *stream, dyn_type *type);
+static int dynType_parseSequence(FILE *stream, dyn_type *type);
+static int dynType_parseSimple(int c, dyn_type *type);
+static int dynType_parseTypedPointer(FILE *stream, dyn_type *type);
+static void dynType_prepCif(ffi_type *type);
+static unsigned short dynType_getOffset(dyn_type *type, int index);
+
+static void dynType_printAny(char *name, dyn_type *type, int depth, FILE *stream);
+static void dynType_printComplex(char *name, dyn_type *type, int depth, FILE *stream);
+static void dynType_printSequence(char *name, dyn_type *type, int depth, FILE *stream);
+static void dynType_printSimple(char *name, dyn_type *type, int depth, FILE *stream);
+static void dynType_printTypedPointer(char *name, dyn_type *type, int depth, FILE *stream);
+static void dynType_printDepth(int depth, FILE *stream);
+
+static void dynType_printTypes(dyn_type *type, FILE *stream);
+static void dynType_printComplexType(dyn_type *type, FILE *stream);
+static void dynType_printSimpleType(dyn_type *type, FILE *stream);
+
+static int dynType_parseText(FILE *stream, dyn_type *type);
+void dynType_freeComplexType(dyn_type *type, void *loc);
+void dynType_deepFree(dyn_type *type, void *loc, bool alsoDeleteSelf);
+void dynType_freeSequenceType(dyn_type *type, void *seqLoc);
+
+static int dynType_parseMetaInfo(FILE *stream, dyn_type *type);
+
+struct generic_sequence {
+ uint32_t cap;
+ uint32_t len;
+ void *buf;
+};
+
+TAILQ_HEAD(meta_properties_head, meta_entry);
+struct meta_entry {
+ char *name;
+ char *value;
+ TAILQ_ENTRY(meta_entry) entries;
+};
+
+
+struct _dyn_type {
+ char *name;
+ char descriptor;
+ int type;
+ ffi_type *ffiType;
+ dyn_type *parent;
+ struct types_head *referenceTypes; //NOTE: not owned
+ struct types_head nestedTypesHead;
+ struct meta_properties_head metaProperties;
+ union {
+ struct {
+ struct complex_type_entries_head entriesHead;
+ ffi_type structType; //dyn_type.ffiType points to this
+ dyn_type **types; //based on entriesHead for fast access
+ } complex;
+ struct {
+ ffi_type seqType; //dyn_type.ffiType points to this
+ dyn_type *itemType;
+ } sequence;
+ struct {
+ dyn_type *typedType;
+ } typedPointer;
+ struct {
+ dyn_type *ref;
+ } ref;
+ };
+};
+
+static const int OK = 0;
+static const int ERROR = 1;
+static const int MEM_ERROR = 2;
+static const int PARSE_ERROR = 3;
+
+int dynType_parse(FILE *descriptorStream, const char *name, struct types_head *refTypes, dyn_type **type) {
+ return dynType_parseWithStream(descriptorStream, name, NULL, refTypes, type);
+}
+
+int dynType_parseWithStr(const char *descriptor, const char *name, struct types_head *refTypes, dyn_type **type) {
+ int status = OK;
+ FILE *stream = fmemopen((char *)descriptor, strlen(descriptor), "r");
+ if (stream != NULL) {
+ status = dynType_parseWithStream(stream, name, NULL, refTypes, type);
+ if (status == OK) {
+ int c = fgetc(stream);
+ if (c != '\0' && c != EOF) {
+ status = PARSE_ERROR;
+ LOG_ERROR("Expected EOF got %c", c);
+ }
+ }
+ fclose(stream);
+ } else {
+ status = ERROR;
+ LOG_ERROR("Error creating mem stream for descriptor string. %s", strerror(errno));
+ }
+ return status;
+}
+
+static int dynType_parseWithStream(FILE *stream, const char *name, dyn_type *parent, struct types_head *refTypes, dyn_type **result) {
+ int status = OK;
+ dyn_type *type = calloc(1, sizeof(*type));
+ if (type != NULL) {
+ type->parent = parent;
+ type->type = DYN_TYPE_INVALID;
+ type->referenceTypes = refTypes;
+ TAILQ_INIT(&type->nestedTypesHead);
+ TAILQ_INIT(&type->metaProperties);
+ if (name != NULL) {
+ type->name = strdup(name);
+ if (type->name == NULL) {
+ status = MEM_ERROR;
+ LOG_ERROR("Error strdup'ing name '%s'\n", name);
+ }
+ }
+ if (status == OK) {
+ status = dynType_parseAny(stream, type);
+ }
+ if (status == OK) {
+ *result = type;
+ } else {
+ dynType_destroy(type);
+ }
+ } else {
+ status = MEM_ERROR;
+ LOG_ERROR("Error allocating memory for type");
+ }
+ return status;
+}
+
+static int dynType_parseAny(FILE *stream, dyn_type *type) {
+ int status = OK;
+
+ int c = fgetc(stream);
+ switch(c) {
+ case 'T' :
+ status = dynType_parseNestedType(stream, type);
+ if (status == OK) {
+ status = dynType_parseAny(stream, type);
+ }
+ break;
+ case 'L' :
+ status = dynType_parseReference(stream, type);
+ break;
+ case 'l' :
+ status = dynType_parseRefByValue(stream, type);
+ break;
+ case '{' :
+ status = dynType_parseComplex(stream, type);
+ break;
+ case '[' :
+ status = dynType_parseSequence(stream, type);
+ break;
+ case '*' :
+ status = dynType_parseTypedPointer(stream, type);
+ break;
+ case 't' :
+ status = dynType_parseText(stream, type);
+ break;
+ case '#' :
+ status = dynType_parseMetaInfo(stream, type);
+ if (status == OK) {
+ status = dynType_parseAny(stream, type);
+ }
+ break;
+ default :
+ status = dynType_parseSimple(c, type);
+ break;
+ }
+
+ return status;
+}
+
+static int dynType_parseMetaInfo(FILE *stream, dyn_type *type) {
+ int status = OK;
+ char *name = NULL;
+ char *value = NULL;
+
+ struct meta_entry *entry = calloc(1, sizeof(*entry));
+ if (entry == NULL) {
+ status = ERROR;
+ }
+
+ if (status == OK) {
+ status = dynCommon_parseName(stream, &name);
+ }
+
+ if (status == OK) {
+ status = dynCommon_eatChar(stream, '=');
+ }
+
+ if (status == OK) {
+ status = dynCommon_parseName(stream, &value);
+ }
+
+ if (status == OK) {
+ status = dynCommon_eatChar(stream, ';');
+ }
+
+ if (status == OK) {
+ entry->name = name;
+ entry->value = value;
+ TAILQ_INSERT_TAIL(&type->metaProperties, entry, entries);
+ LOG_DEBUG("Added meta properties '%s':'%s'", name, value)
+ } else {
+ free(name);
+ free(value);
+ free(entry);
+ }
+
+ return status;
+}
+
+static int dynType_parseText(FILE *stream, dyn_type *type) {
+ int status = OK;
+ type->type = DYN_TYPE_TEXT;
+ type->descriptor = 't';
+ type->ffiType = &ffi_type_pointer;
+ return status;
+}
+
+static int dynType_parseComplex(FILE *stream, dyn_type *type) {
+ int status = OK;
+ type->type = DYN_TYPE_COMPLEX;
+ type->descriptor = '{';
+ type->ffiType = &type->complex.structType;
+ TAILQ_INIT(&type->complex.entriesHead);
+
+ int c = fgetc(stream);
+ struct complex_type_entry *entry = NULL;
+ while (c != ' ' && c != '}') {
+ ungetc(c,stream);
+ entry = calloc(1, sizeof(*entry));
+ if (entry != NULL) {
+ entry->type = calloc(1, sizeof(*entry->type));
+ }
+ if (entry != NULL && entry->type != NULL) {
+ entry->type->parent = type;
+ entry->type->type = DYN_TYPE_INVALID;
+ TAILQ_INIT(&entry->type->nestedTypesHead);
+ TAILQ_INIT(&entry->type->metaProperties);
+ TAILQ_INSERT_TAIL(&type->complex.entriesHead, entry, entries);
+ status = dynType_parseAny(stream, entry->type);
+ } else {
+ if (entry != NULL) {
+ free(entry);
+ }
+ status = MEM_ERROR;
+ LOG_ERROR("Error allocating memory for type");
+ }
+ c = fgetc(stream);
+ }
+
+ entry = TAILQ_FIRST(&type->complex.entriesHead);
+ char *name = NULL;
+ while (c == ' ' && entry != NULL) {
+ status = dynCommon_parseName(stream, &name);
+ if (status == OK) {
+ entry->name = name;
+ entry = TAILQ_NEXT(entry, entries);
+ } else {
+ break;
+ }
+ c = getc(stream);
+ }
+
+ int count = 0;
+ TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
+ count +=1;
+ }
+
+ if (status == OK) {
+ type->complex.structType.type = FFI_TYPE_STRUCT;
+ type->complex.structType.elements = calloc(count + 1, sizeof(ffi_type));
+ if (type->complex.structType.elements != NULL) {
+ type->complex.structType.elements[count] = NULL;
+ int index = 0;
+ TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
+ type->complex.structType.elements[index++] = dynType_ffiType(entry->type);
+ }
+ } else {
+ status = MEM_ERROR;
+ //T\nODO log: error allocating memory
+ }
+ }
+
+ if (status == OK) {
+ type->complex.types = calloc(count, sizeof(dyn_type *));
+ if (type != NULL) {
+ int index = 0;
+ TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
+ type->complex.types[index++] = entry->type;
+ }
+ } else {
+ status = MEM_ERROR;
+ LOG_ERROR("Error allocating memory for type")
+ }
+ }
+
+ if (status == OK) {
+ dynType_prepCif(type->ffiType);
+ }
+
+
+ return status;
+}
+
+static int dynType_parseNestedType(FILE *stream, dyn_type *type) {
+ int status = OK;
+ char *name = NULL;
+ struct type_entry *entry = NULL;
+
+ entry = dynType_allocTypeEntry();
+ if (entry != NULL) {
+ entry->type->parent = type;
+ entry->type->type = DYN_TYPE_INVALID;
+ TAILQ_INIT(&entry->type->nestedTypesHead);
+ TAILQ_INIT(&entry->type->metaProperties);
+ TAILQ_INSERT_TAIL(&type->nestedTypesHead, entry, entries);
+ status = dynCommon_parseName(stream, &name);
+ entry->type->name = name;
+ } else {
+ status = MEM_ERROR;
+ LOG_ERROR("Error allocating entry");
+ }
+
+ if (status == OK) {
+ int c = fgetc(stream);
+ if (c != '=') {
+ status = PARSE_ERROR;
+ LOG_ERROR("Error parsing nested type expected '=' got '%c'", c);
+ }
+ }
+
+ if (status == OK) {
+ status = dynType_parseAny(stream, entry->type);
+ int c = fgetc(stream);
+ if (c != ';') {
+ status = PARSE_ERROR;
+ LOG_ERROR("Expected ';' got '%c'\n", c);
+ }
+ }
+
+ return status;
+}
+
+static int dynType_parseReference(FILE *stream, dyn_type *type) {
+ int status = OK;
+ type->type = DYN_TYPE_TYPED_POINTER;
+ type->descriptor = '*';
+
+ type->ffiType = &ffi_type_pointer;
+ type->typedPointer.typedType = NULL;
+
+ dyn_type *subType = calloc(1, sizeof(*subType));
+
+ if (subType != NULL) {
+ type->typedPointer.typedType = subType;
+ subType->parent = type;
+ subType->type = DYN_TYPE_INVALID;
+ TAILQ_INIT(&subType->nestedTypesHead);
+ TAILQ_INIT(&subType->metaProperties);
+ status = dynType_parseRefByValue(stream, subType);
+ } else {
+ status = MEM_ERROR;
+ LOG_ERROR("Error allocating memory for subtype\n");
+ }
+
+ return status;
+}
+
+static int dynType_parseRefByValue(FILE *stream, dyn_type *type) {
+ int status = OK;
+ type->type = DYN_TYPE_REF;
+ type->descriptor = 'l';
+
+ char *name = NULL;
+ status = dynCommon_parseName(stream, &name);
+ if (status == OK) {
+ dyn_type *ref = dynType_findType(type, name);
+ if (ref != NULL) {
+ type->ref.ref = ref;
+ } else {
+ status = PARSE_ERROR;
+ LOG_ERROR("Error cannot find type '%s'", name);
+ }
+ free(name);
+ }
+
+ if (status == OK) {
+ int c = fgetc(stream);
+ if (c != ';') {
+ status = PARSE_ERROR;
+ LOG_ERROR("Error expected ';' got '%c'", c);
+ }
+ }
+
+ return status;
+}
+
+static struct type_entry *dynType_allocTypeEntry(void) {
+ struct type_entry *entry = calloc(1, sizeof(*entry));
+ if (entry != NULL) {
+ entry->type = calloc(1, sizeof(*entry->type));
+ if (entry->type == NULL) {
+ free(entry);
+ entry = NULL;
+ }
+ }
+ return entry;
+}
+
+static ffi_type *seq_types[] = {&ffi_type_uint32, &ffi_type_uint32, &ffi_type_pointer, NULL};
+
+static int dynType_parseSequence(FILE *stream, dyn_type *type) {
+ int status = OK;
+ type->type = DYN_TYPE_SEQUENCE;
+ type->descriptor = '[';
+
+ type->sequence.seqType.elements = seq_types;
+ type->sequence.seqType.type = FFI_TYPE_STRUCT;
+ type->sequence.seqType.size = 0;
+ type->sequence.seqType.alignment = 0;
+
+ status = dynType_parseWithStream(stream, NULL, type, NULL, &type->sequence.itemType);
+
+ if (status == OK) {
+ type->ffiType = &type->sequence.seqType;
+ dynType_prepCif(&type->sequence.seqType);
+ }
+
+ return status;
+}
+
+static int dynType_parseSimple(int c, dyn_type *type) {
+ int status = OK;
+ ffi_type *ffiType = dynType_ffiTypeFor(c);
+ if (ffiType != NULL) {
+ type->type = DYN_TYPE_SIMPLE;
+ type->descriptor = c;
+ type->ffiType = ffiType;
+ } else {
+ status = PARSE_ERROR;
+ LOG_ERROR("Error unsupported type '%c'", c);
+ }
+
+ return status;
+}
+
+static int dynType_parseTypedPointer(FILE *stream, dyn_type *type) {
+ int status = OK;
+ type->type = DYN_TYPE_TYPED_POINTER;
+ type->descriptor = '*';
+ type->ffiType = &ffi_type_pointer;
+
+ status = dynType_parseWithStream(stream, NULL, type, NULL, &type->typedPointer.typedType);
+
+ return status;
+}
+
+static void dynType_prepCif(ffi_type *type) {
+ ffi_cif cif;
+ ffi_type *args[1];
+ args[0] = type;
+ ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_uint, args);
+}
+
+void dynType_destroy(dyn_type *type) {
+ if (type != NULL) {
+ dynType_clear(type);
+ free(type);
+ }
+}
+
+static void dynType_clear(dyn_type *type) {
+ struct type_entry *entry = TAILQ_FIRST(&type->nestedTypesHead);
+ struct type_entry *tmp = NULL;
+ while (entry != NULL) {
+ tmp = entry;
+ entry = TAILQ_NEXT(entry, entries);
+ if (tmp->type != NULL) {
+ dynType_destroy(tmp->type);
+ tmp->type = NULL;
+ }
+ free(tmp);
+ }
+
+ struct meta_entry *mEntry = TAILQ_FIRST(&type->metaProperties);;
+ struct meta_entry *next = NULL;
+ while (mEntry != NULL) {
+ next = TAILQ_NEXT(mEntry, entries);
+ if (mEntry != NULL) {
+ free(mEntry->name);
+ free(mEntry->value);
+ free(mEntry);
+ }
+ mEntry = next;
+ }
+
+ switch (type->type) {
+ case DYN_TYPE_COMPLEX :
+ dynType_clearComplex(type);
+ break;
+ case DYN_TYPE_SEQUENCE :
+ dynType_clearSequence(type);
+ break;
+ case DYN_TYPE_TYPED_POINTER :
+ dynType_clearTypedPointer(type);
+ break;
+ }
+
+ if (type->name != NULL) {
+ free(type->name);
+ }
+}
+
+static void dynType_clearComplex(dyn_type *type) {
+ assert(type->type == DYN_TYPE_COMPLEX);
+ struct complex_type_entry *entry = TAILQ_FIRST(&type->complex.entriesHead);
+ struct complex_type_entry *tmp = NULL;
+ while (entry != NULL) {
+ dynType_destroy(entry->type);
+ if (entry->name != NULL) {
+ free(entry->name);
+ }
+ tmp = entry;
+ entry = TAILQ_NEXT(entry, entries);
+ free(tmp);
+ }
+ if (type->complex.types != NULL) {
+ free(type->complex.types);
+ }
+ if (type->complex.structType.elements != NULL) {
+ free(type->complex.structType.elements);
+ }
+}
+
+static void dynType_clearSequence(dyn_type *type) {
+ assert(type->type == DYN_TYPE_SEQUENCE);
+ if (type->sequence.itemType != NULL) {
+ dynType_destroy(type->sequence.itemType);
+ }
+}
+
+static void dynType_clearTypedPointer(dyn_type *type) {
+ assert(type->type == DYN_TYPE_TYPED_POINTER);
+ if (type->typedPointer.typedType != NULL) {
+ dynType_destroy(type->typedPointer.typedType);
+ }
+}
+
+int dynType_alloc(dyn_type *type, void **bufLoc) {
+ assert(type->type != DYN_TYPE_REF);
+ assert(type->ffiType->size != 0);
+ int status = OK;
+
+ void *inst = calloc(1, type->ffiType->size);
+ if (inst != NULL) {
+ if (type->type == DYN_TYPE_TYPED_POINTER) {
+ void *ptr = NULL;
+ dyn_type *sub = NULL;
+ status = dynType_typedPointer_getTypedType(type, &sub);
+ if (status == OK) {
+ status = dynType_alloc(sub, &ptr);
+ if (status == OK) {
+ *(void **)inst = ptr;
+ }
+ }
+ }
+ *bufLoc = inst;
+ } else {
+ status = MEM_ERROR;
+ LOG_ERROR("Error allocating memory for type '%c'", type->descriptor);
+ }
+
+ return status;
+}
+
+
+int dynType_complex_indexForName(dyn_type *type, const char *name) {
+ assert(type->type == DYN_TYPE_COMPLEX);
+ int i = 0;
+ int index = -1;
+ struct complex_type_entry *entry = NULL;
+ TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
+ if (strcmp(name, entry->name) == 0) {
+ index = i;
+ }
+ i +=1;
+ }
+ return index;
+}
+
+int dynType_complex_dynTypeAt(dyn_type *type, int index, dyn_type **result) {
+ assert(type->type == DYN_TYPE_COMPLEX);
+ dyn_type *sub = type->complex.types[index];
+ if (sub->type == DYN_TYPE_REF) {
+ sub = sub->ref.ref;
+ }
+ *result = sub;
+ return 0;
+}
+
+int dynType_complex_setValueAt(dyn_type *type, int index, void *start, void *in) {
+ assert(type->type == DYN_TYPE_COMPLEX);
+ char *loc = ((char *)start) + dynType_getOffset(type, index);
+ size_t size = type->complex.structType.elements[index]->size;
+ memcpy(loc, in, size);
+ return 0;
+}
+
+int dynType_complex_valLocAt(dyn_type *type, int index, void *inst, void **result) {
+ assert(type->type == DYN_TYPE_COMPLEX);
+ char *l = (char *)inst;
+ void *loc = (void *)(l + dynType_getOffset(type, index));
+ *result = loc;
+ return 0;
+}
+
+int dynType_complex_entries(dyn_type *type, struct complex_type_entries_head **entries) {
+ assert(type->type == DYN_TYPE_COMPLEX);
+ int status = OK;
+ *entries = &type->complex.entriesHead;
+ return status;
+}
+
+//sequence
+int dynType_sequence_alloc(dyn_type *type, void *inst, uint32_t cap) {
+ assert(type->type == DYN_TYPE_SEQUENCE);
+ int status = OK;
+ struct generic_sequence *seq = inst;
+ if (seq != NULL) {
+ size_t size = dynType_size(type->sequence.itemType);
+ seq->buf = calloc(cap, size);
+ if (seq->buf != NULL) {
+ seq->cap = cap;
+ seq->len = 0;;
+ } else {
+ seq->cap = 0;
+ status = MEM_ERROR;
+ LOG_ERROR("Error allocating memory for buf")
+ }
+ } else {
+ status = MEM_ERROR;
+ LOG_ERROR("Error allocating memory for seq")
+ }
+ return status;
+}
+
+void dynType_free(dyn_type *type, void *loc) {
+ dynType_deepFree(type, loc, true);
+}
+
+void dynType_deepFree(dyn_type *type, void *loc, bool alsoDeleteSelf) {
+ if (loc != NULL) {
+ dyn_type *subType = NULL;
+ char *text = NULL;
+ switch (type->type) {
+ case DYN_TYPE_COMPLEX :
+ dynType_freeComplexType(type, loc);
+ break;
+ case DYN_TYPE_SEQUENCE :
+ dynType_freeSequenceType(type, loc);
+ break;
+ case DYN_TYPE_TYPED_POINTER:
+ dynType_typedPointer_getTypedType(type, &subType);
+ dynType_deepFree(subType, *(void **)loc, true);
+ break;
+ case DYN_TYPE_TEXT :
+ text = *(char **)loc;
+ free(text);
+ break;
+ }
+
+ if (alsoDeleteSelf) {
+ free(loc);
+ }
+ }
+}
+
+void dynType_freeSequenceType(dyn_type *type, void *seqLoc) {
+ struct generic_sequence *seq = seqLoc;
+ dyn_type *itemType = dynType_sequence_itemType(type);
+ void *itemLoc = NULL;
+ int i;
+ for (i = 0; i < seq->len; i += 1) {
+ dynType_sequence_locForIndex(type, seqLoc, i, &itemLoc);
+ dynType_deepFree(itemType, itemLoc, false);
+ }
+ free(seq->buf);
+}
+
+void dynType_freeComplexType(dyn_type *type, void *loc) {
+ struct complex_type_entry *entry = NULL;
+ int index = 0;
+ void *entryLoc = NULL;
+ TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
+ dynType_complex_valLocAt(type, index++, loc, &entryLoc);
+ dynType_deepFree(entry->type, entryLoc, false);
+ }
+}
+
+
+uint32_t dynType_sequence_length(void *seqLoc) {
+ struct generic_sequence *seq = seqLoc;
+ return seq->len;
+}
+
+int dynType_sequence_locForIndex(dyn_type *type, void *seqLoc, int index, void **out) {
+ assert(type->type == DYN_TYPE_SEQUENCE);
+ int status = OK;
+
+ struct generic_sequence *seq = seqLoc;
+ char *valLoc = seq->buf;
+
+ size_t itemSize = dynType_size(type->sequence.itemType);
+
+ if (index >= seq->cap) {
+ status = ERROR;
+ LOG_ERROR("Requested index (%i) is greater than capacity (%u) of sequence", index, seq->cap);
+ }
+
+ if (index >= seq->len) {
+ LOG_WARNING("Requesting index (%i) outsize defined length (%u) but within capacity", index, seq->len);
+ }
+
+ if (status == OK) { }
+ int i;
+ for (i = 0; i < seq->cap; i += 1) {
+ if (index == i) {
+ break;
+ } else {
+ valLoc += itemSize;
+ }
+ }
+
+ (*out) = valLoc;
+
+ return status;
+}
+
+int dynType_sequence_increaseLengthAndReturnLastLoc(dyn_type *type, void *seqLoc, void **valLoc) {
+ assert(type->type == DYN_TYPE_SEQUENCE);
+ int status = OK;
+ struct generic_sequence *seq = seqLoc;
+
+ int lastIndex = seq->len;
+ if (seq->len < seq->cap) {
+ seq->len += 1;
+ } else {
+ status = ERROR;
+ LOG_ERROR("Cannot increase sequence length beyond capacity (%u)", seq->cap);
+ }
+
+ if (status == OK) {
+ status = dynType_sequence_locForIndex(type, seqLoc, lastIndex, valLoc);
+ }
+
+ return status;
+}
+
+dyn_type * dynType_sequence_itemType(dyn_type *type) {
+ assert(type->type == DYN_TYPE_SEQUENCE);
+ dyn_type *itemType = type->sequence.itemType;
+ if (itemType->type == DYN_TYPE_REF) {
+ itemType = itemType->ref.ref;
+ }
+ return itemType;
+}
+
+void dynType_simple_setValue(dyn_type *type, void *inst, void *in) {
+ size_t size = dynType_size(type);
+ memcpy(inst, in, size);
+}
+
+
+int dynType_descriptorType(dyn_type *type) {
+ return type->descriptor;
+}
+
+const char * dynType_getMetaInfo(dyn_type *type, const char *name) {
+ const char *result = NULL;
+ struct meta_entry *entry = NULL;
+ TAILQ_FOREACH(entry, &type->metaProperties, entries) {
+ LOG_DEBUG("Checking '%s'", entry->name);
+ if (strcmp(entry->name, name) == 0) {
+ result = entry->value;
+ break;
+ }
+ }
+ return result;
+}
+
+ffi_type *dynType_ffiType(dyn_type *type) {
+ if (type->type == DYN_TYPE_REF) {
+ return type->ref.ref->ffiType;
+ }
+ return type->ffiType;
+}
+
+static ffi_type * dynType_ffiTypeFor(int c) {
+ ffi_type *type = NULL;
+ switch (c) {
+ case 'Z' :
+ type = &ffi_type_uint8;
+ break;
+ case 'F' :
+ type = &ffi_type_float;
+ break;
+ case 'D' :
+ type = &ffi_type_double;
+ break;
+ case 'B' :
+ type = &ffi_type_sint8;
+ break;
+ case 'b' :
+ type = &ffi_type_uint8;
+ break;
+ case 'S' :
+ type = &ffi_type_sint16;
+ break;
+ case 's' :
+ type = &ffi_type_uint16;
+ break;
+ case 'I' :
+ type = &ffi_type_sint32;
+ break;
+ case 'i' :
+ type = &ffi_type_uint32;
+ break;
+ case 'J' :
+ type = &ffi_type_sint64;
+ break;
+ case 'j' :
+ type = &ffi_type_sint64;
+ break;
+ case 'N' :
+ type = &ffi_type_sint;
+ break;
+ case 'P' :
+ type = &ffi_type_pointer;
+ break;
+ case 'V' :
+ type = &ffi_type_void;
+ break;
+ }
+ return type;
+}
+
+static dyn_type * dynType_findType(dyn_type *type, char *name) {
+ dyn_type *result = NULL;
+
+ struct type_entry *entry = NULL;
+ if (type->referenceTypes != NULL) {
+ TAILQ_FOREACH(entry, type->referenceTypes, entries) {
+ LOG_DEBUG("checking ref type '%s' with name '%s'", entry->type->name, name);
+ if (strcmp(name, entry->type->name) == 0) {
+ result = entry->type;
+ break;
+ }
+ }
+ }
+
+ if (result == NULL) {
+ struct type_entry *nEntry = NULL;
+ TAILQ_FOREACH(nEntry, &type->nestedTypesHead, entries) {
+ LOG_DEBUG("checking nested type '%s' with name '%s'", nEntry->type->name, name);
+ if (strcmp(name, nEntry->type->name) == 0) {
+ result = nEntry->type;
+ break;
+ }
+ }
+ }
+
+ if (result == NULL && type->parent != NULL) {
+ result = dynType_findType(type->parent, name);
+ }
+
+ return result;
+}
+
+static unsigned short dynType_getOffset(dyn_type *type, int index) {
+ assert(type->type == DYN_TYPE_COMPLEX);
+ unsigned short offset = 0;
+
+ ffi_type *ffiType = &type->complex.structType;
+ int i;
+ for (i = 0; i <= index && ffiType->elements[i] != NULL; i += 1) {
+ size_t size = ffiType->elements[i]->size;
+ unsigned short alignment = ffiType->elements[i]->alignment;
+ int alignment_diff = offset % alignment;
+ if (alignment_diff > 0) {
+ offset += (alignment - alignment_diff);
+ }
+ if (i < index) {
+ offset += size;
+ }
+ }
+
+ return offset;
+}
+
+size_t dynType_size(dyn_type *type) {
+ dyn_type *rType = type;
+ if (type->type == DYN_TYPE_REF) {
+ rType = type->ref.ref;
+ }
+ return rType->ffiType->size;
+}
+
+int dynType_type(dyn_type *type) {
+ return type->type;
+}
+
+
+int dynType_typedPointer_getTypedType(dyn_type *type, dyn_type **out) {
+ assert(type->type == DYN_TYPE_TYPED_POINTER);
+ int status = 0;
+
+ dyn_type *typedType = type->typedPointer.typedType;
+ if (typedType->type == DYN_TYPE_REF) {
+ typedType = typedType->ref.ref;
+ }
+
+ *out = typedType;
+ return status;
+}
+
+
+int dynType_text_allocAndInit(dyn_type *type, void *textLoc, const char *value) {
+ assert(type->type == DYN_TYPE_TEXT);
+ int status = 0;
+ const char *str = strdup(value);
+ char const **loc = textLoc;
+ if (str != NULL) {
+ *loc = str;
+ } else {
+ status = ERROR;
+ LOG_ERROR("Cannot allocate memory for string");
+ }
+ return status;
+}
+
+
+
+
+
+void dynType_print(dyn_type *type, FILE *stream) {
+ if (type != NULL) {
+ dynType_printTypes(type, stream);
+
+ fprintf(stream, "main type:\n");
+ dynType_printAny("root", type, 0, stream);
+ } else {
+ fprintf(stream, "invalid type\n");
+ }
+}
+
+static void dynType_printDepth(int depth, FILE *stream) {
+ int i;
+ for (i = 0; i < depth; i +=1 ) {
+ fprintf(stream, "\t");
+ }
+}
+
+static void dynType_printAny(char *name, dyn_type *type, int depth, FILE *stream) {
+ dyn_type *toPrint = type;
+ if (toPrint->type == DYN_TYPE_REF) {
+ toPrint = toPrint->ref.ref;
+ }
+ switch(toPrint->type) {
+ case DYN_TYPE_COMPLEX :
+ dynType_printComplex(name, toPrint, depth, stream);
+ break;
+ case DYN_TYPE_SIMPLE :
+ dynType_printSimple(name, toPrint, depth, stream);
+ break;
+ case DYN_TYPE_SEQUENCE :
+ dynType_printSequence(name, toPrint, depth, stream);
+ break;
+ case DYN_TYPE_TYPED_POINTER :
+ dynType_printTypedPointer(name, toPrint, depth, stream);
+ break;
+ default :
+ fprintf(stream, "TODO Unsupported type %i\n", toPrint->type);
+ break;
+ }
+}
+
+static void dynType_printComplex(char *name, dyn_type *type, int depth, FILE *stream) {
+ if (type->name == NULL) {
+ dynType_printDepth(depth, stream);
+ fprintf(stream, "%s: complex type (anon), size is %zu, alignment is %i, descriptor is '%c'. fields:\n", name, type->ffiType->size, type->ffiType->alignment, type->descriptor);
+
+ struct complex_type_entry *entry = NULL;
+ TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
+ dynType_printAny(entry->name, entry->type, depth + 1, stream);
+ }
+
+ dynType_printDepth(depth, stream);
+ fprintf(stream, "}\n");
+ } else {
+ dynType_printDepth(depth, stream);
+ fprintf(stream, "%s: complex type ('%s'), size is %zu, alignment is %i, descriptor is '%c'.\n", name, type->name, type->ffiType->size, type->ffiType->alignment, type->descriptor);
+ }
+}
+
+static void dynType_printSequence(char *name, dyn_type *type, int depth, FILE *stream) {
+ dynType_printDepth(depth, stream);
+ fprintf(stream, "sequence, size is %zu, alignment is %i, descriptor is '%c'. fields:\n", type->ffiType->size, type->ffiType->alignment, type->descriptor);
+
+ dynType_printDepth(depth + 1, stream);
+ fprintf(stream, "cap: simple type, size is %zu, alignment is %i.\n", type->sequence.seqType.elements[0]->size, type->sequence.seqType.elements[0]->alignment);
+
+ dynType_printDepth(depth + 1, stream);
+ fprintf(stream, "len: simple type, size is %zu, alignment is %i.\n", type->sequence.seqType.elements[1]->size, type->sequence.seqType.elements[1]->alignment);
+
+ dynType_printDepth(depth + 1, stream);
+ fprintf(stream, "buf: array, size is %zu, alignment is %i. points to ->\n", type->sequence.seqType.elements[2]->size, type->sequence.seqType.elements[2]->alignment);
+ dynType_printAny("element", type->sequence.itemType, depth + 1, stream);
+}
+
+static void dynType_printSimple(char *name, dyn_type *type, int depth, FILE *stream) {
+ dynType_printDepth(depth, stream);
+ fprintf(stream, "%s: simple type, size is %zu, alignment is %i, descriptor is '%c'.\n", name, type->ffiType->size, type->ffiType->alignment, type->descriptor);
+}
+
+static void dynType_printTypedPointer(char *name, dyn_type *type, int depth, FILE *stream) {
+ dynType_printDepth(depth, stream);
+ fprintf(stream, "%s: typed pointer, size is %zu, alignment is %i, points to ->\n", name, type->ffiType->size, type->ffiType->alignment);
+ char *subName = NULL;
+ if (name != NULL) {
+ char buf[128];
+ snprintf(buf, 128, "*%s", name);
+ subName = buf;
+ }
+ dynType_printAny(subName, type->typedPointer.typedType, depth + 1, stream);
+}
+
+static void dynType_printTypes(dyn_type *type, FILE *stream) {
+
+ dyn_type *parent = type->parent;
+ struct type_entry *pentry = NULL;
+ while (parent != NULL) {
+ TAILQ_FOREACH(pentry, &parent->nestedTypesHead, entries) {
+ if (pentry->type == type) {
+ return;
+ }
+ }
+ parent = parent->parent;
+ }
+
+ struct type_entry *entry = NULL;
+ TAILQ_FOREACH(entry, &type->nestedTypesHead, entries) {
+ dyn_type *toPrint = entry->type;
+ if (toPrint->type == DYN_TYPE_REF) {
+ toPrint = toPrint->ref.ref;
+ }
+
+ switch(toPrint->type) {
+ case DYN_TYPE_COMPLEX :
+ dynType_printComplexType(toPrint, stream);
+ break;
+ case DYN_TYPE_SIMPLE :
+ dynType_printSimpleType(toPrint, stream);
+ break;
+ default :
+ printf("TODO Print Type\n");
+ break;
+ }
+ }
+
+
+ struct complex_type_entry *centry = NULL;
+ switch(type->type) {
+ case DYN_TYPE_COMPLEX :
+ TAILQ_FOREACH(centry, &type->complex.entriesHead, entries) {
+ dynType_printTypes(centry->type, stream);
+ }
+ break;
+ case DYN_TYPE_SEQUENCE :
+ dynType_printTypes(type->sequence.itemType, stream);
+ break;
+ case DYN_TYPE_TYPED_POINTER :
+ dynType_printTypes(type->typedPointer.typedType, stream);
+ break;
+ }
+}
+
+static void dynType_printComplexType(dyn_type *type, FILE *stream) {
+ fprintf(stream, "type '%s': complex type, size is %zu, alignment is %i, descriptor is '%c'. fields:\n", type->name, type->ffiType->size, type->ffiType->alignment, type->descriptor);
+
+ struct complex_type_entry *entry = NULL;
+ TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
+ dynType_printAny(entry->name, entry->type, 2, stream);
+ }
+
+ fprintf(stream, "}\n");
+}
+
+static void dynType_printSimpleType(dyn_type *type, FILE *stream) {
+ fprintf(stream, "\ttype '%s': simple type, size is %zu, alignment is %i, descriptor is '%c'\n", type->name, type->ffiType->size, type->ffiType->alignment, type->descriptor);
+}
+