You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by ab...@apache.org on 2013/12/05 22:06:57 UTC

svn commit: r1548308 - in /incubator/celix/trunk/remote_services: calculator_endpoint/private/src/ calculator_proxy/ calculator_proxy/private/include/ calculator_proxy/private/src/ calculator_shell/private/src/ remote_service_admin/ remote_service_admi...

Author: abroekhuis
Date: Thu Dec  5 21:06:56 2013
New Revision: 1548308

URL: http://svn.apache.org/r1548308
Log:
CELIX-98: Added callback method to the RSA to be able to handle communication with endpoints. Updated the calculator proxy to use this callback instead of directly calling endpoints.
Also added support for removing exported endpoints from the RSA.

Modified:
    incubator/celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_activator.c
    incubator/celix/trunk/remote_services/calculator_proxy/CMakeLists.txt
    incubator/celix/trunk/remote_services/calculator_proxy/private/include/calculator_proxy_impl.h
    incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c
    incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c
    incubator/celix/trunk/remote_services/calculator_shell/private/src/calculator_shell_activator.c
    incubator/celix/trunk/remote_services/remote_service_admin/CMakeLists.txt
    incubator/celix/trunk/remote_services/remote_service_admin/private/include/import_registration_impl.h
    incubator/celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
    incubator/celix/trunk/remote_services/remote_service_admin/private/src/export_registration_impl.c
    incubator/celix/trunk/remote_services/remote_service_admin/private/src/import_registration_impl.c
    incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c
    incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h

Modified: incubator/celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_activator.c?rev=1548308&r1=1548307&r2=1548308&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_activator.c (original)
+++ incubator/celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_activator.c Thu Dec  5 21:06:56 2013
@@ -66,8 +66,8 @@ celix_status_t bundleActivator_create(bu
 celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
 	celix_status_t status = CELIX_SUCCESS;
 	struct activator *activator = userData;
-	remote_endpoint_pt endpoint;
-	remote_endpoint_service_pt endpointService;
+	remote_endpoint_pt endpoint = NULL;
+	remote_endpoint_service_pt endpointService = NULL;
 
 	calculatorEndpoint_create(activator->pool, &endpoint);
 	endpointService = apr_palloc(activator->pool, sizeof(*endpointService));

Modified: incubator/celix/trunk/remote_services/calculator_proxy/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/calculator_proxy/CMakeLists.txt?rev=1548308&r1=1548307&r2=1548308&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/calculator_proxy/CMakeLists.txt (original)
+++ incubator/celix/trunk/remote_services/calculator_proxy/CMakeLists.txt Thu Dec  5 21:06:56 2013
@@ -16,9 +16,7 @@
 # under the License.
 
 find_package(Jansson REQUIRED)
-find_package(CURL REQUIRED)
 
-include_directories(${CURL_INCLUDE_DIRS})
 include_directories(${JANSSON_INCLUDE_DIRS})
 include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
 include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
@@ -33,4 +31,4 @@ bundle(org.example.api.Calculator_proxy 
     private/include/calculator_proxy_impl.h
 )
 
-target_link_libraries(org.example.api.Calculator_proxy celix_framework ${JANSSON_LIBRARIES} ${CURL_LIBRARIES})
+target_link_libraries(org.example.api.Calculator_proxy celix_framework ${JANSSON_LIBRARIES})

Modified: incubator/celix/trunk/remote_services/calculator_proxy/private/include/calculator_proxy_impl.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/calculator_proxy/private/include/calculator_proxy_impl.h?rev=1548308&r1=1548307&r2=1548308&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/calculator_proxy/private/include/calculator_proxy_impl.h (original)
+++ incubator/celix/trunk/remote_services/calculator_proxy/private/include/calculator_proxy_impl.h Thu Dec  5 21:06:56 2013
@@ -36,16 +36,21 @@
 
 #include "endpoint_listener.h"
 
+
 struct calculator {
 	apr_pool_t *pool;
 	endpoint_description_pt endpoint;
+	sendToHandle sendToCallback;
+	void * sendToHandler;
 };
 
-celix_status_t calculatorProxy_create(apr_pool_t *pool, calculator_pt *calculator);
+celix_status_t calculatorProxy_create(apr_pool_t *pool, calculator_pt *endpoint);
 celix_status_t calculatorProxy_add(calculator_pt calculator, double a, double b, double *result);
 celix_status_t calculatorProxy_sub(calculator_pt calculator, double a, double b, double *result);
 celix_status_t calculatorProxy_sqrt(calculator_pt calculator, double a, double *result);
 
 celix_status_t calculatorProxy_setEndpointDescription(void *proxy, endpoint_description_pt endpoint);
+celix_status_t calculatorProxy_setHandler(void *proxy, void *handler);
+celix_status_t calculatorProxy_setCallback(void *proxy, sendToHandle callback);
 
 #endif /* CALCULATOR_PROXY_IMPL_H_ */

Modified: incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c?rev=1548308&r1=1548307&r2=1548308&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c (original)
+++ incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c Thu Dec  5 21:06:56 2013
@@ -74,6 +74,7 @@ celix_status_t bundleActivator_start(voi
 	remote_proxy_service_pt calculatorProxy;
 
 	calculatorProxy_create(activator->pool, &calculator);
+
 	calculatorService = apr_palloc(activator->pool, sizeof(*calculatorService));
 	calculatorService->calculator = calculator;
 	calculatorService->add = calculatorProxy_add;
@@ -82,6 +83,8 @@ celix_status_t bundleActivator_start(voi
 	calculatorProxy = apr_palloc(activator->pool, sizeof(*calculatorProxy));
 	calculatorProxy->proxy = calculator;
 	calculatorProxy->setEndpointDescription = calculatorProxy_setEndpointDescription;
+	calculatorProxy->setHandler = calculatorProxy_setHandler;
+	calculatorProxy->setCallback = calculatorProxy_setCallback;
 
 	char **services = malloc(2);
 	services[0] = CALCULATOR_SERVICE;

Modified: incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c?rev=1548308&r1=1548307&r2=1548308&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c (original)
+++ incubator/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c Thu Dec  5 21:06:56 2013
@@ -25,8 +25,6 @@
  */
 #include <jansson.h>
 
-#include <curl/curl.h>
-
 #include <string.h>
 #include <apr_strings.h>
 
@@ -36,28 +34,16 @@
 
 #include "calculator_proxy_impl.h"
 
-struct post {
-	const char *readptr;
-	int size;
-};
-
-struct get {
-	char *writeptr;
-	int size;
-};
-
-celix_status_t calculatorProxy_postRequest(calculator_pt calculator, char *url, struct post post, struct get *get);
-static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp);
-static size_t calculatorProxy_write(void *contents, size_t size, size_t nmemb, void *userp);
-
-celix_status_t calculatorProxy_create(apr_pool_t *pool, calculator_pt *endpoint) {
+celix_status_t calculatorProxy_create(apr_pool_t *pool, calculator_pt *calculator)  {
 	celix_status_t status = CELIX_SUCCESS;
-	*endpoint = apr_palloc(pool, sizeof(**endpoint));
-	if (!*endpoint) {
+	*calculator = apr_palloc(pool, sizeof(**calculator));
+	if (!*calculator) {
 		status = CELIX_ENOMEM;
 	} else {
-		(*endpoint)->pool = pool;
-		(*endpoint)->endpoint = NULL;
+		(*calculator)->pool = pool;
+		(*calculator)->endpoint = NULL;
+		(*calculator)->sendToCallback=NULL;
+		(*calculator)->sendToHandler=NULL;
 	}
 
 	return status;
@@ -67,28 +53,21 @@ celix_status_t calculatorProxy_add(calcu
 	celix_status_t status = CELIX_SUCCESS;
 
 	if (calculator->endpoint != NULL) {
-		char *serviceUrl = properties_get(calculator->endpoint->properties, ".ars.alias");
-		printf("CALCULATOR_PROXY: URL: %s\n", serviceUrl);
-		char *url = apr_pstrcat(calculator->pool, serviceUrl, "/add", NULL);
-
 		json_t *root;
 		root = json_pack("{s:f, s:f}", "arg0", a, "arg1", b);
 
-		struct post post;
 		char *data = json_dumps(root, 0);
-		post.readptr = data;
-		post.size = strlen(data);
+		char *reply = calloc(128, sizeof(char));
+		int replyStatus = 0;
 
-		struct get get;
-		get.size = 0;
-		get.writeptr = malloc(1);
+		calculator->sendToCallback(calculator->sendToHandler, calculator->endpoint, "add", data, &reply, &replyStatus);
 
-		status = calculatorProxy_postRequest(calculator, url, post, &get);
 		if (status == CELIX_SUCCESS) {
 			json_error_t jsonError;
-			json_t *reply = json_loads(get.writeptr, 0, &jsonError);
-			json_unpack(reply, "[f]", result);
+			json_t *js_reply = json_loads(reply, 0, &jsonError);
+            json_unpack(js_reply, "[f]", result);
 		}
+
 	} else {
 		printf("CALCULATOR_PROXY: No endpoint information available\n");
 	}
@@ -99,27 +78,19 @@ celix_status_t calculatorProxy_add(calcu
 celix_status_t calculatorProxy_sub(calculator_pt calculator, double a, double b, double *result) {
 	celix_status_t status = CELIX_SUCCESS;
 	if (calculator->endpoint != NULL) {
-	    char *serviceUrl = properties_get(calculator->endpoint->properties, ".ars.alias");
-		printf("CALCULATOR_PROXY: URL: %s\n", serviceUrl);
-		char *url = apr_pstrcat(calculator->pool, serviceUrl, "/sub", NULL);
-
 		json_t *root;
 		root = json_pack("{s:f, s:f}", "arg0", a, "arg1", b);
 
-		struct post post;
 		char *data = json_dumps(root, 0);
-		post.readptr = data;
-		post.size = strlen(data);
+		char *reply = calloc(128, sizeof(char));
+		int replyStatus = 0;
 
-		struct get get;
-		get.size = 0;
-		get.writeptr = malloc(1);
+		calculator->sendToCallback(calculator->sendToHandler, calculator->endpoint, "sub", data, &reply, &replyStatus);
 
-		status = calculatorProxy_postRequest(calculator, url, post, &get);
 		if (status == CELIX_SUCCESS) {
 			json_error_t jsonError;
-			json_t *reply = json_loads(get.writeptr, 0, &jsonError);
-			json_unpack(reply, "[f]", result);
+			json_t *js_reply = json_loads(reply, 0, &jsonError);
+			json_unpack(js_reply, "[f]", result);
 		}
 	} else {
 		printf("CALCULATOR_PROXY: No endpoint information available\n");
@@ -131,27 +102,19 @@ celix_status_t calculatorProxy_sub(calcu
 celix_status_t calculatorProxy_sqrt(calculator_pt calculator, double a, double *result) {
 	celix_status_t status = CELIX_SUCCESS;
 	if (calculator->endpoint != NULL) {
-	    char *serviceUrl = properties_get(calculator->endpoint->properties, ".ars.alias");
-		printf("CALCULATOR_PROXY: URL: %s\n", serviceUrl);
-		char *url = apr_pstrcat(calculator->pool, serviceUrl, "/sqrt", NULL);
-
 		json_t *root;
 		root = json_pack("{s:f}", "arg0", a);
 
-		struct post post;
 		char *data = json_dumps(root, 0);
-		post.readptr = data;
-		post.size = strlen(data);
+		char *reply = calloc(128, sizeof(char));
+		int replyStatus;
 
-		struct get get;
-		get.size = 0;
-		get.writeptr = malloc(1);
+		calculator->sendToCallback(calculator->sendToHandler, calculator->endpoint, "sqrt", data, &reply, &replyStatus);
 
-		status = calculatorProxy_postRequest(calculator, url, post, &get);
 		if (status == CELIX_SUCCESS) {
 			json_error_t jsonError;
-			json_t *reply = json_loads(get.writeptr, 0, &jsonError);
-			json_unpack(reply, "[f]", result);
+			json_t *js_reply = json_loads(reply, 0, &jsonError);
+			json_unpack(js_reply, "[f]", result);
 		}
 	} else {
 		printf("CALCULATOR_PROXY: No endpoint information available\n");
@@ -160,67 +123,31 @@ celix_status_t calculatorProxy_sqrt(calc
 	return status;
 }
 
-celix_status_t calculatorProxy_postRequest(calculator_pt calculator, char *url, struct post post, struct get *get) {
+celix_status_t calculatorProxy_setEndpointDescription(void *proxy, endpoint_description_pt endpoint) {
 	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_URL, url);
-		curl_easy_setopt(curl, CURLOPT_POST, 1L);
-		curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
-		curl_easy_setopt(curl, CURLOPT_READDATA, &post);
-		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, calculatorProxy_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);
 
-		printf("CALCULATOR_PROXY: Data read: \"%s\" %d\n", get->writeptr, res);
+	calculator_pt calculator = proxy;
+	calculator->endpoint = endpoint;
 
-	}
 	return status;
 }
 
-static size_t read_callback(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 calculatorProxy_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)\n");
-    exit(EXIT_FAILURE);
-  }
+celix_status_t calculatorProxy_setHandler(void *proxy, void *handler) {
+	celix_status_t status = CELIX_SUCCESS;
 
-  memcpy(&(mem->writeptr[mem->size]), contents, realsize);
-  mem->size += realsize;
-  mem->writeptr[mem->size] = 0;
+	calculator_pt calculator = proxy;
+	calculator->sendToHandler = handler;
 
-  return realsize;
+	return status;
 }
 
-celix_status_t calculatorProxy_setEndpointDescription(void *proxy, endpoint_description_pt endpoint) {
+
+celix_status_t calculatorProxy_setCallback(void *proxy, sendToHandle callback) {
 	celix_status_t status = CELIX_SUCCESS;
 
 	calculator_pt calculator = proxy;
-	calculator->endpoint = endpoint;
+	calculator->sendToCallback = callback;
 
 	return status;
 }

Modified: incubator/celix/trunk/remote_services/calculator_shell/private/src/calculator_shell_activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/calculator_shell/private/src/calculator_shell_activator.c?rev=1548308&r1=1548307&r2=1548308&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/calculator_shell/private/src/calculator_shell_activator.c (original)
+++ incubator/celix/trunk/remote_services/calculator_shell/private/src/calculator_shell_activator.c Thu Dec  5 21:06:56 2013
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "bundle_activator.h"
 #include "bundle_context.h"
 #include "service_registration.h"
 

Modified: incubator/celix/trunk/remote_services/remote_service_admin/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/CMakeLists.txt?rev=1548308&r1=1548307&r2=1548308&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/CMakeLists.txt (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin/CMakeLists.txt Thu Dec  5 21:06:56 2013
@@ -16,9 +16,9 @@
 # under the License.
 
 find_package(APR REQUIRED)
-find_package(Jansson REQUIRED)
+find_package(CURL REQUIRED)
 
-include_directories(${JANSSON_INCLUDE_DIRS})
+include_directories(${CURL_INCLUDE_DIRS})
 include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
 include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/public/include")
 include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
@@ -49,4 +49,4 @@ install_bundle(remote_service_admin
 		public/include/remote_service_admin.h
 )
 
-target_link_libraries(remote_service_admin celix_framework ${APRUTIL_LIBRARY} ${JANSSON_LIBRARIES})
+target_link_libraries(remote_service_admin celix_framework ${APRUTIL_LIBRARY} ${CURL_LIBRARIES})

Modified: incubator/celix/trunk/remote_services/remote_service_admin/private/include/import_registration_impl.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/private/include/import_registration_impl.h?rev=1548308&r1=1548307&r2=1548308&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/private/include/import_registration_impl.h (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin/private/include/import_registration_impl.h Thu Dec  5 21:06:56 2013
@@ -54,6 +54,9 @@ celix_status_t importRegistration_getExc
 celix_status_t importRegistration_getImportReference(import_registration_pt registration, import_reference_pt *reference);
 
 celix_status_t importRegistration_setEndpointDescription(import_registration_pt registration, endpoint_description_pt endpointDescription);
+celix_status_t importRegistration_setHandler(import_registration_pt registration, void * handler);
+celix_status_t importRegistration_setCallback(import_registration_pt registration, sendToHandle callback);
+
 celix_status_t importRegistration_startTracking(import_registration_pt registration);
 celix_status_t importRegistration_stopTracking(import_registration_pt registration);
 

Modified: incubator/celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h?rev=1548308&r1=1548307&r2=1548308&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h Thu Dec  5 21:06:56 2013
@@ -55,10 +55,14 @@ struct remote_service_admin {
 	struct mg_context *ctx;
 };
 
+celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *methodSignature, char *request, char **reply, int* replyStatus);
+
 celix_status_t remoteServiceAdmin_create(apr_pool_t *pool, bundle_context_pt context, 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(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);

Modified: incubator/celix/trunk/remote_services/remote_service_admin/private/src/export_registration_impl.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/private/src/export_registration_impl.c?rev=1548308&r1=1548307&r2=1548308&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/private/src/export_registration_impl.c (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin/private/src/export_registration_impl.c Thu Dec  5 21:06:56 2013
@@ -187,6 +187,7 @@ celix_status_t exportRegistration_close(
 
 	bundle_stop(registration->bundle);
 	bundle_uninstall(registration->bundle);
+	remoteServiceAdmin_removeExportedService(registration);
 
 	return status;
 }

Modified: incubator/celix/trunk/remote_services/remote_service_admin/private/src/import_registration_impl.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/private/src/import_registration_impl.c?rev=1548308&r1=1548307&r2=1548308&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/private/src/import_registration_impl.c (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin/private/src/import_registration_impl.c Thu Dec  5 21:06:56 2013
@@ -120,14 +120,15 @@ celix_status_t importRegistration_proxyA
 celix_status_t importRegistration_proxyAdded(void * handle, service_reference_pt reference, void *service) {
 	celix_status_t status = CELIX_SUCCESS;
 	import_registration_pt registration = handle;
+	remote_proxy_service_pt proxy = (remote_proxy_service_pt) service;
 
-	printf("PROXY added called!\n");
-	remote_proxy_service_pt proxy = service;
 	if (registration->proxy == NULL) {
 		registration->reference = reference;
 		registration->proxy = proxy;
 		if (registration->endpointDescription != NULL) {
 			proxy->setEndpointDescription(proxy->proxy, registration->endpointDescription);
+			proxy->setHandler(proxy->proxy, registration->rsa);
+			proxy->setCallback(proxy->proxy, (sendToHandle) &remoteServiceAdmin_send);
 		}
 	}
 
@@ -156,6 +157,8 @@ celix_status_t importRegistration_proxyR
 		registration->reference = NULL;
 		registration->proxy = NULL;
 		proxy->setEndpointDescription(proxy->proxy, NULL);
+		proxy->setHandler(proxy->proxy, NULL);
+		proxy->setCallback(proxy->proxy, NULL);
 	}
 
 	return status;
@@ -166,17 +169,19 @@ celix_status_t importRegistration_open(i
 
 	char *bundleStore = NULL;
 	bundleContext_getProperty(registration->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore);
+
 	if (bundleStore == NULL) {
 		bundleStore = DEFAULT_BUNDLE_STORE;
 	}
+
 	char *name = apr_pstrcat(registration->pool, bundleStore, "/", registration->endpointDescription->service, "_proxy.zip", NULL);
 	status = bundleContext_installBundle(registration->context, name, &registration->bundle);
+
 	if (status == CELIX_SUCCESS) {
 		status = bundle_start(registration->bundle);
 		if (status == CELIX_SUCCESS) {
 		}
 	}
-
 	return status;
 }
 
@@ -226,3 +231,26 @@ celix_status_t importRegistration_setEnd
 
 	return status;
 }
+
+
+celix_status_t importRegistration_setHandler(import_registration_pt registration, void * handler) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	if (registration->proxy != NULL) {
+		registration->proxy->setHandler(registration->proxy->proxy, handler);
+	}
+
+	return status;
+}
+
+
+celix_status_t importRegistration_setCallback(import_registration_pt registration, sendToHandle callback) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	if (registration->proxy != NULL) {
+		registration->proxy->setCallback(registration->proxy->proxy, callback);
+	}
+
+	return status;
+}
+

Modified: incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c?rev=1548308&r1=1548307&r2=1548308&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c Thu Dec  5 21:06:56 2013
@@ -29,6 +29,8 @@
 #include <apr_strings.h>
 #include <apr_uuid.h>
 
+#include <curl/curl.h>
+
 #include "remote_service_admin_impl.h"
 #include "export_registration_impl.h"
 #include "import_registration_impl.h"
@@ -40,6 +42,16 @@
 #include "service_reference.h"
 #include "service_registration.h"
 
+struct post {
+    const char *readptr;
+    int size;
+};
+
+struct get {
+    char *writeptr;
+    int size;
+};
+
 static const char *ajax_reply_start =
   "HTTP/1.1 200 OK\r\n"
   "Cache: no-cache\r\n"
@@ -55,6 +67,9 @@ celix_status_t remoteServiceAdmin_instal
 celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, properties_pt serviceProperties, properties_pt endpointProperties, char *interface, endpoint_description_pt *description);
 static celix_status_t constructServiceUrl(remote_service_admin_pt admin, char *service, char **serviceUrl);
 
+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(apr_pool_t *pool, bundle_context_pt context, remote_service_admin_pt *admin) {
 	celix_status_t status = CELIX_SUCCESS;
 
@@ -266,11 +281,23 @@ celix_status_t remoteServiceAdmin_export
 			}
 			hashMap_put(admin->exportedServices, reference, *registrations);
 		}
+		arrayList_destroy(interfaces);
 	}
 
 	return status;
 }
 
+celix_status_t remoteServiceAdmin_removeExportedService(export_registration_pt registration) {
+    celix_status_t status = CELIX_SUCCESS;
+    remote_service_admin_pt admin = registration->rsa;
+    array_list_pt registrations = NULL;
+
+    registrations = hashMap_remove(admin->exportedServices, registration->reference);
+    // Registrations are allocated on the RSA pool, so there is a "leak" here. Removed services still consume memory
+
+    return CELIX_SUCCESS;
+}
+
 celix_status_t remoteServiceAdmin_installEndpoint(remote_service_admin_pt admin, export_registration_pt registration, service_reference_pt reference, char *interface) {
 	celix_status_t status = CELIX_SUCCESS;
 	properties_pt endpointProperties = properties_create();
@@ -403,6 +430,76 @@ celix_status_t remoteServiceAdmin_import
 	return status;
 }
 
+celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *methodSignature, 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, ".ars.alias");
+    printf("CALCULATOR_PROXY: URL: %s\n", serviceUrl);
+    char *url = apr_pstrcat(rsa->pool, serviceUrl, "/", methodSignature, NULL);
+
+    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_URL, url);
+        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);
+
+        printf("CALCULATOR_PROXY: Data read: \"%s\" %d\n", get.writeptr, res);
+        *reply = get.writeptr;
+
+    }
+    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)\n");
+    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;

Modified: incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h?rev=1548308&r1=1548307&r2=1548308&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h Thu Dec  5 21:06:56 2013
@@ -31,9 +31,13 @@
 
 #define REMOTE_PROXY "remote_proxy"
 
+typedef celix_status_t (*sendToHandle)(void *handler, endpoint_description_pt endpointDescription, char *methodSignature, char *request, char **reply, int* replyStatus);
+
 struct remote_proxy_service {
 	void *proxy;
 	celix_status_t (*setEndpointDescription)(void *proxy, endpoint_description_pt service);
+	celix_status_t (*setHandler)(void *proxy, void *handler);
+	celix_status_t (*setCallback)(void *proxy, sendToHandle callback);
 };
 
 typedef struct remote_proxy_service *remote_proxy_service_pt;