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/10/13 12:21:29 UTC

[01/50] [abbrv] celix git commit: CELIX-237: moved rsa_http_ffi source to rsa_dfi

Repository: celix
Updated Branches:
  refs/heads/develop 4ee2e7fc1 -> 093d2dfa7


http://git-wip-us.apache.org/repos/asf/celix/blob/3d7f7641/remote_services/remote_service_admin_http_ffi/private/src/remote_service_admin_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http_ffi/private/src/remote_service_admin_impl.c b/remote_services/remote_service_admin_http_ffi/private/src/remote_service_admin_impl.c
deleted file mode 100644
index ac54e8d..0000000
--- a/remote_services/remote_service_admin_http_ffi/private/src/remote_service_admin_impl.c
+++ /dev/null
@@ -1,1085 +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_impl.c
- *
- *  \date       May 21, 2015
- *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright	Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <ifaddrs.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <uuid/uuid.h>
-
-#include <curl/curl.h>
-
-#include <ffi.h>
-#include <jansson.h>
-
-#include "export_registration_impl.h"
-#include "import_registration_impl.h"
-#include "remote_service_admin_impl.h"
-#include "remote_constants.h"
-#include "constants.h"
-#include "utils.h"
-#include "bundle_context.h"
-#include "bundle.h"
-#include "service_reference.h"
-#include "service_registration.h"
-#include "log_helper.h"
-#include "log_service.h"
-#include "celix_threads.h"
-#include "civetweb.h"
-#include "log_helper.h"
-#include "endpoint_description.h"
-
-// defines how often the webserver is restarted (with an increased port number)
-#define MAX_NUMBER_OF_RESTARTS 	5
-
-typedef void (*GEN_FUNC_TYPE)(void);
-
-struct generic_service_layout {
-    void *handle;
-    GEN_FUNC_TYPE functions[];
-};
-
-struct proxy {
-  remote_service_admin_pt admin;
-  char *sig;
-  int index;
-  ffi_cif cif;
-  ffi_closure *closure;
-  endpoint_description_pt endpointDescription
-};
-
-
-    
-
-
-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;
-};
-
-struct post {
-    const char *readptr;
-    int size;
-};
-
-struct get {
-    char *writeptr;
-    int size;
-};
-
-static const char *data_response_headers =
-  "HTTP/1.1 200 OK\r\n"
-  "Cache: no-cache\r\n"
-  "Content-Type: application/json\r\n"
-  "\r\n";
-
-static const char *no_content_response_headers =
-  "HTTP/1.1 204 OK\r\n";
-
-// TODO do we need to specify a non-Amdatu specific configuration type?!
-static const char * const CONFIGURATION_TYPE = "org.amdatu.remote.admin.http";
-static const char * const ENDPOINT_URL = "org.amdatu.remote.admin.http.url";
-
-static const char *DEFAULT_PORT = "8888";
-static const char *DEFAULT_IP = "127.0.0.1";
-
-static const unsigned int DEFAULT_TIMEOUT = 0;
-
-static int remoteServiceAdmin_callback(struct mg_connection *conn);
-
-static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, char *interface, endpoint_description_pt *description);
-
-static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip);
-
-static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp);
-static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp);
-
-celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin) {
-	celix_status_t status = CELIX_SUCCESS;
-
-	*admin = calloc(1, sizeof(**admin));
-
-	if (!*admin) {
-		status = CELIX_ENOMEM;
-	} else {
-		unsigned int port_counter = 0;
-		char *port = NULL;
-		char *ip = NULL;
-		char *detectedIp = NULL;
-		(*admin)->context = context;
-		(*admin)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL);
-		(*admin)->importedServices = hashMap_create(NULL, NULL, NULL, NULL);
-
-		celixThreadMutex_create(&(*admin)->exportedServicesLock, NULL);
-		celixThreadMutex_create(&(*admin)->importedServicesLock, NULL);
-
-		if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
-			logHelper_start((*admin)->loghelper);
-		}
-
-		bundleContext_getProperty(context, "RSA_PORT", &port);
-		if (port == NULL) {
-			port = (char *)DEFAULT_PORT;
-		}
-
-		bundleContext_getProperty(context, "RSA_IP", &ip);
-		if (ip == NULL) {
-			char *interface = NULL;
-
-			bundleContext_getProperty(context, "RSA_INTERFACE", &interface);
-			if ((interface != NULL) && (remoteServiceAdmin_getIpAdress(interface, &detectedIp) != CELIX_SUCCESS)) {
-				logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: Could not retrieve IP adress for interface %s", interface);
-			}
-
-			if (ip == NULL) {
-				remoteServiceAdmin_getIpAdress(NULL, &detectedIp);
-			}
-
-			ip = detectedIp;
-		}
-
-		if (ip != NULL) {
-			logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Using %s for service annunciation", ip);
-			(*admin)->ip = strdup(ip);
-		}
-		else {
-			logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No IP address for service annunciation set. Using %s", DEFAULT_IP);
-			(*admin)->ip = (char*) DEFAULT_IP;
-		}
-
-		if (detectedIp != NULL) {
-			free(detectedIp);
-		}
-
-		// Prepare callbacks structure. We have only one callback, the rest are NULL.
-		struct mg_callbacks callbacks;
-		memset(&callbacks, 0, sizeof(callbacks));
-		callbacks.begin_request = remoteServiceAdmin_callback;
-
-		do {
-			char newPort[10];
-			const char *options[] = { "listening_ports", port, NULL};
-
-			(*admin)->ctx = mg_start(&callbacks, (*admin), options);
-
-			if ((*admin)->ctx != NULL) {
-				logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Start webserver: %s", port);
-				(*admin)->port = strdup(port);
-
-			}
-			else {
-		        char* endptr = port;
-		        int currentPort = strtol(port, &endptr, 10);
-
-				errno = 0;
-
-		        if (*endptr || errno != 0) {
-		            currentPort = strtol(DEFAULT_PORT, NULL, 10);
-		        }
-
-		        port_counter++;
-				snprintf(&newPort[0], 6,  "%d", (currentPort+1));
-
-				logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_ERROR, "Error while starting rsa server on port %s - retrying on port %s...", port, newPort);
-				port = newPort;
-			}
-		} while(((*admin)->ctx == NULL) && (port_counter < MAX_NUMBER_OF_RESTARTS));
-
-	}
-	return status;
-}
-
-
-celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin)
-{
-    celix_status_t status = CELIX_SUCCESS;
-
-    free((*admin)->ip);
-    free((*admin)->port);
-    free(*admin);
-
-    *admin = NULL;
-
-    return status;
-}
-
-celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin) {
-	celix_status_t status = CELIX_SUCCESS;
-
-    celixThreadMutex_lock(&admin->exportedServicesLock);
-
-	hash_map_iterator_pt iter = hashMapIterator_create(admin->exportedServices);
-	while (hashMapIterator_hasNext(iter)) {
-		array_list_pt exports = hashMapIterator_nextValue(iter);
-		int i;
-		for (i = 0; i < arrayList_size(exports); i++) {
-			export_registration_pt export = arrayList_get(exports, i);
-			exportRegistration_stopTracking(export);
-		}
-	}
-    hashMapIterator_destroy(iter);
-    celixThreadMutex_unlock(&admin->exportedServicesLock);
-
-    celixThreadMutex_lock(&admin->importedServicesLock);
-
-    iter = hashMapIterator_create(admin->importedServices);
-    while (hashMapIterator_hasNext(iter))
-    {
-    	hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
-
-    	import_registration_factory_pt importFactory = hashMapEntry_getValue(entry);
-
-        if (importFactory != NULL) {
-            int i;
-            for (i = 0; i < arrayList_size(importFactory->registrations); i++)
-            {
-                import_registration_pt importRegistration = arrayList_get(importFactory->registrations, i);
-
-                if (importFactory->trackedFactory != NULL)
-                {
-                    importFactory->trackedFactory->unregisterProxyService(importFactory->trackedFactory->factory, importRegistration->endpointDescription);
-                }
-            }
-
-            serviceTracker_close(importFactory->proxyFactoryTracker);
-            importRegistrationFactory_close(importFactory);
-
-            hashMapIterator_remove(iter);
-            importRegistrationFactory_destroy(&importFactory);
-            }
-    }
-    hashMapIterator_destroy(iter);
-    celixThreadMutex_unlock(&admin->importedServicesLock);
-
-	if (admin->ctx != NULL) {
-		logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Stopping webserver...");
-		mg_stop(admin->ctx);
-		admin->ctx = NULL;
-	}
-
-	hashMap_destroy(admin->exportedServices, false, false);
-	hashMap_destroy(admin->importedServices, false, false);
-
-	logHelper_stop(admin->loghelper);
-	logHelper_destroy(&admin->loghelper);
-
-	return status;
-}
-
-/**
- * Request: http://host:port/services/{service}/{request}
- */
-//void *remoteServiceAdmin_callback(enum mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info) {
-
-static int remoteServiceAdmin_callback(struct mg_connection *conn) {
-	int result = 0; // zero means: let civetweb handle it further, any non-zero value means it is handled by us...
-
-	const struct mg_request_info *request_info = mg_get_request_info(conn);
-	if (request_info->uri != NULL) {
-		remote_service_admin_pt rsa = request_info->user_data;
-
-
-		if (strncmp(request_info->uri, "/service/", 9) == 0 && strcmp("POST", request_info->request_method) == 0) {
-
-			// uri = /services/myservice/call
-			const char *uri = request_info->uri;
-			// rest = myservice/call
-
-			const char *rest = uri+9;
-			char *interfaceStart = strchr(rest, '/');
-			int pos = interfaceStart - rest;
-			char service[pos+1];
-			strncpy(service, rest, pos);
-			service[pos] = '\0';
-      long serviceId = atol(service);
-
-			celixThreadMutex_lock(&rsa->exportedServicesLock);
-
-      //find endpoint
-      export_registration_pt export = NULL;
-			hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
-			while (hashMapIterator_hasNext(iter)) {
-				hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
-				array_list_pt exports = hashMapEntry_getValue(entry);
-				int expIt = 0;
-				for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
-					export_registration_pt check = arrayList_get(exports, expIt);
-					if (serviceId == check->endpointDescription->serviceId) {
-              export = check;
-              break;
-          }
-        }
-      }
-      hashMapIterator_destroy(iter);
-
-      if (export != NULL) {
-          uint64_t datalength = request_info->content_length;
-          char* data = malloc(datalength + 1);
-          mg_read(conn, data, datalength);
-          data[datalength] = '\0';
-
-          char *response = NULL;
-
-          //FIXME assuming add signature (add(double, double) : double)
-          /*TODO
-            export->endpoint->handleRequest(export->endpoint->endpoint, data, &response);
-            */
-
-
-          //retreive schema.
-          char *schema = NULL;
-          schema = properties_get(export->endpointDescription->properties, "protocol.schema");
-          printf("RSA: got schema %s\n", schema);
-
-
-          printf("Parsing data: %s\n", data);
-          json_error_t error;
-          json_t *js_request = json_loads(data, 0, &error);
-          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 {
-              printf("RSA: got error '%s' for '%s'\n", error.text, data);
-              return 0;
-          }
-
-          printf("RSA: Looking for method %s\n", sig);
-
-          json_t *js_schema = json_loads(schema, 0, &error);
-          int methodIndex = -1;
-          if (js_schema) {
-              //TODO parse schema and create cif
-              size_t index;
-              json_t *value;
-              json_array_foreach(js_schema, index, value) {
-                  if (strcmp(sig, json_string_value(value)) == 0) {
-                      //found match
-                      methodIndex = index;
-                      break;
-                  }
-              }
-          } else {
-              printf("RSA: got error '%s' for '%s'\n", error.text, schema);
-              return 0;
-          }
-
-          if (methodIndex < 0) {
-              printf("RSA: cannot find method '%s'\n", sig);
-              return 1;
-          }
-
-          size_t sigLength = strlen(sig);
-          char provArgs[sigLength];
-          bool startFound = false;
-          int i = 0;
-          int argIndex = 0;
-          for (; i < sigLength; i += 1) {
-              if (!startFound) {
-                  if (sig[i] == '(') {
-                      startFound = true;
-                  }
-              } else {
-                  if (sig[i] != ')') {
-                      provArgs[argIndex++] = sig[i];
-                  }
-              }
-          } 
-          provArgs[argIndex] = '\0';
-          size_t provArgsLength = strlen(provArgs) -1; 
-          printf("method index is %i and args are '%s'\n", methodIndex, provArgs);
-
-
-          //FFI part
-          ffi_cif cif;
-          ffi_type *argTypes[provArgsLength + 2]; //e.g. void *handle (extra), double a, double b, double *result (extra)
-          void *valuePointers[provArgsLength + 2];
-          //note assuming doubles!!
-          double values[provArgsLength];
-          double result = 0.0;
-          double *resultPointer = &result;
-          int rvalue = 0;
-
-          argTypes[0] = &ffi_type_pointer;
-          argTypes[provArgsLength +1] = &ffi_type_pointer; //last argument is return value, handled as a pointer
-          for (i = 0; i < provArgsLength; i += 1) {
-              //FIXME for now assuming double as arguments
-              argTypes[i+1] = &ffi_type_double;
-          }
-
-          valuePointers[0] = NULL;
-          valuePointers[provArgsLength+1] = &resultPointer;
-          for (i = 0; i < provArgsLength; i += 1) {
-              values[i] = 0.0;
-              valuePointers[i+1] = &(values[i]);
-          }
-
-          json_t *arguments = json_object_get(js_request, "a");
-          json_t *value;
-          size_t index;
-          json_array_foreach(arguments, index, value) {
-              values[index] = json_real_value(value); //setting values, again assuming double
-          }
-
-          json_decref(js_schema);
-          json_decref(js_request);
-
-          if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, provArgsLength + 2,
-                      &ffi_type_sint, argTypes) == FFI_OK)
-          {
-              printf("RSA: FFI PREP OK\n");
-
-              //TRYING TO CALL Calculate service
-              void *service = NULL;
-              bundleContext_getService(rsa->context, export->reference, &service);     
-              if (service == NULL) {
-                  printf("RSA: Ouch service is NULL\n");
-                  return 0;
-              } else {
-                  printf("RSA: service ok\n");
-              }
-
-              struct generic_service_layout *serv = service;
-
-              printf("RSA:Trying to call service using ffi\n");
-              valuePointers[0] = serv->handle;
-              ffi_call(&cif, serv->functions[methodIndex], &rvalue, valuePointers);
-              printf("RSA: Done calling service through ffi, got value %f\n", result);
-
-              json_t *resultRoot;
-              resultRoot = json_pack("{s:f}", "r", result);
-              response = json_dumps(resultRoot, 0);
-              json_decref(resultRoot);  
-          }
-
-          if (response != NULL) {
-              mg_write(conn, data_response_headers, strlen(data_response_headers));
-//              mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
-              mg_write(conn, response, strlen(response));
-//              mg_send_data(conn, response, strlen(response));
-//              mg_write_data(conn, response, strlen(response));
-
-              free(response);
-          } else {
-              mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
-          }
-          result = 0;
-
-          free(data);
-      } else {
-          //TODO log warning
-      }
-
-      celixThreadMutex_unlock(&rsa->exportedServicesLock);
-
-		}
-	}
-
-	return 1;
-}
-
-celix_status_t remoteServiceAdmin_handleRequest(remote_service_admin_pt rsa, char *service, char *data, char **reply) {
-	celixThreadMutex_lock(&rsa->exportedServicesLock);
-
-	hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
-	while (hashMapIterator_hasNext(iter)) {
-		hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
-		array_list_pt exports = hashMapEntry_getValue(entry);
-		int expIt = 0;
-		for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
-			export_registration_pt export = arrayList_get(exports, expIt);
-			if (strcmp(service, export->endpointDescription->service) == 0) {
-				export->endpoint->handleRequest(export->endpoint->endpoint, data, reply);
-			}
-		}
-	}
-    hashMapIterator_destroy(iter);
-
-	celixThreadMutex_unlock(&rsa->exportedServicesLock);
-
-	return CELIX_SUCCESS;
-}
-
-celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations) {
-    celix_status_t status = CELIX_SUCCESS;
-    arrayList_create(registrations);
-    array_list_pt references = NULL;
-    service_reference_pt reference = NULL;
-    char filter [256];
-
-    snprintf(filter, 256, "(%s=%s)", (char *)OSGI_FRAMEWORK_SERVICE_ID, serviceId);
-
-    bundleContext_getServiceReferences(admin->context, NULL, filter, &references); //FIXME not safe
-
-    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: exportService called for serviceId %s", serviceId);
-
-    if (arrayList_size(references) >= 1) {
-        reference = arrayList_get(references, 0);
-    }
-
-    if(references!=NULL){
-        arrayList_destroy(references);
-    }
-
-    if (reference == NULL) {
-        logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "ERROR: expected a reference for service id %s.", serviceId);
-        return CELIX_ILLEGAL_STATE;
-    }
-
-    char *exports = NULL;
-    char *provided = NULL;
-    char *schema = NULL;
-    serviceReference_getProperty(reference, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exports);
-    serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_OBJECTCLASS, &provided);
-    serviceReference_getProperty(reference, (char *) "protocol.schema", &schema);
-
-    if (exports == NULL || provided == NULL) {
-        logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No Services to export.");
-            status = CELIX_ILLEGAL_STATE;
-    } else {
-        if (schema == NULL) {
-            logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: no protocol.schema found.");
-            status = CELIX_ILLEGAL_STATE;
-        } else {
-            logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Export service (%s)", provided);
-
-            char *interface = provided;
-            endpoint_description_pt endpoint = NULL;
-            export_registration_pt registration = NULL;
-
-            remoteServiceAdmin_createEndpointDescription(admin, reference, interface, &endpoint);
-            printf("RSA: Creating export registration with endpoint pointer %p\n", endpoint);
-            exportRegistration_create(admin->loghelper, reference, endpoint, admin, admin->context, &registration);
-            arrayList_add(*registrations, registration);
-
-            exportRegistration_open(registration);
-            exportRegistration_startTracking(registration);
-
-            celixThreadMutex_lock(&admin->exportedServicesLock);
-            hashMap_put(admin->exportedServices, reference, *registrations);
-            celixThreadMutex_unlock(&admin->exportedServicesLock);
-        }
-    }
-    return status;
-}
-
-celix_status_t remoteServiceAdmin_removeExportedService(export_registration_pt registration) {
-    celix_status_t status = CELIX_SUCCESS;
-    remote_service_admin_pt admin = registration->rsa;
-
-    celixThreadMutex_lock(&admin->exportedServicesLock);
-
-    hashMap_remove(admin->exportedServices, registration->reference);
-
-    celixThreadMutex_unlock(&admin->exportedServicesLock);
-
-    return status;
-}
-
-static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, char *interface, endpoint_description_pt *endpoint) {
-	celix_status_t status = CELIX_SUCCESS;
-	properties_pt endpointProperties = properties_create();
-
-
-	unsigned int size = 0;
-    char **keys;
-
-    serviceReference_getPropertyKeys(reference, &keys, &size);
-    for (int i = 0; i < size; i++) {
-        char *key = keys[i];
-        char *value = NULL;
-
-        if (serviceReference_getProperty(reference, key, &value) == CELIX_SUCCESS
-        		&& strcmp(key, (char*) OSGI_RSA_SERVICE_EXPORTED_INTERFACES) != 0
-        		&& strcmp(key, (char*) OSGI_FRAMEWORK_OBJECTCLASS) != 0) {
-        	properties_set(endpointProperties, key, value);
-          printf("Added property '%s' with value '%s'\n", key, value);
-        }
-	}
-
-	hash_map_entry_pt entry = hashMap_getEntry(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
-
-	char* key = hashMapEntry_getKey(entry);
-	char *serviceId = (char *) hashMap_remove(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
-	char *uuid = NULL;
-
-	char buf[512];
-	snprintf(buf, 512,  "/service/%s/%s", serviceId, interface);
-
-	char url[1024];
-	snprintf(url, 1024, "http://%s:%s%s", admin->ip, admin->port, buf);
-
-	uuid_t endpoint_uid;
-	uuid_generate(endpoint_uid);
-	char endpoint_uuid[37];
-	uuid_unparse_lower(endpoint_uid, endpoint_uuid);
-
-	bundleContext_getProperty(admin->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
-	properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
-	properties_set(endpointProperties, (char*) OSGI_FRAMEWORK_OBJECTCLASS, interface);
-	properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_SERVICE_ID, serviceId);
-	properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID, endpoint_uuid);
-	properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED, "true");
-  properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED_CONFIGS, (char*) CONFIGURATION_TYPE);
-  properties_set(endpointProperties, (char*) ENDPOINT_URL, url);
-
-
-
-  *endpoint = calloc(1, sizeof(**endpoint));
-  if (!*endpoint) {
-      status = CELIX_ENOMEM;
-  } else {
-      (*endpoint)->id = properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID);
-      char *serviceId = NULL;
-      serviceReference_getProperty(reference, (char*) OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
-      (*endpoint)->serviceId = strtoull(serviceId, NULL, 0);
-      (*endpoint)->frameworkUUID = properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
-      (*endpoint)->service = interface;
-      (*endpoint)->properties = endpointProperties;
-  }
-
-	free(key);
-	free(serviceId);
-	free(keys);
-
-	return status;
-}
-
-static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip) {
-	celix_status_t status = CELIX_BUNDLE_EXCEPTION;
-
-	struct ifaddrs *ifaddr, *ifa;
-    char host[NI_MAXHOST];
-
-    if (getifaddrs(&ifaddr) != -1)
-    {
-		for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
-		{
-			if (ifa->ifa_addr == NULL)
-				continue;
-
-			if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
-				if (interface == NULL) {
-					*ip = strdup(host);
-					status = CELIX_SUCCESS;
-				}
-				else if (strcmp(ifa->ifa_name, interface) == 0) {
-					*ip = strdup(host);
-					status = CELIX_SUCCESS;
-				}
-			}
-		}
-
-		freeifaddrs(ifaddr);
-    }
-
-    return status;
-}
-
-
-celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description)
-{
-	celix_status_t status = CELIX_SUCCESS;
-
-	properties_destroy((*description)->properties);
-	free(*description);
-
-	return status;
-}
-
-
-celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services) {
-	celix_status_t status = CELIX_SUCCESS;
-	return status;
-}
-
-celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services) {
-	celix_status_t status = CELIX_SUCCESS;
-	return status;
-}
-
-
-static int remoteServiceAdmin_remoteFunctionProxy(ffi_cif *cif, int *ret, void* args[], void *userData); //TODO MOVE
-static int remoteServiceAdmin_remoteFunctionProxy(ffi_cif *cif, int *ret, void* args[], void *userData) {
-   void **handle = args[0];
-   remote_service_admin_pt admin = (*handle);
-
-   struct proxy *proxy = userData;
-
-   printf("ffi closure got called for method sig %s with index %i\n", proxy->sig, proxy->index);
-
-   json_t *root = json_object();
-   json_t *sig = json_string(proxy->sig);
-   json_object_set(root, "m", sig);
-
-   json_t *arguments = json_array();
-   int i;
-   for (i = 1; i < proxy->cif.nargs -1; i += 1) {
-       //NOTE assuming double
-       double *dval = args[i];
-       json_t *value = json_real(*dval);
-       json_array_append(arguments, value);
-   }
-   json_object_set(root, "a", arguments);
-
-   char *data = json_dumps(root, 0);
-   char *reply = NULL;
-   int replyStatus;
-
-   remoteServiceAdmin_send(proxy->admin, proxy->endpointDescription, data, &reply, &replyStatus);
-   (*ret) = replyStatus;
-   printf("got reply from server '%s'\n", reply);
-
-   json_error_t error;
-   json_t *js_reply = json_loads(reply, JSON_DECODE_ANY, &error);
-   if (js_reply) {
-       //note assuming double
-       double **result = args[proxy->cif.nargs - 1];
-       json_unpack(js_reply, "{s:f}", "r", *result);
-       json_decref(js_reply);
-   } else {
-       printf("PROXY: got error '%s' for '%s'\n", error.text, reply);
-   }
-
-   json_decref(root);
-
-   free(data);
-   free(reply);
-
-   return 0;
-}
-
-
-celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpointDescription, import_registration_pt *registration) {
-	celix_status_t status = CELIX_SUCCESS;
-
-	logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Import service %s", endpointDescription->service);
-
-  char *schema = properties_get(endpointDescription->properties, "protocol.schema");
-  if (schema == NULL) {
-    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: protocol schema not found for endpoint\n");
-    return CELIX_SUCCESS;
-  }
-
-  printf("protocol.schema is '%s'\n", schema);
-  json_error_t error;
-  json_t *js_schema = json_loads(schema, 0, &error);
-  if (js_schema) {
-      //TODO parse schema and create cif
-      size_t numOfMethods = json_array_size(js_schema);
-      printf("RSA: num of method for proxy is %i\n", (int) numOfMethods);
-
-      struct generic_service_layout *service = calloc(1, sizeof(*service) + (numOfMethods-1) * sizeof(GEN_FUNC_TYPE)); 
-      service->handle = admin;
-
-        //struct generic_service_layout {
-        //    void *handle;
-        //    GEN_FUNC_TYPE functions[];
-        //};
-
-      size_t index;
-      json_t *value;
-      json_array_foreach(js_schema, index, value) {
-          //create closure
-
-          char *sig = json_string_value(value);
-          size_t sigLength = strlen(sig);
-          char provArgs[sigLength];
-          bool startFound = false;
-          int i = 0;
-          int argIndex = 0;
-          for (; i < sigLength; i += 1) {
-              if (!startFound) {
-                  if (sig[i] == '(') {
-                      startFound = true;
-                  }
-              } else {
-                  if (sig[i] != ')') {
-                      provArgs[argIndex++] = sig[i];
-                  }
-              }
-          } 
-          provArgs[argIndex] = '\0';
-          printf("method index is %i and args are '%s'\n", index, provArgs);
-
-          int provArgLength = strlen(provArgs) -1;
-
-          struct proxy *proxy = malloc(sizeof(*proxy));
-          proxy->admin = admin;
-          proxy->sig = strdup(sig);
-          proxy->index = index;
-          proxy->endpointDescription = endpointDescription;
-          
-          ffi_type **args = calloc(provArgLength +2, sizeof(ffi_type)); //TODO test if this can be on the stack
-
-          void (*function)(void);
-          proxy->closure = ffi_closure_alloc(sizeof(ffi_closure), &function);
-          service->functions[index] = function;
-
-          /* Initialize the argument info vectors */
-          args[0] = &ffi_type_pointer;
-          args[provArgLength + 1] = &ffi_type_pointer;
-          for (i = 0; i < provArgLength; i += 1) {
-              args[i+1] = &ffi_type_double;
-          }
-
-          if (proxy->closure) {
-            if (ffi_prep_cif(&proxy->cif, FFI_DEFAULT_ABI, provArgLength + 2, &ffi_type_sint, args) == FFI_OK) {
-                if (ffi_prep_closure_loc(proxy->closure, &proxy->cif, remoteServiceAdmin_remoteFunctionProxy, proxy, function) == FFI_OK) {
-                    printf("RSA: created closure for method '%s'\n", sig);
-                }
-            }
-          }
-      }
-                   
-      //TODO register with imported properties 
-      char *objectClass = properties_get(endpointDescription->properties, "objectClass");
-      service_registration_pt reg = NULL;
-      bundleContext_registerService(admin->context, objectClass, service, NULL, &reg);
-      printf("registered proxy service with objectclass '%s'\n", objectClass);
-
-  } else {
-      printf("RSA: got error '%s' for '%s'\n", error.text, schema);
-      return CELIX_ILLEGAL_STATE;
-  }
-
-
-  //celixThreadMutex_lock(&admin->importedServicesLock);
-  //celixThreadMutex_unlock(&admin->importedServicesLock);
-
-
-  return status;
-  /*
-
-	celixThreadMutex_lock(&admin->importedServicesLock);
-
-   import_registration_factory_pt registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
-
-	// check whether we already have a registration_factory registered in the hashmap
-	if (registration_factory == NULL)
-	{
-		status = importRegistrationFactory_install(admin->loghelper, endpointDescription->service, admin->context, &registration_factory);
-		if (status == CELIX_SUCCESS) {
-		    hashMap_put(admin->importedServices, endpointDescription->service, registration_factory);
-		}
-	}
-
-	 // factory available
-	if (status != CELIX_SUCCESS || (registration_factory->trackedFactory == NULL))
-	{
-		logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: no proxyFactory available.");
-		if (status == CELIX_SUCCESS) {
-			status = CELIX_SERVICE_EXCEPTION;
-		}
-	}
-	else
-	{
-		// we create an importRegistration per imported service
-		importRegistration_create(endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send, admin->context, registration);
-		registration_factory->trackedFactory->registerProxyService(registration_factory->trackedFactory->factory,  endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send);
-
-		arrayList_add(registration_factory->registrations, *registration);
-	}
-
-    celixThreadMutex_unlock(&admin->importedServicesLock);
-
-
-	return status;
-  */
-}
-
-
-celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration) {
-	celix_status_t status = CELIX_SUCCESS;
-  return status;
-  /*
-
-	endpoint_description_pt endpointDescription = (endpoint_description_pt) registration->endpointDescription;
-	import_registration_factory_pt registration_factory = NULL;
-
-    celixThreadMutex_lock(&admin->importedServicesLock);
-
-    registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
-
-    // factory available
-    if ((registration_factory == NULL) || (registration_factory->trackedFactory == NULL))
-    {
-    	logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: Error while retrieving registration factory for imported service %s", endpointDescription->service);
-    }
-    else
-    {
-		registration_factory->trackedFactory->unregisterProxyService(registration_factory->trackedFactory->factory, endpointDescription);
-		arrayList_removeElement(registration_factory->registrations, registration);
-		importRegistration_destroy(registration);
-
-		if (arrayList_isEmpty(registration_factory->registrations))
-		{
-			logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: closing proxy.");
-
-			serviceTracker_close(registration_factory->proxyFactoryTracker);
-			importRegistrationFactory_close(registration_factory);
-
-			hashMap_remove(admin->importedServices, endpointDescription->service);
-
-			importRegistrationFactory_destroy(&registration_factory);
-		}
-    }
-
-    celixThreadMutex_unlock(&admin->importedServicesLock);
-
-	return status;
-  */
-}
-
-
-celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus) {
-
-    struct post post;
-    post.readptr = request;
-    post.size = strlen(request);
-
-    struct get get;
-    get.size = 0;
-    get.writeptr = malloc(1);
-
-    char *serviceUrl = properties_get(endpointDescription->properties, (char*) ENDPOINT_URL);
-    char url[256];
-    snprintf(url, 256, "%s", serviceUrl);
-
-    // assume the default timeout
-    int timeout = DEFAULT_TIMEOUT;
-
-    char *timeoutStr = NULL;
-    // Check if the endpoint has a timeout, if so, use it.
-	timeoutStr = properties_get(endpointDescription->properties, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT);
-    if (timeoutStr == NULL) {
-    	// If not, get the global variable and use that one.
-    	bundleContext_getProperty(rsa->context, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT, &timeoutStr);
-    }
-
-    // Update timeout if a property is used to set it.
-    if (timeoutStr != NULL) {
-    	timeout = atoi(timeoutStr);
-    }
-
-    celix_status_t status = CELIX_SUCCESS;
-    CURL *curl;
-    CURLcode res;
-
-    curl = curl_easy_init();
-    if(!curl) {
-        status = CELIX_ILLEGAL_STATE;
-    } else {
-    	curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
-        curl_easy_setopt(curl, CURLOPT_URL, &url[0]);
-        curl_easy_setopt(curl, CURLOPT_POST, 1L);
-        curl_easy_setopt(curl, CURLOPT_READFUNCTION, remoteServiceAdmin_readCallback);
-        curl_easy_setopt(curl, CURLOPT_READDATA, &post);
-        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, remoteServiceAdmin_write);
-        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&get);
-        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)post.size);
-        res = curl_easy_perform(curl);
-        curl_easy_cleanup(curl);
-
-        *reply = get.writeptr;
-        *replyStatus = res;
-    }
-
-    return status;
-}
-
-static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp) {
-    struct post *post = userp;
-
-    if (post->size) {
-        *(char *) ptr = post->readptr[0];
-        post->readptr++;
-        post->size--;
-        return 1;
-    }
-
-    return 0;
-}
-
-static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp) {
-  size_t realsize = size * nmemb;
-  struct get *mem = (struct get *)userp;
-
-  mem->writeptr = realloc(mem->writeptr, mem->size + realsize + 1);
-  if (mem->writeptr == NULL) {
-    /* out of memory! */
-	printf("not enough memory (realloc returned NULL)");
-    exit(EXIT_FAILURE);
-  }
-
-  memcpy(&(mem->writeptr[mem->size]), contents, realsize);
-  mem->size += realsize;
-  mem->writeptr[mem->size] = 0;
-
-  return realsize;
-}
-
-
-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;
-}
-
-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;
-}


[08/50] [abbrv] celix git commit: CELIX-237: Updated celix launcher so that mutiple embedded framework can be started (e.g. testing client / server rsa)

Posted by pn...@apache.org.
CELIX-237: Updated celix launcher so that mutiple embedded framework can be started (e.g. testing client / server rsa)


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

Branch: refs/heads/develop
Commit: 55e75be72c24a62818fe3e2326c396725f1d7557
Parents: 87f3fab
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Thu Aug 6 13:27:13 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Thu Aug 6 13:27:13 2015 +0200

----------------------------------------------------------------------
 framework/private/src/framework.c               |  2 +
 launcher/private/src/launcher.c                 | 46 ++++++++++----------
 launcher/private/src/main.c                     | 24 ++++++----
 launcher/public/include/launcher.h              | 12 ++---
 .../remote_service_admin_dfi/tst/rsa_tests.cpp  | 24 ++++++----
 .../remote_service_admin_dfi/tst/run_tests.cpp  | 17 --------
 6 files changed, 62 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/55e75be7/framework/private/src/framework.c
----------------------------------------------------------------------
diff --git a/framework/private/src/framework.c b/framework/private/src/framework.c
index 3f49cdc..6e6e1ba 100644
--- a/framework/private/src/framework.c
+++ b/framework/private/src/framework.c
@@ -335,6 +335,8 @@ celix_status_t framework_destroy(framework_pt framework) {
 	celixThreadMutex_destroy(&framework->mutex);
 	celixThreadCondition_destroy(&framework->condition);
 
+    properties_destroy(framework->configurationMap);
+
 	free(framework);
 
 	return status;

http://git-wip-us.apache.org/repos/asf/celix/blob/55e75be7/launcher/private/src/launcher.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/launcher.c b/launcher/private/src/launcher.c
index 9c021ed..432c709 100644
--- a/launcher/private/src/launcher.c
+++ b/launcher/private/src/launcher.c
@@ -32,23 +32,22 @@
 #include <libgen.h>
 #include <signal.h>
 
+#ifndef CELIX_NO_CURLINIT
 #include <curl/curl.h>
+#endif
 
 #include "framework.h"
 #include "linked_list_iterator.h"
 
-static struct framework * framework;
-static properties_pt config;
-
 #ifdef WITH_APR
 static apr_pool_t *memoryPool;
 #endif
 
-int celixLauncher_launch(const char *configFile) {
+int celixLauncher_launch(const char *configFile, framework_pt *framework) {
     int status = 0;
     FILE *config = fopen(configFile, "r");
     if (config != NULL) {
-        status = celixLauncher_launchWithStream(config);
+        status = celixLauncher_launchWithStream(config, framework);
     } else {
         fprintf(stderr, "Error: invalid or non-existing configuration file: '%s'.", configFile);
         perror("");
@@ -57,10 +56,10 @@ int celixLauncher_launch(const char *configFile) {
     return status;
 }
 
-int celixLauncher_launchWithStream(FILE *stream) {
+int celixLauncher_launchWithStream(FILE *stream, framework_pt *framework) {
     int status = 0;
 
-    config = properties_loadWithStream(stream);
+    properties_pt config = properties_loadWithStream(stream);
     fclose(stream);
     // Make sure we've read it and that nothing went wrong with the file access...
     if (config == NULL) {
@@ -69,14 +68,16 @@ int celixLauncher_launchWithStream(FILE *stream) {
         status = 1;
     }
 
-    // Set signal handler
+
 #ifdef WITH_APR
     apr_status_t rv;
     apr_status_t s;
 #endif
 
+#ifndef CELIX_NO_CURLINIT
     // Before doing anything else, let's setup Curl
     curl_global_init(CURL_GLOBAL_NOTHING);
+#endif
 
 #ifdef WITH_APR
 	rv = apr_initialize();
@@ -93,19 +94,18 @@ int celixLauncher_launchWithStream(FILE *stream) {
 
     if (status == 0) {
         char *autoStart = properties_get(config, "cosgi.auto.start.1");
-        framework = NULL;
         celix_status_t status;
 #ifdef WITH_APR
-        status = framework_create(&framework, memoryPool, config);
+        status = framework_create(framework, memoryPool, config);
 #else
-        status = framework_create(&framework, config);
+        status = framework_create(framework, config);
 #endif
         bundle_pt fwBundle = NULL;
         if (status == CELIX_SUCCESS) {
-            status = fw_init(framework);
+            status = fw_init(*framework);
             if (status == CELIX_SUCCESS) {
                 // Start the system bundle
-                framework_getFrameworkBundle(framework, &fwBundle);
+                framework_getFrameworkBundle(*framework, &fwBundle);
                 bundle_start(fwBundle);
 
                 char delims[] = " ";
@@ -128,7 +128,7 @@ int celixLauncher_launchWithStream(FILE *stream) {
                 // First install all bundles
                 // Afterwards start them
                 arrayList_create(&installed);
-                framework_getFrameworkBundle(framework, &bundle);
+                framework_getFrameworkBundle(*framework, &bundle);
                 bundle_getContext(bundle, &context);
                 iter = linkedListIterator_create(bundles, 0);
                 while (linkedListIterator_hasNext(iter)) {
@@ -164,8 +164,11 @@ int celixLauncher_launchWithStream(FILE *stream) {
 	apr_terminate();
 #endif
 
+
+#ifndef CELIX_NO_CURLINIT
         // Cleanup Curl
         curl_global_cleanup();
+#endif
 
         printf("Launcher: Exit\n");
     }
@@ -173,19 +176,16 @@ int celixLauncher_launchWithStream(FILE *stream) {
     return status;
 }
 
-void celixLauncher_waitForShutdown(void) {
+void celixLauncher_waitForShutdown(framework_pt framework) {
     framework_waitForStop(framework);
+}
+
+void celixLauncher_destroy(framework_pt framework) {
     framework_destroy(framework);
-    properties_destroy(config);
 }
 
-void celixLauncher_stop(void) {
+void celixLauncher_stop(framework_pt framework) {
     bundle_pt fwBundle = NULL;
     framework_getFrameworkBundle(framework, &fwBundle);
     bundle_stop(fwBundle);
-}
-
-struct framework *celixLauncher_getFramework(void) {
-    return framework;
-}
-
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/55e75be7/launcher/private/src/main.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/main.c b/launcher/private/src/main.c
index 00b08bd..82530e1 100644
--- a/launcher/private/src/main.c
+++ b/launcher/private/src/main.c
@@ -31,13 +31,13 @@
 #include "launcher.h"
 
 static void show_usage(char* prog_name);
-static void shutdownCelix(int signal);
+static void shutdown_framework(int signal);
 
 #define DEFAULT_CONFIG_FILE "config.properties"
 
-int main(int argc, char *argv[]) {
+static framework_pt framework = NULL;
 
-    (void) signal(SIGINT, shutdownCelix);
+int main(int argc, char *argv[]) {
 
     // Perform some minimal command-line option parsing...
     char *opt = NULL;
@@ -59,15 +59,21 @@ int main(int argc, char *argv[]) {
         config_file = DEFAULT_CONFIG_FILE;
     }
 
-    celixLauncher_launch(config_file);
-    celixLauncher_waitForShutdown();
+
+    // Set signal handler
+    (void) signal(SIGINT, shutdown_framework);
+
+    celixLauncher_launch(config_file, &framework);
+    celixLauncher_waitForShutdown(framework);
+    celixLauncher_destroy(framework);
 }
 
 static void show_usage(char* prog_name) {
     printf("Usage:\n  %s [path/to/config.properties]\n\n", basename(prog_name));
 }
 
-static void shutdownCelix(int signal) {
-    celixLauncher_stop();
-}
-
+static void shutdown_framework(int signal) {
+    if (framework != NULL) {
+        celixLauncher_stop(framework); //NOTE main thread will destroy
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/55e75be7/launcher/public/include/launcher.h
----------------------------------------------------------------------
diff --git a/launcher/public/include/launcher.h b/launcher/public/include/launcher.h
index 6ee8357..6077e03 100644
--- a/launcher/public/include/launcher.h
+++ b/launcher/public/include/launcher.h
@@ -30,10 +30,12 @@
 #include <stdio.h>
 #include "framework.h"
 
-int celixLauncher_launch(const char *configFile);
-int celixLauncher_launchWithStream(FILE *config);
-void celixLauncher_stop(void);
-void celixLauncher_waitForShutdown(void);
-struct framework *celixLauncher_getFramework(void);
+int celixLauncher_launch(const char *configFile, framework_pt *framework);
+int celixLauncher_launchWithStream(FILE *config, framework_pt *framework);
+
+void celixLauncher_stop(framework_pt framework);
+void celixLauncher_destroy(framework_pt framework);
+
+void celixLauncher_waitForShutdown(framework_pt framework);
 
 #endif //CELIX_LAUNCHER_H

http://git-wip-us.apache.org/repos/asf/celix/blob/55e75be7/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp b/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
index a5a556a..f23babd 100644
--- a/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
@@ -17,16 +17,19 @@ extern "C" {
 #include "remote_service_admin.h"
 
 
+framework_pt framework = NULL;
 bundle_context_pt context = NULL;
 service_reference_pt rsaRef = NULL;
 remote_service_admin_service_pt rsa = NULL;
 
-static void setupContextAndRsa(void) {
+static void setupFm(void) {
     int rc = 0;
-    struct framework *fm = celixLauncher_getFramework();
+
+    rc = celixLauncher_launch("config.properties", &framework);
+    CHECK_EQUAL(CELIX_SUCCESS, rc);
 
     bundle_pt bundle = NULL;
-    rc = framework_getFrameworkBundle(fm, &bundle);
+    rc = framework_getFrameworkBundle(framework, &bundle);
     CHECK_EQUAL(CELIX_SUCCESS, rc);
 
     rc = bundle_getContext(bundle, &context);
@@ -39,13 +42,19 @@ static void setupContextAndRsa(void) {
     CHECK_EQUAL(CELIX_SUCCESS, rc);
 }
 
-static void teardownContextAndRsa(void) {
+static void teardownFm(void) {
     int rc = 0;
     rc = bundleContext_ungetService(context, rsaRef, NULL);
     CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+    celixLauncher_stop(framework);
+    celixLauncher_waitForShutdown(framework);
+    celixLauncher_destroy(framework);
+
     rsaRef = NULL;
     rsa = NULL;
     context = NULL;
+    framework = NULL;
 }
 
 static void testInfo(void) {
@@ -77,14 +86,11 @@ static void testImportService(void) {
 
 TEST_GROUP(RsaDfiTests) {
     void setup() {
-        celixLauncher_launch("config.properties");
-        setupContextAndRsa();
+        setupFm();
     }
 
     void teardown() {
-        teardownContextAndRsa();
-        celixLauncher_stop();
-        celixLauncher_waitForShutdown();
+        teardownFm();
     }
 };
 

http://git-wip-us.apache.org/repos/asf/celix/blob/55e75be7/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/run_tests.cpp b/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
index 81d1908..c5e960c 100644
--- a/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
@@ -4,23 +4,6 @@
 #include <CppUTest/TestHarness.h>
 #include "CppUTest/CommandLineTestRunner.h"
 
-
-extern "C" {
-    #include <stdio.h>
-
-    #include "launcher.h"
-    #include "framework.h"
-
-    static int startCelix(void) {
-        celixLauncher_launch("config.properties");
-    }
-
-    static int stopCelix(void) {
-        celixLauncher_stop();
-        celixLauncher_waitForShutdown();
-    }
-}
-
 int main(int argc, char** argv) {
     return RUN_ALL_TESTS(argc, argv);
 }
\ No newline at end of file


[46/50] [abbrv] celix git commit: CELIX-237: Merge branch 'develop' into ffi

Posted by pn...@apache.org.
CELIX-237: Merge branch 'develop' into ffi

Conflicts:
	.travis.yml
	launcher/private/src/launcher.c
	remote_services/discovery/private/src/endpoint_discovery_poller.c
	utils/CMakeLists.txt


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

Branch: refs/heads/develop
Commit: 119bb95046bf338613f7d7c6439af328ced2172f
Parents: a13465a cec955d
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Oct 7 14:43:09 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Oct 7 14:43:09 2015 +0200

----------------------------------------------------------------------
 .travis.yml                                     |    2 +-
 deployment_admin/CMakeLists.txt                 |    6 +-
 framework/CMakeLists.txt                        |   82 +-
 framework/private/mock/bundle_context_mock.c    |   25 +-
 framework/private/mock/bundle_mock.c            |   13 +-
 framework/private/mock/framework_mock.c         |    6 +-
 framework/private/src/bundle_archive.c          |    2 +-
 framework/private/src/framework.c               |   53 +-
 framework/private/src/service_registration.c    |    6 +-
 framework/private/test/bundle_context_test.cpp  |   75 +-
 .../private/src/endpoint_discovery_poller.c     |  116 +-
 .../private/src/endpoint_discovery_server.c     |    3 +-
 .../discovery_etcd/private/src/discovery_impl.c |    1 -
 .../discovery_etcd/private/src/etcd_watcher.c   |   11 +-
 .../private/src/import_registration_impl.c      |    4 +-
 .../private/src/remote_proxy_factory_impl.c     |    6 +
 .../private/src/remote_service_admin_impl.c     |    5 +-
 .../topology_manager/private/src/activator.c    |    8 +-
 shell/private/src/help_command.c                |    2 +
 shell/private/src/inspect_command.c             |    6 +-
 shell/private/src/update_command.c              |    2 +-
 utils/CMakeLists.txt                            |   44 +-
 utils/private/src/hash_map.c                    |   57 +-
 utils/private/src/linked_list.c                 |    2 +-
 utils/private/test/array_list_test.c            |  357 -----
 utils/private/test/array_list_test.cpp          |  500 +++++-
 utils/private/test/celix_threads_test.cpp       |  346 ++++
 utils/private/test/hash_map_test.c              |  478 ------
 utils/private/test/hash_map_test.cpp            | 1492 ++++++++++++++++++
 utils/private/test/hash_map_test_hash.c         |  359 -----
 utils/private/test/linked_list_test.c           |   96 --
 utils/private/test/linked_list_test.cpp         |  794 ++++++++++
 utils/public/include/celix_threads.h            |    2 +-
 utils/public/include/hash_map.h                 |    4 +-
 utils/public/include/linked_list.h              |    2 +-
 35 files changed, 3403 insertions(+), 1564 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/119bb950/.travis.yml
----------------------------------------------------------------------
diff --cc .travis.yml
index 3a3cfb7,1814464..3ecdf5c
--- a/.travis.yml
+++ b/.travis.yml
@@@ -9,21 -9,15 +9,21 @@@ matrix
      - compiler: gcc
      - compiler: clang
  
 -before_script: 
 -    - wget https://github.com/cpputest/cpputest.github.io/blob/master/releases/cpputest-3.7.1.tar.gz?raw=true -O /tmp/cpputest.tar.gz
 -    - tar -xzvf /tmp/cpputest.tar.gz -C /tmp 
 -    - if [ "$CC" = "clang" ]; then export CXX="clang++"; fi && cd /tmp/cpputest-3.7.1 && ./configure --prefix=$HOME/cpputest && make && make install && cd -
 +before_script:  
 +    - git clone -b 3.7.2 --single-branch https://github.com/cpputest/cpputest.git cpputest-build
 +    - cd cpputest-build
 +    - cmake . && make
 +    - sudo make install 
 +    - cd ..
 +    - git clone -b 2.7 --single-branch https://github.com/akheron/jansson.git jansson-build
 +    - cd jansson-build
 +    - cmake -DJANSSON_BUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=/usr . && make
 +    - sudo make install
 +    - cd ..
      - mkdir build install
 -
 -script: 
      - cd build
 -    - cmake -DBUILD_DEPLOYMENT_ADMIN=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=ON -DBUILD_UTILS-TESTS=ON -DCPPUTEST_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_LIBRARY=$HOME/cpputest/lib/libCppUTest.a -DCPPUTEST_EXT_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_EXT_LIBRARY=$HOME/cpputest/lib/libCppUTestExt.a -DCMAKE_INSTALL_PREFIX=../install ..
 -    - make all && make deploy && make install-all
 -    - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/utils && ./utils/array_list_test && ./utils/celix_threads_test && ./utils/linked_list_test && ./utils/hash_map_test 
 +    - cmake -DENABLE_TESTING=ON -DCMAKE_SKIP_BUILD_RPATH=TRUE -DBUILD_DEPLOYMENT_ADMIN=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 -DCMAKE_INSTALL_PREFIX=../install ..
  
 +script: 
 +    - make all 
-     - make test ARGS="-V"
++    - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/utils && make test ARGS="-V"

http://git-wip-us.apache.org/repos/asf/celix/blob/119bb950/framework/CMakeLists.txt
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/celix/blob/119bb950/framework/private/src/framework.c
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/celix/blob/119bb950/framework/private/src/service_registration.c
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/celix/blob/119bb950/remote_services/discovery/private/src/endpoint_discovery_poller.c
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/celix/blob/119bb950/remote_services/remote_service_admin/private/src/import_registration_impl.c
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/celix/blob/119bb950/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/celix/blob/119bb950/utils/CMakeLists.txt
----------------------------------------------------------------------
diff --cc utils/CMakeLists.txt
index 859e8a5,c786e96..ce0811e
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@@ -52,7 -53,8 +53,8 @@@ if (UTILS
      INSTALL(FILES ${files} DESTINATION include/celix COMPONENT framework)
      
      celix_subproject(UTILS-TESTS "Option to build the utilities library tests" "OFF")
++
      if (UTILS-TESTS)
 -		
      	find_package(CppUTest REQUIRED)
  
  	    include_directories(${CUNIT_INCLUDE_DIRS})


[47/50] [abbrv] celix git commit: CELIX-237: Added extra test

Posted by pn...@apache.org.
CELIX-237: Added extra test


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

Branch: refs/heads/develop
Commit: 6494ec29b61df6e69cd3608eadc841ab0292e96c
Parents: 119bb95
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Mon Oct 12 12:04:36 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon Oct 12 12:04:36 2015 +0200

----------------------------------------------------------------------
 launcher/private/src/main.c                                 | 9 ++++++++-
 .../dynamic_function_interface_tst/dyn_type_tests.cpp       | 5 +++--
 2 files changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/6494ec29/launcher/private/src/main.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/main.c b/launcher/private/src/main.c
index ec72d03..8998e44 100644
--- a/launcher/private/src/main.c
+++ b/launcher/private/src/main.c
@@ -32,6 +32,7 @@
 
 static void show_usage(char* prog_name);
 static void shutdown_framework(int signal);
+static void ignore(int signal);
 
 #define DEFAULT_CONFIG_FILE "config.properties"
 
@@ -62,6 +63,8 @@ int main(int argc, char *argv[]) {
 
     // Set signal handler
     (void) signal(SIGINT, shutdown_framework);
+    (void) signal(SIGUSR1, ignore);
+    (void) signal(SIGUSR2, ignore);
 
     int rc = celixLauncher_launch(config_file, &framework);
     if (rc == 0) {
@@ -78,4 +81,8 @@ static void shutdown_framework(int signal) {
     if (framework != NULL) {
         celixLauncher_stop(framework); //NOTE main thread will destroy
     }
-}
\ No newline at end of file
+}
+
+static void ignore(int signal) {
+    //ignoring for signal SIGUSR1, SIGUSR2. Can be used on threads
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/6494ec29/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
index 57db391..e2fe950 100644
--- 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
@@ -5,7 +5,6 @@
 #include "CppUTest/CommandLineTestRunner.h"                                                                                                                                                                        
 
 extern "C" {
-    #include <string.h>
     #include <stdarg.h>
     
     #include "dyn_common.h"
@@ -44,7 +43,7 @@ extern "C" {
         }
 
         FILE *stream = fopen("/dev/null", "w");
-        dynType_print(type, stream);
+        dynType_print(type, stdout);
         fclose(stream);
         dynType_destroy(type);
         //printf("--\n\n");
@@ -72,6 +71,7 @@ TEST_GROUP(DynTypeTests) {
 #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) { \
@@ -93,6 +93,7 @@ CREATE_EXAMPLES_TEST(EX12)
 CREATE_EXAMPLES_TEST(EX13)
 CREATE_EXAMPLES_TEST(EX14)
 CREATE_EXAMPLES_TEST(EX15)
+CREATE_EXAMPLES_TEST(EX16)
 
 TEST(DynTypeTests, ParseRandomGarbageTest) {
     /*


[29/50] [abbrv] celix git commit: CELIX-237: added test for json_rpc

Posted by pn...@apache.org.
CELIX-237: added test for json_rpc


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

Branch: refs/heads/develop
Commit: c0d4f75af7601b51de346aed118b01b003411a9b
Parents: 837926e
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Thu Sep 3 16:19:24 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Thu Sep 3 16:19:24 2015 +0200

----------------------------------------------------------------------
 .../dynamic_function_interface/json_rpc.c       |  3 +-
 .../json_rpc_tests.cpp                          | 61 ++++++++++++++++++--
 2 files changed, 57 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/c0d4f75a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
index 8a2f15c..5b49f2b 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
@@ -216,6 +216,7 @@ int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void *args[]
         if (argMeta == NULL) {
             //skip
         } else if (strcmp(argMeta, "pre") == 0) {
+            LOG_DEBUG("found pre argument at %i", i);
             dyn_type *subType = NULL;
             dynType_typedPointer_getTypedType(argType, &subType);
             void *tmp = NULL;
@@ -226,7 +227,7 @@ int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void *args[]
             dynType_free(subType, tmp);
         } else if (strcmp(argMeta, "out") == 0) {
             assert(false); //TODO
-        } 
+        }
     }
 
     json_decref(replyJson);

http://git-wip-us.apache.org/repos/asf/celix/blob/c0d4f75a/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
index 52b7386..60b028f 100644
--- 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
@@ -28,34 +28,83 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
 }
 
 
+    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 handleTest(void) {
         dyn_function_type *dynFunc = NULL;
-        int rc = dynFunction_parseWithStr("add(#at=h;PDD#at=pa;*D)N", NULL, &dynFunc);
+        int rc = dynFunction_parseWithStr("add(#am=handle;PDD#am=pre;*D)N", NULL, &dynFunc);
         CHECK_EQUAL(0, rc);
 
-        //TODO jsonRpc_handleReply(dynFunc, )
+        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);
     }
 
-    void prepareTest(void) {
 
+    void callTest(void) {
+        //TODO
     }
 
 }
 
 TEST_GROUP(JsonRpcTests) {
     void setup() {
-        int lvl = 1;
+        int lvl = 4;
         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, handleTest) {
     handleTest();
 }
 
-TEST(JsonRpcTests, prepareTest) {
-    prepareTest();
+TEST(JsonRpcTests, call) {
+    callTest();
 }
 
+


[10/50] [abbrv] celix git commit: CELIX-237: A lot of work on the rsa dfi bundle and some needed refactoring for the remote_service_admin setup to support an non proxy approach.

Posted by pn...@apache.org.
CELIX-237: A lot of work on the rsa dfi bundle and some needed refactoring for the remote_service_admin setup to support an non proxy approach.

- Fixed issue in launcher (cleared curl to soon)
- update service registry/registration so that error status for the factory will be returned.
- Fixed issue in log_factory, concerning a wrong assumption of the provided struct.
- Added rpath for the launcher. Have to see if this works with install, but for now this make running deployment from ide (clion) possible.
    Just set the workdir to the deploy location and use celix as executable
- Removed schema properties from calculator example
- Created a generic export/import_registration header for the (OSGi) generic api
- Moved some export/import_registration/reference code the import/export_registration source files
- Small updated to dfi for additional getters
- Updated rsa_dfi. rsa_dfi now creates a proxy based on dfi and also dfi for export
- Added rsa_dfi cpputest

Note: Still alot of work is needed in the dfi. Also rsa etcd deployment has problem. shm not tested, cfg works fine.


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

Branch: refs/heads/develop
Commit: da86474fb187707d8443a3aeb30ac965b74b1d43
Parents: 55e75be
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Aug 7 16:19:05 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Fri Aug 7 16:19:05 2015 +0200

----------------------------------------------------------------------
 framework/private/src/service_registration.c    |    5 +-
 framework/private/src/service_registry.c        |    2 +-
 launcher/CMakeLists.txt                         |    4 +
 launcher/private/src/launcher.c                 |   29 +-
 log_service/private/src/log_factory.c           |    2 +-
 .../examples/calculator_service/CMakeLists.txt  |    5 +-
 ....apache.celix.calc.api.Calculator.descriptor |   11 +
 .../private/src/calculator_activator.c          |    1 -
 .../public/include/calculator_service.h         |   25 -
 remote_services/examples/deploy.cmake           |   40 +-
 .../private/include/export_registration_impl.h  |    3 -
 .../private/include/remote_service_admin_impl.h |   17 -
 .../private/src/export_registration_impl.c      |   22 +-
 .../private/src/import_registration_impl.c      |   17 +
 .../public/include/export_registration.h        |   22 +
 .../public/include/import_registration.h        |   22 +
 .../public/include/remote_service_admin.h       |    6 +-
 .../remote_service_admin_dfi/CMakeLists.txt     |   21 +-
 .../dynamic_function_interface/CMakeLists.txt   |   10 +-
 .../dynamic_function_interface/dyn_function.c   |   31 +-
 .../dynamic_function_interface/dyn_function.h   |    5 +-
 .../dynamic_function_interface/dyn_interface.c  |   22 +
 .../dynamic_function_interface/dyn_interface.h  |    9 +-
 .../dynamic_function_interface/dyn_type.c       |    2 +
 .../json_serializer.c                           |   21 +-
 .../json_serializer.h                           |    3 +
 .../tst/dyn_function_tests.cpp                  |   29 +
 .../tst/dyn_interface_tests.cpp                 |   10 +-
 .../private/include/export_registration_dfi.h   |   21 +
 .../private/include/import_registration_dfi.h   |   20 +
 .../include/remote_service_admin_http_impl.h    |   23 +-
 .../private/src/export_registration_dfi.c       |  159 +++
 .../private/src/import_registration_dfi.c       |  231 ++++
 .../src/remote_service_admin_activator.c        |    4 +-
 .../private/src/remote_service_admin_dfi.c      |  783 +++++++++++++
 .../private/src/remote_service_admin_impl.c     | 1085 ------------------
 .../remote_service_admin_dfi/tst/CMakeLists.txt |   18 +-
 .../tst/config.properties.in                    |    3 +-
 .../remote_service_admin_dfi/tst/rsa_tests.cpp  |  182 ++-
 .../private/src/remote_service_admin_impl.c     |  129 +--
 .../private/src/remote_service_admin_impl.c     |   26 +-
 41 files changed, 1734 insertions(+), 1346 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/framework/private/src/service_registration.c
----------------------------------------------------------------------
diff --git a/framework/private/src/service_registration.c b/framework/private/src/service_registration.c
index 8e84d1a..c7eb010 100644
--- a/framework/private/src/service_registration.c
+++ b/framework/private/src/service_registration.c
@@ -146,13 +146,14 @@ celix_status_t serviceRegistration_unregister(service_registration_pt registrati
 }
 
 celix_status_t serviceRegistration_getService(service_registration_pt registration, bundle_pt bundle, void **service) {
+	int status = CELIX_SUCCESS;
     if (registration->isServiceFactory) {
         service_factory_pt factory = registration->serviceFactory;
-        factory->getService(registration->serviceFactory, bundle, registration, service);
+        status = factory->getService(factory->factory, bundle, registration, service);
     } else {
         (*service) = registration->svcObj;
     }
-    return CELIX_SUCCESS;
+    return status;
 }
 
 celix_status_t serviceRegistration_ungetService(service_registration_pt registration, bundle_pt bundle, void **service) {

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/framework/private/src/service_registry.c
----------------------------------------------------------------------
diff --git a/framework/private/src/service_registry.c b/framework/private/src/service_registry.c
index 85639b4..ca1641b 100644
--- a/framework/private/src/service_registry.c
+++ b/framework/private/src/service_registry.c
@@ -502,7 +502,7 @@ celix_status_t serviceRegistry_getService(service_registry_pt registry, bundle_p
 	celixThreadMutex_unlock(&registry->mutex);
 
 	if ((usage != NULL) && (*service == NULL)) {
-		serviceRegistration_getService(registration, bundle, service);
+		status = serviceRegistration_getService(registration, bundle, service);
 	}
 	celixThreadMutex_lock(&registry->mutex);
 	if ((!serviceRegistration_isValid(registration)) || (*service == NULL)) {

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/launcher/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index 6001eaf..dac0ce7 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -18,6 +18,10 @@ celix_subproject(LAUNCHER "Option to build the launcher" "ON" DEPS UTILS FRAMEWO
 if (LAUNCHER) 
     find_package(CURL REQUIRED)
 
+    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")
+
     include_directories(public/include)
     
     add_executable(celix

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/launcher/private/src/launcher.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/launcher.c b/launcher/private/src/launcher.c
index 432c709..a6297a0 100644
--- a/launcher/private/src/launcher.c
+++ b/launcher/private/src/launcher.c
@@ -113,7 +113,6 @@ int celixLauncher_launchWithStream(FILE *stream, framework_pt *framework) {
                 char *save_ptr = NULL;
                 linked_list_pt bundles;
                 array_list_pt installed = NULL;
-                bundle_pt bundle = NULL;
                 bundle_context_pt context = NULL;
                 linked_list_iterator_pt iter = NULL;
                 unsigned int i;
@@ -128,8 +127,7 @@ int celixLauncher_launchWithStream(FILE *stream, framework_pt *framework) {
                 // First install all bundles
                 // Afterwards start them
                 arrayList_create(&installed);
-                framework_getFrameworkBundle(*framework, &bundle);
-                bundle_getContext(bundle, &context);
+                bundle_getContext(fwBundle, &context);
                 iter = linkedListIterator_create(bundles, 0);
                 while (linkedListIterator_hasNext(iter)) {
                     bundle_pt current = NULL;
@@ -159,18 +157,7 @@ int celixLauncher_launchWithStream(FILE *stream, framework_pt *framework) {
             printf("Problem creating framework\n");
         }
 
-#ifdef WITH_APR
-	apr_pool_destroy(memoryPool);
-	apr_terminate();
-#endif
-
-
-#ifndef CELIX_NO_CURLINIT
-        // Cleanup Curl
-        curl_global_cleanup();
-#endif
-
-        printf("Launcher: Exit\n");
+        printf("Launcher: Framework Started\n");
     }
 
     return status;
@@ -182,6 +169,18 @@ void celixLauncher_waitForShutdown(framework_pt framework) {
 
 void celixLauncher_destroy(framework_pt framework) {
     framework_destroy(framework);
+
+    #ifdef WITH_APR
+        apr_pool_destroy(memoryPool);
+        apr_terminate();
+    #endif
+
+    #ifndef CELIX_NO_CURLINIT
+        // Cleanup Curl
+        curl_global_cleanup();
+    #endif
+
+    printf("Launcher: Exit\n");
 }
 
 void celixLauncher_stop(framework_pt framework) {

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/log_service/private/src/log_factory.c
----------------------------------------------------------------------
diff --git a/log_service/private/src/log_factory.c b/log_service/private/src/log_factory.c
index 7ea5b2f..d188044 100644
--- a/log_service/private/src/log_factory.c
+++ b/log_service/private/src/log_factory.c
@@ -72,7 +72,7 @@ celix_status_t logFactory_destroy(service_factory_pt *factory) {
 
 
 celix_status_t logFactory_getService(void *factory, bundle_pt bundle, service_registration_pt registration, void **service) {
-    log_service_factory_pt log_factory = ((service_factory_pt) factory)->factory;
+    log_service_factory_pt log_factory = factory;
     log_service_pt log_service = NULL;
     log_service_data_pt log_service_data = NULL;
 

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/examples/calculator_service/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/CMakeLists.txt b/remote_services/examples/calculator_service/CMakeLists.txt
index e17153e..91596ab 100644
--- a/remote_services/examples/calculator_service/CMakeLists.txt
+++ b/remote_services/examples/calculator_service/CMakeLists.txt
@@ -24,11 +24,14 @@ include_directories("public/include")
 SET(BUNDLE_SYMBOLICNAME "apache_celix_remoting_calculator_impl")
 SET(BUNDLE_VERSION "0.0.1")
 
-bundle(calculator SOURCES 
+    bundle(calculator SOURCES
 	private/src/calculator_impl
 	private/src/calculator_activator
     
     private/include/calculator_impl.h
+
+    FILES
+        org.apache.celix.calc.api.Calculator.descriptor
 )
 
 target_link_libraries(calculator celix_framework)

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/examples/calculator_service/org.apache.celix.calc.api.Calculator.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/org.apache.celix.calc.api.Calculator.descriptor b/remote_services/examples/calculator_service/org.apache.celix.calc.api.Calculator.descriptor
new file mode 100644
index 0000000..711df0b
--- /dev/null
+++ b/remote_services/examples/calculator_service/org.apache.celix.calc.api.Calculator.descriptor
@@ -0,0 +1,11 @@
+:header
+type=interface
+name=calculator
+version=1.0.0
+:annotations
+classname=org.example.Calculator
+:types
+:methods
+add(DD)D=add(PDD*D)N
+sub(DD)D=sub(PDD*D)N
+sqrt(D)D=sqrt(PD*D)N

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/examples/calculator_service/private/src/calculator_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/private/src/calculator_activator.c b/remote_services/examples/calculator_service/private/src/calculator_activator.c
index a4dfa46..13ea995 100644
--- a/remote_services/examples/calculator_service/private/src/calculator_activator.c
+++ b/remote_services/examples/calculator_service/private/src/calculator_activator.c
@@ -75,7 +75,6 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
 
 			properties = properties_create();
 			properties_set(properties, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, (char *) CALCULATOR_SERVICE);
-      properties_set(properties, (char *) "protocol.schema", (char *)CALC_SCHEMA);
 
                         bundleContext_registerService(context, (char *) CALCULATOR_SERVICE, activator->service, properties, &activator->calculatorReg);
 

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/examples/calculator_service/public/include/calculator_service.h
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/public/include/calculator_service.h b/remote_services/examples/calculator_service/public/include/calculator_service.h
index 964653e..8e2f0dc 100644
--- a/remote_services/examples/calculator_service/public/include/calculator_service.h
+++ b/remote_services/examples/calculator_service/public/include/calculator_service.h
@@ -35,31 +35,6 @@ typedef struct calculator *calculator_pt;
 
 typedef struct calculator_service *calculator_service_pt;
 
-#define CALC_SCHEMA "[\"add(DD)D\",\"sub(DD)D\",\"sqrt(D)D\"]"
-
-/*
-purpose different schema setup
-{
-  "methods" : [ "add(DD)D", "sub(DD)D", "sqrt(D)D", abc(Labc_input;)D", sum([D)D" ],
-  "types" : {
-    "abc_input" : "DDD a b c"
-  }
-} 
-
-struct abc_input {
-    double a;
-    double b;
-    double c;
-}
-
-//for [D the following struct layout will be assumed
-struct double_sequence {
-    size_t _max;
-    size_t _length;
-    double *buffer;
-};
-*/
-
 /*
  * The calculator service definition corresponds to the following Java interface:
  *

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/examples/deploy.cmake
----------------------------------------------------------------------
diff --git a/remote_services/examples/deploy.cmake b/remote_services/examples/deploy.cmake
index 0b17811..0515917 100644
--- a/remote_services/examples/deploy.cmake
+++ b/remote_services/examples/deploy.cmake
@@ -16,10 +16,44 @@
 # under the License.
 is_enabled(RSA_EXAMPLES)
 if (RSA_EXAMPLES)
+    is_enabled(RSA_REMOTE_SERVICE_ADMIN_HTTP)
+    if (RSA_REMOTE_SERVICE_ADMIN_HTTP)
+        is_enabled(RSA_DISCOVERY_CONFIGURED)
+        if (RSA_DISCOVERY_CONFIGURED)
+            deploy("remote-services-cfg" BUNDLES discovery_configured topology_manager remote_service_admin_http calculator shell shell_tui log_service log_writer
+                                         ENDPOINTS
+                                            org.apache.celix.calc.api.Calculator_endpoint
+                                            org.apache.celix.calc.api.Calculator2_endpoint
+                                         PROPERTIES
+                                            RSA_PORT=8001
+                                            DISCOVERY_CFG_POLL_ENDPOINTS=http://localhost:8082/org.apache.celix.discovery.configured
+                                            DISCOVERY_CFG_SERVER_PORT=8081)
+            deploy("remote-services-cfg-client" BUNDLES topology_manager remote_service_admin_http shell shell_tui log_service log_writer calculator_shell discovery_configured
+                                                ENDPOINTS org.apache.celix.calc.api.Calculator_proxy org.apache.celix.calc.api.Calculator2_proxy
+                                            PROPERTIES
+                                                RSA_PORT=8002
+                                                DISCOVERY_CFG_POLL_ENDPOINTS=http://localhost:8081/org.apache.celix.discovery.configured
+                                                DISCOVERY_CFG_SERVER_PORT=8082)
+        endif ()
+    endif ()
+
+    is_enabled(RSA_REMOTE_SERVICE_ADMIN_SHM)
+    if (RSA_REMOTE_SERVICE_ADMIN_SHM)
+        is_enabled(RSA_DISCOVERY_SHM)
+        if (RSA_DISCOVERY_SHM)
+            deploy("remote-services-shm" BUNDLES discovery_shm topology_manager remote_service_admin_shm calculator shell shell_tui log_service log_writer
+                                         ENDPOINTS org.apache.celix.calc.api.Calculator_endpoint)
+            deploy("remote-services-shm-client" BUNDLES topology_manager remote_service_admin_shm shell shell_tui log_service log_writer calculator_shell discovery_shm
+                                                ENDPOINTS org.apache.celix.calc.api.Calculator_proxy)
+        endif ()
+    endif ()
+
     is_enabled(RSA_DISCOVERY_ETCD)
     if (RSA_DISCOVERY_ETCD)
-        deploy("remote-services-etcd" BUNDLES discovery_etcd topology_manager remote_service_admin_http calculator shell shell_tui log_service log_writer)
-        deploy("remote-services-etcd-client" BUNDLES topology_manager remote_service_admin_http shell shell_tui log_service log_writer calculator_shell discovery_etcd)
+        deploy("remote-services-etcd" BUNDLES discovery_etcd topology_manager remote_service_admin_http calculator shell shell_tui log_service log_writer
+                                     ENDPOINTS org.apache.celix.calc.api.Calculator_endpoint)
+        deploy("remote-services-etcd-client" BUNDLES topology_manager remote_service_admin_http shell shell_tui log_service log_writer calculator_shell discovery_etcd
+                                            ENDPOINTS org.apache.celix.calc.api.Calculator_proxy)
     endif ()
 
-endif (RSA_EXAMPLES)
+endif (RSA_EXAMPLES)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/remote_service_admin/private/include/export_registration_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/private/include/export_registration_impl.h b/remote_services/remote_service_admin/private/include/export_registration_impl.h
index ed38684..bb276f9 100644
--- a/remote_services/remote_service_admin/private/include/export_registration_impl.h
+++ b/remote_services/remote_service_admin/private/include/export_registration_impl.h
@@ -53,9 +53,6 @@ struct export_registration {
 celix_status_t exportRegistration_create(log_helper_pt helper, service_reference_pt reference, endpoint_description_pt endpoint, remote_service_admin_pt rsa, bundle_context_pt context, export_registration_pt *registration);
 celix_status_t exportRegistration_destroy(export_registration_pt *registration);
 celix_status_t exportRegistration_open(export_registration_pt registration);
-celix_status_t exportRegistration_close(export_registration_pt registration);
-celix_status_t exportRegistration_getException(export_registration_pt registration);
-celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *reference);
 
 celix_status_t exportRegistration_setEndpointDescription(export_registration_pt registration, endpoint_description_pt endpointDescription);
 celix_status_t exportRegistration_startTracking(export_registration_pt registration);

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h b/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
index 10b012e..b28757b 100644
--- a/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
+++ b/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
@@ -32,16 +32,6 @@
 #define BUNDLE_STORE_PROPERTY_NAME "ENDPOINTS"
 #define DEFAULT_BUNDLE_STORE "endpoints"
 
-struct export_reference {
-	endpoint_description_pt endpoint;
-	service_reference_pt reference;
-};
-
-struct import_reference {
-	endpoint_description_pt endpoint;
-	service_reference_pt reference;
-};
-
 celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin);
 celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin);
 
@@ -54,13 +44,6 @@ celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt a
 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_IMPL_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/remote_service_admin/private/src/export_registration_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/private/src/export_registration_impl.c b/remote_services/remote_service_admin/private/src/export_registration_impl.c
index d6ce934..18cff6c 100644
--- a/remote_services/remote_service_admin/private/src/export_registration_impl.c
+++ b/remote_services/remote_service_admin/private/src/export_registration_impl.c
@@ -32,6 +32,12 @@
 #include "export_registration_impl.h"
 #include "remote_service_admin_impl.h"
 
+
+struct export_reference {
+	endpoint_description_pt endpoint;
+	service_reference_pt reference;
+};
+
 celix_status_t exportRegistration_endpointAdding(void * handle, service_reference_pt reference, void **service);
 celix_status_t exportRegistration_endpointAdded(void * handle, service_reference_pt reference, void *service);
 celix_status_t exportRegistration_endpointModified(void * handle, service_reference_pt reference, void *service);
@@ -175,7 +181,6 @@ celix_status_t exportRegistration_endpointRemoved(void * handle, service_referen
 
 celix_status_t exportRegistration_open(export_registration_pt registration) {
 	celix_status_t status = CELIX_SUCCESS;
-  /*
 	char *bundleStore = NULL;
 
 	bundleContext_getProperty(registration->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore);
@@ -193,7 +198,6 @@ celix_status_t exportRegistration_open(export_registration_pt registration) {
 		if (status == CELIX_SUCCESS) {
 		}
 	}
-  */
 
 	return status;
 }
@@ -240,3 +244,17 @@ celix_status_t exportRegistration_setEndpointDescription(export_registration_pt
 
 	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/da86474f/remote_services/remote_service_admin/private/src/import_registration_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/private/src/import_registration_impl.c b/remote_services/remote_service_admin/private/src/import_registration_impl.c
index ecf6e09..a9eb70e 100644
--- a/remote_services/remote_service_admin/private/src/import_registration_impl.c
+++ b/remote_services/remote_service_admin/private/src/import_registration_impl.c
@@ -34,6 +34,12 @@
 #include "import_registration_impl.h"
 #include "remote_service_admin_impl.h"
 
+struct import_reference {
+	endpoint_description_pt endpoint;
+	service_reference_pt reference;
+};
+
+
 
 celix_status_t importRegistration_proxyFactoryAdding(void * handle, service_reference_pt reference, void **service);
 celix_status_t importRegistration_proxyFactoryAdded(void * handle, service_reference_pt reference, void *service);
@@ -254,3 +260,14 @@ celix_status_t importRegistration_getImportReference(import_registration_pt regi
 
 	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;
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/remote_service_admin/public/include/export_registration.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/public/include/export_registration.h b/remote_services/remote_service_admin/public/include/export_registration.h
new file mode 100644
index 0000000..9332274
--- /dev/null
+++ b/remote_services/remote_service_admin/public/include/export_registration.h
@@ -0,0 +1,22 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#ifndef CELIX_EXPORT_REGISTRATION_H
+#define CELIX_EXPORT_REGISTRATION_H
+
+#include "celix_errno.h"
+#include "endpoint_description.h"
+#include "service_reference.h"
+
+typedef struct export_registration *export_registration_pt;
+
+typedef struct export_reference *export_reference_pt;
+
+celix_status_t exportRegistration_close(export_registration_pt registration);
+celix_status_t exportRegistration_getException(export_registration_pt registration);
+celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *reference);
+
+celix_status_t exportReference_getExportedEndpoint(export_reference_pt reference, endpoint_description_pt *endpoint);
+celix_status_t exportReference_getExportedService(export_reference_pt reference);
+
+#endif //CELIX_EXPORT_REGISTRATION_H

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/remote_service_admin/public/include/import_registration.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/public/include/import_registration.h b/remote_services/remote_service_admin/public/include/import_registration.h
new file mode 100644
index 0000000..ef8193f
--- /dev/null
+++ b/remote_services/remote_service_admin/public/include/import_registration.h
@@ -0,0 +1,22 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#ifndef CELIX_IMPORT_REGISTRATION_H
+#define CELIX_IMPORT_REGISTRATION_H
+
+#include "celix_errno.h"
+#include "endpoint_description.h"
+#include "service_reference.h"
+
+typedef struct import_registration *import_registration_pt;
+
+typedef struct import_reference *import_reference_pt;
+
+celix_status_t importRegistration_close(import_registration_pt registration);
+celix_status_t importRegistration_getException(import_registration_pt registration);
+celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference);
+
+celix_status_t importReference_getImportedEndpoint(import_reference_pt reference);
+celix_status_t importReference_getImportedService(import_reference_pt reference);
+
+#endif //CELIX_IMPORT_REGISTRATION_H

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/remote_service_admin/public/include/remote_service_admin.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/public/include/remote_service_admin.h b/remote_services/remote_service_admin/public/include/remote_service_admin.h
index b5b42ae..274f2e4 100644
--- a/remote_services/remote_service_admin/public/include/remote_service_admin.h
+++ b/remote_services/remote_service_admin/public/include/remote_service_admin.h
@@ -29,13 +29,11 @@
 
 #include "endpoint_listener.h"
 #include "service_reference.h"
+#include "export_registration.h"
+#include "import_registration.h"
 
 #define OSGI_RSA_REMOTE_SERVICE_ADMIN "remote_service_admin"
 
-typedef struct export_reference *export_reference_pt;
-typedef struct export_registration *export_registration_pt;
-typedef struct import_reference *import_reference_pt;
-typedef struct import_registration *import_registration_pt;
 typedef struct import_registration_factory *import_registration_factory_pt;
 typedef struct remote_service_admin *remote_service_admin_pt;
 

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/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 3937605..b7a66f3 100644
--- a/remote_services/remote_service_admin_dfi/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/CMakeLists.txt
@@ -22,27 +22,38 @@ if (RSA_REMOTE_SERVICE_ADMIN_DFI)
 
     add_subdirectory(dynamic_function_interface)
 
+    include_directories(private/include)
+
     include_directories(${FFI_INCLUDE_DIRS})
     include_directories(${CURL_INCLUDE_DIRS})
     include_directories(${JANSSON_INCLUDE_DIRS})
+
     include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
+
     include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
+
     include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/private/include")
     include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/public/include")
+
     include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
-    include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/include")
     include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_http/private/include")
+
     include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
+    include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_dfi/dynamic_function_interface")
+    include_directories("${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include")
     
     SET_HEADER(BUNDLE_SYMBOLICNAME "apache_celix_remote_service_admin_dfi")
     SET(BUNDLE_VERSION "0.0.1")
     SET_HEADERS("Bundle-Name: Apache Celix Remote Service Admin HTTP for dynamic function interface")
     
     bundle(remote_service_admin_dfi SOURCES
-        private/src/remote_service_admin_impl
-        private/src/remote_service_admin_activator
-        ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/export_registration_impl
-        ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/import_registration_impl
+        private/src/remote_service_admin_dfi.c
+        private/src/remote_service_admin_activator.c
+        private/src/export_registration_dfi.c
+        private/src/import_registration_dfi.c
+
+        ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
+
         ${PROJECT_SOURCE_DIR}/remote_services/utils/private/src/civetweb.c
         ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
     )

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/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
index ae1d5c3..0dad5e1 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt
@@ -31,7 +31,7 @@ target_link_libraries(dfi ${FFI_LIBRARIES} ${JANSSON_LIBRARY})
 
 
 #if (FRAMEWORK_TESTS) TODO
-	add_executable(dfi_tests
+	add_executable(test_dfi
 	    tst/dyn_type_tests.cpp
 	    tst/dyn_function_tests.cpp
 	    tst/dyn_closure_tests.cpp
@@ -39,14 +39,14 @@ target_link_libraries(dfi ${FFI_LIBRARIES} ${JANSSON_LIBRARY})
 	    tst/json_serializer_tests.cpp
 	    tst/run_tests.cpp
 	)
-	target_link_libraries(dfi_tests dfi ${FFI_LIBRARIES} ${CPPUTEST_LIBRARY} ${JANSSON_LIBRARY}) 
+	target_link_libraries(test_dfi dfi ${FFI_LIBRARIES} ${CPPUTEST_LIBRARY} ${JANSSON_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(dfi_tests copy-input)
+	add_dependencies(test_dfi copy-input)
 
-    add_test(NAME run_dfi_tests COMMAND dfi_tests)
-	SETUP_TARGET_FOR_COVERAGE(dfi_tests_cov dfi_tests ${CMAKE_BINARY_DIR}/coverage/dfi)
+    add_test(NAME run_test_dfi COMMAND test_dfi)
+	SETUP_TARGET_FOR_COVERAGE(test_dfi_cov test_dfi ${CMAKE_BINARY_DIR}/coverage/dfi)
 #endif()

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/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
index 0ae2a8a..f80d26f 100644
--- 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
@@ -15,8 +15,6 @@
 #include "dyn_type.h"
 #include "dfi_log_util.h"
 
-DFI_SETUP_LOG(dynFunction)
-
 struct _dyn_function_type {
     char *name;
     struct types_head *refTypes; //NOTE not owned
@@ -45,6 +43,8 @@ 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); 
@@ -240,4 +240,31 @@ int dynFunction_getFnPointer(dyn_function_type *dynFunc, void (**fn)(void)) {
     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/da86474f/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
index 2d5d6bb..b1abfb6 100644
--- 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
@@ -15,13 +15,16 @@
  */
 
 typedef struct _dyn_function_type dyn_function_type;
-typedef struct _dyn_closure_type dyn_closure_type;
 
 DFI_SETUP_LOG_HEADER(dynFunction);
 
 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);
+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);
 

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/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
index 878cfea..5cd7104 100644
--- 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
@@ -12,6 +12,13 @@
 
 DFI_SETUP_LOG(dynInterface);
 
+struct _dyn_interface_type {
+    struct namvals_head header;
+    struct namvals_head annotations;
+    struct types_head types;
+    struct methods_head methods;
+};
+
 const int OK = 0;
 const int ERROR = 1;
 
@@ -369,3 +376,18 @@ static int dynInterface_getEntryForHead(struct namvals_head *head, const char *n
     }
     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/da86474f/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
index 0b0898f..f005bff 100644
--- 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
@@ -29,18 +29,11 @@ TAILQ_HEAD(methods_head, method_entry);
 
 typedef struct _dyn_interface_type dyn_interface_type;
 
-struct _dyn_interface_type {
-    struct namvals_head header;
-    struct namvals_head annotations;
-    struct types_head types;
-    struct methods_head methods;
-};
 
 struct method_entry {
     int index;
     char *id;
     char *name;
-
     dyn_function_type *dynFunc;
 
     TAILQ_ENTRY(method_entry) entries; 
@@ -53,6 +46,8 @@ 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/da86474f/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
index 2946607..c8a9adb 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
@@ -763,6 +763,8 @@ static ffi_type * dynType_ffiTypeFor(int c) {
             break;
         case 'P' :
             type = &ffi_type_pointer;
+        case 'V' :
+            type = &ffi_type_void;
             break;
     }
     return type;

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
index 614e948..c6bda91 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
@@ -9,7 +9,7 @@
 #include <stdint.h>
 #include <string.h>
 
-static int jsonSerializer_createObject(dyn_type *type, json_t *object, void **result);
+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);
@@ -34,12 +34,7 @@ int jsonSerializer_deserialize(dyn_type *type, const char *input, void **result)
     json_t *root = json_loads(input, JSON_DECODE_ANY, &error);
 
     if (root != NULL) {
-        if (json_is_object(root)) {
-            status = jsonSerializer_createObject(type, root, result);
-        } else {
-            status = ERROR;
-            LOG_ERROR("Error expected root element to be an object");
-        }
+        status = jsonSerializer_deserializeJson(type, root, result);
         json_decref(root);
     } else {
         status = ERROR;
@@ -49,8 +44,12 @@ int jsonSerializer_deserialize(dyn_type *type, const char *input, void **result)
     return status;
 }
 
-static int jsonSerializer_createObject(dyn_type *type, json_t *object, void **result) {
-    assert(object != NULL);
+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;
@@ -58,7 +57,7 @@ static int jsonSerializer_createObject(dyn_type *type, json_t *object, void **re
 
     if (status == OK) {
         assert(inst != NULL);
-        status = jsonSerializer_parseObject(type, object, inst);
+        status = jsonSerializer_parseAny(type, inst, val);
 
         if (status != OK) {
             dynType_free(type, inst);
@@ -189,7 +188,7 @@ static int jsonSerializer_parseAny(dyn_type *type, void *loc, json_t *val) {
         case '*' :
             status = dynType_typedPointer_getTypedType(type, &subType);
             if (status == OK) {
-                status = jsonSerializer_createObject(subType, val, (void **)loc);
+                status = jsonSerializer_createType(subType, val, (void **) loc);
             }
             break;
         case 'P' :

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/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
index eb2e629..abfdd03 100644
--- 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
@@ -4,6 +4,7 @@
 #ifndef __JSON_SERIALIZER_H_
 #define __JSON_SERIALIZER_H_
 
+#include <jansson.h>
 #include "dfi_log_util.h"
 #include "dyn_type.h"
 
@@ -11,6 +12,8 @@
 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);
 
 #endif

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/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
index 410b3ec..9b681de 100644
--- 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
@@ -96,6 +96,31 @@ extern "C" {
         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);
+    }
+
+
 }
 
 TEST_GROUP(DynFunctionTests) {
@@ -113,3 +138,7 @@ TEST(DynFunctionTests, DynFuncTest1) {
 TEST(DynFunctionTests, DynFuncTest2) {
     test_example2();
 }
+
+TEST(DynFunctionTests, DynFuncAccTest) {
+    test_access_functions();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/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
index 6453afd..679260f 100644
--- 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
@@ -57,7 +57,15 @@ extern "C" {
         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);
     }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/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
new file mode 100644
index 0000000..4faf9b9
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/private/include/export_registration_dfi.h
@@ -0,0 +1,21 @@
+/**
+ * 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);
+celix_status_t 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/da86474f/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
new file mode 100644
index 0000000..d05375d
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/private/include/import_registration_dfi.h
@@ -0,0 +1,20 @@
+/**
+ * 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>
+
+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_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/da86474f/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
index dbf71c9..65ca83b 100644
--- 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
@@ -27,7 +27,7 @@
 #ifndef REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
 #define REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
 
-#include "remote_service_admin_impl.h"
+#include "remote_service_admin.h"
 #include "log_helper.h"
 #include "civetweb.h"
 
@@ -47,6 +47,27 @@ struct remote_service_admin {
 	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/da86474f/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
new file mode 100644
index 0000000..7814d0d
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/private/src/export_registration_dfi.c
@@ -0,0 +1,159 @@
+/**
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#include <jansson.h>
+#include <dyn_interface.h>
+#include <json_serializer.h>
+#include "export_registration.h"
+#include "export_registration_dfi.h"
+#include "endpoint_description.h"
+
+struct export_registration {
+    endpoint_description_pt endpointDescription;
+    service_reference_pt reference;
+    dyn_interface_type *intf;
+    void *service;
+    bundle_pt bundle;
+
+    bool closed;
+};
+
+struct export_reference {
+    endpoint_description_pt endpoint;
+    service_reference_pt reference;
+};
+
+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 *registration) {
+    celix_status_t status = CELIX_SUCCESS;
+    //TODO
+    return status;
+}
+
+celix_status_t exportRegistration_call(export_registration_pt export, char *data, int datalength, char **response, 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);
+    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 {
+        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;
+    }
+
+    if (method != NULL) {
+
+        int nrOfArgs = dynFunction_nrOfArguments(method->dynFunc);
+        void *args[nrOfArgs + 1]; //arg 0 is handle
+        dyn_type *returnType = dynFunction_returnType(method->dynFunc);
+
+        json_t *arguments = json_object_get(js_request, "a");
+        json_t *value;
+        size_t index;
+        json_array_foreach(arguments, index, value) {
+            dyn_type *argType = dynFunction_argumentTypeForIndex(method->dynFunc, index + 1);
+            status = jsonSerializer_deserializeJson(argType, value, &(args[index + 1]));
+            index += 1;
+            if (status != 0) {
+                break;
+            }
+        }
+
+        json_decref(js_request);
+
+        struct generic_service_layout *serv = export->service;
+        args[0] = serv->handle;
+        void *returnVal = NULL;
+        dynType_alloc(returnType, &returnVal);
+        dynFunction_call(method->dynFunc, serv->methods[method->index], returnVal, args);
+
+        status = jsonSerializer_serialize(returnType, returnVal, response);
+        if (returnVal != NULL) {
+            dynType_free(returnType, returnVal);
+        }
+
+        ///TODO add more status checks
+    }
+
+    //TODO unlock/sema export
+    return status;
+}
+
+celix_status_t exportRegistration_destroy(export_registration_pt registration) {
+    celix_status_t status = CELIX_SUCCESS;
+    //TODO
+    return status;
+}
+
+celix_status_t exportRegistration_start(export_registration_pt registration) {
+    celix_status_t status = CELIX_SUCCESS;
+    //TODO
+    return status;
+}
+
+celix_status_t exportRegistration_stop(export_registration_pt registration) {
+    celix_status_t status = CELIX_SUCCESS;
+    //TODO
+    return status;
+}
+
+celix_status_t exportRegistration_close(export_registration_pt registration) {
+    celix_status_t status = CELIX_SUCCESS;
+    //TODO
+    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 *reference) {
+    celix_status_t status = CELIX_SUCCESS;
+    //TODO
+    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/da86474f/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
new file mode 100644
index 0000000..f8c544c
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/private/src/import_registration_dfi.c
@@ -0,0 +1,231 @@
+#include <malloc.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
+
+    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) {
+        *out = reg;
+    }
+
+    return status;
+}
+
+void importRegistration_destroy(import_registration_pt import) {
+    if (import != 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;
+    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 (status != CELIX_SUCCESS) {
+        printf("Cannot find entry '%s'\n", name);
+    }
+
+    struct service_proxy *proxy = NULL;
+    if (status == CELIX_SUCCESS) {
+        proxy = calloc(1, sizeof(*proxy));
+        if (proxy != NULL) {
+
+        } else {
+            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;
+            }
+        }
+    }
+
+    void **serv = NULL;
+    if (status == CELIX_SUCCESS) {
+        size_t count = dynInterface_nrOfMethods(proxy->intf);
+        serv = calloc(1 + count, sizeof(void *));
+        serv[0] = proxy;
+
+        struct methods_head *list = NULL;
+        dynInterface_methods(proxy->intf, &list);
+        struct method_entry *entry = NULL;
+        void (*fn)(void);
+        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) {
+        proxy->service = serv;
+    } else {
+        if (serv != NULL) {
+            free(serv);
+        }
+    }
+
+    if (status == CELIX_SUCCESS) {
+        *out = proxy;
+    }
+
+    return status;
+}
+
+static void importRegistration_proxyFunc(void *userData, void *args[], void *returnVal) {
+    struct method_entry *entry = userData;
+    //struct proxy_service *proxy = args[0];
+
+    printf("Calling function '%s'\n", entry->id);
+
+    //TODO
+}
+
+celix_status_t importRegistration_ungetService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **out) {
+    celix_status_t  status = CELIX_SUCCESS;
+    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/da86474f/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
index e4125fc..9961a9b 100644
--- 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
@@ -29,8 +29,8 @@
 #include "service_registration.h"
 
 #include "remote_service_admin_http_impl.h"
-#include "export_registration_impl.h"
-#include "import_registration_impl.h"
+#include "export_registration_dfi.h"
+#include "import_registration_dfi.h"
 
 struct activator {
 	remote_service_admin_pt admin;


[33/50] [abbrv] celix git commit: CELIX-237: remove commented line

Posted by pn...@apache.org.
CELIX-237: remove commented line


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

Branch: refs/heads/develop
Commit: 2c1746063cff09c60a58f28bc5f02fb1665f8447
Parents: fa785c5
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Sep 9 13:35:18 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Sep 9 13:35:18 2015 +0200

----------------------------------------------------------------------
 .../remote_service_admin_dfi/dynamic_function_interface/json_rpc.c  | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


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


[14/50] [abbrv] celix git commit: CELIX-237: fixed an issue in dfi export services and fixed an import.

Posted by pn...@apache.org.
CELIX-237: fixed an issue in dfi export services and fixed an import.

- Added dummy access to ptr in export_registration to force full mem initialization for modern unix (linux osx) systems
- remove incorrect ffi-x86.. import


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

Branch: refs/heads/develop
Commit: 4c4a5e9bd064e60b0d6d1569a4208d4c3276c669
Parents: 7dc2039
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Aug 11 20:52:58 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Aug 11 20:52:58 2015 +0200

----------------------------------------------------------------------
 .../dynamic_function_interface/dyn_function.c                | 8 --------
 .../private/src/export_registration_dfi.c                    | 6 ++++++
 2 files changed, 6 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/4c4a5e9b/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
index af3902c..0e12791 100644
--- 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
@@ -3,18 +3,10 @@
  */
 #include "dyn_function.h"
 
-#include <stdio.h>
-#include <stdarg.h>
 #include <strings.h>
-#include <string.h>
 #include <stdlib.h>
 
-#include <ffi.h>
-#include <ffi-x86_64.h>
-
 #include "dyn_common.h"
-#include "dyn_type.h"
-#include "dfi_log_util.h"
 
 struct _dyn_function_type {
     char *name;

http://git-wip-us.apache.org/repos/asf/celix/blob/4c4a5e9b/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
index 0713efb..74512d3 100644
--- 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
@@ -162,6 +162,12 @@ celix_status_t exportRegistration_call(export_registration_pt export, char *data
 
         void *out = NULL;
         dynType_alloc(lastType, &out); //TODO, NOTE only for simple types or single pointer types.. TODO check
+
+        //NOTE !! Need to access out, else it is a dummy pointer which will result in errors.
+        char b;
+        memcpy(&b, out, 1);
+
+        dynType_alloc(lastType, &out); //TODO, NOTE only for simple types or single pointer types.. TODO check
         printf("out ptr is %p value is %f\n", out, *(double *)out);
         args[nrOfArgs-1] = &out; //NOTE for simple type no double
 


[04/50] [abbrv] celix git commit: CELIX-237: initial setup for rsa dfi testing

Posted by pn...@apache.org.
CELIX-237: initial setup for rsa dfi testing


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

Branch: refs/heads/develop
Commit: 1e618fb14061a04d43174291dde729c928e76a3f
Parents: 2f56576
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Jul 31 21:45:10 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Fri Jul 31 21:45:10 2015 +0200

----------------------------------------------------------------------
 launcher/private/src/launcher.c                 | 19 +++++++++++-----
 launcher/private/src/main.c                     |  1 +
 launcher/public/include/launcher.h              |  3 +++
 .../remote_service_admin_dfi/tst/CMakeLists.txt | 23 ++++++++++++++++++++
 .../tst/config.properties.in                    |  1 +
 .../remote_service_admin_dfi/tst/run_tests.cpp  | 18 +++++++++++++++
 6 files changed, 60 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/1e618fb1/launcher/private/src/launcher.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/launcher.c b/launcher/private/src/launcher.c
index 6d09fc4..9292ffb 100644
--- a/launcher/private/src/launcher.c
+++ b/launcher/private/src/launcher.c
@@ -40,6 +40,8 @@
 static void launcher_shutdown(int signal);
 
 static struct framework * framework;
+static properties_pt config;
+
 #ifdef WITH_APR
 static apr_pool_t *memoryPool;
 #endif
@@ -60,7 +62,7 @@ int celixLauncher_launch(const char *configFile) {
 int celixLauncher_launchWithStream(FILE *stream) {
     int status = 0;
 
-    properties_pt config = properties_loadWithStream(stream);
+    config = properties_loadWithStream(stream);
     fclose(stream);
     // Make sure we've read it and that nothing went wrong with the file access...
     if (config == NULL) {
@@ -154,10 +156,6 @@ int celixLauncher_launchWithStream(FILE *stream) {
                 }
 
                 arrayList_destroy(installed);
-
-                framework_waitForStop(framework);
-                framework_destroy(framework);
-                properties_destroy(config);
             }
         }
 
@@ -179,6 +177,17 @@ int celixLauncher_launchWithStream(FILE *stream) {
     return status;
 }
 
+void celixLauncher_waitForShutdown(void) {
+    framework_waitForStop(framework);
+    framework_destroy(framework);
+    properties_destroy(config);
+}
+
+
+struct framework *celixLauncher_getFramework(void) {
+    return framework;
+}
+
 static void launcher_shutdown(int signal) {
     bundle_pt fwBundle = NULL;
     framework_getFrameworkBundle(framework, &fwBundle);

http://git-wip-us.apache.org/repos/asf/celix/blob/1e618fb1/launcher/private/src/main.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/main.c b/launcher/private/src/main.c
index 0a59bc4..b6d3033 100644
--- a/launcher/private/src/main.c
+++ b/launcher/private/src/main.c
@@ -55,6 +55,7 @@ int main(int argc, char *argv[]) {
     }
 
     celixLauncher_launch(config_file);
+    celixLauncher_waitForShutdown();
 }
 
 static void show_usage(char* prog_name) {

http://git-wip-us.apache.org/repos/asf/celix/blob/1e618fb1/launcher/public/include/launcher.h
----------------------------------------------------------------------
diff --git a/launcher/public/include/launcher.h b/launcher/public/include/launcher.h
index 296df7c..f95e160 100644
--- a/launcher/public/include/launcher.h
+++ b/launcher/public/include/launcher.h
@@ -28,8 +28,11 @@
 #define CELIX_LAUNCHER_H
 
 #include <stdio.h>
+#include "framework.h"
 
 int celixLauncher_launch(const char *configFile);
 int celixLauncher_launchWithStream(FILE *config);
+void celixLauncher_waitForShutdown(void);
+struct framework *celixLauncher_getFramework(void);
 
 #endif //CELIX_LAUNCHER_H

http://git-wip-us.apache.org/repos/asf/celix/blob/1e618fb1/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt b/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
new file mode 100644
index 0000000..fb1834a
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
@@ -0,0 +1,23 @@
+#
+# Licensed under Apache License v2. See LICENSE for more information.
+#
+
+include_directories(
+	${PROJECT_SOURCE_DIR}/launcher/public
+    ${CPPUTEST_INCLUDE_DIR}
+)
+
+
+#if (FRAMEWORK_TESTS) TODO
+	add_executable(rsa_dfi_tests
+		${PROJECT_SOURCE_DIR}/launcher/private/src/launcher
+	    tst/run_tests.cpp
+	)
+	target_link_libraries(rsa_dfi_tests ${CPPUTEST_LIBRARY}) #TODO add celix/launcer etc
+
+	get_property(rsa_bundle_file TARGET remote_service_admin_dfi PROPERTY BUNDLE)
+	configure_file(config.properties.in config-rsa.properties @ONLY)
+
+	add_test(NAME run_rsa_dfi_tests COMMAND rsa_dfi_tests)
+	SETUP_TARGET_FOR_COVERAGE(rsa_dfi_tests_cov rsa_dfi_tests ${CMAKE_BINARY_DIR}/coverage/rsa_dfi)
+#endif()

http://git-wip-us.apache.org/repos/asf/celix/blob/1e618fb1/remote_services/remote_service_admin_dfi/tst/config.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/config.properties.in b/remote_services/remote_service_admin_dfi/tst/config.properties.in
new file mode 100644
index 0000000..b926f36
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/tst/config.properties.in
@@ -0,0 +1 @@
+cosgi.auto.start.1=@rsa_bundle_file@
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/1e618fb1/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/run_tests.cpp b/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
new file mode 100644
index 0000000..b5f29e7
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
@@ -0,0 +1,18 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#include <CppUTest/TestHarness.h>
+#include "CppUTest/CommandLineTestRunner.h"
+
+#include <stdio.h>
+
+#include "launcher.h"
+
+
+int main(int argc, char** argv) {
+    celixLauncher_launch("config.properties");
+    int rc = RUN_ALL_TESTS(argc, argv);
+    framework_stop((celixLauncher_getFramework()));
+    celixLauncher_waitForShutdown();
+    return rc;
+}
\ No newline at end of file


[03/50] [abbrv] celix git commit: CELIX-237: Split launcher in a main.c and launcher.c/.h. Trying to reuse the launcher for cpputests

Posted by pn...@apache.org.
CELIX-237: Split launcher in a main.c and launcher.c/.h. Trying to reuse the launcher for cpputests


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

Branch: refs/heads/develop
Commit: 2f56576ae7f4bb006b8c22a776812dd0907abe6f
Parents: 3d7f764
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Jul 31 16:57:09 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Fri Jul 31 16:57:09 2015 +0200

----------------------------------------------------------------------
 framework/private/src/properties.c    |  13 +-
 framework/public/include/properties.h |   3 +
 launcher/CMakeLists.txt               |   6 +-
 launcher/private/src/launcher.c       | 225 ++++++++++++++---------------
 launcher/private/src/main.c           |  62 ++++++++
 launcher/public/include/launcher.h    |  35 +++++
 6 files changed, 220 insertions(+), 124 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/2f56576a/framework/private/src/properties.c
----------------------------------------------------------------------
diff --git a/framework/private/src/properties.c b/framework/private/src/properties.c
index 38ed214..14455c4 100644
--- a/framework/private/src/properties.c
+++ b/framework/private/src/properties.c
@@ -47,9 +47,14 @@ void properties_destroy(properties_pt properties) {
 }
 
 properties_pt properties_load(char *filename) {
-	properties_pt props = NULL;
-	FILE *file = fopen ( filename, "r" );
+	FILE *file = fopen(filename, "r");
+	properties_pt props = properties_loadWithStream(file);
+	fclose(file);
+	return props;
+}
 
+FRAMEWORK_EXPORT properties_pt properties_loadWithStream(FILE *file) {
+	properties_pt props = NULL;
 	char line[1024];
 	char key[1024];
 	char value[1024];
@@ -110,7 +115,7 @@ properties_pt properties_load(char *filename) {
 					}
 				} else if (line[linePos] == '\\') {
 					if (precedingCharIsBackslash) { //double backslash -> backslash
-							output[outputPos++] = '\\';
+						output[outputPos++] = '\\';
 					}
 					precedingCharIsBackslash = true;
 				} else { //normal character
@@ -128,8 +133,6 @@ properties_pt properties_load(char *filename) {
 				hashMap_put(props, strdup(utils_stringTrim(key)), strdup(utils_stringTrim(value)));
 			}
 		}
-
-		fclose(file);
 	}
 
 	return props;

http://git-wip-us.apache.org/repos/asf/celix/blob/2f56576a/framework/public/include/properties.h
----------------------------------------------------------------------
diff --git a/framework/public/include/properties.h b/framework/public/include/properties.h
index 36297a5..c4803cb 100644
--- a/framework/public/include/properties.h
+++ b/framework/public/include/properties.h
@@ -27,6 +27,8 @@
 #ifndef PROPERTIES_H_
 #define PROPERTIES_H_
 
+#include <stdio.h>
+
 #include "hash_map.h"
 #include "framework_exports.h"
 
@@ -35,6 +37,7 @@ typedef hash_map_pt properties_pt;
 FRAMEWORK_EXPORT properties_pt properties_create(void);
 FRAMEWORK_EXPORT void properties_destroy(properties_pt properties);
 FRAMEWORK_EXPORT properties_pt properties_load(char * filename);
+FRAMEWORK_EXPORT properties_pt properties_loadWithStream(FILE *stream);
 FRAMEWORK_EXPORT void properties_store(properties_pt properties, char * file, char * header);
 
 FRAMEWORK_EXPORT char * properties_get(properties_pt properties, char * key);

http://git-wip-us.apache.org/repos/asf/celix/blob/2f56576a/launcher/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index 27d1682..6001eaf 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -17,8 +17,12 @@
 celix_subproject(LAUNCHER "Option to build the launcher" "ON" DEPS UTILS FRAMEWORK)
 if (LAUNCHER) 
     find_package(CURL REQUIRED)
+
+    include_directories(public/include)
     
-    add_executable(celix private/src/launcher)
+    add_executable(celix
+        private/src/main
+        private/src/launcher)
     
     target_link_libraries(celix celix_framework ${CURL_LIBRARIES})
     include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")

http://git-wip-us.apache.org/repos/asf/celix/blob/2f56576a/launcher/private/src/launcher.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/launcher.c b/launcher/private/src/launcher.c
index f334057..6d09fc4 100644
--- a/launcher/private/src/launcher.c
+++ b/launcher/private/src/launcher.c
@@ -23,6 +23,9 @@
  *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
  *  \copyright	Apache License, Version 2.0
  */
+
+#include "launcher.h"
+
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -34,33 +37,48 @@
 #include "framework.h"
 #include "linked_list_iterator.h"
 
-#define DEFAULT_CONFIG_FILE "config.properties"
-
-void launcher_shutdown(int signal);
+static void launcher_shutdown(int signal);
 
-int running = 0;
-
-struct framework * framework;
+static struct framework * framework;
 #ifdef WITH_APR
-apr_pool_t *memoryPool;
+static apr_pool_t *memoryPool;
 #endif
 
-void show_usage(char* prog_name);
+int celixLauncher_launch(const char *configFile) {
+    int status = 0;
+    FILE *config = fopen(configFile, "r");
+    if (config != NULL) {
+        status = celixLauncher_launchWithStream(config);
+    } else {
+        fprintf(stderr, "Error: invalid or non-existing configuration file: '%s'.", configFile);
+        perror("");
+        status = 1;
+    }
+    return status;
+}
+
+int celixLauncher_launchWithStream(FILE *stream) {
+    int status = 0;
+
+    properties_pt config = properties_loadWithStream(stream);
+    fclose(stream);
+    // Make sure we've read it and that nothing went wrong with the file access...
+    if (config == NULL) {
+        fprintf(stderr, "Error: invalid configuration file");
+        perror(NULL);
+        status = 1;
+    }
 
-int main(int argc, char *argv[]) {
-	// Set signal handler
+    // Set signal handler
 #ifdef WITH_APR
     apr_status_t rv;
     apr_status_t s;
 #endif
-    properties_pt config = NULL;
-    char *autoStart = NULL;
-    bundle_pt fwBundle = NULL;
 
-	(void) signal(SIGINT, launcher_shutdown);
+    (void) signal(SIGINT, launcher_shutdown);
 
-	// Before doing anything else, let's setup Curl
-	curl_global_init(CURL_GLOBAL_NOTHING);
+    // Before doing anything else, let's setup Curl
+    curl_global_init(CURL_GLOBAL_NOTHING);
 
 #ifdef WITH_APR
 	rv = apr_initialize();
@@ -74,128 +92,99 @@ int main(int argc, char *argv[]) {
     }
 #endif
 
-	// Perform some minimal command-line option parsing...
-	char* opt = NULL;
-	if (argc > 1) {
-		opt = argv[1];
-	}
-
-	char* config_file = NULL;
-
-	if (opt) {
-		// Check whether the user wants some help...
-		if (strcmp("-h", opt) == 0 || strcmp("-help", opt) == 0) {
-			show_usage(argv[0]);
-			return 0;
-		} else {
-			config_file = opt;
-		}
-	} else {
-		config_file = DEFAULT_CONFIG_FILE;
-	}
-
-    config = properties_load(config_file);
-	// Make sure we've read it and that nothing went wrong with the file access...
-	if (config == NULL) {
-		printf("Error: invalid or non-existing configuration file: \"%s\"!\n", config_file);
-		perror(NULL);
-		show_usage(argv[0]);
-		return CELIX_START_ERROR;
-	}
-
-    autoStart = properties_get(config, "cosgi.auto.start.1");
-    framework = NULL;
-    celix_status_t status;
+
+    if (status == 0) {
+        char *autoStart = properties_get(config, "cosgi.auto.start.1");
+        framework = NULL;
+        celix_status_t status;
 #ifdef WITH_APR
-    status = framework_create(&framework, memoryPool, config);
+        status = framework_create(&framework, memoryPool, config);
 #else
-    status = framework_create(&framework, config);
+        status = framework_create(&framework, config);
 #endif
-    if (status == CELIX_SUCCESS) {
-		status = fw_init(framework);
-		if (status == CELIX_SUCCESS) {
-            // Start the system bundle
-            framework_getFrameworkBundle(framework, &fwBundle);
-            bundle_start(fwBundle);
-
-            char delims[] = " ";
-            char *result = NULL;
-            char *save_ptr = NULL;
-            linked_list_pt bundles;
-            array_list_pt installed = NULL;
-            bundle_pt bundle = NULL;
-            bundle_context_pt context = NULL;
-            linked_list_iterator_pt iter = NULL;
-            unsigned int i;
-
-            linkedList_create(&bundles);
-            result = strtok_r(autoStart, delims, &save_ptr);
-            while (result != NULL) {
-                char * location = strdup(result);
-                linkedList_addElement(bundles, location);
-                result = strtok_r(NULL, delims, &save_ptr);
-            }
-            // First install all bundles
-            // Afterwards start them
-            arrayList_create(&installed);
-            framework_getFrameworkBundle(framework, &bundle);
-            bundle_getContext(bundle, &context);
-            iter = linkedListIterator_create(bundles, 0);
-            while (linkedListIterator_hasNext(iter)) {
-                bundle_pt current = NULL;
-                char * location = (char *) linkedListIterator_next(iter);
-                if (bundleContext_installBundle(context, location, &current) == CELIX_SUCCESS) {
-                    // Only add bundle if it is installed correctly
-                    arrayList_add(installed, current);
-                } else {
-                    printf("Could not install bundle from %s\n", location);
+        bundle_pt fwBundle = NULL;
+        if (status == CELIX_SUCCESS) {
+            status = fw_init(framework);
+            if (status == CELIX_SUCCESS) {
+                // Start the system bundle
+                framework_getFrameworkBundle(framework, &fwBundle);
+                bundle_start(fwBundle);
+
+                char delims[] = " ";
+                char *result = NULL;
+                char *save_ptr = NULL;
+                linked_list_pt bundles;
+                array_list_pt installed = NULL;
+                bundle_pt bundle = NULL;
+                bundle_context_pt context = NULL;
+                linked_list_iterator_pt iter = NULL;
+                unsigned int i;
+
+                linkedList_create(&bundles);
+                result = strtok_r(autoStart, delims, &save_ptr);
+                while (result != NULL) {
+                    char *location = strdup(result);
+                    linkedList_addElement(bundles, location);
+                    result = strtok_r(NULL, delims, &save_ptr);
                 }
-                linkedListIterator_remove(iter);
-                free(location);
-            }
-            linkedListIterator_destroy(iter);
-            linkedList_destroy(bundles);
+                // First install all bundles
+                // Afterwards start them
+                arrayList_create(&installed);
+                framework_getFrameworkBundle(framework, &bundle);
+                bundle_getContext(bundle, &context);
+                iter = linkedListIterator_create(bundles, 0);
+                while (linkedListIterator_hasNext(iter)) {
+                    bundle_pt current = NULL;
+                    char *location = (char *) linkedListIterator_next(iter);
+                    if (bundleContext_installBundle(context, location, &current) == CELIX_SUCCESS) {
+                        // Only add bundle if it is installed correctly
+                        arrayList_add(installed, current);
+                    } else {
+                        printf("Could not install bundle from %s\n", location);
+                    }
+                    linkedListIterator_remove(iter);
+                    free(location);
+                }
+                linkedListIterator_destroy(iter);
+                linkedList_destroy(bundles);
 
-            for (i = 0; i < arrayList_size(installed); i++) {
-                bundle_pt installedBundle = (bundle_pt) arrayList_get(installed, i);
-                bundle_startWithOptions(installedBundle, 0);
-            }
+                for (i = 0; i < arrayList_size(installed); i++) {
+                    bundle_pt installedBundle = (bundle_pt) arrayList_get(installed, i);
+                    bundle_startWithOptions(installedBundle, 0);
+                }
 
-            arrayList_destroy(installed);
+                arrayList_destroy(installed);
 
-            framework_waitForStop(framework);
-            framework_destroy(framework);
-            properties_destroy(config);
-		}
-    }
+                framework_waitForStop(framework);
+                framework_destroy(framework);
+                properties_destroy(config);
+            }
+        }
 
-    if (status != CELIX_SUCCESS) {
-        printf("Problem creating framework\n");
-    }
+        if (status != CELIX_SUCCESS) {
+            printf("Problem creating framework\n");
+        }
 
 #ifdef WITH_APR
 	apr_pool_destroy(memoryPool);
 	apr_terminate();
 #endif
 
-	// Cleanup Curl
-	curl_global_cleanup();
+        // Cleanup Curl
+        curl_global_cleanup();
 
-	printf("Launcher: Exit\n");
+        printf("Launcher: Exit\n");
+    }
 
-    return 0;
+    return status;
 }
 
-void launcher_shutdown(int signal) {
-	bundle_pt fwBundle = NULL;
-	framework_getFrameworkBundle(framework, &fwBundle);
-	bundle_stop(fwBundle);
+static void launcher_shutdown(int signal) {
+    bundle_pt fwBundle = NULL;
+    framework_getFrameworkBundle(framework, &fwBundle);
+    bundle_stop(fwBundle);
 //	if (framework_waitForStop(framework) != CELIX_SUCCESS) {
 //		celix_log("Error waiting for stop.");
 //	}
 //	framework_destroy(framework);
 }
-
-void show_usage(char* prog_name) {
-	printf("Usage:\n  %s [path/to/config.properties]\n\n", basename(prog_name));
-}

http://git-wip-us.apache.org/repos/asf/celix/blob/2f56576a/launcher/private/src/main.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/main.c b/launcher/private/src/main.c
new file mode 100644
index 0000000..0a59bc4
--- /dev/null
+++ b/launcher/private/src/main.c
@@ -0,0 +1,62 @@
+/**
+ *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.
+ */
+/*
+ * main.c
+ *
+ *  \date       Jul 30, 2015
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+
+#include <string.h>
+#include <curl/curl.h>
+#include <signal.h>
+#include "launcher.h"
+
+static void show_usage(char* prog_name);
+
+#define DEFAULT_CONFIG_FILE "config.properties"
+
+int main(int argc, char *argv[]) {
+    // Perform some minimal command-line option parsing...
+    char *opt = NULL;
+    if (argc > 1) {
+        opt = argv[1];
+    }
+
+    char *config_file = NULL;
+
+    if (opt) {
+        // Check whether the user wants some help...
+        if (strcmp("-h", opt) == 0 || strcmp("-help", opt) == 0) {
+            show_usage(argv[0]);
+            return 0;
+        } else {
+            config_file = opt;
+        }
+    } else {
+        config_file = DEFAULT_CONFIG_FILE;
+    }
+
+    celixLauncher_launch(config_file);
+}
+
+static void show_usage(char* prog_name) {
+    printf("Usage:\n  %s [path/to/config.properties]\n\n", basename(prog_name));
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/2f56576a/launcher/public/include/launcher.h
----------------------------------------------------------------------
diff --git a/launcher/public/include/launcher.h b/launcher/public/include/launcher.h
new file mode 100644
index 0000000..296df7c
--- /dev/null
+++ b/launcher/public/include/launcher.h
@@ -0,0 +1,35 @@
+/**
+ *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.
+ */
+/*
+ * launcher.h
+ *
+ *  \date       Jul 30, 2015
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+
+#ifndef CELIX_LAUNCHER_H
+#define CELIX_LAUNCHER_H
+
+#include <stdio.h>
+
+int celixLauncher_launch(const char *configFile);
+int celixLauncher_launchWithStream(FILE *config);
+
+#endif //CELIX_LAUNCHER_H


[05/50] [abbrv] celix git commit: CELIX-237: Finished ccputest setup for testing the rsa dfi bundle. Cpputest uses the launcher to launch an embedded celix

Posted by pn...@apache.org.
CELIX-237: Finished ccputest setup for testing the rsa dfi bundle. Cpputest uses the launcher to launch an embedded celix


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

Branch: refs/heads/develop
Commit: 481e5c86114ecdd2bef5b2f5f6afdb32a6a6a537
Parents: 1e618fb
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Jul 31 22:56:02 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Fri Jul 31 22:56:02 2015 +0200

----------------------------------------------------------------------
 launcher/private/src/launcher.c                 |  9 +++--
 launcher/public/include/launcher.h              |  1 +
 .../remote_service_admin_dfi/CMakeLists.txt     |  4 ++-
 .../remote_service_admin_dfi/tst/CMakeLists.txt | 18 ++++++----
 .../remote_service_admin_dfi/tst/rsa_tests.cpp  | 36 ++++++++++++++++++++
 .../remote_service_admin_dfi/tst/run_tests.cpp  | 21 +++++++++---
 6 files changed, 74 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/481e5c86/launcher/private/src/launcher.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/launcher.c b/launcher/private/src/launcher.c
index 9292ffb..4f0f3de 100644
--- a/launcher/private/src/launcher.c
+++ b/launcher/private/src/launcher.c
@@ -183,15 +183,18 @@ void celixLauncher_waitForShutdown(void) {
     properties_destroy(config);
 }
 
+void celixLauncher_stop(void) {
+    bundle_pt fwBundle = NULL;
+    framework_getFrameworkBundle(framework, &fwBundle);
+    bundle_stop(fwBundle);
+}
 
 struct framework *celixLauncher_getFramework(void) {
     return framework;
 }
 
 static void launcher_shutdown(int signal) {
-    bundle_pt fwBundle = NULL;
-    framework_getFrameworkBundle(framework, &fwBundle);
-    bundle_stop(fwBundle);
+    celixLauncher_stop();
 //	if (framework_waitForStop(framework) != CELIX_SUCCESS) {
 //		celix_log("Error waiting for stop.");
 //	}

http://git-wip-us.apache.org/repos/asf/celix/blob/481e5c86/launcher/public/include/launcher.h
----------------------------------------------------------------------
diff --git a/launcher/public/include/launcher.h b/launcher/public/include/launcher.h
index f95e160..6ee8357 100644
--- a/launcher/public/include/launcher.h
+++ b/launcher/public/include/launcher.h
@@ -32,6 +32,7 @@
 
 int celixLauncher_launch(const char *configFile);
 int celixLauncher_launchWithStream(FILE *config);
+void celixLauncher_stop(void);
 void celixLauncher_waitForShutdown(void);
 struct framework *celixLauncher_getFramework(void);
 

http://git-wip-us.apache.org/repos/asf/celix/blob/481e5c86/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 500e40e..3937605 100644
--- a/remote_services/remote_service_admin_dfi/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/CMakeLists.txt
@@ -46,7 +46,9 @@ if (RSA_REMOTE_SERVICE_ADMIN_DFI)
         ${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 ${CURL_LIBRARIES} ${JANSSON_LIBRARIES} ${FFI_LIBRARIES} dfi)
+    target_link_libraries(remote_service_admin_dfi celix_framework celix_utils ${CURL_LIBRARIES} ${JANSSON_LIBRARIES} ${FFI_LIBRARIES} dfi)
 
     install_bundle(remote_service_admin_dfi)
+
+    add_subdirectory(tst)
 endif (RSA_REMOTE_SERVICE_ADMIN_DFI)

http://git-wip-us.apache.org/repos/asf/celix/blob/481e5c86/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt b/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
index fb1834a..d71186e 100644
--- a/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
@@ -3,20 +3,26 @@
 #
 
 include_directories(
-	${PROJECT_SOURCE_DIR}/launcher/public
+	${PROJECT_SOURCE_DIR}/launcher/public/include
     ${CPPUTEST_INCLUDE_DIR}
+    ${PROJECT_SOURCE_DIR}/framework/public/include
+    ${PROJECT_SOURCE_DIR}/utils/public/include
 )
 
-
 #if (FRAMEWORK_TESTS) TODO
+    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")
+
 	add_executable(rsa_dfi_tests
-		${PROJECT_SOURCE_DIR}/launcher/private/src/launcher
-	    tst/run_tests.cpp
+	    ${PROJECT_SOURCE_DIR}/launcher/private/src/launcher.c
+	    run_tests.cpp
+	    rsa_tests.cpp
 	)
-	target_link_libraries(rsa_dfi_tests ${CPPUTEST_LIBRARY}) #TODO add celix/launcer etc
+	target_link_libraries(rsa_dfi_tests ${CPPUTEST_LIBRARY} celix_framework celix_utils ${CURL_LIBRARIES})
 
 	get_property(rsa_bundle_file TARGET remote_service_admin_dfi PROPERTY BUNDLE)
-	configure_file(config.properties.in config-rsa.properties @ONLY)
+	configure_file(config.properties.in config.properties @ONLY)
 
 	add_test(NAME run_rsa_dfi_tests COMMAND rsa_dfi_tests)
 	SETUP_TARGET_FOR_COVERAGE(rsa_dfi_tests_cov rsa_dfi_tests ${CMAKE_BINARY_DIR}/coverage/rsa_dfi)

http://git-wip-us.apache.org/repos/asf/celix/blob/481e5c86/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp b/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
new file mode 100644
index 0000000..b9206da
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
@@ -0,0 +1,36 @@
+/*
+ * 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 "launcher.h"
+#include "framework.h"
+
+
+static void testFindRsaService(void) {
+    struct framework *fm = celixLauncher_getFramework();
+    CHECK(fm != NULL);
+
+    //TODO get framework bundle context. lookup service -> test service
+}
+
+}
+
+
+TEST_GROUP(RsaDfiTests) {
+    void setup() {
+    }
+};
+
+TEST(RsaDfiTests, FindRsaService) {
+    testFindRsaService();
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/481e5c86/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/run_tests.cpp b/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
index b5f29e7..dedb70a 100644
--- a/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
@@ -4,15 +4,26 @@
 #include <CppUTest/TestHarness.h>
 #include "CppUTest/CommandLineTestRunner.h"
 
-#include <stdio.h>
 
-#include "launcher.h"
+extern "C" {
+    #include <stdio.h>
 
+    #include "launcher.h"
+    #include "framework.h"
+
+    static int startCelix(void) {
+        celixLauncher_launch("config.properties");
+    }
+
+    static int stopCelix(void) {
+        celixLauncher_stop();
+        celixLauncher_waitForShutdown();
+    }
+}
 
 int main(int argc, char** argv) {
-    celixLauncher_launch("config.properties");
+    startCelix();
     int rc = RUN_ALL_TESTS(argc, argv);
-    framework_stop((celixLauncher_getFramework()));
-    celixLauncher_waitForShutdown();
+    stopCelix();
     return rc;
 }
\ No newline at end of file


[20/50] [abbrv] celix git commit: CELIX-237: Refactoring of rsa_dfi layout (lib, lib-tst, rsa bundle, rsa tst)

Posted by pn...@apache.org.
CELIX-237: Refactoring of rsa_dfi layout (lib, lib-tst, rsa bundle, rsa tst)


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

Branch: refs/heads/develop
Commit: a129b4884451d7347749faa43915dcc8452e14b8
Parents: 2522330
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Thu Aug 13 11:08:56 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Thu Aug 13 11:08:56 2015 +0200

----------------------------------------------------------------------
 remote_services/CMakeLists.txt                  |   1 -
 .../public/include/endpoint_listener.h          |  48 --
 .../public/include/endpoint_listener.h          |  48 ++
 .../public/include/remote_constants.h           |  38 +
 .../remote_service_admin_dfi/CMakeLists.txt     |  75 +-
 .../dynamic_function_interface/CMakeLists.txt   |  37 +-
 .../avro_descriptor_translator.c                | 319 --------
 .../descriptor_translator.h                     |  18 -
 .../descriptors/example1.descriptor             |  13 -
 .../schemas/complex.avdl                        |  11 -
 .../schemas/complex.avpr                        |  36 -
 .../schemas/invalid1.avpr                       |  29 -
 .../schemas/invalid2.avpr                       |  31 -
 .../schemas/simple.avdl                         |   6 -
 .../schemas/simple.avpr                         |  33 -
 .../schemas/simple_min.avpr                     |   1 -
 .../tst/avro_descriptor_translator_tests.cpp    | 164 ----
 .../tst/dyn_closure_tests.cpp                   | 146 ----
 .../tst/dyn_function_tests.cpp                  | 231 ------
 .../tst/dyn_interface_tests.cpp                 |  87 ---
 .../tst/dyn_type_tests.cpp                      | 190 -----
 .../tst/json_serializer_tests.cpp               | 398 ----------
 .../tst/run_tests.cpp                           |   9 -
 .../CMakeLists.txt                              |  26 +
 .../avro_descriptor_translator_tests.cpp        | 164 ++++
 .../descriptors/example1.descriptor             |  13 +
 .../dyn_closure_tests.cpp                       | 146 ++++
 .../dyn_function_tests.cpp                      | 231 ++++++
 .../dyn_interface_tests.cpp                     |  87 +++
 .../dyn_type_tests.cpp                          | 190 +++++
 .../json_serializer_tests.cpp                   | 398 ++++++++++
 .../run_tests.cpp                               |   9 +
 .../schemas/complex.avdl                        |  11 +
 .../schemas/complex.avpr                        |  36 +
 .../schemas/invalid1.avpr                       |  29 +
 .../schemas/invalid2.avpr                       |  31 +
 .../schemas/simple.avdl                         |   6 +
 .../schemas/simple.avpr                         |  33 +
 .../schemas/simple_min.avpr                     |   1 +
 .../private/include/export_registration_dfi.h   |  21 -
 .../private/include/import_registration_dfi.h   |  25 -
 .../include/remote_service_admin_http_impl.h    |  73 --
 .../private/src/export_registration_dfi.c       | 239 ------
 .../private/src/import_registration_dfi.c       | 318 --------
 .../src/remote_service_admin_activator.c        | 122 ---
 .../private/src/remote_service_admin_dfi.c      | 747 -------------------
 .../remote_service_admin_dfi/rsa/CMakeLists.txt |  45 ++
 .../private/include/export_registration_dfi.h   |  21 +
 .../private/include/import_registration_dfi.h   |  25 +
 .../include/remote_service_admin_http_impl.h    |  73 ++
 .../rsa/private/src/export_registration_dfi.c   | 239 ++++++
 .../rsa/private/src/import_registration_dfi.c   | 318 ++++++++
 .../src/remote_service_admin_activator.c        | 122 +++
 .../rsa/private/src/remote_service_admin_dfi.c  | 747 +++++++++++++++++++
 .../rsa_tst/CMakeLists.txt                      |  47 ++
 .../rsa_tst/bundle/CMakeLists.txt               |  24 +
 .../rsa_tst/bundle/tst_activator.c              | 137 ++++
 .../rsa_tst/bundle/tst_service.h                |  17 +
 .../rsa_tst/client.properties.in                |   8 +
 .../rsa_tst/config.properties.in                |   3 +
 .../rsa_tst/rsa_client_server_tests.cpp         | 113 +++
 .../rsa_tst/rsa_tests.cpp                       | 201 +++++
 .../rsa_tst/run_tests.cpp                       |   9 +
 .../rsa_tst/server.properties.in                |   8 +
 .../remote_service_admin_dfi/tst/CMakeLists.txt |  47 --
 .../tst/bundle/CMakeLists.txt                   |  25 -
 .../tst/bundle/tst_activator.c                  | 137 ----
 .../tst/bundle/tst_service.h                    |  17 -
 .../tst/client.properties.in                    |   8 -
 .../tst/config.properties.in                    |   3 -
 .../tst/rsa_client_server_tests.cpp             | 113 ---
 .../remote_service_admin_dfi/tst/rsa_tests.cpp  | 201 -----
 .../remote_service_admin_dfi/tst/run_tests.cpp  |   9 -
 .../tst/server.properties.in                    |   8 -
 .../utils/public/include/remote_constants.h     |  38 -
 75 files changed, 3680 insertions(+), 4008 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/CMakeLists.txt b/remote_services/CMakeLists.txt
index f39b604..abc9177 100644
--- a/remote_services/CMakeLists.txt
+++ b/remote_services/CMakeLists.txt
@@ -39,7 +39,6 @@ if (REMOTE_SERVICE_ADMIN)
 
     add_subdirectory(remote_service_admin)
     add_subdirectory(remote_service_admin_http)
-    add_subdirectory(remote_service_admin_dfi/tst/bundle)
     add_subdirectory(remote_service_admin_dfi)
     add_subdirectory(remote_service_admin_shm)
 

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/endpoint_listener/public/include/endpoint_listener.h
----------------------------------------------------------------------
diff --git a/remote_services/endpoint_listener/public/include/endpoint_listener.h b/remote_services/endpoint_listener/public/include/endpoint_listener.h
deleted file mode 100644
index ccf52a8..0000000
--- a/remote_services/endpoint_listener/public/include/endpoint_listener.h
+++ /dev/null
@@ -1,48 +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.
- */
-/*
- * endpoint_listener.h
- *
- *  \date       Sep 29, 2011
- *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright	Apache License, Version 2.0
- */
-
-#ifndef ENDPOINT_LISTENER_H_
-#define ENDPOINT_LISTENER_H_
-
-#include "array_list.h"
-#include "properties.h"
-
-#include "endpoint_description.h"
-
-static const char * const OSGI_ENDPOINT_LISTENER_SERVICE = "endpoint_listener";
-
-static const char * const OSGI_ENDPOINT_LISTENER_SCOPE = "endpoint.listener.scope";
-
-struct endpoint_listener {
-	void *handle;
-	celix_status_t (*endpointAdded)(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
-	celix_status_t (*endpointRemoved)(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
-};
-
-typedef struct endpoint_listener *endpoint_listener_pt;
-
-
-#endif /* ENDPOINT_LISTENER_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin/public/include/endpoint_listener.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/public/include/endpoint_listener.h b/remote_services/remote_service_admin/public/include/endpoint_listener.h
new file mode 100644
index 0000000..ccf52a8
--- /dev/null
+++ b/remote_services/remote_service_admin/public/include/endpoint_listener.h
@@ -0,0 +1,48 @@
+/**
+ *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.
+ */
+/*
+ * endpoint_listener.h
+ *
+ *  \date       Sep 29, 2011
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+
+#ifndef ENDPOINT_LISTENER_H_
+#define ENDPOINT_LISTENER_H_
+
+#include "array_list.h"
+#include "properties.h"
+
+#include "endpoint_description.h"
+
+static const char * const OSGI_ENDPOINT_LISTENER_SERVICE = "endpoint_listener";
+
+static const char * const OSGI_ENDPOINT_LISTENER_SCOPE = "endpoint.listener.scope";
+
+struct endpoint_listener {
+	void *handle;
+	celix_status_t (*endpointAdded)(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
+	celix_status_t (*endpointRemoved)(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
+};
+
+typedef struct endpoint_listener *endpoint_listener_pt;
+
+
+#endif /* ENDPOINT_LISTENER_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin/public/include/remote_constants.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/public/include/remote_constants.h b/remote_services/remote_service_admin/public/include/remote_constants.h
new file mode 100644
index 0000000..0736685
--- /dev/null
+++ b/remote_services/remote_service_admin/public/include/remote_constants.h
@@ -0,0 +1,38 @@
+/**
+ *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_constants.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_CONSTANTS_H_
+#define REMOTE_CONSTANTS_H_
+
+static const char * const OSGI_RSA_SERVICE_EXPORTED_INTERFACES = "service.exported.interfaces";
+static const char * const OSGI_RSA_ENDPOINT_FRAMEWORK_UUID = "endpoint.framework.uuid";
+static const char * const OSGI_RSA_ENDPOINT_SERVICE_ID = "endpoint.service.id";
+static const char * const OSGI_RSA_ENDPOINT_ID = "endpoint.id";
+static const char * const OSGI_RSA_SERVICE_IMPORTED = "service.imported";
+static const char * const OSGI_RSA_SERVICE_IMPORTED_CONFIGS = "service.imported.configs";
+static const char * const OSGI_RSA_SERVICE_LOCATION = "service.location";
+
+#endif /* REMOTE_CONSTANTS_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/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 83dfc41..ccd01f9 100644
--- a/remote_services/remote_service_admin_dfi/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/CMakeLists.txt
@@ -1,65 +1,36 @@
-# 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.
+
+
 celix_subproject(RSA_REMOTE_SERVICE_ADMIN_DFI "Option to enable building the Remote Service Admin Service DFI" OFF)
+
 if (RSA_REMOTE_SERVICE_ADMIN_DFI)
+
     find_package(CURL REQUIRED)
     find_package(Jansson REQUIRED)
     find_package(FFI REQUIRED)
+    #TODO if test
+    find_package(CppUTest REQUIRED)
 
-    add_subdirectory(dynamic_function_interface)
-
-    include_directories(private/include)
-
-    include_directories(${FFI_INCLUDE_DIRS})
-    include_directories(${CURL_INCLUDE_DIRS})
-    include_directories(${JANSSON_INCLUDE_DIRS})
-
-    include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
-
-    include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
+    include_directories(
+        ${CURL_INCLUDE_DIRS}
+        ${JANSSON_INCLUDE_DIRS}
+        ${FFI_INCLUDE_DIRS}
+    )
 
-    include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/private/include")
-    include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/public/include")
+    if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+        include_directories(dynamic_function_interface/memstream)
+    endif()
 
-    include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
-    include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_http/private/include")
+    #TODO if test
+    include_directories(${CPPUTEST_INCLUDE_DIR})
 
-    include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
-    include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_dfi/dynamic_function_interface")
-    include_directories("${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include")
-    
-    SET_HEADER(BUNDLE_SYMBOLICNAME "apache_celix_remote_service_admin_dfi")
-    SET(BUNDLE_VERSION "0.0.1")
-    SET_HEADERS("Bundle-Name: Apache Celix Remote Service Admin Dynamic Function Interface (DFI)")
-    
-    bundle(remote_service_admin_dfi SOURCES
-        private/src/remote_service_admin_dfi.c
-        private/src/remote_service_admin_activator.c
-        private/src/export_registration_dfi.c
-        private/src/import_registration_dfi.c
 
-        ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
 
-        ${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} ${FFI_LIBRARIES} dfi)
+    add_subdirectory(dynamic_function_interface)
+    #TODO if test
+    add_subdirectory(dynamic_function_interface_tst)
 
-    install_bundle(remote_service_admin_dfi)
+    add_subdirectory(rsa)
+    #TODO if test
+    add_subdirectory(rsa_tst)
 
-    add_subdirectory(tst)
-endif (RSA_REMOTE_SERVICE_ADMIN_DFI)
+endif()
\ 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/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
index 0dad5e1..142ae32 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt
@@ -1,16 +1,8 @@
 #
 # Licensed under Apache License v2. See LICENSE for more information.
 #
-find_package(Jansson REQUIRED)
-find_package(CppUTest REQUIRED)
-find_package(FFI REQUIRED)
-
-include_directories( 
-    ${CPPUTEST_INCLUDE_DIR}
-    ${JANSSON_INCLUDE_DIRS}
-    ${CMAKE_CURRENT_LIST_DIR}
-    ${FFI_INCLUDE_DIRS}
-    memstream
+include_directories(
+	.
 )
 
 set(MEMSTREAM_SOURCES "")
@@ -24,29 +16,6 @@ add_library(dfi STATIC
     dyn_function.c
     dyn_interface.c
     json_serializer.c
-#    avro_descriptor_translator.c
     ${MEMSTREAM_SOURCES}
 )
-target_link_libraries(dfi ${FFI_LIBRARIES} ${JANSSON_LIBRARY})
-
-
-#if (FRAMEWORK_TESTS) TODO
-	add_executable(test_dfi
-	    tst/dyn_type_tests.cpp
-	    tst/dyn_function_tests.cpp
-	    tst/dyn_closure_tests.cpp
-        tst/dyn_interface_tests.cpp
-	    tst/json_serializer_tests.cpp
-	    tst/run_tests.cpp
-	)
-	target_link_libraries(test_dfi dfi ${FFI_LIBRARIES} ${CPPUTEST_LIBRARY} ${JANSSON_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/dfi)
-#endif()
+target_link_libraries(dfi ${FFI_LIBRARIES} ${JANSSON_LIBRARY})
\ 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/avro_descriptor_translator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/avro_descriptor_translator.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/avro_descriptor_translator.c
deleted file mode 100644
index a9fea1d..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/avro_descriptor_translator.c
+++ /dev/null
@@ -1,319 +0,0 @@
-/**
- * Licensed under Apache License v2. See LICENSE for more information.
- */
-#include "descriptor_translator.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdbool.h>
-
-#include <jansson.h>
-
-#if defined(BSD) || defined(__APPLE__) 
-#include "open_memstream.h"
-#include "fmemopen.h"
-#endif
-
-DFI_SETUP_LOG(descriptorTranslator)
-
-static const int OK = 0;
-static const int MEM_ERROR = 1;
-static const int PARSE_ERROR = 2;
-static const int INV_ARG_ERROR = 2;
-                   
-static int descriptorTranslator_createMethodInfo(dyn_interface_type *intf, json_t *schema, const char *name, int index, json_t *message); 
-static int descriptorTranslator_parseType(dyn_interface_type *intf, json_t *type);
-static int descriptorTranslator_parseMessage(json_t *schema, const char *name, json_t *message, bool asJavaSignature, char **descriptor); 
-static int descriptorTranslator_parseArgument(FILE *stream, json_t *type);
-
-int descriptorTranslator_translate(const char *schemaStr, dyn_interface_type **out) {
-    LOG_DEBUG("translating descriptor for schema '%s'\n", schemaStr);
-    int status = OK;
-
-    dyn_interface_type *intf = NULL;
-    status = dynInterface_create("TODO", &intf); //TODO parse json first retreive 'Protocol' string value
-    if (status == 0) {
-        json_error_t error;
-        json_t *schema = json_loads(schemaStr, JSON_DECODE_ANY, &error);
-
-        if (schema != NULL) {
-            json_t *types = json_object_get(schema, "types");
-            if (types != NULL) {
-                json_t *type = NULL;
-                int index = 0;
-                json_array_foreach(types, index, type) {
-                    status = descriptorTranslator_parseType(intf, type);
-                    if (status != OK) { 
-                        break;
-                    }
-                }
-            }
-            json_t *messages = json_object_get(schema, "messages");
-            if (status == OK && messages != NULL) {
-                const char *name;
-                json_t *message;
-                int index = 0;
-                json_object_foreach(messages, name, message) {
-                   status = descriptorTranslator_createMethodInfo(intf, schema, name, index++, message); 
-                   if (status != OK) {
-                       break;
-                   }
-                }
-            }
-            json_decref(schema);
-        } else {
-            status = PARSE_ERROR;
-            printf("AVRO_DESCRIPTOR_TRANSLATOR: error parsing json input '%s'. Error is %s\n", schemaStr, error.text);
-        }
-    } else { 
-        status = MEM_ERROR;
-    }
-
-
-    if (status == OK) { 
-        *out = intf;
-    } else {
-        dynInterface_destroy(intf);
-    }
-    return status;
-}
-
-static int descriptorTranslator_createMethodInfo(dyn_interface_type *intf, json_t *schema, const char *name, int index, json_t *message) {
-    int status = OK;
-
-    method_info_type *mInfo = calloc(1, sizeof(*mInfo));
-    if (mInfo != NULL) {
-        mInfo->identifier = index;
-        status = descriptorTranslator_parseMessage(schema, name, message, false, &mInfo->descriptor);
-        if (status == OK) {
-            mInfo->name = strdup(name);
-            if (mInfo->name == NULL) {
-                status = MEM_ERROR;
-            } else {
-                status = descriptorTranslator_parseMessage(schema, name, message, true, &mInfo->strIdentifier);
-            }
-        }
-    } else {
-        status = MEM_ERROR;
-    }
-
-    if (status == OK) {
-        TAILQ_INSERT_TAIL(&intf->methodInfos, mInfo, entries);
-    } else {
-        if (mInfo != NULL) {
-            if (mInfo->name != NULL) {
-                free(mInfo->name);
-            }
-            if (mInfo->descriptor != NULL) {
-                free(mInfo->descriptor);
-            }
-            if (mInfo->strIdentifier != NULL) {
-                free(mInfo->strIdentifier);
-            }
-            free(mInfo);
-        }
-    }
-
-    return status;
-} 
-
-static int descriptorTranslator_parseMessage(json_t *schema, const char *name, json_t *message, bool asJavaSignature, char **descriptor) {
-    int status = OK;
-    //message -> { "request" : [ {"name":"<name>", "type":"<type>"} * ], "response":"<type>" }
-    //array -> "type":"array", "items:"<type>"
-
-    char *ptr = NULL;
-    size_t ptrSize;
-    FILE *memStream = open_memstream(&ptr, &ptrSize);
-    
-    if (memStream != NULL) { 
-        json_t *request = json_object_get(message, "request");
-        fwrite(name, 1, strlen(name), memStream);
-        fputc('(', memStream);
-        if (!asJavaSignature) {
-            fputc('P', memStream); //handle
-        }
-    
-        if (request != NULL) {
-            size_t index;
-            json_t *arg;
-            json_array_foreach(request, index, arg) {
-                //json_t *name = json_object_get(arg, "name");
-                json_t *type = json_object_get(arg, "type");
-                if (type != NULL) {
-                    status = descriptorTranslator_parseArgument(memStream, type);
-                } else {
-                    LOG_ERROR("expected json object with name value for request argument %zu for message/method %s\n", index, name);
-                    status = PARSE_ERROR;
-                }
-                if (status != OK) { 
-                    break;
-                }
-            }
-        } else {
-            status = PARSE_ERROR;
-            LOG_ERROR("Expected request for message %s\n", name);    
-        }
-
-        json_t *response = json_object_get(message, "response");
-        if (status == OK && response != NULL) {
-            if (asJavaSignature) {
-                fputc(')', memStream);
-            } else {
-                fputc('*', memStream); //output parameter
-            }
-            status = descriptorTranslator_parseArgument(memStream, response);
-        } 
-
-        if (!asJavaSignature) {
-            fputc(')', memStream);
-            fputc('N', memStream); //error / exceptions
-        }
-   } else {
-       status = MEM_ERROR;
-   }
-
-    if (memStream != NULL) {
-        fclose(memStream);
-        if (status == OK) {
-            *descriptor = ptr;
-        } else {
-            free(ptr);
-        }
-    } 
-
-    return status;
-}
-
-static const char * const PRIMITIVE_INT = "int";
-static const char * const PRIMITIVE_LONG = "long";
-static const char * const PRIMITIVE_STRING = "string";
-static const char * const PRIMITIVE_BOOL = "boolean";
-static const char * const PRIMITIVE_FLOAT = "float";
-static const char * const PRIMITIVE_DOUBLE = "double";
-static const char * const PRIMITIVE_NULL = "null";
-static const char * const PRIMITIVE_BYTES = "bytes";
-
-static int descriptorTranslator_parseArgument(FILE *stream, json_t *type) {
-    int status = OK;
-    if (json_is_string(type)) {
-        const char *typeStr = json_string_value(type);
-        char t = '\0';
-        if (strcmp(typeStr, PRIMITIVE_INT) == 0) {
-            t = 'I';
-        } else if (strcmp(typeStr, PRIMITIVE_LONG) == 0) {
-            t = 'J';
-        } else if (strcmp(typeStr, PRIMITIVE_STRING) == 0) {
-            t = 'T';
-        } else if (strcmp(typeStr, PRIMITIVE_BOOL) == 0) {
-            t = 'Z';
-        } else if (strcmp(typeStr, PRIMITIVE_FLOAT) == 0) {
-            t = 'F';
-        } else if (strcmp(typeStr, PRIMITIVE_DOUBLE) == 0) {
-            t = 'D';
-        } else if (strcmp(typeStr, PRIMITIVE_NULL) == 0) {
-            t = 'V';
-        } else if (strcmp(typeStr, PRIMITIVE_BYTES) == 0) {
-            t = 'B';
-        } else {
-            fprintf(stream, "L%s;", typeStr);
-        }
-        if (t != '\0') {
-            fputc(t, stream);
-        }
-    } else {
-        json_t *subType = json_object_get(type, "type");
-        json_t *items = json_object_get(type, "items");
-        if (strcmp("array", json_string_value(subType)) == 0) {
-            //array
-            fputc('[', stream);
-            descriptorTranslator_parseArgument(stream, items);
-        } else {
-            LOG_ERROR("sub type %s not supported\n", json_string_value(subType));
-            status = PARSE_ERROR;
-        }
-    }
-    return status;
-}
-            
-static int descriptorTranslator_parseType(dyn_interface_type *intf, json_t *type) {
-    int status = OK;
-    const char *name = json_string_value(json_object_get(type, "name"));
-    type_info_type *tInfo = NULL;
-
-    char *ptr = NULL;
-    size_t ptrSize;
-    FILE *stream = open_memstream(&ptr, &ptrSize);
-
-    if (stream != NULL) {
-        fputc('{', stream);
-        json_t *fields = json_object_get(type, "fields");
-        if (json_is_array(fields)) {
-            int index = 0;
-            json_t *field = NULL;
-            json_array_foreach(fields, index, field) {
-                json_t *type = json_object_get(field, "type");
-                status = descriptorTranslator_parseArgument(stream, type);
-                if (status != OK) { 
-                    break;
-                }
-            }
-            if (status == OK) {
-                json_array_foreach(fields, index, field) {
-                    const char *fieldName = json_string_value(json_object_get(field, "name"));
-                    if (fieldName != NULL) { 
-                        fputc(' ', stream);
-                        fwrite(fieldName, 1, strlen(fieldName), stream);
-                    } else {
-                        status = PARSE_ERROR;
-                        printf("Expected name for field\n");
-                        break;
-                    }
-                }
-            }
-        } else {
-            status = PARSE_ERROR;
-            printf("Expected array type");
-        }
-        fputc('}', stream);
-        fclose(stream);
-    } else {
-        status = MEM_ERROR;
-        LOG_ERROR("Error creating memory stream");
-    }
-
-    if (status == OK) {
-        tInfo = calloc(1, sizeof(*tInfo));
-        if (tInfo != NULL) {
-           tInfo->name = strdup(name);
-           if (tInfo->name != NULL) {
-               tInfo->descriptor = ptr;
-           } else {
-               status = MEM_ERROR;
-               LOG_ERROR("Error allocating memory for type info name");
-           }
-        } else {
-            status = MEM_ERROR;
-            LOG_ERROR("Error allocating memory for type_info");
-        }
-    }
-
-    if (status != 0 ) {
-        if (tInfo != NULL) {
-            if (tInfo->name != NULL) {
-                free(tInfo->name);
-            }
-            free(tInfo);
-        }
-        if (ptr != NULL) {
-            free(ptr);
-        }
-    }
-
-    if (status == OK) {
-        TAILQ_INSERT_TAIL(&intf->typeInfos, tInfo, entries);
-    }
-
-    return status;
-}

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/descriptor_translator.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/descriptor_translator.h b/remote_services/remote_service_admin_dfi/dynamic_function_interface/descriptor_translator.h
deleted file mode 100644
index 6473d0d..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/descriptor_translator.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * Licensed under Apache License v2. See LICENSE for more information.
- */
-#ifndef __DESCRIPTOR_TRANSLATOR_H_
-#define __DESCRIPTOR_TRANSLATOR_H_
-
-#include <stdio.h>
-#include  <sys/queue.h>
-
-#include "dfi_log_util.h"
-#include "dyn_interface.h"
-
-//logging
-DFI_SETUP_LOG_HEADER(descriptorTranslator);
-
-int descriptorTranslator_translate(const char *schemaStr, dyn_interface_type **out);
-
-#endif

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/descriptors/example1.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/descriptors/example1.descriptor b/remote_services/remote_service_admin_dfi/dynamic_function_interface/descriptors/example1.descriptor
deleted file mode 100644
index 97b1df8..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/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(PDD*D)N
-sub(DD)D=sub(PDD*D)N
-sqrt(D)D=sqrt(PD*D)N
-stats([D)LStatsResult;=stats(P[D*LStatsResult;)N

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/complex.avdl
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/complex.avdl b/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/complex.avdl
deleted file mode 100644
index 0490dcd..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/complex.avdl
+++ /dev/null
@@ -1,11 +0,0 @@
-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/schemas/complex.avpr
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/complex.avpr b/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/complex.avpr
deleted file mode 100644
index 0577397..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/complex.avpr
+++ /dev/null
@@ -1,36 +0,0 @@
-{
-  "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/schemas/invalid1.avpr
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/invalid1.avpr b/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/invalid1.avpr
deleted file mode 100644
index c968c61..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/invalid1.avpr
+++ /dev/null
@@ -1,29 +0,0 @@
-{
-  "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/schemas/invalid2.avpr
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/invalid2.avpr b/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/invalid2.avpr
deleted file mode 100644
index fc48ca9..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/invalid2.avpr
+++ /dev/null
@@ -1,31 +0,0 @@
-{
-  "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/schemas/simple.avdl
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple.avdl b/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple.avdl
deleted file mode 100644
index cd5cafe..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple.avdl
+++ /dev/null
@@ -1,6 +0,0 @@
-@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/schemas/simple.avpr
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple.avpr b/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple.avpr
deleted file mode 100644
index 8a90bb2..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple.avpr
+++ /dev/null
@@ -1,33 +0,0 @@
-{
-  "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/schemas/simple_min.avpr
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple_min.avpr b/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple_min.avpr
deleted file mode 100644
index c2bce19..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/schemas/simple_min.avpr
+++ /dev/null
@@ -1 +0,0 @@
-{"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/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 63401e5..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/avro_descriptor_translator_tests.cpp
+++ /dev/null
@@ -1,164 +0,0 @@
-/**
- * Licensed under Apache License v2. See LICENSE for more information.
- */
-#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/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
deleted file mode 100644
index b2b11d7..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_closure_tests.cpp
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * 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
deleted file mode 100644
index cb4e13b..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_function_tests.cpp
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * 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
deleted file mode 100644
index 679260f..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_interface_tests.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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
deleted file mode 100644
index 96f64fa..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/dyn_type_tests.cpp
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * 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
deleted file mode 100644
index 5ee71ac..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/json_serializer_tests.cpp
+++ /dev/null
@@ -1,398 +0,0 @@
-/**
- * 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
deleted file mode 100644
index f405c9f..0000000
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/run_tests.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-/*
- * 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/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
new file mode 100644
index 0000000..50325ab
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/CMakeLists.txt
@@ -0,0 +1,26 @@
+#
+# Licensed under Apache License v2. See LICENSE for more information.
+#
+include_directories(
+	../dynamic_function_interface
+)
+
+add_executable(test_dfi
+	dyn_type_tests.cpp
+	dyn_function_tests.cpp
+	dyn_closure_tests.cpp
+	dyn_interface_tests.cpp
+	json_serializer_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/dfi)
+

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/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
new file mode 100644
index 0000000..63401e5
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/avro_descriptor_translator_tests.cpp
@@ -0,0 +1,164 @@
+/**
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#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/a129b488/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
new file mode 100644
index 0000000..97b1df8
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/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(PDD*D)N
+sub(DD)D=sub(PDD*D)N
+sqrt(D)D=sqrt(PD*D)N
+stats([D)LStatsResult;=stats(P[D*LStatsResult;)N


[38/50] [abbrv] celix git commit: CELIX-237: Forwarded and implemented remove export service to export_registration_dfi

Posted by pn...@apache.org.
CELIX-237: Forwarded and implemented remove export service to export_registration_dfi


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

Branch: refs/heads/develop
Commit: e4d3ea6e81e5b6d700cff0a6752f0b83dfbc0892
Parents: a477ab9
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Sep 16 13:02:38 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Sep 16 13:02:38 2015 +0200

----------------------------------------------------------------------
 .../private/include/export_registration_dfi.h   |  2 +-
 .../rsa/private/src/export_registration_dfi.c   |  7 +----
 .../rsa/private/src/remote_service_admin_dfi.c  | 33 ++++++++++++++------
 3 files changed, 26 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/e4d3ea6e/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h b/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
index 100294c..4356646 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
+++ b/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
@@ -9,7 +9,7 @@
 #include "log_helper.h"
 #include "endpoint_description.h"
 
-celix_status_t exportRegistration_create(log_helper_pt helper, void (*closedCallback)(void *handle, export_registration_pt reg), void *handle, service_reference_pt reference, endpoint_description_pt endpoint, bundle_context_pt context, export_registration_pt *registration);
+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);

http://git-wip-us.apache.org/repos/asf/celix/blob/e4d3ea6e/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
index 9bc5b08..edc085e 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
@@ -18,8 +18,6 @@ struct export_reference {
 
 struct export_registration {
     bundle_context_pt  context;
-    void (*rsaCloseExportCallback)(void *handle, export_registration_pt reg);
-    void *handle;
     struct export_reference exportReference;
     char *servId;
     dyn_interface_type *intf; //owner
@@ -35,7 +33,7 @@ struct export_registration {
 static void exportRegistration_addServ(export_registration_pt reg, service_reference_pt ref, void *service);
 static void exportRegistration_removeServ(export_registration_pt reg, service_reference_pt ref, void *service);
 
-celix_status_t exportRegistration_create(log_helper_pt helper, void (*closedCallback)(void *handle, export_registration_pt reg), void *handle, service_reference_pt reference, endpoint_description_pt endpoint, bundle_context_pt context, export_registration_pt *out) {
+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;
 
     char *servId = NULL;
@@ -55,8 +53,6 @@ celix_status_t exportRegistration_create(log_helper_pt helper, void (*closedCall
 
     if (status == CELIX_SUCCESS) {
         reg->context = context;
-        reg->rsaCloseExportCallback = closedCallback;
-        reg->handle = handle;
         reg->exportReference.endpoint = endpoint;
         reg->exportReference.reference = reference;
         reg->closed = false;
@@ -183,7 +179,6 @@ celix_status_t exportRegistration_stop(export_registration_pt reg) {
 celix_status_t exportRegistration_close(export_registration_pt reg) {
     celix_status_t status = CELIX_SUCCESS;
     exportRegistration_stop(reg);
-    reg->rsaCloseExportCallback(reg->handle, reg);
     return status;
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/e4d3ea6e/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
index c12d0aa..54d08d3 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
@@ -49,6 +49,16 @@
 // defines how often the webserver is restarted (with an increased port number)
 #define MAX_NUMBER_OF_RESTARTS 	5
 
+
+#define LOG_ERROR(admin, msg, ...) \
+    logHelper_log((admin)->loghelper, OSGI_LOGSERVICE_ERROR, (msg),  ##__VA_ARGS__)
+
+#define LOG_WARNING(admin, msg, ...) \
+    logHelper_log((admin)->loghelper, OSGI_LOGSERVICE_ERROR, (msg),  ##__VA_ARGS__)
+
+#define LOG_DEBUG(admin, msg, ...) \
+    logHelper_log((admin)->loghelper, OSGI_LOGSERVICE_ERROR, (msg),  ##__VA_ARGS__)
+
 struct remote_service_admin {
     bundle_context_pt context;
     log_helper_pt loghelper;
@@ -413,7 +423,7 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c
         remoteServiceAdmin_createEndpointDescription(admin, reference, interface, &endpoint);
         printf("RSA: Creating export registration with endpoint pointer %p\n", endpoint);
         //TOOD precheck if descriptor exists
-        status = exportRegistration_create(admin->loghelper, remoteServiceAdmin_removeExportedService, admin, reference, endpoint, admin->context, &registration);
+        status = exportRegistration_create(admin->loghelper, reference, endpoint, admin->context, &registration);
         if (status == CELIX_SUCCESS) {
             status = exportRegistration_start(registration);
             if (status == CELIX_SUCCESS) {
@@ -434,17 +444,22 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c
 
 celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration) {
     celix_status_t status = CELIX_SUCCESS;
-    //TODO
-    /*
-    remote_service_admin_pt admin = registration->rsa;
 
-    celixThreadMutex_lock(&admin->exportedServicesLock);
+    service_reference_pt  ref = NULL;
+    status = exportRegistration_getExportReference(registration, &ref);
+
+    if (status == CELIX_SUCCESS) {
+        celixThreadMutex_lock(&admin->exportedServicesLock);
+        exportRegistration_close(registration);
+        //exportRegistration_destroy(registration); TODO test
+        hashMap_remove(admin->exportedServices, ref);
+        celixThreadMutex_unlock(&admin->exportedServicesLock);
+    } else {
+        LOG_ERROR(admin, "Cannot find reference for registration");
+    }
+
 
-    hashMap_remove(admin->exportedServices, registration->reference);
-    //TODO stop ?
 
-    celixThreadMutex_unlock(&admin->exportedServicesLock);
-    */
     return status;
 }
 


[26/50] [abbrv] celix git commit: CELIX-237: Merge branch 'develop' into ffi

Posted by pn...@apache.org.
CELIX-237: Merge branch 'develop' into ffi


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

Branch: refs/heads/develop
Commit: 3853a7c9d1f32636a679fbcfddb4db30766c5375
Parents: 9937ce1 1094446
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Sep 1 16:43:38 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Sep 1 16:43:38 2015 +0200

----------------------------------------------------------------------
 utils/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/3853a7c9/utils/CMakeLists.txt
----------------------------------------------------------------------


[39/50] [abbrv] celix git commit: CELIX-237: Added curl include path

Posted by pn...@apache.org.
CELIX-237: Added curl include path


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

Branch: refs/heads/develop
Commit: 5262482b5d14367d3cd6858f56bc3566eae632bb
Parents: e4d3ea6
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Sep 22 21:03:37 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Sep 22 21:03:37 2015 +0200

----------------------------------------------------------------------
 framework/CMakeLists.txt | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/5262482b/framework/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt
index a69187a..f27abcb 100644
--- a/framework/CMakeLists.txt
+++ b/framework/CMakeLists.txt
@@ -39,6 +39,7 @@ if (FRAMEWORK)
     
     add_definitions(-DUSE_FILE32API)
     include_directories(${ZLIB_INCLUDE_DIR})
+    include_directories(${CURL_INCLUDE_DIR})
     include_directories(${UUID_INCLUDE_DIR})
     include_directories("private/include")
     include_directories("public/include")


[18/50] [abbrv] celix git commit: CELIX-237: Refactoring of rsa_dfi layout (lib, lib-tst, rsa bundle, rsa tst)

Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
deleted file mode 100644
index c78cc19..0000000
--- a/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
+++ /dev/null
@@ -1,747 +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_impl.c
- *
- *  \date       May 21, 2015
- *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright	Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <ifaddrs.h>
-#include <string.h>
-#include <uuid/uuid.h>
-#include <curl/curl.h>
-
-#include <jansson.h>
-
-#include "import_registration_dfi.h"
-#include "export_registration_dfi.h"
-#include "dyn_interface.h"
-
-#include "remote_service_admin.h"
-#include "remote_constants.h"
-#include "constants.h"
-#include "civetweb.h"
-
-// defines how often the webserver is restarted (with an increased port number)
-#define MAX_NUMBER_OF_RESTARTS 	5
-
-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;
-};
-
-struct post {
-    const char *readptr;
-    int size;
-};
-
-struct get {
-    char *writeptr;
-    int size;
-};
-
-#define OSGI_RSA_REMOTE_PROXY_FACTORY 	"remote_proxy_factory"
-#define OSGI_RSA_REMOTE_PROXY_TIMEOUT   "remote_proxy_timeout"
-
-static const char *data_response_headers =
-        "HTTP/1.1 200 OK\r\n"
-                "Cache: no-cache\r\n"
-                "Content-Type: application/json\r\n"
-                "\r\n";
-
-static const char *no_content_response_headers =
-        "HTTP/1.1 204 OK\r\n";
-
-// TODO do we need to specify a non-Amdatu specific configuration type?!
-static const char * const CONFIGURATION_TYPE = "org.amdatu.remote.admin.http";
-static const char * const ENDPOINT_URL = "org.amdatu.remote.admin.http.url";
-
-static const char *DEFAULT_PORT = "8888";
-static const char *DEFAULT_IP = "127.0.0.1";
-
-static const unsigned int DEFAULT_TIMEOUT = 0;
-
-static int remoteServiceAdmin_callback(struct mg_connection *conn);
-static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, char *interface, endpoint_description_pt *description);
-static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
-static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip);
-static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp);
-static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp);
-static void remoteServiceAdmin_log(remote_service_admin_pt admin, int level, const char *file, int line, const char *msg, ...);
-
-celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin) {
-    celix_status_t status = CELIX_SUCCESS;
-
-    *admin = calloc(1, sizeof(**admin));
-
-    if (!*admin) {
-        status = CELIX_ENOMEM;
-    } else {
-        unsigned int port_counter = 0;
-        char *port = NULL;
-        char *ip = NULL;
-        char *detectedIp = NULL;
-        (*admin)->context = context;
-        (*admin)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL);
-        (*admin)->importedServices = hashMap_create(NULL, NULL, NULL, NULL);
-
-        celixThreadMutex_create(&(*admin)->exportedServicesLock, NULL);
-        celixThreadMutex_create(&(*admin)->importedServicesLock, NULL);
-
-        if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
-            logHelper_start((*admin)->loghelper);
-            dynCommon_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
-            dynType_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
-            dynFunction_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
-            dynInterface_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
-        }
-
-        bundleContext_getProperty(context, "RSA_PORT", &port);
-        if (port == NULL) {
-            port = (char *)DEFAULT_PORT;
-        }
-
-        bundleContext_getProperty(context, "RSA_IP", &ip);
-        if (ip == NULL) {
-            char *interface = NULL;
-
-            bundleContext_getProperty(context, "RSA_INTERFACE", &interface);
-            if ((interface != NULL) && (remoteServiceAdmin_getIpAdress(interface, &detectedIp) != CELIX_SUCCESS)) {
-                logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: Could not retrieve IP adress for interface %s", interface);
-            }
-
-            if (ip == NULL) {
-                remoteServiceAdmin_getIpAdress(NULL, &detectedIp);
-            }
-
-            ip = detectedIp;
-        }
-
-        if (ip != NULL) {
-            logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Using %s for service annunciation", ip);
-            (*admin)->ip = strdup(ip);
-        }
-        else {
-            logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No IP address for service annunciation set. Using %s", DEFAULT_IP);
-            (*admin)->ip = (char*) DEFAULT_IP;
-        }
-
-        if (detectedIp != NULL) {
-            free(detectedIp);
-        }
-
-        // Prepare callbacks structure. We have only one callback, the rest are NULL.
-        struct mg_callbacks callbacks;
-        memset(&callbacks, 0, sizeof(callbacks));
-        callbacks.begin_request = remoteServiceAdmin_callback;
-
-        do {
-            char newPort[10];
-            const char *options[] = { "listening_ports", port, NULL};
-
-            (*admin)->ctx = mg_start(&callbacks, (*admin), options);
-
-            if ((*admin)->ctx != NULL) {
-                logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Start webserver: %s", port);
-                (*admin)->port = strdup(port);
-
-            }
-            else {
-                char* endptr = port;
-                int currentPort = strtol(port, &endptr, 10);
-
-                errno = 0;
-
-                if (*endptr || errno != 0) {
-                    currentPort = strtol(DEFAULT_PORT, NULL, 10);
-                }
-
-                port_counter++;
-                snprintf(&newPort[0], 6,  "%d", (currentPort+1));
-
-                logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_ERROR, "Error while starting rsa server on port %s - retrying on port %s...", port, newPort);
-                port = newPort;
-            }
-        } while(((*admin)->ctx == NULL) && (port_counter < MAX_NUMBER_OF_RESTARTS));
-
-    }
-    return status;
-}
-
-
-celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin)
-{
-    celix_status_t status = CELIX_SUCCESS;
-
-    free((*admin)->ip);
-    free((*admin)->port);
-    free(*admin);
-
-    //TODO destroy exports/imports
-
-    *admin = NULL;
-
-    return status;
-}
-
-
-celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin) {
-    celix_status_t status = CELIX_SUCCESS;
-
-    celixThreadMutex_lock(&admin->exportedServicesLock);
-
-    hash_map_iterator_pt iter = hashMapIterator_create(admin->exportedServices);
-    while (hashMapIterator_hasNext(iter)) {
-        array_list_pt exports = hashMapIterator_nextValue(iter);
-        int i;
-        for (i = 0; i < arrayList_size(exports); i++) {
-            export_registration_pt export = arrayList_get(exports, i);
-            if (export != NULL) {
-                exportRegistration_stop(export);
-            }
-        }
-    }
-    hashMapIterator_destroy(iter);
-    celixThreadMutex_unlock(&admin->exportedServicesLock);
-
-    celixThreadMutex_lock(&admin->importedServicesLock);
-
-    iter = hashMapIterator_create(admin->importedServices);
-    while (hashMapIterator_hasNext(iter))
-    {
-
-        hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
-        import_registration_pt import = hashMapEntry_getValue(entry);
-
-        if (import != NULL) {
-            importRegistration_stop(import);
-        }
-    }
-
-    hashMapIterator_destroy(iter);
-    celixThreadMutex_unlock(&admin->importedServicesLock);
-
-    if (admin->ctx != NULL) {
-        logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Stopping webserver...");
-        mg_stop(admin->ctx);
-        admin->ctx = NULL;
-    }
-
-    hashMap_destroy(admin->exportedServices, false, false);
-    hashMap_destroy(admin->importedServices, false, false);
-
-    logHelper_stop(admin->loghelper);
-    logHelper_destroy(&admin->loghelper);
-
-    return status;
-}
-
-/**
- * Request: http://host:port/services/{service}/{request}
- */
-//void *remoteServiceAdmin_callback(enum mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info) {
-
-celix_status_t importRegistration_getFactory(import_registration_pt import, service_factory_pt *factory);
-
-static int remoteServiceAdmin_callback(struct mg_connection *conn) {
-    int result = 1; // zero means: let civetweb handle it further, any non-zero value means it is handled by us...
-
-    const struct mg_request_info *request_info = mg_get_request_info(conn);
-    if (request_info->uri != NULL) {
-        remote_service_admin_pt rsa = request_info->user_data;
-
-
-        if (strncmp(request_info->uri, "/service/", 9) == 0 && strcmp("POST", request_info->request_method) == 0) {
-
-            // uri = /services/myservice/call
-            const char *uri = request_info->uri;
-            // rest = myservice/call
-
-            const char *rest = uri+9;
-            char *interfaceStart = strchr(rest, '/');
-            int pos = interfaceStart - rest;
-            char service[pos+1];
-            strncpy(service, rest, pos);
-            service[pos] = '\0';
-            long serviceId = atol(service);
-
-            celixThreadMutex_lock(&rsa->exportedServicesLock);
-
-            //find endpoint
-            export_registration_pt export = NULL;
-            hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
-            while (hashMapIterator_hasNext(iter)) {
-                hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
-                array_list_pt exports = hashMapEntry_getValue(entry);
-                int expIt = 0;
-                for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
-                    export_registration_pt check = arrayList_get(exports, expIt);
-                    export_reference_pt  ref = NULL;
-                    exportRegistration_getExportReference(check, &ref);
-                    endpoint_description_pt  checkEndpoint = NULL;
-                    exportReference_getExportedEndpoint(ref, &checkEndpoint);
-                    if (serviceId == checkEndpoint->serviceId) {
-                        export = check;
-                        break;
-                    }
-                }
-            }
-            hashMapIterator_destroy(iter);
-
-            if (export != NULL) {
-
-                uint64_t datalength = request_info->content_length;
-                char* data = malloc(datalength + 1);
-                mg_read(conn, data, datalength);
-                data[datalength] = '\0';
-
-                char *response = NULL;
-                int responceLength = 0;
-                int rc = exportRegistration_call(export, data, -1, &response, &responceLength);
-                //TODO check rc
-
-                if (response != NULL) {
-                    mg_write(conn, data_response_headers, strlen(data_response_headers));
-//              mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
-                    printf("writing response '%s'\n", response);
-                    mg_write(conn, response, strlen(response));
-//              mg_send_data(conn, response, strlen(response));
-//              mg_write_data(conn, response, strlen(response));
-
-                    free(response);
-                } else {
-                    mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
-                }
-                result = 1;
-
-                free(data);
-            } else {
-                result = 0;
-                //TODO log warning
-            }
-
-            celixThreadMutex_unlock(&rsa->exportedServicesLock);
-
-        }
-    }
-
-    return result;
-}
-
-celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations) {
-    celix_status_t status = CELIX_SUCCESS;
-
-    arrayList_create(registrations);
-    array_list_pt references = NULL;
-    service_reference_pt reference = NULL;
-    char filter [256];
-
-    snprintf(filter, 256, "(%s=%s)", (char *)OSGI_FRAMEWORK_SERVICE_ID, serviceId);
-
-    status = bundleContext_getServiceReferences(admin->context, NULL, filter, &references);
-
-    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: exportService called for serviceId %s", serviceId);
-
-    if (status == CELIX_SUCCESS && arrayList_size(references) >= 1) {
-        reference = arrayList_get(references, 0);
-    }
-
-    if(references != NULL){
-        arrayList_destroy(references);
-    }
-
-    if (reference == NULL) {
-        logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "ERROR: expected a reference for service id %s.", serviceId);
-        status = CELIX_ILLEGAL_STATE;
-    }
-
-    char *exports = NULL;
-    char *provided = NULL;
-    if (status == CELIX_SUCCESS) {
-        serviceReference_getProperty(reference, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exports);
-        serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_OBJECTCLASS, &provided);
-
-        if (exports == NULL || provided == NULL || strcmp(exports, provided) != 0) {
-            logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No Services to export.");
-            status = CELIX_ILLEGAL_STATE;
-        } else {
-            logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Export service (%s)", provided);
-        }
-    }
-
-    if (status == CELIX_SUCCESS) {
-        char *interface = provided;
-        endpoint_description_pt endpoint = NULL;
-        export_registration_pt registration = NULL;
-
-        remoteServiceAdmin_createEndpointDescription(admin, reference, interface, &endpoint);
-        printf("RSA: Creating export registration with endpoint pointer %p\n", endpoint);
-        //TOOD precheck if descriptor exists
-        status = exportRegistration_create(admin->loghelper, reference, endpoint, admin->context, &registration);
-        if (status == CELIX_SUCCESS) {
-            status = exportRegistration_start(registration);
-            if (status == CELIX_SUCCESS) {
-                arrayList_add(*registrations, registration);
-            }
-        }
-    }
-
-
-    if (status == CELIX_SUCCESS) {
-        celixThreadMutex_lock(&admin->exportedServicesLock);
-        hashMap_put(admin->exportedServices, reference, *registrations);
-        celixThreadMutex_unlock(&admin->exportedServicesLock);
-    }
-
-    return status;
-}
-
-celix_status_t remoteServiceAdmin_removeExportedService(export_registration_pt registration) {
-    celix_status_t status = CELIX_SUCCESS;
-    //TODO
-    /*
-    remote_service_admin_pt admin = registration->rsa;
-
-    celixThreadMutex_lock(&admin->exportedServicesLock);
-
-    hashMap_remove(admin->exportedServices, registration->reference);
-    //TODO stop ?
-
-    celixThreadMutex_unlock(&admin->exportedServicesLock);
-    */
-    return status;
-}
-
-static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, char *interface, endpoint_description_pt *endpoint) {
-    celix_status_t status = CELIX_SUCCESS;
-    properties_pt endpointProperties = properties_create();
-
-
-    unsigned int size = 0;
-    char **keys;
-
-    serviceReference_getPropertyKeys(reference, &keys, &size);
-    for (int i = 0; i < size; i++) {
-        char *key = keys[i];
-        char *value = NULL;
-
-        if (serviceReference_getProperty(reference, key, &value) == CELIX_SUCCESS
-            && strcmp(key, (char*) OSGI_RSA_SERVICE_EXPORTED_INTERFACES) != 0
-            && strcmp(key, (char*) OSGI_FRAMEWORK_OBJECTCLASS) != 0) {
-            properties_set(endpointProperties, key, value);
-            printf("Added property '%s' with value '%s'\n", key, value);
-        }
-    }
-
-    hash_map_entry_pt entry = hashMap_getEntry(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
-
-    char* key = hashMapEntry_getKey(entry);
-    char *serviceId = (char *) hashMap_remove(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
-    char *uuid = NULL;
-
-    char buf[512];
-    snprintf(buf, 512,  "/service/%s/%s", serviceId, interface);
-
-    char url[1024];
-    snprintf(url, 1024, "http://%s:%s%s", admin->ip, admin->port, buf);
-
-    uuid_t endpoint_uid;
-    uuid_generate(endpoint_uid);
-    char endpoint_uuid[37];
-    uuid_unparse_lower(endpoint_uid, endpoint_uuid);
-
-    bundleContext_getProperty(admin->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
-    properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
-    properties_set(endpointProperties, (char*) OSGI_FRAMEWORK_OBJECTCLASS, interface);
-    properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_SERVICE_ID, serviceId);
-    properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID, endpoint_uuid);
-    properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED, "true");
-    properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED_CONFIGS, (char*) CONFIGURATION_TYPE);
-    properties_set(endpointProperties, (char*) ENDPOINT_URL, url);
-
-
-
-    *endpoint = calloc(1, sizeof(**endpoint));
-    if (!*endpoint) {
-        status = CELIX_ENOMEM;
-    } else {
-        (*endpoint)->id = properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID);
-        char *serviceId = NULL;
-        serviceReference_getProperty(reference, (char*) OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
-        (*endpoint)->serviceId = strtoull(serviceId, NULL, 0);
-        (*endpoint)->frameworkUUID = properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
-        (*endpoint)->service = interface;
-        (*endpoint)->properties = endpointProperties;
-    }
-
-    free(key);
-    free(serviceId);
-    free(keys);
-
-    return status;
-}
-
-static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip) {
-    celix_status_t status = CELIX_BUNDLE_EXCEPTION;
-
-    struct ifaddrs *ifaddr, *ifa;
-    char host[NI_MAXHOST];
-
-    if (getifaddrs(&ifaddr) != -1)
-    {
-        for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
-        {
-            if (ifa->ifa_addr == NULL)
-                continue;
-
-            if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
-                if (interface == NULL) {
-                    *ip = strdup(host);
-                    status = CELIX_SUCCESS;
-                }
-                else if (strcmp(ifa->ifa_name, interface) == 0) {
-                    *ip = strdup(host);
-                    status = CELIX_SUCCESS;
-                }
-            }
-        }
-
-        freeifaddrs(ifaddr);
-    }
-
-    return status;
-}
-
-
-celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description)
-{
-    celix_status_t status = CELIX_SUCCESS;
-
-    properties_destroy((*description)->properties);
-    free(*description);
-
-    return status;
-}
-
-
-celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services) {
-    celix_status_t status = CELIX_SUCCESS;
-    return status;
-}
-
-celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services) {
-    celix_status_t status = CELIX_SUCCESS;
-    return status;
-}
-
-celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpointDescription, import_registration_pt *out) {
-    celix_status_t status = CELIX_SUCCESS;
-
-    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Import service %s", endpointDescription->service);
-
-    const char *objectClass = properties_get(endpointDescription->properties, "objectClass");
-    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "Registering service factory (proxy) for service '%s'\n", objectClass);
-
-
-    import_registration_pt import = NULL;
-    if (objectClass != NULL) {
-        status = importRegistration_create(admin->context, endpointDescription, objectClass, &import);
-    }
-    if (status == CELIX_SUCCESS) {
-        importRegistration_setSendFn(import, remoteServiceAdmin_send, admin);
-    }
-
-    if (status == CELIX_SUCCESS) {
-        status = importRegistration_start(import);
-    }
-
-    //celixThreadMutex_lock(&admin->importedServicesLock);
-    //TODO add to list
-    //celixThreadMutex_unlock(&admin->importedServicesLock);
-
-    if (status == CELIX_SUCCESS) {
-        *out = import;
-    }
-
-    return status;
-}
-
-
-celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration) {
-    celix_status_t status = CELIX_SUCCESS;
-    return status;
-    /*
-
-      endpoint_description_pt endpointDescription = (endpoint_description_pt) registration->endpointDescription;
-      import_registration_factory_pt registration_factory = NULL;
-
-      celixThreadMutex_lock(&admin->importedServicesLock);
-
-      registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
-
-      // factory available
-      if ((registration_factory == NULL) || (registration_factory->trackedFactory == NULL))
-      {
-          logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: Error while retrieving registration factory for imported service %s", endpointDescription->service);
-      }
-      else
-      {
-          registration_factory->trackedFactory->unregisterProxyService(registration_factory->trackedFactory->factory, endpointDescription);
-          arrayList_removeElement(registration_factory->registrations, registration);
-          importRegistration_destroy(registration);
-
-          if (arrayList_isEmpty(registration_factory->registrations))
-          {
-              logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: closing proxy.");
-
-              serviceTracker_close(registration_factory->proxyFactoryTracker);
-              importRegistrationFactory_close(registration_factory);
-
-              hashMap_remove(admin->importedServices, endpointDescription->service);
-
-              importRegistrationFactory_destroy(&registration_factory);
-          }
-      }
-
-      celixThreadMutex_unlock(&admin->importedServicesLock);
-
-      return status;
-    */
-}
-
-
-static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus) {
-    remote_service_admin_pt  rsa = handle;
-    struct post post;
-    post.readptr = request;
-    post.size = strlen(request);
-
-    struct get get;
-    get.size = 0;
-    get.writeptr = malloc(1);
-
-    char *serviceUrl = properties_get(endpointDescription->properties, (char*) ENDPOINT_URL);
-    char url[256];
-    snprintf(url, 256, "%s", serviceUrl);
-
-    // assume the default timeout
-    int timeout = DEFAULT_TIMEOUT;
-
-    char *timeoutStr = NULL;
-    // Check if the endpoint has a timeout, if so, use it.
-    timeoutStr = properties_get(endpointDescription->properties, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT);
-    if (timeoutStr == NULL) {
-        // If not, get the global variable and use that one.
-        bundleContext_getProperty(rsa->context, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT, &timeoutStr);
-    }
-
-    // Update timeout if a property is used to set it.
-    if (timeoutStr != NULL) {
-        timeout = atoi(timeoutStr);
-    }
-
-    celix_status_t status = CELIX_SUCCESS;
-    CURL *curl;
-    CURLcode res;
-
-    curl = curl_easy_init();
-    if(!curl) {
-        status = CELIX_ILLEGAL_STATE;
-    } else {
-        curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
-        curl_easy_setopt(curl, CURLOPT_URL, &url[0]);
-        curl_easy_setopt(curl, CURLOPT_POST, 1L);
-        curl_easy_setopt(curl, CURLOPT_READFUNCTION, remoteServiceAdmin_readCallback);
-        curl_easy_setopt(curl, CURLOPT_READDATA, &post);
-        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, remoteServiceAdmin_write);
-        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&get);
-        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)post.size);
-        logHelper_log(rsa->loghelper, OSGI_LOGSERVICE_DEBUG, "RSA: Performing curl post\n");
-        res = curl_easy_perform(curl);
-
-        *reply = get.writeptr;
-        *replyStatus = res;
-
-        curl_easy_cleanup(curl);
-    }
-
-    return status;
-}
-
-static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp) {
-    struct post *post = userp;
-
-    if (post->size) {
-        *(char *) ptr = post->readptr[0];
-        post->readptr++;
-        post->size--;
-        return 1;
-    }
-
-    return 0;
-}
-
-static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp) {
-    size_t realsize = size * nmemb;
-    struct get *mem = (struct get *)userp;
-
-    mem->writeptr = realloc(mem->writeptr, mem->size + realsize + 1);
-    if (mem->writeptr == NULL) {
-        /* out of memory! */
-        printf("not enough memory (realloc returned NULL)");
-        exit(EXIT_FAILURE);
-    }
-
-    memcpy(&(mem->writeptr[mem->size]), contents, realsize);
-    mem->size += realsize;
-    mem->writeptr[mem->size] = 0;
-
-    return realsize;
-}
-
-
-static void remoteServiceAdmin_log(remote_service_admin_pt admin, int level, const char *file, int line, const char *msg, ...) {
-    va_list ap;
-    va_start(ap, msg);
-    int levels[5] = {0, OSGI_LOGSERVICE_ERROR, OSGI_LOGSERVICE_WARNING, OSGI_LOGSERVICE_INFO, OSGI_LOGSERVICE_DEBUG};
-
-    char buf1[256];
-    snprintf(buf1, 256, "FILE:%s, LINE:%i, MSG:", file, line);
-
-    char buf2[256];
-    vsnprintf(buf2, 256, msg, ap);
-    logHelper_log(admin->loghelper, levels[level], "%s%s", buf1, buf2);
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/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
new file mode 100644
index 0000000..79c9220
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
@@ -0,0 +1,45 @@
+# 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(private/include)
+include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
+include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
+include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/private/include")
+include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
+include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_http/private/include")
+include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_dfi/dynamic_function_interface")
+include_directories("${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include")
+include_directories("../dynamic_function_interface")
+
+SET_HEADER(BUNDLE_SYMBOLICNAME "apache_celix_remote_service_admin_dfi")
+SET(BUNDLE_VERSION "0.0.1")
+SET_HEADERS("Bundle-Name: Apache Celix Remote Service Admin Dynamic Function Interface (DFI)")
+
+bundle(remote_service_admin_dfi SOURCES
+    private/src/remote_service_admin_dfi.c
+    private/src/remote_service_admin_activator.c
+    private/src/export_registration_dfi.c
+    private/src/import_registration_dfi.c
+
+    ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
+
+    ${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)
+
+install_bundle(remote_service_admin_dfi)

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h b/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
new file mode 100644
index 0000000..4356646
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
@@ -0,0 +1,21 @@
+/**
+ * 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/rsa/private/include/import_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h b/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
new file mode 100644
index 0000000..ec885fd
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
@@ -0,0 +1,25 @@
+/**
+ * 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/rsa/private/include/remote_service_admin_http_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_http_impl.h b/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_http_impl.h
new file mode 100644
index 0000000..65ca83b
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_http_impl.h
@@ -0,0 +1,73 @@
+/**
+ *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/rsa/private/src/export_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
new file mode 100644
index 0000000..cc181b3
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
@@ -0,0 +1,239 @@
+/**
+ * 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, &reg->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, &reg->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/rsa/private/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
new file mode 100644
index 0000000..20ff61d
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
@@ -0,0 +1,318 @@
+#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/rsa/private/src/remote_service_admin_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c
new file mode 100644
index 0000000..9961a9b
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c
@@ -0,0 +1,122 @@
+/**
+ *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;
+}
+
+

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
new file mode 100644
index 0000000..c78cc19
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
@@ -0,0 +1,747 @@
+/**
+ *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_impl.c
+ *
+ *  \date       May 21, 2015
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <ifaddrs.h>
+#include <string.h>
+#include <uuid/uuid.h>
+#include <curl/curl.h>
+
+#include <jansson.h>
+
+#include "import_registration_dfi.h"
+#include "export_registration_dfi.h"
+#include "dyn_interface.h"
+
+#include "remote_service_admin.h"
+#include "remote_constants.h"
+#include "constants.h"
+#include "civetweb.h"
+
+// defines how often the webserver is restarted (with an increased port number)
+#define MAX_NUMBER_OF_RESTARTS 	5
+
+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;
+};
+
+struct post {
+    const char *readptr;
+    int size;
+};
+
+struct get {
+    char *writeptr;
+    int size;
+};
+
+#define OSGI_RSA_REMOTE_PROXY_FACTORY 	"remote_proxy_factory"
+#define OSGI_RSA_REMOTE_PROXY_TIMEOUT   "remote_proxy_timeout"
+
+static const char *data_response_headers =
+        "HTTP/1.1 200 OK\r\n"
+                "Cache: no-cache\r\n"
+                "Content-Type: application/json\r\n"
+                "\r\n";
+
+static const char *no_content_response_headers =
+        "HTTP/1.1 204 OK\r\n";
+
+// TODO do we need to specify a non-Amdatu specific configuration type?!
+static const char * const CONFIGURATION_TYPE = "org.amdatu.remote.admin.http";
+static const char * const ENDPOINT_URL = "org.amdatu.remote.admin.http.url";
+
+static const char *DEFAULT_PORT = "8888";
+static const char *DEFAULT_IP = "127.0.0.1";
+
+static const unsigned int DEFAULT_TIMEOUT = 0;
+
+static int remoteServiceAdmin_callback(struct mg_connection *conn);
+static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, char *interface, endpoint_description_pt *description);
+static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
+static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip);
+static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp);
+static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp);
+static void remoteServiceAdmin_log(remote_service_admin_pt admin, int level, const char *file, int line, const char *msg, ...);
+
+celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    *admin = calloc(1, sizeof(**admin));
+
+    if (!*admin) {
+        status = CELIX_ENOMEM;
+    } else {
+        unsigned int port_counter = 0;
+        char *port = NULL;
+        char *ip = NULL;
+        char *detectedIp = NULL;
+        (*admin)->context = context;
+        (*admin)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL);
+        (*admin)->importedServices = hashMap_create(NULL, NULL, NULL, NULL);
+
+        celixThreadMutex_create(&(*admin)->exportedServicesLock, NULL);
+        celixThreadMutex_create(&(*admin)->importedServicesLock, NULL);
+
+        if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
+            logHelper_start((*admin)->loghelper);
+            dynCommon_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
+            dynType_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
+            dynFunction_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
+            dynInterface_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
+        }
+
+        bundleContext_getProperty(context, "RSA_PORT", &port);
+        if (port == NULL) {
+            port = (char *)DEFAULT_PORT;
+        }
+
+        bundleContext_getProperty(context, "RSA_IP", &ip);
+        if (ip == NULL) {
+            char *interface = NULL;
+
+            bundleContext_getProperty(context, "RSA_INTERFACE", &interface);
+            if ((interface != NULL) && (remoteServiceAdmin_getIpAdress(interface, &detectedIp) != CELIX_SUCCESS)) {
+                logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: Could not retrieve IP adress for interface %s", interface);
+            }
+
+            if (ip == NULL) {
+                remoteServiceAdmin_getIpAdress(NULL, &detectedIp);
+            }
+
+            ip = detectedIp;
+        }
+
+        if (ip != NULL) {
+            logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Using %s for service annunciation", ip);
+            (*admin)->ip = strdup(ip);
+        }
+        else {
+            logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No IP address for service annunciation set. Using %s", DEFAULT_IP);
+            (*admin)->ip = (char*) DEFAULT_IP;
+        }
+
+        if (detectedIp != NULL) {
+            free(detectedIp);
+        }
+
+        // Prepare callbacks structure. We have only one callback, the rest are NULL.
+        struct mg_callbacks callbacks;
+        memset(&callbacks, 0, sizeof(callbacks));
+        callbacks.begin_request = remoteServiceAdmin_callback;
+
+        do {
+            char newPort[10];
+            const char *options[] = { "listening_ports", port, NULL};
+
+            (*admin)->ctx = mg_start(&callbacks, (*admin), options);
+
+            if ((*admin)->ctx != NULL) {
+                logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Start webserver: %s", port);
+                (*admin)->port = strdup(port);
+
+            }
+            else {
+                char* endptr = port;
+                int currentPort = strtol(port, &endptr, 10);
+
+                errno = 0;
+
+                if (*endptr || errno != 0) {
+                    currentPort = strtol(DEFAULT_PORT, NULL, 10);
+                }
+
+                port_counter++;
+                snprintf(&newPort[0], 6,  "%d", (currentPort+1));
+
+                logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_ERROR, "Error while starting rsa server on port %s - retrying on port %s...", port, newPort);
+                port = newPort;
+            }
+        } while(((*admin)->ctx == NULL) && (port_counter < MAX_NUMBER_OF_RESTARTS));
+
+    }
+    return status;
+}
+
+
+celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin)
+{
+    celix_status_t status = CELIX_SUCCESS;
+
+    free((*admin)->ip);
+    free((*admin)->port);
+    free(*admin);
+
+    //TODO destroy exports/imports
+
+    *admin = NULL;
+
+    return status;
+}
+
+
+celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    celixThreadMutex_lock(&admin->exportedServicesLock);
+
+    hash_map_iterator_pt iter = hashMapIterator_create(admin->exportedServices);
+    while (hashMapIterator_hasNext(iter)) {
+        array_list_pt exports = hashMapIterator_nextValue(iter);
+        int i;
+        for (i = 0; i < arrayList_size(exports); i++) {
+            export_registration_pt export = arrayList_get(exports, i);
+            if (export != NULL) {
+                exportRegistration_stop(export);
+            }
+        }
+    }
+    hashMapIterator_destroy(iter);
+    celixThreadMutex_unlock(&admin->exportedServicesLock);
+
+    celixThreadMutex_lock(&admin->importedServicesLock);
+
+    iter = hashMapIterator_create(admin->importedServices);
+    while (hashMapIterator_hasNext(iter))
+    {
+
+        hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+        import_registration_pt import = hashMapEntry_getValue(entry);
+
+        if (import != NULL) {
+            importRegistration_stop(import);
+        }
+    }
+
+    hashMapIterator_destroy(iter);
+    celixThreadMutex_unlock(&admin->importedServicesLock);
+
+    if (admin->ctx != NULL) {
+        logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Stopping webserver...");
+        mg_stop(admin->ctx);
+        admin->ctx = NULL;
+    }
+
+    hashMap_destroy(admin->exportedServices, false, false);
+    hashMap_destroy(admin->importedServices, false, false);
+
+    logHelper_stop(admin->loghelper);
+    logHelper_destroy(&admin->loghelper);
+
+    return status;
+}
+
+/**
+ * Request: http://host:port/services/{service}/{request}
+ */
+//void *remoteServiceAdmin_callback(enum mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info) {
+
+celix_status_t importRegistration_getFactory(import_registration_pt import, service_factory_pt *factory);
+
+static int remoteServiceAdmin_callback(struct mg_connection *conn) {
+    int result = 1; // zero means: let civetweb handle it further, any non-zero value means it is handled by us...
+
+    const struct mg_request_info *request_info = mg_get_request_info(conn);
+    if (request_info->uri != NULL) {
+        remote_service_admin_pt rsa = request_info->user_data;
+
+
+        if (strncmp(request_info->uri, "/service/", 9) == 0 && strcmp("POST", request_info->request_method) == 0) {
+
+            // uri = /services/myservice/call
+            const char *uri = request_info->uri;
+            // rest = myservice/call
+
+            const char *rest = uri+9;
+            char *interfaceStart = strchr(rest, '/');
+            int pos = interfaceStart - rest;
+            char service[pos+1];
+            strncpy(service, rest, pos);
+            service[pos] = '\0';
+            long serviceId = atol(service);
+
+            celixThreadMutex_lock(&rsa->exportedServicesLock);
+
+            //find endpoint
+            export_registration_pt export = NULL;
+            hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
+            while (hashMapIterator_hasNext(iter)) {
+                hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+                array_list_pt exports = hashMapEntry_getValue(entry);
+                int expIt = 0;
+                for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
+                    export_registration_pt check = arrayList_get(exports, expIt);
+                    export_reference_pt  ref = NULL;
+                    exportRegistration_getExportReference(check, &ref);
+                    endpoint_description_pt  checkEndpoint = NULL;
+                    exportReference_getExportedEndpoint(ref, &checkEndpoint);
+                    if (serviceId == checkEndpoint->serviceId) {
+                        export = check;
+                        break;
+                    }
+                }
+            }
+            hashMapIterator_destroy(iter);
+
+            if (export != NULL) {
+
+                uint64_t datalength = request_info->content_length;
+                char* data = malloc(datalength + 1);
+                mg_read(conn, data, datalength);
+                data[datalength] = '\0';
+
+                char *response = NULL;
+                int responceLength = 0;
+                int rc = exportRegistration_call(export, data, -1, &response, &responceLength);
+                //TODO check rc
+
+                if (response != NULL) {
+                    mg_write(conn, data_response_headers, strlen(data_response_headers));
+//              mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
+                    printf("writing response '%s'\n", response);
+                    mg_write(conn, response, strlen(response));
+//              mg_send_data(conn, response, strlen(response));
+//              mg_write_data(conn, response, strlen(response));
+
+                    free(response);
+                } else {
+                    mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
+                }
+                result = 1;
+
+                free(data);
+            } else {
+                result = 0;
+                //TODO log warning
+            }
+
+            celixThreadMutex_unlock(&rsa->exportedServicesLock);
+
+        }
+    }
+
+    return result;
+}
+
+celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    arrayList_create(registrations);
+    array_list_pt references = NULL;
+    service_reference_pt reference = NULL;
+    char filter [256];
+
+    snprintf(filter, 256, "(%s=%s)", (char *)OSGI_FRAMEWORK_SERVICE_ID, serviceId);
+
+    status = bundleContext_getServiceReferences(admin->context, NULL, filter, &references);
+
+    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: exportService called for serviceId %s", serviceId);
+
+    if (status == CELIX_SUCCESS && arrayList_size(references) >= 1) {
+        reference = arrayList_get(references, 0);
+    }
+
+    if(references != NULL){
+        arrayList_destroy(references);
+    }
+
+    if (reference == NULL) {
+        logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "ERROR: expected a reference for service id %s.", serviceId);
+        status = CELIX_ILLEGAL_STATE;
+    }
+
+    char *exports = NULL;
+    char *provided = NULL;
+    if (status == CELIX_SUCCESS) {
+        serviceReference_getProperty(reference, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exports);
+        serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_OBJECTCLASS, &provided);
+
+        if (exports == NULL || provided == NULL || strcmp(exports, provided) != 0) {
+            logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No Services to export.");
+            status = CELIX_ILLEGAL_STATE;
+        } else {
+            logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Export service (%s)", provided);
+        }
+    }
+
+    if (status == CELIX_SUCCESS) {
+        char *interface = provided;
+        endpoint_description_pt endpoint = NULL;
+        export_registration_pt registration = NULL;
+
+        remoteServiceAdmin_createEndpointDescription(admin, reference, interface, &endpoint);
+        printf("RSA: Creating export registration with endpoint pointer %p\n", endpoint);
+        //TOOD precheck if descriptor exists
+        status = exportRegistration_create(admin->loghelper, reference, endpoint, admin->context, &registration);
+        if (status == CELIX_SUCCESS) {
+            status = exportRegistration_start(registration);
+            if (status == CELIX_SUCCESS) {
+                arrayList_add(*registrations, registration);
+            }
+        }
+    }
+
+
+    if (status == CELIX_SUCCESS) {
+        celixThreadMutex_lock(&admin->exportedServicesLock);
+        hashMap_put(admin->exportedServices, reference, *registrations);
+        celixThreadMutex_unlock(&admin->exportedServicesLock);
+    }
+
+    return status;
+}
+
+celix_status_t remoteServiceAdmin_removeExportedService(export_registration_pt registration) {
+    celix_status_t status = CELIX_SUCCESS;
+    //TODO
+    /*
+    remote_service_admin_pt admin = registration->rsa;
+
+    celixThreadMutex_lock(&admin->exportedServicesLock);
+
+    hashMap_remove(admin->exportedServices, registration->reference);
+    //TODO stop ?
+
+    celixThreadMutex_unlock(&admin->exportedServicesLock);
+    */
+    return status;
+}
+
+static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, char *interface, endpoint_description_pt *endpoint) {
+    celix_status_t status = CELIX_SUCCESS;
+    properties_pt endpointProperties = properties_create();
+
+
+    unsigned int size = 0;
+    char **keys;
+
+    serviceReference_getPropertyKeys(reference, &keys, &size);
+    for (int i = 0; i < size; i++) {
+        char *key = keys[i];
+        char *value = NULL;
+
+        if (serviceReference_getProperty(reference, key, &value) == CELIX_SUCCESS
+            && strcmp(key, (char*) OSGI_RSA_SERVICE_EXPORTED_INTERFACES) != 0
+            && strcmp(key, (char*) OSGI_FRAMEWORK_OBJECTCLASS) != 0) {
+            properties_set(endpointProperties, key, value);
+            printf("Added property '%s' with value '%s'\n", key, value);
+        }
+    }
+
+    hash_map_entry_pt entry = hashMap_getEntry(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
+
+    char* key = hashMapEntry_getKey(entry);
+    char *serviceId = (char *) hashMap_remove(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
+    char *uuid = NULL;
+
+    char buf[512];
+    snprintf(buf, 512,  "/service/%s/%s", serviceId, interface);
+
+    char url[1024];
+    snprintf(url, 1024, "http://%s:%s%s", admin->ip, admin->port, buf);
+
+    uuid_t endpoint_uid;
+    uuid_generate(endpoint_uid);
+    char endpoint_uuid[37];
+    uuid_unparse_lower(endpoint_uid, endpoint_uuid);
+
+    bundleContext_getProperty(admin->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
+    properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
+    properties_set(endpointProperties, (char*) OSGI_FRAMEWORK_OBJECTCLASS, interface);
+    properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_SERVICE_ID, serviceId);
+    properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID, endpoint_uuid);
+    properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED, "true");
+    properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED_CONFIGS, (char*) CONFIGURATION_TYPE);
+    properties_set(endpointProperties, (char*) ENDPOINT_URL, url);
+
+
+
+    *endpoint = calloc(1, sizeof(**endpoint));
+    if (!*endpoint) {
+        status = CELIX_ENOMEM;
+    } else {
+        (*endpoint)->id = properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID);
+        char *serviceId = NULL;
+        serviceReference_getProperty(reference, (char*) OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
+        (*endpoint)->serviceId = strtoull(serviceId, NULL, 0);
+        (*endpoint)->frameworkUUID = properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
+        (*endpoint)->service = interface;
+        (*endpoint)->properties = endpointProperties;
+    }
+
+    free(key);
+    free(serviceId);
+    free(keys);
+
+    return status;
+}
+
+static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip) {
+    celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+
+    struct ifaddrs *ifaddr, *ifa;
+    char host[NI_MAXHOST];
+
+    if (getifaddrs(&ifaddr) != -1)
+    {
+        for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
+        {
+            if (ifa->ifa_addr == NULL)
+                continue;
+
+            if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
+                if (interface == NULL) {
+                    *ip = strdup(host);
+                    status = CELIX_SUCCESS;
+                }
+                else if (strcmp(ifa->ifa_name, interface) == 0) {
+                    *ip = strdup(host);
+                    status = CELIX_SUCCESS;
+                }
+            }
+        }
+
+        freeifaddrs(ifaddr);
+    }
+
+    return status;
+}
+
+
+celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description)
+{
+    celix_status_t status = CELIX_SUCCESS;
+
+    properties_destroy((*description)->properties);
+    free(*description);
+
+    return status;
+}
+
+
+celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services) {
+    celix_status_t status = CELIX_SUCCESS;
+    return status;
+}
+
+celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services) {
+    celix_status_t status = CELIX_SUCCESS;
+    return status;
+}
+
+celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpointDescription, import_registration_pt *out) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Import service %s", endpointDescription->service);
+
+    const char *objectClass = properties_get(endpointDescription->properties, "objectClass");
+    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "Registering service factory (proxy) for service '%s'\n", objectClass);
+
+
+    import_registration_pt import = NULL;
+    if (objectClass != NULL) {
+        status = importRegistration_create(admin->context, endpointDescription, objectClass, &import);
+    }
+    if (status == CELIX_SUCCESS) {
+        importRegistration_setSendFn(import, remoteServiceAdmin_send, admin);
+    }
+
+    if (status == CELIX_SUCCESS) {
+        status = importRegistration_start(import);
+    }
+
+    //celixThreadMutex_lock(&admin->importedServicesLock);
+    //TODO add to list
+    //celixThreadMutex_unlock(&admin->importedServicesLock);
+
+    if (status == CELIX_SUCCESS) {
+        *out = import;
+    }
+
+    return status;
+}
+
+
+celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration) {
+    celix_status_t status = CELIX_SUCCESS;
+    return status;
+    /*
+
+      endpoint_description_pt endpointDescription = (endpoint_description_pt) registration->endpointDescription;
+      import_registration_factory_pt registration_factory = NULL;
+
+      celixThreadMutex_lock(&admin->importedServicesLock);
+
+      registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
+
+      // factory available
+      if ((registration_factory == NULL) || (registration_factory->trackedFactory == NULL))
+      {
+          logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: Error while retrieving registration factory for imported service %s", endpointDescription->service);
+      }
+      else
+      {
+          registration_factory->trackedFactory->unregisterProxyService(registration_factory->trackedFactory->factory, endpointDescription);
+          arrayList_removeElement(registration_factory->registrations, registration);
+          importRegistration_destroy(registration);
+
+          if (arrayList_isEmpty(registration_factory->registrations))
+          {
+              logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: closing proxy.");
+
+              serviceTracker_close(registration_factory->proxyFactoryTracker);
+              importRegistrationFactory_close(registration_factory);
+
+              hashMap_remove(admin->importedServices, endpointDescription->service);
+
+              importRegistrationFactory_destroy(&registration_factory);
+          }
+      }
+
+      celixThreadMutex_unlock(&admin->importedServicesLock);
+
+      return status;
+    */
+}
+
+
+static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus) {
+    remote_service_admin_pt  rsa = handle;
+    struct post post;
+    post.readptr = request;
+    post.size = strlen(request);
+
+    struct get get;
+    get.size = 0;
+    get.writeptr = malloc(1);
+
+    char *serviceUrl = properties_get(endpointDescription->properties, (char*) ENDPOINT_URL);
+    char url[256];
+    snprintf(url, 256, "%s", serviceUrl);
+
+    // assume the default timeout
+    int timeout = DEFAULT_TIMEOUT;
+
+    char *timeoutStr = NULL;
+    // Check if the endpoint has a timeout, if so, use it.
+    timeoutStr = properties_get(endpointDescription->properties, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT);
+    if (timeoutStr == NULL) {
+        // If not, get the global variable and use that one.
+        bundleContext_getProperty(rsa->context, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT, &timeoutStr);
+    }
+
+    // Update timeout if a property is used to set it.
+    if (timeoutStr != NULL) {
+        timeout = atoi(timeoutStr);
+    }
+
+    celix_status_t status = CELIX_SUCCESS;
+    CURL *curl;
+    CURLcode res;
+
+    curl = curl_easy_init();
+    if(!curl) {
+        status = CELIX_ILLEGAL_STATE;
+    } else {
+        curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
+        curl_easy_setopt(curl, CURLOPT_URL, &url[0]);
+        curl_easy_setopt(curl, CURLOPT_POST, 1L);
+        curl_easy_setopt(curl, CURLOPT_READFUNCTION, remoteServiceAdmin_readCallback);
+        curl_easy_setopt(curl, CURLOPT_READDATA, &post);
+        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, remoteServiceAdmin_write);
+        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&get);
+        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)post.size);
+        logHelper_log(rsa->loghelper, OSGI_LOGSERVICE_DEBUG, "RSA: Performing curl post\n");
+        res = curl_easy_perform(curl);
+
+        *reply = get.writeptr;
+        *replyStatus = res;
+
+        curl_easy_cleanup(curl);
+    }
+
+    return status;
+}
+
+static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp) {
+    struct post *post = userp;
+
+    if (post->size) {
+        *(char *) ptr = post->readptr[0];
+        post->readptr++;
+        post->size--;
+        return 1;
+    }
+
+    return 0;
+}
+
+static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp) {
+    size_t realsize = size * nmemb;
+    struct get *mem = (struct get *)userp;
+
+    mem->writeptr = realloc(mem->writeptr, mem->size + realsize + 1);
+    if (mem->writeptr == NULL) {
+        /* out of memory! */
+        printf("not enough memory (realloc returned NULL)");
+        exit(EXIT_FAILURE);
+    }
+
+    memcpy(&(mem->writeptr[mem->size]), contents, realsize);
+    mem->size += realsize;
+    mem->writeptr[mem->size] = 0;
+
+    return realsize;
+}
+
+
+static void remoteServiceAdmin_log(remote_service_admin_pt admin, int level, const char *file, int line, const char *msg, ...) {
+    va_list ap;
+    va_start(ap, msg);
+    int levels[5] = {0, OSGI_LOGSERVICE_ERROR, OSGI_LOGSERVICE_WARNING, OSGI_LOGSERVICE_INFO, OSGI_LOGSERVICE_DEBUG};
+
+    char buf1[256];
+    snprintf(buf1, 256, "FILE:%s, LINE:%i, MSG:", file, line);
+
+    char buf2[256];
+    vsnprintf(buf2, 256, msg, ap);
+    logHelper_log(admin->loghelper, levels[level], "%s%s", buf1, buf2);
+}
\ No newline at end of file


[22/50] [abbrv] celix git commit: CELIX-237: Moved celix launcher to framework. Adjusted testing setup

Posted by pn...@apache.org.
CELIX-237: Moved celix launcher to framework. Adjusted testing setup


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

Branch: refs/heads/develop
Commit: 16853770c82d8744d4e30f168652e1021f87b068
Parents: fdade6a
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Aug 18 12:22:27 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Aug 18 12:22:27 2015 +0200

----------------------------------------------------------------------
 CMakeLists.txt                                  |   7 +-
 framework/CMakeLists.txt                        |   6 +-
 framework/private/src/celix_launcher.c          | 190 +++++++++++++++++++
 framework/public/include/celix_launcher.h       |  41 ++++
 launcher/CMakeLists.txt                         |   2 +-
 launcher/private/src/launcher.c                 | 190 -------------------
 launcher/private/src/main.c                     |   2 +-
 launcher/public/include/launcher.h              |  41 ----
 .../remote_service_admin_dfi/CMakeLists.txt     |  12 +-
 .../rsa_tst/CMakeLists.txt                      |   2 -
 .../rsa_tst/rsa_client_server_tests.cpp         |   2 +-
 .../rsa_tst/rsa_tests.cpp                       |   2 +-
 12 files changed, 249 insertions(+), 248 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/16853770/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 137c81b..2f78e1f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,7 +41,12 @@ SET(CELIX_MINOR "0")
 SET(CELIX_MICRO "0")
 SET(CELIX_QUALIFIER "")
 
-enable_testing()
+option(ENABLE_TESTING "Enables unit/bundle testing" FALSE)
+
+if (ENABLE_TESTING)
+	enable_testing()
+endif()
+
 
 include(CMakeCelix)
 include(cmake_celix/installation)

http://git-wip-us.apache.org/repos/asf/celix/blob/16853770/framework/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt
index 1719d2c..429dd04 100644
--- a/framework/CMakeLists.txt
+++ b/framework/CMakeLists.txt
@@ -55,7 +55,7 @@ if (FRAMEWORK)
 	 private/src/requirement.c private/src/resolver.c private/src/service_reference.c private/src/service_registration.c 
 	 private/src/service_registry.c private/src/service_tracker.c private/src/service_tracker_customizer.c
 	 private/src/unzip.c private/src/utils.c private/src/version.c private/src/version_range.c private/src/wire.c
-	 private/src/celix_log.c
+	 private/src/celix_log.c private/src/celix_launcher.c
 
 	 private/include/attribute.h public/include/framework_exports.h
 
@@ -81,7 +81,7 @@ if (FRAMEWORK)
     INSTALL(DIRECTORY "${PROJECT_SOURCE_DIR}/cmake/" DESTINATION share/celix/cmake/modules COMPONENT framework) 
 
 	celix_subproject(FRAMEWORK_TESTS "Option to build the framework tests" "OFF" DEPS)
-    if (FRAMEWORK_TESTS)
+    if (ENABLE_TESTING AND FRAMEWORK_TESTS)
     	find_package(CppUTest REQUIRED)
     	
 	    include_directories(${CPPUTEST_INCLUDE_DIR})
@@ -374,5 +374,5 @@ if (FRAMEWORK)
         SETUP_TARGET_FOR_COVERAGE(attribute_test_c attribute_test ${CMAKE_BINARY_DIR}/coverage/attribute_test)
 		SETUP_TARGET_FOR_COVERAGE(wire_test_c wire_test ${CMAKE_BINARY_DIR}/coverage/wire_test)
 		
-	endif (FRAMEWORK_TESTS)
+	endif (ENABLE_TESTING AND FRAMEWORK_TESTS)
 endif (FRAMEWORK)

http://git-wip-us.apache.org/repos/asf/celix/blob/16853770/framework/private/src/celix_launcher.c
----------------------------------------------------------------------
diff --git a/framework/private/src/celix_launcher.c b/framework/private/src/celix_launcher.c
new file mode 100644
index 0000000..bc6bd34
--- /dev/null
+++ b/framework/private/src/celix_launcher.c
@@ -0,0 +1,190 @@
+/**
+ *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.
+ */
+/*
+ * celix_launcher.c
+ *
+ *  \date       Mar 23, 2010
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+
+#include "celix_launcher.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <libgen.h>
+#include <signal.h>
+
+#ifndef CELIX_NO_CURLINIT
+#include <curl/curl.h>
+#endif
+
+#include "framework.h"
+#include "linked_list_iterator.h"
+
+#ifdef WITH_APR
+static apr_pool_t *memoryPool;
+#endif
+
+int celixLauncher_launch(const char *configFile, framework_pt *framework) {
+    int status = 0;
+    FILE *config = fopen(configFile, "r");
+    if (config != NULL) {
+        status = celixLauncher_launchWithStream(config, framework);
+    } else {
+        fprintf(stderr, "Error: invalid or non-existing configuration file: '%s'.", configFile);
+        perror("");
+        status = 1;
+    }
+    return status;
+}
+
+int celixLauncher_launchWithStream(FILE *stream, framework_pt *framework) {
+    int status = 0;
+
+    properties_pt config = properties_loadWithStream(stream);
+    fclose(stream);
+    // Make sure we've read it and that nothing went wrong with the file access...
+    if (config == NULL) {
+        fprintf(stderr, "Error: invalid configuration file");
+        perror(NULL);
+        status = 1;
+    }
+
+
+#ifdef WITH_APR
+    apr_status_t rv;
+    apr_status_t s;
+#endif
+
+#ifndef CELIX_NO_CURLINIT
+    // Before doing anything else, let's setup Curl
+    curl_global_init(CURL_GLOBAL_NOTHING);
+#endif
+
+#ifdef WITH_APR
+	rv = apr_initialize();
+    if (rv != APR_SUCCESS) {
+        return CELIX_START_ERROR;
+    }
+
+    s = apr_pool_create(&memoryPool, NULL);
+    if (s != APR_SUCCESS) {
+        return CELIX_START_ERROR;
+    }
+#endif
+
+
+    if (status == 0) {
+        char *autoStart = properties_get(config, "cosgi.auto.start.1");
+        celix_status_t status;
+#ifdef WITH_APR
+        status = framework_create(framework, memoryPool, config);
+#else
+        status = framework_create(framework, config);
+#endif
+        bundle_pt fwBundle = NULL;
+        if (status == CELIX_SUCCESS) {
+            status = fw_init(*framework);
+            if (status == CELIX_SUCCESS) {
+                // Start the system bundle
+                framework_getFrameworkBundle(*framework, &fwBundle);
+                bundle_start(fwBundle);
+
+                char delims[] = " ";
+                char *result = NULL;
+                char *save_ptr = NULL;
+                linked_list_pt bundles;
+                array_list_pt installed = NULL;
+                bundle_context_pt context = NULL;
+                linked_list_iterator_pt iter = NULL;
+                unsigned int i;
+
+                linkedList_create(&bundles);
+                result = strtok_r(autoStart, delims, &save_ptr);
+                while (result != NULL) {
+                    char *location = strdup(result);
+                    linkedList_addElement(bundles, location);
+                    result = strtok_r(NULL, delims, &save_ptr);
+                }
+                // First install all bundles
+                // Afterwards start them
+                arrayList_create(&installed);
+                bundle_getContext(fwBundle, &context);
+                iter = linkedListIterator_create(bundles, 0);
+                while (linkedListIterator_hasNext(iter)) {
+                    bundle_pt current = NULL;
+                    char *location = (char *) linkedListIterator_next(iter);
+                    if (bundleContext_installBundle(context, location, &current) == CELIX_SUCCESS) {
+                        // Only add bundle if it is installed correctly
+                        arrayList_add(installed, current);
+                    } else {
+                        printf("Could not install bundle from %s\n", location);
+                    }
+                    linkedListIterator_remove(iter);
+                    free(location);
+                }
+                linkedListIterator_destroy(iter);
+                linkedList_destroy(bundles);
+
+                for (i = 0; i < arrayList_size(installed); i++) {
+                    bundle_pt installedBundle = (bundle_pt) arrayList_get(installed, i);
+                    bundle_startWithOptions(installedBundle, 0);
+                }
+
+                arrayList_destroy(installed);
+            }
+        }
+
+        if (status != CELIX_SUCCESS) {
+            printf("Problem creating framework\n");
+        }
+
+        printf("Launcher: Framework Started\n");
+    }
+
+    return status;
+}
+
+void celixLauncher_waitForShutdown(framework_pt framework) {
+    framework_waitForStop(framework);
+}
+
+void celixLauncher_destroy(framework_pt framework) {
+    framework_destroy(framework);
+
+    #ifdef WITH_APR
+        apr_pool_destroy(memoryPool);
+        apr_terminate();
+    #endif
+
+    #ifndef CELIX_NO_CURLINIT
+        // Cleanup Curl
+        curl_global_cleanup();
+    #endif
+
+    printf("Launcher: Exit\n");
+}
+
+void celixLauncher_stop(framework_pt framework) {
+    bundle_pt fwBundle = NULL;
+    framework_getFrameworkBundle(framework, &fwBundle);
+    bundle_stop(fwBundle);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/16853770/framework/public/include/celix_launcher.h
----------------------------------------------------------------------
diff --git a/framework/public/include/celix_launcher.h b/framework/public/include/celix_launcher.h
new file mode 100644
index 0000000..a5d375f
--- /dev/null
+++ b/framework/public/include/celix_launcher.h
@@ -0,0 +1,41 @@
+/**
+ *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.
+ */
+/*
+ * celix_launcher.h
+ *
+ *  \date       Jul 30, 2015
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+
+#ifndef CELIX_LAUNCHER_H
+#define CELIX_LAUNCHER_H
+
+#include <stdio.h>
+#include "framework.h"
+
+int celixLauncher_launch(const char *configFile, framework_pt *framework);
+int celixLauncher_launchWithStream(FILE *config, framework_pt *framework);
+
+void celixLauncher_stop(framework_pt framework);
+void celixLauncher_destroy(framework_pt framework);
+
+void celixLauncher_waitForShutdown(framework_pt framework);
+
+#endif //CELIX_LAUNCHER_H

http://git-wip-us.apache.org/repos/asf/celix/blob/16853770/launcher/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index dac0ce7..e1f9a9c 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -26,7 +26,7 @@ if (LAUNCHER)
     
     add_executable(celix
         private/src/main
-        private/src/launcher)
+    )
     
     target_link_libraries(celix celix_framework ${CURL_LIBRARIES})
     include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")

http://git-wip-us.apache.org/repos/asf/celix/blob/16853770/launcher/private/src/launcher.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/launcher.c b/launcher/private/src/launcher.c
deleted file mode 100644
index a6297a0..0000000
--- a/launcher/private/src/launcher.c
+++ /dev/null
@@ -1,190 +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.
- */
-/*
- * launcher.c
- *
- *  \date       Mar 23, 2010
- *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright	Apache License, Version 2.0
- */
-
-#include "launcher.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <libgen.h>
-#include <signal.h>
-
-#ifndef CELIX_NO_CURLINIT
-#include <curl/curl.h>
-#endif
-
-#include "framework.h"
-#include "linked_list_iterator.h"
-
-#ifdef WITH_APR
-static apr_pool_t *memoryPool;
-#endif
-
-int celixLauncher_launch(const char *configFile, framework_pt *framework) {
-    int status = 0;
-    FILE *config = fopen(configFile, "r");
-    if (config != NULL) {
-        status = celixLauncher_launchWithStream(config, framework);
-    } else {
-        fprintf(stderr, "Error: invalid or non-existing configuration file: '%s'.", configFile);
-        perror("");
-        status = 1;
-    }
-    return status;
-}
-
-int celixLauncher_launchWithStream(FILE *stream, framework_pt *framework) {
-    int status = 0;
-
-    properties_pt config = properties_loadWithStream(stream);
-    fclose(stream);
-    // Make sure we've read it and that nothing went wrong with the file access...
-    if (config == NULL) {
-        fprintf(stderr, "Error: invalid configuration file");
-        perror(NULL);
-        status = 1;
-    }
-
-
-#ifdef WITH_APR
-    apr_status_t rv;
-    apr_status_t s;
-#endif
-
-#ifndef CELIX_NO_CURLINIT
-    // Before doing anything else, let's setup Curl
-    curl_global_init(CURL_GLOBAL_NOTHING);
-#endif
-
-#ifdef WITH_APR
-	rv = apr_initialize();
-    if (rv != APR_SUCCESS) {
-        return CELIX_START_ERROR;
-    }
-
-    s = apr_pool_create(&memoryPool, NULL);
-    if (s != APR_SUCCESS) {
-        return CELIX_START_ERROR;
-    }
-#endif
-
-
-    if (status == 0) {
-        char *autoStart = properties_get(config, "cosgi.auto.start.1");
-        celix_status_t status;
-#ifdef WITH_APR
-        status = framework_create(framework, memoryPool, config);
-#else
-        status = framework_create(framework, config);
-#endif
-        bundle_pt fwBundle = NULL;
-        if (status == CELIX_SUCCESS) {
-            status = fw_init(*framework);
-            if (status == CELIX_SUCCESS) {
-                // Start the system bundle
-                framework_getFrameworkBundle(*framework, &fwBundle);
-                bundle_start(fwBundle);
-
-                char delims[] = " ";
-                char *result = NULL;
-                char *save_ptr = NULL;
-                linked_list_pt bundles;
-                array_list_pt installed = NULL;
-                bundle_context_pt context = NULL;
-                linked_list_iterator_pt iter = NULL;
-                unsigned int i;
-
-                linkedList_create(&bundles);
-                result = strtok_r(autoStart, delims, &save_ptr);
-                while (result != NULL) {
-                    char *location = strdup(result);
-                    linkedList_addElement(bundles, location);
-                    result = strtok_r(NULL, delims, &save_ptr);
-                }
-                // First install all bundles
-                // Afterwards start them
-                arrayList_create(&installed);
-                bundle_getContext(fwBundle, &context);
-                iter = linkedListIterator_create(bundles, 0);
-                while (linkedListIterator_hasNext(iter)) {
-                    bundle_pt current = NULL;
-                    char *location = (char *) linkedListIterator_next(iter);
-                    if (bundleContext_installBundle(context, location, &current) == CELIX_SUCCESS) {
-                        // Only add bundle if it is installed correctly
-                        arrayList_add(installed, current);
-                    } else {
-                        printf("Could not install bundle from %s\n", location);
-                    }
-                    linkedListIterator_remove(iter);
-                    free(location);
-                }
-                linkedListIterator_destroy(iter);
-                linkedList_destroy(bundles);
-
-                for (i = 0; i < arrayList_size(installed); i++) {
-                    bundle_pt installedBundle = (bundle_pt) arrayList_get(installed, i);
-                    bundle_startWithOptions(installedBundle, 0);
-                }
-
-                arrayList_destroy(installed);
-            }
-        }
-
-        if (status != CELIX_SUCCESS) {
-            printf("Problem creating framework\n");
-        }
-
-        printf("Launcher: Framework Started\n");
-    }
-
-    return status;
-}
-
-void celixLauncher_waitForShutdown(framework_pt framework) {
-    framework_waitForStop(framework);
-}
-
-void celixLauncher_destroy(framework_pt framework) {
-    framework_destroy(framework);
-
-    #ifdef WITH_APR
-        apr_pool_destroy(memoryPool);
-        apr_terminate();
-    #endif
-
-    #ifndef CELIX_NO_CURLINIT
-        // Cleanup Curl
-        curl_global_cleanup();
-    #endif
-
-    printf("Launcher: Exit\n");
-}
-
-void celixLauncher_stop(framework_pt framework) {
-    bundle_pt fwBundle = NULL;
-    framework_getFrameworkBundle(framework, &fwBundle);
-    bundle_stop(fwBundle);
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/16853770/launcher/private/src/main.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/main.c b/launcher/private/src/main.c
index 90e5612..ec72d03 100644
--- a/launcher/private/src/main.c
+++ b/launcher/private/src/main.c
@@ -28,7 +28,7 @@
 #include <curl/curl.h>
 #include <signal.h>
 #include <libgen.h>
-#include "launcher.h"
+#include "celix_launcher.h"
 
 static void show_usage(char* prog_name);
 static void shutdown_framework(int signal);

http://git-wip-us.apache.org/repos/asf/celix/blob/16853770/launcher/public/include/launcher.h
----------------------------------------------------------------------
diff --git a/launcher/public/include/launcher.h b/launcher/public/include/launcher.h
deleted file mode 100644
index 6077e03..0000000
--- a/launcher/public/include/launcher.h
+++ /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.
- */
-/*
- * launcher.h
- *
- *  \date       Jul 30, 2015
- *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright	Apache License, Version 2.0
- */
-
-#ifndef CELIX_LAUNCHER_H
-#define CELIX_LAUNCHER_H
-
-#include <stdio.h>
-#include "framework.h"
-
-int celixLauncher_launch(const char *configFile, framework_pt *framework);
-int celixLauncher_launchWithStream(FILE *config, framework_pt *framework);
-
-void celixLauncher_stop(framework_pt framework);
-void celixLauncher_destroy(framework_pt framework);
-
-void celixLauncher_waitForShutdown(framework_pt framework);
-
-#endif //CELIX_LAUNCHER_H

http://git-wip-us.apache.org/repos/asf/celix/blob/16853770/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 7f9404c..9d6db45 100644
--- a/remote_services/remote_service_admin_dfi/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/CMakeLists.txt
@@ -20,15 +20,13 @@ if (RSA_REMOTE_SERVICE_ADMIN_DFI)
         include_directories(dynamic_function_interface/memstream)
     endif()
 
-    #TODO if test check
-    include_directories(${CPPUTEST_INCLUDE_DIR})
-
-
     add_subdirectory(dynamic_function_interface)
     add_subdirectory(rsa)
 
-    #TODO if test check
-    add_subdirectory(dynamic_function_interface_tst)
-    add_subdirectory(rsa_tst)
+    if (ENABLE_TESTING)
+        include_directories(${CPPUTEST_INCLUDE_DIR})
+        add_subdirectory(dynamic_function_interface_tst)
+        add_subdirectory(rsa_tst)
+    endif()
 
 endif()
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/16853770/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 82d908b..076231c 100644
--- a/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
@@ -4,7 +4,6 @@
 
 
 include_directories(
-    ${PROJECT_SOURCE_DIR}/launcher/public/include
     ${PROJECT_SOURCE_DIR}/framework/public/include
     ${PROJECT_SOURCE_DIR}/utils/public/include
     ${PROJECT_SOURCE_DIR}/utils/public/include
@@ -24,7 +23,6 @@ add_executable(test_rsa_dfi
     rsa_tests.cpp
     rsa_client_server_tests.cpp
 
-    ${PROJECT_SOURCE_DIR}/launcher/private/src/launcher.c #TODO move to libframework
     ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
 )
 target_link_libraries(test_rsa_dfi celix_framework celix_utils ${CURL_LIBRARIES} ${CPPUTEST_LIBRARY})

http://git-wip-us.apache.org/repos/asf/celix/blob/16853770/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp b/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp
index 35beffe..c1b9b91 100644
--- a/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp
@@ -17,7 +17,7 @@ extern "C" {
 #include <ctype.h>
 #include <unistd.h>
 
-#include "launcher.h"
+#include "celix_launcher.h"
 #include "framework.h"
 #include "remote_service_admin.h"
 #include "calculator_service.h"

http://git-wip-us.apache.org/repos/asf/celix/blob/16853770/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp b/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp
index 1384573..c56a677 100644
--- a/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp
@@ -15,7 +15,7 @@ extern "C" {
 #include <string.h>
 #include <ctype.h>
 
-#include "launcher.h"
+#include "celix_launcher.h"
 #include "framework.h"
 #include "remote_service_admin.h"
 #include "calculator_service.h"


[31/50] [abbrv] celix git commit: CELIX-237: Added support for handling reply for output pointers.

Posted by pn...@apache.org.
CELIX-237: Added support for handling reply for output pointers.


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

Branch: refs/heads/develop
Commit: 2d6ef1ba83abee0a62b6aa726dbaed4cea4f1742
Parents: f99de6e
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Mon Sep 7 13:44:11 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon Sep 7 13:44:11 2015 +0200

----------------------------------------------------------------------
 .../dynamic_function_interface/dyn_function.c   | 37 ++++++++-
 .../dynamic_function_interface/dyn_function.h   |  8 ++
 .../dynamic_function_interface/dyn_interface.c  | 12 +++
 .../dynamic_function_interface/dyn_type.c       |  1 -
 .../dynamic_function_interface/json_rpc.c       | 87 ++++++++++++--------
 .../json_rpc_tests.cpp                          | 49 ++++++++++-
 6 files changed, 154 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/2d6ef1ba/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
index e059078..7a6a24d 100644
--- 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
@@ -27,7 +27,7 @@ typedef struct _dyn_function_argument_type dyn_function_argument_type;
 struct _dyn_function_argument_type {
     int index;
     char *name;
-    int argumentType;
+    enum dyn_function_argument_meta argumentMeta;
     dyn_type *type;
     TAILQ_ENTRY(_dyn_function_argument_type) entries;
 };
@@ -65,8 +65,27 @@ int dynFunction_parse(FILE *descriptor, struct types_head *refTypes, dyn_functio
         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 == 0) {
+    if (status == OK) {
         *out = dynFunc;
     }    else {
         if (dynFunc != NULL) {
@@ -156,6 +175,20 @@ static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descrip
     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;

http://git-wip-us.apache.org/repos/asf/celix/blob/2d6ef1ba/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
index de8853c..b756e76 100644
--- 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
@@ -22,11 +22,19 @@ 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);

http://git-wip-us.apache.org/repos/asf/celix/blob/2d6ef1ba/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
index 5cd7104..ab436b7 100644
--- 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
@@ -279,6 +279,18 @@ static int dynInterface_parseMethods(dyn_interface_type *intf, FILE *stream) {
                 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;

http://git-wip-us.apache.org/repos/asf/celix/blob/2d6ef1ba/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
index 70f6a7b..3967e15 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
@@ -452,7 +452,6 @@ static int dynType_parseSequence(FILE *stream, dyn_type *type) {
     if (status == OK) {
         type->ffiType = &type->sequence.seqType;
         dynType_prepCif(&type->sequence.seqType);
-        LOG_DEBUG("seq size is %zu\n", type->ffiType->size);
     }
 
     return status;

http://git-wip-us.apache.org/repos/asf/celix/blob/2d6ef1ba/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
index 9acd3fb..56c237c 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
@@ -87,16 +87,16 @@ int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request, c
 
     for (i = 0; i < nrOfArgs; i += 1) {
         dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
-        const char *argMeta = dynType_getMetaInfo(argType, "am");
-        if (argMeta == NULL) {
+        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 (strcmp(argMeta, "pre") == 0) {
+        } else if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
             dynType_alloc(argType, &args[i]);
-        } else if (strcmp(argMeta, "out") == 0) {
+        } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) {
             void *inMemPtr = calloc(1, sizeof(void *));
             args[i] = &inMemPtr;
-        } else if (strcmp(argMeta, "handle") == 0) {
+        } else if (meta == DYN_FUNCTION_ARGUMENT_META__HANDLE) {
             args[i] = &handle;
         }
 
@@ -127,15 +127,15 @@ int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request, c
     if (funcCallStatus == 0 && status == OK) {
         for (i = 0; i < nrOfArgs; i += 1) {
             dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
-            const char *argMeta = dynType_getMetaInfo(argType, "am");
-            if (argMeta == NULL) {
+            enum dyn_function_argument_meta  meta = dynFunction_argumentMetaForIndex(func, i);
+            if (meta == DYN_FUNCTION_ARGUMENT_META__STD) {
                 dynType_free(argType, args[i]);
-            } else if (strcmp(argMeta, "pre") == 0) {
+            } else 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 (strcmp(argMeta, "out") == 0) {
+            } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) {
                 void ***out = args[i];
                 if (out != NULL && *out != NULL && **out != NULL) {
                     status = jsonSerializer_serializeJson(argType, out, &jsonResult);
@@ -179,7 +179,6 @@ int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request, c
         free(response);
     }
 
-    //TODO free args (created by jsonSerializer and dynType_alloc) (dynType_free)
     return status;
 }
 
@@ -198,8 +197,8 @@ int jsonRpc_prepareInvokeRequest(dyn_function_type *func, const char *id, void *
     int nrOfArgs = dynFunction_nrOfArguments(func);
     for (i = 0; i < nrOfArgs; i +=1) {
         dyn_type *type = dynFunction_argumentTypeForIndex(func, i);
-        const char *argMeta = dynType_getMetaInfo(type, "am");
-        if (argMeta == NULL) {
+        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);
@@ -225,31 +224,51 @@ int jsonRpc_prepareInvokeRequest(dyn_function_type *func, const char *id, void *
 }
 
 int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void *args[]) {
-    int status = 0;
+    int status = OK;
 
-    json_t *replyJson = json_loads(reply, JSON_DECODE_ANY, NULL); //TODO check
-    json_t *result = json_object_get(replyJson, "r"); //TODO check
+    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);
+    }
 
-    LOG_DEBUG("replyJson ptr is %p and result ptr is %p\n", replyJson, result);
+    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);
+        }
+    }
 
-    int nrOfArgs = dynFunction_nrOfArguments(func);
-    int i;
-    for (i = 0; i < nrOfArgs; i += 1) {
-        dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
-        const char *argMeta = dynType_getMetaInfo(argType, "am");
-        if (argMeta == NULL) {
-            //skip
-        } else if (strcmp(argMeta, "pre") == 0) {
-            dyn_type *subType = NULL;
-            dynType_typedPointer_getTypedType(argType, &subType);
-            void *tmp = NULL;
-            size_t size = dynType_size(subType);
-            status = jsonSerializer_deserializeJson(subType, result, &tmp);
-            void **out = (void **)args[i];
-            memcpy(*out, tmp, size);
-            dynType_free(subType, tmp);
-        } else if (strcmp(argMeta, "out") == 0) {
-            assert(false); //TODO
+    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) {
+                //FIXME need a tmp because deserialize does always does a create (add option?)
+                dyn_type *subType = NULL;
+                dynType_typedPointer_getTypedType(argType, &subType);
+                void *tmp = NULL;
+                size_t size = dynType_size(subType);
+                status = jsonSerializer_deserializeJson(subType, result, &tmp);
+                void **out = (void **)args[i];
+                memcpy(*out, tmp, size);
+                dynType_free(subType, tmp);
+            } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) {
+                dyn_type *subType = NULL;
+                dynType_typedPointer_getTypedType(argType, &subType);
+                dyn_type *subSubType = NULL;
+                dynType_typedPointer_getTypedType(subType, &subSubType);
+                void ***out = (void **)args[i];
+                //status = jsonSerializer_deserializeJson(subType, result, *out);
+                status = jsonSerializer_deserializeJson(subSubType, result, *out);
+            } else {
+                //skip
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/2d6ef1ba/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
index 5e116a5..6ebf1c3 100644
--- 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
@@ -59,7 +59,7 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
         dynFunction_destroy(dynFunc);
     }
 
-    void handleTest(void) {
+    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);
@@ -182,6 +182,45 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
         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);
+
+        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);
+    }
+
 }
 
 TEST_GROUP(JsonRpcTests) {
@@ -202,8 +241,12 @@ TEST(JsonRpcTests, prepareTest) {
     prepareTest();
 }
 
-TEST(JsonRpcTests, handleTest) {
-    handleTest();
+TEST(JsonRpcTests, handleTestPre) {
+    handleTestPre();
+}
+
+TEST(JsonRpcTests, handleTestOut) {
+    handleTestOut();
 }
 
 TEST(JsonRpcTests, callPre) {


[24/50] [abbrv] celix git commit: CELIX-237: Enabled testing for travis config

Posted by pn...@apache.org.
CELIX-237: Enabled testing for travis config


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

Branch: refs/heads/develop
Commit: b6f2ae4ea6ee5df3b3841ac4e350b6148431f61b
Parents: b5d2367
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Aug 18 13:31:03 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Aug 18 13:31:03 2015 +0200

----------------------------------------------------------------------
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/b6f2ae4e/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index 58d767d..3a3cfb7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -22,7 +22,7 @@ before_script:
     - cd ..
     - mkdir build install
     - cd build
-    - cmake -DCMAKE_SKIP_BUILD_RPATH=TRUE -DBUILD_DEPLOYMENT_ADMIN=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 -DCMAKE_INSTALL_PREFIX=../install ..
+    - cmake -DENABLE_TESTING=ON -DCMAKE_SKIP_BUILD_RPATH=TRUE -DBUILD_DEPLOYMENT_ADMIN=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 -DCMAKE_INSTALL_PREFIX=../install ..
 
 script: 
     - make all 


[37/50] [abbrv] celix git commit: CELIX-237: Forward remove endpoint call from rsa to import_registration. Removed status check for mutex unlock in top man. This causes deadlocks when an error occurs

Posted by pn...@apache.org.
CELIX-237: Forward remove endpoint call from rsa to import_registration. Removed status check for mutex unlock in top man. This causes deadlocks when an error occurs


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

Branch: refs/heads/develop
Commit: a477ab96cf01896d360b71823e6302b942271840
Parents: 313452d
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Sep 16 12:45:19 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Sep 16 12:45:19 2015 +0200

----------------------------------------------------------------------
 .../private/include/import_registration_dfi.h   |   3 +-
 .../rsa/private/src/import_registration_dfi.c   |  40 ++++---
 .../rsa/private/src/remote_service_admin_dfi.c  |  52 ++--------
 .../private/src/topology_manager.c              | 104 +++++++++----------
 4 files changed, 86 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/a477ab96/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h b/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
index 6f2a232..6aa1b26 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
+++ b/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
@@ -10,8 +10,7 @@
 
 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, void (*rsaCallback)(void *, import_registration_pt),
-                                         void *rsaHandle, endpoint_description_pt description, const char *classObject,
+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);
 

http://git-wip-us.apache.org/repos/asf/celix/blob/a477ab96/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
index d192e29..56144d9 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
@@ -10,6 +10,9 @@ struct import_registration {
     bundle_context_pt context;
     endpoint_description_pt  endpoint; //TODO owner? -> free when destroyed
     const char *classObject; //NOTE owned by endpoint
+
+    celix_thread_mutex_t mutex; //protects send & sendhandle
+
     send_func_type send;
     void *sendHandle;
 
@@ -17,9 +20,6 @@ struct import_registration {
     service_registration_pt factoryReg;
 
     hash_map_pt proxies; //key -> bundle, value -> service_proxy
-
-    void (*rsaCloseImportCallback)(void *, import_registration_pt);
-    void *rsaHandle;
 };
 
 struct service_proxy {
@@ -33,8 +33,7 @@ static celix_status_t importRegistration_createProxy(import_registration_pt impo
 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, void (*rsaCallback)(void *, import_registration_pt),
-                                         void *rsaHandle, endpoint_description_pt endpoint, const char *classObject,
+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));
@@ -45,11 +44,10 @@ celix_status_t importRegistration_create(bundle_context_pt context, void (*rsaCa
 
     if (reg != NULL && reg->factory != NULL) {
         reg->context = context;
-        reg->rsaCloseImportCallback = rsaCallback;
-        reg->rsaHandle = rsaHandle;
         reg->endpoint = endpoint;
         reg->classObject = classObject;
         reg->proxies = hashMap_create(NULL, NULL, NULL, NULL);
+        celixThreadMutex_create(&reg->mutex, NULL);
 
         reg->factory->factory = reg;
         reg->factory->getService = (void *)importRegistration_getService;
@@ -70,8 +68,10 @@ celix_status_t importRegistration_create(bundle_context_pt context, void (*rsaCa
 celix_status_t importRegistration_setSendFn(import_registration_pt reg,
                                             send_func_type send,
                                             void *handle) {
+    celixThreadMutex_lock(&reg->mutex);
     reg->send = send;
     reg->sendHandle = handle;
+    celixThreadMutex_unlock(&reg->mutex);
 
     return CELIX_SUCCESS;
 }
@@ -79,7 +79,12 @@ celix_status_t importRegistration_setSendFn(import_registration_pt reg,
 void importRegistration_destroy(import_registration_pt import) {
     if (import != NULL) {
         if (import->proxies != NULL) {
-            //TODO destroy proxies
+            hash_map_iterator_pt  iter = hashMapIterator_create(import->proxies);
+            while (hashMapIterator_hasNext(iter)) {
+                struct service_proxy *proxy = hashMapIterator_nextEntry(iter);
+                importRegistration_destroyProxy(proxy);
+            }
+            hashMapIterator_destroy(iter);
             hashMap_destroy(import->proxies, false, false);
             import->proxies = NULL;
         }
@@ -121,6 +126,7 @@ celix_status_t importRegistration_getService(import_registration_pt import, bund
     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);
@@ -207,13 +213,8 @@ static celix_status_t importRegistration_createProxy(import_registration_pt impo
             dynInterface_destroy(proxy->intf);
             proxy->intf = NULL;
         }
-        if (proxy->service != NULL) {
-            free(proxy->service);
-            proxy->service = NULL;
-        }
-        if (proxy != NULL) {
-            free(proxy);
-        }
+        free(proxy->service);
+        free(proxy);
     }
 
     return status;
@@ -235,11 +236,16 @@ static void importRegistration_proxyFunc(void *userData, void *args[], void *ret
         //printf("Need to send following json '%s'\n", invokeRequest);
     }
 
+
     if (status == CELIX_SUCCESS) {
         char *reply = NULL;
         int rc = 0;
         //printf("sending request\n");
-        import->send(import->sendHandle, import->endpoint, invokeRequest, &reply, &rc);
+        celixThreadMutex_lock(&import->mutex);
+        if (import->send != NULL) {
+            import->send(import->sendHandle, import->endpoint, invokeRequest, &reply, &rc);
+        }
+        celixThreadMutex_unlock(&import->mutex);
         //printf("request sended. got reply '%s' with status %i\n", reply, rc);
 
         if (rc == 0) {
@@ -295,7 +301,7 @@ static void importRegistration_destroyProxy(struct service_proxy *proxy) {
 
 celix_status_t importRegistration_close(import_registration_pt registration) {
     celix_status_t status = CELIX_SUCCESS;
-    registration->rsaCloseImportCallback(registration->rsaHandle, registration);
+    importRegistration_stop(registration);
     return status;
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/a477ab96/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
index 8eadbdb..c12d0aa 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
@@ -173,7 +173,7 @@ celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_servi
 
         do {
             char newPort[10];
-            const char *options[] = { "listening_ports", port, NULL};
+            const char *options[] = { "listening_ports", port, "num_threads", "5", NULL};
 
             (*admin)->ctx = mg_start(&callbacks, (*admin), options);
 
@@ -581,7 +581,7 @@ celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, e
 
     import_registration_pt import = NULL;
     if (objectClass != NULL) {
-        status = importRegistration_create(admin->context, NULL, NULL, endpointDescription, objectClass, &import);
+        status = importRegistration_create(admin->context, endpointDescription, objectClass, &import);
     }
     if (status == CELIX_SUCCESS) {
         importRegistration_setSendFn(import, remoteServiceAdmin_send, admin);
@@ -591,9 +591,9 @@ celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, e
         status = importRegistration_start(import);
     }
 
-    //celixThreadMutex_lock(&admin->importedServicesLock);
-    //TODO add to list
-    //celixThreadMutex_unlock(&admin->importedServicesLock);
+    celixThreadMutex_lock(&admin->importedServicesLock);
+    hashMap_put(admin->importedServices, import, import);
+    celixThreadMutex_unlock(&admin->importedServicesLock);
 
     if (status == CELIX_SUCCESS) {
         *out = import;
@@ -605,44 +605,14 @@ celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, e
 
 celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration) {
     celix_status_t status = CELIX_SUCCESS;
-    return status;
-    /*
-
-      endpoint_description_pt endpointDescription = (endpoint_description_pt) registration->endpointDescription;
-      import_registration_factory_pt registration_factory = NULL;
-
-      celixThreadMutex_lock(&admin->importedServicesLock);
-
-      registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
-
-      // factory available
-      if ((registration_factory == NULL) || (registration_factory->trackedFactory == NULL))
-      {
-          logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: Error while retrieving registration factory for imported service %s", endpointDescription->service);
-      }
-      else
-      {
-          registration_factory->trackedFactory->unregisterProxyService(registration_factory->trackedFactory->factory, endpointDescription);
-          arrayList_removeElement(registration_factory->registrations, registration);
-          importRegistration_destroy(registration);
 
-          if (arrayList_isEmpty(registration_factory->registrations))
-          {
-              logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: closing proxy.");
-
-              serviceTracker_close(registration_factory->proxyFactoryTracker);
-              importRegistrationFactory_close(registration_factory);
-
-              hashMap_remove(admin->importedServices, endpointDescription->service);
-
-              importRegistrationFactory_destroy(&registration_factory);
-          }
-      }
-
-      celixThreadMutex_unlock(&admin->importedServicesLock);
+    celixThreadMutex_lock(&admin->importedServicesLock);
+    importRegistration_close(registration);
+    //importRegistration_destroy(registration); TODO enable & debug -> segfault
+    hashMap_remove(admin->importedServices, registration);
+    celixThreadMutex_unlock(&admin->importedServicesLock);
 
-      return status;
-    */
+    return status;
 }
 
 

http://git-wip-us.apache.org/repos/asf/celix/blob/a477ab96/remote_services/topology_manager/private/src/topology_manager.c
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/private/src/topology_manager.c b/remote_services/topology_manager/private/src/topology_manager.c
index 3b9b62f..f78bde5 100644
--- a/remote_services/topology_manager/private/src/topology_manager.c
+++ b/remote_services/topology_manager/private/src/topology_manager.c
@@ -624,60 +624,59 @@ celix_status_t topologyManager_endpointListenerRemoved(void * handle, service_re
     celix_status_t status;
     topology_manager_pt manager = handle;
 
-    status = celixThreadMutex_lock(&manager->listenerListLock);
-
-    if (status == CELIX_SUCCESS) {
-        if (hashMap_remove(manager->listenerList, reference)) {
-            logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "EndpointListener Removed");
-        }
+    celixThreadMutex_lock(&manager->listenerListLock);
 
-        status = celixThreadMutex_unlock(&manager->listenerListLock);
+    if (hashMap_remove(manager->listenerList, reference)) {
+        logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "EndpointListener Removed");
     }
 
+
+    celixThreadMutex_unlock(&manager->listenerListLock);
+
+
     return status;
 }
 
 celix_status_t topologyManager_notifyListenersEndpointAdded(topology_manager_pt manager, remote_service_admin_service_pt rsa, array_list_pt registrations) {
     celix_status_t status;
 
-    status = celixThreadMutex_lock(&manager->listenerListLock);
+    celixThreadMutex_lock(&manager->listenerListLock);
 
-    if (status == CELIX_SUCCESS) {
-        hash_map_iterator_pt iter = hashMapIterator_create(manager->listenerList);
-        while (hashMapIterator_hasNext(iter)) {
-            char *scope = NULL;
-            endpoint_listener_pt epl = NULL;
-            service_reference_pt reference = hashMapIterator_nextKey(iter);
 
-            serviceReference_getProperty(reference, (char *) OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
+    hash_map_iterator_pt iter = hashMapIterator_create(manager->listenerList);
+    while (hashMapIterator_hasNext(iter)) {
+        char *scope = NULL;
+        endpoint_listener_pt epl = NULL;
+        service_reference_pt reference = hashMapIterator_nextKey(iter);
 
-            status = bundleContext_getService(manager->context, reference, (void **) &epl);
-            if (status == CELIX_SUCCESS) {
-                filter_pt filter = filter_create(scope);
-
-                int regSize = arrayList_size(registrations);
-                for (int regIt = 0; regIt < regSize; regIt++) {
-                    export_registration_pt export = arrayList_get(registrations, regIt);
-
-                    endpoint_description_pt endpoint = NULL;
-                    status = topologyManager_getEndpointDescriptionForExportRegistration(rsa, export, &endpoint);
-                    if (status == CELIX_SUCCESS) {
-                        bool matchResult = false;
-                        filter_match(filter, endpoint->properties, &matchResult);
-                        if (matchResult) {
-                            status = epl->endpointAdded(epl->handle, endpoint, scope);
-                        }
+        serviceReference_getProperty(reference, (char *) OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
+
+        status = bundleContext_getService(manager->context, reference, (void **) &epl);
+        if (status == CELIX_SUCCESS) {
+            filter_pt filter = filter_create(scope);
+
+            int regSize = arrayList_size(registrations);
+            for (int regIt = 0; regIt < regSize; regIt++) {
+                export_registration_pt export = arrayList_get(registrations, regIt);
+
+                endpoint_description_pt endpoint = NULL;
+                status = topologyManager_getEndpointDescriptionForExportRegistration(rsa, export, &endpoint);
+                if (status == CELIX_SUCCESS) {
+                    bool matchResult = false;
+                    filter_match(filter, endpoint->properties, &matchResult);
+                    if (matchResult) {
+                        status = epl->endpointAdded(epl->handle, endpoint, scope);
                     }
                 }
-
-                filter_destroy(filter);
             }
+
+            filter_destroy(filter);
         }
+    }
 
-        hashMapIterator_destroy(iter);
+    hashMapIterator_destroy(iter);
 
-        status = celixThreadMutex_unlock(&manager->listenerListLock);
-    }
+    celixThreadMutex_unlock(&manager->listenerListLock);
 
     return status;
 }
@@ -686,35 +685,34 @@ celix_status_t topologyManager_notifyListenersEndpointRemoved(topology_manager_p
 
     celix_status_t status;
 
-    status = celixThreadMutex_lock(&manager->listenerListLock);
+    celixThreadMutex_lock(&manager->listenerListLock);
 
-    if (status == CELIX_SUCCESS) {
-        hash_map_iterator_pt iter = hashMapIterator_create(manager->listenerList);
-        while (hashMapIterator_hasNext(iter)) {
-            endpoint_description_pt endpoint = NULL;
-            endpoint_listener_pt epl = NULL;
-            char *scope = NULL;
+    hash_map_iterator_pt iter = hashMapIterator_create(manager->listenerList);
+    while (hashMapIterator_hasNext(iter)) {
+        endpoint_description_pt endpoint = NULL;
+        endpoint_listener_pt epl = NULL;
+        char *scope = NULL;
 
-            service_reference_pt reference = hashMapIterator_nextKey(iter);
-            serviceReference_getProperty(reference, (char *) OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
+        service_reference_pt reference = hashMapIterator_nextKey(iter);
+        serviceReference_getProperty(reference, (char *) OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
 
-            status = bundleContext_getService(manager->context, reference, (void **) &epl);
+        status = bundleContext_getService(manager->context, reference, (void **) &epl);
 
-            if (status == CELIX_SUCCESS) {
-                status = topologyManager_getEndpointDescriptionForExportRegistration(rsa, export, &endpoint);
-            }
+        if (status == CELIX_SUCCESS) {
+            status = topologyManager_getEndpointDescriptionForExportRegistration(rsa, export, &endpoint);
+        }
 
-            if (status == CELIX_SUCCESS) {
-                status = epl->endpointRemoved(epl->handle, endpoint, NULL);
-            }
+        if (status == CELIX_SUCCESS) {
+            status = epl->endpointRemoved(epl->handle, endpoint, NULL);
         }
 
         hashMapIterator_destroy(iter);
 
-        status = celixThreadMutex_unlock(&manager->listenerListLock);
 
     }
 
+    celixThreadMutex_unlock(&manager->listenerListLock);
+
     return status;
 }
 


[32/50] [abbrv] celix git commit: CELIX-237: Added missing lib to framework build. Update intall locations for some rsa headers

Posted by pn...@apache.org.
CELIX-237: Added missing lib to framework build. Update intall locations for some rsa headers


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

Branch: refs/heads/develop
Commit: fa785c5e7a4806a7853d6b1e5dafffee04fc52a1
Parents: 2d6ef1b
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Mon Sep 7 20:50:53 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon Sep 7 20:50:53 2015 +0200

----------------------------------------------------------------------
 framework/CMakeLists.txt                            | 3 ++-
 remote_services/remote_service_admin/CMakeLists.txt | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/fa785c5e/framework/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt
index 429dd04..a69187a 100644
--- a/framework/CMakeLists.txt
+++ b/framework/CMakeLists.txt
@@ -21,6 +21,7 @@ if (FRAMEWORK)
     
     find_package(ZLIB REQUIRED)
     find_package(UUID REQUIRED)
+    find_package(CURL REQUIRED)
 
     include(CPackComponent)
     
@@ -73,7 +74,7 @@ if (FRAMEWORK)
     if (WITH_APR)
         set(APR ${APR_LIBRARY})
     endif()
-    target_link_libraries(celix_framework celix_utils ${UUID} ${ZLIB_LIBRARY} ${APR})
+    target_link_libraries(celix_framework celix_utils ${UUID} ${ZLIB_LIBRARY} ${APR} ${CURL_LIBRARIES})
 
     install(TARGETS celix_framework DESTINATION lib COMPONENT framework)
     FILE(GLOB files "public/include/*.h")

http://git-wip-us.apache.org/repos/asf/celix/blob/fa785c5e/remote_services/remote_service_admin/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/CMakeLists.txt b/remote_services/remote_service_admin/CMakeLists.txt
index 30f1ba3..310dafa 100644
--- a/remote_services/remote_service_admin/CMakeLists.txt
+++ b/remote_services/remote_service_admin/CMakeLists.txt
@@ -26,8 +26,8 @@ install (FILES
         public/include/remote_proxy.h
         public/include/remote_service_admin.h
         public/include/endpoint_description.h
-        ../endpoint_listener/public/include/endpoint_listener.h
-        ../utils/public/include/remote_constants.h
+        public/include/endpoint_listener.h
+        public/include/remote_constants.h
     DESTINATION 
         include/celix/remote_service_admin 
     COMPONENT 
@@ -41,7 +41,7 @@ install (FILES
         remote_service_admin
 )
 install (FILES 
-        ${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include/endpoint_listener.h
+        public/include/endpoint_listener.h
     DESTINATION 
         include/celix/endpoint_listener 
     COMPONENT 


[49/50] [abbrv] celix git commit: CELIX-237: Only enabling error logging for the dfi lib

Posted by pn...@apache.org.
CELIX-237: Only enabling error logging for the dfi lib


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

Branch: refs/heads/develop
Commit: 8689fc1021932c7baaf9f6bc3d613af97d17c3b0
Parents: c66eb88
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Oct 13 12:00:48 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Oct 13 12:16:50 2015 +0200

----------------------------------------------------------------------
 .../rsa/private/src/remote_service_admin_dfi.c            | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/8689fc10/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
index 9ea470b..4bd8c58 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
@@ -135,11 +135,11 @@ celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_servi
 
         if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
             logHelper_start((*admin)->loghelper);
-            dynCommon_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
-            dynType_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
-            dynFunction_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
-            dynInterface_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
-            jsonSerializer_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
+            dynCommon_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
+            dynType_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
+            dynFunction_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
+            dynInterface_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
+            jsonSerializer_logSetup((void *)remoteServiceAdmin_log, *admin, 1);
         }
 
         bundleContext_getProperty(context, "RSA_PORT", &port);


[21/50] [abbrv] celix git commit: CELIX-237: Refactor import/export_registration moved all json stuff to json_serializer.c

Posted by pn...@apache.org.
CELIX-237: Refactor import/export_registration moved all json stuff to json_serializer.c


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

Branch: refs/heads/develop
Commit: fdade6aaafba00b95fa30c280e36cca29adcb938
Parents: a129b48
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Thu Aug 13 12:43:23 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Thu Aug 13 12:43:23 2015 +0200

----------------------------------------------------------------------
 .../remote_service_admin_dfi/CMakeLists.txt     |  12 +-
 .../dynamic_function_interface/dyn_function.h   |   4 +-
 .../dynamic_function_interface/dyn_interface.h  |   7 +-
 .../dynamic_function_interface/dyn_type.h       |   1 -
 .../json_serializer.c                           | 122 ++++++++++++++++---
 .../json_serializer.h                           |   9 +-
 .../remote_service_admin_dfi/rsa/CMakeLists.txt |  20 +--
 .../rsa/private/src/export_registration_dfi.c   |  76 +-----------
 .../rsa/private/src/import_registration_dfi.c   |  46 +++----
 .../rsa/private/src/remote_service_admin_dfi.c  |   2 +
 .../rsa_tst/bundle/tst_activator.c              |   2 +-
 11 files changed, 154 insertions(+), 147 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/fdade6aa/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 ccd01f9..7f9404c 100644
--- a/remote_services/remote_service_admin_dfi/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/CMakeLists.txt
@@ -7,7 +7,7 @@ if (RSA_REMOTE_SERVICE_ADMIN_DFI)
     find_package(CURL REQUIRED)
     find_package(Jansson REQUIRED)
     find_package(FFI REQUIRED)
-    #TODO if test
+    #TODO if test check
     find_package(CppUTest REQUIRED)
 
     include_directories(
@@ -20,17 +20,15 @@ if (RSA_REMOTE_SERVICE_ADMIN_DFI)
         include_directories(dynamic_function_interface/memstream)
     endif()
 
-    #TODO if test
+    #TODO if test check
     include_directories(${CPPUTEST_INCLUDE_DIR})
 
 
-
     add_subdirectory(dynamic_function_interface)
-    #TODO if test
-    add_subdirectory(dynamic_function_interface_tst)
-
     add_subdirectory(rsa)
-    #TODO if test
+
+    #TODO if test check
+    add_subdirectory(dynamic_function_interface_tst)
     add_subdirectory(rsa_tst)
 
 endif()
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/fdade6aa/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
index 5cbf686..e99bc7a 100644
--- 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
@@ -18,7 +18,7 @@
  * e.g add(DD)D or sum({[D[D setA setB})D
  */
 
-//TODO maybe refactor to meta info flags (e.g context/handler, output, etc with a start/stop -> M(MetaType);
+typedef struct _dyn_function_type dyn_function_type;
 
 #define DYN_FUNCTION_ARG_META_UNKNOWN_TYPE 0
 #define DYN_FUNCTION_ARG_META_INPUT_TYPE 1
@@ -27,8 +27,6 @@
 #define DYN_FUNCTION_ARG_META_HANDLE_TYPE 4
 //TODO input/output types?
 
-typedef struct _dyn_function_type dyn_function_type;
-
 DFI_SETUP_LOG_HEADER(dynFunction);
 
 int dynFunction_parse(FILE *descriptorStream, struct types_head *refTypes, dyn_function_type **dynFunc);

http://git-wip-us.apache.org/repos/asf/celix/blob/fdade6aa/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
index f005bff..d13aa67 100644
--- 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
@@ -22,14 +22,9 @@ DFI_SETUP_LOG_HEADER(dynInterface);
  * ':methods\n' [MethodIdValue]
  *
  */
-
-//struct namvals_head in dyn_common.h
-TAILQ_HEAD(methods_head, method_entry);
-//struct reference_types_head in dyn_type.h
-
 typedef struct _dyn_interface_type dyn_interface_type;
 
-
+TAILQ_HEAD(methods_head, method_entry);
 struct method_entry {
     int index;
     char *id;

http://git-wip-us.apache.org/repos/asf/celix/blob/fdade6aa/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
index a409ff5..2058c41 100644
--- 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
@@ -83,7 +83,6 @@
 
 typedef struct _dyn_type dyn_type;
 
-//TODO rename
 TAILQ_HEAD(types_head, type_entry);
 struct type_entry {
     dyn_type *type;

http://git-wip-us.apache.org/repos/asf/celix/blob/fdade6aa/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
index a2cc34e..a689483 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
@@ -3,6 +3,7 @@
  */
 #include "json_serializer.h"
 #include "dyn_type.h"
+#include "dyn_interface.h"
 
 #include <jansson.h>
 #include <assert.h>
@@ -26,6 +27,13 @@ static int ERROR = 1;
 
 DFI_SETUP_LOG(jsonSerializer);
 
+typedef void (*gen_func_type)(void);
+
+struct generic_service_layout {
+    void *handle;
+    gen_func_type methods[];
+};
+
 int jsonSerializer_deserialize(dyn_type *type, const char *input, void **result) {
     assert(dynType_type(type) == DYN_TYPE_COMPLEX);
     int status = 0;
@@ -416,13 +424,60 @@ static int jsonSerializer_writeComplex(dyn_type *type, void *input, json_t **out
     return status;
 }
 
-int jsonSerializer_call(dyn_function_type *func, void *handle, void (*fp)(void), json_t *arguments, json_t **out) {
+int jsonSerializer_call(dyn_interface_type *intf, void *service, const char *request, char **out) {
     int status = OK;
 
-    int nrOfArgs = dynFunction_nrOfArguments(func);
-    void *args[nrOfArgs];
+    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);
+    } else {
+        LOG_DEBUG("RSA: found method '%s'\n", entry->id);
+    }
 
+    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;
 
@@ -451,6 +506,7 @@ int jsonSerializer_call(dyn_function_type *func, void *handle, void (*fp)(void),
             break;
         }
     }
+    json_decref(js_request);
 
 
     //TODO assert return type is native int
@@ -460,12 +516,14 @@ int jsonSerializer_call(dyn_function_type *func, void *handle, void (*fp)(void),
     double **r = args[2];
     printf("result ptrptr is %p, result ptr %p, result is %f\n", r, *r, **r);
 
+
+    json_t *jsonResult = NULL;
     for (i = 0; i < nrOfArgs; i += 1) {
         int metaInfo = dynFunction_argumentMetaInfoForIndex(func, i);
         dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
         if (metaInfo == DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE) {
             if (status == OK) {
-                status = jsonSerializer_serializeJson(argType, args[i], out);
+                status = jsonSerializer_serializeJson(argType, args[i], &jsonResult);
             }
         } else if (metaInfo == DYN_FUNCTION_ARG_META_OUTPUT_TYPE) {
             printf("TODO\n");
@@ -477,17 +535,41 @@ int jsonSerializer_call(dyn_function_type *func, void *handle, void (*fp)(void),
         }
     }
 
+    char *response = NULL;
+    if (status == OK) {
+        LOG_DEBUG("creating payload\n");
+        json_t *payload = json_object();
+        json_object_set_new(payload, "r", jsonResult);
+        response = json_dumps(payload, JSON_DECODE_ANY);
+        json_decref(payload);
+        LOG_DEBUG("status ptr is %p. response if '%s'\n", status, response);
+    }
+
+    if (status == OK) {
+        *out = response;
+    } else {
+        if (response != NULL) {
+            free(response);
+        }
+    }
+
     //TODO free args (created by jsonSerializer and dynType_alloc) (dynType_free)
     return status;
 }
 
-int jsonSerializer_prepareArguments(dyn_function_type *func, void *args[], json_t **out) {
+int jsonSerializer_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(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) {
         if (dynFunction_argumentMetaInfoForIndex(func, i) == DYN_FUNCTION_ARG_META_INPUT_TYPE) {
             json_t *val = NULL;
@@ -504,34 +586,46 @@ int jsonSerializer_prepareArguments(dyn_function_type *func, void *args[], json_
         }
     }
 
+    char *invokeStr = json_dumps(invoke, JSON_DECODE_ANY);
+    json_decref(invoke);
+
     if (status == OK) {
-        *out = arguments;
+        *out = invokeStr;
     }
 
     return status;
 }
 
-int jsonSerializer_handleReply(dyn_function_type *func, void *handle, json_t *reply, void *args[]) {
+int jsonSerializer_handleReply(dyn_function_type *func, const char *reply, void *args[]) {
     int status = 0;
 
+    json_t *replyJson = json_loads(reply, JSON_DECODE_ANY, NULL); //TODO check
+    json_t *result = json_object_get(replyJson, "r"); //TODO check
+
+    LOG_DEBUG("replyJson ptr is %p and result ptr is %p\n", replyJson, result);
+
     int nrOfArgs = dynFunction_nrOfArguments(func);
     int i;
     for (i = 0; i < nrOfArgs; i += 1) {
         dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
         int metaInf = dynFunction_argumentMetaInfoForIndex(func, i);
         if (metaInf == DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE) {
-            void **tmp = NULL;
+            dyn_type *subType = NULL;
+            dynType_typedPointer_getTypedType(argType, &subType);
+            void *tmp = NULL;
+            size_t size = dynType_size(subType);
+            status = jsonSerializer_deserializeJson(subType, result, &tmp);
             void **out = (void **)args[i];
-            size_t size = dynType_size(argType);
-            status = jsonSerializer_deserializeJson(argType, reply, (void **)&tmp);
-            memcpy(*out, *tmp, size);
-            dynType_free(argType, tmp);
+            memcpy(*out, tmp, size);
+            dynType_free(subType, tmp);
         } else if (metaInf == DYN_FUNCTION_ARG_META_OUTPUT_TYPE) {
             assert(false); //TODO
         } else {
-            //skipt handle and input types
+            //skip handle and input types
         }
     }
 
+    json_decref(replyJson);
+
     return status;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/fdade6aa/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
index 0853114..6e7ee7d 100644
--- 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
@@ -8,6 +8,7 @@
 #include "dfi_log_util.h"
 #include "dyn_type.h"
 #include "dyn_function.h"
+#include "dyn_interface.h"
 
 //logging
 DFI_SETUP_LOG_HEADER(jsonSerializer);
@@ -18,10 +19,8 @@ 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);
 
-//input should be a json array with with the std args
-int jsonSerializer_call(dyn_function_type *func, void *handle, void (*fp)(void), json_t *arguments, json_t **result);
-
-int jsonSerializer_prepareArguments(dyn_function_type *func, void *args[], json_t **arguments);
-int jsonSerializer_handleReply(dyn_function_type *func, void *handle, json_t *reply, void *args[]);
+int jsonSerializer_call(dyn_interface_type *intf, void *service, const char *request, char **out);
 
+int jsonSerializer_prepareInvokeRequest(dyn_function_type *func, const char *id, void *args[], char **out);
+int jsonSerializer_handleReply(dyn_function_type *func, const char *reply, void *args[]);
 #endif

http://git-wip-us.apache.org/repos/asf/celix/blob/fdade6aa/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 79c9220..2c8ef5d 100644
--- a/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
@@ -15,15 +15,17 @@
 # specific language governing permissions and limitations
 # under the License.
 
-include_directories(private/include)
-include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/private/include")
-include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_http/private/include")
-include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_dfi/dynamic_function_interface")
-include_directories("${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include")
-include_directories("../dynamic_function_interface")
+include_directories(
+    private/include
+    ${PROJECT_SOURCE_DIR}/utils/public/include
+    ${PROJECT_SOURCE_DIR}/log_service/public/include
+    ${PROJECT_SOURCE_DIR}/remote_services/utils/private/include
+    ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/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}/remote_services/examples/calculator_service/public/include
+    ../dynamic_function_interface
+)
 
 SET_HEADER(BUNDLE_SYMBOLICNAME "apache_celix_remote_service_admin_dfi")
 SET(BUNDLE_VERSION "0.0.1")

http://git-wip-us.apache.org/repos/asf/celix/blob/fdade6aa/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
index cc181b3..85ecb43 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
@@ -5,7 +5,6 @@
 #include <dyn_interface.h>
 #include <json_serializer.h>
 #include <remote_constants.h>
-#include <assert.h>
 #include "export_registration.h"
 #include "export_registration_dfi.h"
 
@@ -24,13 +23,6 @@ struct export_registration {
     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;
 
@@ -94,72 +86,12 @@ celix_status_t exportRegistration_create(log_helper_pt helper, service_reference
 
 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
-    }
+    *responseLength = -1;
+    //TODO lock service
+    status = jsonSerializer_call(export->intf, export->service, data, responseOut);
+    //TODO unlock service
 
-    //TODO unlock/sema export
-    printf("done export reg call\n");
     return status;
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/fdade6aa/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
index 20ff61d..09ad25b 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
@@ -216,47 +216,35 @@ static void importRegistration_proxyFunc(void *userData, void *args[], void *ret
     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));
+    if (import == NULL || import->send == NULL) {
+        status = CELIX_ILLEGAL_ARGUMENT;
+    }
 
-    json_t *arguments = NULL;
 
-    status = jsonSerializer_prepareArguments(entry->dynFunc, args, &arguments);
+    char *invokeRequest = NULL;
     if (status == CELIX_SUCCESS) {
-        json_object_set_new(invoke, "a", arguments);
+        status = jsonSerializer_prepareInvokeRequest(entry->dynFunc, entry->id, args, &invokeRequest);
+        printf("Need to send following json '%s'\n", invokeRequest);
     }
 
-    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) {
+    if (status == CELIX_SUCCESS) {
         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);
+        import->send(import->sendHandle, import->endpoint, invokeRequest, &reply, &rc);
+        printf("request sended. got reply '%s' with status %i\n", reply, rc);
 
-
-
-
-        if (status == 0) {
-            printf("done with proxy func\n");
+        if (rc == 0) {
+            printf("handling reply\n");
+            status = jsonSerializer_handleReply(entry->dynFunc, reply, args);
         }
-    } else {
-        printf("Error import of import->send is NULL\n");
+
+        *(int *) returnVal = rc;
     }
 
-    //TODO assert double check if return type is native int
-    int *rVal = returnVal;
-    *rVal = status;
+    if (status != CELIX_SUCCESS) {
+        //TODO log error
+    }
 }
 
 celix_status_t importRegistration_ungetService(import_registration_pt import, bundle_pt bundle, service_registration_pt registration, void **out) {

http://git-wip-us.apache.org/repos/asf/celix/blob/fdade6aa/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
index c78cc19..a092a63 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
@@ -34,6 +34,7 @@
 #include <curl/curl.h>
 
 #include <jansson.h>
+#include <json_serializer.h>
 
 #include "import_registration_dfi.h"
 #include "export_registration_dfi.h"
@@ -127,6 +128,7 @@ celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_servi
             dynType_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
             dynFunction_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
             dynInterface_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
+            jsonSerializer_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
         }
 
         bundleContext_getProperty(context, "RSA_PORT", &port);

http://git-wip-us.apache.org/repos/asf/celix/blob/fdade6aa/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c
index 728030e..1f72db1 100644
--- a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c
@@ -120,7 +120,7 @@ static int test(void *handle) {
 	int status = 0;
 	struct activator *act = handle;
 
-	double result = 0.0;
+	double result = -1.0;
 
     int rc;
     if (act->calc != NULL) {


[35/50] [abbrv] celix git commit: CELIX-237: Removed some printf statements

Posted by pn...@apache.org.
CELIX-237: Removed some printf statements


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

Branch: refs/heads/develop
Commit: c647773eb53b4643110d6ed53a9fdc874c95e58f
Parents: b74a63b
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Sep 9 20:45:14 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Sep 9 20:45:14 2015 +0200

----------------------------------------------------------------------
 .../rsa/private/src/import_registration_dfi.c                | 8 ++++----
 .../rsa/private/src/remote_service_admin_dfi.c               | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/c647773e/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
index 9c4d717..d192e29 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
@@ -232,18 +232,18 @@ static void importRegistration_proxyFunc(void *userData, void *args[], void *ret
     char *invokeRequest = NULL;
     if (status == CELIX_SUCCESS) {
         status = jsonRpc_prepareInvokeRequest(entry->dynFunc, entry->id, args, &invokeRequest);
-        printf("Need to send following json '%s'\n", invokeRequest);
+        //printf("Need to send following json '%s'\n", invokeRequest);
     }
 
     if (status == CELIX_SUCCESS) {
         char *reply = NULL;
         int rc = 0;
-        printf("sending request\n");
+        //printf("sending request\n");
         import->send(import->sendHandle, import->endpoint, invokeRequest, &reply, &rc);
-        printf("request sended. got reply '%s' with status %i\n", reply, rc);
+        //printf("request sended. got reply '%s' with status %i\n", reply, rc);
 
         if (rc == 0) {
-            printf("handling reply\n");
+            //printf("handling reply\n");
             status = jsonRpc_handleReply(entry->dynFunc, reply, args);
         }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/c647773e/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
index 00a4b0f..8eadbdb 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
@@ -339,7 +339,7 @@ static int remoteServiceAdmin_callback(struct mg_connection *conn) {
                 if (response != NULL) {
                     mg_write(conn, data_response_headers, strlen(data_response_headers));
 //              mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
-                    printf("writing response '%s'\n", response);
+                    //printf("writing response '%s'\n", response);
                     mg_write(conn, response, strlen(response));
 //              mg_send_data(conn, response, strlen(response));
 //              mg_write_data(conn, response, strlen(response));


[48/50] [abbrv] celix git commit: CELIX-237: Added locking and some clearup

Posted by pn...@apache.org.
CELIX-237: Added locking and some clearup


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

Branch: refs/heads/develop
Commit: c66eb88753e001fefe007e57325777f8dd8fc4db
Parents: 6494ec2
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Oct 13 11:38:00 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Oct 13 12:16:38 2015 +0200

----------------------------------------------------------------------
 .../rsa/private/src/import_registration_dfi.c   | 42 +++++++++++++++-----
 1 file changed, 33 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/c66eb887/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
index 3ba20e7..f0530b0 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
@@ -1,6 +1,7 @@
 #include <stdlib.h>
 #include <jansson.h>
 #include <json_rpc.h>
+#include <assert.h>
 #include "json_serializer.h"
 #include "dyn_interface.h"
 #include "import_registration.h"
@@ -20,6 +21,7 @@ struct import_registration {
     service_registration_pt factoryReg;
 
     hash_map_pt proxies; //key -> bundle, value -> service_proxy
+    celix_thread_mutex_t proxiesMutex; //protects proxies
 };
 
 struct service_proxy {
@@ -32,6 +34,7 @@ static celix_status_t importRegistration_createProxy(import_registration_pt impo
                                               struct service_proxy **proxy);
 static void importRegistration_proxyFunc(void *userData, void *args[], void *returnVal);
 static void importRegistration_destroyProxy(struct service_proxy *proxy);
+static void importRegistration_clearProxies(import_registration_pt import);
 
 celix_status_t importRegistration_create(bundle_context_pt context, endpoint_description_pt endpoint, const char *classObject,
                                          import_registration_pt *out) {
@@ -47,7 +50,9 @@ celix_status_t importRegistration_create(bundle_context_pt context, endpoint_des
         reg->endpoint = endpoint;
         reg->classObject = classObject;
         reg->proxies = hashMap_create(NULL, NULL, NULL, NULL);
+
         celixThreadMutex_create(&reg->mutex, NULL);
+        celixThreadMutex_create(&reg->proxiesMutex, NULL);
 
         reg->factory->factory = reg;
         reg->factory->getService = (void *)importRegistration_getService;
@@ -76,18 +81,32 @@ celix_status_t importRegistration_setSendFn(import_registration_pt reg,
     return CELIX_SUCCESS;
 }
 
-void importRegistration_destroy(import_registration_pt import) {
+static void importRegistration_clearProxies(import_registration_pt import) {
     if (import != NULL) {
+        pthread_mutex_lock(&import->proxiesMutex);
         if (import->proxies != NULL) {
-            hash_map_iterator_pt  iter = hashMapIterator_create(import->proxies);
+            hash_map_iterator_pt iter = hashMapIterator_create(import->proxies);
             while (hashMapIterator_hasNext(iter)) {
                 struct service_proxy *proxy = hashMapIterator_nextEntry(iter);
                 importRegistration_destroyProxy(proxy);
             }
             hashMapIterator_destroy(iter);
+        }
+        pthread_mutex_unlock(&import->proxiesMutex);
+    }
+}
+
+void importRegistration_destroy(import_registration_pt import) {
+    if (import != NULL) {
+        if (import->proxies != NULL) {
+            importRegistration_clearProxies(import);
             hashMap_destroy(import->proxies, false, false);
             import->proxies = NULL;
         }
+
+        pthread_mutex_destroy(&import->mutex);
+        pthread_mutex_destroy(&import->proxiesMutex);
+
         if (import->factory != NULL) {
             free(import->factory);
         }
@@ -110,7 +129,9 @@ celix_status_t importRegistration_stop(import_registration_pt import) {
     if (import->factoryReg != NULL) {
         serviceRegistration_unregister(import->factoryReg);
     }
-    //TODO unregister every serv instance? Needed for factory?
+
+    importRegistration_clearProxies(import);
+
     return status;
 }
 
@@ -127,11 +148,12 @@ celix_status_t importRegistration_getService(import_registration_pt import, bund
      */
 
 
-    struct service_proxy *proxy = hashMap_get(import->proxies, bundle); //TODO lock
+    pthread_mutex_lock(&import->proxiesMutex);
+    struct service_proxy *proxy = hashMap_get(import->proxies, bundle);
     if (proxy == NULL) {
         status = importRegistration_createProxy(import, bundle, &proxy);
         if (status == CELIX_SUCCESS) {
-            hashMap_put(import->proxies, bundle, proxy); //TODO lock
+            hashMap_put(import->proxies, bundle, proxy);
         }
     }
 
@@ -139,6 +161,7 @@ celix_status_t importRegistration_getService(import_registration_pt import, bund
         proxy->count += 1;
         *out = proxy->service;
     }
+    pthread_mutex_unlock(&import->proxiesMutex);
 
     return status;
 }
@@ -263,13 +286,13 @@ static void importRegistration_proxyFunc(void *userData, void *args[], void *ret
 
 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
+    pthread_mutex_lock(&import->proxiesMutex);
+
+    struct service_proxy *proxy = hashMap_get(import->proxies, bundle);
     if (proxy != NULL) {
         if (*out == proxy->service) {
             proxy->count -= 1;
@@ -281,7 +304,8 @@ celix_status_t importRegistration_ungetService(import_registration_pt import, bu
             importRegistration_destroyProxy(proxy);
         }
     }
-     */
+
+    pthread_mutex_lock(&import->proxiesMutex);
 
     return status;
 }


[41/50] [abbrv] celix git commit: CELIX-237: Added support for boolean (Z)

Posted by pn...@apache.org.
CELIX-237: Added support for boolean (Z)


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

Branch: refs/heads/develop
Commit: 8248c2c1d8d812ae0ad645505bc55941d7ad86aa
Parents: d340898
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Sep 23 14:51:27 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Sep 23 14:51:27 2015 +0200

----------------------------------------------------------------------
 .../dynamic_function_interface/dyn_type.c              |  3 +++
 .../dynamic_function_interface/json_serializer.c       | 13 ++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/8248c2c1/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
index de00784..88f8766 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
@@ -825,6 +825,9 @@ ffi_type *dynType_ffiType(dyn_type *type) {
 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;

http://git-wip-us.apache.org/repos/asf/celix/blob/8248c2c1/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
index eb38dbc..ae1b95b 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
@@ -126,6 +126,7 @@ static int jsonSerializer_parseAny(dyn_type *type, void *loc, json_t *val) {
     printf("\n");
      */
 
+    bool *z;            //Z
     float *f;           //F
     double *d;          //D
     char *b;            //B
@@ -139,6 +140,10 @@ static int jsonSerializer_parseAny(dyn_type *type, void *loc, json_t *val) {
     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);
@@ -277,6 +282,7 @@ static int jsonSerializer_writeAny(dyn_type *type, void *input, json_t **out) {
     json_t *val = NULL;
     dyn_type *subType = NULL;
 
+    bool *z;            //Z
     float *f;           //F
     double *d;          //D
     char *b;            //B
@@ -290,6 +296,10 @@ static int jsonSerializer_writeAny(dyn_type *type, void *input, json_t **out) {
     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);
@@ -438,4 +448,5 @@ static int jsonSerializer_writeComplex(dyn_type *type, void *input, json_t **out
     }
 
     return status;
-}
\ No newline at end of file
+}
+


[40/50] [abbrv] celix git commit: Fixed a small issue of an error not reported in json_serializer, added an extra test and edited some log statements

Posted by pn...@apache.org.
Fixed a small issue of an error not reported in json_serializer, added an extra test and edited some log statements


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

Branch: refs/heads/develop
Commit: d340898029489b525ce009350ff376ffd9d68376
Parents: 5262482
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Sep 22 21:05:10 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Sep 22 21:05:10 2015 +0200

----------------------------------------------------------------------
 .../json_serializer.c                           | 19 ++++++-
 .../descriptors/example2.descriptor             |  9 +++
 .../dyn_type_tests.cpp                          | 51 +++++++++++++++++
 .../json_rpc_tests.cpp                          | 60 ++++++++++++++++++++
 .../rsa/private/src/import_registration_dfi.c   |  2 +-
 .../rsa/private/src/remote_service_admin_dfi.c  |  2 +
 6 files changed, 139 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/d3408980/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
index 0fb07fc..eb38dbc 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
@@ -90,11 +90,18 @@ 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) {
     int status = OK;
-    int index = dynType_complex_indexForName(type, name);
     void *valp = NULL;
     dyn_type *valType = NULL;
 
-    status = dynType_complex_valLocAt(type, index, inst, &valp);
+    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);
@@ -113,6 +120,12 @@ static int jsonSerializer_parseAny(dyn_type *type, void *loc, json_t *val) {
     dyn_type *subType = NULL;
     char c = dynType_descriptorType(type);
 
+    /*
+    printf("parseAny with descriptor '%c' :", c);
+    json_dumpf(val, stdout, 0); //TODO remove
+    printf("\n");
+     */
+
     float *f;           //F
     double *d;          //D
     char *b;            //B
@@ -225,7 +238,7 @@ static int jsonSerializer_parseSequence(dyn_type *seq, json_t *array, void *seqL
         json_array_foreach(array, index, val) {
             void *valLoc = NULL;
             status = dynType_sequence_increaseLengthAndReturnLastLoc(seq, seqLoc, &valLoc);
-            //LOG_DEBUG("Got sequence loc %p", valLoc);
+            //LOG_DEBUG("Got sequence loc %p for index %zu", valLoc, index);
 
             if (status == OK) {
                 status = jsonSerializer_parseAny(itemType, valLoc, val);

http://git-wip-us.apache.org/repos/asf/celix/blob/d3408980/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
new file mode 100644
index 0000000..38bf442
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/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/d3408980/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
index 2f05bd1..ae14c0f 100644
--- 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
@@ -210,3 +210,54 @@ TEST(DynTypeTests, MetaInfoTest) {
     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/d3408980/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
index 6ebf1c3..6140bec 100644
--- 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
@@ -131,6 +131,17 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
         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 *);
@@ -221,6 +232,51 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
         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);
+
+        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);
+
+
+        free(result->buf);
+        free(result);
+        dynInterface_destroy(intf);    }
+
 }
 
 TEST_GROUP(JsonRpcTests) {
@@ -257,4 +313,8 @@ TEST(JsonRpcTests, callOut) {
     callTestOutput();
 }
 
+TEST(JsonRpcTests, handleOutSeq) {
+    handleTestOutputSequence();
+}
+
 

http://git-wip-us.apache.org/repos/asf/celix/blob/d3408980/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
index 56144d9..680a75a 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
@@ -249,7 +249,7 @@ static void importRegistration_proxyFunc(void *userData, void *args[], void *ret
         //printf("request sended. got reply '%s' with status %i\n", reply, rc);
 
         if (rc == 0) {
-            //printf("handling reply\n");
+            //printf("Handling reply '%s'\n", reply);
             status = jsonRpc_handleReply(entry->dynFunc, reply, args);
         }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/d3408980/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
index 54d08d3..9ea470b 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
@@ -444,6 +444,7 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c
 
 celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration) {
     celix_status_t status = CELIX_SUCCESS;
+    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_DFI: Removing exported service");
 
     service_reference_pt  ref = NULL;
     status = exportRegistration_getExportReference(registration, &ref);
@@ -620,6 +621,7 @@ celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, e
 
 celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration) {
     celix_status_t status = CELIX_SUCCESS;
+    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_DFI: Removing imported service");
 
     celixThreadMutex_lock(&admin->importedServicesLock);
     importRegistration_close(registration);


[15/50] [abbrv] celix git commit: CELIX-237: Added support for argument meta info (output types) and added use of this info in the export_registration

Posted by pn...@apache.org.
CELIX-237: Added support for argument meta info (output types) and added use of this info in the export_registration


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

Branch: refs/heads/develop
Commit: 62ede189c0e5cbc32b1a29256f3c109e8acef02c
Parents: 4c4a5e9
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Aug 12 18:16:08 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Aug 12 18:16:08 2015 +0200

----------------------------------------------------------------------
 ...apache.celix.calc.api.Calculator2.descriptor |   6 +-
 .../dynamic_function_interface/dyn_function.c   | 114 +++++++++++++++++--
 .../dynamic_function_interface/dyn_function.h   |  15 ++-
 .../dynamic_function_interface/dyn_type.c       |  13 ++-
 .../tst/dyn_function_tests.cpp                  |  55 ++++++++-
 .../private/src/export_registration_dfi.c       |  81 ++++++++-----
 6 files changed, 238 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/62ede189/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor b/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
index 711df0b..52e3322 100644
--- a/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
+++ b/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
@@ -6,6 +6,6 @@ version=1.0.0
 classname=org.example.Calculator
 :types
 :methods
-add(DD)D=add(PDD*D)N
-sub(DD)D=sub(PDD*D)N
-sqrt(D)D=sqrt(PD*D)N
+add(DD)D=add(#PDD^*D)N
+sub(DD)D=sub(#PDD^*D)N
+sqrt(D)D=sqrt(#PD^*D)N

http://git-wip-us.apache.org/repos/asf/celix/blob/62ede189/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
index 0e12791..8880bc7 100644
--- 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
@@ -27,6 +27,7 @@ typedef struct _dyn_function_argument_type dyn_function_argument_type;
 struct _dyn_function_argument_type {
     int index;
     char *name;
+    int argumentType;
     dyn_type *type;
     TAILQ_ENTRY(_dyn_function_argument_type) entries;
 };
@@ -40,7 +41,11 @@ 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); 
+static void dynFunction_ffiBind(ffi_cif *cif, void *ret, void *args[], void *userData);
+
+static int dynFunction_checkArgument(dyn_function_argument_type *argument);
+
+static void dynFunction_parseArgMeta(FILE *descriptor, int *meta);
 
 int dynFunction_parse(FILE *descriptor, struct types_head *refTypes, dyn_function_type **out) {
     int status = OK;
@@ -67,7 +72,12 @@ int dynFunction_parse(FILE *descriptor, struct types_head *refTypes, dyn_functio
     
     if (status == 0) {
         *out = dynFunc;
-    }     
+    }    else {
+        if (dynFunc != NULL) {
+            dynFunction_destroy(dynFunc);
+        }
+
+    }
     
     return status;
 }
@@ -106,22 +116,50 @@ static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descrip
     int nextChar = fgetc(descriptor);
     int index = 0;
     dyn_type *type = NULL;
+    int argMetaInfo = DYN_FUNCTION_ARG_META_STD_TYPE;
+    char argName[32];
     while (nextChar != ')' && status == 0)  {
-        type = NULL;
         ungetc(nextChar, descriptor);
-        status = dynType_parse(descriptor, NULL, dynFunc->refTypes, &type); 
+        type = NULL;
+
+        dynFunction_parseArgMeta(descriptor, &argMetaInfo);
+        dyn_function_argument_type *arg = NULL;
+
+        status = dynType_parse(descriptor, NULL, dynFunc->refTypes, &type);
         if (status == 0) {
-            dyn_function_argument_type *arg = calloc(1, sizeof(*arg));
-            arg->index = index++;
-            arg->type = type;
-            arg->name = NULL; //TODO
+            arg = calloc(1, sizeof(*arg));
             if (arg != NULL) {
-                TAILQ_INSERT_TAIL(&dynFunc->arguments, arg, entries);
+                arg->index = index;
+                arg->type = type;
+                arg->argumentType = argMetaInfo;
+
+                snprintf(argName, 32, "arg%04i", index);
+                arg->name = strdup(argName);
+
+                index += 1;
             } else {
                 LOG_ERROR("Error allocating memory");
                 status = MEM_ERROR;
             }
-        } 
+        }
+
+        if (status == 0) {
+            status = dynFunction_checkArgument(arg);
+        }
+
+        if (status == 0) {
+            TAILQ_INSERT_TAIL(&dynFunc->arguments, arg, entries);
+        } else {
+            if (arg != NULL) {
+                if (arg->name != NULL) {
+                    free(arg->name);
+                }
+                if (arg->type != NULL) {
+                    dynType_destroy(arg->type);
+                }
+                free(arg);
+            }
+        }
         nextChar = fgetc(descriptor);
     }
 
@@ -132,6 +170,48 @@ static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descrip
     return status;
 }
 
+static void dynFunction_parseArgMeta(FILE *descriptor, int *meta) {
+    int c = fgetc(descriptor);
+
+    switch (c) {
+        case '~' :
+            *meta = DYN_FUNCTION_ARG_META_OUPUT_TYPE;
+            break;
+        case '^' :
+            *meta = DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE;
+            break;
+        case '#' :
+            *meta = DYN_FUNCTION_ARG_META_HANDLE_TYPE;
+            break;
+        default :
+            *meta = DYN_FUNCTION_ARG_META_STD_TYPE;
+            ungetc(c, descriptor);
+            break;
+    }
+}
+
+static int dynFunction_checkArgument(dyn_function_argument_type *argument) {
+    int status = 0;
+    if (argument->argumentType == DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE) {
+        //expect atleast one *
+        if (dynType_type(argument->type) != DYN_TYPE_TYPED_POINTER) {
+            status = ERROR;
+        }
+    } else if (argument->argumentType == DYN_FUNCTION_ARG_META_OUPUT_TYPE) {
+        //expect atleast two **
+        if (dynType_type(argument->type) == DYN_TYPE_TYPED_POINTER) {
+            dyn_type *subType = NULL;
+            status = dynType_typedPointer_getTypedType(argument->type, &subType);
+            if (status == OK && dynType_type(subType) != DYN_TYPE_TYPED_POINTER) {
+                status = ERROR;
+            }
+        } else {
+            status = ERROR;
+        }
+    }
+    return status;
+}
+
 static int dynFunction_initCif(dyn_function_type *dynFunc) {
     int status = 0;
 
@@ -261,4 +341,18 @@ dyn_type * dynFunction_returnType(dyn_function_type *dynFunction) {
     return dynFunction->funcReturn;
 }
 
+int dynFunction_argumentMetaInfoForIndex(dyn_function_type *dynFunc, int argumentNr) {
+    int argType = DYN_FUNCTION_ARG_META_UNKNOWN_TYPE;
+    int index = 0;
+    dyn_function_argument_type *entry = NULL;
+    TAILQ_FOREACH(entry, &dynFunc->arguments, entries) {
+        if (index == argumentNr) {
+            argType = entry->argumentType;
+            break;
+        }
+        index +=1;
+    }
+    return argType;
+}
+
 

http://git-wip-us.apache.org/repos/asf/celix/blob/62ede189/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
index b1abfb6..733c092 100644
--- 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
@@ -10,10 +10,22 @@
 
 /**
  * Uses the following schema
- * (Name)([Type]*)Type
+ * (Name)([ArgType]*)Type
+ *
+ * ArgType = (Type|PreAllocatedOutputType|OutputType)
+ * PreAllocatedOutputType = ^(Type) #Note must be *(Type)
+ * OutputType = ~(Type) #Note must be **(Type)
  * e.g add(DD)D or sum({[D[D setA setB})D
  */
 
+//TODO maybe refactor to meta info flags (e.g context/handler, output, etc with a start/stop -> M(MetaType);
+
+#define DYN_FUNCTION_ARG_META_UNKNOWN_TYPE 0
+#define DYN_FUNCTION_ARG_META_STD_TYPE 1
+#define DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE 2
+#define DYN_FUNCTION_ARG_META_OUPUT_TYPE 3
+#define DYN_FUNCTION_ARG_META_HANDLE_TYPE 4
+
 typedef struct _dyn_function_type dyn_function_type;
 
 DFI_SETUP_LOG_HEADER(dynFunction);
@@ -24,6 +36,7 @@ int dynFunction_parseWithStr(const char *descriptor, struct types_head *refTypes
 int dynFunction_nrOfArguments(dyn_function_type *dynFunc);
 dyn_type *dynFunction_argumentTypeForIndex(dyn_function_type *dynFunc, int argumentNr);
 dyn_type * dynFunction_returnType(dyn_function_type *dynFunction);
+int dynFunction_argumentMetaInfoForIndex(dyn_function_type *dynFunc, int argumentNr);
 
 void dynFunction_destroy(dyn_function_type *dynFunc);
 int dynFunction_call(dyn_function_type *dynFunc, void(*fn)(void), void *returnValue, void **argValues);

http://git-wip-us.apache.org/repos/asf/celix/blob/62ede189/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
index e47fe6d..6396d1c 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
@@ -503,6 +503,17 @@ int dynType_alloc(dyn_type *type, void **bufLoc) {
 
     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;
@@ -913,7 +924,7 @@ static void dynType_printComplex(char *name, dyn_type *type, int depth, FILE *st
         }
 
         dynType_printDepth(depth, stream);
-        printf("}\n");
+        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);

http://git-wip-us.apache.org/repos/asf/celix/blob/62ede189/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
index 006897c..ab5f33e 100644
--- 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
@@ -133,6 +133,7 @@ extern "C" {
 
     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);
@@ -145,15 +146,60 @@ extern "C" {
         args[0] = &ptr;
         args[1] = &a;
         args[2] = &input;
-        void (*fp)(void) = (void(*)(void)) testExample3;
-
         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_STD_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_OUPUT_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) {
@@ -176,7 +222,10 @@ 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/62ede189/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
index 74512d3..c763222 100644
--- 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
@@ -5,6 +5,7 @@
 #include <dyn_interface.h>
 #include <json_serializer.h>
 #include <remote_constants.h>
+#include <assert.h>
 #include "export_registration.h"
 #include "export_registration_dfi.h"
 
@@ -129,31 +130,43 @@ celix_status_t exportRegistration_call(export_registration_pt export, char *data
 
     if (method != NULL) {
 
+        struct generic_service_layout *serv = export->service;
+
         int nrOfArgs = dynFunction_nrOfArguments(method->dynFunc);
-        void *args[nrOfArgs]; //arg 0 is handle
+        void *args[nrOfArgs];
 
         json_t *arguments = json_object_get(js_request, "a");
         json_t *value = NULL;
-        int index = -1;
-        json_array_foreach(arguments, index, value) {
-            int argNr = index + 1;
-            if (argNr < nrOfArgs -1 ) { //note skip last argument. this is the output
-                dyn_type *argType = dynFunction_argumentTypeForIndex(method->dynFunc, argNr);
-                status = jsonSerializer_deserializeJson(argType, value, &(args[argNr]));
+
+        int i;
+        int index = 0;
+        for (i = 0; i < nrOfArgs; i += 1) {
+            int metaInfo = dynFunction_argumentMetaInfoForIndex(method->dynFunc, i);
+            dyn_type *argType = dynFunction_argumentTypeForIndex(method->dynFunc, i);
+            if (metaInfo == DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE) {
+                printf("setting pre alloc output for %i\n", i);
+                dynType_alloc(argType, &args[i]);
+
+            } else if ( metaInfo == DYN_FUNCTION_ARG_META_OUPUT_TYPE) {
+                printf("setting output for %i\n", i);
+                args[i] = NULL;
+            } else if (metaInfo == DYN_FUNCTION_ARG_META_HANDLE_TYPE) {
+                printf("setting handle for %i\n", i);
+                args[i] = &serv->handle;
             } else {
-                status = CELIX_ILLEGAL_ARGUMENT;
+                printf("setting std for %i\n", i);
+                value = json_array_get(arguments, index++);
+                status = jsonSerializer_deserializeJson(argType, value, &(args[i]));
             }
-            if (status != 0) {
+
+            if (status != CELIX_SUCCESS) {
                 break;
             }
         }
 
         json_decref(js_request);
 
-
-        struct generic_service_layout *serv = export->service;
-        args[0] = &serv->handle;
-
+        /*
         //TODO assert last is output pointer (e.g. double pointer)
         dyn_type *lastTypePtr = dynFunction_argumentTypeForIndex(method->dynFunc, nrOfArgs-1);
         dyn_type *lastType = NULL;
@@ -170,34 +183,46 @@ celix_status_t exportRegistration_call(export_registration_pt export, char *data
         dynType_alloc(lastType, &out); //TODO, NOTE only for simple types or single pointer types.. TODO check
         printf("out ptr is %p value is %f\n", out, *(double *)out);
         args[nrOfArgs-1] = &out; //NOTE for simple type no double
+         */
 
         printf("args is %p %p %p\n", args[0] , args[1], args[2]);
         printf("args derefs is %p %p %p\n", *(void **)args[0], *(void **)args[1], *(void **)args[2]);
 
         //TODO assert return type is native int
         int returnVal = 0;
-        //printf("calling function '%s', with index %i, nrOfArgs %i and at loc %p\n", method->id, method->index, nrOfArgs, serv->methods[method->index]);
         dynFunction_call(method->dynFunc, serv->methods[method->index], (void *)&returnVal, args);
-        //printf("done calling\n");
-        //printf("args is %p %p %p\n", args[0] , args[1], args[2]);
-        //printf("args derefs is %p %p %p\n", *(void **)args[0], *(void **)args[1], *(void **)args[2]);
-        //printf("out is %p and val is %f\n", out, *(double *)out);
+        printf("done calling\n");
+        double **r = args[2];
+        printf("result ptrptr is %p, result ptr %p, result is %f\n", r, *r, **r);
 
         json_t *responseJson = NULL;
-        //double r = 2.0;
-        //status = jsonSerializer_serializeJson(lastOutputType, &r /*out*/, &responseJson);
-        printf("out ptr is %p, value is %f\n", out, *(double *)out);
-        status = jsonSerializer_serializeJson(lastType, out, &responseJson);
 
-        json_t *payload = json_object();
-        json_object_set_new(payload, "r", responseJson);
+        for (i = 0; i < nrOfArgs; i += 1) {
+            int metaInfo = dynFunction_argumentMetaInfoForIndex(method->dynFunc, i);
+            dyn_type *argType = dynFunction_argumentTypeForIndex(method->dynFunc, i);
+            if (metaInfo == DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE) {
+                if (status == CELIX_SUCCESS) {
+                    status = jsonSerializer_serializeJson(argType, args[i], &responseJson);
+                }
+                break;
+            } else if (metaInfo == DYN_FUNCTION_ARG_META_OUPUT_TYPE) {
+                printf("TODO\n");
+                assert(false);
+            }
+        }
+
+        if (status == CELIX_SUCCESS) {
+            printf("creating payload\n");
+            json_t *payload = json_object();
+            json_object_set_new(payload, "r", responseJson);
 
-        char *response = json_dumps(payload, JSON_DECODE_ANY);
-        json_decref(payload);
+            char *response = json_dumps(payload, JSON_DECODE_ANY);
+            json_decref(payload);
 
+            *responseOut = response;
+            *responseLength = -1;
+        }
 
-        *responseOut = response;
-        *responseLength = -1;
 
         //TODO free args (created by jsonSerializer and dynType_alloc) (dynType_free)
 


[02/50] [abbrv] celix git commit: CELIX-237: moved rsa_http_ffi source to rsa_dfi

Posted by pn...@apache.org.
CELIX-237: moved rsa_http_ffi source to rsa_dfi


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

Branch: refs/heads/develop
Commit: 3d7f7641fbd58c79b54e00d9d7d1395f54db166c
Parents: bf76d21
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Jul 31 16:11:31 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Fri Jul 31 16:11:31 2015 +0200

----------------------------------------------------------------------
 .../remote_service_admin_dfi/CMakeLists.txt     |   26 +-
 .../dynamic_function_interface/CMakeLists.txt   |    5 +-
 .../include/remote_service_admin_http_impl.h    |   52 +
 .../src/remote_service_admin_activator.c        |  122 ++
 .../private/src/remote_service_admin_impl.c     | 1085 ++++++++++++++++++
 .../CMakeLists.txt                              |   51 -
 .../include/remote_service_admin_http_impl.h    |   52 -
 .../src/remote_service_admin_activator.c        |  122 --
 .../private/src/remote_service_admin_impl.c     | 1085 ------------------
 9 files changed, 1274 insertions(+), 1326 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/3d7f7641/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 f74cac1..500e40e 100644
--- a/remote_services/remote_service_admin_dfi/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/CMakeLists.txt
@@ -34,19 +34,19 @@ if (RSA_REMOTE_SERVICE_ADMIN_DFI)
     include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_http/private/include")
     include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
     
-    #SET_HEADER(BUNDLE_SYMBOLICNAME "apache_celix_remote_service_admin_dfi")
-    #SET(BUNDLE_VERSION "0.0.1")
-    #SET_HEADERS("Bundle-Name: Apache Celix Remote Service Admin HTTP for dynamic function interface")
+    SET_HEADER(BUNDLE_SYMBOLICNAME "apache_celix_remote_service_admin_dfi")
+    SET(BUNDLE_VERSION "0.0.1")
+    SET_HEADERS("Bundle-Name: Apache Celix Remote Service Admin HTTP for dynamic function interface")
     
-    #bundle(remote_service_admin_dfi SOURCES
-    #    private/src/remote_service_admin_impl
-    #    private/src/remote_service_admin_activator
-    #    ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/export_registration_impl
-    #    ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/import_registration_impl
-    #    ${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 ${CURL_LIBRARIES} ${JANSSON_LIBRARIES} ${FFI_LIBRARIES})
+    bundle(remote_service_admin_dfi SOURCES
+        private/src/remote_service_admin_impl
+        private/src/remote_service_admin_activator
+        ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/export_registration_impl
+        ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/import_registration_impl
+        ${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 ${CURL_LIBRARIES} ${JANSSON_LIBRARIES} ${FFI_LIBRARIES} dfi)
 
-    #install_bundle(remote_service_admin_dfi)
+    install_bundle(remote_service_admin_dfi)
 endif (RSA_REMOTE_SERVICE_ADMIN_DFI)

http://git-wip-us.apache.org/repos/asf/celix/blob/3d7f7641/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
index 309176f..ae1d5c3 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt
@@ -18,7 +18,7 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
 	set(MEMSTREAM_SOURCES memstream/open_memstream.c memstream/fmemopen.c)
 endif()
 
-add_library(dfi
+add_library(dfi STATIC
     dyn_common.c
     dyn_type.c
     dyn_function.c
@@ -30,14 +30,13 @@ add_library(dfi
 target_link_libraries(dfi ${FFI_LIBRARIES} ${JANSSON_LIBRARY})
 
 
-#if (FRAMEWORK_TESTS)
+#if (FRAMEWORK_TESTS) TODO
 	add_executable(dfi_tests
 	    tst/dyn_type_tests.cpp
 	    tst/dyn_function_tests.cpp
 	    tst/dyn_closure_tests.cpp
         tst/dyn_interface_tests.cpp
 	    tst/json_serializer_tests.cpp
-#	    tst/avro_descriptor_translator_tests.cpp
 	    tst/run_tests.cpp
 	)
 	target_link_libraries(dfi_tests dfi ${FFI_LIBRARIES} ${CPPUTEST_LIBRARY} ${JANSSON_LIBRARY}) 

http://git-wip-us.apache.org/repos/asf/celix/blob/3d7f7641/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
new file mode 100644
index 0000000..dbf71c9
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/private/include/remote_service_admin_http_impl.h
@@ -0,0 +1,52 @@
+/**
+ *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_impl.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_stop(remote_service_admin_pt admin);
+
+#endif /* REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/3d7f7641/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
new file mode 100644
index 0000000..e4125fc
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_activator.c
@@ -0,0 +1,122 @@
+/**
+ *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_impl.h"
+#include "import_registration_impl.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;
+}
+
+

http://git-wip-us.apache.org/repos/asf/celix/blob/3d7f7641/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_impl.c b/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_impl.c
new file mode 100644
index 0000000..ac54e8d
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_impl.c
@@ -0,0 +1,1085 @@
+/**
+ *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_impl.c
+ *
+ *  \date       May 21, 2015
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <ifaddrs.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <uuid/uuid.h>
+
+#include <curl/curl.h>
+
+#include <ffi.h>
+#include <jansson.h>
+
+#include "export_registration_impl.h"
+#include "import_registration_impl.h"
+#include "remote_service_admin_impl.h"
+#include "remote_constants.h"
+#include "constants.h"
+#include "utils.h"
+#include "bundle_context.h"
+#include "bundle.h"
+#include "service_reference.h"
+#include "service_registration.h"
+#include "log_helper.h"
+#include "log_service.h"
+#include "celix_threads.h"
+#include "civetweb.h"
+#include "log_helper.h"
+#include "endpoint_description.h"
+
+// defines how often the webserver is restarted (with an increased port number)
+#define MAX_NUMBER_OF_RESTARTS 	5
+
+typedef void (*GEN_FUNC_TYPE)(void);
+
+struct generic_service_layout {
+    void *handle;
+    GEN_FUNC_TYPE functions[];
+};
+
+struct proxy {
+  remote_service_admin_pt admin;
+  char *sig;
+  int index;
+  ffi_cif cif;
+  ffi_closure *closure;
+  endpoint_description_pt endpointDescription
+};
+
+
+    
+
+
+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;
+};
+
+struct post {
+    const char *readptr;
+    int size;
+};
+
+struct get {
+    char *writeptr;
+    int size;
+};
+
+static const char *data_response_headers =
+  "HTTP/1.1 200 OK\r\n"
+  "Cache: no-cache\r\n"
+  "Content-Type: application/json\r\n"
+  "\r\n";
+
+static const char *no_content_response_headers =
+  "HTTP/1.1 204 OK\r\n";
+
+// TODO do we need to specify a non-Amdatu specific configuration type?!
+static const char * const CONFIGURATION_TYPE = "org.amdatu.remote.admin.http";
+static const char * const ENDPOINT_URL = "org.amdatu.remote.admin.http.url";
+
+static const char *DEFAULT_PORT = "8888";
+static const char *DEFAULT_IP = "127.0.0.1";
+
+static const unsigned int DEFAULT_TIMEOUT = 0;
+
+static int remoteServiceAdmin_callback(struct mg_connection *conn);
+
+static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, char *interface, endpoint_description_pt *description);
+
+static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip);
+
+static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp);
+static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp);
+
+celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	*admin = calloc(1, sizeof(**admin));
+
+	if (!*admin) {
+		status = CELIX_ENOMEM;
+	} else {
+		unsigned int port_counter = 0;
+		char *port = NULL;
+		char *ip = NULL;
+		char *detectedIp = NULL;
+		(*admin)->context = context;
+		(*admin)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL);
+		(*admin)->importedServices = hashMap_create(NULL, NULL, NULL, NULL);
+
+		celixThreadMutex_create(&(*admin)->exportedServicesLock, NULL);
+		celixThreadMutex_create(&(*admin)->importedServicesLock, NULL);
+
+		if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
+			logHelper_start((*admin)->loghelper);
+		}
+
+		bundleContext_getProperty(context, "RSA_PORT", &port);
+		if (port == NULL) {
+			port = (char *)DEFAULT_PORT;
+		}
+
+		bundleContext_getProperty(context, "RSA_IP", &ip);
+		if (ip == NULL) {
+			char *interface = NULL;
+
+			bundleContext_getProperty(context, "RSA_INTERFACE", &interface);
+			if ((interface != NULL) && (remoteServiceAdmin_getIpAdress(interface, &detectedIp) != CELIX_SUCCESS)) {
+				logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: Could not retrieve IP adress for interface %s", interface);
+			}
+
+			if (ip == NULL) {
+				remoteServiceAdmin_getIpAdress(NULL, &detectedIp);
+			}
+
+			ip = detectedIp;
+		}
+
+		if (ip != NULL) {
+			logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Using %s for service annunciation", ip);
+			(*admin)->ip = strdup(ip);
+		}
+		else {
+			logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No IP address for service annunciation set. Using %s", DEFAULT_IP);
+			(*admin)->ip = (char*) DEFAULT_IP;
+		}
+
+		if (detectedIp != NULL) {
+			free(detectedIp);
+		}
+
+		// Prepare callbacks structure. We have only one callback, the rest are NULL.
+		struct mg_callbacks callbacks;
+		memset(&callbacks, 0, sizeof(callbacks));
+		callbacks.begin_request = remoteServiceAdmin_callback;
+
+		do {
+			char newPort[10];
+			const char *options[] = { "listening_ports", port, NULL};
+
+			(*admin)->ctx = mg_start(&callbacks, (*admin), options);
+
+			if ((*admin)->ctx != NULL) {
+				logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Start webserver: %s", port);
+				(*admin)->port = strdup(port);
+
+			}
+			else {
+		        char* endptr = port;
+		        int currentPort = strtol(port, &endptr, 10);
+
+				errno = 0;
+
+		        if (*endptr || errno != 0) {
+		            currentPort = strtol(DEFAULT_PORT, NULL, 10);
+		        }
+
+		        port_counter++;
+				snprintf(&newPort[0], 6,  "%d", (currentPort+1));
+
+				logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_ERROR, "Error while starting rsa server on port %s - retrying on port %s...", port, newPort);
+				port = newPort;
+			}
+		} while(((*admin)->ctx == NULL) && (port_counter < MAX_NUMBER_OF_RESTARTS));
+
+	}
+	return status;
+}
+
+
+celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin)
+{
+    celix_status_t status = CELIX_SUCCESS;
+
+    free((*admin)->ip);
+    free((*admin)->port);
+    free(*admin);
+
+    *admin = NULL;
+
+    return status;
+}
+
+celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin) {
+	celix_status_t status = CELIX_SUCCESS;
+
+    celixThreadMutex_lock(&admin->exportedServicesLock);
+
+	hash_map_iterator_pt iter = hashMapIterator_create(admin->exportedServices);
+	while (hashMapIterator_hasNext(iter)) {
+		array_list_pt exports = hashMapIterator_nextValue(iter);
+		int i;
+		for (i = 0; i < arrayList_size(exports); i++) {
+			export_registration_pt export = arrayList_get(exports, i);
+			exportRegistration_stopTracking(export);
+		}
+	}
+    hashMapIterator_destroy(iter);
+    celixThreadMutex_unlock(&admin->exportedServicesLock);
+
+    celixThreadMutex_lock(&admin->importedServicesLock);
+
+    iter = hashMapIterator_create(admin->importedServices);
+    while (hashMapIterator_hasNext(iter))
+    {
+    	hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+
+    	import_registration_factory_pt importFactory = hashMapEntry_getValue(entry);
+
+        if (importFactory != NULL) {
+            int i;
+            for (i = 0; i < arrayList_size(importFactory->registrations); i++)
+            {
+                import_registration_pt importRegistration = arrayList_get(importFactory->registrations, i);
+
+                if (importFactory->trackedFactory != NULL)
+                {
+                    importFactory->trackedFactory->unregisterProxyService(importFactory->trackedFactory->factory, importRegistration->endpointDescription);
+                }
+            }
+
+            serviceTracker_close(importFactory->proxyFactoryTracker);
+            importRegistrationFactory_close(importFactory);
+
+            hashMapIterator_remove(iter);
+            importRegistrationFactory_destroy(&importFactory);
+            }
+    }
+    hashMapIterator_destroy(iter);
+    celixThreadMutex_unlock(&admin->importedServicesLock);
+
+	if (admin->ctx != NULL) {
+		logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Stopping webserver...");
+		mg_stop(admin->ctx);
+		admin->ctx = NULL;
+	}
+
+	hashMap_destroy(admin->exportedServices, false, false);
+	hashMap_destroy(admin->importedServices, false, false);
+
+	logHelper_stop(admin->loghelper);
+	logHelper_destroy(&admin->loghelper);
+
+	return status;
+}
+
+/**
+ * Request: http://host:port/services/{service}/{request}
+ */
+//void *remoteServiceAdmin_callback(enum mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info) {
+
+static int remoteServiceAdmin_callback(struct mg_connection *conn) {
+	int result = 0; // zero means: let civetweb handle it further, any non-zero value means it is handled by us...
+
+	const struct mg_request_info *request_info = mg_get_request_info(conn);
+	if (request_info->uri != NULL) {
+		remote_service_admin_pt rsa = request_info->user_data;
+
+
+		if (strncmp(request_info->uri, "/service/", 9) == 0 && strcmp("POST", request_info->request_method) == 0) {
+
+			// uri = /services/myservice/call
+			const char *uri = request_info->uri;
+			// rest = myservice/call
+
+			const char *rest = uri+9;
+			char *interfaceStart = strchr(rest, '/');
+			int pos = interfaceStart - rest;
+			char service[pos+1];
+			strncpy(service, rest, pos);
+			service[pos] = '\0';
+      long serviceId = atol(service);
+
+			celixThreadMutex_lock(&rsa->exportedServicesLock);
+
+      //find endpoint
+      export_registration_pt export = NULL;
+			hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
+			while (hashMapIterator_hasNext(iter)) {
+				hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+				array_list_pt exports = hashMapEntry_getValue(entry);
+				int expIt = 0;
+				for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
+					export_registration_pt check = arrayList_get(exports, expIt);
+					if (serviceId == check->endpointDescription->serviceId) {
+              export = check;
+              break;
+          }
+        }
+      }
+      hashMapIterator_destroy(iter);
+
+      if (export != NULL) {
+          uint64_t datalength = request_info->content_length;
+          char* data = malloc(datalength + 1);
+          mg_read(conn, data, datalength);
+          data[datalength] = '\0';
+
+          char *response = NULL;
+
+          //FIXME assuming add signature (add(double, double) : double)
+          /*TODO
+            export->endpoint->handleRequest(export->endpoint->endpoint, data, &response);
+            */
+
+
+          //retreive schema.
+          char *schema = NULL;
+          schema = properties_get(export->endpointDescription->properties, "protocol.schema");
+          printf("RSA: got schema %s\n", schema);
+
+
+          printf("Parsing data: %s\n", data);
+          json_error_t error;
+          json_t *js_request = json_loads(data, 0, &error);
+          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 {
+              printf("RSA: got error '%s' for '%s'\n", error.text, data);
+              return 0;
+          }
+
+          printf("RSA: Looking for method %s\n", sig);
+
+          json_t *js_schema = json_loads(schema, 0, &error);
+          int methodIndex = -1;
+          if (js_schema) {
+              //TODO parse schema and create cif
+              size_t index;
+              json_t *value;
+              json_array_foreach(js_schema, index, value) {
+                  if (strcmp(sig, json_string_value(value)) == 0) {
+                      //found match
+                      methodIndex = index;
+                      break;
+                  }
+              }
+          } else {
+              printf("RSA: got error '%s' for '%s'\n", error.text, schema);
+              return 0;
+          }
+
+          if (methodIndex < 0) {
+              printf("RSA: cannot find method '%s'\n", sig);
+              return 1;
+          }
+
+          size_t sigLength = strlen(sig);
+          char provArgs[sigLength];
+          bool startFound = false;
+          int i = 0;
+          int argIndex = 0;
+          for (; i < sigLength; i += 1) {
+              if (!startFound) {
+                  if (sig[i] == '(') {
+                      startFound = true;
+                  }
+              } else {
+                  if (sig[i] != ')') {
+                      provArgs[argIndex++] = sig[i];
+                  }
+              }
+          } 
+          provArgs[argIndex] = '\0';
+          size_t provArgsLength = strlen(provArgs) -1; 
+          printf("method index is %i and args are '%s'\n", methodIndex, provArgs);
+
+
+          //FFI part
+          ffi_cif cif;
+          ffi_type *argTypes[provArgsLength + 2]; //e.g. void *handle (extra), double a, double b, double *result (extra)
+          void *valuePointers[provArgsLength + 2];
+          //note assuming doubles!!
+          double values[provArgsLength];
+          double result = 0.0;
+          double *resultPointer = &result;
+          int rvalue = 0;
+
+          argTypes[0] = &ffi_type_pointer;
+          argTypes[provArgsLength +1] = &ffi_type_pointer; //last argument is return value, handled as a pointer
+          for (i = 0; i < provArgsLength; i += 1) {
+              //FIXME for now assuming double as arguments
+              argTypes[i+1] = &ffi_type_double;
+          }
+
+          valuePointers[0] = NULL;
+          valuePointers[provArgsLength+1] = &resultPointer;
+          for (i = 0; i < provArgsLength; i += 1) {
+              values[i] = 0.0;
+              valuePointers[i+1] = &(values[i]);
+          }
+
+          json_t *arguments = json_object_get(js_request, "a");
+          json_t *value;
+          size_t index;
+          json_array_foreach(arguments, index, value) {
+              values[index] = json_real_value(value); //setting values, again assuming double
+          }
+
+          json_decref(js_schema);
+          json_decref(js_request);
+
+          if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, provArgsLength + 2,
+                      &ffi_type_sint, argTypes) == FFI_OK)
+          {
+              printf("RSA: FFI PREP OK\n");
+
+              //TRYING TO CALL Calculate service
+              void *service = NULL;
+              bundleContext_getService(rsa->context, export->reference, &service);     
+              if (service == NULL) {
+                  printf("RSA: Ouch service is NULL\n");
+                  return 0;
+              } else {
+                  printf("RSA: service ok\n");
+              }
+
+              struct generic_service_layout *serv = service;
+
+              printf("RSA:Trying to call service using ffi\n");
+              valuePointers[0] = serv->handle;
+              ffi_call(&cif, serv->functions[methodIndex], &rvalue, valuePointers);
+              printf("RSA: Done calling service through ffi, got value %f\n", result);
+
+              json_t *resultRoot;
+              resultRoot = json_pack("{s:f}", "r", result);
+              response = json_dumps(resultRoot, 0);
+              json_decref(resultRoot);  
+          }
+
+          if (response != NULL) {
+              mg_write(conn, data_response_headers, strlen(data_response_headers));
+//              mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
+              mg_write(conn, response, strlen(response));
+//              mg_send_data(conn, response, strlen(response));
+//              mg_write_data(conn, response, strlen(response));
+
+              free(response);
+          } else {
+              mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
+          }
+          result = 0;
+
+          free(data);
+      } else {
+          //TODO log warning
+      }
+
+      celixThreadMutex_unlock(&rsa->exportedServicesLock);
+
+		}
+	}
+
+	return 1;
+}
+
+celix_status_t remoteServiceAdmin_handleRequest(remote_service_admin_pt rsa, char *service, char *data, char **reply) {
+	celixThreadMutex_lock(&rsa->exportedServicesLock);
+
+	hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
+	while (hashMapIterator_hasNext(iter)) {
+		hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+		array_list_pt exports = hashMapEntry_getValue(entry);
+		int expIt = 0;
+		for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
+			export_registration_pt export = arrayList_get(exports, expIt);
+			if (strcmp(service, export->endpointDescription->service) == 0) {
+				export->endpoint->handleRequest(export->endpoint->endpoint, data, reply);
+			}
+		}
+	}
+    hashMapIterator_destroy(iter);
+
+	celixThreadMutex_unlock(&rsa->exportedServicesLock);
+
+	return CELIX_SUCCESS;
+}
+
+celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations) {
+    celix_status_t status = CELIX_SUCCESS;
+    arrayList_create(registrations);
+    array_list_pt references = NULL;
+    service_reference_pt reference = NULL;
+    char filter [256];
+
+    snprintf(filter, 256, "(%s=%s)", (char *)OSGI_FRAMEWORK_SERVICE_ID, serviceId);
+
+    bundleContext_getServiceReferences(admin->context, NULL, filter, &references); //FIXME not safe
+
+    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: exportService called for serviceId %s", serviceId);
+
+    if (arrayList_size(references) >= 1) {
+        reference = arrayList_get(references, 0);
+    }
+
+    if(references!=NULL){
+        arrayList_destroy(references);
+    }
+
+    if (reference == NULL) {
+        logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "ERROR: expected a reference for service id %s.", serviceId);
+        return CELIX_ILLEGAL_STATE;
+    }
+
+    char *exports = NULL;
+    char *provided = NULL;
+    char *schema = NULL;
+    serviceReference_getProperty(reference, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exports);
+    serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_OBJECTCLASS, &provided);
+    serviceReference_getProperty(reference, (char *) "protocol.schema", &schema);
+
+    if (exports == NULL || provided == NULL) {
+        logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No Services to export.");
+            status = CELIX_ILLEGAL_STATE;
+    } else {
+        if (schema == NULL) {
+            logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: no protocol.schema found.");
+            status = CELIX_ILLEGAL_STATE;
+        } else {
+            logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Export service (%s)", provided);
+
+            char *interface = provided;
+            endpoint_description_pt endpoint = NULL;
+            export_registration_pt registration = NULL;
+
+            remoteServiceAdmin_createEndpointDescription(admin, reference, interface, &endpoint);
+            printf("RSA: Creating export registration with endpoint pointer %p\n", endpoint);
+            exportRegistration_create(admin->loghelper, reference, endpoint, admin, admin->context, &registration);
+            arrayList_add(*registrations, registration);
+
+            exportRegistration_open(registration);
+            exportRegistration_startTracking(registration);
+
+            celixThreadMutex_lock(&admin->exportedServicesLock);
+            hashMap_put(admin->exportedServices, reference, *registrations);
+            celixThreadMutex_unlock(&admin->exportedServicesLock);
+        }
+    }
+    return status;
+}
+
+celix_status_t remoteServiceAdmin_removeExportedService(export_registration_pt registration) {
+    celix_status_t status = CELIX_SUCCESS;
+    remote_service_admin_pt admin = registration->rsa;
+
+    celixThreadMutex_lock(&admin->exportedServicesLock);
+
+    hashMap_remove(admin->exportedServices, registration->reference);
+
+    celixThreadMutex_unlock(&admin->exportedServicesLock);
+
+    return status;
+}
+
+static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, char *interface, endpoint_description_pt *endpoint) {
+	celix_status_t status = CELIX_SUCCESS;
+	properties_pt endpointProperties = properties_create();
+
+
+	unsigned int size = 0;
+    char **keys;
+
+    serviceReference_getPropertyKeys(reference, &keys, &size);
+    for (int i = 0; i < size; i++) {
+        char *key = keys[i];
+        char *value = NULL;
+
+        if (serviceReference_getProperty(reference, key, &value) == CELIX_SUCCESS
+        		&& strcmp(key, (char*) OSGI_RSA_SERVICE_EXPORTED_INTERFACES) != 0
+        		&& strcmp(key, (char*) OSGI_FRAMEWORK_OBJECTCLASS) != 0) {
+        	properties_set(endpointProperties, key, value);
+          printf("Added property '%s' with value '%s'\n", key, value);
+        }
+	}
+
+	hash_map_entry_pt entry = hashMap_getEntry(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
+
+	char* key = hashMapEntry_getKey(entry);
+	char *serviceId = (char *) hashMap_remove(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
+	char *uuid = NULL;
+
+	char buf[512];
+	snprintf(buf, 512,  "/service/%s/%s", serviceId, interface);
+
+	char url[1024];
+	snprintf(url, 1024, "http://%s:%s%s", admin->ip, admin->port, buf);
+
+	uuid_t endpoint_uid;
+	uuid_generate(endpoint_uid);
+	char endpoint_uuid[37];
+	uuid_unparse_lower(endpoint_uid, endpoint_uuid);
+
+	bundleContext_getProperty(admin->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
+	properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
+	properties_set(endpointProperties, (char*) OSGI_FRAMEWORK_OBJECTCLASS, interface);
+	properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_SERVICE_ID, serviceId);
+	properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID, endpoint_uuid);
+	properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED, "true");
+  properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED_CONFIGS, (char*) CONFIGURATION_TYPE);
+  properties_set(endpointProperties, (char*) ENDPOINT_URL, url);
+
+
+
+  *endpoint = calloc(1, sizeof(**endpoint));
+  if (!*endpoint) {
+      status = CELIX_ENOMEM;
+  } else {
+      (*endpoint)->id = properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID);
+      char *serviceId = NULL;
+      serviceReference_getProperty(reference, (char*) OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
+      (*endpoint)->serviceId = strtoull(serviceId, NULL, 0);
+      (*endpoint)->frameworkUUID = properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
+      (*endpoint)->service = interface;
+      (*endpoint)->properties = endpointProperties;
+  }
+
+	free(key);
+	free(serviceId);
+	free(keys);
+
+	return status;
+}
+
+static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip) {
+	celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+
+	struct ifaddrs *ifaddr, *ifa;
+    char host[NI_MAXHOST];
+
+    if (getifaddrs(&ifaddr) != -1)
+    {
+		for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
+		{
+			if (ifa->ifa_addr == NULL)
+				continue;
+
+			if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
+				if (interface == NULL) {
+					*ip = strdup(host);
+					status = CELIX_SUCCESS;
+				}
+				else if (strcmp(ifa->ifa_name, interface) == 0) {
+					*ip = strdup(host);
+					status = CELIX_SUCCESS;
+				}
+			}
+		}
+
+		freeifaddrs(ifaddr);
+    }
+
+    return status;
+}
+
+
+celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description)
+{
+	celix_status_t status = CELIX_SUCCESS;
+
+	properties_destroy((*description)->properties);
+	free(*description);
+
+	return status;
+}
+
+
+celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services) {
+	celix_status_t status = CELIX_SUCCESS;
+	return status;
+}
+
+celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services) {
+	celix_status_t status = CELIX_SUCCESS;
+	return status;
+}
+
+
+static int remoteServiceAdmin_remoteFunctionProxy(ffi_cif *cif, int *ret, void* args[], void *userData); //TODO MOVE
+static int remoteServiceAdmin_remoteFunctionProxy(ffi_cif *cif, int *ret, void* args[], void *userData) {
+   void **handle = args[0];
+   remote_service_admin_pt admin = (*handle);
+
+   struct proxy *proxy = userData;
+
+   printf("ffi closure got called for method sig %s with index %i\n", proxy->sig, proxy->index);
+
+   json_t *root = json_object();
+   json_t *sig = json_string(proxy->sig);
+   json_object_set(root, "m", sig);
+
+   json_t *arguments = json_array();
+   int i;
+   for (i = 1; i < proxy->cif.nargs -1; i += 1) {
+       //NOTE assuming double
+       double *dval = args[i];
+       json_t *value = json_real(*dval);
+       json_array_append(arguments, value);
+   }
+   json_object_set(root, "a", arguments);
+
+   char *data = json_dumps(root, 0);
+   char *reply = NULL;
+   int replyStatus;
+
+   remoteServiceAdmin_send(proxy->admin, proxy->endpointDescription, data, &reply, &replyStatus);
+   (*ret) = replyStatus;
+   printf("got reply from server '%s'\n", reply);
+
+   json_error_t error;
+   json_t *js_reply = json_loads(reply, JSON_DECODE_ANY, &error);
+   if (js_reply) {
+       //note assuming double
+       double **result = args[proxy->cif.nargs - 1];
+       json_unpack(js_reply, "{s:f}", "r", *result);
+       json_decref(js_reply);
+   } else {
+       printf("PROXY: got error '%s' for '%s'\n", error.text, reply);
+   }
+
+   json_decref(root);
+
+   free(data);
+   free(reply);
+
+   return 0;
+}
+
+
+celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpointDescription, import_registration_pt *registration) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Import service %s", endpointDescription->service);
+
+  char *schema = properties_get(endpointDescription->properties, "protocol.schema");
+  if (schema == NULL) {
+    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: protocol schema not found for endpoint\n");
+    return CELIX_SUCCESS;
+  }
+
+  printf("protocol.schema is '%s'\n", schema);
+  json_error_t error;
+  json_t *js_schema = json_loads(schema, 0, &error);
+  if (js_schema) {
+      //TODO parse schema and create cif
+      size_t numOfMethods = json_array_size(js_schema);
+      printf("RSA: num of method for proxy is %i\n", (int) numOfMethods);
+
+      struct generic_service_layout *service = calloc(1, sizeof(*service) + (numOfMethods-1) * sizeof(GEN_FUNC_TYPE)); 
+      service->handle = admin;
+
+        //struct generic_service_layout {
+        //    void *handle;
+        //    GEN_FUNC_TYPE functions[];
+        //};
+
+      size_t index;
+      json_t *value;
+      json_array_foreach(js_schema, index, value) {
+          //create closure
+
+          char *sig = json_string_value(value);
+          size_t sigLength = strlen(sig);
+          char provArgs[sigLength];
+          bool startFound = false;
+          int i = 0;
+          int argIndex = 0;
+          for (; i < sigLength; i += 1) {
+              if (!startFound) {
+                  if (sig[i] == '(') {
+                      startFound = true;
+                  }
+              } else {
+                  if (sig[i] != ')') {
+                      provArgs[argIndex++] = sig[i];
+                  }
+              }
+          } 
+          provArgs[argIndex] = '\0';
+          printf("method index is %i and args are '%s'\n", index, provArgs);
+
+          int provArgLength = strlen(provArgs) -1;
+
+          struct proxy *proxy = malloc(sizeof(*proxy));
+          proxy->admin = admin;
+          proxy->sig = strdup(sig);
+          proxy->index = index;
+          proxy->endpointDescription = endpointDescription;
+          
+          ffi_type **args = calloc(provArgLength +2, sizeof(ffi_type)); //TODO test if this can be on the stack
+
+          void (*function)(void);
+          proxy->closure = ffi_closure_alloc(sizeof(ffi_closure), &function);
+          service->functions[index] = function;
+
+          /* Initialize the argument info vectors */
+          args[0] = &ffi_type_pointer;
+          args[provArgLength + 1] = &ffi_type_pointer;
+          for (i = 0; i < provArgLength; i += 1) {
+              args[i+1] = &ffi_type_double;
+          }
+
+          if (proxy->closure) {
+            if (ffi_prep_cif(&proxy->cif, FFI_DEFAULT_ABI, provArgLength + 2, &ffi_type_sint, args) == FFI_OK) {
+                if (ffi_prep_closure_loc(proxy->closure, &proxy->cif, remoteServiceAdmin_remoteFunctionProxy, proxy, function) == FFI_OK) {
+                    printf("RSA: created closure for method '%s'\n", sig);
+                }
+            }
+          }
+      }
+                   
+      //TODO register with imported properties 
+      char *objectClass = properties_get(endpointDescription->properties, "objectClass");
+      service_registration_pt reg = NULL;
+      bundleContext_registerService(admin->context, objectClass, service, NULL, &reg);
+      printf("registered proxy service with objectclass '%s'\n", objectClass);
+
+  } else {
+      printf("RSA: got error '%s' for '%s'\n", error.text, schema);
+      return CELIX_ILLEGAL_STATE;
+  }
+
+
+  //celixThreadMutex_lock(&admin->importedServicesLock);
+  //celixThreadMutex_unlock(&admin->importedServicesLock);
+
+
+  return status;
+  /*
+
+	celixThreadMutex_lock(&admin->importedServicesLock);
+
+   import_registration_factory_pt registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
+
+	// check whether we already have a registration_factory registered in the hashmap
+	if (registration_factory == NULL)
+	{
+		status = importRegistrationFactory_install(admin->loghelper, endpointDescription->service, admin->context, &registration_factory);
+		if (status == CELIX_SUCCESS) {
+		    hashMap_put(admin->importedServices, endpointDescription->service, registration_factory);
+		}
+	}
+
+	 // factory available
+	if (status != CELIX_SUCCESS || (registration_factory->trackedFactory == NULL))
+	{
+		logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: no proxyFactory available.");
+		if (status == CELIX_SUCCESS) {
+			status = CELIX_SERVICE_EXCEPTION;
+		}
+	}
+	else
+	{
+		// we create an importRegistration per imported service
+		importRegistration_create(endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send, admin->context, registration);
+		registration_factory->trackedFactory->registerProxyService(registration_factory->trackedFactory->factory,  endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send);
+
+		arrayList_add(registration_factory->registrations, *registration);
+	}
+
+    celixThreadMutex_unlock(&admin->importedServicesLock);
+
+
+	return status;
+  */
+}
+
+
+celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration) {
+	celix_status_t status = CELIX_SUCCESS;
+  return status;
+  /*
+
+	endpoint_description_pt endpointDescription = (endpoint_description_pt) registration->endpointDescription;
+	import_registration_factory_pt registration_factory = NULL;
+
+    celixThreadMutex_lock(&admin->importedServicesLock);
+
+    registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
+
+    // factory available
+    if ((registration_factory == NULL) || (registration_factory->trackedFactory == NULL))
+    {
+    	logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: Error while retrieving registration factory for imported service %s", endpointDescription->service);
+    }
+    else
+    {
+		registration_factory->trackedFactory->unregisterProxyService(registration_factory->trackedFactory->factory, endpointDescription);
+		arrayList_removeElement(registration_factory->registrations, registration);
+		importRegistration_destroy(registration);
+
+		if (arrayList_isEmpty(registration_factory->registrations))
+		{
+			logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: closing proxy.");
+
+			serviceTracker_close(registration_factory->proxyFactoryTracker);
+			importRegistrationFactory_close(registration_factory);
+
+			hashMap_remove(admin->importedServices, endpointDescription->service);
+
+			importRegistrationFactory_destroy(&registration_factory);
+		}
+    }
+
+    celixThreadMutex_unlock(&admin->importedServicesLock);
+
+	return status;
+  */
+}
+
+
+celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus) {
+
+    struct post post;
+    post.readptr = request;
+    post.size = strlen(request);
+
+    struct get get;
+    get.size = 0;
+    get.writeptr = malloc(1);
+
+    char *serviceUrl = properties_get(endpointDescription->properties, (char*) ENDPOINT_URL);
+    char url[256];
+    snprintf(url, 256, "%s", serviceUrl);
+
+    // assume the default timeout
+    int timeout = DEFAULT_TIMEOUT;
+
+    char *timeoutStr = NULL;
+    // Check if the endpoint has a timeout, if so, use it.
+	timeoutStr = properties_get(endpointDescription->properties, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT);
+    if (timeoutStr == NULL) {
+    	// If not, get the global variable and use that one.
+    	bundleContext_getProperty(rsa->context, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT, &timeoutStr);
+    }
+
+    // Update timeout if a property is used to set it.
+    if (timeoutStr != NULL) {
+    	timeout = atoi(timeoutStr);
+    }
+
+    celix_status_t status = CELIX_SUCCESS;
+    CURL *curl;
+    CURLcode res;
+
+    curl = curl_easy_init();
+    if(!curl) {
+        status = CELIX_ILLEGAL_STATE;
+    } else {
+    	curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
+        curl_easy_setopt(curl, CURLOPT_URL, &url[0]);
+        curl_easy_setopt(curl, CURLOPT_POST, 1L);
+        curl_easy_setopt(curl, CURLOPT_READFUNCTION, remoteServiceAdmin_readCallback);
+        curl_easy_setopt(curl, CURLOPT_READDATA, &post);
+        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, remoteServiceAdmin_write);
+        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&get);
+        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)post.size);
+        res = curl_easy_perform(curl);
+        curl_easy_cleanup(curl);
+
+        *reply = get.writeptr;
+        *replyStatus = res;
+    }
+
+    return status;
+}
+
+static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp) {
+    struct post *post = userp;
+
+    if (post->size) {
+        *(char *) ptr = post->readptr[0];
+        post->readptr++;
+        post->size--;
+        return 1;
+    }
+
+    return 0;
+}
+
+static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp) {
+  size_t realsize = size * nmemb;
+  struct get *mem = (struct get *)userp;
+
+  mem->writeptr = realloc(mem->writeptr, mem->size + realsize + 1);
+  if (mem->writeptr == NULL) {
+    /* out of memory! */
+	printf("not enough memory (realloc returned NULL)");
+    exit(EXIT_FAILURE);
+  }
+
+  memcpy(&(mem->writeptr[mem->size]), contents, realsize);
+  mem->size += realsize;
+  mem->writeptr[mem->size] = 0;
+
+  return realsize;
+}
+
+
+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;
+}
+
+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;
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/3d7f7641/remote_services/remote_service_admin_http_ffi/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http_ffi/CMakeLists.txt b/remote_services/remote_service_admin_http_ffi/CMakeLists.txt
deleted file mode 100644
index 6180ef0..0000000
--- a/remote_services/remote_service_admin_http_ffi/CMakeLists.txt
+++ /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.
-celix_subproject(RSA_REMOTE_SERVICE_ADMIN_HTTP "Option to enable building the Remote Service Admin Service HTTP ffi" OFF)
-if (RSA_REMOTE_SERVICE_ADMIN_HTTP)
-    find_package(CURL REQUIRED)
-    find_package(Jansson REQUIRED)
-    find_package(FFI REQUIRED)
-    
-    include_directories(${FFI_INCLUDE_DIRS})
-    include_directories(${CURL_INCLUDE_DIRS})
-    include_directories(${JANSSON_INCLUDE_DIRS})
-    include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
-    include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
-    include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/private/include")
-    include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/public/include")
-    include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
-    include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/include")
-    include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_http/private/include")
-    include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
-    
-    SET_HEADER(BUNDLE_SYMBOLICNAME "apache_celix_remote_service_admin_http_ffi")
-    SET(BUNDLE_VERSION "0.0.1")
-    SET_HEADERS("Bundle-Name: Apache Celix Remote Service Admin HTTP for ffi")
-    
-    bundle(remote_service_admin_http SOURCES
-    private/src/remote_service_admin_impl
-    private/src/remote_service_admin_activator
-    ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/export_registration_impl
-    ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/import_registration_impl
-    ${PROJECT_SOURCE_DIR}/remote_services/utils/private/src/civetweb.c
-    ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
-    )
-
-	install_bundle(remote_service_admin_http)
-
-  target_link_libraries(remote_service_admin_http celix_framework ${CURL_LIBRARIES} ${JANSSON_LIBRARIES} ${FFI_LIBRARIES}) 
-endif (RSA_REMOTE_SERVICE_ADMIN_HTTP)

http://git-wip-us.apache.org/repos/asf/celix/blob/3d7f7641/remote_services/remote_service_admin_http_ffi/private/include/remote_service_admin_http_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http_ffi/private/include/remote_service_admin_http_impl.h b/remote_services/remote_service_admin_http_ffi/private/include/remote_service_admin_http_impl.h
deleted file mode 100644
index dbf71c9..0000000
--- a/remote_services/remote_service_admin_http_ffi/private/include/remote_service_admin_http_impl.h
+++ /dev/null
@@ -1,52 +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_impl.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_stop(remote_service_admin_pt admin);
-
-#endif /* REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/3d7f7641/remote_services/remote_service_admin_http_ffi/private/src/remote_service_admin_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http_ffi/private/src/remote_service_admin_activator.c b/remote_services/remote_service_admin_http_ffi/private/src/remote_service_admin_activator.c
deleted file mode 100644
index e4125fc..0000000
--- a/remote_services/remote_service_admin_http_ffi/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_impl.h"
-#include "import_registration_impl.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;
-}
-
-


[11/50] [abbrv] celix git commit: CELIX-237: Added setup for client - server ccputest. This test start two embedded Celix frameworks for remote services test

Posted by pn...@apache.org.
CELIX-237: Added setup for client - server ccputest. This test start two embedded Celix frameworks for remote services test


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

Branch: refs/heads/develop
Commit: 30f7e8419c28d085e7e782a7dcd6828c1eb79e3f
Parents: da86474
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Mon Aug 10 22:07:15 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon Aug 10 22:07:15 2015 +0200

----------------------------------------------------------------------
 remote_services/CMakeLists.txt                  |   7 +-
 .../private/src/endpoint_discovery_poller.c     |   5 +-
 .../examples/calculator_service/CMakeLists.txt  |   2 +-
 ....apache.celix.calc.api.Calculator.descriptor |  11 --
 ...apache.celix.calc.api.Calculator2.descriptor |  11 ++
 .../examples/calculator_shell/CMakeLists.txt    |   4 +
 .../dynamic_function_interface/dyn_type.h       |   6 +-
 .../private/include/export_registration_dfi.h   |   2 +-
 .../private/src/export_registration_dfi.c       | 131 +++++++++++++++----
 .../private/src/import_registration_dfi.c       |  12 +-
 .../private/src/remote_service_admin_dfi.c      |  32 +----
 .../remote_service_admin_dfi/tst/CMakeLists.txt |  52 +++++---
 .../tst/bundle/CMakeLists.txt                   |  20 +++
 .../tst/bundle/tst_activator.c                  |  91 +++++++++++++
 .../tst/bundle/tst_service.h                    |  17 +++
 .../tst/client.properties.in                    |   7 +
 .../tst/config.properties.in                    |   3 +-
 .../tst/rsa_client_server_tests.cpp             | 118 +++++++++++++++++
 .../remote_service_admin_dfi/tst/rsa_tests.cpp  |  28 +++-
 .../tst/server.properties.in                    |   7 +
 20 files changed, 464 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/CMakeLists.txt b/remote_services/CMakeLists.txt
index a16977f..abc9177 100644
--- a/remote_services/CMakeLists.txt
+++ b/remote_services/CMakeLists.txt
@@ -33,14 +33,15 @@ if (REMOTE_SERVICE_ADMIN)
 
     add_subdirectory(topology_manager)
 
+    add_subdirectory(discovery_configured)
+    add_subdirectory(discovery_etcd)
+    add_subdirectory(discovery_shm)
+
     add_subdirectory(remote_service_admin)
     add_subdirectory(remote_service_admin_http)
     add_subdirectory(remote_service_admin_dfi)
     add_subdirectory(remote_service_admin_shm)
 
-    add_subdirectory(discovery_configured)
-    add_subdirectory(discovery_etcd)
-    add_subdirectory(discovery_shm)
 
 endif (REMOTE_SERVICE_ADMIN)
 

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/discovery/private/src/endpoint_discovery_poller.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/src/endpoint_discovery_poller.c b/remote_services/discovery/private/src/endpoint_discovery_poller.c
index 569d7a9..d8c16a5 100644
--- a/remote_services/discovery/private/src/endpoint_discovery_poller.c
+++ b/remote_services/discovery/private/src/endpoint_discovery_poller.c
@@ -325,6 +325,8 @@ static size_t endpointDiscoveryPoller_writeMemory(void *contents, size_t size, s
 static celix_status_t endpointDiscoveryPoller_getEndpoints(endpoint_discovery_poller_pt poller, char *url, array_list_pt *updatedEndpoints) {
     celix_status_t status = CELIX_SUCCESS;
 
+	logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_DEBUG, "Polling url '%s'", url);
+
     CURL *curl = NULL;
     CURLcode res = CURLE_OK;
 
@@ -349,6 +351,7 @@ static celix_status_t endpointDiscoveryPoller_getEndpoints(endpoint_discovery_po
 
     	status = endpointDescriptorReader_create(poller, &reader);
     	if (status == CELIX_SUCCESS) {
+			logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_DEBUG, "Polled data '%s'", chunk.memory);
 			status = endpointDescriptorReader_parseDocument(reader, chunk.memory, updatedEndpoints);
     	}
 
@@ -356,7 +359,7 @@ static celix_status_t endpointDiscoveryPoller_getEndpoints(endpoint_discovery_po
 			endpointDescriptorReader_destroy(reader);
     	}
     } else {
-    	logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_ERROR, "ENDPOINT_POLLER: unable to read endpoints, reason: %s", curl_easy_strerror(res));
+    	logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_ERROR, "ENDPOINT_POLLER: unable to read endpoints at '%s', reason: %s", url, curl_easy_strerror(res));
     }
 
     // clean up endpoints file

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/examples/calculator_service/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/CMakeLists.txt b/remote_services/examples/calculator_service/CMakeLists.txt
index 91596ab..a3cad0d 100644
--- a/remote_services/examples/calculator_service/CMakeLists.txt
+++ b/remote_services/examples/calculator_service/CMakeLists.txt
@@ -31,7 +31,7 @@ SET(BUNDLE_VERSION "0.0.1")
     private/include/calculator_impl.h
 
     FILES
-        org.apache.celix.calc.api.Calculator.descriptor
+        public/include/org.apache.celix.calc.api.Calculator2.descriptor
 )
 
 target_link_libraries(calculator celix_framework)

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/examples/calculator_service/org.apache.celix.calc.api.Calculator.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/org.apache.celix.calc.api.Calculator.descriptor b/remote_services/examples/calculator_service/org.apache.celix.calc.api.Calculator.descriptor
deleted file mode 100644
index 711df0b..0000000
--- a/remote_services/examples/calculator_service/org.apache.celix.calc.api.Calculator.descriptor
+++ /dev/null
@@ -1,11 +0,0 @@
-:header
-type=interface
-name=calculator
-version=1.0.0
-:annotations
-classname=org.example.Calculator
-:types
-:methods
-add(DD)D=add(PDD*D)N
-sub(DD)D=sub(PDD*D)N
-sqrt(D)D=sqrt(PD*D)N

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor b/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
new file mode 100644
index 0000000..711df0b
--- /dev/null
+++ b/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
@@ -0,0 +1,11 @@
+:header
+type=interface
+name=calculator
+version=1.0.0
+:annotations
+classname=org.example.Calculator
+:types
+:methods
+add(DD)D=add(PDD*D)N
+sub(DD)D=sub(PDD*D)N
+sqrt(D)D=sqrt(PD*D)N

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/examples/calculator_shell/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/CMakeLists.txt b/remote_services/examples/calculator_shell/CMakeLists.txt
index 955e688..dcb8c8f 100644
--- a/remote_services/examples/calculator_shell/CMakeLists.txt
+++ b/remote_services/examples/calculator_shell/CMakeLists.txt
@@ -33,6 +33,10 @@ bundle(calculator_shell SOURCES
     private/include/sqrt_command.h
     private/include/sub_command.h
     ../../../shell/public/src/command.c
+
+
+        FILES
+            ../calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
 )
 
 target_link_libraries(calculator_shell celix_framework)

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/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
index 9fdbff2..a409ff5 100644
--- 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
@@ -14,9 +14,9 @@
 
 #include "dfi_log_util.h"
 
-#if defined(BSD) || defined(__APPLE__) 
-#include "open_memstream.h"
-#include "fmemopen.h"
+#if defined(BSD) || defined(__APPLE__)
+#include "memstream/open_memstream.h"
+#include "memstream/fmemopen.h"
 #endif
 
 /* Description string

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/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
index 4faf9b9..4356646 100644
--- 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
@@ -10,7 +10,7 @@
 #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);
-celix_status_t exportRegistration_destroy(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);

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/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
index 7814d0d..95d58b9 100644
--- 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
@@ -4,35 +4,89 @@
 #include <jansson.h>
 #include <dyn_interface.h>
 #include <json_serializer.h>
+#include <remote_constants.h>
 #include "export_registration.h"
 #include "export_registration_dfi.h"
 #include "endpoint_description.h"
 
-struct export_registration {
-    endpoint_description_pt endpointDescription;
+struct export_reference {
+    endpoint_description_pt endpoint; //owner
     service_reference_pt reference;
-    dyn_interface_type *intf;
+};
+
+struct export_registration {
+    bundle_context_pt  context;
+    struct export_reference exportReference;
     void *service;
-    bundle_pt bundle;
+    dyn_interface_type *intf; //owner
 
+    //TODO add tracker and lock
     bool closed;
 };
 
-struct export_reference {
-    endpoint_description_pt endpoint;
-    service_reference_pt reference;
-};
-
-typedef void (*GEN_FUNC_TYPE)(void);
-
 struct generic_service_layout {
     void *handle;
-    GEN_FUNC_TYPE methods[];
+    void **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 *registration) {
+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;
-    //TODO
+
+    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, &reg->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;
 }
 
@@ -108,27 +162,40 @@ celix_status_t exportRegistration_call(export_registration_pt export, char *data
     return status;
 }
 
-celix_status_t exportRegistration_destroy(export_registration_pt registration) {
-    celix_status_t status = CELIX_SUCCESS;
-    //TODO
-    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 registration) {
+celix_status_t exportRegistration_start(export_registration_pt reg) {
     celix_status_t status = CELIX_SUCCESS;
-    //TODO
+    status = bundleContext_getService(reg->context, reg->exportReference.reference, &reg->service); //TODO use tracker
     return status;
 }
 
-celix_status_t exportRegistration_stop(export_registration_pt registration) {
+celix_status_t exportRegistration_stop(export_registration_pt reg) {
     celix_status_t status = CELIX_SUCCESS;
-    //TODO
+    status = bundleContext_ungetService(reg->context, reg->exportReference.reference, NULL);
     return status;
 }
 
-celix_status_t exportRegistration_close(export_registration_pt registration) {
+celix_status_t exportRegistration_close(export_registration_pt reg) {
     celix_status_t status = CELIX_SUCCESS;
-    //TODO
+    exportRegistration_stop(reg);
+    //TODO callback to rsa to remove from list
     return status;
 }
 
@@ -138,9 +205,21 @@ celix_status_t exportRegistration_getException(export_registration_pt registrati
     return status;
 }
 
-celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *reference) {
+celix_status_t exportRegistration_getExportReference(export_registration_pt registration, export_reference_pt *out) {
     celix_status_t status = CELIX_SUCCESS;
-    //TODO
+    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;
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/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
index f8c544c..4e424a8 100644
--- 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
@@ -1,4 +1,4 @@
-#include <malloc.h>
+#include <stdlib.h>
 #include "dyn_interface.h"
 #include "import_registration.h"
 #include "import_registration_dfi.h"
@@ -84,6 +84,16 @@ 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 **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);

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
index eae2816..5e11c3b 100644
--- a/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
+++ b/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
@@ -414,34 +414,8 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c
         if (exports == NULL || provided == NULL || strcmp(exports, provided) != 0) {
             logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No Services to export.");
             status = CELIX_ILLEGAL_STATE;
-        }
-    }
-
-    bundle_pt bundle = NULL;
-    if (status == CELIX_SUCCESS) {
-        logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Export service (%s)", provided);
-        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);
-    }
-
-    if (status == CELIX_SUCCESS) {
-        dyn_interface_type *intf = NULL;
-        if (descriptorFile != NULL) {
-            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(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: Error parsing service descriptor.");
-                }
-            }
+        } else {
+            logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Export service (%s)", provided);
         }
     }
 
@@ -452,6 +426,7 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c
 
         remoteServiceAdmin_createEndpointDescription(admin, reference, interface, &endpoint);
         printf("RSA: Creating export registration with endpoint pointer %p\n", endpoint);
+        //TOOD precheck if descriptor exists
         status = exportRegistration_create(admin->loghelper, reference, endpoint, admin->context, &registration);
         if (status == CELIX_SUCCESS) {
             status = exportRegistration_start(registration);
@@ -461,6 +436,7 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c
         }
     }
 
+
     if (status == CELIX_SUCCESS) {
         celixThreadMutex_lock(&admin->exportedServicesLock);
         hashMap_put(admin->exportedServices, reference, *registrations);

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt b/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
index d0814c6..a184d21 100644
--- a/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
@@ -2,34 +2,48 @@
 # Licensed under Apache License v2. See LICENSE for more information.
 #
 
-include_directories(
-	${PROJECT_SOURCE_DIR}/launcher/public/include
-    ${CPPUTEST_INCLUDE_DIR}
-    ${PROJECT_SOURCE_DIR}/framework/public/include
-    ${PROJECT_SOURCE_DIR}/utils/public/include
-)
-
-#if (FRAMEWORK_TESTS) TODO
+#TODO add FRAMEWORK_TEST / TEST check
+#if (RSA_EXAMPLES)
+
+    add_subdirectory(bundle)
+
+    include_directories(
+        ${PROJECT_SOURCE_DIR}/launcher/public/include
+        ${CPPUTEST_INCLUDE_DIR}
+        ${PROJECT_SOURCE_DIR}/framework/public/include
+        ${PROJECT_SOURCE_DIR}/utils/public/include
+        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")
 
-	add_executable(test_rsa_dfi
-	    run_tests.cpp
-	    rsa_tests.cpp
+    add_executable(test_rsa_dfi
+        run_tests.cpp
+        rsa_tests.cpp
+        rsa_client_server_tests.cpp
 
-	    ${PROJECT_SOURCE_DIR}/launcher/private/src/launcher.c #TODO move to libframework
-	    ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
-	)
-	target_link_libraries(test_rsa_dfi ${CPPUTEST_LIBRARY} celix_framework celix_utils ${CURL_LIBRARIES})
+        ${PROJECT_SOURCE_DIR}/launcher/private/src/launcher.c #TODO move to libframework
+        ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
+    )
+    target_link_libraries(test_rsa_dfi celix_framework celix_utils ${CURL_LIBRARIES})
+
+    get_property(rsa_bundle_file TARGET remote_service_admin_dfi PROPERTY BUNDLE)
+    get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE)
+    get_property(calculator_shell_bundle_file TARGET calculator_shell PROPERTY BUNDLE)
+    get_property(discovery_configured_bundle_file TARGET discovery_configured PROPERTY BUNDLE)
+    get_property(topology_manager_bundle_file TARGET topology_manager PROPERTY BUNDLE)
+    get_property(tst_bundle_file TARGET rsa_dfi_tst_bundle PROPERTY BUNDLE)
 
-	get_property(rsa_bundle_file TARGET remote_service_admin_dfi PROPERTY BUNDLE)
-	get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE)
     configure_file(config.properties.in config.properties @ONLY)
+    configure_file(client.properties.in client.properties @ONLY)
+    configure_file(server.properties.in server.properties @ONLY)
 
     add_dependencies(test_rsa_dfi remote_service_admin_dfi calculator)
 
 
-	add_test(NAME run_test_rsa_dfi COMMAND test_rsa_dfi)
-	SETUP_TARGET_FOR_COVERAGE(test_rsa_dfi_cov test_rsa_dfi ${CMAKE_BINARY_DIR}/coverage/rsa_dfi)
+    add_test(NAME run_test_rsa_dfi COMMAND test_rsa_dfi)
+    SETUP_TARGET_FOR_COVERAGE(test_rsa_dfi_cov test_rsa_dfi ${CMAKE_BINARY_DIR}/coverage/rsa_dfi)
+
 #endif()

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt b/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt
new file mode 100644
index 0000000..e1d4fb3
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt
@@ -0,0 +1,20 @@
+#
+# Licensed under Apache License v2. See LICENSE for more information.
+#
+
+include_directories(
+        ${PROJECT_SOURCE_DIR}/launcher/public/include
+        ${CPPUTEST_INCLUDE_DIR}
+        ${PROJECT_SOURCE_DIR}/framework/public/include
+        ${PROJECT_SOURCE_DIR}/utils/public/include
+)
+
+
+bundle(rsa_dfi_tst_bundle
+    SOURCES
+        tst_activator.c
+
+    FILES
+        ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
+)
+target_link_libraries(rsa_dfi_tst_bundle ${CPPUTEST_LIBRARY} celix_framework celix_utils)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c b/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c
new file mode 100644
index 0000000..9b16e65
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c
@@ -0,0 +1,91 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "bundle_activator.h"
+#include "bundle_context.h"
+#include "service_registration.h"
+#include "service_reference.h"
+#include "celix_errno.h"
+
+#include "tst_service.h"
+#include "calculator_service.h"
+
+
+struct activator {
+	bundle_context_pt context;
+	struct tst_service serv;
+	service_registration_pt  reg;
+};
+
+static void test(void *handle);
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **out) {
+	celix_status_t status = CELIX_SUCCESS;
+	struct activator *act = calloc(1, sizeof(*act));
+	if (act != NULL) {
+		act->context = context;
+		act->serv.handle = act;
+		act->serv.test = test;
+	} else {
+		status = CELIX_ENOMEM;
+	}
+
+	if (status == CELIX_SUCCESS) {
+		*out = act;
+	}
+
+	return CELIX_SUCCESS;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+    celix_status_t status = CELIX_SUCCESS;
+	struct activator * act = userData;
+
+	act->reg = NULL;
+	status = bundleContext_registerService(context, (char *)TST_SERVICE_NAME, &act->serv, NULL, &act->reg);
+
+	return status;
+}
+
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+    celix_status_t status = CELIX_SUCCESS;
+	struct activator * act = userData;
+
+	status = serviceRegistration_unregister(act->reg);
+
+	return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+	free(userData);
+	return CELIX_SUCCESS;
+}
+
+static void test(void *handle) {
+	struct activator *act = handle;
+	bundle_context_pt context = act->context;
+	//TODO improve. don't use asserts.
+
+	int rc = 0;
+	service_reference_pt ref = NULL;
+	calculator_service_pt calc = NULL;
+
+	rc = bundleContext_getServiceReference(context, (char *)CALCULATOR2_SERVICE, &ref);
+	assert(rc == 0);
+
+	rc = bundleContext_getService(context, ref, (void **)&calc);
+	assert(rc == 0);
+
+	double result = 0.0;
+	rc = calc->sqrt(calc->calculator, 4, &result);
+	assert(rc == 0);
+	assert(result == 2);
+
+	bundleContext_ungetService(context, ref, NULL);
+	bundleContext_ungetServiceReference(context, ref);
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h b/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h
new file mode 100644
index 0000000..2fc2b21
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h
@@ -0,0 +1,17 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+
+#ifndef CELIX_TST_SERVICE_H
+#define CELIX_TST_SERVICE_H
+
+#define TST_SERVICE_NAME "tst_service"
+
+struct tst_service {
+    void *handle;
+    void (*test)(void *handle);
+};
+
+typedef struct tst_service *tst_service_pt;
+
+#endif //CELIX_TST_SERVICE_H

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/client.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/client.properties.in b/remote_services/remote_service_admin_dfi/tst/client.properties.in
new file mode 100644
index 0000000..9cde4bd
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/tst/client.properties.in
@@ -0,0 +1,7 @@
+cosgi.auto.start.1=@rsa_bundle_file@ @calculator_shell_bundle_file@ @discovery_configured_bundle_file@ @topology_manager_bundle_file@ @tst_bundle_file@
+LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+RSA_PORT=50881
+DISCOVERY_CFG_SERVER_PORT=50991
+DISCOVERY_CFG_POLL_ENDPOINTS=http://127.0.0.1:50992/org.apache.celix.discovery.configured
+org.osgi.framework.storage.clean=onFirstInit
+DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/config.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/config.properties.in b/remote_services/remote_service_admin_dfi/tst/config.properties.in
index df5e625..8412214 100644
--- a/remote_services/remote_service_admin_dfi/tst/config.properties.in
+++ b/remote_services/remote_service_admin_dfi/tst/config.properties.in
@@ -1,2 +1,3 @@
 cosgi.auto.start.1=@rsa_bundle_file@ @calc_bundle_file@
-LOGHELPER_ENABLE_STDOUT_FALLBACK=true
\ No newline at end of file
+LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+org.osgi.framework.storage.clean=onFirstInit
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp b/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp
new file mode 100644
index 0000000..5ffb47a
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp
@@ -0,0 +1,118 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#include <CppUTest/TestHarness.h>
+#include <remote_constants.h>
+#include <constants.h>
+#include "CppUTest/CommandLineTestRunner.h"
+#include "../../examples/calculator_service/public/include/calculator_service.h"
+
+extern "C" {
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+
+#include "launcher.h"
+#include "framework.h"
+#include "remote_service_admin.h"
+#include "calculator_service.h"
+
+    static framework_pt serverFramework = NULL;
+    static bundle_context_pt serverContext = NULL;
+
+    static framework_pt clientFramework = NULL;
+    static bundle_context_pt clientContext = NULL;
+
+    static void setupFm(void) {
+        int rc = 0;
+        bundle_pt bundle = NULL;
+
+        //server
+        rc = celixLauncher_launch("server.properties", &serverFramework);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        bundle = NULL;
+        rc = framework_getFrameworkBundle(serverFramework, &bundle);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = bundle_getContext(bundle, &serverContext);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+
+        //client
+        rc = celixLauncher_launch("client.properties", &clientFramework);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        bundle = NULL;
+        rc = framework_getFrameworkBundle(clientFramework, &bundle);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = bundle_getContext(bundle, &clientContext);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+    }
+
+    static void teardownFm(void) {
+        int rc = 0;
+
+        celixLauncher_stop(serverFramework);
+        celixLauncher_waitForShutdown(serverFramework);
+        celixLauncher_destroy(serverFramework);
+
+        celixLauncher_stop(clientFramework);
+        celixLauncher_waitForShutdown(clientFramework);
+        celixLauncher_destroy(clientFramework);
+
+        serverContext = NULL;
+        serverFramework = NULL;
+        clientContext = NULL;
+        clientFramework = NULL;
+    }
+
+    static void test1(void) {
+        int rc = 0;
+        /* TODO use tst_service for (which has a descriptor file of the calculator service)
+        service_reference_pt ref = NULL;
+        calculator_service_pt calc = NULL;
+
+        usleep(5000000); //needed to accept connection (firewall)
+
+        bundleContext_getServiceReference(clientContext, (char *)CALCULATOR2_SERVICE, &ref);
+        CHECK_EQUAL(0, rc);
+        CHECK(ref != NULL);
+
+        //NOTE will not work. using framework context. need to use calc client context (lookup bundle / create own?)
+
+        bundleContext_getService(clientContext, ref, (void **)&calc);
+        CHECK_EQUAL(0, rc);
+        CHECK(calc != NULL);
+
+        double result = 0.0;
+        rc = calc->sqrt(calc->calculator, 4, &result);
+        CHECK_EQUAL(0, rc);
+        CHECK(result == 2.0);
+
+        bundleContext_ungetService(clientContext, ref, NULL);
+        bundleContext_ungetServiceReference(clientContext, ref);
+         */
+    }
+
+}
+
+
+TEST_GROUP(RsaDfiClientServerTests) {
+    void setup() {
+        setupFm();
+    }
+
+    void teardown() {
+        teardownFm();
+    }
+};
+
+TEST(RsaDfiClientServerTests, Test1) {
+    test1();
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp b/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
index 060b15b..1384573 100644
--- a/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
@@ -21,14 +21,14 @@ extern "C" {
 #include "calculator_service.h"
 
 
-    framework_pt framework = NULL;
-    bundle_context_pt context = NULL;
+    static framework_pt framework = NULL;
+    static bundle_context_pt context = NULL;
 
-    service_reference_pt rsaRef = NULL;
-    remote_service_admin_service_pt rsa = NULL;
+    static service_reference_pt rsaRef = NULL;
+    static remote_service_admin_service_pt rsa = NULL;
 
-    service_reference_pt calcRef = NULL;
-    calculator_service_pt calc = NULL;
+    static service_reference_pt calcRef = NULL;
+    static calculator_service_pt calc = NULL;
 
     static void setupFm(void) {
         int rc = 0;
@@ -50,7 +50,7 @@ extern "C" {
         rc = bundleContext_getService(context, rsaRef, (void **)&rsa);
         CHECK_EQUAL(CELIX_SUCCESS, rc);
 
-        rc = bundleContext_getServiceReference(context, (char *)CALCULATOR_SERVICE, &calcRef);
+        rc = bundleContext_getServiceReference(context, (char *)CALCULATOR2_SERVICE, &calcRef);
         CHECK_EQUAL(CELIX_SUCCESS, rc);
         CHECK(calcRef != NULL);
 
@@ -154,6 +154,20 @@ extern "C" {
         CHECK_EQUAL(0, rc);
         CHECK_EQUAL(3, arrayList_size(bundles)); //framework, rsa_dfi & calc
 
+        /*
+        int size = arrayList_size(bundles);
+        int i;
+        for (i = 0; i < size; i += 1) {
+            bundle_pt bundle = NULL;
+            module_pt module = NULL;
+            char *name = NULL;
+
+            bundle = (bundle_pt) arrayList_get(bundles, i);
+            bundle_getCurrentModule(bundle, &module);
+            module_getSymbolicName(module, &name);
+            printf("got bundle with symbolic name '%s'", name);
+        }*/
+
         arrayList_destroy(bundles);
     }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/30f7e841/remote_services/remote_service_admin_dfi/tst/server.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/server.properties.in b/remote_services/remote_service_admin_dfi/tst/server.properties.in
new file mode 100644
index 0000000..f75bf24
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/tst/server.properties.in
@@ -0,0 +1,7 @@
+cosgi.auto.start.1=@rsa_bundle_file@ @calc_bundle_file@ @discovery_configured_bundle_file@ @topology_manager_bundle_file@
+LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+RSA_PORT=50882
+DISCOVERY_CFG_SERVER_PORT=50992
+DISCOVERY_CFG_POLL_ENDPOINTS=http://127.0.0.1:50991/org.apache.celix.discovery.configured
+org.osgi.framework.storage.clean=onFirstInit
+DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file


[19/50] [abbrv] celix git commit: CELIX-237: Refactoring of rsa_dfi layout (lib, lib-tst, rsa bundle, rsa tst)

Posted by pn...@apache.org.
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, &reg->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, &reg->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;
-}
-
-


[45/50] [abbrv] celix git commit: CELIX-237: Merge branch 'feature/CELIX-237_rsa-ffi' of https://git-wip-us.apache.org/repos/asf/celix into ffi

Posted by pn...@apache.org.
CELIX-237: Merge branch 'feature/CELIX-237_rsa-ffi' of https://git-wip-us.apache.org/repos/asf/celix into ffi


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

Branch: refs/heads/develop
Commit: a13465a78baf995909398cc03c5cd4cd3dfea342
Parents: f3ae660 f04a213
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Oct 7 14:34:03 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Oct 7 14:34:03 2015 +0200

----------------------------------------------------------------------
 .../rsa/private/src/import_registration_dfi.c                    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/a13465a7/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
----------------------------------------------------------------------


[16/50] [abbrv] celix git commit: CELIX-237: Moved some json / argument handling from export/import_registration to json_serializer. Still need to add some tests

Posted by pn...@apache.org.
CELIX-237: Moved some json / argument handling from export/import_registration to json_serializer. Still need to add some tests


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

Branch: refs/heads/develop
Commit: 25223306e59d4fd084e94f700c419456bbf7dcda
Parents: 62ede18
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Aug 12 21:45:27 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Aug 12 21:45:27 2015 +0200

----------------------------------------------------------------------
 .../dynamic_function_interface/dyn_function.c   |   8 +-
 .../dynamic_function_interface/dyn_function.h   |   5 +-
 .../json_serializer.c                           | 120 +++++++++++++++++++
 .../json_serializer.h                           |   7 ++
 .../tst/dyn_function_tests.cpp                  |   4 +-
 .../private/src/export_registration_dfi.c       |  93 ++------------
 .../private/src/import_registration_dfi.c       |  52 +++-----
 7 files changed, 162 insertions(+), 127 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/25223306/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
index 8880bc7..06f6aaa 100644
--- 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
@@ -116,7 +116,7 @@ static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descrip
     int nextChar = fgetc(descriptor);
     int index = 0;
     dyn_type *type = NULL;
-    int argMetaInfo = DYN_FUNCTION_ARG_META_STD_TYPE;
+    int argMetaInfo = DYN_FUNCTION_ARG_META_INPUT_TYPE;
     char argName[32];
     while (nextChar != ')' && status == 0)  {
         ungetc(nextChar, descriptor);
@@ -175,7 +175,7 @@ static void dynFunction_parseArgMeta(FILE *descriptor, int *meta) {
 
     switch (c) {
         case '~' :
-            *meta = DYN_FUNCTION_ARG_META_OUPUT_TYPE;
+            *meta = DYN_FUNCTION_ARG_META_OUTPUT_TYPE;
             break;
         case '^' :
             *meta = DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE;
@@ -184,7 +184,7 @@ static void dynFunction_parseArgMeta(FILE *descriptor, int *meta) {
             *meta = DYN_FUNCTION_ARG_META_HANDLE_TYPE;
             break;
         default :
-            *meta = DYN_FUNCTION_ARG_META_STD_TYPE;
+            *meta = DYN_FUNCTION_ARG_META_INPUT_TYPE;
             ungetc(c, descriptor);
             break;
     }
@@ -197,7 +197,7 @@ static int dynFunction_checkArgument(dyn_function_argument_type *argument) {
         if (dynType_type(argument->type) != DYN_TYPE_TYPED_POINTER) {
             status = ERROR;
         }
-    } else if (argument->argumentType == DYN_FUNCTION_ARG_META_OUPUT_TYPE) {
+    } else if (argument->argumentType == DYN_FUNCTION_ARG_META_OUTPUT_TYPE) {
         //expect atleast two **
         if (dynType_type(argument->type) == DYN_TYPE_TYPED_POINTER) {
             dyn_type *subType = NULL;

http://git-wip-us.apache.org/repos/asf/celix/blob/25223306/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
index 733c092..5cbf686 100644
--- 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
@@ -21,10 +21,11 @@
 //TODO maybe refactor to meta info flags (e.g context/handler, output, etc with a start/stop -> M(MetaType);
 
 #define DYN_FUNCTION_ARG_META_UNKNOWN_TYPE 0
-#define DYN_FUNCTION_ARG_META_STD_TYPE 1
+#define DYN_FUNCTION_ARG_META_INPUT_TYPE 1
 #define DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE 2
-#define DYN_FUNCTION_ARG_META_OUPUT_TYPE 3
+#define DYN_FUNCTION_ARG_META_OUTPUT_TYPE 3
 #define DYN_FUNCTION_ARG_META_HANDLE_TYPE 4
+//TODO input/output types?
 
 typedef struct _dyn_function_type dyn_function_type;
 

http://git-wip-us.apache.org/repos/asf/celix/blob/25223306/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
index cf9a0ee..a2cc34e 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
@@ -414,4 +414,124 @@ static int jsonSerializer_writeComplex(dyn_type *type, void *input, json_t **out
     }
 
     return status;
+}
+
+int jsonSerializer_call(dyn_function_type *func, void *handle, void (*fp)(void), json_t *arguments, json_t **out) {
+    int status = OK;
+
+    int nrOfArgs = dynFunction_nrOfArguments(func);
+    void *args[nrOfArgs];
+
+
+
+    json_t *value = NULL;
+
+    int i;
+    int index = 0;
+    for (i = 0; i < nrOfArgs; i += 1) {
+        int metaInfo = dynFunction_argumentMetaInfoForIndex(func, i);
+        dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
+        if (metaInfo == DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE) {
+            printf("setting pre alloc output for %i\n", i);
+            dynType_alloc(argType, &args[i]);
+
+        } else if ( metaInfo == DYN_FUNCTION_ARG_META_OUTPUT_TYPE) {
+            printf("setting output for %i\n", i);
+            args[i] = NULL;
+        } else if (metaInfo == DYN_FUNCTION_ARG_META_HANDLE_TYPE) {
+            printf("setting handle for %i\n", i);
+            args[i] = &handle;
+        } else {
+            printf("setting std for %i\n", i);
+            value = json_array_get(arguments, index++);
+            status = jsonSerializer_deserializeJson(argType, value, &(args[i]));
+        }
+
+        if (status != OK) {
+            break;
+        }
+    }
+
+
+    //TODO assert return type is native int
+    int returnVal = 0;
+    dynFunction_call(func, fp, (void *)&returnVal, args);
+    printf("done calling\n");
+    double **r = args[2];
+    printf("result ptrptr is %p, result ptr %p, result is %f\n", r, *r, **r);
+
+    for (i = 0; i < nrOfArgs; i += 1) {
+        int metaInfo = dynFunction_argumentMetaInfoForIndex(func, i);
+        dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
+        if (metaInfo == DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE) {
+            if (status == OK) {
+                status = jsonSerializer_serializeJson(argType, args[i], out);
+            }
+        } else if (metaInfo == DYN_FUNCTION_ARG_META_OUTPUT_TYPE) {
+            printf("TODO\n");
+            assert(false);
+        }
+
+        if (status != OK) {
+            break;
+        }
+    }
+
+    //TODO free args (created by jsonSerializer and dynType_alloc) (dynType_free)
+    return status;
+}
+
+int jsonSerializer_prepareArguments(dyn_function_type *func, void *args[], json_t **out) {
+    int status = OK;
+    json_t *arguments = json_array();
+
+    int i;
+    int nrOfArgs = dynFunction_nrOfArguments(func);
+
+    for (i = 0; i < nrOfArgs; i +=1) {
+        if (dynFunction_argumentMetaInfoForIndex(func, i) == DYN_FUNCTION_ARG_META_INPUT_TYPE) {
+            json_t *val = NULL;
+            dyn_type *type = dynFunction_argumentTypeForIndex(func, i);
+            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
+        }
+    }
+
+    if (status == OK) {
+        *out = arguments;
+    }
+
+    return status;
+}
+
+int jsonSerializer_handleReply(dyn_function_type *func, void *handle, json_t *reply, void *args[]) {
+    int status = 0;
+
+    int nrOfArgs = dynFunction_nrOfArguments(func);
+    int i;
+    for (i = 0; i < nrOfArgs; i += 1) {
+        dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
+        int metaInf = dynFunction_argumentMetaInfoForIndex(func, i);
+        if (metaInf == DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE) {
+            void **tmp = NULL;
+            void **out = (void **)args[i];
+            size_t size = dynType_size(argType);
+            status = jsonSerializer_deserializeJson(argType, reply, (void **)&tmp);
+            memcpy(*out, *tmp, size);
+            dynType_free(argType, tmp);
+        } else if (metaInf == DYN_FUNCTION_ARG_META_OUTPUT_TYPE) {
+            assert(false); //TODO
+        } else {
+            //skipt handle and input types
+        }
+    }
+
+    return status;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/25223306/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
index 9999aea..0853114 100644
--- 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
@@ -7,6 +7,7 @@
 #include <jansson.h>
 #include "dfi_log_util.h"
 #include "dyn_type.h"
+#include "dyn_function.h"
 
 //logging
 DFI_SETUP_LOG_HEADER(jsonSerializer);
@@ -17,4 +18,10 @@ 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);
 
+//input should be a json array with with the std args
+int jsonSerializer_call(dyn_function_type *func, void *handle, void (*fp)(void), json_t *arguments, json_t **result);
+
+int jsonSerializer_prepareArguments(dyn_function_type *func, void *args[], json_t **arguments);
+int jsonSerializer_handleReply(dyn_function_type *func, void *handle, json_t *reply, void *args[]);
+
 #endif

http://git-wip-us.apache.org/repos/asf/celix/blob/25223306/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
index ab5f33e..cb4e13b 100644
--- 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
@@ -174,9 +174,9 @@ extern "C" {
         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_STD_TYPE, dynFunction_argumentMetaInfoForIndex(func, 0));
+        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_OUPUT_TYPE, dynFunction_argumentMetaInfoForIndex(func, 2));
+        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);

http://git-wip-us.apache.org/repos/asf/celix/blob/25223306/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
index c763222..cc181b3 100644
--- 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
@@ -99,10 +99,13 @@ celix_status_t exportRegistration_call(export_registration_pt export, char *data
     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);
@@ -110,7 +113,6 @@ celix_status_t exportRegistration_call(export_registration_pt export, char *data
     }
 
     printf("RSA: Looking for method %s\n", sig);
-
     struct methods_head *methods = NULL;
     dynInterface_methods(export->intf, &methods);
     struct method_entry *entry = NULL;
@@ -131,100 +133,27 @@ celix_status_t exportRegistration_call(export_registration_pt export, char *data
     if (method != NULL) {
 
         struct generic_service_layout *serv = export->service;
+        void *handle = serv->handle;
+        void (*fp)(void) = serv->methods[method->index];
 
-        int nrOfArgs = dynFunction_nrOfArguments(method->dynFunc);
-        void *args[nrOfArgs];
-
-        json_t *arguments = json_object_get(js_request, "a");
-        json_t *value = NULL;
-
-        int i;
-        int index = 0;
-        for (i = 0; i < nrOfArgs; i += 1) {
-            int metaInfo = dynFunction_argumentMetaInfoForIndex(method->dynFunc, i);
-            dyn_type *argType = dynFunction_argumentTypeForIndex(method->dynFunc, i);
-            if (metaInfo == DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE) {
-                printf("setting pre alloc output for %i\n", i);
-                dynType_alloc(argType, &args[i]);
-
-            } else if ( metaInfo == DYN_FUNCTION_ARG_META_OUPUT_TYPE) {
-                printf("setting output for %i\n", i);
-                args[i] = NULL;
-            } else if (metaInfo == DYN_FUNCTION_ARG_META_HANDLE_TYPE) {
-                printf("setting handle for %i\n", i);
-                args[i] = &serv->handle;
-            } else {
-                printf("setting std for %i\n", i);
-                value = json_array_get(arguments, index++);
-                status = jsonSerializer_deserializeJson(argType, value, &(args[i]));
-            }
-
-            if (status != CELIX_SUCCESS) {
-                break;
-            }
-        }
+        json_t *result = NULL;
+        status = jsonSerializer_call(method->dynFunc, handle, fp, arguments, &result);
 
         json_decref(js_request);
 
-        /*
-        //TODO assert last is output pointer (e.g. double pointer)
-        dyn_type *lastTypePtr = dynFunction_argumentTypeForIndex(method->dynFunc, nrOfArgs-1);
-        dyn_type *lastType = NULL;
-        dynType_typedPointer_getTypedType(lastTypePtr, &lastType);
-
-
-        void *out = NULL;
-        dynType_alloc(lastType, &out); //TODO, NOTE only for simple types or single pointer types.. TODO check
-
-        //NOTE !! Need to access out, else it is a dummy pointer which will result in errors.
-        char b;
-        memcpy(&b, out, 1);
-
-        dynType_alloc(lastType, &out); //TODO, NOTE only for simple types or single pointer types.. TODO check
-        printf("out ptr is %p value is %f\n", out, *(double *)out);
-        args[nrOfArgs-1] = &out; //NOTE for simple type no double
-         */
-
-        printf("args is %p %p %p\n", args[0] , args[1], args[2]);
-        printf("args derefs is %p %p %p\n", *(void **)args[0], *(void **)args[1], *(void **)args[2]);
-
-        //TODO assert return type is native int
-        int returnVal = 0;
-        dynFunction_call(method->dynFunc, serv->methods[method->index], (void *)&returnVal, args);
-        printf("done calling\n");
-        double **r = args[2];
-        printf("result ptrptr is %p, result ptr %p, result is %f\n", r, *r, **r);
-
-        json_t *responseJson = NULL;
-
-        for (i = 0; i < nrOfArgs; i += 1) {
-            int metaInfo = dynFunction_argumentMetaInfoForIndex(method->dynFunc, i);
-            dyn_type *argType = dynFunction_argumentTypeForIndex(method->dynFunc, i);
-            if (metaInfo == DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE) {
-                if (status == CELIX_SUCCESS) {
-                    status = jsonSerializer_serializeJson(argType, args[i], &responseJson);
-                }
-                break;
-            } else if (metaInfo == DYN_FUNCTION_ARG_META_OUPUT_TYPE) {
-                printf("TODO\n");
-                assert(false);
-            }
-        }
-
         if (status == CELIX_SUCCESS) {
             printf("creating payload\n");
             json_t *payload = json_object();
-            json_object_set_new(payload, "r", responseJson);
+            json_object_set_new(payload, "r", result);
 
             char *response = json_dumps(payload, JSON_DECODE_ANY);
-            json_decref(payload);
+            printf("status ptr is %p. response if '%s'\n", status, response);
 
             *responseOut = response;
             *responseLength = -1;
-        }
 
-
-        //TODO free args (created by jsonSerializer and dynType_alloc) (dynType_free)
+            json_decref(payload);
+        }
 
         ///TODO add more status checks
     }

http://git-wip-us.apache.org/repos/asf/celix/blob/25223306/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
index 985d94d..20ff61d 100644
--- 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
@@ -214,36 +214,24 @@ static celix_status_t importRegistration_createProxy(import_registration_pt impo
 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 function '%s'\n", entry->id);
+    printf("Calling remote function '%s'\n", entry->id);
     json_t *invoke = json_object();
     json_object_set(invoke, "m", json_string(entry->id));
 
-    json_t *jsonArgs = json_array();
-    json_object_set(invoke, "a", jsonArgs);
-    json_decref(jsonArgs);
-
-    int i;
-    int nrOfArgs = dynFunction_nrOfArguments(entry->dynFunc);
-    import_registration_pt import = *((void **)args[0]);
+    json_t *arguments = NULL;
 
-    for (i = 1; i < nrOfArgs -1; i +=1) { //note 0 = handle, last = output
-        json_t *val = NULL;
-        dyn_type *type = dynFunction_argumentTypeForIndex(entry->dynFunc, i);
-        int rc = jsonSerializer_serializeJson(type, args[i], &val);
-        if (rc == 0) {
-            json_array_append_new(jsonArgs, val);
-        } else {
-            status = CELIX_ILLEGAL_ARGUMENT;
-            break;
-        }
+    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);
 
-    printf("import is %p\n", import);
     if (import != NULL && import->send != NULL) {
         char *reply = NULL;
         int rc = 0;
@@ -253,32 +241,22 @@ static void importRegistration_proxyFunc(void *userData, void *args[], void *ret
 
         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);
+
 
-        printf("replyJson p is %p and result is %p\n", replyJson, result);
-
-        if (rc == 0) {
-            dyn_type *lastPtr = dynFunction_argumentTypeForIndex(entry->dynFunc, nrOfArgs - 1);
-            dyn_type *lastType = NULL;
-            dynType_typedPointer_getTypedType(lastPtr, &lastType);
-            if (rc == CELIX_SUCCESS) {
-                void *tmp = NULL;
-                rc = jsonSerializer_deserializeJson(lastType, result, &tmp);
-                void **out = (void **)args[nrOfArgs-1];
-                memcpy(*out, tmp, dynType_size(lastType));
-                dynType_free(lastType, tmp); //TODO only for simple types -> eg complex type will be alloc by callee
-            }
-            json_decref(replyJson);
 
-            int *returnInt = returnVal;
-            *returnInt = status;
 
+        if (status == 0) {
             printf("done with proxy func\n");
         }
     } else {
         printf("Error import of import->send is NULL\n");
     }
 
-    json_decref(invoke);
+    //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) {


[09/50] [abbrv] celix git commit: CELIX-237: A lot of work on the rsa dfi bundle and some needed refactoring for the remote_service_admin setup to support an non proxy approach.

Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
new file mode 100644
index 0000000..eae2816
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
@@ -0,0 +1,783 @@
+/**
+ *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_impl.c
+ *
+ *  \date       May 21, 2015
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <ifaddrs.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <uuid/uuid.h>
+#include <curl/curl.h>
+#include <sys/queue.h>
+
+#include <jansson.h>
+
+#include "import_registration_dfi.h"
+#include "export_registration_dfi.h"
+#include "dyn_interface.h"
+
+#include "remote_service_admin.h"
+#include "remote_constants.h"
+#include "constants.h"
+#include "utils.h"
+#include "bundle_context.h"
+#include "bundle.h"
+#include "service_reference.h"
+#include "service_registration.h"
+#include "log_helper.h"
+#include "log_service.h"
+#include "celix_threads.h"
+#include "civetweb.h"
+#include "log_helper.h"
+#include "endpoint_description.h"
+#include "dyn_interface.h"
+#include "json_serializer.h"
+
+// defines how often the webserver is restarted (with an increased port number)
+#define MAX_NUMBER_OF_RESTARTS 	5
+
+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;
+};
+
+struct post {
+    const char *readptr;
+    int size;
+};
+
+struct get {
+    char *writeptr;
+    int size;
+};
+
+#define OSGI_RSA_REMOTE_PROXY_FACTORY 	"remote_proxy_factory"
+#define OSGI_RSA_REMOTE_PROXY_TIMEOUT   "remote_proxy_timeout"
+
+static const char *data_response_headers =
+        "HTTP/1.1 200 OK\r\n"
+                "Cache: no-cache\r\n"
+                "Content-Type: application/json\r\n"
+                "\r\n";
+
+static const char *no_content_response_headers =
+        "HTTP/1.1 204 OK\r\n";
+
+// TODO do we need to specify a non-Amdatu specific configuration type?!
+static const char * const CONFIGURATION_TYPE = "org.amdatu.remote.admin.http";
+static const char * const ENDPOINT_URL = "org.amdatu.remote.admin.http.url";
+
+static const char *DEFAULT_PORT = "8888";
+static const char *DEFAULT_IP = "127.0.0.1";
+
+static const unsigned int DEFAULT_TIMEOUT = 0;
+
+static int remoteServiceAdmin_callback(struct mg_connection *conn);
+
+static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, char *interface, endpoint_description_pt *description);
+
+static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip);
+
+static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp);
+static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp);
+static void remoteServiceAdmin_log(remote_service_admin_pt admin, int level, const char *file, int line, const char *msg, ...);
+
+celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    *admin = calloc(1, sizeof(**admin));
+
+    if (!*admin) {
+        status = CELIX_ENOMEM;
+    } else {
+        unsigned int port_counter = 0;
+        char *port = NULL;
+        char *ip = NULL;
+        char *detectedIp = NULL;
+        (*admin)->context = context;
+        (*admin)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL);
+        (*admin)->importedServices = hashMap_create(NULL, NULL, NULL, NULL);
+
+        celixThreadMutex_create(&(*admin)->exportedServicesLock, NULL);
+        celixThreadMutex_create(&(*admin)->importedServicesLock, NULL);
+
+        if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
+            logHelper_start((*admin)->loghelper);
+            dynCommon_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
+            dynType_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
+            dynFunction_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
+            dynInterface_logSetup((void *)remoteServiceAdmin_log, *admin, 4);
+        }
+
+        bundleContext_getProperty(context, "RSA_PORT", &port);
+        if (port == NULL) {
+            port = (char *)DEFAULT_PORT;
+        }
+
+        bundleContext_getProperty(context, "RSA_IP", &ip);
+        if (ip == NULL) {
+            char *interface = NULL;
+
+            bundleContext_getProperty(context, "RSA_INTERFACE", &interface);
+            if ((interface != NULL) && (remoteServiceAdmin_getIpAdress(interface, &detectedIp) != CELIX_SUCCESS)) {
+                logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: Could not retrieve IP adress for interface %s", interface);
+            }
+
+            if (ip == NULL) {
+                remoteServiceAdmin_getIpAdress(NULL, &detectedIp);
+            }
+
+            ip = detectedIp;
+        }
+
+        if (ip != NULL) {
+            logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Using %s for service annunciation", ip);
+            (*admin)->ip = strdup(ip);
+        }
+        else {
+            logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No IP address for service annunciation set. Using %s", DEFAULT_IP);
+            (*admin)->ip = (char*) DEFAULT_IP;
+        }
+
+        if (detectedIp != NULL) {
+            free(detectedIp);
+        }
+
+        // Prepare callbacks structure. We have only one callback, the rest are NULL.
+        struct mg_callbacks callbacks;
+        memset(&callbacks, 0, sizeof(callbacks));
+        callbacks.begin_request = remoteServiceAdmin_callback;
+
+        do {
+            char newPort[10];
+            const char *options[] = { "listening_ports", port, NULL};
+
+            (*admin)->ctx = mg_start(&callbacks, (*admin), options);
+
+            if ((*admin)->ctx != NULL) {
+                logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Start webserver: %s", port);
+                (*admin)->port = strdup(port);
+
+            }
+            else {
+                char* endptr = port;
+                int currentPort = strtol(port, &endptr, 10);
+
+                errno = 0;
+
+                if (*endptr || errno != 0) {
+                    currentPort = strtol(DEFAULT_PORT, NULL, 10);
+                }
+
+                port_counter++;
+                snprintf(&newPort[0], 6,  "%d", (currentPort+1));
+
+                logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_ERROR, "Error while starting rsa server on port %s - retrying on port %s...", port, newPort);
+                port = newPort;
+            }
+        } while(((*admin)->ctx == NULL) && (port_counter < MAX_NUMBER_OF_RESTARTS));
+
+    }
+    return status;
+}
+
+
+celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin)
+{
+    celix_status_t status = CELIX_SUCCESS;
+
+    free((*admin)->ip);
+    free((*admin)->port);
+    free(*admin);
+
+    //TODO destroy exports/imports
+
+    *admin = NULL;
+
+    return status;
+}
+
+
+celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    celixThreadMutex_lock(&admin->exportedServicesLock);
+
+    hash_map_iterator_pt iter = hashMapIterator_create(admin->exportedServices);
+    while (hashMapIterator_hasNext(iter)) {
+        array_list_pt exports = hashMapIterator_nextValue(iter);
+        int i;
+        for (i = 0; i < arrayList_size(exports); i++) {
+            export_registration_pt export = arrayList_get(exports, i);
+            if (export != NULL) {
+                exportRegistration_stop(export);
+            }
+        }
+    }
+    hashMapIterator_destroy(iter);
+    celixThreadMutex_unlock(&admin->exportedServicesLock);
+
+    celixThreadMutex_lock(&admin->importedServicesLock);
+
+    iter = hashMapIterator_create(admin->importedServices);
+    while (hashMapIterator_hasNext(iter))
+    {
+
+        hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+        import_registration_pt import = hashMapEntry_getValue(entry);
+
+        if (import != NULL) {
+            importRegistration_stop(import);
+        }
+    }
+
+    hashMapIterator_destroy(iter);
+    celixThreadMutex_unlock(&admin->importedServicesLock);
+
+    if (admin->ctx != NULL) {
+        logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Stopping webserver...");
+        mg_stop(admin->ctx);
+        admin->ctx = NULL;
+    }
+
+    hashMap_destroy(admin->exportedServices, false, false);
+    hashMap_destroy(admin->importedServices, false, false);
+
+    logHelper_stop(admin->loghelper);
+    logHelper_destroy(&admin->loghelper);
+
+    return status;
+}
+
+/**
+ * Request: http://host:port/services/{service}/{request}
+ */
+//void *remoteServiceAdmin_callback(enum mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info) {
+
+celix_status_t importRegistration_getFactory(import_registration_pt import, service_factory_pt *factory);
+
+static int remoteServiceAdmin_callback(struct mg_connection *conn) {
+    int result = 0; // zero means: let civetweb handle it further, any non-zero value means it is handled by us...
+
+    const struct mg_request_info *request_info = mg_get_request_info(conn);
+    if (request_info->uri != NULL) {
+        remote_service_admin_pt rsa = request_info->user_data;
+
+
+        if (strncmp(request_info->uri, "/service/", 9) == 0 && strcmp("POST", request_info->request_method) == 0) {
+
+            // uri = /services/myservice/call
+            const char *uri = request_info->uri;
+            // rest = myservice/call
+
+            const char *rest = uri+9;
+            char *interfaceStart = strchr(rest, '/');
+            int pos = interfaceStart - rest;
+            char service[pos+1];
+            strncpy(service, rest, pos);
+            service[pos] = '\0';
+            long serviceId = atol(service);
+
+            celixThreadMutex_lock(&rsa->exportedServicesLock);
+
+            //find endpoint
+            export_registration_pt export = NULL;
+            hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
+            while (hashMapIterator_hasNext(iter)) {
+                hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+                array_list_pt exports = hashMapEntry_getValue(entry);
+                int expIt = 0;
+                for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
+                    export_registration_pt check = arrayList_get(exports, expIt);
+                    export_reference_pt  ref = NULL;
+                    exportRegistration_getExportReference(check, &ref);
+                    endpoint_description_pt  checkEndpoint = NULL;
+                    exportReference_getExportedEndpoint(ref, &checkEndpoint);
+                    if (serviceId == checkEndpoint->serviceId) {
+                        export = check;
+                        break;
+                    }
+                }
+            }
+            hashMapIterator_destroy(iter);
+
+            if (export != NULL) {
+
+                uint64_t datalength = request_info->content_length;
+                char* data = malloc(datalength + 1);
+                mg_read(conn, data, datalength);
+                data[datalength] = '\0';
+
+                char *response = NULL;
+                int responceLength = 0;
+                int rc = exportRegistration_call(export, data, -1, &response, &responceLength);
+                //TODO check rc
+
+                if (response != NULL) {
+                    mg_write(conn, data_response_headers, strlen(data_response_headers));
+//              mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
+                    mg_write(conn, response, strlen(response));
+//              mg_send_data(conn, response, strlen(response));
+//              mg_write_data(conn, response, strlen(response));
+
+                    free(response);
+                } else {
+                    mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
+                }
+                result = 0;
+
+                free(data);
+            } else {
+                //TODO log warning
+            }
+
+            celixThreadMutex_unlock(&rsa->exportedServicesLock);
+
+        }
+    }
+
+    return result;
+}
+
+celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    arrayList_create(registrations);
+    array_list_pt references = NULL;
+    service_reference_pt reference = NULL;
+    char filter [256];
+
+    snprintf(filter, 256, "(%s=%s)", (char *)OSGI_FRAMEWORK_SERVICE_ID, serviceId);
+
+    status = bundleContext_getServiceReferences(admin->context, NULL, filter, &references);
+
+    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: exportService called for serviceId %s", serviceId);
+
+    if (status == CELIX_SUCCESS && arrayList_size(references) >= 1) {
+        reference = arrayList_get(references, 0);
+    }
+
+    if(references != NULL){
+        arrayList_destroy(references);
+    }
+
+    if (reference == NULL) {
+        logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "ERROR: expected a reference for service id %s.", serviceId);
+        status = CELIX_ILLEGAL_STATE;
+    }
+
+    char *exports = NULL;
+    char *provided = NULL;
+    if (status == CELIX_SUCCESS) {
+        serviceReference_getProperty(reference, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exports);
+        serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_OBJECTCLASS, &provided);
+
+        if (exports == NULL || provided == NULL || strcmp(exports, provided) != 0) {
+            logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No Services to export.");
+            status = CELIX_ILLEGAL_STATE;
+        }
+    }
+
+    bundle_pt bundle = NULL;
+    if (status == CELIX_SUCCESS) {
+        logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Export service (%s)", provided);
+        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);
+    }
+
+    if (status == CELIX_SUCCESS) {
+        dyn_interface_type *intf = NULL;
+        if (descriptorFile != NULL) {
+            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(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: Error parsing service descriptor.");
+                }
+            }
+        }
+    }
+
+    if (status == CELIX_SUCCESS) {
+        char *interface = provided;
+        endpoint_description_pt endpoint = NULL;
+        export_registration_pt registration = NULL;
+
+        remoteServiceAdmin_createEndpointDescription(admin, reference, interface, &endpoint);
+        printf("RSA: Creating export registration with endpoint pointer %p\n", endpoint);
+        status = exportRegistration_create(admin->loghelper, reference, endpoint, admin->context, &registration);
+        if (status == CELIX_SUCCESS) {
+            status = exportRegistration_start(registration);
+            if (status == CELIX_SUCCESS) {
+                arrayList_add(*registrations, registration);
+            }
+        }
+    }
+
+    if (status == CELIX_SUCCESS) {
+        celixThreadMutex_lock(&admin->exportedServicesLock);
+        hashMap_put(admin->exportedServices, reference, *registrations);
+        celixThreadMutex_unlock(&admin->exportedServicesLock);
+    }
+
+    return status;
+}
+
+celix_status_t remoteServiceAdmin_removeExportedService(export_registration_pt registration) {
+    celix_status_t status = CELIX_SUCCESS;
+    //TODO
+    /*
+    remote_service_admin_pt admin = registration->rsa;
+
+    celixThreadMutex_lock(&admin->exportedServicesLock);
+
+    hashMap_remove(admin->exportedServices, registration->reference);
+    //TODO stop ?
+
+    celixThreadMutex_unlock(&admin->exportedServicesLock);
+    */
+    return status;
+}
+
+static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, char *interface, endpoint_description_pt *endpoint) {
+    celix_status_t status = CELIX_SUCCESS;
+    properties_pt endpointProperties = properties_create();
+
+
+    unsigned int size = 0;
+    char **keys;
+
+    serviceReference_getPropertyKeys(reference, &keys, &size);
+    for (int i = 0; i < size; i++) {
+        char *key = keys[i];
+        char *value = NULL;
+
+        if (serviceReference_getProperty(reference, key, &value) == CELIX_SUCCESS
+            && strcmp(key, (char*) OSGI_RSA_SERVICE_EXPORTED_INTERFACES) != 0
+            && strcmp(key, (char*) OSGI_FRAMEWORK_OBJECTCLASS) != 0) {
+            properties_set(endpointProperties, key, value);
+            printf("Added property '%s' with value '%s'\n", key, value);
+        }
+    }
+
+    hash_map_entry_pt entry = hashMap_getEntry(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
+
+    char* key = hashMapEntry_getKey(entry);
+    char *serviceId = (char *) hashMap_remove(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
+    char *uuid = NULL;
+
+    char buf[512];
+    snprintf(buf, 512,  "/service/%s/%s", serviceId, interface);
+
+    char url[1024];
+    snprintf(url, 1024, "http://%s:%s%s", admin->ip, admin->port, buf);
+
+    uuid_t endpoint_uid;
+    uuid_generate(endpoint_uid);
+    char endpoint_uuid[37];
+    uuid_unparse_lower(endpoint_uid, endpoint_uuid);
+
+    bundleContext_getProperty(admin->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
+    properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
+    properties_set(endpointProperties, (char*) OSGI_FRAMEWORK_OBJECTCLASS, interface);
+    properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_SERVICE_ID, serviceId);
+    properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID, endpoint_uuid);
+    properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED, "true");
+    properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED_CONFIGS, (char*) CONFIGURATION_TYPE);
+    properties_set(endpointProperties, (char*) ENDPOINT_URL, url);
+
+
+
+    *endpoint = calloc(1, sizeof(**endpoint));
+    if (!*endpoint) {
+        status = CELIX_ENOMEM;
+    } else {
+        (*endpoint)->id = properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID);
+        char *serviceId = NULL;
+        serviceReference_getProperty(reference, (char*) OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
+        (*endpoint)->serviceId = strtoull(serviceId, NULL, 0);
+        (*endpoint)->frameworkUUID = properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
+        (*endpoint)->service = interface;
+        (*endpoint)->properties = endpointProperties;
+    }
+
+    free(key);
+    free(serviceId);
+    free(keys);
+
+    return status;
+}
+
+static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip) {
+    celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+
+    struct ifaddrs *ifaddr, *ifa;
+    char host[NI_MAXHOST];
+
+    if (getifaddrs(&ifaddr) != -1)
+    {
+        for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
+        {
+            if (ifa->ifa_addr == NULL)
+                continue;
+
+            if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
+                if (interface == NULL) {
+                    *ip = strdup(host);
+                    status = CELIX_SUCCESS;
+                }
+                else if (strcmp(ifa->ifa_name, interface) == 0) {
+                    *ip = strdup(host);
+                    status = CELIX_SUCCESS;
+                }
+            }
+        }
+
+        freeifaddrs(ifaddr);
+    }
+
+    return status;
+}
+
+
+celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description)
+{
+    celix_status_t status = CELIX_SUCCESS;
+
+    properties_destroy((*description)->properties);
+    free(*description);
+
+    return status;
+}
+
+
+celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services) {
+    celix_status_t status = CELIX_SUCCESS;
+    return status;
+}
+
+celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services) {
+    celix_status_t status = CELIX_SUCCESS;
+    return status;
+}
+
+celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpointDescription, import_registration_pt *out) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Import service %s", endpointDescription->service);
+
+    const char *objectClass = properties_get(endpointDescription->properties, "objectClass");
+    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "Registering service factory (proxy) for service '%s'\n", objectClass);
+
+
+    import_registration_pt import = NULL;
+    if (objectClass != NULL) {
+        status = importRegistration_create(admin->context, endpointDescription, objectClass, &import);
+    }
+
+    if (status == CELIX_SUCCESS) {
+        status = importRegistration_start(import);
+    }
+
+    //celixThreadMutex_lock(&admin->importedServicesLock);
+    //TODO add to list
+    //celixThreadMutex_unlock(&admin->importedServicesLock);
+
+    if (status == CELIX_SUCCESS) {
+        *out = import;
+    }
+
+    return status;
+}
+
+
+celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration) {
+    celix_status_t status = CELIX_SUCCESS;
+    return status;
+    /*
+
+      endpoint_description_pt endpointDescription = (endpoint_description_pt) registration->endpointDescription;
+      import_registration_factory_pt registration_factory = NULL;
+
+      celixThreadMutex_lock(&admin->importedServicesLock);
+
+      registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
+
+      // factory available
+      if ((registration_factory == NULL) || (registration_factory->trackedFactory == NULL))
+      {
+          logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: Error while retrieving registration factory for imported service %s", endpointDescription->service);
+      }
+      else
+      {
+          registration_factory->trackedFactory->unregisterProxyService(registration_factory->trackedFactory->factory, endpointDescription);
+          arrayList_removeElement(registration_factory->registrations, registration);
+          importRegistration_destroy(registration);
+
+          if (arrayList_isEmpty(registration_factory->registrations))
+          {
+              logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: closing proxy.");
+
+              serviceTracker_close(registration_factory->proxyFactoryTracker);
+              importRegistrationFactory_close(registration_factory);
+
+              hashMap_remove(admin->importedServices, endpointDescription->service);
+
+              importRegistrationFactory_destroy(&registration_factory);
+          }
+      }
+
+      celixThreadMutex_unlock(&admin->importedServicesLock);
+
+      return status;
+    */
+}
+
+
+celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus) {
+
+    struct post post;
+    post.readptr = request;
+    post.size = strlen(request);
+
+    struct get get;
+    get.size = 0;
+    get.writeptr = malloc(1);
+
+    char *serviceUrl = properties_get(endpointDescription->properties, (char*) ENDPOINT_URL);
+    char url[256];
+    snprintf(url, 256, "%s", serviceUrl);
+
+    // assume the default timeout
+    int timeout = DEFAULT_TIMEOUT;
+
+    char *timeoutStr = NULL;
+    // Check if the endpoint has a timeout, if so, use it.
+    timeoutStr = properties_get(endpointDescription->properties, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT);
+    if (timeoutStr == NULL) {
+        // If not, get the global variable and use that one.
+        bundleContext_getProperty(rsa->context, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT, &timeoutStr);
+    }
+
+    // Update timeout if a property is used to set it.
+    if (timeoutStr != NULL) {
+        timeout = atoi(timeoutStr);
+    }
+
+    celix_status_t status = CELIX_SUCCESS;
+    CURL *curl;
+    CURLcode res;
+
+    curl = curl_easy_init();
+    if(!curl) {
+        status = CELIX_ILLEGAL_STATE;
+    } else {
+        curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
+        curl_easy_setopt(curl, CURLOPT_URL, &url[0]);
+        curl_easy_setopt(curl, CURLOPT_POST, 1L);
+        curl_easy_setopt(curl, CURLOPT_READFUNCTION, remoteServiceAdmin_readCallback);
+        curl_easy_setopt(curl, CURLOPT_READDATA, &post);
+        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, remoteServiceAdmin_write);
+        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&get);
+        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)post.size);
+        res = curl_easy_perform(curl);
+        curl_easy_cleanup(curl);
+
+        *reply = get.writeptr;
+        *replyStatus = res;
+    }
+
+    return status;
+}
+
+static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp) {
+    struct post *post = userp;
+
+    if (post->size) {
+        *(char *) ptr = post->readptr[0];
+        post->readptr++;
+        post->size--;
+        return 1;
+    }
+
+    return 0;
+}
+
+static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp) {
+    size_t realsize = size * nmemb;
+    struct get *mem = (struct get *)userp;
+
+    mem->writeptr = realloc(mem->writeptr, mem->size + realsize + 1);
+    if (mem->writeptr == NULL) {
+        /* out of memory! */
+        printf("not enough memory (realloc returned NULL)");
+        exit(EXIT_FAILURE);
+    }
+
+    memcpy(&(mem->writeptr[mem->size]), contents, realsize);
+    mem->size += realsize;
+    mem->writeptr[mem->size] = 0;
+
+    return realsize;
+}
+
+
+static void remoteServiceAdmin_log(remote_service_admin_pt admin, int level, const char *file, int line, const char *msg, ...) {
+    va_list ap;
+    va_start(ap, msg);
+    int levels[5] = {0, OSGI_LOGSERVICE_ERROR, OSGI_LOGSERVICE_WARNING, OSGI_LOGSERVICE_INFO, OSGI_LOGSERVICE_DEBUG};
+
+    char buf1[256];
+    snprintf(buf1, 256, "FILE:%s, LINE:%i, MSG:", file, line);
+
+    char buf2[256];
+    vsnprintf(buf2, 256, msg, ap);
+    logHelper_log(admin->loghelper, levels[level], "%s%s", buf1, buf2);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_impl.c b/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_impl.c
deleted file mode 100644
index ac54e8d..0000000
--- a/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_impl.c
+++ /dev/null
@@ -1,1085 +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_impl.c
- *
- *  \date       May 21, 2015
- *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright	Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <ifaddrs.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <uuid/uuid.h>
-
-#include <curl/curl.h>
-
-#include <ffi.h>
-#include <jansson.h>
-
-#include "export_registration_impl.h"
-#include "import_registration_impl.h"
-#include "remote_service_admin_impl.h"
-#include "remote_constants.h"
-#include "constants.h"
-#include "utils.h"
-#include "bundle_context.h"
-#include "bundle.h"
-#include "service_reference.h"
-#include "service_registration.h"
-#include "log_helper.h"
-#include "log_service.h"
-#include "celix_threads.h"
-#include "civetweb.h"
-#include "log_helper.h"
-#include "endpoint_description.h"
-
-// defines how often the webserver is restarted (with an increased port number)
-#define MAX_NUMBER_OF_RESTARTS 	5
-
-typedef void (*GEN_FUNC_TYPE)(void);
-
-struct generic_service_layout {
-    void *handle;
-    GEN_FUNC_TYPE functions[];
-};
-
-struct proxy {
-  remote_service_admin_pt admin;
-  char *sig;
-  int index;
-  ffi_cif cif;
-  ffi_closure *closure;
-  endpoint_description_pt endpointDescription
-};
-
-
-    
-
-
-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;
-};
-
-struct post {
-    const char *readptr;
-    int size;
-};
-
-struct get {
-    char *writeptr;
-    int size;
-};
-
-static const char *data_response_headers =
-  "HTTP/1.1 200 OK\r\n"
-  "Cache: no-cache\r\n"
-  "Content-Type: application/json\r\n"
-  "\r\n";
-
-static const char *no_content_response_headers =
-  "HTTP/1.1 204 OK\r\n";
-
-// TODO do we need to specify a non-Amdatu specific configuration type?!
-static const char * const CONFIGURATION_TYPE = "org.amdatu.remote.admin.http";
-static const char * const ENDPOINT_URL = "org.amdatu.remote.admin.http.url";
-
-static const char *DEFAULT_PORT = "8888";
-static const char *DEFAULT_IP = "127.0.0.1";
-
-static const unsigned int DEFAULT_TIMEOUT = 0;
-
-static int remoteServiceAdmin_callback(struct mg_connection *conn);
-
-static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, char *interface, endpoint_description_pt *description);
-
-static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip);
-
-static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp);
-static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp);
-
-celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin) {
-	celix_status_t status = CELIX_SUCCESS;
-
-	*admin = calloc(1, sizeof(**admin));
-
-	if (!*admin) {
-		status = CELIX_ENOMEM;
-	} else {
-		unsigned int port_counter = 0;
-		char *port = NULL;
-		char *ip = NULL;
-		char *detectedIp = NULL;
-		(*admin)->context = context;
-		(*admin)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL);
-		(*admin)->importedServices = hashMap_create(NULL, NULL, NULL, NULL);
-
-		celixThreadMutex_create(&(*admin)->exportedServicesLock, NULL);
-		celixThreadMutex_create(&(*admin)->importedServicesLock, NULL);
-
-		if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
-			logHelper_start((*admin)->loghelper);
-		}
-
-		bundleContext_getProperty(context, "RSA_PORT", &port);
-		if (port == NULL) {
-			port = (char *)DEFAULT_PORT;
-		}
-
-		bundleContext_getProperty(context, "RSA_IP", &ip);
-		if (ip == NULL) {
-			char *interface = NULL;
-
-			bundleContext_getProperty(context, "RSA_INTERFACE", &interface);
-			if ((interface != NULL) && (remoteServiceAdmin_getIpAdress(interface, &detectedIp) != CELIX_SUCCESS)) {
-				logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: Could not retrieve IP adress for interface %s", interface);
-			}
-
-			if (ip == NULL) {
-				remoteServiceAdmin_getIpAdress(NULL, &detectedIp);
-			}
-
-			ip = detectedIp;
-		}
-
-		if (ip != NULL) {
-			logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Using %s for service annunciation", ip);
-			(*admin)->ip = strdup(ip);
-		}
-		else {
-			logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No IP address for service annunciation set. Using %s", DEFAULT_IP);
-			(*admin)->ip = (char*) DEFAULT_IP;
-		}
-
-		if (detectedIp != NULL) {
-			free(detectedIp);
-		}
-
-		// Prepare callbacks structure. We have only one callback, the rest are NULL.
-		struct mg_callbacks callbacks;
-		memset(&callbacks, 0, sizeof(callbacks));
-		callbacks.begin_request = remoteServiceAdmin_callback;
-
-		do {
-			char newPort[10];
-			const char *options[] = { "listening_ports", port, NULL};
-
-			(*admin)->ctx = mg_start(&callbacks, (*admin), options);
-
-			if ((*admin)->ctx != NULL) {
-				logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Start webserver: %s", port);
-				(*admin)->port = strdup(port);
-
-			}
-			else {
-		        char* endptr = port;
-		        int currentPort = strtol(port, &endptr, 10);
-
-				errno = 0;
-
-		        if (*endptr || errno != 0) {
-		            currentPort = strtol(DEFAULT_PORT, NULL, 10);
-		        }
-
-		        port_counter++;
-				snprintf(&newPort[0], 6,  "%d", (currentPort+1));
-
-				logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_ERROR, "Error while starting rsa server on port %s - retrying on port %s...", port, newPort);
-				port = newPort;
-			}
-		} while(((*admin)->ctx == NULL) && (port_counter < MAX_NUMBER_OF_RESTARTS));
-
-	}
-	return status;
-}
-
-
-celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin)
-{
-    celix_status_t status = CELIX_SUCCESS;
-
-    free((*admin)->ip);
-    free((*admin)->port);
-    free(*admin);
-
-    *admin = NULL;
-
-    return status;
-}
-
-celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin) {
-	celix_status_t status = CELIX_SUCCESS;
-
-    celixThreadMutex_lock(&admin->exportedServicesLock);
-
-	hash_map_iterator_pt iter = hashMapIterator_create(admin->exportedServices);
-	while (hashMapIterator_hasNext(iter)) {
-		array_list_pt exports = hashMapIterator_nextValue(iter);
-		int i;
-		for (i = 0; i < arrayList_size(exports); i++) {
-			export_registration_pt export = arrayList_get(exports, i);
-			exportRegistration_stopTracking(export);
-		}
-	}
-    hashMapIterator_destroy(iter);
-    celixThreadMutex_unlock(&admin->exportedServicesLock);
-
-    celixThreadMutex_lock(&admin->importedServicesLock);
-
-    iter = hashMapIterator_create(admin->importedServices);
-    while (hashMapIterator_hasNext(iter))
-    {
-    	hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
-
-    	import_registration_factory_pt importFactory = hashMapEntry_getValue(entry);
-
-        if (importFactory != NULL) {
-            int i;
-            for (i = 0; i < arrayList_size(importFactory->registrations); i++)
-            {
-                import_registration_pt importRegistration = arrayList_get(importFactory->registrations, i);
-
-                if (importFactory->trackedFactory != NULL)
-                {
-                    importFactory->trackedFactory->unregisterProxyService(importFactory->trackedFactory->factory, importRegistration->endpointDescription);
-                }
-            }
-
-            serviceTracker_close(importFactory->proxyFactoryTracker);
-            importRegistrationFactory_close(importFactory);
-
-            hashMapIterator_remove(iter);
-            importRegistrationFactory_destroy(&importFactory);
-            }
-    }
-    hashMapIterator_destroy(iter);
-    celixThreadMutex_unlock(&admin->importedServicesLock);
-
-	if (admin->ctx != NULL) {
-		logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Stopping webserver...");
-		mg_stop(admin->ctx);
-		admin->ctx = NULL;
-	}
-
-	hashMap_destroy(admin->exportedServices, false, false);
-	hashMap_destroy(admin->importedServices, false, false);
-
-	logHelper_stop(admin->loghelper);
-	logHelper_destroy(&admin->loghelper);
-
-	return status;
-}
-
-/**
- * Request: http://host:port/services/{service}/{request}
- */
-//void *remoteServiceAdmin_callback(enum mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info) {
-
-static int remoteServiceAdmin_callback(struct mg_connection *conn) {
-	int result = 0; // zero means: let civetweb handle it further, any non-zero value means it is handled by us...
-
-	const struct mg_request_info *request_info = mg_get_request_info(conn);
-	if (request_info->uri != NULL) {
-		remote_service_admin_pt rsa = request_info->user_data;
-
-
-		if (strncmp(request_info->uri, "/service/", 9) == 0 && strcmp("POST", request_info->request_method) == 0) {
-
-			// uri = /services/myservice/call
-			const char *uri = request_info->uri;
-			// rest = myservice/call
-
-			const char *rest = uri+9;
-			char *interfaceStart = strchr(rest, '/');
-			int pos = interfaceStart - rest;
-			char service[pos+1];
-			strncpy(service, rest, pos);
-			service[pos] = '\0';
-      long serviceId = atol(service);
-
-			celixThreadMutex_lock(&rsa->exportedServicesLock);
-
-      //find endpoint
-      export_registration_pt export = NULL;
-			hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
-			while (hashMapIterator_hasNext(iter)) {
-				hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
-				array_list_pt exports = hashMapEntry_getValue(entry);
-				int expIt = 0;
-				for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
-					export_registration_pt check = arrayList_get(exports, expIt);
-					if (serviceId == check->endpointDescription->serviceId) {
-              export = check;
-              break;
-          }
-        }
-      }
-      hashMapIterator_destroy(iter);
-
-      if (export != NULL) {
-          uint64_t datalength = request_info->content_length;
-          char* data = malloc(datalength + 1);
-          mg_read(conn, data, datalength);
-          data[datalength] = '\0';
-
-          char *response = NULL;
-
-          //FIXME assuming add signature (add(double, double) : double)
-          /*TODO
-            export->endpoint->handleRequest(export->endpoint->endpoint, data, &response);
-            */
-
-
-          //retreive schema.
-          char *schema = NULL;
-          schema = properties_get(export->endpointDescription->properties, "protocol.schema");
-          printf("RSA: got schema %s\n", schema);
-
-
-          printf("Parsing data: %s\n", data);
-          json_error_t error;
-          json_t *js_request = json_loads(data, 0, &error);
-          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 {
-              printf("RSA: got error '%s' for '%s'\n", error.text, data);
-              return 0;
-          }
-
-          printf("RSA: Looking for method %s\n", sig);
-
-          json_t *js_schema = json_loads(schema, 0, &error);
-          int methodIndex = -1;
-          if (js_schema) {
-              //TODO parse schema and create cif
-              size_t index;
-              json_t *value;
-              json_array_foreach(js_schema, index, value) {
-                  if (strcmp(sig, json_string_value(value)) == 0) {
-                      //found match
-                      methodIndex = index;
-                      break;
-                  }
-              }
-          } else {
-              printf("RSA: got error '%s' for '%s'\n", error.text, schema);
-              return 0;
-          }
-
-          if (methodIndex < 0) {
-              printf("RSA: cannot find method '%s'\n", sig);
-              return 1;
-          }
-
-          size_t sigLength = strlen(sig);
-          char provArgs[sigLength];
-          bool startFound = false;
-          int i = 0;
-          int argIndex = 0;
-          for (; i < sigLength; i += 1) {
-              if (!startFound) {
-                  if (sig[i] == '(') {
-                      startFound = true;
-                  }
-              } else {
-                  if (sig[i] != ')') {
-                      provArgs[argIndex++] = sig[i];
-                  }
-              }
-          } 
-          provArgs[argIndex] = '\0';
-          size_t provArgsLength = strlen(provArgs) -1; 
-          printf("method index is %i and args are '%s'\n", methodIndex, provArgs);
-
-
-          //FFI part
-          ffi_cif cif;
-          ffi_type *argTypes[provArgsLength + 2]; //e.g. void *handle (extra), double a, double b, double *result (extra)
-          void *valuePointers[provArgsLength + 2];
-          //note assuming doubles!!
-          double values[provArgsLength];
-          double result = 0.0;
-          double *resultPointer = &result;
-          int rvalue = 0;
-
-          argTypes[0] = &ffi_type_pointer;
-          argTypes[provArgsLength +1] = &ffi_type_pointer; //last argument is return value, handled as a pointer
-          for (i = 0; i < provArgsLength; i += 1) {
-              //FIXME for now assuming double as arguments
-              argTypes[i+1] = &ffi_type_double;
-          }
-
-          valuePointers[0] = NULL;
-          valuePointers[provArgsLength+1] = &resultPointer;
-          for (i = 0; i < provArgsLength; i += 1) {
-              values[i] = 0.0;
-              valuePointers[i+1] = &(values[i]);
-          }
-
-          json_t *arguments = json_object_get(js_request, "a");
-          json_t *value;
-          size_t index;
-          json_array_foreach(arguments, index, value) {
-              values[index] = json_real_value(value); //setting values, again assuming double
-          }
-
-          json_decref(js_schema);
-          json_decref(js_request);
-
-          if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, provArgsLength + 2,
-                      &ffi_type_sint, argTypes) == FFI_OK)
-          {
-              printf("RSA: FFI PREP OK\n");
-
-              //TRYING TO CALL Calculate service
-              void *service = NULL;
-              bundleContext_getService(rsa->context, export->reference, &service);     
-              if (service == NULL) {
-                  printf("RSA: Ouch service is NULL\n");
-                  return 0;
-              } else {
-                  printf("RSA: service ok\n");
-              }
-
-              struct generic_service_layout *serv = service;
-
-              printf("RSA:Trying to call service using ffi\n");
-              valuePointers[0] = serv->handle;
-              ffi_call(&cif, serv->functions[methodIndex], &rvalue, valuePointers);
-              printf("RSA: Done calling service through ffi, got value %f\n", result);
-
-              json_t *resultRoot;
-              resultRoot = json_pack("{s:f}", "r", result);
-              response = json_dumps(resultRoot, 0);
-              json_decref(resultRoot);  
-          }
-
-          if (response != NULL) {
-              mg_write(conn, data_response_headers, strlen(data_response_headers));
-//              mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
-              mg_write(conn, response, strlen(response));
-//              mg_send_data(conn, response, strlen(response));
-//              mg_write_data(conn, response, strlen(response));
-
-              free(response);
-          } else {
-              mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
-          }
-          result = 0;
-
-          free(data);
-      } else {
-          //TODO log warning
-      }
-
-      celixThreadMutex_unlock(&rsa->exportedServicesLock);
-
-		}
-	}
-
-	return 1;
-}
-
-celix_status_t remoteServiceAdmin_handleRequest(remote_service_admin_pt rsa, char *service, char *data, char **reply) {
-	celixThreadMutex_lock(&rsa->exportedServicesLock);
-
-	hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
-	while (hashMapIterator_hasNext(iter)) {
-		hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
-		array_list_pt exports = hashMapEntry_getValue(entry);
-		int expIt = 0;
-		for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
-			export_registration_pt export = arrayList_get(exports, expIt);
-			if (strcmp(service, export->endpointDescription->service) == 0) {
-				export->endpoint->handleRequest(export->endpoint->endpoint, data, reply);
-			}
-		}
-	}
-    hashMapIterator_destroy(iter);
-
-	celixThreadMutex_unlock(&rsa->exportedServicesLock);
-
-	return CELIX_SUCCESS;
-}
-
-celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations) {
-    celix_status_t status = CELIX_SUCCESS;
-    arrayList_create(registrations);
-    array_list_pt references = NULL;
-    service_reference_pt reference = NULL;
-    char filter [256];
-
-    snprintf(filter, 256, "(%s=%s)", (char *)OSGI_FRAMEWORK_SERVICE_ID, serviceId);
-
-    bundleContext_getServiceReferences(admin->context, NULL, filter, &references); //FIXME not safe
-
-    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: exportService called for serviceId %s", serviceId);
-
-    if (arrayList_size(references) >= 1) {
-        reference = arrayList_get(references, 0);
-    }
-
-    if(references!=NULL){
-        arrayList_destroy(references);
-    }
-
-    if (reference == NULL) {
-        logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "ERROR: expected a reference for service id %s.", serviceId);
-        return CELIX_ILLEGAL_STATE;
-    }
-
-    char *exports = NULL;
-    char *provided = NULL;
-    char *schema = NULL;
-    serviceReference_getProperty(reference, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exports);
-    serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_OBJECTCLASS, &provided);
-    serviceReference_getProperty(reference, (char *) "protocol.schema", &schema);
-
-    if (exports == NULL || provided == NULL) {
-        logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No Services to export.");
-            status = CELIX_ILLEGAL_STATE;
-    } else {
-        if (schema == NULL) {
-            logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: no protocol.schema found.");
-            status = CELIX_ILLEGAL_STATE;
-        } else {
-            logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Export service (%s)", provided);
-
-            char *interface = provided;
-            endpoint_description_pt endpoint = NULL;
-            export_registration_pt registration = NULL;
-
-            remoteServiceAdmin_createEndpointDescription(admin, reference, interface, &endpoint);
-            printf("RSA: Creating export registration with endpoint pointer %p\n", endpoint);
-            exportRegistration_create(admin->loghelper, reference, endpoint, admin, admin->context, &registration);
-            arrayList_add(*registrations, registration);
-
-            exportRegistration_open(registration);
-            exportRegistration_startTracking(registration);
-
-            celixThreadMutex_lock(&admin->exportedServicesLock);
-            hashMap_put(admin->exportedServices, reference, *registrations);
-            celixThreadMutex_unlock(&admin->exportedServicesLock);
-        }
-    }
-    return status;
-}
-
-celix_status_t remoteServiceAdmin_removeExportedService(export_registration_pt registration) {
-    celix_status_t status = CELIX_SUCCESS;
-    remote_service_admin_pt admin = registration->rsa;
-
-    celixThreadMutex_lock(&admin->exportedServicesLock);
-
-    hashMap_remove(admin->exportedServices, registration->reference);
-
-    celixThreadMutex_unlock(&admin->exportedServicesLock);
-
-    return status;
-}
-
-static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, char *interface, endpoint_description_pt *endpoint) {
-	celix_status_t status = CELIX_SUCCESS;
-	properties_pt endpointProperties = properties_create();
-
-
-	unsigned int size = 0;
-    char **keys;
-
-    serviceReference_getPropertyKeys(reference, &keys, &size);
-    for (int i = 0; i < size; i++) {
-        char *key = keys[i];
-        char *value = NULL;
-
-        if (serviceReference_getProperty(reference, key, &value) == CELIX_SUCCESS
-        		&& strcmp(key, (char*) OSGI_RSA_SERVICE_EXPORTED_INTERFACES) != 0
-        		&& strcmp(key, (char*) OSGI_FRAMEWORK_OBJECTCLASS) != 0) {
-        	properties_set(endpointProperties, key, value);
-          printf("Added property '%s' with value '%s'\n", key, value);
-        }
-	}
-
-	hash_map_entry_pt entry = hashMap_getEntry(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
-
-	char* key = hashMapEntry_getKey(entry);
-	char *serviceId = (char *) hashMap_remove(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
-	char *uuid = NULL;
-
-	char buf[512];
-	snprintf(buf, 512,  "/service/%s/%s", serviceId, interface);
-
-	char url[1024];
-	snprintf(url, 1024, "http://%s:%s%s", admin->ip, admin->port, buf);
-
-	uuid_t endpoint_uid;
-	uuid_generate(endpoint_uid);
-	char endpoint_uuid[37];
-	uuid_unparse_lower(endpoint_uid, endpoint_uuid);
-
-	bundleContext_getProperty(admin->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
-	properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
-	properties_set(endpointProperties, (char*) OSGI_FRAMEWORK_OBJECTCLASS, interface);
-	properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_SERVICE_ID, serviceId);
-	properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID, endpoint_uuid);
-	properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED, "true");
-  properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED_CONFIGS, (char*) CONFIGURATION_TYPE);
-  properties_set(endpointProperties, (char*) ENDPOINT_URL, url);
-
-
-
-  *endpoint = calloc(1, sizeof(**endpoint));
-  if (!*endpoint) {
-      status = CELIX_ENOMEM;
-  } else {
-      (*endpoint)->id = properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID);
-      char *serviceId = NULL;
-      serviceReference_getProperty(reference, (char*) OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
-      (*endpoint)->serviceId = strtoull(serviceId, NULL, 0);
-      (*endpoint)->frameworkUUID = properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
-      (*endpoint)->service = interface;
-      (*endpoint)->properties = endpointProperties;
-  }
-
-	free(key);
-	free(serviceId);
-	free(keys);
-
-	return status;
-}
-
-static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip) {
-	celix_status_t status = CELIX_BUNDLE_EXCEPTION;
-
-	struct ifaddrs *ifaddr, *ifa;
-    char host[NI_MAXHOST];
-
-    if (getifaddrs(&ifaddr) != -1)
-    {
-		for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
-		{
-			if (ifa->ifa_addr == NULL)
-				continue;
-
-			if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
-				if (interface == NULL) {
-					*ip = strdup(host);
-					status = CELIX_SUCCESS;
-				}
-				else if (strcmp(ifa->ifa_name, interface) == 0) {
-					*ip = strdup(host);
-					status = CELIX_SUCCESS;
-				}
-			}
-		}
-
-		freeifaddrs(ifaddr);
-    }
-
-    return status;
-}
-
-
-celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description)
-{
-	celix_status_t status = CELIX_SUCCESS;
-
-	properties_destroy((*description)->properties);
-	free(*description);
-
-	return status;
-}
-
-
-celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services) {
-	celix_status_t status = CELIX_SUCCESS;
-	return status;
-}
-
-celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services) {
-	celix_status_t status = CELIX_SUCCESS;
-	return status;
-}
-
-
-static int remoteServiceAdmin_remoteFunctionProxy(ffi_cif *cif, int *ret, void* args[], void *userData); //TODO MOVE
-static int remoteServiceAdmin_remoteFunctionProxy(ffi_cif *cif, int *ret, void* args[], void *userData) {
-   void **handle = args[0];
-   remote_service_admin_pt admin = (*handle);
-
-   struct proxy *proxy = userData;
-
-   printf("ffi closure got called for method sig %s with index %i\n", proxy->sig, proxy->index);
-
-   json_t *root = json_object();
-   json_t *sig = json_string(proxy->sig);
-   json_object_set(root, "m", sig);
-
-   json_t *arguments = json_array();
-   int i;
-   for (i = 1; i < proxy->cif.nargs -1; i += 1) {
-       //NOTE assuming double
-       double *dval = args[i];
-       json_t *value = json_real(*dval);
-       json_array_append(arguments, value);
-   }
-   json_object_set(root, "a", arguments);
-
-   char *data = json_dumps(root, 0);
-   char *reply = NULL;
-   int replyStatus;
-
-   remoteServiceAdmin_send(proxy->admin, proxy->endpointDescription, data, &reply, &replyStatus);
-   (*ret) = replyStatus;
-   printf("got reply from server '%s'\n", reply);
-
-   json_error_t error;
-   json_t *js_reply = json_loads(reply, JSON_DECODE_ANY, &error);
-   if (js_reply) {
-       //note assuming double
-       double **result = args[proxy->cif.nargs - 1];
-       json_unpack(js_reply, "{s:f}", "r", *result);
-       json_decref(js_reply);
-   } else {
-       printf("PROXY: got error '%s' for '%s'\n", error.text, reply);
-   }
-
-   json_decref(root);
-
-   free(data);
-   free(reply);
-
-   return 0;
-}
-
-
-celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpointDescription, import_registration_pt *registration) {
-	celix_status_t status = CELIX_SUCCESS;
-
-	logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Import service %s", endpointDescription->service);
-
-  char *schema = properties_get(endpointDescription->properties, "protocol.schema");
-  if (schema == NULL) {
-    logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: protocol schema not found for endpoint\n");
-    return CELIX_SUCCESS;
-  }
-
-  printf("protocol.schema is '%s'\n", schema);
-  json_error_t error;
-  json_t *js_schema = json_loads(schema, 0, &error);
-  if (js_schema) {
-      //TODO parse schema and create cif
-      size_t numOfMethods = json_array_size(js_schema);
-      printf("RSA: num of method for proxy is %i\n", (int) numOfMethods);
-
-      struct generic_service_layout *service = calloc(1, sizeof(*service) + (numOfMethods-1) * sizeof(GEN_FUNC_TYPE)); 
-      service->handle = admin;
-
-        //struct generic_service_layout {
-        //    void *handle;
-        //    GEN_FUNC_TYPE functions[];
-        //};
-
-      size_t index;
-      json_t *value;
-      json_array_foreach(js_schema, index, value) {
-          //create closure
-
-          char *sig = json_string_value(value);
-          size_t sigLength = strlen(sig);
-          char provArgs[sigLength];
-          bool startFound = false;
-          int i = 0;
-          int argIndex = 0;
-          for (; i < sigLength; i += 1) {
-              if (!startFound) {
-                  if (sig[i] == '(') {
-                      startFound = true;
-                  }
-              } else {
-                  if (sig[i] != ')') {
-                      provArgs[argIndex++] = sig[i];
-                  }
-              }
-          } 
-          provArgs[argIndex] = '\0';
-          printf("method index is %i and args are '%s'\n", index, provArgs);
-
-          int provArgLength = strlen(provArgs) -1;
-
-          struct proxy *proxy = malloc(sizeof(*proxy));
-          proxy->admin = admin;
-          proxy->sig = strdup(sig);
-          proxy->index = index;
-          proxy->endpointDescription = endpointDescription;
-          
-          ffi_type **args = calloc(provArgLength +2, sizeof(ffi_type)); //TODO test if this can be on the stack
-
-          void (*function)(void);
-          proxy->closure = ffi_closure_alloc(sizeof(ffi_closure), &function);
-          service->functions[index] = function;
-
-          /* Initialize the argument info vectors */
-          args[0] = &ffi_type_pointer;
-          args[provArgLength + 1] = &ffi_type_pointer;
-          for (i = 0; i < provArgLength; i += 1) {
-              args[i+1] = &ffi_type_double;
-          }
-
-          if (proxy->closure) {
-            if (ffi_prep_cif(&proxy->cif, FFI_DEFAULT_ABI, provArgLength + 2, &ffi_type_sint, args) == FFI_OK) {
-                if (ffi_prep_closure_loc(proxy->closure, &proxy->cif, remoteServiceAdmin_remoteFunctionProxy, proxy, function) == FFI_OK) {
-                    printf("RSA: created closure for method '%s'\n", sig);
-                }
-            }
-          }
-      }
-                   
-      //TODO register with imported properties 
-      char *objectClass = properties_get(endpointDescription->properties, "objectClass");
-      service_registration_pt reg = NULL;
-      bundleContext_registerService(admin->context, objectClass, service, NULL, &reg);
-      printf("registered proxy service with objectclass '%s'\n", objectClass);
-
-  } else {
-      printf("RSA: got error '%s' for '%s'\n", error.text, schema);
-      return CELIX_ILLEGAL_STATE;
-  }
-
-
-  //celixThreadMutex_lock(&admin->importedServicesLock);
-  //celixThreadMutex_unlock(&admin->importedServicesLock);
-
-
-  return status;
-  /*
-
-	celixThreadMutex_lock(&admin->importedServicesLock);
-
-   import_registration_factory_pt registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
-
-	// check whether we already have a registration_factory registered in the hashmap
-	if (registration_factory == NULL)
-	{
-		status = importRegistrationFactory_install(admin->loghelper, endpointDescription->service, admin->context, &registration_factory);
-		if (status == CELIX_SUCCESS) {
-		    hashMap_put(admin->importedServices, endpointDescription->service, registration_factory);
-		}
-	}
-
-	 // factory available
-	if (status != CELIX_SUCCESS || (registration_factory->trackedFactory == NULL))
-	{
-		logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: no proxyFactory available.");
-		if (status == CELIX_SUCCESS) {
-			status = CELIX_SERVICE_EXCEPTION;
-		}
-	}
-	else
-	{
-		// we create an importRegistration per imported service
-		importRegistration_create(endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send, admin->context, registration);
-		registration_factory->trackedFactory->registerProxyService(registration_factory->trackedFactory->factory,  endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send);
-
-		arrayList_add(registration_factory->registrations, *registration);
-	}
-
-    celixThreadMutex_unlock(&admin->importedServicesLock);
-
-
-	return status;
-  */
-}
-
-
-celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration) {
-	celix_status_t status = CELIX_SUCCESS;
-  return status;
-  /*
-
-	endpoint_description_pt endpointDescription = (endpoint_description_pt) registration->endpointDescription;
-	import_registration_factory_pt registration_factory = NULL;
-
-    celixThreadMutex_lock(&admin->importedServicesLock);
-
-    registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
-
-    // factory available
-    if ((registration_factory == NULL) || (registration_factory->trackedFactory == NULL))
-    {
-    	logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: Error while retrieving registration factory for imported service %s", endpointDescription->service);
-    }
-    else
-    {
-		registration_factory->trackedFactory->unregisterProxyService(registration_factory->trackedFactory->factory, endpointDescription);
-		arrayList_removeElement(registration_factory->registrations, registration);
-		importRegistration_destroy(registration);
-
-		if (arrayList_isEmpty(registration_factory->registrations))
-		{
-			logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: closing proxy.");
-
-			serviceTracker_close(registration_factory->proxyFactoryTracker);
-			importRegistrationFactory_close(registration_factory);
-
-			hashMap_remove(admin->importedServices, endpointDescription->service);
-
-			importRegistrationFactory_destroy(&registration_factory);
-		}
-    }
-
-    celixThreadMutex_unlock(&admin->importedServicesLock);
-
-	return status;
-  */
-}
-
-
-celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus) {
-
-    struct post post;
-    post.readptr = request;
-    post.size = strlen(request);
-
-    struct get get;
-    get.size = 0;
-    get.writeptr = malloc(1);
-
-    char *serviceUrl = properties_get(endpointDescription->properties, (char*) ENDPOINT_URL);
-    char url[256];
-    snprintf(url, 256, "%s", serviceUrl);
-
-    // assume the default timeout
-    int timeout = DEFAULT_TIMEOUT;
-
-    char *timeoutStr = NULL;
-    // Check if the endpoint has a timeout, if so, use it.
-	timeoutStr = properties_get(endpointDescription->properties, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT);
-    if (timeoutStr == NULL) {
-    	// If not, get the global variable and use that one.
-    	bundleContext_getProperty(rsa->context, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT, &timeoutStr);
-    }
-
-    // Update timeout if a property is used to set it.
-    if (timeoutStr != NULL) {
-    	timeout = atoi(timeoutStr);
-    }
-
-    celix_status_t status = CELIX_SUCCESS;
-    CURL *curl;
-    CURLcode res;
-
-    curl = curl_easy_init();
-    if(!curl) {
-        status = CELIX_ILLEGAL_STATE;
-    } else {
-    	curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
-        curl_easy_setopt(curl, CURLOPT_URL, &url[0]);
-        curl_easy_setopt(curl, CURLOPT_POST, 1L);
-        curl_easy_setopt(curl, CURLOPT_READFUNCTION, remoteServiceAdmin_readCallback);
-        curl_easy_setopt(curl, CURLOPT_READDATA, &post);
-        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, remoteServiceAdmin_write);
-        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&get);
-        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)post.size);
-        res = curl_easy_perform(curl);
-        curl_easy_cleanup(curl);
-
-        *reply = get.writeptr;
-        *replyStatus = res;
-    }
-
-    return status;
-}
-
-static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp) {
-    struct post *post = userp;
-
-    if (post->size) {
-        *(char *) ptr = post->readptr[0];
-        post->readptr++;
-        post->size--;
-        return 1;
-    }
-
-    return 0;
-}
-
-static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp) {
-  size_t realsize = size * nmemb;
-  struct get *mem = (struct get *)userp;
-
-  mem->writeptr = realloc(mem->writeptr, mem->size + realsize + 1);
-  if (mem->writeptr == NULL) {
-    /* out of memory! */
-	printf("not enough memory (realloc returned NULL)");
-    exit(EXIT_FAILURE);
-  }
-
-  memcpy(&(mem->writeptr[mem->size]), contents, realsize);
-  mem->size += realsize;
-  mem->writeptr[mem->size] = 0;
-
-  return realsize;
-}
-
-
-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;
-}
-
-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;
-}

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt b/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
index a9b7b00..d0814c6 100644
--- a/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
@@ -14,16 +14,22 @@ include_directories(
     SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) #TODO needed?
     SET(CMAKE_INSTALL_RPATH "${PROJECT_BINARY_DIR}/framework" "${PROJECT_BINARY_DIR}/utils")
 
-	add_executable(rsa_dfi_tests
-	    ${PROJECT_SOURCE_DIR}/launcher/private/src/launcher.c
+	add_executable(test_rsa_dfi
 	    run_tests.cpp
 	    rsa_tests.cpp
+
+	    ${PROJECT_SOURCE_DIR}/launcher/private/src/launcher.c #TODO move to libframework
+	    ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
 	)
-	target_link_libraries(rsa_dfi_tests ${CPPUTEST_LIBRARY} celix_framework celix_utils ${CURL_LIBRARIES})
+	target_link_libraries(test_rsa_dfi ${CPPUTEST_LIBRARY} celix_framework celix_utils ${CURL_LIBRARIES})
 
 	get_property(rsa_bundle_file TARGET remote_service_admin_dfi PROPERTY BUNDLE)
-	configure_file(config.properties.in config.properties @ONLY)
+	get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE)
+    configure_file(config.properties.in config.properties @ONLY)
+
+    add_dependencies(test_rsa_dfi remote_service_admin_dfi calculator)
+
 
-	add_test(NAME run_rsa_dfi_tests COMMAND rsa_dfi_tests)
-	SETUP_TARGET_FOR_COVERAGE(rsa_dfi_tests_cov rsa_dfi_tests ${CMAKE_BINARY_DIR}/coverage/rsa_dfi)
+	add_test(NAME run_test_rsa_dfi COMMAND test_rsa_dfi)
+	SETUP_TARGET_FOR_COVERAGE(test_rsa_dfi_cov test_rsa_dfi ${CMAKE_BINARY_DIR}/coverage/rsa_dfi)
 #endif()

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/remote_service_admin_dfi/tst/config.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/config.properties.in b/remote_services/remote_service_admin_dfi/tst/config.properties.in
index b926f36..df5e625 100644
--- a/remote_services/remote_service_admin_dfi/tst/config.properties.in
+++ b/remote_services/remote_service_admin_dfi/tst/config.properties.in
@@ -1 +1,2 @@
-cosgi.auto.start.1=@rsa_bundle_file@
\ No newline at end of file
+cosgi.auto.start.1=@rsa_bundle_file@ @calc_bundle_file@
+LOGHELPER_ENABLE_STDOUT_FALLBACK=true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp b/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
index f23babd..060b15b 100644
--- a/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
@@ -2,7 +2,10 @@
  * Licensed under Apache License v2. See LICENSE for more information.
  */
 #include <CppUTest/TestHarness.h>
-#include "CppUTest/CommandLineTestRunner.h"                                                                                                                                                                        
+#include <remote_constants.h>
+#include <constants.h>
+#include "CppUTest/CommandLineTestRunner.h"
+#include "../../examples/calculator_service/public/include/calculator_service.h"
 
 extern "C" {
 
@@ -15,71 +18,144 @@ extern "C" {
 #include "launcher.h"
 #include "framework.h"
 #include "remote_service_admin.h"
+#include "calculator_service.h"
 
 
-framework_pt framework = NULL;
-bundle_context_pt context = NULL;
-service_reference_pt rsaRef = NULL;
-remote_service_admin_service_pt rsa = NULL;
+    framework_pt framework = NULL;
+    bundle_context_pt context = NULL;
 
-static void setupFm(void) {
-    int rc = 0;
+    service_reference_pt rsaRef = NULL;
+    remote_service_admin_service_pt rsa = NULL;
 
-    rc = celixLauncher_launch("config.properties", &framework);
-    CHECK_EQUAL(CELIX_SUCCESS, rc);
+    service_reference_pt calcRef = NULL;
+    calculator_service_pt calc = NULL;
 
-    bundle_pt bundle = NULL;
-    rc = framework_getFrameworkBundle(framework, &bundle);
-    CHECK_EQUAL(CELIX_SUCCESS, rc);
+    static void setupFm(void) {
+        int rc = 0;
 
-    rc = bundle_getContext(bundle, &context);
-    CHECK_EQUAL(CELIX_SUCCESS, rc);
+        rc = celixLauncher_launch("config.properties", &framework);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
 
-    rc = bundleContext_getServiceReference(context, (char *)OSGI_RSA_REMOTE_SERVICE_ADMIN, &rsaRef);
-    CHECK_EQUAL(CELIX_SUCCESS, rc);
+        bundle_pt bundle = NULL;
+        rc = framework_getFrameworkBundle(framework, &bundle);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
 
-    rc = bundleContext_getService(context, rsaRef, (void **)&rsa);
-    CHECK_EQUAL(CELIX_SUCCESS, rc);
-}
+        rc = bundle_getContext(bundle, &context);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
 
-static void teardownFm(void) {
-    int rc = 0;
-    rc = bundleContext_ungetService(context, rsaRef, NULL);
-    CHECK_EQUAL(CELIX_SUCCESS, rc);
+        rc = bundleContext_getServiceReference(context, (char *)OSGI_RSA_REMOTE_SERVICE_ADMIN, &rsaRef);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        CHECK(rsaRef != NULL);
 
-    celixLauncher_stop(framework);
-    celixLauncher_waitForShutdown(framework);
-    celixLauncher_destroy(framework);
+        rc = bundleContext_getService(context, rsaRef, (void **)&rsa);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
 
-    rsaRef = NULL;
-    rsa = NULL;
-    context = NULL;
-    framework = NULL;
-}
+        rc = bundleContext_getServiceReference(context, (char *)CALCULATOR_SERVICE, &calcRef);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        CHECK(calcRef != NULL);
 
-static void testInfo(void) {
-    int rc = 0;
-    array_list_pt exported = NULL;
-    array_list_pt imported = NULL;
-    arrayList_create(&exported);
-    arrayList_create(&imported);
+        rc = bundleContext_getService(context, calcRef, (void **)&calc);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+    }
 
-    rc = rsa->getExportedServices(rsa->admin, &exported);
-    CHECK_EQUAL(CELIX_SUCCESS, rc);
-    CHECK_EQUAL(0, arrayList_size(exported));
+    static void teardownFm(void) {
+        int rc = 0;
+        rc = bundleContext_ungetService(context, rsaRef, NULL);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
 
-    rc = rsa->getImportedEndpoints(rsa->admin, &imported);
-    CHECK_EQUAL(CELIX_SUCCESS, rc);
-    CHECK_EQUAL(0, arrayList_size(imported));
-}
+        rc = bundleContext_ungetService(context, calcRef, NULL);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
 
-static void testExportService(void) {
-    //TODO
-}
+        celixLauncher_stop(framework);
+        celixLauncher_waitForShutdown(framework);
+        celixLauncher_destroy(framework);
 
-static void testImportService(void) {
-    //TODO
-}
+        rsaRef = NULL;
+        rsa = NULL;
+        calcRef = NULL;
+        calc = NULL;
+        context = NULL;
+        framework = NULL;
+    }
+
+    static void testServices(void) {
+        int rc = 0;
+        array_list_pt exported = NULL;
+        array_list_pt imported = NULL;
+        arrayList_create(&exported);
+        arrayList_create(&imported);
+
+        rc = rsa->getExportedServices(rsa->admin, &exported);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        CHECK_EQUAL(0, arrayList_size(exported));
+
+        rc = rsa->getImportedEndpoints(rsa->admin, &imported);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        CHECK_EQUAL(0, arrayList_size(imported));
+
+        double result = 0;
+        rc = calc->add(calc->calculator, 2.0, 5.0, &result);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        CHECK_EQUAL(7.0, result);
+    }
+
+    static void testExportService(void) {
+        int rc = 0;
+        char *calcId = NULL;
+        array_list_pt regs = NULL;
+
+        rc = arrayList_create(&regs);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = serviceReference_getProperty(calcRef, (char *)"service.id", &calcId);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = rsa->exportService(rsa->admin, calcId, NULL, &regs);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        CHECK_EQUAL(1, arrayList_size(regs));
+    }
+
+    static void testImportService(void) {
+        int rc = 0;
+        import_registration_pt reg = NULL;
+        endpoint_description_pt endpoint = NULL;
+
+        properties_pt props = properties_create();
+        properties_set(props, (char *)OSGI_RSA_ENDPOINT_SERVICE_ID, (char *)"42");
+        properties_set(props, (char *)OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42");
+        properties_set(props, (char *)OSGI_RSA_ENDPOINT_ID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42-42");
+        properties_set(props, (char *)OSGI_FRAMEWORK_OBJECTCLASS,(char *)"org.apache.celix.Example");
+
+        rc = endpointDescription_create(props, &endpoint);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = rsa->importService(rsa->admin, endpoint, &reg);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        CHECK(reg != NULL);
+
+        service_reference_pt ref = NULL;
+        rc = bundleContext_getServiceReference(context, (char *)"org.apache.celix.Example", &ref);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        CHECK(ref != NULL);
+
+        /* Cannot test. uses requesting bundles descriptor
+        void *service = NULL;
+        rc = bundleContext_getService(context, ref, &service);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        CHECK(service != NULL);
+         */
+    }
+
+    static void testBundles(void) {
+        array_list_pt bundles = NULL;
+
+        int rc = bundleContext_getBundles(context, &bundles);
+        CHECK_EQUAL(0, rc);
+        CHECK_EQUAL(3, arrayList_size(bundles)); //framework, rsa_dfi & calc
+
+        arrayList_destroy(bundles);
+    }
 
 }
 
@@ -95,7 +171,7 @@ TEST_GROUP(RsaDfiTests) {
 };
 
 TEST(RsaDfiTests, InfoTest) {
-    testInfo();
+    testServices();
 }
 
 TEST(RsaDfiTests, ExportService) {
@@ -105,3 +181,7 @@ TEST(RsaDfiTests, ExportService) {
 TEST(RsaDfiTests, ImportService) {
     testImportService();
 }
+
+TEST(RsaDfiTests, TestBundles) {
+    testBundles();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c b/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
index 319c849..41d1659 100644
--- a/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
+++ b/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
@@ -679,57 +679,74 @@ celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt
 
 
 celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus) {
+	celix_status_t status = CELIX_SUCCESS;
 
-    struct post post;
-    post.readptr = request;
-    post.size = strlen(request);
+	struct post post;
+	struct get get;
+	char url[256];
+	if (request != NULL) {
 
-    struct get get;
-    get.size = 0;
-    get.writeptr = malloc(1);
 
-    char *serviceUrl = properties_get(endpointDescription->properties, (char*) ENDPOINT_URL);
-    char url[256];
-    snprintf(url, 256, "%s", serviceUrl);
+		post.readptr = request;
+		post.size = strlen(request);
 
-    // assume the default timeout
-    int timeout = DEFAULT_TIMEOUT;
+		get.size = 0;
+		get.writeptr = malloc(1);
 
-    char *timeoutStr = NULL;
-    // Check if the endpoint has a timeout, if so, use it.
-	timeoutStr = properties_get(endpointDescription->properties, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT);
-    if (timeoutStr == NULL) {
-    	// If not, get the global variable and use that one.
-    	bundleContext_getProperty(rsa->context, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT, &timeoutStr);
-    }
+		char *serviceUrl = properties_get(endpointDescription->properties, (char *) ENDPOINT_URL);
+		if (serviceUrl != NULL) {
+			snprintf(url, 256, "%s", serviceUrl);
+		} else {
+			status = CELIX_BUNDLE_EXCEPTION;
+			logHelper_log(rsa->loghelper, OSGI_LOGSERVICE_INFO, "Endpoint Description does not contain mandatory property '%s'", ENDPOINT_URL);
+		}
+	} else {
+		status = CELIX_ILLEGAL_ARGUMENT;
+	}
 
-    // Update timeout if a property is used to set it.
-    if (timeoutStr != NULL) {
-    	timeout = atoi(timeoutStr);
-    }
+	// assume the default timeout
+	int timeout = DEFAULT_TIMEOUT;
 
-    celix_status_t status = CELIX_SUCCESS;
-    CURL *curl;
-    CURLcode res;
-
-    curl = curl_easy_init();
-    if(!curl) {
-        status = CELIX_ILLEGAL_STATE;
-    } else {
-    	curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
-        curl_easy_setopt(curl, CURLOPT_URL, &url[0]);
-        curl_easy_setopt(curl, CURLOPT_POST, 1L);
-        curl_easy_setopt(curl, CURLOPT_READFUNCTION, remoteServiceAdmin_readCallback);
-        curl_easy_setopt(curl, CURLOPT_READDATA, &post);
-        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, remoteServiceAdmin_write);
-        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&get);
-        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)post.size);
-        res = curl_easy_perform(curl);
-        curl_easy_cleanup(curl);
-
-        *reply = get.writeptr;
-        *replyStatus = res;
-    }
+	if (status == CELIX_SUCCESS) {
+		char *timeoutStr = NULL;
+
+		// Check if the endpoint has a timeout, if so, use it.
+		timeoutStr = properties_get(endpointDescription->properties, (char *) OSGI_RSA_REMOTE_PROXY_TIMEOUT);
+		if (timeoutStr == NULL) {
+			// If not, get the global variable and use that one.
+			status = bundleContext_getProperty(rsa->context, (char *) OSGI_RSA_REMOTE_PROXY_TIMEOUT, &timeoutStr);
+		}
+
+		// Update timeout if a property is used to set it.
+		if (timeoutStr != NULL) {
+			timeout = atoi(timeoutStr);
+		}
+	}
+
+	if (status == CELIX_SUCCESS) {
+
+		CURL *curl;
+		CURLcode res;
+
+		curl = curl_easy_init();
+		if (!curl) {
+			status = CELIX_ILLEGAL_STATE;
+		} else {
+			curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
+			curl_easy_setopt(curl, CURLOPT_URL, &url[0]);
+			curl_easy_setopt(curl, CURLOPT_POST, 1L);
+			curl_easy_setopt(curl, CURLOPT_READFUNCTION, remoteServiceAdmin_readCallback);
+			curl_easy_setopt(curl, CURLOPT_READDATA, &post);
+			curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, remoteServiceAdmin_write);
+			curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &get);
+			curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t) post.size);
+			res = curl_easy_perform(curl);
+			curl_easy_cleanup(curl);
+
+			*reply = get.writeptr;
+			*replyStatus = res;
+		}
+	}
 
     return status;
 }
@@ -764,27 +781,3 @@ static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb
 
   return realsize;
 }
-
-
-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;
-}
-
-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;
-}

http://git-wip-us.apache.org/repos/asf/celix/blob/da86474f/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c b/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
index 7f8f97a..34b8533 100644
--- a/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
+++ b/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
@@ -863,28 +863,4 @@ celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt
     }
 
     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;
-}
-
-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


[30/50] [abbrv] celix git commit: CELIX-237: Fixed issue with sequence and removed mem leaks from json_rpc

Posted by pn...@apache.org.
CELIX-237: Fixed issue with sequence and removed mem leaks from json_rpc


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

Branch: refs/heads/develop
Commit: f99de6ed13f730840d233bb1b87ace041f966631
Parents: c0d4f75
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Mon Sep 7 12:32:45 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon Sep 7 12:32:45 2015 +0200

----------------------------------------------------------------------
 .../dynamic_function_interface/dyn_function.c   |   9 +-
 .../dynamic_function_interface/dyn_type.c       |   6 +
 .../dynamic_function_interface/json_rpc.c       |  93 +++++++++------
 .../descriptors/example1.descriptor             |   8 +-
 .../dyn_function_tests.cpp                      |  45 +++++++-
 .../json_rpc_tests.cpp                          | 115 ++++++++++++++++++-
 6 files changed, 226 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/f99de6ed/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
index abd27d0..e059078 100644
--- 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
@@ -135,13 +135,11 @@ static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descrip
             }
         }
 
-        if (status == 0) {
+        if (status == OK) {
             TAILQ_INSERT_TAIL(&dynFunc->arguments, arg, entries);
         } else {
             if (arg != NULL) {
-                if (arg->name != NULL) {
-                    free(arg->name);
-                }
+                free(arg->name);
                 if (arg->type != NULL) {
                     dynType_destroy(arg->type);
                 }
@@ -218,8 +216,7 @@ void dynFunction_destroy(dyn_function_type *dynFunc) {
 }
 
 int dynFunction_call(dyn_function_type *dynFunc, void(*fn)(void), void *returnValue, void **argValues) {
-    //TODO check dynFunc arg
-    ffi_call(&dynFunc->cif, fn, returnValue, argValues);    
+    ffi_call(&dynFunc->cif, fn, returnValue, argValues);
     return 0;
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/f99de6ed/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
index aae7ebc..70f6a7b 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
@@ -443,11 +443,16 @@ static int dynType_parseSequence(FILE *stream, dyn_type *type) {
     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);
+        LOG_DEBUG("seq size is %zu\n", type->ffiType->size);
     }
 
     return status;
@@ -513,6 +518,7 @@ static void dynType_clear(dyn_type *type) {
         if (mEntry != NULL) {
             free(mEntry->name);
             free(mEntry->value);
+            free(mEntry);
         }
         mEntry = next;
     }

http://git-wip-us.apache.org/repos/asf/celix/blob/f99de6ed/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
index 5b49f2b..9acd3fb 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
@@ -5,7 +5,6 @@
 #include "json_serializer.h"
 #include "dyn_type.h"
 #include "dyn_interface.h"
-
 #include <jansson.h>
 #include <assert.h>
 #include <stdint.h>
@@ -62,6 +61,8 @@ int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request, c
         LOG_DEBUG("RSA: found method '%s'\n", entry->id);
     }
 
+    dyn_type *returnType = dynFunction_returnType(method->dynFunc);
+
     void (*fp)(void) = NULL;
     void *handle = NULL;
     if (status == OK) {
@@ -83,22 +84,19 @@ int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request, c
 
     int i;
     int index = 0;
+
     for (i = 0; i < nrOfArgs; i += 1) {
         dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
         const char *argMeta = dynType_getMetaInfo(argType, "am");
         if (argMeta == NULL) {
-            printf("setting std for %i\n", i);
             value = json_array_get(arguments, index++);
             status = jsonSerializer_deserializeJson(argType, value, &(args[i]));
         } else if (strcmp(argMeta, "pre") == 0) {
-            printf("setting pre alloc output for %i\n", i);
             dynType_alloc(argType, &args[i]);
-
-        } else if ( strcmp(argMeta, "out") == 0) {
-            printf("setting output for %i\n", i);
-            args[i] = NULL;
+        } else if (strcmp(argMeta, "out") == 0) {
+            void *inMemPtr = calloc(1, sizeof(void *));
+            args[i] = &inMemPtr;
         } else if (strcmp(argMeta, "handle") == 0) {
-            printf("setting handle for %i\n", i);
             args[i] = &handle;
         }
 
@@ -108,32 +106,54 @@ int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request, c
     }
     json_decref(js_request);
 
+    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;
 
-    //TODO assert return type is native int
-    int returnVal = 0;
-    dynFunction_call(func, fp, (void *)&returnVal, args);
-    printf("done calling\n");
-    double **r = args[2];
-    printf("result ptrptr is %p, result ptr %p, result is %f\n", r, *r, **r);
+    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);
-        const char *argMeta = dynType_getMetaInfo(argType, "am");
-        if (argMeta == NULL) {
-            //ignore
-        } else if (strcmp(argMeta, "pre") == 0)  {
-            if (status == OK) {
-                status = jsonSerializer_serializeJson(argType, args[i], &jsonResult);
+    if (funcCallStatus == 0 && status == OK) {
+        for (i = 0; i < nrOfArgs; i += 1) {
+            dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
+            const char *argMeta = dynType_getMetaInfo(argType, "am");
+            if (argMeta == NULL) {
+                dynType_free(argType, args[i]);
+            } else if (strcmp(argMeta, "pre") == 0) {
+                if (status == OK) {
+                    status = jsonSerializer_serializeJson(argType, args[i], &jsonResult);
+                }
+                dynType_free(argType, args[i]);
+            } else if (strcmp(argMeta, "out") == 0) {
+                void ***out = args[i];
+                if (out != NULL && *out != NULL && **out != NULL) {
+                    status = jsonSerializer_serializeJson(argType, out, &jsonResult);
+                    dyn_type *typedType = NULL;
+                    if (status == OK) {
+                        status = dynType_typedPointer_getTypedType(argType, &typedType);
+                    }
+                    if (status == OK) {
+                        dynType_free(typedType, *out);
+                    }
+                } else {
+                    LOG_DEBUG("Output ptr is null");
+                }
             }
-        } else if (strcmp(argMeta, "out") == 0) {
-            printf("TODO\n");
-            assert(false);
-        }
 
-        if (status != OK) {
-            break;
+            if (status != OK) {
+                break;
+            }
         }
     }
 
@@ -141,18 +161,22 @@ int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request, c
     if (status == OK) {
         LOG_DEBUG("creating payload\n");
         json_t *payload = json_object();
-        json_object_set_new(payload, "r", jsonResult);
+        if (funcCallStatus == 0) {
+            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 if '%s'\n", status, response);
+        LOG_DEBUG("status ptr is %p. response is '%s'\n", status, response);
     }
 
     if (status == OK) {
         *out = response;
     } else {
-        if (response != NULL) {
-            free(response);
-        }
+        free(response);
     }
 
     //TODO free args (created by jsonSerializer and dynType_alloc) (dynType_free)
@@ -165,7 +189,7 @@ int jsonRpc_prepareInvokeRequest(dyn_function_type *func, const char *id, void *
 
     LOG_DEBUG("Calling remote function '%s'\n", id);
     json_t *invoke = json_object();
-    json_object_set(invoke, "m", json_string(id));
+    json_object_set_new(invoke, "m", json_string(id));
 
     json_t *arguments = json_array();
     json_object_set_new(invoke, "a", arguments);
@@ -216,7 +240,6 @@ int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void *args[]
         if (argMeta == NULL) {
             //skip
         } else if (strcmp(argMeta, "pre") == 0) {
-            LOG_DEBUG("found pre argument at %i", i);
             dyn_type *subType = NULL;
             dynType_typedPointer_getTypedType(argType, &subType);
             void *tmp = NULL;

http://git-wip-us.apache.org/repos/asf/celix/blob/f99de6ed/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
index 97b1df8..771dc5e 100644
--- 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
@@ -7,7 +7,7 @@ classname=org.example.Calculator
 :types
 StatsResult={DDD[D average min max input}
 :methods
-add(DD)D=add(PDD*D)N
-sub(DD)D=sub(PDD*D)N
-sqrt(D)D=sqrt(PD*D)N
-stats([D)LStatsResult;=stats(P[D*LStatsResult;)N
+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/f99de6ed/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
index 413f6e9..14f2f54 100644
--- 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
@@ -166,6 +166,45 @@ extern "C" {
 
         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) {
@@ -190,4 +229,8 @@ TEST(DynFunctionTests, DynFuncAccTest) {
 
 TEST(DynFunctionTests, DynFuncTest3) {
     test_example3();
-}
\ No newline at end of file
+}
+
+TEST(DynFunctionTests, DynFuncTest4) {
+    test_example4();
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/f99de6ed/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
index 60b028f..5e116a5 100644
--- 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
@@ -2,6 +2,8 @@
  * Licensed under Apache License v2. See LICENSE for more information.
  */
 #include <CppUTest/TestHarness.h>
+#include <float.h>
+#include <assert.h>
 #include "CppUTest/CommandLineTestRunner.h"                                                                                                                                                                        
 
 extern "C" {
@@ -74,9 +76,110 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
         dynFunction_destroy(dynFunc);
     }
 
+    int add(void *handle, double a, double b, double *result) {
+        *result = a + b;
+        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;
+        int count = 0;
+        double max = DBL_MIN;
+        double min = DBL_MAX;
+
+        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 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 **);
+    };
+
+    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);
+
+        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);
+
+        char *result = NULL;
 
-    void callTest(void) {
-        //TODO
+        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);
     }
 
 }
@@ -103,8 +206,12 @@ TEST(JsonRpcTests, handleTest) {
     handleTest();
 }
 
-TEST(JsonRpcTests, call) {
-    callTest();
+TEST(JsonRpcTests, callPre) {
+    callTestPreAllocated();
+}
+
+TEST(JsonRpcTests, callOut) {
+    callTestOutput();
 }
 
 


[25/50] [abbrv] celix git commit: CELIX-237: Merge branch 'develop' into ffi

Posted by pn...@apache.org.
CELIX-237: Merge branch 'develop' into ffi


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

Branch: refs/heads/develop
Commit: 9937ce132caabdfa4e2de27f13558258d5c584f7
Parents: b6f2ae4 e0a5195
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Sep 1 16:37:41 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Sep 1 16:37:41 2015 +0200

----------------------------------------------------------------------
 .gitignore                                      |   1 +
 CMakeLists.txt                                  |   3 +-
 dependency_manager_2/CMakeLists.txt             |   2 +-
 deployment_admin/CMakeLists.txt                 |   2 +-
 deployment_admin/private/src/deployment_admin.c |   9 +-
 log_service/CMakeLists.txt                      |   2 +-
 log_writer/CMakeLists.txt                       |   2 +-
 .../private/src/endpoint_discovery_poller.c     |  72 +++++-----
 .../discovery_configured/CMakeLists.txt         |   2 +-
 remote_services/discovery_etcd/CMakeLists.txt   |   2 +-
 .../discovery_etcd/private/include/etcd.h       |   2 +-
 .../discovery_etcd/private/src/etcd.c           | 135 ++++++++++---------
 .../discovery_etcd/private/src/etcd_watcher.c   |  70 ++++++++--
 .../discovery_shm/private/src/shm_watcher.c     |   2 +-
 remote_services/examples/CMakeLists.txt         |   2 +-
 .../remote_service_admin_http/CMakeLists.txt    |   2 +-
 remote_shell/CMakeLists.txt                     |   4 +-
 shell/CMakeLists.txt                            |   2 +-
 shell_tui/CMakeLists.txt                        |   2 +-
 19 files changed, 200 insertions(+), 118 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/9937ce13/.gitignore
----------------------------------------------------------------------
diff --cc .gitignore
index 159da4f,98033a5..f630756
--- a/.gitignore
+++ b/.gitignore
@@@ -17,7 -17,5 +17,8 @@@
  
  /.project
  .DS_Store
+ .idea
  build
 +*~
 +*.swp
 +.idea

http://git-wip-us.apache.org/repos/asf/celix/blob/9937ce13/CMakeLists.txt
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/celix/blob/9937ce13/remote_services/discovery/private/src/endpoint_discovery_poller.c
----------------------------------------------------------------------


[12/50] [abbrv] celix git commit: CELIX-237: Added extra dyn function test for a output parameter

Posted by pn...@apache.org.
CELIX-237: Added extra dyn function test for a output parameter


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

Branch: refs/heads/develop
Commit: fa527209f1e74b61d2d844a8d2b7f38f2b28659a
Parents: 30f7e84
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Aug 11 19:01:44 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Aug 11 19:01:44 2015 +0200

----------------------------------------------------------------------
 .../tst/dyn_function_tests.cpp                  | 41 ++++++++++++++++++++
 1 file changed, 41 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/fa527209/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
index 9b681de..868073b 100644
--- 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
@@ -120,6 +120,42 @@ extern "C" {
         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;
+        printf("out is %p and *out is %f\n", out, *out);
+        return 0;
+    }
+
+    static void test_example3(void) {
+        dyn_function_type *dynFunc = NULL;
+        int rc;
+
+        rc = dynFunction_parseWithStr(EXAMPLE3_DESCRIPTOR, NULL, &dynFunc);
+        CHECK_EQUAL(0, rc);
+        double result = -1.0;
+        double *input = &result;
+        printf("\n");
+        printf("input is %p, &input is %p and *input is %d\n", input, &input, *input);
+        double a = 2.0;
+        void *ptr = &a;
+        void *args[3];
+        args[0] = &ptr;
+        args[1] = &a;
+        args[2] = &input;
+        void (*fp)(void) = (void(*)(void)) testExample3;
+
+        rc = dynFunction_call(dynFunc, fp, &result, args);
+        printf("input is %p, &input is %p and *input is %d\n", input, &input, *input);
+
+        CHECK_EQUAL(0, rc);
+        CHECK_EQUAL(4.0, result);
+    }
 
 }
 
@@ -141,4 +177,9 @@ TEST(DynFunctionTests, DynFuncTest2) {
 
 TEST(DynFunctionTests, DynFuncAccTest) {
     test_access_functions();
+}
+
+
+TEST(DynFunctionTests, DynFuncTest3) {
+    test_example3();
 }
\ No newline at end of file


[23/50] [abbrv] celix git commit: CELIX_237: Merge remote-tracking branch 'origin/develop' into ffi

Posted by pn...@apache.org.
CELIX_237: Merge remote-tracking branch 'origin/develop' into ffi

Conflicts:
	.travis.yml


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

Branch: refs/heads/develop
Commit: b5d2367d88b4969cb00eb7a9f40fd09e03cf5bd8
Parents: 1685377 f32a233
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Aug 18 12:46:11 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Aug 18 12:46:11 2015 +0200

----------------------------------------------------------------------
 CMakeLists.txt                                  |     1 +
 cmake/CMakeCelix.cmake                          |     4 +
 deployment_admin/private/src/deployment_admin.c |     2 +-
 device_access/device_access/CMakeLists.txt      |     2 -
 device_access/driver_locator/CMakeLists.txt     |     2 -
 .../example/base_driver/CMakeLists.txt          |     2 -
 .../base_driver/private/src/base_driver.c       |     2 +-
 .../example/consuming_driver/CMakeLists.txt     |     2 -
 .../private/src/consuming_driver.c              |     1 +
 .../example/refining_driver/CMakeLists.txt      |     2 -
 examples/CMakeLists.txt                         |     7 +-
 examples/deploy.cmake                           |     6 +-
 framework/private/src/framework.c               |     3 +-
 .../private/src/endpoint_discovery_server.c     |     9 +
 .../discovery_configured/CMakeLists.txt         |    22 +-
 .../remote_service_admin_http/CMakeLists.txt    |     6 +-
 .../private/src/remote_service_admin_impl.c     |    10 +-
 .../utils/private/include/civetweb.h            |   542 +-
 remote_services/utils/private/src/civetweb.c    | 14935 +++++++----------
 19 files changed, 6574 insertions(+), 8986 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/b5d2367d/CMakeLists.txt
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/celix/blob/b5d2367d/cmake/CMakeCelix.cmake
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/celix/blob/b5d2367d/framework/private/src/framework.c
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/celix/blob/b5d2367d/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
----------------------------------------------------------------------


[43/50] [abbrv] celix git commit: CELIX-237: In case of an empty descriptorFile, the proxy is not set but free'd

Posted by pn...@apache.org.
CELIX-237: In case of an empty descriptorFile, the proxy is not set but free'd


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

Branch: refs/heads/develop
Commit: f04a213b4faa6961a1b7b82e7a170f4f8b2b747a
Parents: 3f71ac4
Author: Bjoern Petri <bp...@apache.org>
Authored: Mon Sep 28 16:56:06 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Mon Sep 28 16:56:06 2015 +0200

----------------------------------------------------------------------
 .../rsa/private/src/import_registration_dfi.c                    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/f04a213b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
index 680a75a..fbb958e 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
@@ -208,7 +208,7 @@ static celix_status_t importRegistration_createProxy(import_registration_pt impo
 
     if (status == CELIX_SUCCESS) {
         *out = proxy;
-    } else {
+    } else if (proxy != NULL) {
         if (proxy->intf != NULL) {
             dynInterface_destroy(proxy->intf);
             proxy->intf = NULL;
@@ -325,4 +325,4 @@ celix_status_t importReference_getImportedEndpoint(import_reference_pt reference
 celix_status_t importReference_getImportedService(import_reference_pt reference) {
     celix_status_t status = CELIX_SUCCESS;
     return status;
-}
\ No newline at end of file
+}


[27/50] [abbrv] celix git commit: CELIX-237: Added callback from export/import registration to rsa to remove the export/import from internal registration

Posted by pn...@apache.org.
CELIX-237: Added callback from export/import registration to rsa to remove the export/import from internal registration


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

Branch: refs/heads/develop
Commit: 89968d937fd239b93382d419dd6354469f107bbb
Parents: 3853a7c
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Sep 2 13:42:50 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Sep 2 13:42:50 2015 +0200

----------------------------------------------------------------------
 .../private/include/export_registration_dfi.h   |  2 +-
 .../private/include/import_registration_dfi.h   |  4 +-
 .../private/include/remote_service_admin_dfi.h  | 56 +++++++++++++++
 .../include/remote_service_admin_http_impl.h    | 73 -------------------
 .../rsa/private/src/export_registration_dfi.c   | 75 +++++++++++++++++---
 .../rsa/private/src/import_registration_dfi.c   | 23 ++++--
 .../src/remote_service_admin_activator.c        |  4 +-
 .../rsa/private/src/remote_service_admin_dfi.c  | 11 +--
 .../rsa_tst/bundle/tst_activator.c              |  2 +-
 9 files changed, 153 insertions(+), 97 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/89968d93/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h b/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
index 4356646..100294c 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
+++ b/remote_services/remote_service_admin_dfi/rsa/private/include/export_registration_dfi.h
@@ -9,7 +9,7 @@
 #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);
+celix_status_t exportRegistration_create(log_helper_pt helper, void (*closedCallback)(void *handle, export_registration_pt reg), void *handle, 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);

http://git-wip-us.apache.org/repos/asf/celix/blob/89968d93/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h b/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
index ec885fd..6f2a232 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
+++ b/remote_services/remote_service_admin_dfi/rsa/private/include/import_registration_dfi.h
@@ -10,7 +10,9 @@
 
 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);
+celix_status_t importRegistration_create(bundle_context_pt context, void (*rsaCallback)(void *, import_registration_pt),
+                                         void *rsaHandle, 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,

http://git-wip-us.apache.org/repos/asf/celix/blob/89968d93/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h b/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h
new file mode 100644
index 0000000..64e69e4
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_dfi.h
@@ -0,0 +1,56 @@
+/**
+ *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 "bundle_context.h"
+#include "endpoint_description.h"
+
+typedef struct remote_service_admin *remote_service_admin_pt;
+
+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_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations);
+celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt  admin, 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/89968d93/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_http_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_http_impl.h b/remote_services/remote_service_admin_dfi/rsa/private/include/remote_service_admin_http_impl.h
deleted file mode 100644
index 65ca83b..0000000
--- a/remote_services/remote_service_admin_dfi/rsa/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/89968d93/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
index 85ecb43..b5f0fec 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
@@ -5,7 +5,9 @@
 #include <dyn_interface.h>
 #include <json_serializer.h>
 #include <remote_constants.h>
-#include "export_registration.h"
+#include <remote_service_admin.h>
+#include <service_tracker_customizer.h>
+#include <service_tracker.h>
 #include "export_registration_dfi.h"
 
 struct export_reference {
@@ -15,28 +17,50 @@ struct export_reference {
 
 struct export_registration {
     bundle_context_pt  context;
+    void (*rsaCloseExportCallback)(void *handle, export_registration_pt reg);
+    void *handle;
     struct export_reference exportReference;
-    void *service;
+    char *servId;
     dyn_interface_type *intf; //owner
+    service_tracker_pt tracker;
+
+    celix_thread_mutex_t mutex;
+    void *service; //protected by mutex
 
     //TODO add tracker and lock
     bool closed;
 };
 
-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) {
+static void exportRegistration_addServ(export_registration_pt reg, service_reference_pt ref, void *service);
+static void exportRegistration_removeServ(export_registration_pt reg, service_reference_pt ref, void *service);
+
+celix_status_t exportRegistration_create(log_helper_pt helper, void (*closedCallback)(void *handle, export_registration_pt reg), void *handle, 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));
+    char *servId = NULL;
+    status = serviceReference_getProperty(reference, "service.id", &servId);
+    if (status != CELIX_SUCCESS) {
+        logHelper_log(helper, OSGI_LOGSERVICE_WARNING, "Cannot find service.id for ref");
+    }
 
-    if (reg == NULL) {
-        status = CELIX_ENOMEM;
+    export_registration_pt reg = NULL;
+    if (status == CELIX_SUCCESS) {
+        reg = calloc(1, sizeof(*reg));
+        if (reg == NULL) {
+            status = CELIX_ENOMEM;
+        }
     }
 
+
     if (status == CELIX_SUCCESS) {
         reg->context = context;
+        reg->rsaCloseExportCallback = closedCallback;
+        reg->handle = handle;
         reg->exportReference.endpoint = endpoint;
         reg->exportReference.reference = reference;
         reg->closed = false;
+
+        celixThreadMutex_create(&reg->mutex, NULL);
     }
 
     char *exports = NULL;
@@ -75,6 +99,17 @@ celix_status_t exportRegistration_create(log_helper_pt helper, service_reference
     }
 
     if (status == CELIX_SUCCESS) {
+        service_tracker_customizer_pt cust = NULL;
+        status = serviceTrackerCustomizer_create(reg, NULL, exportRegistration_addServ, NULL,
+                                                 exportRegistration_removeServ, &cust);
+        if (status == CELIX_SUCCESS) {
+            char filter[32];
+            snprintf(filter, 32, "(service.id=%s)", servId);
+            status = serviceTracker_createWithFilter(reg->context, filter, cust, &reg->tracker);
+        }
+    }
+
+    if (status == CELIX_SUCCESS) {
         *out = reg;
     } else {
         logHelper_log(helper, OSGI_LOGSERVICE_ERROR, "Error creating export registration");
@@ -88,9 +123,9 @@ celix_status_t exportRegistration_call(export_registration_pt export, char *data
     int status = CELIX_SUCCESS;
 
     *responseLength = -1;
-    //TODO lock service
+    celixThreadMutex_lock(&export->mutex);
     status = jsonSerializer_call(export->intf, export->service, data, responseOut);
-    //TODO unlock service
+    celixThreadMutex_unlock(&export->mutex);
 
     return status;
 }
@@ -108,6 +143,10 @@ void exportRegistration_destroy(export_registration_pt reg) {
             reg->exportReference.endpoint = NULL;
             endpointDescription_destroy(ep);
         }
+        if (reg->tracker != NULL) {
+            serviceTracker_destroy(reg->tracker);
+        }
+        celixThreadMutex_destroy(&reg->mutex);
 
         free(reg);
     }
@@ -115,10 +154,25 @@ void exportRegistration_destroy(export_registration_pt reg) {
 
 celix_status_t exportRegistration_start(export_registration_pt reg) {
     celix_status_t status = CELIX_SUCCESS;
-    status = bundleContext_getService(reg->context, reg->exportReference.reference, &reg->service); //TODO use tracker
+
+    serviceTracker_open(reg->tracker);
     return status;
 }
 
+static void exportRegistration_addServ(export_registration_pt reg, service_reference_pt ref, void *service) {
+    celixThreadMutex_lock(&reg->mutex);
+    reg->service = service;
+    celixThreadMutex_unlock(&reg->mutex);
+}
+
+static void exportRegistration_removeServ(export_registration_pt reg, service_reference_pt ref, void *service) {
+    celixThreadMutex_lock(&reg->mutex);
+    if (reg->service == service) {
+        reg->service == NULL;
+    }
+    celixThreadMutex_unlock(&reg->mutex);
+}
+
 celix_status_t exportRegistration_stop(export_registration_pt reg) {
     celix_status_t status = CELIX_SUCCESS;
     status = bundleContext_ungetService(reg->context, reg->exportReference.reference, NULL);
@@ -128,7 +182,7 @@ celix_status_t exportRegistration_stop(export_registration_pt reg) {
 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
+    reg->rsaCloseExportCallback(reg->handle, reg);
     return status;
 }
 
@@ -146,7 +200,6 @@ celix_status_t exportRegistration_getExportReference(export_registration_pt regi
         ref->reference = registration->exportReference.reference;
     } else {
         status = CELIX_ENOMEM;
-        //TODO log
     }
 
     if (status == CELIX_SUCCESS) {

http://git-wip-us.apache.org/repos/asf/celix/blob/89968d93/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
index 09ad25b..9667fa9 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
@@ -16,6 +16,9 @@ struct import_registration {
     service_registration_pt factoryReg;
 
     hash_map_pt proxies; //key -> bundle, value -> service_proxy
+
+    void (*rsaCloseImportCallback)(void *, import_registration_pt);
+    void *rsaHandle;
 };
 
 struct service_proxy {
@@ -29,7 +32,9 @@ static celix_status_t importRegistration_createProxy(import_registration_pt impo
 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 importRegistration_create(bundle_context_pt context, void (*rsaCallback)(void *, import_registration_pt),
+                                         void *rsaHandle, 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));
 
@@ -39,6 +44,8 @@ celix_status_t importRegistration_create(bundle_context_pt context, endpoint_des
 
     if (reg != NULL && reg->factory != NULL) {
         reg->context = context;
+        reg->rsaCloseImportCallback = rsaCallback;
+        reg->rsaHandle = rsaHandle;
         reg->endpoint = endpoint;
         reg->classObject = classObject;
         reg->proxies = hashMap_create(NULL, NULL, NULL, NULL);
@@ -97,7 +104,7 @@ celix_status_t importRegistration_stop(import_registration_pt import) {
     if (import->factoryReg != NULL) {
         serviceRegistration_unregister(import->factoryReg);
     }
-    //TODO unregister every serv instance?
+    //TODO unregister every serv instance? Needed for factory?
     return status;
 }
 
@@ -273,13 +280,21 @@ celix_status_t importRegistration_ungetService(import_registration_pt import, bu
 }
 
 static void importRegistration_destroyProxy(struct service_proxy *proxy) {
-    //TODO
+    if (proxy != NULL) {
+        if (proxy->intf != NULL) {
+            dynInterface_destroy(proxy->intf);
+        }
+        if (proxy->service != NULL) {
+            free(proxy->service);
+        }
+        free(proxy);
+    }
 }
 
 
 celix_status_t importRegistration_close(import_registration_pt registration) {
     celix_status_t status = CELIX_SUCCESS;
-    //TODO
+    registration->rsaCloseImportCallback(registration->rsaHandle, registration);
     return status;
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/89968d93/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c
index 9961a9b..40fb288 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_activator.c
@@ -24,11 +24,13 @@
  *  \copyright	Apache License, Version 2.0
  */
 #include <stdlib.h>
+#include <remote_service_admin.h>
+
+#include "remote_service_admin_dfi.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"
 

http://git-wip-us.apache.org/repos/asf/celix/blob/89968d93/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
index a092a63..00a4b0f 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c
@@ -34,13 +34,14 @@
 #include <curl/curl.h>
 
 #include <jansson.h>
-#include <json_serializer.h>
+#include "json_serializer.h"
+#include "remote_service_admin.h"
 
 #include "import_registration_dfi.h"
 #include "export_registration_dfi.h"
+#include "remote_service_admin_dfi.h"
 #include "dyn_interface.h"
 
-#include "remote_service_admin.h"
 #include "remote_constants.h"
 #include "constants.h"
 #include "civetweb.h"
@@ -412,7 +413,7 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c
         remoteServiceAdmin_createEndpointDescription(admin, reference, interface, &endpoint);
         printf("RSA: Creating export registration with endpoint pointer %p\n", endpoint);
         //TOOD precheck if descriptor exists
-        status = exportRegistration_create(admin->loghelper, reference, endpoint, admin->context, &registration);
+        status = exportRegistration_create(admin->loghelper, remoteServiceAdmin_removeExportedService, admin, reference, endpoint, admin->context, &registration);
         if (status == CELIX_SUCCESS) {
             status = exportRegistration_start(registration);
             if (status == CELIX_SUCCESS) {
@@ -431,7 +432,7 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c
     return status;
 }
 
-celix_status_t remoteServiceAdmin_removeExportedService(export_registration_pt registration) {
+celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration) {
     celix_status_t status = CELIX_SUCCESS;
     //TODO
     /*
@@ -580,7 +581,7 @@ celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, e
 
     import_registration_pt import = NULL;
     if (objectClass != NULL) {
-        status = importRegistration_create(admin->context, endpointDescription, objectClass, &import);
+        status = importRegistration_create(admin->context, NULL, NULL, endpointDescription, objectClass, &import);
     }
     if (status == CELIX_SUCCESS) {
         importRegistration_setSendFn(import, remoteServiceAdmin_send, admin);

http://git-wip-us.apache.org/repos/asf/celix/blob/89968d93/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c
index 1f72db1..c067abf 100644
--- a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c
@@ -125,7 +125,7 @@ static int test(void *handle) {
     int rc;
     if (act->calc != NULL) {
          rc = act->calc->sqrt(act->calc->calculator, 4, &result);
-        printf("calc result is %d\n", result);
+        printf("calc result is %f\n", result);
     } else {
         printf("calc not ready\n");
     }


[17/50] [abbrv] celix git commit: CELIX-237: Refactoring of rsa_dfi layout (lib, lib-tst, rsa bundle, rsa tst)

Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/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
new file mode 100644
index 0000000..82d908b
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
@@ -0,0 +1,47 @@
+#
+# Licensed under Apache License v2. See LICENSE for more information.
+#
+
+
+include_directories(
+    ${PROJECT_SOURCE_DIR}/launcher/public/include
+    ${PROJECT_SOURCE_DIR}/framework/public/include
+    ${PROJECT_SOURCE_DIR}/utils/public/include
+    ${PROJECT_SOURCE_DIR}/utils/public/include
+    ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include
+    ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include
+    bundle
+)
+
+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")
+
+add_executable(test_rsa_dfi
+    run_tests.cpp
+    rsa_tests.cpp
+    rsa_client_server_tests.cpp
+
+    ${PROJECT_SOURCE_DIR}/launcher/private/src/launcher.c #TODO move to libframework
+    ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
+)
+target_link_libraries(test_rsa_dfi celix_framework celix_utils ${CURL_LIBRARIES} ${CPPUTEST_LIBRARY})
+
+get_property(rsa_bundle_file TARGET remote_service_admin_dfi PROPERTY BUNDLE)
+get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE)
+get_property(calculator_shell_bundle_file TARGET calculator_shell PROPERTY BUNDLE)
+get_property(discovery_configured_bundle_file TARGET discovery_configured PROPERTY BUNDLE)
+get_property(topology_manager_bundle_file TARGET topology_manager PROPERTY BUNDLE)
+get_property(tst_bundle_file TARGET rsa_dfi_tst_bundle PROPERTY BUNDLE)
+
+configure_file(config.properties.in config.properties @ONLY)
+configure_file(client.properties.in client.properties @ONLY)
+configure_file(server.properties.in server.properties @ONLY)
+
+add_dependencies(test_rsa_dfi remote_service_admin_dfi calculator)
+
+add_test(NAME run_test_rsa_dfi COMMAND test_rsa_dfi)
+SETUP_TARGET_FOR_COVERAGE(test_rsa_dfi_cov test_rsa_dfi ${CMAKE_BINARY_DIR}/coverage/rsa_dfi)
+

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt
new file mode 100644
index 0000000..0c41ed9
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt
@@ -0,0 +1,24 @@
+#
+# Licensed under Apache License v2. See LICENSE for more information.
+#
+
+include_directories(
+        ${CPPUTEST_INCLUDE_DIR}
+        ${PROJECT_SOURCE_DIR}/framework/public/include
+        ${PROJECT_SOURCE_DIR}/utils/public/include
+        ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include
+)
+
+SET_HEADER(BUNDLE_SYMBOLICNAME "apache_celix_remote_service_admin_dfi_tst_bundle")
+SET(BUNDLE_VERSION "0.0.1")
+SET_HEADERS("Bundle-Name: Apache Celix Remote Service Admin DFI test bundle")
+
+
+bundle(rsa_dfi_tst_bundle
+    SOURCES
+        tst_activator.c
+
+    FILES
+        ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
+)
+target_link_libraries(rsa_dfi_tst_bundle ${CPPUTEST_LIBRARY} celix_framework celix_utils)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c
new file mode 100644
index 0000000..728030e
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_activator.c
@@ -0,0 +1,137 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <service_tracker_customizer.h>
+#include <service_tracker.h>
+
+#include "bundle_activator.h"
+#include "bundle_context.h"
+#include "service_registration.h"
+#include "service_reference.h"
+#include "celix_errno.h"
+
+#include "tst_service.h"
+#include "calculator_service.h"
+
+
+struct activator {
+	bundle_context_pt context;
+	struct tst_service serv;
+	service_registration_pt  reg;
+
+	service_tracker_customizer_pt cust;
+	service_tracker_pt tracker;
+	calculator_service_pt calc;
+};
+
+static celix_status_t addCalc(void * handle, service_reference_pt reference, void * service);
+static celix_status_t removeCalc(void * handle, service_reference_pt reference, void * service);
+static int test(void *handle);
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **out) {
+	celix_status_t status = CELIX_SUCCESS;
+	struct activator *act = calloc(1, sizeof(*act));
+	if (act != NULL) {
+		act->context = context;
+		act->serv.handle = act;
+		act->serv.test = test;
+
+		status = serviceTrackerCustomizer_create(act, NULL, addCalc, NULL, removeCalc, &act->cust);
+		status = CELIX_DO_IF(status, serviceTracker_create(context, CALCULATOR2_SERVICE, act->cust, &act->tracker));
+
+	} else {
+		status = CELIX_ENOMEM;
+	}
+
+	if (status == CELIX_SUCCESS) {
+		*out = act;
+	} else if (act != NULL) {
+		if (act->cust != NULL) {
+			free(act->cust);
+			act->cust = NULL;
+		}
+		if (act->tracker != NULL) {
+			serviceTracker_destroy(act->tracker);
+			act->tracker = NULL;
+		}
+		free(act);
+	}
+
+	return CELIX_SUCCESS;
+}
+
+static celix_status_t addCalc(void * handle, service_reference_pt reference, void * service) {
+	celix_status_t status = CELIX_SUCCESS;
+	struct activator * act = handle;
+	act->calc = service;
+	return status;
+}
+
+static celix_status_t removeCalc(void * handle, service_reference_pt reference, void * service) {
+	celix_status_t status = CELIX_SUCCESS;
+	struct activator * act = handle;
+	if (act->calc == service) {
+		act->calc = NULL;
+	}
+	return status;
+
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+    celix_status_t status = CELIX_SUCCESS;
+	struct activator * act = userData;
+
+	act->reg = NULL;
+	status = bundleContext_registerService(context, (char *)TST_SERVICE_NAME, &act->serv, NULL, &act->reg);
+
+	status = CELIX_DO_IF(status, serviceTracker_open(act->tracker));
+
+
+	return status;
+}
+
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+    celix_status_t status = CELIX_SUCCESS;
+	struct activator * act = userData;
+
+	status = serviceRegistration_unregister(act->reg);
+	status = CELIX_DO_IF(status, serviceTracker_close(act->tracker));
+
+	return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+	struct activator *act = userData;
+	if (act != NULL) {
+		if (act->tracker != NULL) {
+			serviceTracker_destroy(act->tracker);
+			act->tracker = NULL;
+		}
+		free(act);
+	}
+	return CELIX_SUCCESS;
+}
+
+static int test(void *handle) {
+	int status = 0;
+	struct activator *act = handle;
+
+	double result = 0.0;
+
+    int rc;
+    if (act->calc != NULL) {
+         rc = act->calc->sqrt(act->calc->calculator, 4, &result);
+        printf("calc result is %d\n", result);
+    } else {
+        printf("calc not ready\n");
+    }
+
+	if (rc != 0 || result != 2.0) {
+		status = 1;
+	}
+	return status;
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_service.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_service.h b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_service.h
new file mode 100644
index 0000000..2678b0c
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/tst_service.h
@@ -0,0 +1,17 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+
+#ifndef CELIX_TST_SERVICE_H
+#define CELIX_TST_SERVICE_H
+
+#define TST_SERVICE_NAME "tst_service"
+
+struct tst_service {
+    void *handle;
+    int (*test)(void *handle);
+};
+
+typedef struct tst_service *tst_service_pt;
+
+#endif //CELIX_TST_SERVICE_H

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/rsa_tst/client.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/client.properties.in b/remote_services/remote_service_admin_dfi/rsa_tst/client.properties.in
new file mode 100644
index 0000000..a9a06fb
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/client.properties.in
@@ -0,0 +1,8 @@
+cosgi.auto.start.1=@rsa_bundle_file@ @calculator_shell_bundle_file@ @discovery_configured_bundle_file@ @topology_manager_bundle_file@ @tst_bundle_file@
+LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+RSA_PORT=50881
+DISCOVERY_CFG_SERVER_PORT=50991
+DISCOVERY_CFG_POLL_ENDPOINTS=http://127.0.0.1:50992/org.apache.celix.discovery.configured
+org.osgi.framework.storage.clean=onFirstInit
+org.osgi.framework.storage=.cacheClient
+DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/rsa_tst/config.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/config.properties.in b/remote_services/remote_service_admin_dfi/rsa_tst/config.properties.in
new file mode 100644
index 0000000..8412214
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/config.properties.in
@@ -0,0 +1,3 @@
+cosgi.auto.start.1=@rsa_bundle_file@ @calc_bundle_file@
+LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+org.osgi.framework.storage.clean=onFirstInit
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp b/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp
new file mode 100644
index 0000000..35beffe
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp
@@ -0,0 +1,113 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#include <CppUTest/TestHarness.h>
+#include <remote_constants.h>
+#include <constants.h>
+#include <tst_service.h>
+#include "CppUTest/CommandLineTestRunner.h"
+#include "../../examples/calculator_service/public/include/calculator_service.h"
+
+extern "C" {
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+
+#include "launcher.h"
+#include "framework.h"
+#include "remote_service_admin.h"
+#include "calculator_service.h"
+
+    static framework_pt serverFramework = NULL;
+    static bundle_context_pt serverContext = NULL;
+
+    static framework_pt clientFramework = NULL;
+    static bundle_context_pt clientContext = NULL;
+
+    static void setupFm(void) {
+        int rc = 0;
+        bundle_pt bundle = NULL;
+
+        //server
+        rc = celixLauncher_launch("server.properties", &serverFramework);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        bundle = NULL;
+        rc = framework_getFrameworkBundle(serverFramework, &bundle);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = bundle_getContext(bundle, &serverContext);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+
+        //client
+        rc = celixLauncher_launch("client.properties", &clientFramework);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        bundle = NULL;
+        rc = framework_getFrameworkBundle(clientFramework, &bundle);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = bundle_getContext(bundle, &clientContext);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+    }
+
+    static void teardownFm(void) {
+        int rc = 0;
+
+        celixLauncher_stop(serverFramework);
+        celixLauncher_waitForShutdown(serverFramework);
+        celixLauncher_destroy(serverFramework);
+
+        celixLauncher_stop(clientFramework);
+        celixLauncher_waitForShutdown(clientFramework);
+        celixLauncher_destroy(clientFramework);
+
+        serverContext = NULL;
+        serverFramework = NULL;
+        clientContext = NULL;
+        clientFramework = NULL;
+    }
+
+    static void test1(void) {
+        int rc = 0;
+        service_reference_pt ref = NULL;
+        tst_service_pt tst = NULL;
+
+        usleep(2000000); //TODO use tracker
+
+        bundleContext_getServiceReference(clientContext, (char *)TST_SERVICE_NAME, &ref);
+        CHECK_EQUAL(0, rc);
+        CHECK(ref != NULL);
+
+        bundleContext_getService(clientContext, ref, (void **)&tst);
+        CHECK_EQUAL(0, rc);
+        CHECK(tst != NULL);
+
+        rc = tst->test(tst->handle);
+        CHECK_EQUAL(0, rc);
+
+        bundleContext_ungetService(clientContext, ref, NULL);
+        bundleContext_ungetServiceReference(clientContext, ref);
+    }
+
+}
+
+
+TEST_GROUP(RsaDfiClientServerTests) {
+    void setup() {
+        setupFm();
+    }
+
+    void teardown() {
+        teardownFm();
+    }
+};
+
+TEST(RsaDfiClientServerTests, Test1) {
+    test1();
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp b/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp
new file mode 100644
index 0000000..1384573
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp
@@ -0,0 +1,201 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#include <CppUTest/TestHarness.h>
+#include <remote_constants.h>
+#include <constants.h>
+#include "CppUTest/CommandLineTestRunner.h"
+#include "../../examples/calculator_service/public/include/calculator_service.h"
+
+extern "C" {
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "launcher.h"
+#include "framework.h"
+#include "remote_service_admin.h"
+#include "calculator_service.h"
+
+
+    static framework_pt framework = NULL;
+    static bundle_context_pt context = NULL;
+
+    static service_reference_pt rsaRef = NULL;
+    static remote_service_admin_service_pt rsa = NULL;
+
+    static service_reference_pt calcRef = NULL;
+    static calculator_service_pt calc = NULL;
+
+    static void setupFm(void) {
+        int rc = 0;
+
+        rc = celixLauncher_launch("config.properties", &framework);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        bundle_pt bundle = NULL;
+        rc = framework_getFrameworkBundle(framework, &bundle);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = bundle_getContext(bundle, &context);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = bundleContext_getServiceReference(context, (char *)OSGI_RSA_REMOTE_SERVICE_ADMIN, &rsaRef);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        CHECK(rsaRef != NULL);
+
+        rc = bundleContext_getService(context, rsaRef, (void **)&rsa);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = bundleContext_getServiceReference(context, (char *)CALCULATOR2_SERVICE, &calcRef);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        CHECK(calcRef != NULL);
+
+        rc = bundleContext_getService(context, calcRef, (void **)&calc);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+    }
+
+    static void teardownFm(void) {
+        int rc = 0;
+        rc = bundleContext_ungetService(context, rsaRef, NULL);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = bundleContext_ungetService(context, calcRef, NULL);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        celixLauncher_stop(framework);
+        celixLauncher_waitForShutdown(framework);
+        celixLauncher_destroy(framework);
+
+        rsaRef = NULL;
+        rsa = NULL;
+        calcRef = NULL;
+        calc = NULL;
+        context = NULL;
+        framework = NULL;
+    }
+
+    static void testServices(void) {
+        int rc = 0;
+        array_list_pt exported = NULL;
+        array_list_pt imported = NULL;
+        arrayList_create(&exported);
+        arrayList_create(&imported);
+
+        rc = rsa->getExportedServices(rsa->admin, &exported);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        CHECK_EQUAL(0, arrayList_size(exported));
+
+        rc = rsa->getImportedEndpoints(rsa->admin, &imported);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        CHECK_EQUAL(0, arrayList_size(imported));
+
+        double result = 0;
+        rc = calc->add(calc->calculator, 2.0, 5.0, &result);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        CHECK_EQUAL(7.0, result);
+    }
+
+    static void testExportService(void) {
+        int rc = 0;
+        char *calcId = NULL;
+        array_list_pt regs = NULL;
+
+        rc = arrayList_create(&regs);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = serviceReference_getProperty(calcRef, (char *)"service.id", &calcId);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = rsa->exportService(rsa->admin, calcId, NULL, &regs);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        CHECK_EQUAL(1, arrayList_size(regs));
+    }
+
+    static void testImportService(void) {
+        int rc = 0;
+        import_registration_pt reg = NULL;
+        endpoint_description_pt endpoint = NULL;
+
+        properties_pt props = properties_create();
+        properties_set(props, (char *)OSGI_RSA_ENDPOINT_SERVICE_ID, (char *)"42");
+        properties_set(props, (char *)OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42");
+        properties_set(props, (char *)OSGI_RSA_ENDPOINT_ID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42-42");
+        properties_set(props, (char *)OSGI_FRAMEWORK_OBJECTCLASS,(char *)"org.apache.celix.Example");
+
+        rc = endpointDescription_create(props, &endpoint);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = rsa->importService(rsa->admin, endpoint, &reg);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        CHECK(reg != NULL);
+
+        service_reference_pt ref = NULL;
+        rc = bundleContext_getServiceReference(context, (char *)"org.apache.celix.Example", &ref);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        CHECK(ref != NULL);
+
+        /* Cannot test. uses requesting bundles descriptor
+        void *service = NULL;
+        rc = bundleContext_getService(context, ref, &service);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        CHECK(service != NULL);
+         */
+    }
+
+    static void testBundles(void) {
+        array_list_pt bundles = NULL;
+
+        int rc = bundleContext_getBundles(context, &bundles);
+        CHECK_EQUAL(0, rc);
+        CHECK_EQUAL(3, arrayList_size(bundles)); //framework, rsa_dfi & calc
+
+        /*
+        int size = arrayList_size(bundles);
+        int i;
+        for (i = 0; i < size; i += 1) {
+            bundle_pt bundle = NULL;
+            module_pt module = NULL;
+            char *name = NULL;
+
+            bundle = (bundle_pt) arrayList_get(bundles, i);
+            bundle_getCurrentModule(bundle, &module);
+            module_getSymbolicName(module, &name);
+            printf("got bundle with symbolic name '%s'", name);
+        }*/
+
+        arrayList_destroy(bundles);
+    }
+
+}
+
+
+TEST_GROUP(RsaDfiTests) {
+    void setup() {
+        setupFm();
+    }
+
+    void teardown() {
+        teardownFm();
+    }
+};
+
+TEST(RsaDfiTests, InfoTest) {
+    testServices();
+}
+
+TEST(RsaDfiTests, ExportService) {
+    testExportService();
+}
+
+TEST(RsaDfiTests, ImportService) {
+    testImportService();
+}
+
+TEST(RsaDfiTests, TestBundles) {
+    testBundles();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/rsa_tst/run_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/run_tests.cpp b/remote_services/remote_service_admin_dfi/rsa_tst/run_tests.cpp
new file mode 100644
index 0000000..c5e960c
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa_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);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/rsa_tst/server.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/server.properties.in b/remote_services/remote_service_admin_dfi/rsa_tst/server.properties.in
new file mode 100644
index 0000000..ea02519
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/server.properties.in
@@ -0,0 +1,8 @@
+cosgi.auto.start.1=@rsa_bundle_file@ @calc_bundle_file@ @discovery_configured_bundle_file@ @topology_manager_bundle_file@
+LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+RSA_PORT=50882
+DISCOVERY_CFG_SERVER_PORT=50992
+DISCOVERY_CFG_POLL_ENDPOINTS=http://127.0.0.1:50991/org.apache.celix.discovery.configured
+org.osgi.framework.storage.clean=onFirstInit
+org.osgi.framework.storage=.cacheServer
+DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt b/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
deleted file mode 100644
index d21fb89..0000000
--- a/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
+++ /dev/null
@@ -1,47 +0,0 @@
-#
-# Licensed under Apache License v2. See LICENSE for more information.
-#
-
-#TODO add FRAMEWORK_TEST / TEST check
-#if (RSA_EXAMPLES)
-
-    include_directories(
-        ${PROJECT_SOURCE_DIR}/launcher/public/include
-        ${CPPUTEST_INCLUDE_DIR}
-        ${PROJECT_SOURCE_DIR}/framework/public/include
-        ${PROJECT_SOURCE_DIR}/utils/public/include
-        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")
-
-    add_executable(test_rsa_dfi
-        run_tests.cpp
-        rsa_tests.cpp
-        rsa_client_server_tests.cpp
-
-        ${PROJECT_SOURCE_DIR}/launcher/private/src/launcher.c #TODO move to libframework
-        ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
-    )
-    target_link_libraries(test_rsa_dfi celix_framework celix_utils ${CURL_LIBRARIES} ${CPPUTEST_LIBRARY})
-
-    get_property(rsa_bundle_file TARGET remote_service_admin_dfi PROPERTY BUNDLE)
-    get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE)
-    get_property(calculator_shell_bundle_file TARGET calculator_shell PROPERTY BUNDLE)
-    get_property(discovery_configured_bundle_file TARGET discovery_configured PROPERTY BUNDLE)
-    get_property(topology_manager_bundle_file TARGET topology_manager PROPERTY BUNDLE)
-    get_property(tst_bundle_file TARGET rsa_dfi_tst_bundle PROPERTY BUNDLE)
-
-    configure_file(config.properties.in config.properties @ONLY)
-    configure_file(client.properties.in client.properties @ONLY)
-    configure_file(server.properties.in server.properties @ONLY)
-
-    add_dependencies(test_rsa_dfi remote_service_admin_dfi calculator)
-
-
-    add_test(NAME run_test_rsa_dfi COMMAND test_rsa_dfi)
-    SETUP_TARGET_FOR_COVERAGE(test_rsa_dfi_cov test_rsa_dfi ${CMAKE_BINARY_DIR}/coverage/rsa_dfi)
-
-#endif()

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt b/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt
deleted file mode 100644
index b91ebf1..0000000
--- a/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-#
-# Licensed under Apache License v2. See LICENSE for more information.
-#
-
-include_directories(
-        ${PROJECT_SOURCE_DIR}/launcher/public/include
-        ${CPPUTEST_INCLUDE_DIR}
-        ${PROJECT_SOURCE_DIR}/framework/public/include
-        ${PROJECT_SOURCE_DIR}/utils/public/include
-        ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include
-)
-
-SET_HEADER(BUNDLE_SYMBOLICNAME "apache_celix_remote_service_admin_dfi_tst_bundle")
-SET(BUNDLE_VERSION "0.0.1")
-SET_HEADERS("Bundle-Name: Apache Celix Remote Service Admin DFI test bundle")
-
-
-bundle(rsa_dfi_tst_bundle
-    SOURCES
-        tst_activator.c
-
-    FILES
-        ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
-)
-target_link_libraries(rsa_dfi_tst_bundle ${CPPUTEST_LIBRARY} celix_framework celix_utils)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c b/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c
deleted file mode 100644
index 728030e..0000000
--- a/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Licensed under Apache License v2. See LICENSE for more information.
- */
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <service_tracker_customizer.h>
-#include <service_tracker.h>
-
-#include "bundle_activator.h"
-#include "bundle_context.h"
-#include "service_registration.h"
-#include "service_reference.h"
-#include "celix_errno.h"
-
-#include "tst_service.h"
-#include "calculator_service.h"
-
-
-struct activator {
-	bundle_context_pt context;
-	struct tst_service serv;
-	service_registration_pt  reg;
-
-	service_tracker_customizer_pt cust;
-	service_tracker_pt tracker;
-	calculator_service_pt calc;
-};
-
-static celix_status_t addCalc(void * handle, service_reference_pt reference, void * service);
-static celix_status_t removeCalc(void * handle, service_reference_pt reference, void * service);
-static int test(void *handle);
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **out) {
-	celix_status_t status = CELIX_SUCCESS;
-	struct activator *act = calloc(1, sizeof(*act));
-	if (act != NULL) {
-		act->context = context;
-		act->serv.handle = act;
-		act->serv.test = test;
-
-		status = serviceTrackerCustomizer_create(act, NULL, addCalc, NULL, removeCalc, &act->cust);
-		status = CELIX_DO_IF(status, serviceTracker_create(context, CALCULATOR2_SERVICE, act->cust, &act->tracker));
-
-	} else {
-		status = CELIX_ENOMEM;
-	}
-
-	if (status == CELIX_SUCCESS) {
-		*out = act;
-	} else if (act != NULL) {
-		if (act->cust != NULL) {
-			free(act->cust);
-			act->cust = NULL;
-		}
-		if (act->tracker != NULL) {
-			serviceTracker_destroy(act->tracker);
-			act->tracker = NULL;
-		}
-		free(act);
-	}
-
-	return CELIX_SUCCESS;
-}
-
-static celix_status_t addCalc(void * handle, service_reference_pt reference, void * service) {
-	celix_status_t status = CELIX_SUCCESS;
-	struct activator * act = handle;
-	act->calc = service;
-	return status;
-}
-
-static celix_status_t removeCalc(void * handle, service_reference_pt reference, void * service) {
-	celix_status_t status = CELIX_SUCCESS;
-	struct activator * act = handle;
-	if (act->calc == service) {
-		act->calc = NULL;
-	}
-	return status;
-
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
-    celix_status_t status = CELIX_SUCCESS;
-	struct activator * act = userData;
-
-	act->reg = NULL;
-	status = bundleContext_registerService(context, (char *)TST_SERVICE_NAME, &act->serv, NULL, &act->reg);
-
-	status = CELIX_DO_IF(status, serviceTracker_open(act->tracker));
-
-
-	return status;
-}
-
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
-    celix_status_t status = CELIX_SUCCESS;
-	struct activator * act = userData;
-
-	status = serviceRegistration_unregister(act->reg);
-	status = CELIX_DO_IF(status, serviceTracker_close(act->tracker));
-
-	return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
-	struct activator *act = userData;
-	if (act != NULL) {
-		if (act->tracker != NULL) {
-			serviceTracker_destroy(act->tracker);
-			act->tracker = NULL;
-		}
-		free(act);
-	}
-	return CELIX_SUCCESS;
-}
-
-static int test(void *handle) {
-	int status = 0;
-	struct activator *act = handle;
-
-	double result = 0.0;
-
-    int rc;
-    if (act->calc != NULL) {
-         rc = act->calc->sqrt(act->calc->calculator, 4, &result);
-        printf("calc result is %d\n", result);
-    } else {
-        printf("calc not ready\n");
-    }
-
-	if (rc != 0 || result != 2.0) {
-		status = 1;
-	}
-	return status;
-}

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h b/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h
deleted file mode 100644
index 2678b0c..0000000
--- a/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Licensed under Apache License v2. See LICENSE for more information.
- */
-
-#ifndef CELIX_TST_SERVICE_H
-#define CELIX_TST_SERVICE_H
-
-#define TST_SERVICE_NAME "tst_service"
-
-struct tst_service {
-    void *handle;
-    int (*test)(void *handle);
-};
-
-typedef struct tst_service *tst_service_pt;
-
-#endif //CELIX_TST_SERVICE_H

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/tst/client.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/client.properties.in b/remote_services/remote_service_admin_dfi/tst/client.properties.in
deleted file mode 100644
index a9a06fb..0000000
--- a/remote_services/remote_service_admin_dfi/tst/client.properties.in
+++ /dev/null
@@ -1,8 +0,0 @@
-cosgi.auto.start.1=@rsa_bundle_file@ @calculator_shell_bundle_file@ @discovery_configured_bundle_file@ @topology_manager_bundle_file@ @tst_bundle_file@
-LOGHELPER_ENABLE_STDOUT_FALLBACK=true
-RSA_PORT=50881
-DISCOVERY_CFG_SERVER_PORT=50991
-DISCOVERY_CFG_POLL_ENDPOINTS=http://127.0.0.1:50992/org.apache.celix.discovery.configured
-org.osgi.framework.storage.clean=onFirstInit
-org.osgi.framework.storage=.cacheClient
-DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/tst/config.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/config.properties.in b/remote_services/remote_service_admin_dfi/tst/config.properties.in
deleted file mode 100644
index 8412214..0000000
--- a/remote_services/remote_service_admin_dfi/tst/config.properties.in
+++ /dev/null
@@ -1,3 +0,0 @@
-cosgi.auto.start.1=@rsa_bundle_file@ @calc_bundle_file@
-LOGHELPER_ENABLE_STDOUT_FALLBACK=true
-org.osgi.framework.storage.clean=onFirstInit
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp b/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp
deleted file mode 100644
index 35beffe..0000000
--- a/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed under Apache License v2. See LICENSE for more information.
- */
-#include <CppUTest/TestHarness.h>
-#include <remote_constants.h>
-#include <constants.h>
-#include <tst_service.h>
-#include "CppUTest/CommandLineTestRunner.h"
-#include "../../examples/calculator_service/public/include/calculator_service.h"
-
-extern "C" {
-
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <unistd.h>
-
-#include "launcher.h"
-#include "framework.h"
-#include "remote_service_admin.h"
-#include "calculator_service.h"
-
-    static framework_pt serverFramework = NULL;
-    static bundle_context_pt serverContext = NULL;
-
-    static framework_pt clientFramework = NULL;
-    static bundle_context_pt clientContext = NULL;
-
-    static void setupFm(void) {
-        int rc = 0;
-        bundle_pt bundle = NULL;
-
-        //server
-        rc = celixLauncher_launch("server.properties", &serverFramework);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-
-        bundle = NULL;
-        rc = framework_getFrameworkBundle(serverFramework, &bundle);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-
-        rc = bundle_getContext(bundle, &serverContext);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-
-
-        //client
-        rc = celixLauncher_launch("client.properties", &clientFramework);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-
-        bundle = NULL;
-        rc = framework_getFrameworkBundle(clientFramework, &bundle);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-
-        rc = bundle_getContext(bundle, &clientContext);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-    }
-
-    static void teardownFm(void) {
-        int rc = 0;
-
-        celixLauncher_stop(serverFramework);
-        celixLauncher_waitForShutdown(serverFramework);
-        celixLauncher_destroy(serverFramework);
-
-        celixLauncher_stop(clientFramework);
-        celixLauncher_waitForShutdown(clientFramework);
-        celixLauncher_destroy(clientFramework);
-
-        serverContext = NULL;
-        serverFramework = NULL;
-        clientContext = NULL;
-        clientFramework = NULL;
-    }
-
-    static void test1(void) {
-        int rc = 0;
-        service_reference_pt ref = NULL;
-        tst_service_pt tst = NULL;
-
-        usleep(2000000); //TODO use tracker
-
-        bundleContext_getServiceReference(clientContext, (char *)TST_SERVICE_NAME, &ref);
-        CHECK_EQUAL(0, rc);
-        CHECK(ref != NULL);
-
-        bundleContext_getService(clientContext, ref, (void **)&tst);
-        CHECK_EQUAL(0, rc);
-        CHECK(tst != NULL);
-
-        rc = tst->test(tst->handle);
-        CHECK_EQUAL(0, rc);
-
-        bundleContext_ungetService(clientContext, ref, NULL);
-        bundleContext_ungetServiceReference(clientContext, ref);
-    }
-
-}
-
-
-TEST_GROUP(RsaDfiClientServerTests) {
-    void setup() {
-        setupFm();
-    }
-
-    void teardown() {
-        teardownFm();
-    }
-};
-
-TEST(RsaDfiClientServerTests, Test1) {
-    test1();
-}

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp b/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
deleted file mode 100644
index 1384573..0000000
--- a/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Licensed under Apache License v2. See LICENSE for more information.
- */
-#include <CppUTest/TestHarness.h>
-#include <remote_constants.h>
-#include <constants.h>
-#include "CppUTest/CommandLineTestRunner.h"
-#include "../../examples/calculator_service/public/include/calculator_service.h"
-
-extern "C" {
-
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "launcher.h"
-#include "framework.h"
-#include "remote_service_admin.h"
-#include "calculator_service.h"
-
-
-    static framework_pt framework = NULL;
-    static bundle_context_pt context = NULL;
-
-    static service_reference_pt rsaRef = NULL;
-    static remote_service_admin_service_pt rsa = NULL;
-
-    static service_reference_pt calcRef = NULL;
-    static calculator_service_pt calc = NULL;
-
-    static void setupFm(void) {
-        int rc = 0;
-
-        rc = celixLauncher_launch("config.properties", &framework);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-
-        bundle_pt bundle = NULL;
-        rc = framework_getFrameworkBundle(framework, &bundle);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-
-        rc = bundle_getContext(bundle, &context);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-
-        rc = bundleContext_getServiceReference(context, (char *)OSGI_RSA_REMOTE_SERVICE_ADMIN, &rsaRef);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-        CHECK(rsaRef != NULL);
-
-        rc = bundleContext_getService(context, rsaRef, (void **)&rsa);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-
-        rc = bundleContext_getServiceReference(context, (char *)CALCULATOR2_SERVICE, &calcRef);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-        CHECK(calcRef != NULL);
-
-        rc = bundleContext_getService(context, calcRef, (void **)&calc);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-    }
-
-    static void teardownFm(void) {
-        int rc = 0;
-        rc = bundleContext_ungetService(context, rsaRef, NULL);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-
-        rc = bundleContext_ungetService(context, calcRef, NULL);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-
-        celixLauncher_stop(framework);
-        celixLauncher_waitForShutdown(framework);
-        celixLauncher_destroy(framework);
-
-        rsaRef = NULL;
-        rsa = NULL;
-        calcRef = NULL;
-        calc = NULL;
-        context = NULL;
-        framework = NULL;
-    }
-
-    static void testServices(void) {
-        int rc = 0;
-        array_list_pt exported = NULL;
-        array_list_pt imported = NULL;
-        arrayList_create(&exported);
-        arrayList_create(&imported);
-
-        rc = rsa->getExportedServices(rsa->admin, &exported);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-        CHECK_EQUAL(0, arrayList_size(exported));
-
-        rc = rsa->getImportedEndpoints(rsa->admin, &imported);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-        CHECK_EQUAL(0, arrayList_size(imported));
-
-        double result = 0;
-        rc = calc->add(calc->calculator, 2.0, 5.0, &result);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-        CHECK_EQUAL(7.0, result);
-    }
-
-    static void testExportService(void) {
-        int rc = 0;
-        char *calcId = NULL;
-        array_list_pt regs = NULL;
-
-        rc = arrayList_create(&regs);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-
-        rc = serviceReference_getProperty(calcRef, (char *)"service.id", &calcId);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-
-        rc = rsa->exportService(rsa->admin, calcId, NULL, &regs);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-
-        CHECK_EQUAL(1, arrayList_size(regs));
-    }
-
-    static void testImportService(void) {
-        int rc = 0;
-        import_registration_pt reg = NULL;
-        endpoint_description_pt endpoint = NULL;
-
-        properties_pt props = properties_create();
-        properties_set(props, (char *)OSGI_RSA_ENDPOINT_SERVICE_ID, (char *)"42");
-        properties_set(props, (char *)OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42");
-        properties_set(props, (char *)OSGI_RSA_ENDPOINT_ID, (char *)"eec5404d-51d0-47ef-8d86-c825a8beda42-42");
-        properties_set(props, (char *)OSGI_FRAMEWORK_OBJECTCLASS,(char *)"org.apache.celix.Example");
-
-        rc = endpointDescription_create(props, &endpoint);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-
-        rc = rsa->importService(rsa->admin, endpoint, &reg);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-        CHECK(reg != NULL);
-
-        service_reference_pt ref = NULL;
-        rc = bundleContext_getServiceReference(context, (char *)"org.apache.celix.Example", &ref);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-        CHECK(ref != NULL);
-
-        /* Cannot test. uses requesting bundles descriptor
-        void *service = NULL;
-        rc = bundleContext_getService(context, ref, &service);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
-        CHECK(service != NULL);
-         */
-    }
-
-    static void testBundles(void) {
-        array_list_pt bundles = NULL;
-
-        int rc = bundleContext_getBundles(context, &bundles);
-        CHECK_EQUAL(0, rc);
-        CHECK_EQUAL(3, arrayList_size(bundles)); //framework, rsa_dfi & calc
-
-        /*
-        int size = arrayList_size(bundles);
-        int i;
-        for (i = 0; i < size; i += 1) {
-            bundle_pt bundle = NULL;
-            module_pt module = NULL;
-            char *name = NULL;
-
-            bundle = (bundle_pt) arrayList_get(bundles, i);
-            bundle_getCurrentModule(bundle, &module);
-            module_getSymbolicName(module, &name);
-            printf("got bundle with symbolic name '%s'", name);
-        }*/
-
-        arrayList_destroy(bundles);
-    }
-
-}
-
-
-TEST_GROUP(RsaDfiTests) {
-    void setup() {
-        setupFm();
-    }
-
-    void teardown() {
-        teardownFm();
-    }
-};
-
-TEST(RsaDfiTests, InfoTest) {
-    testServices();
-}
-
-TEST(RsaDfiTests, ExportService) {
-    testExportService();
-}
-
-TEST(RsaDfiTests, ImportService) {
-    testImportService();
-}
-
-TEST(RsaDfiTests, TestBundles) {
-    testBundles();
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/run_tests.cpp b/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
deleted file mode 100644
index c5e960c..0000000
--- a/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-/*
- * 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);
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/remote_service_admin_dfi/tst/server.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/server.properties.in b/remote_services/remote_service_admin_dfi/tst/server.properties.in
deleted file mode 100644
index ea02519..0000000
--- a/remote_services/remote_service_admin_dfi/tst/server.properties.in
+++ /dev/null
@@ -1,8 +0,0 @@
-cosgi.auto.start.1=@rsa_bundle_file@ @calc_bundle_file@ @discovery_configured_bundle_file@ @topology_manager_bundle_file@
-LOGHELPER_ENABLE_STDOUT_FALLBACK=true
-RSA_PORT=50882
-DISCOVERY_CFG_SERVER_PORT=50992
-DISCOVERY_CFG_POLL_ENDPOINTS=http://127.0.0.1:50991/org.apache.celix.discovery.configured
-org.osgi.framework.storage.clean=onFirstInit
-org.osgi.framework.storage=.cacheServer
-DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/a129b488/remote_services/utils/public/include/remote_constants.h
----------------------------------------------------------------------
diff --git a/remote_services/utils/public/include/remote_constants.h b/remote_services/utils/public/include/remote_constants.h
deleted file mode 100644
index 0736685..0000000
--- a/remote_services/utils/public/include/remote_constants.h
+++ /dev/null
@@ -1,38 +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_constants.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_CONSTANTS_H_
-#define REMOTE_CONSTANTS_H_
-
-static const char * const OSGI_RSA_SERVICE_EXPORTED_INTERFACES = "service.exported.interfaces";
-static const char * const OSGI_RSA_ENDPOINT_FRAMEWORK_UUID = "endpoint.framework.uuid";
-static const char * const OSGI_RSA_ENDPOINT_SERVICE_ID = "endpoint.service.id";
-static const char * const OSGI_RSA_ENDPOINT_ID = "endpoint.id";
-static const char * const OSGI_RSA_SERVICE_IMPORTED = "service.imported";
-static const char * const OSGI_RSA_SERVICE_IMPORTED_CONFIGS = "service.imported.configs";
-static const char * const OSGI_RSA_SERVICE_LOCATION = "service.location";
-
-#endif /* REMOTE_CONSTANTS_H_ */


[42/50] [abbrv] celix git commit: CELIX-237: Fixed small memory leak when methods return not 0

Posted by pn...@apache.org.
CELIX-237: Fixed small memory leak when methods return not 0


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

Branch: refs/heads/develop
Commit: 3f71ac4a950bc8cca8542ecc770247089d7022bc
Parents: 8248c2c
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Sep 23 16:21:55 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Sep 23 16:21:55 2015 +0200

----------------------------------------------------------------------
 .../dynamic_function_interface/json_rpc.c       | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/3f71ac4a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
index d4c8f30..01dc6b5 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
@@ -124,13 +124,19 @@ int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request, c
     }
 
     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) {
+            //TODO SOMETIMES segfault 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__STD) {
-                dynType_free(argType, args[i]);
-            } else if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
+            if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
                 if (status == OK) {
                     status = jsonSerializer_serializeJson(argType, args[i], &jsonResult);
                 }
@@ -162,8 +168,12 @@ int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request, c
         LOG_DEBUG("creating payload\n");
         json_t *payload = json_object();
         if (funcCallStatus == 0) {
-            LOG_DEBUG("Setting result payload");
-            json_object_set_new(payload, "r", jsonResult);
+            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));


[50/50] [abbrv] celix git commit: CELIX-237: Merge remote-tracking branch 'remotes/origin/feature/CELIX-237_rsa-ffi' into develop

Posted by pn...@apache.org.
CELIX-237: Merge remote-tracking branch 'remotes/origin/feature/CELIX-237_rsa-ffi' into develop

Conflicts:
	.travis.yml


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

Branch: refs/heads/develop
Commit: 093d2dfa7c7f0cf83ddcb96bc3cf3817747da17f
Parents: 4ee2e7f 8689fc1
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Oct 13 12:20:39 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Oct 13 12:20:39 2015 +0200

----------------------------------------------------------------------
 .gitignore                                      |    3 +
 .travis.yml                                     |   25 +-
 CMakeLists.txt                                  |    7 +-
 LICENSE                                         |   26 +-
 cmake/CMakeCelix.cmake                          |    2 +-
 cmake/FindCppUTest.cmake                        |   34 +-
 cmake/FindFFI.cmake                             |   54 +
 cmake/cmake_celix/Test.cmake                    |   52 -
 framework/CMakeLists.txt                        |   54 +-
 framework/private/src/celix_launcher.c          |  190 +++
 framework/private/src/celix_log.c               |    5 +-
 framework/private/src/framework.c               |   14 +-
 framework/private/src/properties.c              |   13 +-
 framework/private/src/service_registration.c    |    5 +-
 framework/private/src/service_registry.c        |    2 +-
 framework/public/include/celix_launcher.h       |   41 +
 framework/public/include/properties.h           |    3 +
 launcher/CMakeLists.txt                         |   10 +-
 launcher/private/src/launcher.c                 |  204 ----
 launcher/private/src/main.c                     |   88 ++
 log_service/private/src/log_factory.c           |    2 +-
 remote_services/CMakeLists.txt                  |   11 +-
 .../private/src/endpoint_discovery_poller.c     |    3 +
 .../public/include/endpoint_listener.h          |   48 -
 .../private/src/calculator_proxy_impl.c         |    2 +-
 .../examples/calculator_service/CMakeLists.txt  |    5 +-
 .../public/include/calculator_service.h         |    6 +-
 ...apache.celix.calc.api.Calculator2.descriptor |   11 +
 .../examples/calculator_shell/CMakeLists.txt    |    4 +
 .../calculator_shell/private/src/add_command.c  |    2 +-
 .../calculator_shell/private/src/sqrt_command.c |    2 +-
 .../calculator_shell/private/src/sub_command.c  |    2 +-
 remote_services/examples/deploy.cmake           |    4 +-
 .../remote_service_admin/CMakeLists.txt         |    6 +-
 .../private/include/export_registration_impl.h  |    3 -
 .../private/include/remote_service_admin_impl.h |   17 -
 .../private/src/export_registration_impl.c      |   22 +-
 .../private/src/import_registration_impl.c      |   17 +
 .../public/include/endpoint_listener.h          |   48 +
 .../public/include/export_registration.h        |   22 +
 .../public/include/import_registration.h        |   22 +
 .../public/include/remote_constants.h           |   38 +
 .../public/include/remote_service_admin.h       |    6 +-
 .../remote_service_admin_dfi/CMakeLists.txt     |   32 +
 .../dynamic_function_interface/CMakeLists.txt   |   22 +
 .../dynamic_function_interface/dfi_log_util.h   |   48 +
 .../dynamic_function_interface/dyn_common.c     |  136 +++
 .../dynamic_function_interface/dyn_common.h     |   32 +
 .../dynamic_function_interface/dyn_function.c   |  320 +++++
 .../dynamic_function_interface/dyn_function.h   |   46 +
 .../dynamic_function_interface/dyn_interface.c  |  405 +++++++
 .../dynamic_function_interface/dyn_interface.h  |   48 +
 .../dynamic_function_interface/dyn_type.c       | 1129 ++++++++++++++++++
 .../dynamic_function_interface/dyn_type.h       |  142 +++
 .../dynamic_function_interface/json_rpc.c       |  287 +++++
 .../dynamic_function_interface/json_rpc.h       |   22 +
 .../json_serializer.c                           |  452 +++++++
 .../json_serializer.h                           |   22 +
 .../memstream/README.md                         |   49 +
 .../memstream/fmemopen.c                        |   78 ++
 .../memstream/fmemopen.h                        |   52 +
 .../memstream/open_memstream.c                  |  130 ++
 .../memstream/open_memstream.h                  |   15 +
 .../CMakeLists.txt                              |   27 +
 .../avro_descriptor_translator_tests.cpp        |  164 +++
 .../descriptors/example1.descriptor             |   13 +
 .../descriptors/example2.descriptor             |    9 +
 .../descriptors/example3.descriptor             |   11 +
 .../dyn_closure_tests.cpp                       |  146 +++
 .../dyn_function_tests.cpp                      |  236 ++++
 .../dyn_interface_tests.cpp                     |  103 ++
 .../dyn_type_tests.cpp                          |  281 +++++
 .../json_rpc_tests.cpp                          |  329 +++++
 .../json_serializer_tests.cpp                   |  435 +++++++
 .../run_tests.cpp                               |    9 +
 .../schemas/complex.avdl                        |   11 +
 .../schemas/complex.avpr                        |   36 +
 .../schemas/invalid1.avpr                       |   29 +
 .../schemas/invalid2.avpr                       |   31 +
 .../schemas/simple.avdl                         |    6 +
 .../schemas/simple.avpr                         |   33 +
 .../schemas/simple_min.avpr                     |    1 +
 .../remote_service_admin_dfi/rsa/CMakeLists.txt |   47 +
 .../private/include/export_registration_dfi.h   |   21 +
 .../private/include/import_registration_dfi.h   |   26 +
 .../private/include/remote_service_admin_dfi.h  |   56 +
 .../rsa/private/src/export_registration_dfi.c   |  222 ++++
 .../rsa/private/src/import_registration_dfi.c   |  352 ++++++
 .../src/remote_service_admin_activator.c        |  124 ++
 .../rsa/private/src/remote_service_admin_dfi.c  |  737 ++++++++++++
 .../rsa_tst/CMakeLists.txt                      |   45 +
 .../rsa_tst/bundle/CMakeLists.txt               |   24 +
 .../rsa_tst/bundle/tst_activator.c              |  137 +++
 .../rsa_tst/bundle/tst_service.h                |   17 +
 .../rsa_tst/client.properties.in                |    8 +
 .../rsa_tst/config.properties.in                |    3 +
 .../rsa_tst/rsa_client_server_tests.cpp         |  113 ++
 .../rsa_tst/rsa_tests.cpp                       |  201 ++++
 .../rsa_tst/run_tests.cpp                       |    9 +
 .../rsa_tst/server.properties.in                |    8 +
 .../private/src/remote_service_admin_impl.c     |  129 +-
 .../private/src/remote_service_admin_impl.c     |   26 +-
 .../private/src/topology_manager.c              |  104 +-
 .../utils/public/include/remote_constants.h     |   38 -
 utils/CMakeLists.txt                            |    4 +-
 105 files changed, 8366 insertions(+), 597 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/093d2dfa/.travis.yml
----------------------------------------------------------------------
diff --cc .travis.yml
index f742f21,3ecdf5c..0a9a4b5
--- a/.travis.yml
+++ b/.travis.yml
@@@ -2,28 -2,28 +2,35 @@@ language: 
  
  before_install:
    - sudo apt-get update -qq
-   - sudo apt-get install -y uuid-dev libjansson-dev libxml2-dev lcov
- 
 -  - sudo apt-get install -y uuid-dev libxml2-dev libffi-dev lcov
++  - sudo apt-get install -y uuid-dev libjansson-dev libxml2-dev lcov libffi-dev
  
  matrix:
    include:
      - compiler: gcc
      - compiler: clang
  
- before_script: 
-     - wget https://github.com/cpputest/cpputest.github.io/blob/master/releases/cpputest-3.7.1.tar.gz?raw=true -O /tmp/cpputest.tar.gz
-     - tar -xzvf /tmp/cpputest.tar.gz -C /tmp 
-     - if [ "$CC" = "clang" ]; then export CXX="clang++"; fi && cd /tmp/cpputest-3.7.1 && ./configure --prefix=$HOME/cpputest && make && make install && cd -
+ before_script:  
+     - git clone -b 3.7.2 --single-branch https://github.com/cpputest/cpputest.git cpputest-build
+     - cd cpputest-build
+     - cmake . && make
+     - sudo make install 
+     - cd ..
+     - git clone -b 2.7 --single-branch https://github.com/akheron/jansson.git jansson-build
+     - cd jansson-build
+     - cmake -DJANSSON_BUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=/usr . && make
+     - sudo make install
+     - cd ..
      - mkdir build install
- 
- script: 
      - cd build
-     - cmake -DBUILD_DEPLOYMENT_ADMIN=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 -DBUILD_UTILS-TESTS=ON -DCPPUTEST_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_LIBRARY=$HOME/cpputest/lib/libCppUTest.a -DCPPUTEST_EXT_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_EXT_LIBRARY=$HOME/cpputest/lib/libCppUTestExt.a -DENABLE_CODE_COVERAGE=ON -DCMAKE_INSTALL_PREFIX=../install ..
 -    - cmake -DENABLE_TESTING=ON -DCMAKE_SKIP_BUILD_RPATH=TRUE -DBUILD_DEPLOYMENT_ADMIN=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 -DCMAKE_INSTALL_PREFIX=../install ..
++    - cmake -DBUILD_DEPLOYMENT_ADMIN=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 -DBUILD_UTILS-TESTS=ON -DCPPUTEST_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_LIBRARY=$HOME/cpputest/lib/libCppUTest.a -DCPPUTEST_EXT_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_EXT_LIBRARY=$HOME/cpputest/lib/libCppUTestExt.a -DENABLE_CODE_COVERAGE=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN DFI=ON -DCMAKE_INSTALL_PREFIX=../install ..
 +    - make all && make deploy && make install-all
 +    - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/utils:`pwd`/framework && make test && make coverage
 +
 +after_success:
 +    - cd ${TRAVIS_BUILD_DIR}/build
 +    - gem install coveralls-lcov
 +    - lcx="lcov --output-file=coverage.info " && for i in `find . -name "*.info.cleaned"`; do lcx+=" --add-tracefile=$i"; done && $lcx && coveralls-lcov --repo-token=9dpeTAjiGoQU5hgXFe0ezk65iu40oc3WY coverage.info
  
+ script: 
+     - make all 
+     - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/utils && make test ARGS="-V"

http://git-wip-us.apache.org/repos/asf/celix/blob/093d2dfa/CMakeLists.txt
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/celix/blob/093d2dfa/framework/private/src/framework.c
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/celix/blob/093d2dfa/remote_services/discovery/private/src/endpoint_discovery_poller.c
----------------------------------------------------------------------


[07/50] [abbrv] celix git commit: CELIX-237: Small update for launcher + rsa test setup

Posted by pn...@apache.org.
CELIX-237: Small update for launcher + rsa test setup


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

Branch: refs/heads/develop
Commit: 87f3fabf7f7e97140877faee73c5948319bcbaa7
Parents: 4e3be10
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Sat Aug 1 21:51:05 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Sat Aug 1 21:51:05 2015 +0200

----------------------------------------------------------------------
 launcher/private/src/launcher.c                 | 11 ---
 launcher/private/src/main.c                     | 10 +++
 .../remote_service_admin_dfi/tst/rsa_tests.cpp  | 75 ++++++++++++++++++--
 .../remote_service_admin_dfi/tst/run_tests.cpp  |  5 +-
 4 files changed, 81 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/87f3fabf/launcher/private/src/launcher.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/launcher.c b/launcher/private/src/launcher.c
index 4f0f3de..9c021ed 100644
--- a/launcher/private/src/launcher.c
+++ b/launcher/private/src/launcher.c
@@ -37,8 +37,6 @@
 #include "framework.h"
 #include "linked_list_iterator.h"
 
-static void launcher_shutdown(int signal);
-
 static struct framework * framework;
 static properties_pt config;
 
@@ -77,8 +75,6 @@ int celixLauncher_launchWithStream(FILE *stream) {
     apr_status_t s;
 #endif
 
-    (void) signal(SIGINT, launcher_shutdown);
-
     // Before doing anything else, let's setup Curl
     curl_global_init(CURL_GLOBAL_NOTHING);
 
@@ -193,10 +189,3 @@ struct framework *celixLauncher_getFramework(void) {
     return framework;
 }
 
-static void launcher_shutdown(int signal) {
-    celixLauncher_stop();
-//	if (framework_waitForStop(framework) != CELIX_SUCCESS) {
-//		celix_log("Error waiting for stop.");
-//	}
-//	framework_destroy(framework);
-}

http://git-wip-us.apache.org/repos/asf/celix/blob/87f3fabf/launcher/private/src/main.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/main.c b/launcher/private/src/main.c
index b6d3033..00b08bd 100644
--- a/launcher/private/src/main.c
+++ b/launcher/private/src/main.c
@@ -27,13 +27,18 @@
 #include <string.h>
 #include <curl/curl.h>
 #include <signal.h>
+#include <libgen.h>
 #include "launcher.h"
 
 static void show_usage(char* prog_name);
+static void shutdownCelix(int signal);
 
 #define DEFAULT_CONFIG_FILE "config.properties"
 
 int main(int argc, char *argv[]) {
+
+    (void) signal(SIGINT, shutdownCelix);
+
     // Perform some minimal command-line option parsing...
     char *opt = NULL;
     if (argc > 1) {
@@ -61,3 +66,8 @@ int main(int argc, char *argv[]) {
 static void show_usage(char* prog_name) {
     printf("Usage:\n  %s [path/to/config.properties]\n\n", basename(prog_name));
 }
+
+static void shutdownCelix(int signal) {
+    celixLauncher_stop();
+}
+

http://git-wip-us.apache.org/repos/asf/celix/blob/87f3fabf/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp b/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
index b9206da..a5a556a 100644
--- a/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/tst/rsa_tests.cpp
@@ -14,13 +14,62 @@ extern "C" {
 
 #include "launcher.h"
 #include "framework.h"
+#include "remote_service_admin.h"
 
 
-static void testFindRsaService(void) {
+bundle_context_pt context = NULL;
+service_reference_pt rsaRef = NULL;
+remote_service_admin_service_pt rsa = NULL;
+
+static void setupContextAndRsa(void) {
+    int rc = 0;
     struct framework *fm = celixLauncher_getFramework();
-    CHECK(fm != NULL);
 
-    //TODO get framework bundle context. lookup service -> test service
+    bundle_pt bundle = NULL;
+    rc = framework_getFrameworkBundle(fm, &bundle);
+    CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+    rc = bundle_getContext(bundle, &context);
+    CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+    rc = bundleContext_getServiceReference(context, (char *)OSGI_RSA_REMOTE_SERVICE_ADMIN, &rsaRef);
+    CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+    rc = bundleContext_getService(context, rsaRef, (void **)&rsa);
+    CHECK_EQUAL(CELIX_SUCCESS, rc);
+}
+
+static void teardownContextAndRsa(void) {
+    int rc = 0;
+    rc = bundleContext_ungetService(context, rsaRef, NULL);
+    CHECK_EQUAL(CELIX_SUCCESS, rc);
+    rsaRef = NULL;
+    rsa = NULL;
+    context = NULL;
+}
+
+static void testInfo(void) {
+    int rc = 0;
+    array_list_pt exported = NULL;
+    array_list_pt imported = NULL;
+    arrayList_create(&exported);
+    arrayList_create(&imported);
+
+    rc = rsa->getExportedServices(rsa->admin, &exported);
+    CHECK_EQUAL(CELIX_SUCCESS, rc);
+    CHECK_EQUAL(0, arrayList_size(exported));
+
+    rc = rsa->getImportedEndpoints(rsa->admin, &imported);
+    CHECK_EQUAL(CELIX_SUCCESS, rc);
+    CHECK_EQUAL(0, arrayList_size(imported));
+}
+
+static void testExportService(void) {
+    //TODO
+}
+
+static void testImportService(void) {
+    //TODO
 }
 
 }
@@ -28,9 +77,25 @@ static void testFindRsaService(void) {
 
 TEST_GROUP(RsaDfiTests) {
     void setup() {
+        celixLauncher_launch("config.properties");
+        setupContextAndRsa();
+    }
+
+    void teardown() {
+        teardownContextAndRsa();
+        celixLauncher_stop();
+        celixLauncher_waitForShutdown();
     }
 };
 
-TEST(RsaDfiTests, FindRsaService) {
-    testFindRsaService();
+TEST(RsaDfiTests, InfoTest) {
+    testInfo();
+}
+
+TEST(RsaDfiTests, ExportService) {
+    testExportService();
+}
+
+TEST(RsaDfiTests, ImportService) {
+    testImportService();
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/87f3fabf/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/run_tests.cpp b/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
index dedb70a..81d1908 100644
--- a/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/tst/run_tests.cpp
@@ -22,8 +22,5 @@ extern "C" {
 }
 
 int main(int argc, char** argv) {
-    startCelix();
-    int rc = RUN_ALL_TESTS(argc, argv);
-    stopCelix();
-    return rc;
+    return RUN_ALL_TESTS(argc, argv);
 }
\ No newline at end of file


[36/50] [abbrv] celix git commit: CELIX-237: Added support for '/' in method id.

Posted by pn...@apache.org.
CELIX-237: Added support for '/' in method id.


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

Branch: refs/heads/develop
Commit: 313452d347929c9faa9badbc42474955ce1fc99d
Parents: c647773
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Sep 11 14:48:16 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Fri Sep 11 14:48:16 2015 +0200

----------------------------------------------------------------------
 .../dynamic_function_interface/dyn_interface.c                   | 2 +-
 .../dynamic_function_interface/json_serializer.c                 | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/313452d3/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
index ab436b7..d869d16 100644
--- 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
@@ -256,7 +256,7 @@ static int dynInterface_parseMethods(dyn_interface_type *intf, FILE *stream) {
         ungetc(peek, stream);
 
         char *id;
-        status = dynCommon_parseNameAlsoAccept(stream, "();[{}", &id);
+        status = dynCommon_parseNameAlsoAccept(stream, "();[{}/", &id);
 
         if (status == OK) {
             status = dynCommon_eatChar(stream, '=');

http://git-wip-us.apache.org/repos/asf/celix/blob/313452d3/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
index aaf5cc3..0fb07fc 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
@@ -215,7 +215,7 @@ static int jsonSerializer_parseSequence(dyn_type *seq, json_t *array, void *seqL
     int status = OK;
 
     size_t size = json_array_size(array);
-    LOG_DEBUG("Allocating sequence with capacity %zu", size);
+    //LOG_DEBUG("Allocating sequence with capacity %zu", size);
     status = dynType_sequence_alloc(seq, seqLoc, (int) size);
 
     if (status == OK) {
@@ -225,7 +225,7 @@ static int jsonSerializer_parseSequence(dyn_type *seq, json_t *array, void *seqL
         json_array_foreach(array, index, val) {
             void *valLoc = NULL;
             status = dynType_sequence_increaseLengthAndReturnLastLoc(seq, seqLoc, &valLoc);
-            LOG_DEBUG("Got sequence loc %p", valLoc);
+            //LOG_DEBUG("Got sequence loc %p", valLoc);
 
             if (status == OK) {
                 status = jsonSerializer_parseAny(itemType, valLoc, val);


[13/50] [abbrv] celix git commit: CELIX-237: Implemented client server test and needed changes to get that working. There is still an issue in the export_registration

Posted by pn...@apache.org.
CELIX-237: Implemented client server test and needed changes to get that working. There is still an issue in the export_registration


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

Branch: refs/heads/develop
Commit: 7dc2039f11b6fc3505ce2677ad2a59bfdb423d1f
Parents: fa52720
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Aug 11 20:18:15 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Aug 11 20:18:15 2015 +0200

----------------------------------------------------------------------
 launcher/private/src/main.c                     |   8 +-
 remote_services/CMakeLists.txt                  |   1 +
 .../remote_service_admin_dfi/CMakeLists.txt     |   2 +-
 .../dynamic_function_interface/dyn_function.c   |   2 +
 .../dynamic_function_interface/dyn_type.c       |  16 +--
 .../json_serializer.c                           |   6 +-
 .../json_serializer.h                           |   1 +
 .../tst/dyn_function_tests.cpp                  |   7 +-
 .../private/include/import_registration_dfi.h   |   5 +
 .../private/src/export_registration_dfi.c       |  81 ++++++++---
 .../private/src/import_registration_dfi.c       | 135 ++++++++++++++++---
 .../private/src/remote_service_admin_dfi.c      |  38 ++----
 .../remote_service_admin_dfi/tst/CMakeLists.txt |   4 +-
 .../tst/bundle/CMakeLists.txt                   |   5 +
 .../tst/bundle/tst_activator.c                  |  86 +++++++++---
 .../tst/bundle/tst_service.h                    |   2 +-
 .../tst/client.properties.in                    |   1 +
 .../tst/rsa_client_server_tests.cpp             |  19 +--
 .../tst/server.properties.in                    |   1 +
 19 files changed, 296 insertions(+), 124 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/launcher/private/src/main.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/main.c b/launcher/private/src/main.c
index 82530e1..90e5612 100644
--- a/launcher/private/src/main.c
+++ b/launcher/private/src/main.c
@@ -63,9 +63,11 @@ int main(int argc, char *argv[]) {
     // Set signal handler
     (void) signal(SIGINT, shutdown_framework);
 
-    celixLauncher_launch(config_file, &framework);
-    celixLauncher_waitForShutdown(framework);
-    celixLauncher_destroy(framework);
+    int rc = celixLauncher_launch(config_file, &framework);
+    if (rc == 0) {
+        celixLauncher_waitForShutdown(framework);
+        celixLauncher_destroy(framework);
+    }
 }
 
 static void show_usage(char* prog_name) {

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/remote_services/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/CMakeLists.txt b/remote_services/CMakeLists.txt
index abc9177..f39b604 100644
--- a/remote_services/CMakeLists.txt
+++ b/remote_services/CMakeLists.txt
@@ -39,6 +39,7 @@ if (REMOTE_SERVICE_ADMIN)
 
     add_subdirectory(remote_service_admin)
     add_subdirectory(remote_service_admin_http)
+    add_subdirectory(remote_service_admin_dfi/tst/bundle)
     add_subdirectory(remote_service_admin_dfi)
     add_subdirectory(remote_service_admin_shm)
 

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/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 b7a66f3..83dfc41 100644
--- a/remote_services/remote_service_admin_dfi/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/CMakeLists.txt
@@ -44,7 +44,7 @@ if (RSA_REMOTE_SERVICE_ADMIN_DFI)
     
     SET_HEADER(BUNDLE_SYMBOLICNAME "apache_celix_remote_service_admin_dfi")
     SET(BUNDLE_VERSION "0.0.1")
-    SET_HEADERS("Bundle-Name: Apache Celix Remote Service Admin HTTP for dynamic function interface")
+    SET_HEADERS("Bundle-Name: Apache Celix Remote Service Admin Dynamic Function Interface (DFI)")
     
     bundle(remote_service_admin_dfi SOURCES
         private/src/remote_service_admin_dfi.c

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/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
index f80d26f..af3902c 100644
--- 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
@@ -10,6 +10,7 @@
 #include <stdlib.h>
 
 #include <ffi.h>
+#include <ffi-x86_64.h>
 
 #include "dyn_common.h"
 #include "dyn_type.h"
@@ -222,6 +223,7 @@ int dynFunction_createClosure(dyn_function_type *dynFunc, void (*bind)(void *, v
     }
 
     if (status == 0) {
+        dynFunc->userData = userData;
         dynFunc->bind = bind;
         dynFunc->fn = fn;
         *out =fn;

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
index c8a9adb..e47fe6d 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
@@ -5,11 +5,6 @@
 
 #include <stdlib.h>
 #include <string.h>
-#include <stdio.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <string.h>
-#include <ctype.h>
 #include <assert.h>
 #include <errno.h>
 
@@ -763,6 +758,7 @@ static ffi_type * dynType_ffiTypeFor(int c) {
             break;
         case 'P' :
             type = &ffi_type_pointer;
+            break;
         case 'V' :
             type = &ffi_type_void;
             break;
@@ -864,16 +860,6 @@ int dynType_text_allocAndInit(dyn_type *type, void *textLoc, const char *value)
 
 
 
-
-
-
-
-
-
-
-
-
-
 void dynType_print(dyn_type *type, FILE *stream) {
     if (type != NULL) {
         dynType_printTypes(type, stream);

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
index c6bda91..cf9a0ee 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
@@ -237,7 +237,7 @@ int jsonSerializer_serialize(dyn_type *type, void *input, char **output) {
     int status = OK;
 
     json_t *root = NULL;
-    status = jsonSerializer_writeAny(type, input, &root);
+    status = jsonSerializer_serializeJson(type, input, &root);
 
     if (status == OK) {
         *output = json_dumps(root, JSON_COMPACT);
@@ -247,6 +247,10 @@ int jsonSerializer_serialize(dyn_type *type, void *input, char **output) {
     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;
 

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/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
index abfdd03..9999aea 100644
--- 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
@@ -15,5 +15,6 @@ 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/7dc2039f/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
index 868073b..006897c 100644
--- 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
@@ -128,7 +128,6 @@ extern "C" {
         CHECK_EQUAL(2.0, *b)
         CHECK_EQUAL(a, 2.0);
         *out = *b * a;
-        printf("out is %p and *out is %f\n", out, *out);
         return 0;
     }
 
@@ -140,8 +139,6 @@ extern "C" {
         CHECK_EQUAL(0, rc);
         double result = -1.0;
         double *input = &result;
-        printf("\n");
-        printf("input is %p, &input is %p and *input is %d\n", input, &input, *input);
         double a = 2.0;
         void *ptr = &a;
         void *args[3];
@@ -150,8 +147,8 @@ extern "C" {
         args[2] = &input;
         void (*fp)(void) = (void(*)(void)) testExample3;
 
-        rc = dynFunction_call(dynFunc, fp, &result, args);
-        printf("input is %p, &input is %p and *input is %d\n", input, &input, *input);
+        int rVal;
+        rc = dynFunction_call(dynFunc, fp, &rVal, args);
 
         CHECK_EQUAL(0, rc);
         CHECK_EQUAL(4.0, result);

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/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
index d05375d..ec885fd 100644
--- 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
@@ -8,9 +8,14 @@
 
 #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);
 

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/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
index 95d58b9..0713efb 100644
--- 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
@@ -7,7 +7,6 @@
 #include <remote_constants.h>
 #include "export_registration.h"
 #include "export_registration_dfi.h"
-#include "endpoint_description.h"
 
 struct export_reference {
     endpoint_description_pt endpoint; //owner
@@ -24,15 +23,17 @@ struct export_registration {
     bool closed;
 };
 
+typedef void (*gen_func_type)(void);
+
 struct generic_service_layout {
     void *handle;
-    void **methods;
+    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));
+    export_registration_pt reg = calloc(1, sizeof(*reg));
 
     if (reg == NULL) {
         status = CELIX_ENOMEM;
@@ -90,7 +91,7 @@ celix_status_t exportRegistration_create(log_helper_pt helper, service_reference
     return status;
 }
 
-celix_status_t exportRegistration_call(export_registration_pt export, char *data, int datalength, char **response, int *responseLength) {
+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
 
@@ -122,21 +123,26 @@ celix_status_t exportRegistration_call(export_registration_pt export, char *data
 
     if (method == NULL) {
         status = CELIX_ILLEGAL_STATE;
+    } else {
+        printf("RSA: found method '%s'\n", entry->id);
     }
 
     if (method != NULL) {
 
         int nrOfArgs = dynFunction_nrOfArguments(method->dynFunc);
-        void *args[nrOfArgs + 1]; //arg 0 is handle
-        dyn_type *returnType = dynFunction_returnType(method->dynFunc);
+        void *args[nrOfArgs]; //arg 0 is handle
 
         json_t *arguments = json_object_get(js_request, "a");
-        json_t *value;
-        size_t index;
+        json_t *value = NULL;
+        int index = -1;
         json_array_foreach(arguments, index, value) {
-            dyn_type *argType = dynFunction_argumentTypeForIndex(method->dynFunc, index + 1);
-            status = jsonSerializer_deserializeJson(argType, value, &(args[index + 1]));
-            index += 1;
+            int argNr = index + 1;
+            if (argNr < nrOfArgs -1 ) { //note skip last argument. this is the output
+                dyn_type *argType = dynFunction_argumentTypeForIndex(method->dynFunc, argNr);
+                status = jsonSerializer_deserializeJson(argType, value, &(args[argNr]));
+            } else {
+                status = CELIX_ILLEGAL_ARGUMENT;
+            }
             if (status != 0) {
                 break;
             }
@@ -144,21 +150,56 @@ celix_status_t exportRegistration_call(export_registration_pt export, char *data
 
         json_decref(js_request);
 
+
         struct generic_service_layout *serv = export->service;
-        args[0] = serv->handle;
-        void *returnVal = NULL;
-        dynType_alloc(returnType, &returnVal);
-        dynFunction_call(method->dynFunc, serv->methods[method->index], returnVal, args);
-
-        status = jsonSerializer_serialize(returnType, returnVal, response);
-        if (returnVal != NULL) {
-            dynType_free(returnType, returnVal);
-        }
+        args[0] = &serv->handle;
+
+        //TODO assert last is output pointer (e.g. double pointer)
+        dyn_type *lastTypePtr = dynFunction_argumentTypeForIndex(method->dynFunc, nrOfArgs-1);
+        dyn_type *lastType = NULL;
+        dynType_typedPointer_getTypedType(lastTypePtr, &lastType);
+
+
+        void *out = NULL;
+        dynType_alloc(lastType, &out); //TODO, NOTE only for simple types or single pointer types.. TODO check
+        printf("out ptr is %p value is %f\n", out, *(double *)out);
+        args[nrOfArgs-1] = &out; //NOTE for simple type no double
+
+        printf("args is %p %p %p\n", args[0] , args[1], args[2]);
+        printf("args derefs is %p %p %p\n", *(void **)args[0], *(void **)args[1], *(void **)args[2]);
+
+        //TODO assert return type is native int
+        int returnVal = 0;
+        //printf("calling function '%s', with index %i, nrOfArgs %i and at loc %p\n", method->id, method->index, nrOfArgs, serv->methods[method->index]);
+        dynFunction_call(method->dynFunc, serv->methods[method->index], (void *)&returnVal, args);
+        //printf("done calling\n");
+        //printf("args is %p %p %p\n", args[0] , args[1], args[2]);
+        //printf("args derefs is %p %p %p\n", *(void **)args[0], *(void **)args[1], *(void **)args[2]);
+        //printf("out is %p and val is %f\n", out, *(double *)out);
+
+        json_t *responseJson = NULL;
+        //double r = 2.0;
+        //status = jsonSerializer_serializeJson(lastOutputType, &r /*out*/, &responseJson);
+        printf("out ptr is %p, value is %f\n", out, *(double *)out);
+        status = jsonSerializer_serializeJson(lastType, out, &responseJson);
+
+        json_t *payload = json_object();
+        json_object_set_new(payload, "r", responseJson);
+
+        char *response = json_dumps(payload, JSON_DECODE_ANY);
+        json_decref(payload);
+
+
+        *responseOut = response;
+        *responseLength = -1;
+
+        //TODO free args (created by jsonSerializer and dynType_alloc) (dynType_free)
 
         ///TODO add more status checks
     }
 
     //TODO unlock/sema export
+    printf("done export reg call\n");
     return status;
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/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
index 4e424a8..985d94d 100644
--- 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
@@ -1,4 +1,6 @@
 #include <stdlib.h>
+#include <jansson.h>
+#include "json_serializer.h"
 #include "dyn_interface.h"
 #include "import_registration.h"
 #include "import_registration_dfi.h"
@@ -7,6 +9,8 @@ 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;
@@ -47,14 +51,30 @@ celix_status_t importRegistration_create(bundle_context_pt context, endpoint_des
     }
 
     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);
         }
@@ -93,7 +113,6 @@ celix_status_t importRegistration_getService(import_registration_pt import, bund
     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);
@@ -117,16 +136,17 @@ static celix_status_t importRegistration_createProxy(import_registration_pt impo
     char name[128];
     snprintf(name, 128, "%s.descriptor", import->classObject);
     status = bundle_getEntry(bundle, name, &descriptorFile);
-    if (status != CELIX_SUCCESS) {
+    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) {
-
-        } else {
+        if (proxy == NULL) {
             status = CELIX_ENOMEM;
         }
     }
@@ -142,16 +162,23 @@ static celix_status_t importRegistration_createProxy(import_registration_pt impo
         }
     }
 
-    void **serv = NULL;
+
     if (status == CELIX_SUCCESS) {
         size_t count = dynInterface_nrOfMethods(proxy->intf);
-        serv = calloc(1 + count, sizeof(void *));
-        serv[0] = proxy;
+        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);
+        void (*fn)(void) = NULL;
         int index = 0;
         TAILQ_FOREACH(entry, list, entries) {
             int rc = dynFunction_createClosure(entry->dynFunc, importRegistration_proxyFunc, entry, &fn);
@@ -166,31 +193,102 @@ static celix_status_t importRegistration_createProxy(import_registration_pt impo
     }
 
     if (status == CELIX_SUCCESS) {
-        proxy->service = serv;
+        *out = proxy;
     } else {
-        if (serv != NULL) {
-            free(serv);
+        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);
         }
-    }
-
-    if (status == CELIX_SUCCESS) {
-        *out = proxy;
     }
 
     return status;
 }
 
 static void importRegistration_proxyFunc(void *userData, void *args[], void *returnVal) {
+    int  status = CELIX_SUCCESS;
     struct method_entry *entry = userData;
-    //struct proxy_service *proxy = args[0];
 
     printf("Calling function '%s'\n", entry->id);
+    json_t *invoke = json_object();
+    json_object_set(invoke, "m", json_string(entry->id));
+
+    json_t *jsonArgs = json_array();
+    json_object_set(invoke, "a", jsonArgs);
+    json_decref(jsonArgs);
+
+    int i;
+    int nrOfArgs = dynFunction_nrOfArguments(entry->dynFunc);
+    import_registration_pt import = *((void **)args[0]);
+
+    for (i = 1; i < nrOfArgs -1; i +=1) { //note 0 = handle, last = output
+        json_t *val = NULL;
+        dyn_type *type = dynFunction_argumentTypeForIndex(entry->dynFunc, i);
+        int rc = jsonSerializer_serializeJson(type, args[i], &val);
+        if (rc == 0) {
+            json_array_append_new(jsonArgs, val);
+        } else {
+            status = CELIX_ILLEGAL_ARGUMENT;
+            break;
+        }
+    }
 
-    //TODO
+
+    char *output = json_dumps(invoke, JSON_DECODE_ANY);
+    printf("Need to send following json '%s'\n", output);
+
+    printf("import is %p\n", import);
+    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
+
+        printf("replyJson p is %p and result is %p\n", replyJson, result);
+
+        if (rc == 0) {
+            dyn_type *lastPtr = dynFunction_argumentTypeForIndex(entry->dynFunc, nrOfArgs - 1);
+            dyn_type *lastType = NULL;
+            dynType_typedPointer_getTypedType(lastPtr, &lastType);
+            if (rc == CELIX_SUCCESS) {
+                void *tmp = NULL;
+                rc = jsonSerializer_deserializeJson(lastType, result, &tmp);
+                void **out = (void **)args[nrOfArgs-1];
+                memcpy(*out, tmp, dynType_size(lastType));
+                dynType_free(lastType, tmp); //TODO only for simple types -> eg complex type will be alloc by callee
+            }
+            json_decref(replyJson);
+
+            int *returnInt = returnVal;
+            *returnInt = status;
+
+            printf("done with proxy func\n");
+        }
+    } else {
+        printf("Error import of import->send is NULL\n");
+    }
+
+    json_decref(invoke);
 }
 
 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) {
@@ -203,6 +301,7 @@ celix_status_t importRegistration_ungetService(import_registration_pt import, bu
             importRegistration_destroyProxy(proxy);
         }
     }
+     */
 
     return status;
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
index 5e11c3b..c78cc19 100644
--- a/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
+++ b/remote_services/remote_service_admin_dfi/private/src/remote_service_admin_dfi.c
@@ -27,16 +27,11 @@
 #include <stdlib.h>
 
 #include <arpa/inet.h>
-#include <sys/socket.h>
 #include <netdb.h>
 #include <ifaddrs.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
 #include <string.h>
 #include <uuid/uuid.h>
 #include <curl/curl.h>
-#include <sys/queue.h>
 
 #include <jansson.h>
 
@@ -47,19 +42,7 @@
 #include "remote_service_admin.h"
 #include "remote_constants.h"
 #include "constants.h"
-#include "utils.h"
-#include "bundle_context.h"
-#include "bundle.h"
-#include "service_reference.h"
-#include "service_registration.h"
-#include "log_helper.h"
-#include "log_service.h"
-#include "celix_threads.h"
 #include "civetweb.h"
-#include "log_helper.h"
-#include "endpoint_description.h"
-#include "dyn_interface.h"
-#include "json_serializer.h"
 
 // defines how often the webserver is restarted (with an increased port number)
 #define MAX_NUMBER_OF_RESTARTS 	5
@@ -112,11 +95,9 @@ static const char *DEFAULT_IP = "127.0.0.1";
 static const unsigned int DEFAULT_TIMEOUT = 0;
 
 static int remoteServiceAdmin_callback(struct mg_connection *conn);
-
 static celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, char *interface, endpoint_description_pt *description);
-
+static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
 static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip);
-
 static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp);
 static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp);
 static void remoteServiceAdmin_log(remote_service_admin_pt admin, int level, const char *file, int line, const char *msg, ...);
@@ -296,7 +277,7 @@ celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin) {
 celix_status_t importRegistration_getFactory(import_registration_pt import, service_factory_pt *factory);
 
 static int remoteServiceAdmin_callback(struct mg_connection *conn) {
-    int result = 0; // zero means: let civetweb handle it further, any non-zero value means it is handled by us...
+    int result = 1; // zero means: let civetweb handle it further, any non-zero value means it is handled by us...
 
     const struct mg_request_info *request_info = mg_get_request_info(conn);
     if (request_info->uri != NULL) {
@@ -355,6 +336,7 @@ static int remoteServiceAdmin_callback(struct mg_connection *conn) {
                 if (response != NULL) {
                     mg_write(conn, data_response_headers, strlen(data_response_headers));
 //              mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
+                    printf("writing response '%s'\n", response);
                     mg_write(conn, response, strlen(response));
 //              mg_send_data(conn, response, strlen(response));
 //              mg_write_data(conn, response, strlen(response));
@@ -363,10 +345,11 @@ static int remoteServiceAdmin_callback(struct mg_connection *conn) {
                 } else {
                     mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
                 }
-                result = 0;
+                result = 1;
 
                 free(data);
             } else {
+                result = 0;
                 //TODO log warning
             }
 
@@ -597,6 +580,9 @@ celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, e
     if (objectClass != NULL) {
         status = importRegistration_create(admin->context, endpointDescription, objectClass, &import);
     }
+    if (status == CELIX_SUCCESS) {
+        importRegistration_setSendFn(import, remoteServiceAdmin_send, admin);
+    }
 
     if (status == CELIX_SUCCESS) {
         status = importRegistration_start(import);
@@ -657,8 +643,8 @@ celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt
 }
 
 
-celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus) {
-
+static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus) {
+    remote_service_admin_pt  rsa = handle;
     struct post post;
     post.readptr = request;
     post.size = strlen(request);
@@ -703,11 +689,13 @@ celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_des
         curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, remoteServiceAdmin_write);
         curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&get);
         curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)post.size);
+        logHelper_log(rsa->loghelper, OSGI_LOGSERVICE_DEBUG, "RSA: Performing curl post\n");
         res = curl_easy_perform(curl);
-        curl_easy_cleanup(curl);
 
         *reply = get.writeptr;
         *replyStatus = res;
+
+        curl_easy_cleanup(curl);
     }
 
     return status;

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt b/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
index a184d21..d21fb89 100644
--- a/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
@@ -5,8 +5,6 @@
 #TODO add FRAMEWORK_TEST / TEST check
 #if (RSA_EXAMPLES)
 
-    add_subdirectory(bundle)
-
     include_directories(
         ${PROJECT_SOURCE_DIR}/launcher/public/include
         ${CPPUTEST_INCLUDE_DIR}
@@ -27,7 +25,7 @@
         ${PROJECT_SOURCE_DIR}/launcher/private/src/launcher.c #TODO move to libframework
         ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
     )
-    target_link_libraries(test_rsa_dfi celix_framework celix_utils ${CURL_LIBRARIES})
+    target_link_libraries(test_rsa_dfi celix_framework celix_utils ${CURL_LIBRARIES} ${CPPUTEST_LIBRARY})
 
     get_property(rsa_bundle_file TARGET remote_service_admin_dfi PROPERTY BUNDLE)
     get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE)

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt b/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt
index e1d4fb3..b91ebf1 100644
--- a/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/tst/bundle/CMakeLists.txt
@@ -7,8 +7,13 @@ include_directories(
         ${CPPUTEST_INCLUDE_DIR}
         ${PROJECT_SOURCE_DIR}/framework/public/include
         ${PROJECT_SOURCE_DIR}/utils/public/include
+        ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include
 )
 
+SET_HEADER(BUNDLE_SYMBOLICNAME "apache_celix_remote_service_admin_dfi_tst_bundle")
+SET(BUNDLE_VERSION "0.0.1")
+SET_HEADERS("Bundle-Name: Apache Celix Remote Service Admin DFI test bundle")
+
 
 bundle(rsa_dfi_tst_bundle
     SOURCES

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c b/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c
index 9b16e65..728030e 100644
--- a/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c
+++ b/remote_services/remote_service_admin_dfi/tst/bundle/tst_activator.c
@@ -4,6 +4,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include <service_tracker_customizer.h>
+#include <service_tracker.h>
 
 #include "bundle_activator.h"
 #include "bundle_context.h"
@@ -19,9 +21,15 @@ struct activator {
 	bundle_context_pt context;
 	struct tst_service serv;
 	service_registration_pt  reg;
+
+	service_tracker_customizer_pt cust;
+	service_tracker_pt tracker;
+	calculator_service_pt calc;
 };
 
-static void test(void *handle);
+static celix_status_t addCalc(void * handle, service_reference_pt reference, void * service);
+static celix_status_t removeCalc(void * handle, service_reference_pt reference, void * service);
+static int test(void *handle);
 
 celix_status_t bundleActivator_create(bundle_context_pt context, void **out) {
 	celix_status_t status = CELIX_SUCCESS;
@@ -30,17 +38,48 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **out) {
 		act->context = context;
 		act->serv.handle = act;
 		act->serv.test = test;
+
+		status = serviceTrackerCustomizer_create(act, NULL, addCalc, NULL, removeCalc, &act->cust);
+		status = CELIX_DO_IF(status, serviceTracker_create(context, CALCULATOR2_SERVICE, act->cust, &act->tracker));
+
 	} else {
 		status = CELIX_ENOMEM;
 	}
 
 	if (status == CELIX_SUCCESS) {
 		*out = act;
+	} else if (act != NULL) {
+		if (act->cust != NULL) {
+			free(act->cust);
+			act->cust = NULL;
+		}
+		if (act->tracker != NULL) {
+			serviceTracker_destroy(act->tracker);
+			act->tracker = NULL;
+		}
+		free(act);
 	}
 
 	return CELIX_SUCCESS;
 }
 
+static celix_status_t addCalc(void * handle, service_reference_pt reference, void * service) {
+	celix_status_t status = CELIX_SUCCESS;
+	struct activator * act = handle;
+	act->calc = service;
+	return status;
+}
+
+static celix_status_t removeCalc(void * handle, service_reference_pt reference, void * service) {
+	celix_status_t status = CELIX_SUCCESS;
+	struct activator * act = handle;
+	if (act->calc == service) {
+		act->calc = NULL;
+	}
+	return status;
+
+}
+
 celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
     celix_status_t status = CELIX_SUCCESS;
 	struct activator * act = userData;
@@ -48,6 +87,9 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
 	act->reg = NULL;
 	status = bundleContext_registerService(context, (char *)TST_SERVICE_NAME, &act->serv, NULL, &act->reg);
 
+	status = CELIX_DO_IF(status, serviceTracker_open(act->tracker));
+
+
 	return status;
 }
 
@@ -57,35 +99,39 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context)
 	struct activator * act = userData;
 
 	status = serviceRegistration_unregister(act->reg);
+	status = CELIX_DO_IF(status, serviceTracker_close(act->tracker));
 
 	return status;
 }
 
 celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
-	free(userData);
+	struct activator *act = userData;
+	if (act != NULL) {
+		if (act->tracker != NULL) {
+			serviceTracker_destroy(act->tracker);
+			act->tracker = NULL;
+		}
+		free(act);
+	}
 	return CELIX_SUCCESS;
 }
 
-static void test(void *handle) {
+static int test(void *handle) {
+	int status = 0;
 	struct activator *act = handle;
-	bundle_context_pt context = act->context;
-	//TODO improve. don't use asserts.
-
-	int rc = 0;
-	service_reference_pt ref = NULL;
-	calculator_service_pt calc = NULL;
-
-	rc = bundleContext_getServiceReference(context, (char *)CALCULATOR2_SERVICE, &ref);
-	assert(rc == 0);
-
-	rc = bundleContext_getService(context, ref, (void **)&calc);
-	assert(rc == 0);
 
 	double result = 0.0;
-	rc = calc->sqrt(calc->calculator, 4, &result);
-	assert(rc == 0);
-	assert(result == 2);
 
-	bundleContext_ungetService(context, ref, NULL);
-	bundleContext_ungetServiceReference(context, ref);
+    int rc;
+    if (act->calc != NULL) {
+         rc = act->calc->sqrt(act->calc->calculator, 4, &result);
+        printf("calc result is %d\n", result);
+    } else {
+        printf("calc not ready\n");
+    }
+
+	if (rc != 0 || result != 2.0) {
+		status = 1;
+	}
+	return status;
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h b/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h
index 2fc2b21..2678b0c 100644
--- a/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h
+++ b/remote_services/remote_service_admin_dfi/tst/bundle/tst_service.h
@@ -9,7 +9,7 @@
 
 struct tst_service {
     void *handle;
-    void (*test)(void *handle);
+    int (*test)(void *handle);
 };
 
 typedef struct tst_service *tst_service_pt;

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/remote_services/remote_service_admin_dfi/tst/client.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/client.properties.in b/remote_services/remote_service_admin_dfi/tst/client.properties.in
index 9cde4bd..a9a06fb 100644
--- a/remote_services/remote_service_admin_dfi/tst/client.properties.in
+++ b/remote_services/remote_service_admin_dfi/tst/client.properties.in
@@ -4,4 +4,5 @@ RSA_PORT=50881
 DISCOVERY_CFG_SERVER_PORT=50991
 DISCOVERY_CFG_POLL_ENDPOINTS=http://127.0.0.1:50992/org.apache.celix.discovery.configured
 org.osgi.framework.storage.clean=onFirstInit
+org.osgi.framework.storage=.cacheClient
 DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp b/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp
index 5ffb47a..35beffe 100644
--- a/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/tst/rsa_client_server_tests.cpp
@@ -4,6 +4,7 @@
 #include <CppUTest/TestHarness.h>
 #include <remote_constants.h>
 #include <constants.h>
+#include <tst_service.h>
 #include "CppUTest/CommandLineTestRunner.h"
 #include "../../examples/calculator_service/public/include/calculator_service.h"
 
@@ -74,30 +75,24 @@ extern "C" {
 
     static void test1(void) {
         int rc = 0;
-        /* TODO use tst_service for (which has a descriptor file of the calculator service)
         service_reference_pt ref = NULL;
-        calculator_service_pt calc = NULL;
+        tst_service_pt tst = NULL;
 
-        usleep(5000000); //needed to accept connection (firewall)
+        usleep(2000000); //TODO use tracker
 
-        bundleContext_getServiceReference(clientContext, (char *)CALCULATOR2_SERVICE, &ref);
+        bundleContext_getServiceReference(clientContext, (char *)TST_SERVICE_NAME, &ref);
         CHECK_EQUAL(0, rc);
         CHECK(ref != NULL);
 
-        //NOTE will not work. using framework context. need to use calc client context (lookup bundle / create own?)
-
-        bundleContext_getService(clientContext, ref, (void **)&calc);
+        bundleContext_getService(clientContext, ref, (void **)&tst);
         CHECK_EQUAL(0, rc);
-        CHECK(calc != NULL);
+        CHECK(tst != NULL);
 
-        double result = 0.0;
-        rc = calc->sqrt(calc->calculator, 4, &result);
+        rc = tst->test(tst->handle);
         CHECK_EQUAL(0, rc);
-        CHECK(result == 2.0);
 
         bundleContext_ungetService(clientContext, ref, NULL);
         bundleContext_ungetServiceReference(clientContext, ref);
-         */
     }
 
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/7dc2039f/remote_services/remote_service_admin_dfi/tst/server.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/server.properties.in b/remote_services/remote_service_admin_dfi/tst/server.properties.in
index f75bf24..ea02519 100644
--- a/remote_services/remote_service_admin_dfi/tst/server.properties.in
+++ b/remote_services/remote_service_admin_dfi/tst/server.properties.in
@@ -4,4 +4,5 @@ RSA_PORT=50882
 DISCOVERY_CFG_SERVER_PORT=50992
 DISCOVERY_CFG_POLL_ENDPOINTS=http://127.0.0.1:50991/org.apache.celix.discovery.configured
 org.osgi.framework.storage.clean=onFirstInit
+org.osgi.framework.storage=.cacheServer
 DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file


[28/50] [abbrv] celix git commit: CELIX-237: Refactored meta chars in dyn_function to a more generic meta property setup in dyn_type. Split of rpc / serialization json stuff

Posted by pn...@apache.org.
CELIX-237: Refactored meta chars in dyn_function to a more generic meta property setup in dyn_type. Split of rpc / serialization json stuff


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

Branch: refs/heads/develop
Commit: 837926e6bdfa0ba97beb00c0db52146a68d74911
Parents: 89968d9
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Sep 2 17:43:28 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Sep 2 17:43:28 2015 +0200

----------------------------------------------------------------------
 ...apache.celix.calc.api.Calculator2.descriptor |   6 +-
 .../dynamic_function_interface/CMakeLists.txt   |   1 +
 .../dynamic_function_interface/dyn_function.c   |  68 ------
 .../dynamic_function_interface/dyn_function.h   |  18 +-
 .../dynamic_function_interface/dyn_type.c       |  85 +++++++
 .../dynamic_function_interface/dyn_type.h       |  11 +-
 .../dynamic_function_interface/json_rpc.c       | 235 +++++++++++++++++++
 .../dynamic_function_interface/json_rpc.h       |  22 ++
 .../json_serializer.c                           | 213 -----------------
 .../json_serializer.h                           |   4 -
 .../CMakeLists.txt                              |   1 +
 .../dyn_function_tests.cpp                      |  38 ---
 .../dyn_type_tests.cpp                          |  24 +-
 .../json_rpc_tests.cpp                          |  61 +++++
 .../rsa/private/src/export_registration_dfi.c   |   9 +-
 .../rsa/private/src/import_registration_dfi.c   |   5 +-
 16 files changed, 451 insertions(+), 350 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/837926e6/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor b/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
index 52e3322..c8ba53d 100644
--- a/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
+++ b/remote_services/examples/calculator_service/public/include/org.apache.celix.calc.api.Calculator2.descriptor
@@ -6,6 +6,6 @@ version=1.0.0
 classname=org.example.Calculator
 :types
 :methods
-add(DD)D=add(#PDD^*D)N
-sub(DD)D=sub(#PDD^*D)N
-sqrt(D)D=sqrt(#PD^*D)N
+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

http://git-wip-us.apache.org/repos/asf/celix/blob/837926e6/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
index 142ae32..aefd243 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt
@@ -16,6 +16,7 @@ add_library(dfi STATIC
     dyn_function.c
     dyn_interface.c
     json_serializer.c
+    json_rpc.c
     ${MEMSTREAM_SOURCES}
 )
 target_link_libraries(dfi ${FFI_LIBRARIES} ${JANSSON_LIBRARY})
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/837926e6/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
index 06f6aaa..abd27d0 100644
--- 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
@@ -43,10 +43,6 @@ 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);
 
-static int dynFunction_checkArgument(dyn_function_argument_type *argument);
-
-static void dynFunction_parseArgMeta(FILE *descriptor, int *meta);
-
 int dynFunction_parse(FILE *descriptor, struct types_head *refTypes, dyn_function_type **out) {
     int status = OK;
     dyn_function_type *dynFunc = NULL;
@@ -116,13 +112,11 @@ static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descrip
     int nextChar = fgetc(descriptor);
     int index = 0;
     dyn_type *type = NULL;
-    int argMetaInfo = DYN_FUNCTION_ARG_META_INPUT_TYPE;
     char argName[32];
     while (nextChar != ')' && status == 0)  {
         ungetc(nextChar, descriptor);
         type = NULL;
 
-        dynFunction_parseArgMeta(descriptor, &argMetaInfo);
         dyn_function_argument_type *arg = NULL;
 
         status = dynType_parse(descriptor, NULL, dynFunc->refTypes, &type);
@@ -131,8 +125,6 @@ static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descrip
             if (arg != NULL) {
                 arg->index = index;
                 arg->type = type;
-                arg->argumentType = argMetaInfo;
-
                 snprintf(argName, 32, "arg%04i", index);
                 arg->name = strdup(argName);
 
@@ -144,10 +136,6 @@ static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descrip
         }
 
         if (status == 0) {
-            status = dynFunction_checkArgument(arg);
-        }
-
-        if (status == 0) {
             TAILQ_INSERT_TAIL(&dynFunc->arguments, arg, entries);
         } else {
             if (arg != NULL) {
@@ -170,47 +158,6 @@ static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descrip
     return status;
 }
 
-static void dynFunction_parseArgMeta(FILE *descriptor, int *meta) {
-    int c = fgetc(descriptor);
-
-    switch (c) {
-        case '~' :
-            *meta = DYN_FUNCTION_ARG_META_OUTPUT_TYPE;
-            break;
-        case '^' :
-            *meta = DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE;
-            break;
-        case '#' :
-            *meta = DYN_FUNCTION_ARG_META_HANDLE_TYPE;
-            break;
-        default :
-            *meta = DYN_FUNCTION_ARG_META_INPUT_TYPE;
-            ungetc(c, descriptor);
-            break;
-    }
-}
-
-static int dynFunction_checkArgument(dyn_function_argument_type *argument) {
-    int status = 0;
-    if (argument->argumentType == DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE) {
-        //expect atleast one *
-        if (dynType_type(argument->type) != DYN_TYPE_TYPED_POINTER) {
-            status = ERROR;
-        }
-    } else if (argument->argumentType == DYN_FUNCTION_ARG_META_OUTPUT_TYPE) {
-        //expect atleast two **
-        if (dynType_type(argument->type) == DYN_TYPE_TYPED_POINTER) {
-            dyn_type *subType = NULL;
-            status = dynType_typedPointer_getTypedType(argument->type, &subType);
-            if (status == OK && dynType_type(subType) != DYN_TYPE_TYPED_POINTER) {
-                status = ERROR;
-            }
-        } else {
-            status = ERROR;
-        }
-    }
-    return status;
-}
 
 static int dynFunction_initCif(dyn_function_type *dynFunc) {
     int status = 0;
@@ -341,18 +288,3 @@ dyn_type * dynFunction_returnType(dyn_function_type *dynFunction) {
     return dynFunction->funcReturn;
 }
 
-int dynFunction_argumentMetaInfoForIndex(dyn_function_type *dynFunc, int argumentNr) {
-    int argType = DYN_FUNCTION_ARG_META_UNKNOWN_TYPE;
-    int index = 0;
-    dyn_function_argument_type *entry = NULL;
-    TAILQ_FOREACH(entry, &dynFunc->arguments, entries) {
-        if (index == argumentNr) {
-            argType = entry->argumentType;
-            break;
-        }
-        index +=1;
-    }
-    return argType;
-}
-
-

http://git-wip-us.apache.org/repos/asf/celix/blob/837926e6/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
index e99bc7a..de8853c 100644
--- 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
@@ -10,23 +10,16 @@
 
 /**
  * Uses the following schema
- * (Name)([ArgType]*)Type
+ * (Name)([Type]*)Type
  *
- * ArgType = (Type|PreAllocatedOutputType|OutputType)
- * PreAllocatedOutputType = ^(Type) #Note must be *(Type)
- * OutputType = ~(Type) #Note must be **(Type)
- * e.g add(DD)D or sum({[D[D setA setB})D
+ * 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;
 
-#define DYN_FUNCTION_ARG_META_UNKNOWN_TYPE 0
-#define DYN_FUNCTION_ARG_META_INPUT_TYPE 1
-#define DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE 2
-#define DYN_FUNCTION_ARG_META_OUTPUT_TYPE 3
-#define DYN_FUNCTION_ARG_META_HANDLE_TYPE 4
-//TODO input/output types?
-
 DFI_SETUP_LOG_HEADER(dynFunction);
 
 int dynFunction_parse(FILE *descriptorStream, struct types_head *refTypes, dyn_function_type **dynFunc);
@@ -35,7 +28,6 @@ int dynFunction_parseWithStr(const char *descriptor, struct types_head *refTypes
 int dynFunction_nrOfArguments(dyn_function_type *dynFunc);
 dyn_type *dynFunction_argumentTypeForIndex(dyn_function_type *dynFunc, int argumentNr);
 dyn_type * dynFunction_returnType(dyn_function_type *dynFunction);
-int dynFunction_argumentMetaInfoForIndex(dyn_function_type *dynFunc, int argumentNr);
 
 void dynFunction_destroy(dyn_function_type *dynFunc);
 int dynFunction_call(dyn_function_type *dynFunc, void(*fn)(void), void *returnValue, void **argValues);

http://git-wip-us.apache.org/repos/asf/celix/blob/837926e6/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
index 6396d1c..aae7ebc 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
@@ -49,12 +49,22 @@ 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;
@@ -63,6 +73,7 @@ struct _dyn_type {
     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;
@@ -119,6 +130,7 @@ static int dynType_parseWithStream(FILE *stream, const char *name, dyn_type *par
         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) {
@@ -170,6 +182,12 @@ static int dynType_parseAny(FILE *stream, dyn_type *type) {
         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;
@@ -178,6 +196,46 @@ static int dynType_parseAny(FILE *stream, dyn_type *type) {
     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;
@@ -205,6 +263,7 @@ static int dynType_parseComplex(FILE *stream, dyn_type *type) {
             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 {
@@ -281,6 +340,7 @@ static int dynType_parseNestedType(FILE *stream, dyn_type *type) {
         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;
@@ -324,6 +384,7 @@ static int dynType_parseReference(FILE *stream, dyn_type *type) {
         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;
@@ -445,6 +506,17 @@ static void dynType_clear(dyn_type *type) {
         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);
+        }
+        mEntry = next;
+    }
+
     switch (type->type) {
         case DYN_TYPE_COMPLEX :
             dynType_clearComplex(type);
@@ -724,6 +796,19 @@ 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;

http://git-wip-us.apache.org/repos/asf/celix/blob/837926e6/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
index 2058c41..e759dc2 100644
--- 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
@@ -21,7 +21,7 @@
 
 /* Description string
  *
- * Type = [TypeDef]* (SimpleType | ComplexType | SequenceType | TypedPointer | PointerReference ) [TypeDef]* [Annotation]*
+ * Type = [TypeDef]* (MetaInfo)* (SimpleType | ComplexType | SequenceType | TypedPointer | PointerReference ) [TypeDef]*
  * Name = alpha[(alpha|numeric)*]
  * SPACE = ' ' 
  *
@@ -63,8 +63,10 @@
  * TypedPointer
  * *(Type)
  *
- * Annotation TODO
- * <(Name)=(Value)>
+ * MetaInfo TODO
+ * #Name=Value;
+ *
+ *
  *
  * examples
  * "{DDII a b c d}" -> struct { double a; double b; int c; int d; }; 
@@ -111,7 +113,8 @@ 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);
+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);

http://git-wip-us.apache.org/repos/asf/celix/blob/837926e6/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
new file mode 100644
index 0000000..8a2f15c
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
@@ -0,0 +1,235 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#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;
+
+    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);
+    } else {
+        LOG_DEBUG("RSA: found method '%s'\n", entry->id);
+    }
+
+    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;
+    for (i = 0; i < nrOfArgs; i += 1) {
+        dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
+        const char *argMeta = dynType_getMetaInfo(argType, "am");
+        if (argMeta == NULL) {
+            printf("setting std for %i\n", i);
+            value = json_array_get(arguments, index++);
+            status = jsonSerializer_deserializeJson(argType, value, &(args[i]));
+        } else if (strcmp(argMeta, "pre") == 0) {
+            printf("setting pre alloc output for %i\n", i);
+            dynType_alloc(argType, &args[i]);
+
+        } else if ( strcmp(argMeta, "out") == 0) {
+            printf("setting output for %i\n", i);
+            args[i] = NULL;
+        } else if (strcmp(argMeta, "handle") == 0) {
+            printf("setting handle for %i\n", i);
+            args[i] = &handle;
+        }
+
+        if (status != OK) {
+            break;
+        }
+    }
+    json_decref(js_request);
+
+
+    //TODO assert return type is native int
+    int returnVal = 0;
+    dynFunction_call(func, fp, (void *)&returnVal, args);
+    printf("done calling\n");
+    double **r = args[2];
+    printf("result ptrptr is %p, result ptr %p, result is %f\n", r, *r, **r);
+
+
+    json_t *jsonResult = NULL;
+    for (i = 0; i < nrOfArgs; i += 1) {
+        dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
+        const char *argMeta = dynType_getMetaInfo(argType, "am");
+        if (argMeta == NULL) {
+            //ignore
+        } else if (strcmp(argMeta, "pre") == 0)  {
+            if (status == OK) {
+                status = jsonSerializer_serializeJson(argType, args[i], &jsonResult);
+            }
+        } else if (strcmp(argMeta, "out") == 0) {
+            printf("TODO\n");
+            assert(false);
+        }
+
+        if (status != OK) {
+            break;
+        }
+    }
+
+    char *response = NULL;
+    if (status == OK) {
+        LOG_DEBUG("creating payload\n");
+        json_t *payload = json_object();
+        json_object_set_new(payload, "r", jsonResult);
+        response = json_dumps(payload, JSON_DECODE_ANY);
+        json_decref(payload);
+        LOG_DEBUG("status ptr is %p. response if '%s'\n", status, response);
+    }
+
+    if (status == OK) {
+        *out = response;
+    } else {
+        if (response != NULL) {
+            free(response);
+        }
+    }
+
+    //TODO free args (created by jsonSerializer and dynType_alloc) (dynType_free)
+    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(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);
+        const char *argMeta = dynType_getMetaInfo(type, "am");
+        if (argMeta == NULL) {
+            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 = 0;
+
+    json_t *replyJson = json_loads(reply, JSON_DECODE_ANY, NULL); //TODO check
+    json_t *result = json_object_get(replyJson, "r"); //TODO check
+
+    LOG_DEBUG("replyJson ptr is %p and result ptr is %p\n", replyJson, result);
+
+    int nrOfArgs = dynFunction_nrOfArguments(func);
+    int i;
+    for (i = 0; i < nrOfArgs; i += 1) {
+        dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
+        const char *argMeta = dynType_getMetaInfo(argType, "am");
+        if (argMeta == NULL) {
+            //skip
+        } else if (strcmp(argMeta, "pre") == 0) {
+            dyn_type *subType = NULL;
+            dynType_typedPointer_getTypedType(argType, &subType);
+            void *tmp = NULL;
+            size_t size = dynType_size(subType);
+            status = jsonSerializer_deserializeJson(subType, result, &tmp);
+            void **out = (void **)args[i];
+            memcpy(*out, tmp, size);
+            dynType_free(subType, tmp);
+        } else if (strcmp(argMeta, "out") == 0) {
+            assert(false); //TODO
+        } 
+    }
+
+    json_decref(replyJson);
+
+    return status;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/837926e6/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
new file mode 100644
index 0000000..60811ac
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.h
@@ -0,0 +1,22 @@
+/**
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#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/837926e6/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
index a689483..30f5296 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c
@@ -27,13 +27,6 @@ static int ERROR = 1;
 
 DFI_SETUP_LOG(jsonSerializer);
 
-typedef void (*gen_func_type)(void);
-
-struct generic_service_layout {
-    void *handle;
-    gen_func_type methods[];
-};
-
 int jsonSerializer_deserialize(dyn_type *type, const char *input, void **result) {
     assert(dynType_type(type) == DYN_TYPE_COMPLEX);
     int status = 0;
@@ -422,210 +415,4 @@ static int jsonSerializer_writeComplex(dyn_type *type, void *input, json_t **out
     }
 
     return status;
-}
-
-int jsonSerializer_call(dyn_interface_type *intf, void *service, const char *request, char **out) {
-    int status = OK;
-
-    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);
-    } else {
-        LOG_DEBUG("RSA: found method '%s'\n", entry->id);
-    }
-
-    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;
-    for (i = 0; i < nrOfArgs; i += 1) {
-        int metaInfo = dynFunction_argumentMetaInfoForIndex(func, i);
-        dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
-        if (metaInfo == DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE) {
-            printf("setting pre alloc output for %i\n", i);
-            dynType_alloc(argType, &args[i]);
-
-        } else if ( metaInfo == DYN_FUNCTION_ARG_META_OUTPUT_TYPE) {
-            printf("setting output for %i\n", i);
-            args[i] = NULL;
-        } else if (metaInfo == DYN_FUNCTION_ARG_META_HANDLE_TYPE) {
-            printf("setting handle for %i\n", i);
-            args[i] = &handle;
-        } else {
-            printf("setting std for %i\n", i);
-            value = json_array_get(arguments, index++);
-            status = jsonSerializer_deserializeJson(argType, value, &(args[i]));
-        }
-
-        if (status != OK) {
-            break;
-        }
-    }
-    json_decref(js_request);
-
-
-    //TODO assert return type is native int
-    int returnVal = 0;
-    dynFunction_call(func, fp, (void *)&returnVal, args);
-    printf("done calling\n");
-    double **r = args[2];
-    printf("result ptrptr is %p, result ptr %p, result is %f\n", r, *r, **r);
-
-
-    json_t *jsonResult = NULL;
-    for (i = 0; i < nrOfArgs; i += 1) {
-        int metaInfo = dynFunction_argumentMetaInfoForIndex(func, i);
-        dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
-        if (metaInfo == DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE) {
-            if (status == OK) {
-                status = jsonSerializer_serializeJson(argType, args[i], &jsonResult);
-            }
-        } else if (metaInfo == DYN_FUNCTION_ARG_META_OUTPUT_TYPE) {
-            printf("TODO\n");
-            assert(false);
-        }
-
-        if (status != OK) {
-            break;
-        }
-    }
-
-    char *response = NULL;
-    if (status == OK) {
-        LOG_DEBUG("creating payload\n");
-        json_t *payload = json_object();
-        json_object_set_new(payload, "r", jsonResult);
-        response = json_dumps(payload, JSON_DECODE_ANY);
-        json_decref(payload);
-        LOG_DEBUG("status ptr is %p. response if '%s'\n", status, response);
-    }
-
-    if (status == OK) {
-        *out = response;
-    } else {
-        if (response != NULL) {
-            free(response);
-        }
-    }
-
-    //TODO free args (created by jsonSerializer and dynType_alloc) (dynType_free)
-    return status;
-}
-
-int jsonSerializer_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(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) {
-        if (dynFunction_argumentMetaInfoForIndex(func, i) == DYN_FUNCTION_ARG_META_INPUT_TYPE) {
-            json_t *val = NULL;
-            dyn_type *type = dynFunction_argumentTypeForIndex(func, i);
-            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 jsonSerializer_handleReply(dyn_function_type *func, const char *reply, void *args[]) {
-    int status = 0;
-
-    json_t *replyJson = json_loads(reply, JSON_DECODE_ANY, NULL); //TODO check
-    json_t *result = json_object_get(replyJson, "r"); //TODO check
-
-    LOG_DEBUG("replyJson ptr is %p and result ptr is %p\n", replyJson, result);
-
-    int nrOfArgs = dynFunction_nrOfArguments(func);
-    int i;
-    for (i = 0; i < nrOfArgs; i += 1) {
-        dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
-        int metaInf = dynFunction_argumentMetaInfoForIndex(func, i);
-        if (metaInf == DYN_FUNCTION_ARG_META_PRE_ALLOCATED_OUTPUT_TYPE) {
-            dyn_type *subType = NULL;
-            dynType_typedPointer_getTypedType(argType, &subType);
-            void *tmp = NULL;
-            size_t size = dynType_size(subType);
-            status = jsonSerializer_deserializeJson(subType, result, &tmp);
-            void **out = (void **)args[i];
-            memcpy(*out, tmp, size);
-            dynType_free(subType, tmp);
-        } else if (metaInf == DYN_FUNCTION_ARG_META_OUTPUT_TYPE) {
-            assert(false); //TODO
-        } else {
-            //skip handle and input types
-        }
-    }
-
-    json_decref(replyJson);
-
-    return status;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/837926e6/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
index 6e7ee7d..9976938 100644
--- 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
@@ -19,8 +19,4 @@ 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);
 
-int jsonSerializer_call(dyn_interface_type *intf, void *service, const char *request, char **out);
-
-int jsonSerializer_prepareInvokeRequest(dyn_function_type *func, const char *id, void *args[], char **out);
-int jsonSerializer_handleReply(dyn_function_type *func, const char *reply, void *args[]);
 #endif

http://git-wip-us.apache.org/repos/asf/celix/blob/837926e6/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
index 50325ab..13477c4 100644
--- 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
@@ -11,6 +11,7 @@ add_executable(test_dfi
 	dyn_closure_tests.cpp
 	dyn_interface_tests.cpp
 	json_serializer_tests.cpp
+	json_rpc_tests.cpp
 	run_tests.cpp
 )
 target_link_libraries(test_dfi dfi ${CPPUTEST_LIBRARY})

http://git-wip-us.apache.org/repos/asf/celix/blob/837926e6/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
index cb4e13b..413f6e9 100644
--- 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
@@ -166,40 +166,6 @@ extern "C" {
 
         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) {
@@ -224,8 +190,4 @@ TEST(DynFunctionTests, DynFuncAccTest) {
 
 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/837926e6/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
index 96f64fa..2f05bd1 100644
--- 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
@@ -38,7 +38,7 @@ extern "C" {
 
 TEST_GROUP(DynTypeTests) {
 	void setup() {
-	    dynType_logSetup(stdLog, NULL, 0);
+	    dynType_logSetup(stdLog, NULL, 4);
 	}
 };
 
@@ -188,3 +188,25 @@ TEST(DynTypeTests, AssignTest3) {
     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);
+}
+

http://git-wip-us.apache.org/repos/asf/celix/blob/837926e6/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
new file mode 100644
index 0000000..52b7386
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp
@@ -0,0 +1,61 @@
+/**
+ * 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"
+#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 handleTest(void) {
+        dyn_function_type *dynFunc = NULL;
+        int rc = dynFunction_parseWithStr("add(#at=h;PDD#at=pa;*D)N", NULL, &dynFunc);
+        CHECK_EQUAL(0, rc);
+
+        //TODO jsonRpc_handleReply(dynFunc, )
+    }
+
+    void prepareTest(void) {
+
+    }
+
+}
+
+TEST_GROUP(JsonRpcTests) {
+    void setup() {
+        int lvl = 1;
+        dynCommon_logSetup(stdLog, NULL, lvl);
+        dynType_logSetup(stdLog, NULL,lvl);
+        jsonSerializer_logSetup(stdLog, NULL, lvl);
+    }
+};
+
+TEST(JsonRpcTests, handleTest) {
+    handleTest();
+}
+
+TEST(JsonRpcTests, prepareTest) {
+    prepareTest();
+}
+

http://git-wip-us.apache.org/repos/asf/celix/blob/837926e6/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
index b5f0fec..9bc5b08 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
@@ -8,6 +8,7 @@
 #include <remote_service_admin.h>
 #include <service_tracker_customizer.h>
 #include <service_tracker.h>
+#include <json_rpc.h>
 #include "export_registration_dfi.h"
 
 struct export_reference {
@@ -100,8 +101,8 @@ celix_status_t exportRegistration_create(log_helper_pt helper, void (*closedCall
 
     if (status == CELIX_SUCCESS) {
         service_tracker_customizer_pt cust = NULL;
-        status = serviceTrackerCustomizer_create(reg, NULL, exportRegistration_addServ, NULL,
-                                                 exportRegistration_removeServ, &cust);
+        status = serviceTrackerCustomizer_create(reg, NULL, (void *) exportRegistration_addServ, NULL,
+                                                 (void *) exportRegistration_removeServ, &cust);
         if (status == CELIX_SUCCESS) {
             char filter[32];
             snprintf(filter, 32, "(service.id=%s)", servId);
@@ -124,7 +125,7 @@ celix_status_t exportRegistration_call(export_registration_pt export, char *data
 
     *responseLength = -1;
     celixThreadMutex_lock(&export->mutex);
-    status = jsonSerializer_call(export->intf, export->service, data, responseOut);
+    status = jsonRpc_call(export->intf, export->service, data, responseOut);
     celixThreadMutex_unlock(&export->mutex);
 
     return status;
@@ -168,7 +169,7 @@ static void exportRegistration_addServ(export_registration_pt reg, service_refer
 static void exportRegistration_removeServ(export_registration_pt reg, service_reference_pt ref, void *service) {
     celixThreadMutex_lock(&reg->mutex);
     if (reg->service == service) {
-        reg->service == NULL;
+        reg->service = NULL;
     }
     celixThreadMutex_unlock(&reg->mutex);
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/837926e6/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
index 9667fa9..9c4d717 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
@@ -1,5 +1,6 @@
 #include <stdlib.h>
 #include <jansson.h>
+#include <json_rpc.h>
 #include "json_serializer.h"
 #include "dyn_interface.h"
 #include "import_registration.h"
@@ -230,7 +231,7 @@ static void importRegistration_proxyFunc(void *userData, void *args[], void *ret
 
     char *invokeRequest = NULL;
     if (status == CELIX_SUCCESS) {
-        status = jsonSerializer_prepareInvokeRequest(entry->dynFunc, entry->id, args, &invokeRequest);
+        status = jsonRpc_prepareInvokeRequest(entry->dynFunc, entry->id, args, &invokeRequest);
         printf("Need to send following json '%s'\n", invokeRequest);
     }
 
@@ -243,7 +244,7 @@ static void importRegistration_proxyFunc(void *userData, void *args[], void *ret
 
         if (rc == 0) {
             printf("handling reply\n");
-            status = jsonSerializer_handleReply(entry->dynFunc, reply, args);
+            status = jsonRpc_handleReply(entry->dynFunc, reply, args);
         }
 
         *(int *) returnVal = rc;


[44/50] [abbrv] celix git commit: CELIX-237: Fixed an issue in the dyn_type, added some extra tests and improved some logging handling in the framework

Posted by pn...@apache.org.
CELIX-237: Fixed an issue in the dyn_type, added some extra tests and improved some logging handling in the framework


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

Branch: refs/heads/develop
Commit: f3ae660e980859ffa29bbcfa829c4db591791f9f
Parents: 3f71ac4
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Oct 7 14:30:51 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Oct 7 14:30:51 2015 +0200

----------------------------------------------------------------------
 framework/private/src/celix_log.c                |  5 ++++-
 framework/private/src/framework.c                | 12 ++++++------
 .../dynamic_function_interface/dyn_type.c        |  3 ++-
 .../dynamic_function_interface/json_rpc.c        |  2 +-
 .../descriptors/example3.descriptor              | 11 +++++++++++
 .../dyn_interface_tests.cpp                      | 16 ++++++++++++++++
 .../dyn_type_tests.cpp                           | 19 ++++++++++++++++++-
 .../json_rpc_tests.cpp                           | 11 ++++++++++-
 .../rsa/private/src/export_registration_dfi.c    |  2 ++
 .../rsa/private/src/import_registration_dfi.c    |  2 +-
 10 files changed, 71 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/framework/private/src/celix_log.c
----------------------------------------------------------------------
diff --git a/framework/private/src/celix_log.c b/framework/private/src/celix_log.c
index 404c02f..d2e222e 100644
--- a/framework/private/src/celix_log.c
+++ b/framework/private/src/celix_log.c
@@ -34,7 +34,10 @@ void framework_log(framework_logger_pt logger, framework_log_level_t level, cons
     va_start(listPointer, fmsg);
     vsprintf(msg, fmsg, listPointer);
 
-    logger->logFunction(level, func, file, line, msg);
+    //FIXME logger and/or logger->logFucntion can be null. But this solution is not thread safe!
+    if (logger != NULL && logger->logFunction != NULL) {
+        logger->logFunction(level, func, file, line, msg);
+    }
 }
 
 void framework_logCode(framework_logger_pt logger, framework_log_level_t level, const char *func, const char *file, int line, celix_status_t code, char *fmsg, ...) {

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/framework/private/src/framework.c
----------------------------------------------------------------------
diff --git a/framework/private/src/framework.c b/framework/private/src/framework.c
index 17cfdba..22abc43 100644
--- a/framework/private/src/framework.c
+++ b/framework/private/src/framework.c
@@ -322,11 +322,6 @@ celix_status_t framework_destroy(framework_pt framework) {
 
 	unsetenv(OSGI_FRAMEWORK_FRAMEWORK_UUID);
 
-	logger = hashMap_get(framework->configurationMap, "logger");
-	if (logger == NULL) {
-		free(framework->logger);
-	}
-
 	celixThreadCondition_destroy(&framework->dispatcher);
 	celixThreadMutex_destroy(&framework->bundleListenerLock);
 	celixThreadMutex_destroy(&framework->dispatcherLock);
@@ -335,9 +330,14 @@ celix_status_t framework_destroy(framework_pt framework) {
 	celixThreadMutex_destroy(&framework->mutex);
 	celixThreadCondition_destroy(&framework->condition);
 
+    logger = hashMap_get(framework->configurationMap, "logger");
+    if (logger == NULL) {
+        free(framework->logger);
+    }
+
     properties_destroy(framework->configurationMap);
 
-	free(framework);
+    free(framework);
 
 	return status;
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
index 88f8766..972278d 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/dyn_type.c
@@ -301,7 +301,7 @@ static int dynType_parseComplex(FILE *stream, dyn_type *type) {
         if (type->complex.structType.elements != NULL) {
             int index = 0;
             TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
-                type->complex.structType.elements[index++] = entry->type->ffiType;
+                type->complex.structType.elements[index++] = dynType_ffiType(entry->type);
             }
         } else {
             status = MEM_ERROR;
@@ -576,6 +576,7 @@ static void dynType_clearTypedPointer(dyn_type *type) {
 
 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);

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
index 01dc6b5..756b24e 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c
@@ -128,7 +128,7 @@ int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request, c
         dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
         enum dyn_function_argument_meta  meta = dynFunction_argumentMetaForIndex(func, i);
         if (meta == DYN_FUNCTION_ARGUMENT_META__STD) {
-            //TODO SOMETIMES segfault dynType_free(argType, args[i]);
+            dynType_free(argType, args[i]);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/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
new file mode 100644
index 0000000..c89d969
--- /dev/null
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/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/f3ae660e/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
index 679260f..f7cc370 100644
--- 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
@@ -69,6 +69,18 @@ extern "C" {
         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);
+    }
+
 }
 
 
@@ -85,3 +97,7 @@ TEST_GROUP(DynInterfaceTests) {
 TEST(DynInterfaceTests, test1) {
     test1();
 }
+
+TEST(DynInterfaceTests, test2) {
+    test2();
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/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
index ae14c0f..57db391 100644
--- 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
@@ -22,12 +22,27 @@ extern "C" {
 
     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);
 
+        //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);
@@ -56,6 +71,7 @@ TEST_GROUP(DynTypeTests) {
 #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 CREATE_EXAMPLES_TEST(DESC) \
     TEST(DynTypeTests, ParseTestExample ## DESC) { \
@@ -76,6 +92,7 @@ CREATE_EXAMPLES_TEST(EX11)
 CREATE_EXAMPLES_TEST(EX12)
 CREATE_EXAMPLES_TEST(EX13)
 CREATE_EXAMPLES_TEST(EX14)
+CREATE_EXAMPLES_TEST(EX15)
 
 TEST(DynTypeTests, ParseRandomGarbageTest) {
     /*

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/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
index 6140bec..c7a3350 100644
--- 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
@@ -156,6 +156,7 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
         CHECK(desc != NULL);
         int rc = dynInterface_parse(desc, &intf);
         CHECK_EQUAL(0, rc);
+        fclose(desc);
 
         char *result = NULL;
 
@@ -178,6 +179,7 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
         CHECK(desc != NULL);
         int rc = dynInterface_parse(desc, &intf);
         CHECK_EQUAL(0, rc);
+        fclose(desc);
 
         char *result = NULL;
 
@@ -199,6 +201,7 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
         CHECK(desc != NULL);
         int rc = dynInterface_parse(desc, &intf);
         CHECK_EQUAL(0, rc);
+        fclose(desc);
 
         struct methods_head *head;
         dynInterface_methods(intf, &head);
@@ -238,6 +241,7 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
         CHECK(desc != NULL);
         int rc = dynInterface_parse(desc, &intf);
         CHECK_EQUAL(0, rc);
+        fclose(desc);
 
         struct methods_head *head;
         dynInterface_methods(intf, &head);
@@ -273,9 +277,14 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
         CHECK_EQUAL(2.5, result->buf[1]->b);
 
 
+        int i;
+        for (i = 0; i < result->len; i +=1 ) {
+            free(result->buf[i]);
+        }
         free(result->buf);
         free(result);
-        dynInterface_destroy(intf);    }
+        dynInterface_destroy(intf);
+    }
 
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
index edc085e..474749f 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/export_registration_dfi.c
@@ -119,6 +119,8 @@ celix_status_t exportRegistration_create(log_helper_pt helper, service_reference
 celix_status_t exportRegistration_call(export_registration_pt export, char *data, int datalength, char **responseOut, int *responseLength) {
     int status = CELIX_SUCCESS;
 
+    //printf("calling for '%s'\n");
+
     *responseLength = -1;
     celixThreadMutex_lock(&export->mutex);
     status = jsonRpc_call(export->intf, export->service, data, responseOut);

http://git-wip-us.apache.org/repos/asf/celix/blob/f3ae660e/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
index 680a75a..fdc95df 100644
--- a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
+++ b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c
@@ -249,7 +249,7 @@ static void importRegistration_proxyFunc(void *userData, void *args[], void *ret
         //printf("request sended. got reply '%s' with status %i\n", reply, rc);
 
         if (rc == 0) {
-            //printf("Handling reply '%s'\n", reply);
+            //fjprintf("Handling reply '%s'\n", reply);
             status = jsonRpc_handleReply(entry->dynFunc, reply, args);
         }
 


[06/50] [abbrv] celix git commit: CELIX-237: Some small changes needed for Mac

Posted by pn...@apache.org.
CELIX-237: Some small changes needed for Mac


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

Branch: refs/heads/develop
Commit: 4e3be109d24da30b787a753a00e8462a6f905e52
Parents: 481e5c8
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Sat Aug 1 21:15:51 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Sat Aug 1 21:15:51 2015 +0200

----------------------------------------------------------------------
 .../tst/json_serializer_tests.cpp                         | 10 +++++-----
 .../remote_service_admin_dfi/tst/CMakeLists.txt           |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/4e3be109/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/json_serializer_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/json_serializer_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/json_serializer_tests.cpp
index c21d594..5ee71ac 100644
--- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/json_serializer_tests.cpp
+++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/tst/json_serializer_tests.cpp
@@ -49,9 +49,9 @@ struct example1 {
 static void check_example1(void *data) {
     struct example1 *ex = (struct example1 *)data;
     CHECK_EQUAL(1.0, ex->a);
-    CHECK_EQUAL(22, ex->b);
-    CHECK_EQUAL(32, ex->c);
-    CHECK_EQUAL(42, ex->d);
+    LONGS_EQUAL(22, ex->b);
+    LONGS_EQUAL(32, ex->c);
+    LONGS_EQUAL(42, ex->d);
     CHECK_EQUAL(4.4f, ex->e);
 }
 
@@ -79,8 +79,8 @@ struct example2 {
 static void check_example2(void *data) {
     struct example2 *ex = (struct example2 *)data;
     CHECK_EQUAL(42, ex->byte);
-    CHECK_EQUAL(232, ex->long1);
-    CHECK_EQUAL(242, ex->long2);
+    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);

http://git-wip-us.apache.org/repos/asf/celix/blob/4e3be109/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt b/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
index d71186e..a9b7b00 100644
--- a/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/tst/CMakeLists.txt
@@ -12,7 +12,7 @@ include_directories(
 #if (FRAMEWORK_TESTS) TODO
     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")
 
 	add_executable(rsa_dfi_tests
 	    ${PROJECT_SOURCE_DIR}/launcher/private/src/launcher.c


[34/50] [abbrv] celix git commit: CELIX-237: fixed issue in dyn_type. Added support for uint8_t to json_serializer

Posted by pn...@apache.org.
CELIX-237: fixed issue in dyn_type. Added support for uint8_t to json_serializer


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

Branch: refs/heads/develop
Commit: b74a63b0640c452dfa793fefdfa20c9a2a94b7c1
Parents: 2c17460
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Sep 9 20:32:46 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Sep 9 20:32:46 2015 +0200

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


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

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

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

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