celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1652984 [4/5] - in /celix/branches/celix_config_admin: ./ cmake/cmake_celix/ dependency_manager_2/ deployment_admin/private/include/ deployment_admin/private/src/ device_access/device_access/ device_access/device_access/private/src/ event_...
Date Mon, 19 Jan 2015 12:26:55 GMT
Modified: celix/branches/celix_config_admin/remote_services/remote_service_admin_http/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_services/remote_service_admin_http/CMakeLists.txt?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_services/remote_service_admin_http/CMakeLists.txt (original)
+++ celix/branches/celix_config_admin/remote_services/remote_service_admin_http/CMakeLists.txt Mon Jan 19 12:26:54 2015
@@ -15,11 +15,12 @@
 # specific language governing permissions and limitations
 # under the License.
 
-find_package(APR REQUIRED)
+
 find_package(CURL REQUIRED)
 
 include_directories(${CURL_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")
@@ -33,12 +34,13 @@ SET_HEADERS("Bundle-Name: Apache Celix R
 
 bundle(remote_service_admin_http SOURCES 
 	private/src/remote_service_admin_impl
-	private/src/export_registration_impl
-	private/src/import_registration_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 ${APRUTIL_LIBRARY} ${CURL_LIBRARIES})
+target_link_libraries(remote_service_admin_http celix_framework ${CURL_LIBRARIES})

Modified: celix/branches/celix_config_admin/remote_services/remote_service_admin_http/private/include/remote_service_admin_http_impl.h
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_services/remote_service_admin_http/private/include/remote_service_admin_http_impl.h?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_services/remote_service_admin_http/private/include/remote_service_admin_http_impl.h (original)
+++ celix/branches/celix_config_admin/remote_services/remote_service_admin_http/private/include/remote_service_admin_http_impl.h Mon Jan 19 12:26:54 2015
@@ -28,13 +28,17 @@
 #define REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
 
 #include "remote_service_admin_impl.h"
+#include "log_helper.h"
 #include "civetweb.h"
 
 struct remote_service_admin {
-	apr_pool_t *pool;
 	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;

Modified: celix/branches/celix_config_admin/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c (original)
+++ celix/branches/celix_config_admin/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c Mon Jan 19 12:26:54 2015
@@ -33,33 +33,23 @@
 #include "import_registration_impl.h"
 
 struct activator {
-	apr_pool_t *pool;
 	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;
-	apr_pool_t *parentPool = NULL;
-	apr_pool_t *pool = NULL;
 	struct activator *activator;
 
-	status = bundleContext_getMemoryPool(context, &parentPool);
-	if (status == CELIX_SUCCESS) {
-		if (apr_pool_create(&pool, parentPool) != APR_SUCCESS) {
-			status = CELIX_BUNDLE_EXCEPTION;
-		} else {
-			activator = apr_palloc(pool, sizeof(*activator));
-			if (!activator) {
-				status = CELIX_ENOMEM;
-			} else {
-				activator->pool = pool;
-				activator->admin = NULL;
-				activator->registration = NULL;
+	activator = calloc(1, sizeof(*activator));
+	if (!activator) {
+		status = CELIX_ENOMEM;
+	} else {
+		activator->admin = NULL;
+		activator->registration = NULL;
 
-				*userData = activator;
-			}
-		}
+		*userData = activator;
 	}
 
 	return status;
@@ -70,14 +60,15 @@ celix_status_t bundleActivator_start(voi
 	struct activator *activator = userData;
 	remote_service_admin_service_pt remoteServiceAdmin = NULL;
 
-	status = remoteServiceAdmin_create(activator->pool, context, &activator->admin);
+	status = remoteServiceAdmin_create(context, &activator->admin);
 	if (status == CELIX_SUCCESS) {
-		remoteServiceAdmin = apr_palloc(activator->pool, sizeof(*remoteServiceAdmin));
+		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;
@@ -97,6 +88,7 @@ celix_status_t bundleActivator_start(voi
 			remoteServiceAdmin->importRegistration_getImportReference = importRegistration_getImportReference;
 
 			status = bundleContext_registerService(context, OSGI_RSA_REMOTE_SERVICE_ADMIN, remoteServiceAdmin, NULL, &activator->registration);
+			activator->adminService = remoteServiceAdmin;
 		}
 	}
 
@@ -111,11 +103,17 @@ celix_status_t bundleActivator_stop(void
 	serviceRegistration_unregister(activator->registration);
 	activator->registration = NULL;
 
+	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;
 }
 

Modified: celix/branches/celix_config_admin/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c (original)
+++ celix/branches/celix_config_admin/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c Mon Jan 19 12:26:54 2015
@@ -34,10 +34,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
-#include <apr_strings.h>
-#include <apr_uuid.h>
 #include <uuid/uuid.h>
-#include <apr_network_io.h>
 
 #include <curl/curl.h>
 
@@ -51,7 +48,9 @@
 #include "bundle.h"
 #include "service_reference.h"
 #include "service_registration.h"
-#include "celix_log.h"
+#include "log_helper.h"
+#include "log_service.h"
+#include "celix_threads.h"
 
 // defines how often the webserver is restarted (with an increased port number)
 #define MAX_NUMBER_OF_RESTARTS 	5
@@ -66,12 +65,15 @@ struct get {
     int size;
 };
 
-static const char *response_headers =
+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";
@@ -90,22 +92,28 @@ static celix_status_t remoteServiceAdmin
 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 remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin) {
 	celix_status_t status = CELIX_SUCCESS;
 
-	*admin = apr_palloc(pool, sizeof(**admin));
+	*admin = calloc(1, sizeof(**admin));
 	if (!*admin) {
 		status = CELIX_ENOMEM;
 	} else {
 		unsigned int port_counter = 0;
 		char *port = NULL;
 		char *ip = NULL;
-
-		(*admin)->pool = pool;
+		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;
@@ -116,62 +124,84 @@ celix_status_t remoteServiceAdmin_create
 			char *interface = NULL;
 
 			bundleContext_getProperty(context, "RSA_INTERFACE", &interface);
-			if ((interface != NULL) && (remoteServiceAdmin_getIpAdress(interface, &ip) != CELIX_SUCCESS)) {
-				fw_log(logger, OSGI_FRAMEWORK_LOG_WARNING, "RSA: Could not retrieve IP adress for interface %s", 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, &ip);
+				remoteServiceAdmin_getIpAdress(NULL, &detectedIp);
 			}
+
+			ip = detectedIp;
 		}
 
 		if (ip != NULL) {
-			fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "RSA: Using %s for service annunciation", ip);
-			(*admin)->ip = apr_pstrdup(pool, ip);
+			logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Using %s for service annunciation", ip);
+			(*admin)->ip = strdup(ip);
 		}
 		else {
-			fw_log(logger, OSGI_FRAMEWORK_LOG_WARNING, "RSA: No IP address for service annunciation set. Using %s", DEFAULT_IP);
+			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) {
-				fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "RSA: Start webserver: %s", port);
-				(*admin)->port = port;
+				logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Start webserver: %s", port);
+				(*admin)->port = strdup(port);
+
 			}
 			else {
-				errno = 0;
-				char* newPort = calloc(10, sizeof(*newPort));
 		        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, 6,  "%d", (currentPort+1));
+				snprintf(&newPort[0], 6,  "%d", (currentPort+1));
 
-				fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Error while starting rsa server on port %s - retrying on port %s...", port, newPort);
+				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);
+	*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);
@@ -182,10 +212,17 @@ celix_status_t remoteServiceAdmin_stop(r
 		}
 	}
     hashMapIterator_destroy(iter);
+    celixThreadMutex_unlock(&admin->exportedServicesLock);
+
+    celixThreadMutex_lock(&admin->importedServicesLock);
+
     iter = hashMapIterator_create(admin->importedServices);
     while (hashMapIterator_hasNext(iter))
     {
-    	import_registration_factory_pt importFactory = hashMapIterator_nextValue(iter);
+    	hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+
+    	import_registration_factory_pt importFactory = hashMapEntry_getValue(entry);
+
         int i;
         for (i = 0; i < arrayList_size(importFactory->registrations); i++)
         {
@@ -193,14 +230,31 @@ celix_status_t remoteServiceAdmin_stop(r
 
 			if (importFactory->trackedFactory != NULL)
 			{
-				importFactory->trackedFactory->unregisterProxyService(importFactory->trackedFactory, importRegistration->endpointDescription);
+				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;
 }
@@ -217,10 +271,13 @@ static int remoteServiceAdmin_callback(s
 	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;
@@ -228,6 +285,8 @@ static int remoteServiceAdmin_callback(s
 			strncpy(service, rest, pos);
 			service[pos] = '\0';
 
+			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);
@@ -246,16 +305,21 @@ static int remoteServiceAdmin_callback(s
 						export->endpoint->handleRequest(export->endpoint->endpoint, data, &response);
 
 						if (response != NULL) {
-							mg_write(conn, response_headers, strlen(response_headers));
+						    mg_write(conn, data_response_headers, strlen(data_response_headers));
 							mg_write(conn, response, strlen(response));
 
-							result = 1;
+							free(response);
+						} else {
+						    mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
 						}
+                        result = 1;
 
 						free(data);
 					}
 				}
 			}
+			celixThreadMutex_unlock(&rsa->exportedServicesLock);
+
             hashMapIterator_destroy(iter);
 		}
 	}
@@ -264,6 +328,8 @@ static int remoteServiceAdmin_callback(s
 }
 
 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);
@@ -277,6 +343,9 @@ celix_status_t remoteServiceAdmin_handle
 		}
 	}
     hashMapIterator_destroy(iter);
+
+	celixThreadMutex_unlock(&rsa->exportedServicesLock);
+
 	return CELIX_SUCCESS;
 }
 
@@ -285,18 +354,14 @@ celix_status_t remoteServiceAdmin_export
 	arrayList_create(registrations);
 	array_list_pt references = NULL;
 	service_reference_pt reference = NULL;
-	apr_pool_t *tmpPool = NULL;
+	char filter [256];
 
-	apr_pool_create(&tmpPool, admin->pool);
-	if (tmpPool == NULL) {
-		return CELIX_ENOMEM;
-	} else {
-		char *filter = apr_pstrcat(admin->pool, "(", (char *)OSGI_FRAMEWORK_SERVICE_ID, "=", serviceId, ")", NULL); /*FIXME memory leak*/
-		bundleContext_getServiceReferences(admin->context, NULL, filter, &references);
-		apr_pool_destroy(tmpPool);
-		if (arrayList_size(references) >= 1) {
-			reference = arrayList_get(references, 0);
-		}
+	snprintf(filter, 256, "(%s=%s)", (char *)OSGI_FRAMEWORK_SERVICE_ID, serviceId);
+
+	bundleContext_getServiceReferences(admin->context, NULL, filter, &references);
+
+	if (arrayList_size(references) >= 1) {
+		reference = arrayList_get(references, 0);
 	}
 
     if(references!=NULL){
@@ -304,7 +369,7 @@ celix_status_t remoteServiceAdmin_export
     }
 
 	if (reference == NULL) {
-		fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "ERROR: expected a reference for service id %s.", serviceId);
+		logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "ERROR: expected a reference for service id %s.", serviceId);
 		return CELIX_ILLEGAL_STATE;
 	}
 
@@ -314,32 +379,28 @@ celix_status_t remoteServiceAdmin_export
 	serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_OBJECTCLASS, &provided);
 
 	if (exports == NULL || provided == NULL) {
-		fw_log(logger, OSGI_FRAMEWORK_LOG_WARNING, "RSA: No Services to export.");
+		logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No Services to export.");
 	} else {
-		fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "RSA: Export services (%s)", exports);
+		logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Export services (%s)", exports);
 		array_list_pt interfaces = NULL;
 		arrayList_create(&interfaces);
 		if (strcmp(utils_stringTrim(exports), "*") == 0) {
-			char *token;
-			char *interface = apr_strtok(provided, ",", &token);
+			char *interface = strtok(provided, ",");
 			while (interface != NULL) {
 				arrayList_add(interfaces, utils_stringTrim(interface));
-				interface = apr_strtok(NULL, ",", &token);
+				interface = strtok(NULL, ",");
 			}
 		} else {
-			char *exportToken;
-			char *providedToken;
-
-			char *pinterface = apr_strtok(provided, ",", &providedToken);
+			char *pinterface = strtok(provided, ",");
 			while (pinterface != NULL) {
-				char *einterface = apr_strtok(exports, ",", &exportToken);
+				char *einterface = strtok(exports, ",");
 				while (einterface != NULL) {
 					if (strcmp(einterface, pinterface) == 0) {
 						arrayList_add(interfaces, einterface);
 					}
-					einterface = apr_strtok(NULL, ",", &exportToken);
+					einterface = strtok(NULL, ",");
 				}
-				pinterface = apr_strtok(NULL, ",", &providedToken);
+				pinterface = strtok(NULL, ",");
 			}
 		}
 
@@ -349,14 +410,17 @@ celix_status_t remoteServiceAdmin_export
 				char *interface = arrayList_get(interfaces, iter);
 				export_registration_pt registration = NULL;
 
-				exportRegistration_create(admin->pool, reference, NULL, admin, admin->context, &registration);
+				exportRegistration_create(admin->loghelper, reference, NULL, admin, admin->context, &registration);
 				arrayList_add(*registrations, registration);
 
 				remoteServiceAdmin_installEndpoint(admin, registration, reference, interface);
 				exportRegistration_open(registration);
 				exportRegistration_startTracking(registration);
 			}
+			celixThreadMutex_lock(&admin->exportedServicesLock);
 			hashMap_put(admin->exportedServices, reference, *registrations);
+			celixThreadMutex_unlock(&admin->exportedServicesLock);
+
 		}
 		arrayList_destroy(interfaces);
 	}
@@ -368,8 +432,12 @@ celix_status_t remoteServiceAdmin_remove
     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;
 }
 
@@ -377,6 +445,7 @@ celix_status_t remoteServiceAdmin_instal
 	celix_status_t status = CELIX_SUCCESS;
 	properties_pt endpointProperties = properties_create();
 
+
 	unsigned int size = 0;
     char **keys;
 
@@ -385,16 +454,24 @@ celix_status_t remoteServiceAdmin_instal
         char *key = keys[i];
         char *value = NULL;
 
-        if (serviceReference_getProperty(reference, key, &value) == CELIX_SUCCESS)
+        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);
+        }
 	}
 
+	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];
-	sprintf(buf, "/service/%s/%s", serviceId, interface);
-    char *url = apr_pstrcat(admin->pool, "http://", admin->ip, ":", admin->port, buf, NULL);
+	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);
@@ -414,6 +491,10 @@ celix_status_t remoteServiceAdmin_instal
 	remoteServiceAdmin_createEndpointDescription(admin, reference, endpointProperties, interface, &endpointDescription);
 	exportRegistration_setEndpointDescription(registration, endpointDescription);
 
+	free(key);
+	free(serviceId);
+	free(keys);
+
 	return status;
 }
 
@@ -453,17 +534,14 @@ celix_status_t remoteServiceAdmin_create
 		properties_pt endpointProperties, char *interface, endpoint_description_pt *description) {
 	celix_status_t status = CELIX_SUCCESS;
 
-	apr_pool_t *childPool = NULL;
-	apr_pool_create(&childPool, admin->pool); //TODO pool should be destroyed after when endpoint is removed
-
-	*description = apr_palloc(childPool, sizeof(*description));
+	*description = calloc(1, sizeof(**description));
 	if (!*description) {
 		status = CELIX_ENOMEM;
 	} else {
 		(*description)->id = properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID);
 		char *serviceId = NULL;
 		serviceReference_getProperty(reference, (char*) OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
-		(*description)->serviceId = apr_atoi64(serviceId);
+		(*description)->serviceId = strtoull(serviceId, NULL, 0);
 		(*description)->frameworkUUID = properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
 		(*description)->service = interface;
 		(*description)->properties = endpointProperties;
@@ -472,6 +550,18 @@ celix_status_t remoteServiceAdmin_create
 	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;
@@ -487,14 +577,16 @@ celix_status_t remoteServiceAdmin_getImp
 celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpointDescription, import_registration_pt *registration) {
 	celix_status_t status = CELIX_SUCCESS;
 
-	fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "RSA: Import service %s", endpointDescription->service);
+	logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Import service %s", endpointDescription->service);
+
+	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->pool, endpointDescription->service, admin->context, &registration_factory);
+		status = importRegistrationFactory_install(admin->loghelper, endpointDescription->service, admin->context, &registration_factory);
 		if (status == CELIX_SUCCESS) {
 		    hashMap_put(admin->importedServices, endpointDescription->service, registration_factory);
 		}
@@ -503,17 +595,23 @@ celix_status_t remoteServiceAdmin_import
 	 // factory available
 	if (status != CELIX_SUCCESS || (registration_factory->trackedFactory == NULL))
 	{
-		fw_log(logger, OSGI_FRAMEWORK_LOG_WARNING, "RSA: no proxyFactory available.");
+		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(admin->pool, endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send, admin->context, registration);
-		registration_factory->trackedFactory->registerProxyService(registration_factory->trackedFactory,  endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send);
+		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;
 }
 
@@ -521,31 +619,38 @@ celix_status_t remoteServiceAdmin_import
 celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration) {
 	celix_status_t status = CELIX_SUCCESS;
 	endpoint_description_pt endpointDescription = (endpoint_description_pt) registration->endpointDescription;
-	import_registration_factory_pt registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
+	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))
     {
-    	fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "RSA: Error while retrieving registration factory for imported service %s", endpointDescription->service);
+    	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, endpointDescription);
+		registration_factory->trackedFactory->unregisterProxyService(registration_factory->trackedFactory->factory, endpointDescription);
 		arrayList_removeElement(registration_factory->registrations, registration);
 		importRegistration_destroy(registration);
 
 		if (arrayList_isEmpty(registration_factory->registrations))
 		{
-			fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "RSA: closing proxy");
+			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;
 }
 
@@ -561,7 +666,8 @@ celix_status_t remoteServiceAdmin_send(r
     get.writeptr = malloc(1);
 
     char *serviceUrl = properties_get(endpointDescription->properties, (char*) ENDPOINT_URL);
-    char *url = apr_pstrcat(rsa->pool, serviceUrl, NULL);
+    char url[256];
+    snprintf(url, 256, "%s", serviceUrl);
 
     celix_status_t status = CELIX_SUCCESS;
     CURL *curl;
@@ -571,7 +677,7 @@ celix_status_t remoteServiceAdmin_send(r
     if(!curl) {
         status = CELIX_ILLEGAL_STATE;
     } else {
-        curl_easy_setopt(curl, CURLOPT_URL, url);
+        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);
@@ -608,7 +714,7 @@ static size_t remoteServiceAdmin_write(v
   mem->writeptr = realloc(mem->writeptr, mem->size + realsize + 1);
   if (mem->writeptr == NULL) {
     /* out of memory! */
-	  fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "not enough memory (realloc returned NULL)");
+	printf("not enough memory (realloc returned NULL)");
     exit(EXIT_FAILURE);
   }
 

Modified: celix/branches/celix_config_admin/remote_services/remote_service_admin_shm/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_services/remote_service_admin_shm/CMakeLists.txt?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_services/remote_service_admin_shm/CMakeLists.txt (original)
+++ celix/branches/celix_config_admin/remote_services/remote_service_admin_shm/CMakeLists.txt Mon Jan 19 12:26:54 2015
@@ -14,11 +14,12 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-celix_subproject(RSA_BUNDLES_REMOTE_SERVICE_ADMIN_SHM "Option to enable	building the Remote Service Admin Service SHM bundle" ON DEPS LAUNCHER topology_manager remote_service_admin)
+celix_subproject(RSA_BUNDLES_REMOTE_SERVICE_ADMIN_SHM "Option to enable	building the Remote Service Admin Service SHM bundle" OFF DEPS LAUNCHER topology_manager remote_service_admin)
 if (RSA_BUNDLES_REMOTE_SERVICE_ADMIN_SHM)
 	link_directories("/opt/local/lib")
 	include_directories("/opt/local/include")
 	include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
+	include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
 	include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
 	include_directories("${PROJECT_SOURCE_DIR}/framework/private/include")
 	include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/public/include")
@@ -34,18 +35,17 @@ if (RSA_BUNDLES_REMOTE_SERVICE_ADMIN_SHM
 
 	bundle(remote_service_admin_shm SOURCES 
 		private/src/remote_service_admin_impl
-		private/src/export_registration_impl
-		private/src/import_registration_impl
-		private/src/remote_service_admin_activator
+        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}/log_service/public/src/log_helper.c
 	)
 
 	install_bundle(remote_service_admin_shm
 		HEADERS
-			${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include/remote_endpoint_impl.h
-			${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include/remote_endpoint.h
-			${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include/remote_proxy.h
-			${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include/remote_service_admin.h
+			${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_shm/public/include/remote_service_admin_shm.h
 	)
 
 	target_link_libraries(remote_service_admin_shm celix_framework ${APRUTIL_LIBRARY})
 endif (RSA_BUNDLES_REMOTE_SERVICE_ADMIN_SHM)
+

Modified: celix/branches/celix_config_admin/remote_services/remote_service_admin_shm/private/src/remote_service_admin_activator.c
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_services/remote_service_admin_shm/private/src/remote_service_admin_activator.c?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_services/remote_service_admin_shm/private/src/remote_service_admin_activator.c (original)
+++ celix/branches/celix_config_admin/remote_services/remote_service_admin_shm/private/src/remote_service_admin_activator.c Mon Jan 19 12:26:54 2015
@@ -120,10 +120,13 @@ celix_status_t bundleActivator_destroy(v
 	struct activator *activator = userData;
 
 	if(activator==NULL || activator->admin==NULL){
-		return CELIX_BUNDLE_EXCEPTION;
+		status = CELIX_BUNDLE_EXCEPTION;
+	}
+	else {
+		status = remoteServiceAdmin_destroy(activator->admin);
 	}
 
-	return remoteServiceAdmin_destroy(activator->admin);
+	return status;
 }
 
 

Modified: celix/branches/celix_config_admin/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c (original)
+++ celix/branches/celix_config_admin/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c Mon Jan 19 12:26:54 2015
@@ -67,7 +67,6 @@ celix_status_t remoteServiceAdmin_getSha
 celix_status_t remoteServiceAdmin_removeSharedIdentityFile(char *fwUuid, char* servicename);
 celix_status_t remoteServiceAdmin_removeSharedIdentityFiles(char* fwUuid);
 
-static bool lockHolder[3];
 
 celix_status_t remoteServiceAdmin_create(apr_pool_t *pool, bundle_context_pt context, remote_service_admin_pt *admin)
 {
@@ -124,7 +123,7 @@ celix_status_t remoteServiceAdmin_stop(r
 
 			if (importFactory->trackedFactory != NULL)
 			{
-				importFactory->trackedFactory->unregisterProxyService(importFactory->trackedFactory, importRegistration->endpointDescription);
+				importFactory->trackedFactory->unregisterProxyService(importFactory->trackedFactory->factory, importRegistration->endpointDescription);
 			}
         }
 
@@ -633,7 +632,8 @@ celix_status_t remoteServiceAdmin_export
                 char *interface = arrayList_get(interfaces, iter);
                 export_registration_pt registration = NULL;
 
-                exportRegistration_create(admin->pool, reference, NULL, admin, admin->context, &registration);
+                // TODO: add logHelper reference
+                exportRegistration_create(admin->pool, NULL, reference, NULL, admin, admin->context, &registration);
 
                 arrayList_add(*registrations, registration);
 
@@ -747,7 +747,6 @@ celix_status_t remoteServiceAdmin_delete
 celix_status_t remoteServiceAdmin_createOrAttachShm(hash_map_pt ipcSegment, remote_service_admin_pt admin, endpoint_description_pt endpointDescription, bool createIfNotFound)
 {
     celix_status_t status = CELIX_SUCCESS;
-    apr_status_t aprStatus = 0;
 
     /* setup ipc sehment */
     ipc_segment_pt ipc = NULL;
@@ -971,7 +970,8 @@ celix_status_t remoteServiceAdmin_import
 	// check whether we already have a registration_factory
 	if (registration_factory == NULL)
 	{
-		importRegistrationFactory_install(admin->pool, endpointDescription->service, admin->context, &registration_factory);
+	    // TODO: Add logHelper
+		importRegistrationFactory_install(admin->pool, NULL, endpointDescription->service, admin->context, &registration_factory);
 		hashMap_put(admin->importedServices, endpointDescription->service, registration_factory);
 	}
 
@@ -984,7 +984,7 @@ celix_status_t remoteServiceAdmin_import
 	{
 		// we create an importRegistration per imported service
 		importRegistration_create(admin->pool, endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send, admin->context, registration);
-		registration_factory->trackedFactory->registerProxyService(registration_factory->trackedFactory,  endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send);
+		registration_factory->trackedFactory->registerProxyService(registration_factory->trackedFactory->factory,  endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send);
 
 		arrayList_add(registration_factory->registrations, *registration);
 		remoteServiceAdmin_createOrAttachShm(admin->importedIpcSegment, admin, endpointDescription, false);
@@ -1022,7 +1022,7 @@ celix_status_t remoteServiceAdmin_remove
 		}
 		else
 		{
-			registration_factory->trackedFactory->unregisterProxyService(registration_factory->trackedFactory, endpointDescription);
+			registration_factory->trackedFactory->unregisterProxyService(registration_factory->trackedFactory->factory, endpointDescription);
 			arrayList_removeElement(registration_factory->registrations, registration);
 			importRegistration_destroy(registration);
 

Modified: celix/branches/celix_config_admin/remote_services/topology_manager/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_services/topology_manager/CMakeLists.txt?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_services/topology_manager/CMakeLists.txt (original)
+++ celix/branches/celix_config_admin/remote_services/topology_manager/CMakeLists.txt Mon Jan 19 12:26:54 2015
@@ -20,6 +20,7 @@ include_directories("${PROJECT_SOURCE_DI
 include_directories("${PROJECT_SOURCE_DIR}/remote_services/topology_manager/private/include")
 include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
 include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
+include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
 
 SET_HEADER(BUNDLE_SYMBOLICNAME "apache_celix_rs_topology_manager")
 SET(BUNDLE_VERSION "0.0.1")
@@ -29,6 +30,8 @@ bundle(topology_manager SOURCES
     private/src/topology_manager
     private/src/activator
     
+    ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
+    
     private/include/topology_manager.h
 )
 

Modified: celix/branches/celix_config_admin/remote_services/topology_manager/private/include/topology_manager.h
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_services/topology_manager/private/include/topology_manager.h?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_services/topology_manager/private/include/topology_manager.h (original)
+++ celix/branches/celix_config_admin/remote_services/topology_manager/private/include/topology_manager.h Mon Jan 19 12:26:54 2015
@@ -30,11 +30,13 @@
 #include "endpoint_listener.h"
 #include "service_reference.h"
 #include "bundle_context.h"
+#include "log_helper.h"
 
 typedef struct topology_manager *topology_manager_pt;
 
-celix_status_t topologyManager_create(bundle_context_pt context, topology_manager_pt *manager);
+celix_status_t topologyManager_create(bundle_context_pt context, log_helper_pt logHelper, topology_manager_pt *manager);
 celix_status_t topologyManager_destroy(topology_manager_pt manager);
+celix_status_t topologyManager_closeImports(topology_manager_pt manager);
 
 celix_status_t topologyManager_rsaAdding(void *handle, service_reference_pt reference, void **service);
 celix_status_t topologyManager_rsaAdded(void *handle, service_reference_pt reference, void *service);

Modified: celix/branches/celix_config_admin/remote_services/topology_manager/private/src/activator.c
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_services/topology_manager/private/src/activator.c?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_services/topology_manager/private/src/activator.c (original)
+++ celix/branches/celix_config_admin/remote_services/topology_manager/private/src/activator.c Mon Jan 19 12:26:54 2015
@@ -36,6 +36,8 @@
 #include "endpoint_listener.h"
 #include "remote_constants.h"
 #include "listener_hook_service.h"
+#include "log_service.h"
+#include "log_helper.h"
 
 struct activator {
 	bundle_context_pt context;
@@ -45,8 +47,13 @@ struct activator {
 	service_tracker_pt remoteServiceAdminTracker;
 	service_listener_pt serviceListener;
 
+	endpoint_listener_pt endpointListener;
 	service_registration_pt endpointListenerService;
+
+	listener_hook_service_pt hookService;
 	service_registration_pt hook;
+
+	log_helper_pt loghelper;
 };
 
 static celix_status_t bundleActivator_createRSATracker(struct activator *activator, service_tracker_pt *tracker);
@@ -57,6 +64,7 @@ celix_status_t bundleActivator_create(bu
 	struct activator *activator = NULL;
 
 	activator = malloc(sizeof(struct activator));
+
 	if (!activator) {
 		return CELIX_ENOMEM;
 	}
@@ -68,7 +76,10 @@ celix_status_t bundleActivator_create(bu
 	activator->remoteServiceAdminTracker = NULL;
 	activator->serviceListener = NULL;
 
-	status = topologyManager_create(context, &activator->manager);
+	logHelper_create(context, &activator->loghelper);
+	logHelper_start(activator->loghelper);
+
+	status = topologyManager_create(context, activator->loghelper, &activator->manager);
 	if (status == CELIX_SUCCESS) {
 		status = bundleActivator_createRSATracker(activator, &activator->remoteServiceAdminTracker);
 		if (status == CELIX_SUCCESS) {
@@ -119,11 +130,12 @@ celix_status_t bundleActivator_start(voi
 	endpointListener->handle = activator->manager;
 	endpointListener->endpointAdded = topologyManager_addImportedService;
 	endpointListener->endpointRemoved = topologyManager_removeImportedService;
+	activator->endpointListener = endpointListener;
 
 	char *uuid = NULL;
 	status = bundleContext_getProperty(activator->context, (char *)OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
 	if (!uuid) {
-		fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "TOPOLOGY_MANAGER: no framework UUID defined?!");
+		logHelper_log(activator->loghelper, OSGI_LOGSERVICE_ERROR, "TOPOLOGY_MANAGER: no framework UUID defined?!");
 		return CELIX_ILLEGAL_STATE;
 	}
 
@@ -135,7 +147,7 @@ celix_status_t bundleActivator_start(voi
 
 	snprintf(scope, len, "(&(%s=*)(!(%s=%s)))", OSGI_FRAMEWORK_OBJECTCLASS, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
 
-	fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "TOPOLOGY_MANAGER: endpoint listener scope is %s", scope);
+	logHelper_log(activator->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: endpoint listener scope is %s", scope);
 
 	properties_pt props = properties_create();
 	properties_set(props, (char *) OSGI_ENDPOINT_LISTENER_SCOPE, scope);
@@ -145,12 +157,13 @@ celix_status_t bundleActivator_start(voi
 
 	bundleContext_registerService(context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, endpointListener, props, &activator->endpointListenerService);
 
-	listener_hook_service_pt hook = malloc(sizeof(*hook));
-	hook->handle = activator->manager;
-	hook->added = topologyManager_listenerAdded;
-	hook->removed = topologyManager_listenerRemoved;
+	listener_hook_service_pt hookService = malloc(sizeof(*hookService));
+	hookService->handle = activator->manager;
+	hookService->added = topologyManager_listenerAdded;
+	hookService->removed = topologyManager_listenerRemoved;
+	activator->hookService = hookService;
 
-	bundleContext_registerService(context, (char *) OSGI_FRAMEWORK_LISTENER_HOOK_SERVICE_NAME, hook, NULL, &activator->hook);
+	bundleContext_registerService(context, (char *) OSGI_FRAMEWORK_LISTENER_HOOK_SERVICE_NAME, hookService, NULL, &activator->hook);
 
 	bundleContext_addServiceListener(context, activator->serviceListener, "(service.exported.interfaces=*)");
 	serviceTracker_open(activator->remoteServiceAdminTracker);
@@ -165,6 +178,8 @@ celix_status_t bundleActivator_start(voi
         status = CELIX_DO_IF(status, topologyManager_addExportedService(activator->manager, reference, serviceId));
 	}
 
+	arrayList_destroy(references);
+
 	return status;
 }
 
@@ -173,20 +188,36 @@ celix_status_t bundleActivator_stop(void
 	struct activator *activator = userData;
 
 	serviceTracker_close(activator->remoteServiceAdminTracker);
+	serviceTracker_destroy(activator->remoteServiceAdminTracker);
 
 	bundleContext_removeServiceListener(context, activator->serviceListener);
+	free(activator->serviceListener);
 
 	serviceRegistration_unregister(activator->hook);
+	free(activator->hookService);
+
 	serviceRegistration_unregister(activator->endpointListenerService);
+	free(activator->endpointListener);
+
+	topologyManager_closeImports(activator->manager);
 
 	return status;
 }
 
 celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+	celix_status_t status = CELIX_SUCCESS;
+
 	struct activator *activator = userData;
 	if (!activator || !activator->manager) {
-		return CELIX_BUNDLE_EXCEPTION;
+		status = CELIX_BUNDLE_EXCEPTION;
 	}
+	else {
+		logHelper_stop(activator->loghelper);
+		logHelper_destroy(&activator->loghelper);
 
-	return topologyManager_destroy(activator->manager);
+		status = topologyManager_destroy(activator->manager);
+		free(activator);
+	}
+
+	return status;
 }

Modified: celix/branches/celix_config_admin/remote_services/topology_manager/private/src/topology_manager.c
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_services/topology_manager/private/src/topology_manager.c?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_services/topology_manager/private/src/topology_manager.c (original)
+++ celix/branches/celix_config_admin/remote_services/topology_manager/private/src/topology_manager.c Mon Jan 19 12:26:54 2015
@@ -38,6 +38,9 @@
 #include "utils.h"
 #include "service_reference.h"
 #include "service_registration.h"
+#include "log_service.h"
+#include "log_helper.h"
+
 
 struct topology_manager {
 	bundle_context_pt context;
@@ -53,6 +56,8 @@ struct topology_manager {
 
 	celix_thread_mutex_t importInterestsLock;
 	hash_map_pt importInterests;
+
+	log_helper_pt loghelper;
 };
 
 struct import_interest {
@@ -63,7 +68,7 @@ struct import_interest {
 celix_status_t topologyManager_notifyListenersEndpointAdded(topology_manager_pt manager, remote_service_admin_service_pt rsa,  array_list_pt registrations);
 celix_status_t topologyManager_notifyListenersEndpointRemoved(topology_manager_pt manager, remote_service_admin_service_pt rsa,  export_registration_pt export);
 
-celix_status_t topologyManager_create(bundle_context_pt context, topology_manager_pt *manager) {
+celix_status_t topologyManager_create(bundle_context_pt context, log_helper_pt logHelper, topology_manager_pt *manager) {
 	celix_status_t status = CELIX_SUCCESS;
 
 	*manager = malloc(sizeof(**manager));
@@ -84,6 +89,8 @@ celix_status_t topologyManager_create(bu
 	(*manager)->importedServices = hashMap_create(NULL, NULL, NULL, NULL);
 	(*manager)->importInterests = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
 
+	(*manager)->loghelper = logHelper;
+
 	return status;
 }
 
@@ -113,7 +120,7 @@ celix_status_t topologyManager_destroy(t
 
 	status = celixThreadMutex_lock(&manager->importInterestsLock);
 
-	hashMap_destroy(manager->importInterests, false, false);
+	hashMap_destroy(manager->importInterests, true, true);
 
 	status = celixThreadMutex_unlock(&manager->importInterestsLock);
 	status = celixThreadMutex_destroy(&manager->importInterestsLock);
@@ -123,6 +130,46 @@ celix_status_t topologyManager_destroy(t
 	return status;
 }
 
+celix_status_t topologyManager_closeImports(topology_manager_pt manager) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	status = celixThreadMutex_lock(&manager->importedServicesLock);
+
+	hash_map_iterator_pt iter = hashMapIterator_create(manager->importedServices);
+	while (hashMapIterator_hasNext(iter)) {
+		hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+		endpoint_description_pt ep = hashMapEntry_getKey(entry);
+		hash_map_pt imports = hashMapEntry_getValue(entry);
+
+		logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Remove imported service (%s; %s).", ep->service, ep->id);
+		hash_map_iterator_pt importsIter = hashMapIterator_create(imports);
+
+		while (hashMapIterator_hasNext(importsIter)) {
+			hash_map_entry_pt entry = hashMapIterator_nextEntry(importsIter);
+
+			remote_service_admin_service_pt rsa = hashMapEntry_getKey(entry);
+			import_registration_pt import = hashMapEntry_getValue(entry);
+
+			status = rsa->importRegistration_close(rsa->admin, import);
+			if (status == CELIX_SUCCESS) {
+				hashMapIterator_remove(importsIter);
+			}
+		}
+		hashMapIterator_destroy(importsIter);
+
+		hashMapIterator_remove(iter);
+
+		if (imports != NULL) {
+			hashMap_destroy(imports, false, false);
+		}
+	}
+	hashMapIterator_destroy(iter);
+
+	status = celixThreadMutex_unlock(&manager->importedServicesLock);
+
+	return status;
+}
+
 
 celix_status_t topologyManager_rsaAdding(void * handle, service_reference_pt reference, void **service) {
 	celix_status_t status = CELIX_SUCCESS;
@@ -137,7 +184,7 @@ celix_status_t topologyManager_rsaAdded(
 	celix_status_t status = CELIX_SUCCESS;
 	topology_manager_pt manager = handle;
 	remote_service_admin_service_pt rsa = (remote_service_admin_service_pt) service;
-	fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "TOPOLOGY_MANAGER: Added RSA");
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Added RSA");
 
 	status = celixThreadMutex_lock(&manager->rsaListLock);
 	arrayList_add(manager->rsaList, rsa);
@@ -156,10 +203,17 @@ celix_status_t topologyManager_rsaAdded(
 
 		if (status == CELIX_SUCCESS) {
 		    hash_map_pt imports = hashMapEntry_getValue(entry);
+
+			if (imports == NULL) {
+				imports = hashMap_create(NULL, NULL, NULL, NULL);
+			}
+
 			hashMap_put(imports, service, import);
 		}
 	}
 
+    hashMapIterator_destroy(importedServicesIterator);
+
 	status = celixThreadMutex_unlock(&manager->importedServicesLock);
 
 	// add already exported services to new rsa
@@ -178,11 +232,18 @@ celix_status_t topologyManager_rsaAdded(
 
 		if (status == CELIX_SUCCESS) {
 			hash_map_pt exports = hashMapEntry_getValue(entry);
+
+			if (exports == NULL) {
+				exports = hashMap_create(NULL, NULL, NULL, NULL);
+			}
+
 			hashMap_put(exports, rsa, endpoints);
 			status = topologyManager_notifyListenersEndpointAdded(manager, rsa, endpoints);
 		}
     }
 
+    hashMapIterator_destroy(exportedServicesIterator);
+
 	status = celixThreadMutex_unlock(&manager->exportedServicesLock);
 
 	return status;
@@ -200,10 +261,11 @@ celix_status_t topologyManager_rsaRemove
     celix_status_t status = CELIX_SUCCESS;
     topology_manager_pt manager = handle;
 
-    fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "TOPOLOGY_MANAGER: Removed RSA");
+    logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Removed RSA");
 
     remote_service_admin_service_pt rsa = (remote_service_admin_service_pt) service;
 
+
     status = celixThreadMutex_lock(&manager->exportedServicesLock);
 
     hash_map_iterator_pt iter = hashMapIterator_create(manager->exportedServices);
@@ -211,14 +273,18 @@ celix_status_t topologyManager_rsaRemove
     while (hashMapIterator_hasNext(iter)) {
         int exportsIter = 0;
 
-        hash_map_pt exports = hashMapIterator_nextValue(iter);
+        hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+
+        service_reference_pt key = hashMapEntry_getKey(entry);
+        hash_map_pt exports = hashMapEntry_getValue(entry);
+
         array_list_pt exports_list = hashMap_get(exports, rsa);
 
         if (exports_list != NULL) {
             for (exportsIter = 0; exportsIter < arrayList_size(exports_list); exportsIter++) {
                 export_registration_pt export = arrayList_get(exports_list, exportsIter);
-                rsa->exportRegistration_close(export);
                 topologyManager_notifyListenersEndpointRemoved(manager, rsa, export);
+                rsa->exportRegistration_close(export);
             }
 
             arrayList_destroy(exports_list);
@@ -226,11 +292,22 @@ celix_status_t topologyManager_rsaRemove
         }
 
         hashMap_remove(exports, rsa);
-        rsa = NULL;
+
+        if (hashMap_size(exports) == 0) {
+        	hashMap_remove(manager->exportedServices, key);
+        	hashMap_destroy(exports, false, false);
+
+            hashMapIterator_destroy(iter);
+            iter = hashMapIterator_create(manager->exportedServices);
+        }
+
     }
+
+    hashMapIterator_destroy(iter);
+
     status = celixThreadMutex_unlock(&manager->exportedServicesLock);
 
-    fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "TOPOLOGY_MANAGER: Removed RSA");
+    logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Removed RSA");
 
     status = celixThreadMutex_lock(&manager->rsaListLock);
     arrayList_removeElement(manager->rsaList, rsa);
@@ -291,7 +368,7 @@ celix_status_t topologyManager_addImport
 	celix_status_t status = CELIX_SUCCESS;
 	topology_manager_pt manager = handle;
 
-	fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "TOPOLOGY_MANAGER: Add imported service (%s; %s).", endpoint->service, endpoint->id);
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Add imported service (%s; %s).", endpoint->service, endpoint->id);
 
 	// Create a local copy of the current list of RSAs, to ensure we do not run into threading issues...
 	array_list_pt localRSAs = NULL;
@@ -313,6 +390,8 @@ celix_status_t topologyManager_addImport
 		}
 	}
 
+	arrayList_destroy(localRSAs);
+
 	status = celixThreadMutex_unlock(&manager->importedServicesLock);
 
 	return status;
@@ -322,7 +401,7 @@ celix_status_t topologyManager_removeImp
 	celix_status_t status = CELIX_SUCCESS;
 	topology_manager_pt manager = handle;
 
-	fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "TOPOLOGY_MANAGER: Remove imported service (%s; %s).", endpoint->service, endpoint->id);
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Remove imported service (%s; %s).", endpoint->service, endpoint->id);
 
 	status = celixThreadMutex_lock(&manager->importedServicesLock);
 
@@ -343,11 +422,17 @@ celix_status_t topologyManager_removeImp
 
                 status = rsa->importRegistration_close(rsa->admin, import);
                 if (status == CELIX_SUCCESS) {
-                    hashMap_remove(imports, rsa);
+                    hashMapIterator_remove(importsIter);
                 }
             }
-
             hashMapIterator_destroy(importsIter);
+
+        	hashMapIterator_remove(iter);
+
+        	if (imports != NULL) {
+        		hashMap_destroy(imports, false, false);
+        	}
+
 	    }
 	}
 	hashMapIterator_destroy(iter);
@@ -360,7 +445,7 @@ celix_status_t topologyManager_removeImp
 celix_status_t topologyManager_addExportedService(topology_manager_pt manager, service_reference_pt reference, char *serviceId) {
 	celix_status_t status = CELIX_SUCCESS;
 
-	fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "TOPOLOGY_MANAGER: Add exported service (%s).", serviceId);
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Add exported service (%s).", serviceId);
 
 	// Create a local copy of the current list of RSAs, to ensure we do not run into threading issues...
 	array_list_pt localRSAs = NULL;
@@ -373,7 +458,7 @@ celix_status_t topologyManager_addExport
 
 	int size = arrayList_size(localRSAs);
 	if (size == 0) {
-		fw_log(logger, OSGI_FRAMEWORK_LOG_WARNING, "TOPOLOGY_MANAGER: No RSA available yet.");
+		logHelper_log(manager->loghelper, OSGI_LOGSERVICE_WARNING, "TOPOLOGY_MANAGER: No RSA available yet.");
 	}
 
 	for (int iter = 0; iter < size; iter++) {
@@ -388,6 +473,8 @@ celix_status_t topologyManager_addExport
 		}
 	}
 
+	arrayList_destroy(localRSAs);
+
 	status = celixThreadMutex_unlock(&manager->exportedServicesLock);
 
 	return status;
@@ -396,7 +483,7 @@ celix_status_t topologyManager_addExport
 celix_status_t topologyManager_removeExportedService(topology_manager_pt manager, service_reference_pt reference, char *serviceId) {
 	celix_status_t status = CELIX_SUCCESS;
 
-	fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "TOPOLOGY_MANAGER: Remove exported service (%s).", serviceId);
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Remove exported service (%s).", serviceId);
 
 	status = celixThreadMutex_lock(&manager->exportedServicesLock);
 
@@ -407,20 +494,30 @@ celix_status_t topologyManager_removeExp
 			hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
 
 			remote_service_admin_service_pt rsa = hashMapEntry_getKey(entry);
-			array_list_pt exports = hashMapEntry_getValue(entry);
-
-			for (int exportsIter = 0; exportsIter < arrayList_size(exports); exportsIter++) {
-				export_registration_pt export = arrayList_get(exports, exportsIter);
-				rsa->exportRegistration_close(export);
+			array_list_pt exportRegistrations = hashMapEntry_getValue(entry);
 
+			for (int exportsIter = 0; exportsIter < arrayList_size(exportRegistrations); exportsIter++) {
+				export_registration_pt export = arrayList_get(exportRegistrations, exportsIter);
 				topologyManager_notifyListenersEndpointRemoved(manager, rsa, export);
+				rsa->exportRegistration_close(export);
 			}
-			arrayList_destroy(exports);
-			exports = NULL;
+			arrayList_destroy(exportRegistrations);
+			exportRegistrations = NULL;
+
+			hashMap_remove(exports, rsa);
+			hashMapIterator_destroy(iter);
+			iter = hashMapIterator_create(exports);
+
 		}
 		hashMapIterator_destroy(iter);
 	}
 
+	exports = hashMap_remove(manager->exportedServices, reference);
+
+	if (exports != NULL) {
+		hashMap_destroy(exports, false, false);
+    }
+
 	status = celixThreadMutex_unlock(&manager->exportedServicesLock);
 
 	return status;
@@ -431,11 +528,12 @@ celix_status_t topologyManager_getEndpoi
 
 	export_reference_pt reference = NULL;
 	status = rsa->exportRegistration_getExportReference(export, &reference);
-	if (status != CELIX_SUCCESS) {
-		return status;
+
+	if (status == CELIX_SUCCESS) {
+	    status = rsa->exportReference_getExportedEndpoint(reference, endpoint);
 	}
 
-	status = rsa->exportReference_getExportedEndpoint(reference, endpoint);
+	free(reference);
 
 	return status;
 }
@@ -525,13 +623,14 @@ celix_status_t topologyManager_notifyLis
 	return status;
 }
 
-celix_status_t topologyManager_extendFilter(bundle_context_pt context, char *filter, char **updatedFilter) {
+celix_status_t topologyManager_extendFilter(topology_manager_pt manager, char *filter, char **updatedFilter) {
 	celix_status_t status = CELIX_SUCCESS;
-
+	bundle_context_pt context = manager->context;
 	char* uuid = NULL;
+
 	status = bundleContext_getProperty(context, (char *)OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
 	if (!uuid) {
-		fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "TOPOLOGY_MANAGER: no framework UUID defined?!");
+		logHelper_log(manager->loghelper, OSGI_LOGSERVICE_ERROR, "TOPOLOGY_MANAGER: no framework UUID defined?!");
 		return CELIX_BUNDLE_EXCEPTION;
 	}
 
@@ -557,20 +656,21 @@ celix_status_t topologyManager_listenerA
 		bundleContext_getBundle(info->context, &bundle);
 		bundleContext_getBundle(manager->context, &self);
 		if (bundle == self) {
-			fw_log(logger, OSGI_FRAMEWORK_LOG_DEBUG, "TOPOLOGY_MANAGER: Ignore myself.");
+			logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "TOPOLOGY_MANAGER: Ignore myself.");
 			continue;
 		}
 
-		fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "TOPOLOGY_MANAGER: listener with filter \"%s\" added", info->filter);
+		logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: listener with filter \"%s\" added", info->filter);
 
 		char *filter = NULL;
-		topologyManager_extendFilter(manager->context, info->filter, &filter);
+		topologyManager_extendFilter(manager, info->filter, &filter);
 
 		status = celixThreadMutex_lock(&manager->importInterestsLock);
 
 		struct import_interest *interest = hashMap_get(manager->importInterests, filter);
 		if (interest) {
 			interest->refs++;
+			free(filter);
 		} else {
 			interest = malloc(sizeof(*interest));
 			interest->filter = filter;
@@ -595,22 +695,30 @@ celix_status_t topologyManager_listenerR
 		bundleContext_getBundle(info->context, &bundle);
 		bundleContext_getBundle(manager->context, &self);
 		if (bundle == self) {
-			fw_log(logger, OSGI_FRAMEWORK_LOG_DEBUG, "TOPOLOGY_MANAGER: Ignore myself.");
+			logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "TOPOLOGY_MANAGER: Ignore myself.");
 			continue;
 		}
 
-		fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "TOPOLOGY_MANAGER: listener with filter \"%s\" removed.", info->filter);
+		logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: listener with filter \"%s\" removed.", info->filter);
 
 		char *filter = NULL;
-		topologyManager_extendFilter(manager->context, info->filter, &filter);
+		topologyManager_extendFilter(manager, info->filter, &filter);
 
 		status = celixThreadMutex_lock(&manager->importInterestsLock);
 
 		struct import_interest *interest = hashMap_get(manager->importInterests, filter);
-		if (interest != NULL && interest->refs-- <= 0) {
-			// last reference, remove from scope
-			interest = hashMap_remove(manager->importInterests, filter);
-		}
+        if (interest != NULL && --interest->refs <= 0) {
+            // last reference, remove from scope
+            hash_map_entry_pt entry = hashMap_getEntry(manager->importInterests, filter);
+            char* key = (char*) hashMapEntry_getKey(entry);
+            interest = hashMap_remove(manager->importInterests, filter);
+            free(key);
+            free(interest);
+        }
+
+        if (filter != NULL) {
+            free(filter);
+        }
 
 		status = celixThreadMutex_unlock(&manager->importInterestsLock);
 	}

Modified: celix/branches/celix_config_admin/remote_shell/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_shell/CMakeLists.txt?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_shell/CMakeLists.txt (original)
+++ celix/branches/celix_config_admin/remote_shell/CMakeLists.txt Mon Jan 19 12:26:54 2015
@@ -27,6 +27,8 @@ if (REMOTE_SHELL)
     	private/src/shell_mediator 
     	private/src/remote_shell
 
+		${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
+		
 		private/include/remote_shell.h
 		private/include/connection_listener.h
 	)
@@ -36,6 +38,7 @@ if (REMOTE_SHELL)
     include_directories("private/include")
     include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
     include_directories("${PROJECT_SOURCE_DIR}/shell/public/include")
+    include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
     
-    target_link_libraries(remote_shell celix_framework ${APRUTIL_LIBRARY})
+    target_link_libraries(remote_shell celix_framework)
 endif (REMOTE_SHELL)
\ No newline at end of file

Modified: celix/branches/celix_config_admin/remote_shell/private/include/connection_listener.h
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_shell/private/include/connection_listener.h?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_shell/private/include/connection_listener.h (original)
+++ celix/branches/celix_config_admin/remote_shell/private/include/connection_listener.h Mon Jan 19 12:26:54 2015
@@ -27,8 +27,6 @@
 #ifndef connectionListener_H_
 #define connectionListener_H_
 
-#include <apr_pools.h>
-
 #include <bundle_context.h>
 #include <celix_errno.h>
 
@@ -36,8 +34,8 @@
 
 typedef struct connection_listener *connection_listener_pt;
 
-celix_status_t connectionListener_create(apr_pool_t *pool, remote_shell_pt remoteShell, apr_size_t port, connection_listener_pt *instance);
-
+celix_status_t connectionListener_create(remote_shell_pt remoteShell, int port, connection_listener_pt *instance);
+celix_status_t connectionListener_destroy(connection_listener_pt instance);
 celix_status_t connectionListener_start(connection_listener_pt instance);
 celix_status_t connectionListener_stop(connection_listener_pt instance);
 

Modified: celix/branches/celix_config_admin/remote_shell/private/include/remote_shell.h
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_shell/private/include/remote_shell.h?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_shell/private/include/remote_shell.h (original)
+++ celix/branches/celix_config_admin/remote_shell/private/include/remote_shell.h Mon Jan 19 12:26:54 2015
@@ -27,19 +27,24 @@
 #ifndef REMOTE_SHELL_H_
 #define REMOTE_SHELL_H_
 
-#include <apr_pools.h>
-
 #include <bundle_context.h>
 #include <celix_errno.h>
 
 #include "shell_mediator.h"
 
-typedef struct remote_shell *remote_shell_pt;
-
-celix_status_t remoteShell_create(apr_pool_t *pool, shell_mediator_pt mediator, apr_size_t maximumConnections, remote_shell_pt *instance);
+struct remote_shell {
+	log_helper_pt* loghelper;
+	shell_mediator_pt mediator;
+	celix_thread_mutex_t mutex;
+	int maximumConnections;
 
-celix_status_t remoteShell_addConnection(remote_shell_pt instance, apr_socket_t *socket);
+	array_list_pt connections;
+};
+typedef struct remote_shell *remote_shell_pt;
 
+celix_status_t remoteShell_create(shell_mediator_pt mediator, int maximumConnections, remote_shell_pt *instance);
+celix_status_t remoteShell_destroy(remote_shell_pt instance);
+celix_status_t remoteShell_addConnection(remote_shell_pt instance, int socket);
 celix_status_t remoteShell_stopConnections(remote_shell_pt instance);
 
 #endif /* REMOTE_SHELL_H_ */

Modified: celix/branches/celix_config_admin/remote_shell/private/include/shell_mediator.h
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_shell/private/include/shell_mediator.h?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_shell/private/include/shell_mediator.h (original)
+++ celix/branches/celix_config_admin/remote_shell/private/include/shell_mediator.h Mon Jan 19 12:26:54 2015
@@ -28,16 +28,26 @@
 #ifndef shellMediator_H_
 #define shellMediator_H_
 
-#include <apr_pools.h>
-#include <apr_network_io.h>
-
 #include <bundle_context.h>
+#include <service_tracker.h>
 #include <celix_errno.h>
 
-typedef struct shell_mediator *shell_mediator_pt;
+#include <shell.h>
 
-celix_status_t shellMediator_create(apr_pool_t *pool, bundle_context_pt context, shell_mediator_pt *instance);
+struct shell_mediator {
+
+	log_helper_pt loghelper;
+	bundle_context_pt context;
+	service_tracker_pt tracker;
+	celix_thread_mutex_t mutex;
+
+	//protected by mutex
+	shell_service_pt shellService;
+};
+typedef struct shell_mediator *shell_mediator_pt;
 
-celix_status_t shellMediator_executeCommand(shell_mediator_pt instance, char *command, apr_socket_t *socket);
+celix_status_t shellMediator_create(bundle_context_pt context, shell_mediator_pt *instance);
+celix_status_t shellMediator_destroy(shell_mediator_pt instance);
+celix_status_t shellMediator_executeCommand(shell_mediator_pt instance, char *command, int socket);
 
 #endif /* shellMediator_H_ */

Modified: celix/branches/celix_config_admin/remote_shell/private/src/activator.c
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_shell/private/src/activator.c?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_shell/private/src/activator.c (original)
+++ celix/branches/celix_config_admin/remote_shell/private/src/activator.c Mon Jan 19 12:26:54 2015
@@ -27,23 +27,23 @@
 #include <celix_errno.h>
 
 #include <stdlib.h>
-#include <apr_strings.h>
 
 #include "bundle_activator.h"
 #include "bundle_context.h"
 
+#include "log_helper.h"
 #include "connection_listener.h"
 #include "shell_mediator.h"
 #include "remote_shell.h"
 
-#define REMOTE_SHELL_TELNET_PORT_PROPERTY_NAME ("remote.shell.telnet.port")
-#define DEFAULT_REMOTE_SHELL_TELNET_PORT (6666)
+#define REMOTE_SHELL_TELNET_PORT_PROPERTY_NAME 	"remote.shell.telnet.port"
+#define DEFAULT_REMOTE_SHELL_TELNET_PORT 		6666
 
-#define REMOTE_SHELL_TELNET_MAXCONN_PROPERTY_NAME ("remote.shell.telnet.maxconn")
-#define DEFAULT_REMOTE_SHELL_TELNET_MAXCONN (2)
+#define REMOTE_SHELL_TELNET_MAXCONN_PROPERTY_NAME 	"remote.shell.telnet.maxconn"
+#define DEFAULT_REMOTE_SHELL_TELNET_MAXCONN 		2
 
 struct bundle_instance {
-	apr_pool_t *pool;
+	log_helper_pt loghelper;
 	shell_mediator_pt shellMediator;
 	remote_shell_pt remoteShell;
 	connection_listener_pt connectionListener;
@@ -51,83 +51,100 @@ struct bundle_instance {
 
 typedef struct bundle_instance *bundle_instance_pt;
 
-static apr_size_t bundleActivator_getPort(bundle_context_pt context);
-static apr_size_t bundleActivator_getMaximumConnections(bundle_context_pt context);
-static apr_size_t bundleActivator_getProperty(bundle_context_pt context, char * propertyName, apr_size_t defaultValue);
+static int bundleActivator_getPort(bundle_instance_pt bi, bundle_context_pt context);
+static int bundleActivator_getMaximumConnections(bundle_instance_pt bi, bundle_context_pt context);
+static int bundleActivator_getProperty(bundle_instance_pt bi, bundle_context_pt context, char * propertyName, int defaultValue);
 
 celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
 	celix_status_t status = CELIX_SUCCESS;
-    apr_pool_t *ctxpool;
-    apr_pool_t *pool;
 
-    status = bundleContext_getMemoryPool(context, &ctxpool);
-    apr_pool_create(&pool, ctxpool);
-    if (status == CELIX_SUCCESS) {
-    	bundle_instance_pt bi = (bundle_instance_pt) apr_palloc(pool, sizeof(struct bundle_instance));
-        if (userData != NULL) {
-        	bi->pool = pool;
-        	bi->shellMediator = NULL;
-        	bi->remoteShell = NULL;
-        	bi->connectionListener = NULL;
-        	(*userData) = bi;
-        } else {
-        	status = CELIX_ENOMEM;
-        }
-    }
-    return status;
+	bundle_instance_pt bi = (bundle_instance_pt) calloc(1, sizeof(struct bundle_instance));
+
+	if (!bi)
+	{
+		status = CELIX_ENOMEM;
+	}
+	else if (userData != NULL) {
+		bi->shellMediator = NULL;
+		bi->remoteShell = NULL;
+		bi->connectionListener = NULL;
+
+		status = logHelper_create(context, &bi->loghelper);
+
+		(*userData) = bi;
+	} else {
+		status = CELIX_ILLEGAL_ARGUMENT;
+		free(bi);
+	}
+
+	return status;
 }
 
 celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
-    celix_status_t status = CELIX_SUCCESS;
-    bundle_instance_pt bi = (bundle_instance_pt)userData;
+	celix_status_t status = CELIX_SUCCESS;
+	bundle_instance_pt bi = (bundle_instance_pt) userData;
+
+	int port = bundleActivator_getPort(bi, context);
+	int maxConn = bundleActivator_getMaximumConnections(bi, context);
 
-    apr_size_t port = bundleActivator_getPort(context);
-    apr_size_t maxConn = bundleActivator_getMaximumConnections(context);
+	status = logHelper_start(bi->loghelper);
 
-    status = shellMediator_create(bi->pool, context, &bi->shellMediator);
-	status = CELIX_DO_IF(status, remoteShell_create(bi->pool, bi->shellMediator,  maxConn, &bi->remoteShell));
-	status = CELIX_DO_IF(status, connectionListener_create(bi->pool, bi->remoteShell, port, &bi->connectionListener));
-    status = CELIX_DO_IF(status, connectionListener_start(bi->connectionListener));
+	status = CELIX_DO_IF(status, shellMediator_create(context, &bi->shellMediator));
+	status = CELIX_DO_IF(status, remoteShell_create(bi->shellMediator, maxConn, &bi->remoteShell));
+	status = CELIX_DO_IF(status, connectionListener_create(bi->remoteShell, port, &bi->connectionListener));
+	status = CELIX_DO_IF(status, connectionListener_start(bi->connectionListener));
 
-    return status;
+	return status;
 }
 
 celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
-    celix_status_t status = CELIX_SUCCESS;
-    bundle_instance_pt bi = (bundle_instance_pt)userData;
+	celix_status_t status = CELIX_SUCCESS;
+	bundle_instance_pt bi = (bundle_instance_pt) userData;
+
+	shellMediator_destroy(bi->shellMediator);
+
+	connectionListener_stop(bi->connectionListener);
+	remoteShell_stopConnections(bi->remoteShell);
 
-    connectionListener_stop(bi->connectionListener);
-    remoteShell_stopConnections(bi->remoteShell);
+	status = logHelper_stop(bi->loghelper);
 
-    return status;
+	return status;
 }
 
 celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
-    return CELIX_SUCCESS;
+	celix_status_t status = CELIX_SUCCESS;
+	bundle_instance_pt bi = (bundle_instance_pt) userData;
+
+	connectionListener_destroy(bi->connectionListener);
+	status = logHelper_destroy(&bi->loghelper);
+
+	return status;
 }
 
-static apr_size_t bundleActivator_getPort(bundle_context_pt context) {
-	return bundleActivator_getProperty(context, REMOTE_SHELL_TELNET_PORT_PROPERTY_NAME, DEFAULT_REMOTE_SHELL_TELNET_PORT);
+static int bundleActivator_getPort(bundle_instance_pt bi, bundle_context_pt context) {
+	return bundleActivator_getProperty(bi, context, REMOTE_SHELL_TELNET_PORT_PROPERTY_NAME, DEFAULT_REMOTE_SHELL_TELNET_PORT);
 }
 
-static apr_size_t bundleActivator_getMaximumConnections(bundle_context_pt context) {
-	return bundleActivator_getProperty(context, REMOTE_SHELL_TELNET_MAXCONN_PROPERTY_NAME, DEFAULT_REMOTE_SHELL_TELNET_MAXCONN);
+static int bundleActivator_getMaximumConnections(bundle_instance_pt bi, bundle_context_pt context) {
+	return bundleActivator_getProperty(bi, context, REMOTE_SHELL_TELNET_MAXCONN_PROPERTY_NAME, DEFAULT_REMOTE_SHELL_TELNET_MAXCONN);
 }
 
-static apr_size_t bundleActivator_getProperty(bundle_context_pt context, char * propertyName, apr_size_t defaultValue) {
-	apr_size_t value;
+static int bundleActivator_getProperty(bundle_instance_pt bi, bundle_context_pt context, char* propertyName, int defaultValue) {
 	char *strValue = NULL;
+	int value;
 
 	bundleContext_getProperty(context, propertyName, &strValue);
 	if (strValue != NULL) {
-        	char* endptr = strValue;
-        	errno = 0;
-        	value = (apr_size_t) strtol(strValue, &endptr, 10);
-        	if (*endptr || errno != 0) { 
-			printf("incorrect format for %s\n", propertyName);
+		char* endptr = strValue;
+
+		errno = 0;
+		value = strtol(strValue, &endptr, 10);
+		if (*endptr || errno != 0) {
+			logHelper_log(bi->loghelper, OSGI_LOGSERVICE_WARNING, "incorrect format for %s", propertyName);
 			value = defaultValue;
 		}
-	} else {
+	}
+	else {
 		value = defaultValue;
 	}
 

Modified: celix/branches/celix_config_admin/remote_shell/private/src/connection_listener.c
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_shell/private/src/connection_listener.c?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_shell/private/src/connection_listener.c (original)
+++ celix/branches/celix_config_admin/remote_shell/private/src/connection_listener.c Mon Jan 19 12:26:54 2015
@@ -25,49 +25,55 @@
  */
 
 #include <stdlib.h>
-
-#include <apr_pools.h>
-#include <apr_thread_mutex.h>
-#include <apr_thread_proc.h>
-#include <apr_time.h>
-#include <apr_poll.h>
-#include <apr_thread_pool.h>
-
 #include <celix_errno.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <fcntl.h>
+
+#include "log_service.h"
+#include "log_helper.h"
 
 #include "connection_listener.h"
 
 #include "shell_mediator.h"
 #include "remote_shell.h"
 
+#define CONNECTION_LISTENER_TIMEOUT_SEC		5
+
 struct connection_listener {
 	//constant
-    apr_pool_t *pool;
-    apr_size_t port;
-    remote_shell_pt remoteShell;
-	apr_thread_mutex_t *mutex;
+	int port;
+	log_helper_pt* loghelper;
+	remote_shell_pt remoteShell;
+	celix_thread_mutex_t mutex;
 
 	//protected by mutex
-	apr_thread_t *thread;
-	apr_pollset_t *pollset;
+	bool running;
+	celix_thread_t thread;
+	fd_set pollset;
 };
 
-static void* APR_THREAD_FUNC connection_listener_thread(apr_thread_t *thread, void *data);
-static apr_status_t connectionListener_cleanup(connection_listener_pt instance);
+static void* connection_listener_thread(void *data);
 
-celix_status_t connectionListener_create(apr_pool_t *pool, remote_shell_pt remoteShell, apr_size_t port, connection_listener_pt *instance) {
+celix_status_t connectionListener_create(remote_shell_pt remoteShell, int port, connection_listener_pt *instance) {
 	celix_status_t status = CELIX_SUCCESS;
-    (*instance) = apr_palloc(pool, sizeof(**instance));
-    if ((*instance) != NULL) {
-    	(*instance)->pool = pool;
-    	(*instance)->port = port;
-		(*instance)->mutex = NULL;
+	(*instance) = calloc(1, sizeof(**instance));
+
+	if ((*instance) != NULL) {
+		(*instance)->port = port;
 		(*instance)->remoteShell = remoteShell;
-		(*instance)->thread = NULL;
-		(*instance)->pollset = NULL;
-		apr_pool_pre_cleanup_register(pool, (*instance), (void *)connectionListener_cleanup);
+		(*instance)->running = false;
+		(*instance)->loghelper = remoteShell->loghelper;
+
+		FD_ZERO(&(*instance)-> pollset);
 
-		status = apr_thread_mutex_create(&(*instance)->mutex, APR_THREAD_MUTEX_DEFAULT, pool);
+		status = celixThreadMutex_create(&(*instance)->mutex, NULL);
 	} else {
 		status = CELIX_ENOMEM;
 	}
@@ -76,131 +82,138 @@ celix_status_t connectionListener_create
 
 celix_status_t connectionListener_start(connection_listener_pt instance) {
 	celix_status_t status = CELIX_SUCCESS;
-	apr_thread_mutex_lock(instance->mutex);
-
-	if (instance->thread == NULL) {
-		apr_threadattr_t *threadAttributes = NULL;
-		apr_threadattr_create(&threadAttributes, instance->pool);
-		apr_thread_create(&instance->thread, threadAttributes, connection_listener_thread, instance, instance->pool);
-	} else {
-		status = CELIX_ILLEGAL_STATE;
-	}
-
-	apr_thread_mutex_unlock(instance->mutex);
+	celixThreadMutex_lock(&instance->mutex);
+	celixThread_create(&instance->thread, NULL, connection_listener_thread, instance);
+	celixThreadMutex_unlock(&instance->mutex);
 	return status;
 }
 
 celix_status_t connectionListener_stop(connection_listener_pt instance) {
 	celix_status_t status = CELIX_SUCCESS;
-	apr_thread_t *thread = NULL;
-	apr_pollset_t *pollset = NULL;
+	celix_thread_t thread;
+	fd_set pollset;
 
-	fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "CONNECTION_LISTENER: Stopping thread\n");
+	instance->running = false;
+	FD_ZERO(&pollset);
 
-	apr_thread_mutex_lock(instance->mutex);
-	thread=instance->thread;
-	instance->thread = NULL;
-	pollset=instance->pollset;
-	apr_thread_mutex_unlock(instance->mutex);
-
-	if (thread != NULL && pollset != NULL) {
-		apr_status_t threadStatus = APR_SUCCESS;
-		apr_status_t stat = APR_SUCCESS;
-		char error[512];
-
-		fw_log(logger, OSGI_FRAMEWORK_LOG_DEBUG, "Stopping thread by waking poll on listen socket\n");
-		stat = apr_pollset_wakeup(pollset);
-		
-		apr_strerror(stat, error, 512);
-		fw_log(logger, OSGI_FRAMEWORK_LOG_DEBUG, "Got error %s.", error);
-
-		apr_thread_join(&threadStatus, thread);
-		fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "Done joining thread.");
-	} else if (thread != NULL) {
-		fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Cannot stop thread.");
-	} else {
-		fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "No running thread.");
-	}
+	logHelper_log(*instance->loghelper, OSGI_LOGSERVICE_INFO, "CONNECTION_LISTENER: Stopping thread\n");
 
+	celixThreadMutex_lock(&instance->mutex);
+	thread = instance->thread;
+
+	pollset = instance->pollset;
+	celixThreadMutex_unlock(&instance->mutex);
+
+	celixThread_join(thread, NULL);
 	return status;
 }
 
-static void* APR_THREAD_FUNC connection_listener_thread(apr_thread_t *thread, void *data) {
-	apr_status_t status = APR_SUCCESS;
+celix_status_t connectionListener_destroy(connection_listener_pt instance) {
+	free(instance);
+
+	return CELIX_SUCCESS;
+}
+
+static void* connection_listener_thread(void *data) {
+	celix_status_t status = CELIX_BUNDLE_EXCEPTION;
 	connection_listener_pt instance = data;
+	struct timeval timeout; /* Timeout for select */
+	fd_set active_fd_set;
+	int listenSocket = 0;
+	int on = 1;
+
+	struct addrinfo *result, *rp;
+	struct addrinfo hints;
+
+	memset(&hints, 0, sizeof(struct addrinfo));
+	hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
+	hints.ai_socktype = SOCK_STREAM; /* Datagram socket */
+	hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */
+	hints.ai_protocol = 0; /* Any protocol */
+	hints.ai_canonname = NULL;
+	hints.ai_addr = NULL;
+	hints.ai_next = NULL;
+
+	char portStr[10];
+	snprintf(&portStr[0], 10, "%d", instance->port);
+
+	getaddrinfo(NULL, portStr, &hints, &result);
+
+	for (rp = result; rp != NULL && status == CELIX_BUNDLE_EXCEPTION; rp = rp->ai_next) {
+
+		status = CELIX_BUNDLE_EXCEPTION;
+
+		/* Create socket */
+		listenSocket = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
+		if (listenSocket < 0) {
+			logHelper_log(*instance->loghelper, OSGI_LOGSERVICE_ERROR, "Error creating socket: %s", strerror(errno));
+		}
+		else if (setsockopt(listenSocket, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) < 0) {
+			logHelper_log(*instance->loghelper, OSGI_LOGSERVICE_ERROR, "cannot set socket option: %s", strerror(errno));
+		}
+		else if (bind(listenSocket, rp->ai_addr, rp->ai_addrlen) < 0) {
+			logHelper_log(*instance->loghelper, OSGI_LOGSERVICE_ERROR, "cannot bind: %s", strerror(errno));
+		}
+		else if (listen(listenSocket, 5) < 0) {
+			logHelper_log(*instance->loghelper, OSGI_LOGSERVICE_ERROR, "listen failed: %s", strerror(errno));
+		}
+		else {
+			status = CELIX_SUCCESS;
+		}
+	}
+
+	if (status == CELIX_SUCCESS) {
 
-	apr_sockaddr_t *listenAddress = NULL;
-	apr_socket_t *listenSocket = NULL;
-	apr_socket_t *acceptedSocket = NULL;
-	apr_pollset_t *pollset = NULL;
-	apr_pollfd_t pfd = { instance->pool, APR_POLL_SOCKET, APR_POLLIN, 0, { NULL }, NULL };
-	apr_int32_t num;
-	const apr_pollfd_t *ret_pfd;
-
-	status = apr_sockaddr_info_get(&listenAddress, NULL, APR_UNSPEC, instance->port, 0, instance->pool);
-	status = CELIX_DO_IF(status, apr_socket_create(&listenSocket, APR_INET, SOCK_STREAM, APR_PROTO_TCP, instance->pool));
-	status = CELIX_DO_IF(status, apr_socket_opt_set(listenSocket, APR_SO_REUSEADDR, TRUE));
-	status = CELIX_DO_IF(status, apr_socket_bind(listenSocket, listenAddress));
-	status = CELIX_DO_IF(status, apr_socket_listen(listenSocket, 2));
-	status = CELIX_DO_IF(status, apr_pollset_create(&pollset, 1, instance->pool, APR_POLLSET_WAKEABLE));
-	pfd.desc.s = listenSocket;
-	status = CELIX_DO_IF(status, apr_pollset_add(pollset, &pfd));
-
-
-    apr_thread_mutex_lock(instance->mutex);
-    instance->pollset=pollset;
-    apr_thread_mutex_unlock(instance->mutex);
-
-    if (status != APR_SUCCESS) {
-    	char error[64];
-		apr_strerror(status, error, 64);
-		fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Error creating and listing on socket: %s.", error);
-    } else {
-    	fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "Remote Shell accepting connections on port %ld", instance->port);
-    }
-
-	while (status == APR_SUCCESS) {
-		status = apr_pollset_poll(pollset, -1, &num, &ret_pfd); //blocks on fd till a connection is made
-		if (status == APR_SUCCESS) {
-			apr_status_t socketStatus = APR_SUCCESS;
-			apr_pool_t *socketPool = NULL;
-
-			acceptedSocket = NULL;
-			apr_pool_create(&socketPool, instance->pool);
-			socketStatus = apr_socket_accept(&acceptedSocket, listenSocket, socketPool);
-
-			fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "REMOTE_SHELL: created connection socket.");
-			if (socketStatus == APR_SUCCESS) {
-				remoteShell_addConnection(instance->remoteShell, acceptedSocket);
-			} else {
-				apr_pool_destroy(socketPool);
-				fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "REMOTE_SHELL: Could not accept connection.");
+		logHelper_log(*instance->loghelper, OSGI_LOGSERVICE_INFO, "Remote Shell accepting connections on port %d", instance->port);
+
+		celixThreadMutex_lock(&instance->mutex);
+		instance->pollset = active_fd_set;
+		celixThreadMutex_unlock(&instance->mutex);
+
+		instance->running = true;
+
+		while (status == CELIX_SUCCESS && instance->running) {
+			int selectRet = -1;
+			do {
+				timeout.tv_sec = CONNECTION_LISTENER_TIMEOUT_SEC;
+				timeout.tv_usec = 0;
+
+				FD_ZERO(&active_fd_set);
+				FD_SET(listenSocket, &active_fd_set);
+
+				selectRet = select(listenSocket + 1, &active_fd_set, NULL, NULL, &timeout);
+			} while (selectRet == -1 && errno == EINTR && instance->running == true);
+			if (selectRet < 0) {
+				logHelper_log(*instance->loghelper, OSGI_LOGSERVICE_ERROR, "select on listenSocket failed: %s", strerror(errno));
+				status = CELIX_BUNDLE_EXCEPTION;
+			}
+			else if (selectRet == 0) {
+				/* do nothing here */
+			}
+			else if (FD_ISSET(listenSocket, &active_fd_set)) {
+				int acceptedSocket = accept(listenSocket, NULL, NULL);
+
+				if (acceptedSocket < 0) {
+					logHelper_log(*instance->loghelper, OSGI_LOGSERVICE_ERROR, "REMOTE_SHELL: accept failed: %s.", strerror(errno));
+					status = CELIX_BUNDLE_EXCEPTION;
+				}
+				else {
+					logHelper_log(*instance->loghelper, OSGI_LOGSERVICE_INFO, "REMOTE_SHELL: connection established.");
+					remoteShell_addConnection(instance->remoteShell, acceptedSocket);
+				}
+			}
+			else {
+				logHelper_log(*instance->loghelper, OSGI_LOGSERVICE_DEBUG, "REMOTE_SHELL: received data on a not-expected file-descriptor?");
 			}
-		} else if (status == APR_EINTR) {
-			fw_log(logger, OSGI_FRAMEWORK_LOG_DEBUG, "REMOTE_SHELL: Poll interrupted.");
-		} else /*error*/ {
-			char error[64];
-			apr_strerror(status, error, 64);
-			fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "REMOTE_SHELL: Got error %s.", error);
-			break;
 		}
 	}
 
-	if (pollset != NULL) {
-		apr_pollset_remove(pollset, &pfd);
-		apr_pollset_destroy(pollset);
-	}
-	if (listenSocket != NULL) {
-		apr_socket_shutdown(listenSocket, APR_SHUTDOWN_READWRITE);
-		apr_socket_close(listenSocket);
+	if (listenSocket > 0) {
+		close(listenSocket);
 	}
 
-    apr_thread_exit(thread, status);
-    return NULL;
-}
+	freeaddrinfo(result);
 
-static apr_status_t connectionListener_cleanup(connection_listener_pt instance) {
-        celix_status_t status = CELIX_SUCCESS;
-        status = connectionListener_stop(instance);
-        return APR_SUCCESS;
+	return NULL;
 }
+



Mime
View raw message