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); } }
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; } }