Repository: celix
Updated Branches:
refs/heads/feature/CELIX-237_rsa-ffi 8b1b23cc1 -> 08b5bc0ca
CELIX-237: some refactoring in function names
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/5c52b219
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/5c52b219
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/5c52b219
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: 5c52b2192130075ed31030c6057dbd8882088003
Parents: 8b1b23c
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Sat Jul 11 21:29:13 2015 +0200
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Sat Jul 11 21:29:13 2015 +0200
----------------------------------------------------------------------
.../dynamic_function_interface/dyn_function.c | 18 ++++++++++---
.../dynamic_function_interface/dyn_function.h | 6 +++--
.../dynamic_function_interface/dyn_type.c | 27 +++++++++++++++-----
.../dynamic_function_interface/dyn_type.h | 23 ++++++++++-------
.../tst/dyn_closure_tests.cpp | 6 ++---
.../tst/dyn_function_tests.cpp | 4 +--
.../tst/dyn_type_tests.cpp | 10 ++++----
.../tst/json_serializer_tests.cpp | 12 ++++-----
8 files changed, 68 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/5c52b219/remote_services/dynamic_function_interface/dyn_function.c
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_function.c b/remote_services/dynamic_function_interface/dyn_function.c
index 96804e7..8814d3c 100644
--- a/remote_services/dynamic_function_interface/dyn_function.c
+++ b/remote_services/dynamic_function_interface/dyn_function.c
@@ -38,7 +38,12 @@ static int dynFunction_initCif(ffi_cif *cif, dyn_type *arguments, dyn_type
*fun
static int dynFunction_parseDescriptor(const char *functionDescriptor, dyn_type_list_type
*typeReferences, dyn_type **arguments, dyn_type **funcReturn);
static void dynClosure_ffiBind(ffi_cif *cif, void *ret, void *args[], void *userData);
-int dynFunction_create(const char *descriptor, dyn_type_list_type *typeReferences, void (*fn)(void),
dyn_function_type **out) {
+int dynFunction_create(FILE *descriptorStream, dyn_type_list_type *typeReferences, void (*fn)(void),
dyn_function_type **dynFunc) {
+ //TODO
+ return 0;
+}
+
+int dynFunction_createWithStr(const char *descriptor, dyn_type_list_type *typeReferences,
void (*fn)(void), dyn_function_type **out) {
int status = 0;
dyn_function_type *dynFunc = NULL;
LOG_DEBUG("Creating dyn function for descriptor '%s'\n", descriptor);
@@ -89,9 +94,9 @@ static int dynFunction_parseDescriptor(const char *descriptor, dyn_type_list_typ
returnDesc[len] = '\0';
LOG_DEBUG("returnDesc is '%s'\n", returnDesc);
- status = dynType_create(argDesc, typeReferences, arguments);
+ status = dynType_createWithStr(argDesc, NULL, typeReferences, arguments);
if (status == 0) {
- status = dynType_create(returnDesc, typeReferences, funcReturn);
+ status = dynType_createWithStr(returnDesc, NULL, typeReferences, funcReturn);
}
} else {
status = 1;
@@ -142,7 +147,12 @@ static void dynClosure_ffiBind(ffi_cif *cif, void *ret, void *args[],
void *user
dynClosure->bind(dynClosure->userData, args, ret);
}
-int dynClosure_create(const char *descriptor, dyn_type_list_type *typeReferences, void (*bind)(void
*, void **, void*), void *userData, dyn_closure_type **out) {
+int dynClosure_create(FILE *descriptorStream, dyn_type_list_type *typeReferences, void (*bind)(void
*, void **, void*), void *userData, dyn_closure_type **out) {
+ //TODO
+ return 0;
+}
+
+int dynClosure_createWithStr(const char *descriptor, dyn_type_list_type *typeReferences,
void (*bind)(void *, void **, void*), void *userData, dyn_closure_type **out) {
int status = 0;
dyn_closure_type *dynClosure = calloc(1, sizeof(*dynClosure));
if (dynClosure != NULL) {
http://git-wip-us.apache.org/repos/asf/celix/blob/5c52b219/remote_services/dynamic_function_interface/dyn_function.h
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_function.h b/remote_services/dynamic_function_interface/dyn_function.h
index 4d3536e..11994fe 100644
--- a/remote_services/dynamic_function_interface/dyn_function.h
+++ b/remote_services/dynamic_function_interface/dyn_function.h
@@ -19,11 +19,13 @@ typedef struct _dyn_closure_type dyn_closure_type;
DFI_SETUP_LOG_HEADER(dynFunction);
-int dynFunction_create(const char *descriptor, dyn_type_list_type *typeReferences, void (*fn)(void),
dyn_function_type **dynFunc);
+int dynFunction_create(FILE *descriptorStream, dyn_type_list_type *typeReferences, void (*fn)(void),
dyn_function_type **dynFunc);
+int dynFunction_createWithStr(const char *descriptor, dyn_type_list_type *typeReferences,
void (*fn)(void), dyn_function_type **dynFunc);
void dynFunction_destroy(dyn_function_type *dynFunc);
int dynFunction_call(dyn_function_type *dynFunc, void *returnValue, void **argValues);
-int dynClosure_create(const char *descriptor, dyn_type_list_type *typeReferences, void (*bind)(void
*, void **, void*), void *userData, dyn_closure_type **out);
+int dynClosure_create(FILE *descriptorStream, dyn_type_list_type *typeReferences, void (*bind)(void
*, void **, void*), void *userData, dyn_closure_type **out);
+int dynClosure_createWithStr(const char *descriptor, dyn_type_list_type *typeReferences,
void (*bind)(void *, void **, void*), void *userData, dyn_closure_type **out);
int dynClosure_getFnPointer(dyn_closure_type *dynClosure, void(**fn)(void));
void dynClosure_destroy(dyn_closure_type *dynClosure);
http://git-wip-us.apache.org/repos/asf/celix/blob/5c52b219/remote_services/dynamic_function_interface/dyn_type.c
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_type.c b/remote_services/dynamic_function_interface/dyn_type.c
index cfb2c3f..2dbb645 100644
--- a/remote_services/dynamic_function_interface/dyn_type.c
+++ b/remote_services/dynamic_function_interface/dyn_type.c
@@ -15,7 +15,7 @@
DFI_SETUP_LOG(dynType)
-static int dynType_createWithStream(FILE *stream, dyn_type *parent, dyn_type_list_type *typeReferences,
dyn_type **result);
+static int dynType_createWithStream(FILE *stream, const char *name, dyn_type *parent, dyn_type_list_type
*typeReferences, dyn_type **result);
static void dynType_clear(dyn_type *type);
static void dynType_clearComplex(dyn_type *type);
static void dynType_clearSequence(dyn_type *type);
@@ -57,11 +57,15 @@ static const int DT_ERROR = 1;
static const int DT_MEM_ERROR = 2;
static const int DT_PARSE_ERROR = 3;
-int dynType_create(const char *descriptor, dyn_type_list_type *typeReferences, dyn_type **type)
{
+int dynType_create(FILE *descriptorStream, const char *name, dyn_type_list_type *typeReferences,
dyn_type **type) {
+ return dynType_createWithStream(descriptorStream, name, NULL, typeReferences, type);
+}
+
+int dynType_createWithStr(const char *descriptor, const char *name, dyn_type_list_type *typeReferences,
dyn_type **type) {
int status = DT_OK;
FILE *stream = fmemopen((char *)descriptor, strlen(descriptor), "r");
if (stream != NULL) {
- status = dynType_createWithStream(stream, NULL, typeReferences, type);
+ status = dynType_createWithStream(stream, name, NULL, typeReferences, type);
if (status == DT_OK) {
int c = fgetc(stream);
if (c != '\0' && c != EOF) {
@@ -77,7 +81,7 @@ int dynType_create(const char *descriptor, dyn_type_list_type *typeReferences,
d
return status;
}
-static int dynType_createWithStream(FILE *stream, dyn_type *parent, dyn_type_list_type *typeReferences,
dyn_type **result) {
+static int dynType_createWithStream(FILE *stream, const char *name, dyn_type *parent, dyn_type_list_type
*typeReferences, dyn_type **result) {
int status = DT_OK;
dyn_type *type = calloc(1, sizeof(*type));
if (type != NULL) {
@@ -85,7 +89,16 @@ static int dynType_createWithStream(FILE *stream, dyn_type *parent, dyn_type_lis
type->type = DYN_TYPE_INVALID;
type->typeReferences = typeReferences;
TAILQ_INIT(&type->nestedTypesHead);
- status = dynType_parse(stream, type);
+ if (name != NULL) {
+ type->name = strdup(name);
+ if (type->name == NULL) {
+ status = DT_MEM_ERROR;
+ LOG_ERROR("Error strdup'ing name '%s'\n", name);
+ }
+ }
+ if (status == DT_OK) {
+ status = dynType_parse(stream, type);
+ }
if (status == DT_OK) {
*result = type;
} else {
@@ -334,7 +347,7 @@ static int dynType_parseSequence(FILE *stream, dyn_type *type) {
type->descriptor = '[';
type->sequence.seqType.elements = seq_types;
- status = dynType_createWithStream(stream, type, NULL, &type->sequence.itemType);
+ status = dynType_createWithStream(stream, NULL, type, NULL, &type->sequence.itemType);
if (status == DT_OK) {
type->ffiType = &type->sequence.seqType;
@@ -365,7 +378,7 @@ static int dynType_parseTypedPointer(FILE *stream, dyn_type *type) {
type->descriptor = '*';
type->ffiType = &ffi_type_pointer;
- status = dynType_createWithStream(stream, type, NULL, &type->typedPointer.typedType);
+ status = dynType_createWithStream(stream, NULL, type, NULL, &type->typedPointer.typedType);
return status;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/5c52b219/remote_services/dynamic_function_interface/dyn_type.h
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_type.h b/remote_services/dynamic_function_interface/dyn_type.h
index 2495811..a02b347 100644
--- a/remote_services/dynamic_function_interface/dyn_type.h
+++ b/remote_services/dynamic_function_interface/dyn_type.h
@@ -20,7 +20,7 @@
/* Description string
*
- * Type = [TypeDef]* (SimpleType | ComplexType | SequenceType | TypedPointer | PointerReference
) [TypeDef]*
+ * Type = [TypeDef]* (SimpleType | ComplexType | SequenceType | TypedPointer | PointerReference
) [TypeDef]* [Annotation]*
* Name = alpha[(alpha|numeric)*]
* SPACE = ' '
*
@@ -30,16 +30,16 @@
* C (not supported)
* D double
* F float
- * I int //TODO use int32_t instead?
- * J long //TODO use int64_t intead?
- * S short //TODO use int16_t instead?
+ * I int32_t
+ * J int64_t
+ * S int16_t
* V void
* Z boolean
* //Extended
* b unsigned char
- * i unsigned int (see I)
- * j unsigned long (see J)
- * s unsigned short (see S)
+ * i uint32_t
+ * j uint62_t
+ * s uint64_t
* P pointer
* t char* string
* N native int
@@ -60,9 +60,12 @@
* SequenceType
* [(Type)
*
+ * Annotation 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;
}; };
+ * "{DD{FF c1 c2} a b c}" -> struct { double a; double b; struct c { float c1; float c2;
}; };
*
*
*/
@@ -122,8 +125,10 @@ struct nested_entry {
DFI_SETUP_LOG_HEADER(dynType);
//generic
-int dynType_create(const char *descriptor, dyn_type_list_type *typeReferences, dyn_type **type);
+int dynType_create(FILE *descriptorStream, const char *name, dyn_type_list_type *typeReferences,
dyn_type **type);
+int dynType_createWithStr(const char *descriptor, const char *name, dyn_type_list_type *typeReferences,
dyn_type **type);
void dynType_destroy(dyn_type *type);
+
int dynType_alloc(dyn_type *type, void **bufLoc);
void dynType_print(dyn_type *type);
size_t dynType_size(dyn_type *type);
http://git-wip-us.apache.org/repos/asf/celix/blob/5c52b219/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp b/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp
index ac0566b..072c0f3 100644
--- a/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp
+++ b/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp
@@ -79,7 +79,7 @@ static void tests() {
int rc = 0;
{
- rc = dynClosure_create(EXAMPLE1_DESCRIPTOR, NULL, example1_binding, NULL, &dynClosure);
+ rc = dynClosure_createWithStr(EXAMPLE1_DESCRIPTOR, NULL, example1_binding, NULL,
&dynClosure);
CHECK_EQUAL(0, rc);
int32_t (*func)(int32_t a, int32_t b, int32_t c) = NULL;
int rc = dynClosure_getFnPointer(dynClosure, (void(**)(void))&func);
@@ -92,7 +92,7 @@ static void tests() {
{
dynClosure = NULL;
- rc = dynClosure_create(EXAMPLE2_DESCRIPTOR, NULL, example2_binding, NULL, &dynClosure);
+ rc = dynClosure_createWithStr(EXAMPLE2_DESCRIPTOR, NULL, example2_binding, NULL,
&dynClosure);
CHECK_EQUAL(0, rc);
double (*func)(int32_t a, struct example2_arg2 b, int32_t c) = NULL;
rc = dynClosure_getFnPointer(dynClosure, (void(**)(void))&func);
@@ -109,7 +109,7 @@ static void tests() {
{
dynClosure = NULL;
- rc = dynClosure_create(EXAMPLE3_DESCRIPTOR, NULL, example3_binding, NULL, &dynClosure);
+ rc = dynClosure_createWithStr(EXAMPLE3_DESCRIPTOR, NULL, example3_binding, NULL,
&dynClosure);
CHECK_EQUAL(0, rc);
struct example3_ret * (*func)(int32_t a, int32_t b, int32_t c) = NULL;
rc = dynClosure_getFnPointer(dynClosure, (void(**)(void))&func);
http://git-wip-us.apache.org/repos/asf/celix/blob/5c52b219/remote_services/dynamic_function_interface/tst/dyn_function_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/tst/dyn_function_tests.cpp b/remote_services/dynamic_function_interface/tst/dyn_function_tests.cpp
index c7b5679..478a70c 100644
--- a/remote_services/dynamic_function_interface/tst/dyn_function_tests.cpp
+++ b/remote_services/dynamic_function_interface/tst/dyn_function_tests.cpp
@@ -35,7 +35,7 @@ extern "C" {
int rc;
void (*fp)(void) = (void (*)(void)) example1;
- rc = dynFunction_create(EXAMPLE1_DESCRIPTOR, NULL, fp, &dynFunc);
+ rc = dynFunction_createWithStr(EXAMPLE1_DESCRIPTOR, NULL, fp, &dynFunc);
CHECK_EQUAL(0, rc);
int32_t a = 2;
@@ -74,7 +74,7 @@ extern "C" {
int rc;
void (*fp)(void) = (void (*)(void)) example2;
- rc = dynFunction_create(EXAMPLE2_DESCRIPTOR, NULL, fp, &dynFunc);
+ rc = dynFunction_createWithStr(EXAMPLE2_DESCRIPTOR, NULL, fp, &dynFunc);
CHECK_EQUAL(0, rc);
int32_t arg1 = 2;
http://git-wip-us.apache.org/repos/asf/celix/blob/5c52b219/remote_services/dynamic_function_interface/tst/dyn_type_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/tst/dyn_type_tests.cpp b/remote_services/dynamic_function_interface/tst/dyn_type_tests.cpp
index 046c757..bd3c333 100644
--- a/remote_services/dynamic_function_interface/tst/dyn_type_tests.cpp
+++ b/remote_services/dynamic_function_interface/tst/dyn_type_tests.cpp
@@ -24,7 +24,7 @@ extern "C" {
int i;
type = NULL;
printf("\n-- example %s with descriptor string '%s' --\n", exName, descriptorStr);
- int status = dynType_create(descriptorStr, NULL, &type);
+ int status = dynType_createWithStr(descriptorStr, exName, NULL, &type);
CHECK_EQUAL(0, status);
if (status == 0) {
dynType_print(type);
@@ -105,8 +105,8 @@ TEST(DynTypeTests, ParseRandomGarbageTest) {
}
//printf("ParseRandomGarbageTest iteration %i with descriptor string '%s'\n", k,
descriptorStr);
- dyn_type *type = NULL;
- int status = dynType_create(descriptorStr, NULL, &type);
+ dyn_type *type = NULL;
+ int status = dynType_createWithStr(descriptorStr, NULL, NULL, &type);
if (status == 0) {
dynType_destroy(type);
}
@@ -122,7 +122,7 @@ TEST(DynTypeTests, AssignTest1) {
struct ex1 inst;
const char *desc = "{III a b c}";
dyn_type *type = NULL;
- int status = dynType_create(desc, NULL, &type);
+ int status = dynType_createWithStr(desc, NULL, NULL, &type);
CHECK_EQUAL(0, status);
int32_t val1 = 2;
int32_t val2 = 4;
@@ -146,7 +146,7 @@ TEST(DynTypeTests, AssignTest2) {
struct ex inst;
const char *desc = "{I{DD a b} a b}";
dyn_type *type = NULL;
- int status = dynType_create(desc, NULL, &type);
+ int status = dynType_createWithStr(desc, NULL, NULL, &type);
CHECK_EQUAL(0, status);
int32_t a = 2;
double b_a = 1.1;
http://git-wip-us.apache.org/repos/asf/celix/blob/5c52b219/remote_services/dynamic_function_interface/tst/json_serializer_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/tst/json_serializer_tests.cpp b/remote_services/dynamic_function_interface/tst/json_serializer_tests.cpp
index ee6d4d9..1ec4655 100644
--- a/remote_services/dynamic_function_interface/tst/json_serializer_tests.cpp
+++ b/remote_services/dynamic_function_interface/tst/json_serializer_tests.cpp
@@ -47,7 +47,7 @@ struct example1 {
static void print_example1(void *data) {
struct example1 *ex = (struct example1 *)data;
- printf("example1: a:%f, b:%li, c:%i, d:%i, e:%f\n", ex->a, ex->b, ex->c, ex->d,
ex->e);
+ printf("example1: a:%f, b:%li, c:%i, d:%i, e:%f\n", ex->a, (long)ex->b, ex->c,
ex->d, ex->e);
}
/*********** example 2 ************************/
@@ -73,7 +73,7 @@ struct example2 {
static void print_example2(void *data) {
struct example2 *ex = (struct example2 *)data;
- printf("example2: byte:%i, long1:%li, long2:%li, double1:%f, float1:%f, double2:%f\n",
ex->byte, ex->long1, ex->long2, ex->double1, ex->float1, ex->double2);
+ printf("example2: byte:%i, long1:%li, long2:%li, double1:%f, float1:%f, double2:%f\n",
ex->byte, (long)ex->long1, (long)ex->long2, ex->double1, ex->float1, ex->double2);
}
@@ -136,7 +136,7 @@ static void tests() {
type = NULL;
inst = NULL;
- rc = dynType_create(example1_descriptor, NULL, &type);
+ rc = dynType_createWithStr(example1_descriptor, NULL, NULL, &type);
CHECK_EQUAL(0, rc);
rc = json_deserialize(type, example1_input, &inst);
CHECK_EQUAL(0, rc);
@@ -146,7 +146,7 @@ static void tests() {
type = NULL;
inst = NULL;
- rc = dynType_create(example2_descriptor, NULL, &type);
+ rc = dynType_createWithStr(example2_descriptor, NULL, NULL, &type);
CHECK_EQUAL(0, rc);
rc = json_deserialize(type, example2_input, &inst);
CHECK_EQUAL(0, rc);
@@ -155,7 +155,7 @@ static void tests() {
type = NULL;
inst = NULL;
- rc = dynType_create(example3_descriptor, NULL, &type);
+ rc = dynType_createWithStr(example3_descriptor, NULL, NULL, &type);
CHECK_EQUAL(0, rc);
rc = json_deserialize(type, example3_input, &inst);
CHECK_EQUAL(0, rc);
@@ -163,7 +163,7 @@ static void tests() {
type = NULL;
inst = NULL;
- rc = dynType_create(example4_descriptor, NULL, &type);
+ rc = dynType_createWithStr(example4_descriptor, NULL, NULL, &type);
CHECK_EQUAL(0, rc);
rc = json_deserialize(type, example4_input, &inst);
CHECK_EQUAL(0, rc);
|