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/08/13 12:37:00 UTC
[3/5] celix git commit: CELIX-237: Refactoring of rsa_dfi layout (lib, lib-tst,
rsa bundle, rsa tst)
http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/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
new file mode 100644
index 0000000..b2b11d7
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_closure_tests.cpp
@@ -0,0 +1,146 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#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() {
+ dynFunction_logSetup(stdLog, NULL, 3);
+ dynType_logSetup(stdLog, NULL, 3);
+ //TODO dynType_logSetup(stdLog, NULL, 4);
+ dynCommon_logSetup(stdLog, NULL, 3);
+ g_count = 0;
+ }
+};
+
+TEST(DynClosureTests, DynCLosureTest1) {
+ //TODO split up
+ tests();
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/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
new file mode 100644
index 0000000..cb4e13b
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_function_tests.cpp
@@ -0,0 +1,231 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#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;
+ 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;
+ rc = dynFunction_call(dynFunc, fp, &rVal, args);
+ CHECK_EQUAL(0, rc);
+ CHECK_EQUAL(4.0, result);
+ free(inMemResult);
+
+ dynFunction_destroy(dynFunc);
+ }
+
+ void test_meta(void) {
+ int rc;
+ dyn_function_type *func = NULL;
+
+ const char *descriptor1 = "sqrt(D^*D~**D#P)V";
+ rc = dynFunction_parseWithStr(descriptor1, NULL, &func);
+ CHECK_EQUAL(0, rc);
+ CHECK_EQUAL(DYN_FUNCTION_ARG_META_INPUT_TYPE, dynFunction_argumentMetaInfoForIndex(func, 0));
+ CHECK_EQUAL(DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE, dynFunction_argumentMetaInfoForIndex(func, 1));
+ CHECK_EQUAL(DYN_FUNCTION_ARG_META_OUTPUT_TYPE, dynFunction_argumentMetaInfoForIndex(func, 2));
+ CHECK_EQUAL(DYN_FUNCTION_ARG_META_HANDLE_TYPE, dynFunction_argumentMetaInfoForIndex(func, 3));
+ CHECK_EQUAL(DYN_FUNCTION_ARG_META_UNKNOWN_TYPE, dynFunction_argumentMetaInfoForIndex(func, 4));
+ dynFunction_destroy(func);
+
+ const char *descriptor2 = "sqrt(D~*D)V";
+ rc = dynFunction_parseWithStr(descriptor2, NULL, &func);
+ CHECK(rc != 0);
+
+ const char *descriptor3 = "sqrt(D~***D)V";
+ rc = dynFunction_parseWithStr(descriptor3, NULL, &func);
+ CHECK_EQUAL(0, rc);
+ dynFunction_destroy(func);
+
+
+ const char *descriptor4 = "sqrt(D^D)V";
+ rc = dynFunction_parseWithStr(descriptor4, NULL, &func);
+ CHECK(rc != 0);
+
+ const char *descriptor5 = "sqrt(D^***D)V";
+ rc = dynFunction_parseWithStr(descriptor5, NULL, &func);
+ CHECK_EQUAL(0, rc);
+ dynFunction_destroy(func);
+ }
+}
+
+TEST_GROUP(DynFunctionTests) {
+ void setup() {
+ dynFunction_logSetup(stdLog, NULL, 3);
+ dynType_logSetup(stdLog, NULL, 3);
+ dynCommon_logSetup(stdLog, NULL, 3);
+ }
+};
+
+TEST(DynFunctionTests, DynFuncTest1) {
+ test_example1();
+}
+
+TEST(DynFunctionTests, DynFuncTest2) {
+ test_example2();
+}
+
+TEST(DynFunctionTests, DynFuncAccTest) {
+ test_access_functions();
+}
+
+TEST(DynFunctionTests, DynFuncTest3) {
+ test_example3();
+}
+
+TEST(DynFunctionTests, DynFuncTestMeta) {
+ test_meta();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/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
new file mode 100644
index 0000000..679260f
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_interface_tests.cpp
@@ -0,0 +1,87 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#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);
+ }
+
+}
+
+
+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();
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/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
new file mode 100644
index 0000000..96f64fa
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_type_tests.cpp
@@ -0,0 +1,190 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#include <CppUTest/TestHarness.h>
+#include "CppUTest/CommandLineTestRunner.h"
+
+extern "C" {
+ #include <string.h>
+ #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;
+ int i;
+ 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);
+
+ 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, 0);
+ }
+};
+
+#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 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)
+
+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);
+}
+
http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/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
new file mode 100644
index 0000000..5ee71ac
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_serializer_tests.cpp
@@ -0,0 +1,398 @@
+/**
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#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 4 ************************/
+/** 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 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);
+}
+
+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 = {.a=1, .b=2, .c=3, .d=4, .e=5, .f=6, .g=7, .h=8.8f, .i=9.9, .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 = { .a = 1, .b = 2 };
+ struct write_example2 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 = {.name = "John", .age = 33};
+ struct write_example3_person p2 = {.name = "Peter", .age = 44};
+ struct write_example3_person p3 = {.name = "Carol", .age = 55};
+ struct write_example3_person p4 = {.name = "Elton", .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/a129b488/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
new file mode 100644
index 0000000..f405c9f
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/run_tests.cpp
@@ -0,0 +1,9 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#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/a129b488/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
new file mode 100644
index 0000000..0490dcd
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/complex.avdl
@@ -0,0 +1,11 @@
+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/a129b488/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
new file mode 100644
index 0000000..0577397
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/complex.avpr
@@ -0,0 +1,36 @@
+{
+ "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/a129b488/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
new file mode 100644
index 0000000..c968c61
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/invalid1.avpr
@@ -0,0 +1,29 @@
+{
+ "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/a129b488/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
new file mode 100644
index 0000000..fc48ca9
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/invalid2.avpr
@@ -0,0 +1,31 @@
+{
+ "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/a129b488/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
new file mode 100644
index 0000000..cd5cafe
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/simple.avdl
@@ -0,0 +1,6 @@
+@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/a129b488/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
new file mode 100644
index 0000000..8a90bb2
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/simple.avpr
@@ -0,0 +1,33 @@
+{
+ "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/a129b488/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
new file mode 100644
index 0000000..c2bce19
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/schemas/simple_min.avpr
@@ -0,0 +1 @@
+{"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/a129b488/remote_services/remote_service_admin_dfi/private/include/export_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/private/include/export_registration_dfi.h b/remote_services/remote_service_admin_dfi/private/include/export_registration_dfi.h
deleted file mode 100644
index 4356646..0000000
--- a/remote_services/remote_service_admin_dfi/private/include/export_registration_dfi.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * Licensed under Apache License v2. See LICENSE for more information.
- */
-#ifndef CELIX_EXPORT_REGISTRATION_DFI_H
-#define CELIX_EXPORT_REGISTRATION_DFI_H
-
-
-#include "export_registration.h"
-#include "log_helper.h"
-#include "endpoint_description.h"
-
-celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, bundle_context_pt context, export_registration_pt *registration);
-void exportRegistration_destroy(export_registration_pt registration);
-
-celix_status_t exportRegistration_start(export_registration_pt registration);
-celix_status_t exportRegistration_stop(export_registration_pt registration);
-
-celix_status_t exportRegistration_call(export_registration_pt export, char *data, int datalength, char **response, int *responseLength);
-
-
-#endif //CELIX_EXPORT_REGISTRATION_DFI_H
http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/private/include/import_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/private/include/import_registration_dfi.h b/remote_services/remote_service_admin_dfi/private/include/import_registration_dfi.h
deleted file mode 100644
index ec885fd..0000000
--- a/remote_services/remote_service_admin_dfi/private/include/import_registration_dfi.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * Licensed under Apache License v2. See LICENSE for more information.
- */
-#ifndef CELIX_IMPORT_REGISTRATION_DFI_H
-#define CELIX_IMPORT_REGISTRATION_DFI_H
-
-#include "import_registration.h"
-
-#include <celix_errno.h>
-
-typedef void (*send_func_type)(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
-
-celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt description, const char *classObject, import_registration_pt *import);
-void importRegistration_destroy(import_registration_pt import);
-
-celix_status_t importRegistration_setSendFn(import_registration_pt reg,
- send_func_type,
- void *handle);
-celix_status_t importRegistration_start(import_registration_pt import);
-celix_status_t importRegistration_stop(import_registration_pt import);
-
-celix_status_t importRegistration_getService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **service);
-celix_status_t importRegistration_ungetService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **service);
-
-#endif //CELIX_IMPORT_REGISTRATION_DFI_H
http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/private/include/remote_service_admin_http_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/private/include/remote_service_admin_http_impl.h b/remote_services/remote_service_admin_dfi/private/include/remote_service_admin_http_impl.h
deleted file mode 100644
index 65ca83b..0000000
--- a/remote_services/remote_service_admin_dfi/private/include/remote_service_admin_http_impl.h
+++ /dev/null
@@ -1,73 +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.
- */
-/*
- * remote_service_admin_http_impl.h
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
-#define REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
-
-#include "remote_service_admin.h"
-#include "log_helper.h"
-#include "civetweb.h"
-
-struct remote_service_admin {
- bundle_context_pt context;
- log_helper_pt loghelper;
-
- celix_thread_mutex_t exportedServicesLock;
- hash_map_pt exportedServices;
-
- celix_thread_mutex_t importedServicesLock;
- hash_map_pt importedServices;
-
- char *port;
- char *ip;
-
- struct mg_context *ctx;
-};
-
-
-celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin);
-celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin);
-
-celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin);
-celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *methodSignature, char **reply, int* replyStatus);
-
-celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
-celix_status_t remoteServiceAdmin_removeExportedService(export_registration_pt registration);
-celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services);
-celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services);
-celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpoint, import_registration_pt *registration);
-celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration);
-
-
-celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint);
-celix_status_t exportReference_getExportedService(export_reference_pt reference);
-
-celix_status_t importReference_getImportedEndpoint(import_reference_pt reference);
-celix_status_t importReference_getImportedService(import_reference_pt reference);
-
-celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description);
-
-#endif /* REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/private/src/export_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/private/src/export_registration_dfi.c b/remote_services/remote_service_admin_dfi/private/src/export_registration_dfi.c
deleted file mode 100644
index cc181b3..0000000
--- a/remote_services/remote_service_admin_dfi/private/src/export_registration_dfi.c
+++ /dev/null
@@ -1,239 +0,0 @@
-/**
- * Licensed under Apache License v2. See LICENSE for more information.
- */
-#include <jansson.h>
-#include <dyn_interface.h>
-#include <json_serializer.h>
-#include <remote_constants.h>
-#include <assert.h>
-#include "export_registration.h"
-#include "export_registration_dfi.h"
-
-struct export_reference {
- endpoint_description_pt endpoint; //owner
- service_reference_pt reference;
-};
-
-struct export_registration {
- bundle_context_pt context;
- struct export_reference exportReference;
- void *service;
- dyn_interface_type *intf; //owner
-
- //TODO add tracker and lock
- bool closed;
-};
-
-typedef void (*gen_func_type)(void);
-
-struct generic_service_layout {
- void *handle;
- gen_func_type methods[];
-};
-
-celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, bundle_context_pt context, export_registration_pt *out) {
- celix_status_t status = CELIX_SUCCESS;
-
- export_registration_pt reg = calloc(1, sizeof(*reg));
-
- if (reg == NULL) {
- status = CELIX_ENOMEM;
- }
-
- if (status == CELIX_SUCCESS) {
- reg->context = context;
- reg->exportReference.endpoint = endpoint;
- reg->exportReference.reference = reference;
- reg->closed = false;
- }
-
- char *exports = NULL;
- CELIX_DO_IF(status, serviceReference_getProperty(reference, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exports));
-
- bundle_pt bundle = NULL;
- CELIX_DO_IF(status, serviceReference_getBundle(reference, &bundle));
-
-
- char *descriptorFile = NULL;
- if (status == CELIX_SUCCESS) {
- char name[128];
- snprintf(name, 128, "%s.descriptor", exports);
- status = bundle_getEntry(bundle, name, &descriptorFile);
- logHelper_log(helper, OSGI_LOGSERVICE_DEBUG, "RSA: Found descriptor '%s' for %'s'.", descriptorFile, exports);
- }
-
- if (descriptorFile == NULL) {
- logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "RSA: Cannot find descrriptor in bundle for service '%s'", exports);
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- FILE *df = fopen(descriptorFile, "r");
- if (df != NULL) {
- int rc = dynInterface_parse(df, ®->intf);
- fclose(df);
- if (rc != 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "RSA: Error parsing service descriptor.");
- }
- } else {
- status = CELIX_BUNDLE_EXCEPTION;
- logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Cannot open descriptor '%s'", descriptorFile);
- }
- }
-
- if (status == CELIX_SUCCESS) {
- *out = reg;
- } else {
- logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Error creating export registration");
- exportRegistration_destroy(reg);
- }
-
- return status;
-}
-
-celix_status_t exportRegistration_call(export_registration_pt export, char *data, int datalength, char **responseOut, int *responseLength) {
- int status = CELIX_SUCCESS;
- //TODO lock/sema export
-
- printf("Parsing data: %s\n", data);
- json_error_t error;
- json_t *js_request = json_loads(data, 0, &error);
- json_t *arguments = NULL;
- const char *sig;
- if (js_request) {
- if (json_unpack(js_request, "{s:s}", "m", &sig) != 0) {
- printf("RSA: Got error '%s'\n", error.text);
- } else {
- arguments = json_object_get(js_request, "a");
- }
- } else {
- printf("RSA: got error '%s' for '%s'\n", error.text, data);
- return 0;
- }
-
- printf("RSA: Looking for method %s\n", sig);
- struct methods_head *methods = NULL;
- dynInterface_methods(export->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 = CELIX_ILLEGAL_STATE;
- } else {
- printf("RSA: found method '%s'\n", entry->id);
- }
-
- if (method != NULL) {
-
- struct generic_service_layout *serv = export->service;
- void *handle = serv->handle;
- void (*fp)(void) = serv->methods[method->index];
-
- json_t *result = NULL;
- status = jsonSerializer_call(method->dynFunc, handle, fp, arguments, &result);
-
- json_decref(js_request);
-
- if (status == CELIX_SUCCESS) {
- printf("creating payload\n");
- json_t *payload = json_object();
- json_object_set_new(payload, "r", result);
-
- char *response = json_dumps(payload, JSON_DECODE_ANY);
- printf("status ptr is %p. response if '%s'\n", status, response);
-
- *responseOut = response;
- *responseLength = -1;
-
- json_decref(payload);
- }
-
- ///TODO add more status checks
- }
-
- //TODO unlock/sema export
- printf("done export reg call\n");
- return status;
-}
-
-void exportRegistration_destroy(export_registration_pt reg) {
- if (reg != NULL) {
- if (reg->intf != NULL) {
- dyn_interface_type *intf = reg->intf;
- reg->intf = NULL;
- dynInterface_destroy(intf);
- }
-
- if (reg->exportReference.endpoint != NULL) {
- endpoint_description_pt ep = reg->exportReference.endpoint;
- reg->exportReference.endpoint = NULL;
- endpointDescription_destroy(ep);
- }
-
- free(reg);
- }
-}
-
-celix_status_t exportRegistration_start(export_registration_pt reg) {
- celix_status_t status = CELIX_SUCCESS;
- status = bundleContext_getService(reg->context, reg->exportReference.reference, ®->service); //TODO use tracker
- return status;
-}
-
-celix_status_t exportRegistration_stop(export_registration_pt reg) {
- celix_status_t status = CELIX_SUCCESS;
- status = bundleContext_ungetService(reg->context, reg->exportReference.reference, NULL);
- return status;
-}
-
-celix_status_t exportRegistration_close(export_registration_pt reg) {
- celix_status_t status = CELIX_SUCCESS;
- exportRegistration_stop(reg);
- //TODO callback to rsa to remove from list
- return status;
-}
-
-celix_status_t exportRegistration_getException(export_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- //TODO
- return status;
-}
-
-celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *out) {
- celix_status_t status = CELIX_SUCCESS;
- export_reference_pt ref = calloc(1, sizeof(*ref));
- if (ref != NULL) {
- ref->endpoint = registration->exportReference.endpoint;
- ref->reference = registration->exportReference.reference;
- } else {
- status = CELIX_ENOMEM;
- //TODO log
- }
-
- if (status == CELIX_SUCCESS) {
- *out = ref;
- }
-
- return status;
-}
-
-celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint) {
- celix_status_t status = CELIX_SUCCESS;
- *endpoint = reference->endpoint;
- return status;
-}
-
-celix_status_t exportReference_getExportedService(export_reference_pt reference) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-
-
http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/private/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/private/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/private/src/import_registration_dfi.c
deleted file mode 100644
index 20ff61d..0000000
--- a/remote_services/remote_service_admin_dfi/private/src/import_registration_dfi.c
+++ /dev/null
@@ -1,318 +0,0 @@
-#include <stdlib.h>
-#include <jansson.h>
-#include "json_serializer.h"
-#include "dyn_interface.h"
-#include "import_registration.h"
-#include "import_registration_dfi.h"
-
-struct import_registration {
- bundle_context_pt context;
- endpoint_description_pt endpoint; //TODO owner? -> free when destroyed
- const char *classObject; //NOTE owned by endpoint
- send_func_type send;
- void *sendHandle;
-
- service_factory_pt factory;
- service_registration_pt factoryReg;
-
- hash_map_pt proxies; //key -> bundle, value -> service_proxy
-};
-
-struct service_proxy {
- dyn_interface_type *intf;
- void *service;
- int count;
-};
-
-static celix_status_t importRegistration_createProxy(import_registration_pt import, bundle_pt bundle,
- struct service_proxy **proxy);
-static void importRegistration_proxyFunc(void *userData, void *args[], void *returnVal);
-static void importRegistration_destroyProxy(struct service_proxy *proxy);
-
-celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt endpoint, const char *classObject, import_registration_pt *out) {
- celix_status_t status = CELIX_SUCCESS;
- import_registration_pt reg = calloc(1, sizeof(*reg));
-
- if (reg != NULL) {
- reg->factory = calloc(1, sizeof(*reg->factory));
- }
-
- if (reg != NULL && reg->factory != NULL) {
- reg->context = context;
- reg->endpoint = endpoint;
- reg->classObject = classObject;
- reg->proxies = hashMap_create(NULL, NULL, NULL, NULL);
-
- reg->factory->factory = reg;
- reg->factory->getService = (void *)importRegistration_getService;
- reg->factory->ungetService = (void *)importRegistration_ungetService;
- } else {
- status = CELIX_ENOMEM;
- }
-
- if (status == CELIX_SUCCESS) {
- printf("IMPORT REGISTRATION IS %p\n", reg);
- *out = reg;
- }
-
- return status;
-}
-
-
-celix_status_t importRegistration_setSendFn(import_registration_pt reg,
- send_func_type send,
- void *handle) {
- reg->send = send;
- reg->sendHandle = handle;
-
- return CELIX_SUCCESS;
-}
-
-void importRegistration_destroy(import_registration_pt import) {
- if (import != NULL) {
- if (import->proxies != NULL) {
- //TODO destroy proxies
- hashMap_destroy(import->proxies, false, false);
- import->proxies = NULL;
- }
- if (import->factory != NULL) {
- free(import->factory);
- }
- free(import);
- }
-}
-
-celix_status_t importRegistration_start(import_registration_pt import) {
- celix_status_t status = CELIX_SUCCESS;
- if (import->factoryReg == NULL && import->factory != NULL) {
- status = bundleContext_registerServiceFactory(import->context, (char *)import->classObject, import->factory, NULL /*TODO*/, &import->factoryReg);
- } else {
- status = CELIX_ILLEGAL_STATE;
- }
- return status;
-}
-
-celix_status_t importRegistration_stop(import_registration_pt import) {
- celix_status_t status = CELIX_SUCCESS;
- if (import->factoryReg != NULL) {
- serviceRegistration_unregister(import->factoryReg);
- }
- //TODO unregister every serv instance?
- return status;
-}
-
-
-celix_status_t importRegistration_getService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **out) {
- celix_status_t status = CELIX_SUCCESS;
-
- /*
- module_pt module = NULL;
- char *name = NULL;
- bundle_getCurrentModule(bundle, &module);
- module_getSymbolicName(module, &name);
- printf("getting service for bundle '%s'\n", name);
- */
-
- struct service_proxy *proxy = hashMap_get(import->proxies, bundle); //TODO lock
- if (proxy == NULL) {
- status = importRegistration_createProxy(import, bundle, &proxy);
- if (status == CELIX_SUCCESS) {
- hashMap_put(import->proxies, bundle, proxy); //TODO lock
- }
- }
-
- if (status == CELIX_SUCCESS) {
- proxy->count += 1;
- *out = proxy->service;
- }
-
- return status;
-}
-
-static celix_status_t importRegistration_createProxy(import_registration_pt import, bundle_pt bundle, struct service_proxy **out) {
- celix_status_t status = CELIX_SUCCESS;
-
- char *descriptorFile = NULL;
- char name[128];
- snprintf(name, 128, "%s.descriptor", import->classObject);
- status = bundle_getEntry(bundle, name, &descriptorFile);
- if (descriptorFile == NULL) {
- printf("Cannot find entry '%s'\n", name);
- status = CELIX_ILLEGAL_ARGUMENT;
- } else {
- printf("Found descriptor at '%s'\n", descriptorFile);
- }
-
- struct service_proxy *proxy = NULL;
- if (status == CELIX_SUCCESS) {
- proxy = calloc(1, sizeof(*proxy));
- if (proxy == NULL) {
- status = CELIX_ENOMEM;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- FILE *df = fopen(descriptorFile, "r");
- if (df != NULL) {
- int rc = dynInterface_parse(df, &proxy->intf);
- fclose(df);
- if (rc != 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
- }
-
-
- if (status == CELIX_SUCCESS) {
- size_t count = dynInterface_nrOfMethods(proxy->intf);
- proxy->service = calloc(1 + count, sizeof(void *));
- if (proxy->service == NULL) {
- status = CELIX_ENOMEM;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- void **serv = proxy->service;
- serv[0] = import;
-
- struct methods_head *list = NULL;
- dynInterface_methods(proxy->intf, &list);
- struct method_entry *entry = NULL;
- void (*fn)(void) = NULL;
- int index = 0;
- TAILQ_FOREACH(entry, list, entries) {
- int rc = dynFunction_createClosure(entry->dynFunc, importRegistration_proxyFunc, entry, &fn);
- serv[index + 1] = fn;
- index += 1;
-
- if (rc != 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- break;
- }
- }
- }
-
- if (status == CELIX_SUCCESS) {
- *out = proxy;
- } else {
- if (proxy->intf != NULL) {
- dynInterface_destroy(proxy->intf);
- proxy->intf = NULL;
- }
- if (proxy->service != NULL) {
- free(proxy->service);
- proxy->service = NULL;
- }
- if (proxy != NULL) {
- free(proxy);
- }
- }
-
- return status;
-}
-
-static void importRegistration_proxyFunc(void *userData, void *args[], void *returnVal) {
- int status = CELIX_SUCCESS;
- struct method_entry *entry = userData;
- import_registration_pt import = *((void **)args[0]);
-
- printf("Calling remote function '%s'\n", entry->id);
- json_t *invoke = json_object();
- json_object_set(invoke, "m", json_string(entry->id));
-
- json_t *arguments = NULL;
-
- status = jsonSerializer_prepareArguments(entry->dynFunc, args, &arguments);
- if (status == CELIX_SUCCESS) {
- json_object_set_new(invoke, "a", arguments);
- }
-
- char *output = json_dumps(invoke, JSON_DECODE_ANY);
- json_decref(invoke);
-
- printf("Need to send following json '%s'\n", output);
-
- if (import != NULL && import->send != NULL) {
- char *reply = NULL;
- int rc = 0;
- printf("sending request\n");
- import->send(import->sendHandle, import->endpoint, output, &reply, &rc);
- printf("request sended. got reply '%s'\n", reply);
-
- json_t *replyJson = json_loads(reply, JSON_DECODE_ANY, NULL); //TODO check
- json_t *result = json_object_get(replyJson, "r"); //TODO check
- status = jsonSerializer_handleReply(entry->dynFunc, NULL, result, args);
- json_decref(result);
-
-
-
-
- if (status == 0) {
- printf("done with proxy func\n");
- }
- } else {
- printf("Error import of import->send is NULL\n");
- }
-
- //TODO assert double check if return type is native int
- int *rVal = returnVal;
- *rVal = status;
-}
-
-celix_status_t importRegistration_ungetService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **out) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-
- /* TODO fix. gives segfault in framework shutdown (import->proxies == NULL)
- assert(import != NULL);
- assert(import->proxies != NULL);
-
- struct service_proxy *proxy = hashMap_get(import->proxies, bundle); //TODO lock
- if (proxy != NULL) {
- if (*out == proxy->service) {
- proxy->count -= 1;
- } else {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (proxy->count == 0) {
- importRegistration_destroyProxy(proxy);
- }
- }
- */
-
- return status;
-}
-
-static void importRegistration_destroyProxy(struct service_proxy *proxy) {
- //TODO
-}
-
-
-celix_status_t importRegistration_close(import_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- //TODO
- return status;
-}
-
-celix_status_t importRegistration_getException(import_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- //TODO
- return status;
-}
-
-celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference) {
- celix_status_t status = CELIX_SUCCESS;
- //TODO
- return status;
-}
-
-celix_status_t importReference_getImportedEndpoint(import_reference_pt reference) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-celix_status_t importReference_getImportedService(import_reference_pt reference) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_activator.c b/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_activator.c
deleted file mode 100644
index 9961a9b..0000000
--- a/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_activator.c
+++ /dev/null
@@ -1,122 +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.
- */
-/*
- * remote_service_admin_activator.c
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-
-#include "bundle_activator.h"
-#include "service_registration.h"
-
-#include "remote_service_admin_http_impl.h"
-#include "export_registration_dfi.h"
-#include "import_registration_dfi.h"
-
-struct activator {
- remote_service_admin_pt admin;
- remote_service_admin_service_pt adminService;
- service_registration_pt registration;
-};
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator;
-
- activator = calloc(1, sizeof(*activator));
- if (!activator) {
- status = CELIX_ENOMEM;
- } else {
- activator->admin = NULL;
- activator->registration = NULL;
-
- *userData = activator;
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
- remote_service_admin_service_pt remoteServiceAdmin = NULL;
-
- status = remoteServiceAdmin_create(context, &activator->admin);
- if (status == CELIX_SUCCESS) {
- remoteServiceAdmin = calloc(1, sizeof(*remoteServiceAdmin));
- if (!remoteServiceAdmin) {
- status = CELIX_ENOMEM;
- } else {
- remoteServiceAdmin->admin = activator->admin;
- remoteServiceAdmin->exportService = remoteServiceAdmin_exportService;
-
- remoteServiceAdmin->getExportedServices = remoteServiceAdmin_getExportedServices;
- remoteServiceAdmin->getImportedEndpoints = remoteServiceAdmin_getImportedEndpoints;
- remoteServiceAdmin->importService = remoteServiceAdmin_importService;
-
- remoteServiceAdmin->exportReference_getExportedEndpoint = exportReference_getExportedEndpoint;
- remoteServiceAdmin->exportReference_getExportedService = exportReference_getExportedService;
-
- remoteServiceAdmin->exportRegistration_close = exportRegistration_close;
- remoteServiceAdmin->exportRegistration_getException = exportRegistration_getException;
- remoteServiceAdmin->exportRegistration_getExportReference = exportRegistration_getExportReference;
-
- remoteServiceAdmin->importReference_getImportedEndpoint = importReference_getImportedEndpoint;
- remoteServiceAdmin->importReference_getImportedService = importReference_getImportedService;
-
- remoteServiceAdmin->importRegistration_close = remoteServiceAdmin_removeImportedService;
- remoteServiceAdmin->importRegistration_getException = importRegistration_getException;
- remoteServiceAdmin->importRegistration_getImportReference = importRegistration_getImportReference;
-
- status = bundleContext_registerService(context, OSGI_RSA_REMOTE_SERVICE_ADMIN, remoteServiceAdmin, NULL, &activator->registration);
- activator->adminService = remoteServiceAdmin;
- }
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- remoteServiceAdmin_stop(activator->admin);
- serviceRegistration_unregister(activator->registration);
- activator->registration = NULL;
-
- remoteServiceAdmin_destroy(&activator->admin);
-
- free(activator->adminService);
-
- return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- free(activator);
-
- return status;
-}
-
-