celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1652984 [5/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_shell/private/src/remote_shell.c
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_shell/private/src/remote_shell.c?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_shell/private/src/remote_shell.c (original)
+++ celix/branches/celix_config_admin/remote_shell/private/src/remote_shell.c Mon Jan 19 12:26:54 2015
@@ -26,15 +26,13 @@
 
 #include <stdlib.h>
 
-#include <apr_pools.h>
-#include <apr_thread_mutex.h>
-#include <apr_thread_pool.h>
-#include <apr_strings.h>
-#include <apr_poll.h>
-
+#include <unistd.h>
 #include <utils.h>
 #include <array_list.h>
 
+#include "log_helper.h"
+
+#include "log_service.h"
 #include "remote_shell.h"
 
 #define COMMAND_BUFF_SIZE (256)
@@ -45,146 +43,139 @@
 #define RS_ERROR ("Error executing command!\n")
 #define RS_MAXIMUM_CONNECTIONS_REACHED ("Maximum number of connections  reached. Disconnecting ...\n")
 
-struct remote_shell {
-	apr_pool_t *pool;
-	shell_mediator_pt mediator;
-	apr_thread_mutex_t *mutex;
-	apr_int64_t maximumConnections;
-
-	//protected by mutex
-	apr_thread_pool_t *threadPool;
-	array_list_pt connections;
-};
+#define CONNECTION_LISTENER_TIMEOUT_SEC		5
+
+
 
 struct connection {
 	remote_shell_pt parent;
-	apr_socket_t *socket;
-	apr_pool_t *pool;
-	apr_pollset_t *pollset;
+	int socket;
+	fd_set pollset;
+	bool threadRunning;
 };
 
 typedef struct connection *connection_pt;
 
-static apr_status_t remoteShell_cleanup(remote_shell_pt instance); //gets called from apr pool cleanup
-
 static celix_status_t remoteShell_connection_print(connection_pt connection, char * text);
 static celix_status_t remoteShell_connection_execute(connection_pt connection, char *command);
-static void* APR_THREAD_FUNC remoteShell_connection_run(apr_thread_t *thread, void *data);
+static void* remoteShell_connection_run(void *data);
 
-celix_status_t remoteShell_create(apr_pool_t *pool, shell_mediator_pt mediator, apr_size_t maximumConnections, remote_shell_pt *instance) {
+celix_status_t remoteShell_create(shell_mediator_pt mediator, int maximumConnections, remote_shell_pt *instance) {
 	celix_status_t status = CELIX_SUCCESS;
-	(*instance) = apr_palloc(pool, sizeof(**instance));
+	(*instance) = calloc(1, sizeof(**instance));
 	if ((*instance) != NULL) {
-		(*instance)->pool = pool;
 		(*instance)->mediator = mediator;
 		(*instance)->maximumConnections = maximumConnections;
-		(*instance)->threadPool = NULL;
-		(*instance)->mutex = NULL;
 		(*instance)->connections = NULL;
+		(*instance)->loghelper = &mediator->loghelper;
 
-		apr_pool_pre_cleanup_register(pool, (*instance), (void *)remoteShell_cleanup);
+		status = celixThreadMutex_create(&(*instance)->mutex, NULL);
 
-		status = apr_thread_mutex_create(&(*instance)->mutex, APR_THREAD_MUTEX_DEFAULT, pool);
-		status = apr_thread_pool_create(&(*instance)->threadPool, 0, maximumConnections, pool);
-		status = arrayList_create(&(*instance)->connections);
+		if (status == CELIX_SUCCESS) {
+			status = arrayList_create(&(*instance)->connections);
+		}
 	} else {
 		status = CELIX_ENOMEM;
 	}
 	return status;
 }
 
-static apr_status_t remoteShell_cleanup(remote_shell_pt instance) {
+celix_status_t remoteShell_destroy(remote_shell_pt instance) {
+	celix_status_t status = CELIX_SUCCESS;
+
 	remoteShell_stopConnections(instance);
 
-	apr_thread_mutex_lock(instance->mutex);
+	celixThreadMutex_lock(&instance->mutex);
 	arrayList_destroy(instance->connections);
-	apr_thread_pool_destroy(instance->threadPool);
-	apr_thread_mutex_unlock(instance->mutex);
+	celixThreadMutex_unlock(&instance->mutex);
 
-	return APR_SUCCESS;
+	return status;
 }
 
-celix_status_t remoteShell_addConnection(remote_shell_pt instance, apr_socket_t *socket) {
+celix_status_t remoteShell_addConnection(remote_shell_pt instance, int socket) {
 	celix_status_t status = CELIX_SUCCESS;
-	apr_pool_t *pool = apr_socket_pool_get(socket);
-	connection_pt connection = apr_palloc(pool, sizeof(struct connection));
+	connection_pt connection = calloc(1, sizeof(struct connection));
+
 	if (connection != NULL) {
 		connection->parent = instance;
 		connection->socket = socket;
-		connection->pool = pool;
-		connection->pollset = NULL;
+		connection->threadRunning = false;
+
+		celixThreadMutex_lock(&instance->mutex);
 
-		apr_pollset_create(&connection->pollset, 1, connection->pool, APR_POLLSET_WAKEABLE);
-		apr_thread_mutex_lock(instance->mutex);
-		if (apr_thread_pool_busy_count(instance->threadPool) < instance->maximumConnections) {
+		if (arrayList_size(instance->connections) < instance->maximumConnections) {
+			celix_thread_t connectionRunThread = celix_thread_default;
 			arrayList_add(instance->connections, connection);
-			status = apr_thread_pool_push(instance->threadPool, remoteShell_connection_run, connection, 0, instance);
+			status = celixThread_create(&connectionRunThread, NULL, &remoteShell_connection_run, connection);
 		} else {
-			status = APR_ECONNREFUSED;
+			status = CELIX_BUNDLE_EXCEPTION;
 			remoteShell_connection_print(connection, RS_MAXIMUM_CONNECTIONS_REACHED);
 		}
-		apr_thread_mutex_unlock(instance->mutex);
+		celixThreadMutex_unlock(&instance->mutex);
 	} else {
 		status = CELIX_ENOMEM;
 	}
 
 	if (status != CELIX_SUCCESS) {
-		apr_socket_close(socket);
-		apr_pool_destroy(pool);
+		close(connection->socket);
+		free(connection);
 	}
+
 	return status;
 }
 
 celix_status_t remoteShell_stopConnections(remote_shell_pt instance) {
 	celix_status_t status = CELIX_SUCCESS;
-	apr_status_t wakeupStatus = APR_SUCCESS;
-	char error[64];
 	int length = 0;
 	int i = 0;
 
-	apr_thread_mutex_lock(instance->mutex);
+	celixThreadMutex_lock(&instance->mutex);
 	length = arrayList_size(instance->connections);
+
 	for (i = 0; i < length; i += 1) {
 		connection_pt connection = arrayList_get(instance->connections, i);
-		wakeupStatus = apr_pollset_wakeup(connection->pollset);
-		if (wakeupStatus != APR_SUCCESS) {
-			apr_strerror(wakeupStatus, error, 64);
-			fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "REMOTE_SHELLE: Error waking up connection %i: '%s'", i, error);
-		}
+		connection->threadRunning = false;
 	}
-	apr_thread_mutex_unlock(instance->mutex);
-	apr_thread_pool_tasks_cancel(instance->threadPool,instance);
+
+	celixThreadMutex_unlock(&instance->mutex);
 
 	return status;
 }
 
-void *APR_THREAD_FUNC remoteShell_connection_run(apr_thread_t *thread, void *data) {
+void *remoteShell_connection_run(void *data) {
 	celix_status_t status = CELIX_SUCCESS;
 	connection_pt connection = data;
+	size_t len;
+	int result;
+	struct timeval timeout; /* Timeout for select */
+
+	connection->threadRunning = true;
+	status = remoteShell_connection_print(connection, RS_WELCOME);
+
+	while (status == CELIX_SUCCESS && connection->threadRunning == true) {
+		do {
+			timeout.tv_sec = CONNECTION_LISTENER_TIMEOUT_SEC;
+			timeout.tv_usec = 0;
+
+			FD_ZERO(&connection->pollset);
+			FD_SET(connection->socket, &connection->pollset);
+			result = select(connection->socket + 1, &connection->pollset, NULL, NULL, &timeout);
+		} while (result == -1 && errno == EINTR && connection->threadRunning == true);
+
+		/* The socket_fd has data available to be read */
+		if (result > 0 && FD_ISSET(connection->socket, &connection->pollset)) {
+			char buff[COMMAND_BUFF_SIZE];
+
+			len = recv(connection->socket, buff, COMMAND_BUFF_SIZE - 1, 0);
+			if (len < COMMAND_BUFF_SIZE) {
+				celix_status_t commandStatus = CELIX_SUCCESS;
+				buff[len] = '\0';
 
-	apr_size_t len;
-	char buff[COMMAND_BUFF_SIZE];
-	apr_pollfd_t pfd = { connection->pool, APR_POLL_SOCKET, APR_POLLIN, 0, { NULL }, NULL };
-	apr_int32_t num;
-	const apr_pollfd_t *ret_pfd;
-
-	pfd.desc.s = connection->socket;
-
-	status = CELIX_DO_IF(status, apr_pollset_add(connection->pollset, &pfd));
-
-	remoteShell_connection_print(connection, RS_WELCOME);
-	while (status == CELIX_SUCCESS) {
-		status = apr_pollset_poll(connection->pollset, -1, &num, &ret_pfd); //blocks on fd until a connection is made
-		if (status == APR_SUCCESS) {
-			len = COMMAND_BUFF_SIZE -1;
-			status = apr_socket_recv(connection->socket, buff, &len);
-			if (status == APR_SUCCESS && len < COMMAND_BUFF_SIZE) {
-				apr_status_t commandStatus = APR_SUCCESS;
-				buff[len]='\0';
 				commandStatus = remoteShell_connection_execute(connection, buff);
+
 				if (commandStatus == CELIX_SUCCESS) {
 					remoteShell_connection_print(connection, RS_PROMPT);
-				} else if (commandStatus == APR_EOF) {
+				} else if (commandStatus == CELIX_FILE_IO_EXCEPTION) {
 					//exit command
 					break;
 				} else { //error
@@ -193,60 +184,46 @@ void *APR_THREAD_FUNC remoteShell_connec
 				}
 
 			} else {
-				char error[64];
-				apr_strerror(status, error, 64);
-				fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "REMOTE_SHELL: Got error %s", error);
+				logHelper_log(*connection->parent->loghelper, OSGI_LOGSERVICE_ERROR, "REMOTE_SHELL: Error while retrieving data");
 			}
-		} 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;
 		}
 	}
+
 	remoteShell_connection_print(connection, RS_GOODBYE);
 
-	fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "REMOTE_SHELL: Closing socket");
-	apr_thread_mutex_lock(connection->parent->mutex);
+	logHelper_log(*connection->parent->loghelper, OSGI_LOGSERVICE_INFO, "REMOTE_SHELL: Closing socket");
+	celixThreadMutex_lock(&connection->parent->mutex);
 	arrayList_removeElement(connection->parent->connections, connection);
-	apr_thread_mutex_unlock(connection->parent->mutex);
+	celixThreadMutex_unlock(&connection->parent->mutex);
 
-	apr_socket_shutdown(connection->socket, APR_SHUTDOWN_READWRITE);
-	apr_pollset_destroy(connection->pollset);
-	apr_socket_close(connection->socket);
-	apr_pool_destroy(connection->pool);
+	close(connection->socket);
 
 	return NULL;
 }
 
 static celix_status_t remoteShell_connection_execute(connection_pt connection, char *command) {
-	celix_status_t status;
-
-	apr_pool_t *workPool = NULL;
-	status = apr_pool_create(&workPool,  connection->pool);
+	celix_status_t status = CELIX_SUCCESS;
 
 	if (status == CELIX_SUCCESS) {
-		char *dline = apr_pstrdup(workPool, command);
+		char *dline = strdup(command);
 		char *line = utils_stringTrim(dline);
 		int len = strlen(line);
 
 		if (len == 0) {
 			//ignore
 		} else if (len == 4 && strncmp("exit", line, 4) == 0) {
-			status = APR_EOF;
+			status = CELIX_FILE_IO_EXCEPTION;
 		} else {
 			status = shellMediator_executeCommand(connection->parent->mediator, line, connection->socket);
 		}
 
-		apr_pool_destroy(workPool);
+		free(dline);
 	}
 
 	return status;
 }
 
 celix_status_t remoteShell_connection_print(connection_pt connection, char *text) {
-	apr_size_t len = strlen(text);
-	return apr_socket_send(connection->socket, text, &len);
+	size_t len = strlen(text);
+	return (send(connection->socket, text, len, 0) > 0) ? CELIX_SUCCESS : CELIX_FILE_IO_EXCEPTION;
 }

Modified: celix/branches/celix_config_admin/remote_shell/private/src/shell_mediator.c
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/remote_shell/private/src/shell_mediator.c?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/remote_shell/private/src/shell_mediator.c (original)
+++ celix/branches/celix_config_admin/remote_shell/private/src/shell_mediator.c Mon Jan 19 12:26:54 2015
@@ -26,31 +26,19 @@
 
 #include <stdlib.h>
 
-#include <apr_pools.h>
-#include <apr_thread_mutex.h>
-
 #include <utils.h>
 #include <shell.h>
 #include <service_tracker.h>
 #include <command.h>
 
+#include "log_helper.h"
+#include "log_service.h"
 #include "shell_mediator.h"
 
-struct shell_mediator {
-    apr_pool_t *pool;
-	bundle_context_pt context;
-	service_tracker_pt tracker;
-	apr_thread_mutex_t *mutex;
-
-	//protected by mutex
-	shell_service_pt shellService;
-};
-
 //NOTE: multiple instances of shell_mediator are not supported, because we need
 // 		a non ADT - shared between instances - variable.
-static apr_socket_t *currentOutputSocket = NULL;
+static int currentOutputSocket = -1;
 
-static apr_status_t shellMediator_cleanup(void *handle); //gets called from apr pool cleanup
 static void shellMediator_writeOnCurrentSocket(char *buff);
 
 static celix_status_t shellMediator_addingService(void *handler, service_reference_pt reference, void **service);
@@ -58,63 +46,73 @@ static celix_status_t shellMediator_adde
 static celix_status_t shellMediator_modifiedService(void *handler, service_reference_pt reference, void * service);
 static celix_status_t shellMediator_removedService(void *handler, service_reference_pt reference, void * service);
 
-celix_status_t shellMediator_create(apr_pool_t *pool, bundle_context_pt context, shell_mediator_pt *instance) {
+celix_status_t shellMediator_create(bundle_context_pt context, shell_mediator_pt *instance) {
 	celix_status_t status = CELIX_SUCCESS;
 	service_tracker_customizer_pt customizer = NULL;
 
-	(*instance) = (shell_mediator_pt) apr_palloc(pool, sizeof(**instance));
-    if ((*instance) != NULL) {
-		apr_pool_pre_cleanup_register(pool, *instance, shellMediator_cleanup);
+	(*instance) = (shell_mediator_pt) calloc(1, sizeof(**instance));
+	if ((*instance) != NULL) {
 
-    	(*instance)->pool = pool;
 		(*instance)->context = context;
 		(*instance)->tracker = NULL;
-		(*instance)->mutex = NULL;
 		(*instance)->shellService = NULL;
 
-		status = apr_thread_mutex_create(&(*instance)->mutex, APR_THREAD_MUTEX_DEFAULT, pool);
+		status = logHelper_create(context, &(*instance)->loghelper);
+
+		status = CELIX_DO_IF(status, celixThreadMutex_create(&(*instance)->mutex, NULL));
+
 		status = CELIX_DO_IF(status, serviceTrackerCustomizer_create((*instance), shellMediator_addingService, shellMediator_addedService,
 				shellMediator_modifiedService, shellMediator_removedService, &customizer));
-		status = CELIX_DO_IF(status, serviceTracker_create(context, (char *)OSGI_SHELL_SERVICE_NAME, customizer, &(*instance)->tracker));
+		status = CELIX_DO_IF(status, serviceTracker_create(context, (char * )OSGI_SHELL_SERVICE_NAME, customizer, &(*instance)->tracker));
+
 		if (status == CELIX_SUCCESS) {
+			logHelper_start((*instance)->loghelper);
 			serviceTracker_open((*instance)->tracker);
 		}
 	} else {
 		status = CELIX_ENOMEM;
 	}
 
-    if (status != CELIX_SUCCESS) {
-    	printf("Error creating shell_mediator, error code is %i\n", status);
-    }
+	if (status != CELIX_SUCCESS) {
+		logHelper_log((*instance)->loghelper, OSGI_LOGSERVICE_ERROR, "Error creating shell_mediator, error code is %i\n", status);
+	}
 	return status;
 }
 
-static apr_status_t shellMediator_cleanup(void *handle) {
-	shell_mediator_pt instance = (shell_mediator_pt) handle;
-    apr_thread_mutex_lock(instance->mutex);
+celix_status_t shellMediator_destroy(shell_mediator_pt instance) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	celixThreadMutex_lock(&instance->mutex);
 
-    instance->shellService=NULL;
-    serviceTracker_close(instance->tracker);
+	instance->shellService = NULL;
+	serviceTracker_close(instance->tracker);
+	celixThreadMutex_unlock(&instance->mutex);
+
+	logHelper_stop(instance->loghelper);
 
-    apr_thread_mutex_unlock(instance->mutex);
-    return APR_SUCCESS;
+	status = logHelper_destroy(&instance->loghelper);
+
+	return status;
 }
 
 static void shellMediator_writeOnCurrentSocket(char *buff) {
-	apr_size_t len = strlen(buff);
-	apr_socket_send(currentOutputSocket, buff, &len);
+
+	size_t len = strlen(buff);
+	send(currentOutputSocket, buff, len, 0);
 }
 
-celix_status_t shellMediator_executeCommand(shell_mediator_pt instance, char *command, apr_socket_t *socket) {
-	apr_status_t status = CELIX_SUCCESS;
+celix_status_t shellMediator_executeCommand(shell_mediator_pt instance, char *command, int socket) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	celixThreadMutex_lock(&instance->mutex);
 
-	apr_thread_mutex_lock(instance->mutex);
 	if (instance->shellService != NULL) {
-		currentOutputSocket=socket;
+		currentOutputSocket = socket;
 		instance->shellService->executeCommand(instance->shellService->shell, command, shellMediator_writeOnCurrentSocket, shellMediator_writeOnCurrentSocket);
-		currentOutputSocket=NULL;
+		currentOutputSocket = -1;
 	}
-	apr_thread_mutex_unlock(instance->mutex);
+
+	celixThreadMutex_unlock(&instance->mutex);
 
 	return status;
 }
@@ -129,9 +127,9 @@ static celix_status_t shellMediator_addi
 static celix_status_t shellMediator_addedService(void *handler, service_reference_pt reference, void * service) {
 	celix_status_t status = CELIX_SUCCESS;
 	shell_mediator_pt instance = (shell_mediator_pt) handler;
-	apr_thread_mutex_lock(instance->mutex);
+	celixThreadMutex_lock(&instance->mutex);
 	instance->shellService = (shell_service_pt) service;
-	apr_thread_mutex_unlock(instance->mutex);
+	celixThreadMutex_unlock(&instance->mutex);
 	return status;
 }
 
@@ -144,9 +142,9 @@ static celix_status_t shellMediator_modi
 static celix_status_t shellMediator_removedService(void *handler, service_reference_pt reference, void * service) {
 	celix_status_t status = CELIX_SUCCESS;
 	shell_mediator_pt instance = (shell_mediator_pt) handler;
-	apr_thread_mutex_lock(instance->mutex);
+	celixThreadMutex_lock(&instance->mutex);
 	instance->shellService = NULL;
-	apr_thread_mutex_unlock(instance->mutex);
+	celixThreadMutex_unlock(&instance->mutex);
 	return status;
 }
 

Modified: celix/branches/celix_config_admin/shell/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/shell/CMakeLists.txt?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/shell/CMakeLists.txt (original)
+++ celix/branches/celix_config_admin/shell/CMakeLists.txt Mon Jan 19 12:26:54 2015
@@ -24,7 +24,8 @@ if (SHELL)
 
     bundle(shell SOURCES
     	public/src/command
-     
+    	
+     	private/src/activator
     	private/src/shell 
     	private/src/ps_command 
     	private/src/start_command 

Modified: celix/branches/celix_config_admin/shell/private/include/shell_private.h
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/shell/private/include/shell_private.h?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/shell/private/include/shell_private.h (original)
+++ celix/branches/celix_config_admin/shell/private/include/shell_private.h Mon Jan 19 12:26:54 2015
@@ -27,26 +27,26 @@
 #ifndef SHELL_PRIVATE_H_
 #define SHELL_PRIVATE_H_
 
-#include <apr_general.h>
-
+#include "bundle_context.h"
 #include "shell.h"
 #include "hash_map.h"
 #include "command.h"
 
 struct shell {
-	apr_pool_t *pool;
 	bundle_context_pt bundleContext;
 	hash_map_pt commandReferenceMap;
 	hash_map_pt commandNameMap;
 };
 
-shell_pt shell_create();
+celix_status_t shell_create(bundle_context_pt, shell_service_pt* shellService);
+celix_status_t shell_destroy(shell_service_pt* shellService);
+celix_status_t shell_addCommand(shell_pt shell, service_reference_pt reference);
+
+
 char * shell_getCommandUsage(shell_pt shell, char * commandName);
 char * shell_getCommandDescription(shell_pt shell, char * commandName);
 service_reference_pt shell_getCommandReference(shell_pt shell, char * command);
 void shell_executeCommand(shell_pt shell, char * commandLine, void (*out)(char *), void (*error)(char *));
-
-command_service_pt shell_getCommand(shell_pt shell, char * commandName);
-
+void shell_serviceChanged(service_listener_pt listener, service_event_pt event);
 
 #endif /* SHELL_PRIVATE_H_ */

Modified: celix/branches/celix_config_admin/shell/private/src/install_command.c
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/shell/private/src/install_command.c?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/shell/private/src/install_command.c (original)
+++ celix/branches/celix_config_admin/shell/private/src/install_command.c Mon Jan 19 12:26:54 2015
@@ -69,7 +69,7 @@ void installCommand_execute(command_pt c
 		info[0] = '\0';
 		while (sub != NULL) {
 			bundle_pt bundle = NULL;
-			installCommand_install(command, &bundle, strdup(sub), out, err);
+			installCommand_install(command, &bundle, sub, out, err);
 			if (bundle != NULL) {
 				long id;
 				bundle_archive_pt archive = NULL;

Modified: celix/branches/celix_config_admin/shell/private/src/log_command.c
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/shell/private/src/log_command.c?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/shell/private/src/log_command.c (original)
+++ celix/branches/celix_config_admin/shell/private/src/log_command.c Mon Jan 19 12:26:54 2015
@@ -52,52 +52,43 @@ void logCommand_destroy(command_pt comma
 
 void logCommand_execute(command_pt command, char *line, void (*out)(char *), void (*err)(char *)) {
     service_reference_pt readerService = NULL;
-    apr_pool_t *memory_pool = NULL;
 
     bundleContext_getServiceReference(command->bundleContext, (char *) OSGI_LOGSERVICE_READER_SERVICE_NAME, &readerService);
     if (readerService != NULL) {
-        char line[256];
         linked_list_pt list = NULL;
         linked_list_iterator_pt iter = NULL;
         log_reader_service_pt reader = NULL;
 
-        apr_pool_create(&memory_pool, NULL);
-        if (memory_pool) {
-            bundleContext_getService(command->bundleContext, readerService, (void **) &reader);
-            reader->getLog(reader->reader, memory_pool, &list);
-            iter = linkedListIterator_create(list, 0);
-            while (linkedListIterator_hasNext(iter)) {
-                log_entry_pt entry = linkedListIterator_next(iter);
-                char time[20];
-                char *level = NULL;
-                module_pt module = NULL;
-                char *bundleSymbolicName = NULL;
-                char errorString[256];
-
-                celix_status_t status = bundle_getCurrentModule(entry->bundle, &module);
-                if (status == CELIX_SUCCESS) {
-                    status = module_getSymbolicName(module, &bundleSymbolicName);
-
-                    strftime(time, 20, "%Y-%m-%d %H:%M:%S", localtime(&entry->time));
-                    logCommand_levelAsString(command, entry->level, &level);
-
-                    if (entry->errorCode > 0) {
-                        celix_strerror(entry->errorCode, errorString, 256);
-                        sprintf(line, "%s - Bundle: %s - %s - %d %s\n", time, bundleSymbolicName, entry->message, entry->errorCode, errorString);
-                        out(line);
-                    } else {
-                        sprintf(line, "%s - Bundle: %s - %s\n", time, bundleSymbolicName, entry->message);
-                        out(line);
-                    }
-                }
-            }
-            linkedListIterator_destroy(iter);
-            bool result = true;
-            bundleContext_ungetService(command->bundleContext, readerService, &result);
-            apr_pool_destroy(memory_pool);
-        } else {
-            out("Log reader service: out of memory!\n");
-        }
+
+		bundleContext_getService(command->bundleContext, readerService, (void **) &reader);
+		reader->getLog(reader->reader, &list);
+		iter = linkedListIterator_create(list, 0);
+		while (linkedListIterator_hasNext(iter)) {
+			log_entry_pt entry = linkedListIterator_next(iter);
+			char time[20];
+			char *level = NULL;
+			char errorString[256];
+
+			size_t timeLength = strftime(time, 20, "%Y-%m-%d %H:%M:%S", localtime(&entry->time));
+			logCommand_levelAsString(command, entry->level, &level);
+
+			if (entry->errorCode > 0) {
+				celix_strerror(entry->errorCode, errorString, 256);
+				size_t length = timeLength + strlen(entry->bundleSymbolicName) + strlen(entry->message) + strlen(errorString) + 40;
+		        char line[length];
+				snprintf(line, length, "%s - Bundle: %s - %s - %d %s\n", time, entry->bundleSymbolicName, entry->message, entry->errorCode, errorString);
+				out(line);
+			} else {
+				size_t length = timeLength + strlen(entry->bundleSymbolicName) + strlen(entry->message) + 20;
+				char line[length];
+				snprintf(line, length, "%s - Bundle: %s - %s\n", time, entry->bundleSymbolicName, entry->message);
+				out(line);
+			}
+		}
+		linkedListIterator_destroy(iter);
+		linkedList_destroy(list);
+		bool result = true;
+		bundleContext_ungetService(command->bundleContext, readerService, &result);
         bundleContext_ungetServiceReference(command->bundleContext, readerService);
     } else {
         out("No log reader available\n");

Modified: celix/branches/celix_config_admin/shell/private/src/shell.c
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/shell/private/src/shell.c?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/shell/private/src/shell.c (original)
+++ celix/branches/celix_config_admin/shell/private/src/shell.c Mon Jan 19 12:26:54 2015
@@ -26,6 +26,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "celix_errno.h"
+
 #include "shell_private.h"
 #include "bundle_activator.h"
 #include "command_impl.h"
@@ -45,64 +47,70 @@
 
 #include "utils.h"
 
-struct shellServiceActivator {
-    apr_pool_t *pool;
-	shell_pt shell;
-	shell_service_pt shellService;
-	service_registration_pt registration;
-	service_listener_pt listener;
-
-	service_registration_pt psCommand;
-	command_pt psCmd;
-	command_service_pt psCmdSrv;
-
-	service_registration_pt startCommand;
-	command_pt startCmd;
-	command_service_pt startCmdSrv;
-
-	service_registration_pt stopCommand;
-	command_pt stopCmd;
-	command_service_pt stopCmdSrv;
-
-	service_registration_pt installCommand;
-	command_pt installCmd;
-	command_service_pt installCmdSrv;
-
-	service_registration_pt uninstallCommand;
-    command_pt uninstallCmd;
-    command_service_pt uninstallCmdSrv;
-
-	service_registration_pt updateCommand;
-	command_pt updateCmd;
-	command_service_pt updateCmdSrv;
-
-	service_registration_pt logCommand;
-    command_pt logCmd;
-    command_service_pt logCmdSrv;
-
-    service_registration_pt inspectCommand;
-	command_pt inspectCmd;
-	command_service_pt inspectCmdSrv;
-
-	service_registration_pt helpCommand;
-	command_pt helpCmd;
-	command_service_pt helpCmdSrv;
-};
-
-static celix_status_t shell_createCommandService(apr_pool_t *pool, command_pt command, command_service_pt *commandService);
-
-shell_pt shell_create(apr_pool_t *pool) {
-	shell_pt shell = (shell_pt) malloc(sizeof(*shell));
-	shell->pool = pool;
-	shell->commandNameMap = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
-	shell->commandReferenceMap = hashMap_create(NULL, NULL, NULL, NULL);
-	return shell;
-}
-
-void shell_destroy(shell_pt shell) {
-	hashMap_destroy(shell->commandNameMap, false, false);
-	hashMap_destroy(shell->commandReferenceMap, false, false);
-	free(shell);
+static command_service_pt shell_getCommand(shell_pt shell, char * commandName);
+array_list_pt shell_getCommands(shell_pt shell);
+
+celix_status_t shell_create(bundle_context_pt context, shell_service_pt* shellService) {
+	celix_status_t status = CELIX_ENOMEM;
+
+	shell_service_pt lclService = (shell_service_pt) calloc(1, sizeof(struct shellService));
+	shell_pt lclShell = (shell_pt) calloc(1, sizeof(struct shell));
+
+	if (lclService && lclShell) {
+		lclShell->bundleContext = context;
+		lclShell->commandNameMap = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
+		lclShell->commandReferenceMap = hashMap_create(NULL, NULL, NULL, NULL);
+		lclService->shell = lclShell;
+
+		lclService->getCommands = shell_getCommands;
+		lclService->getCommandDescription = shell_getCommandDescription;
+		lclService->getCommandUsage = shell_getCommandUsage;
+		lclService->getCommandReference = shell_getCommandReference;
+		lclService->executeCommand = shell_executeCommand;
+
+		*shellService = lclService;
+		status = CELIX_SUCCESS;
+	}
+
+	return status;
+}
+
+celix_status_t shell_destroy(shell_service_pt* shellService) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	hashMap_destroy((*shellService)->shell->commandNameMap, false, false);
+	hashMap_destroy((*shellService)->shell->commandReferenceMap, false, false);
+
+	free((*shellService)->shell);
+	free(*shellService);
+
+	return status;
+}
+
+celix_status_t shell_addCommand(shell_pt shell, service_reference_pt reference) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	command_service_pt command = NULL;
+	void *cmd = NULL;
+	bundleContext_getService(shell->bundleContext, reference, &cmd);
+	command = (command_service_pt) cmd;
+	hashMap_put(shell->commandNameMap, command->getName(command->command), command);
+	hashMap_put(shell->commandReferenceMap, reference, command);
+
+	return status;
+}
+
+celix_status_t shell_removeCommand(shell_pt shell, service_reference_pt reference) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	command_service_pt command = (command_service_pt) hashMap_remove(shell->commandReferenceMap, reference);
+	if (command != NULL) {
+		bool result = false;
+		hashMap_remove(shell->commandNameMap, command->getName(command->command));
+		bundleContext_ungetService(shell->bundleContext, reference, &result);
+	}
+
+	return status;
 }
 
 array_list_pt shell_getCommands(shell_pt shell) {
@@ -143,201 +151,27 @@ service_reference_pt shell_getCommandRef
 
 void shell_executeCommand(shell_pt shell, char * commandLine, void (*out)(char *), void (*error)(char *)) {
 	unsigned int pos = strcspn(commandLine, " ");
-	char * commandName = (pos != strlen(commandLine)) ? string_ndup((char *)commandLine, pos) : strdup(commandLine);
+	char * commandName = (pos != strlen(commandLine)) ? string_ndup((char *) commandLine, pos) : strdup(commandLine);
 	command_service_pt command = shell_getCommand(shell, commandName);
 	if (command != NULL) {
 		command->executeCommand(command->command, commandLine, out, error);
 	} else {
-	    error("No such command\n");
+		error("No such command\n");
 	}
 	free(commandName);
 }
 
-command_service_pt shell_getCommand(shell_pt shell, char * commandName) {
+static command_service_pt shell_getCommand(shell_pt shell, char * commandName) {
 	command_service_pt command = hashMap_get(shell->commandNameMap, commandName);
 	return (command == NULL) ? NULL : command;
 }
 
-void shell_addCommand(shell_pt shell, service_reference_pt reference) {
-    command_service_pt command = NULL;
-	void *cmd = NULL;
-	bundleContext_getService(shell->bundleContext, reference, &cmd);
-	command = (command_service_pt) cmd;
-	hashMap_put(shell->commandNameMap, command->getName(command->command), command);
-	hashMap_put(shell->commandReferenceMap, reference, command);
-}
-
-void shell_removeCommand(shell_pt shell, service_reference_pt reference) {
-	command_service_pt command = (command_service_pt) hashMap_remove(shell->commandReferenceMap, reference);
-	if (command != NULL) {
-	    bool result = false;
-		hashMap_remove(shell->commandNameMap, command->getName(command->command));
-		bundleContext_ungetService(shell->bundleContext, reference, &result);
-	}
-}
-
 void shell_serviceChanged(service_listener_pt listener, service_event_pt event) {
 	shell_pt shell = (shell_pt) listener->handle;
 	if (event->type == OSGI_FRAMEWORK_SERVICE_EVENT_REGISTERED) {
 		shell_addCommand(shell, event->reference);
 	} else if (event->type == OSGI_FRAMEWORK_SERVICE_EVENT_UNREGISTERING) {
-	    shell_removeCommand(shell, event->reference);
-	}
-}
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
-	apr_pool_t *pool = NULL;
-	shell_pt shell = NULL;
-	*userData = malloc(sizeof(struct shellServiceActivator));
-
-	apr_pool_create(&pool, NULL);
-
-	shell = shell_create(pool);
-//	struct shellServiceActivator * activator = (struct shellServiceActivator *) (*userData);
-	((struct shellServiceActivator *) (*userData))->shell = shell;
-	((struct shellServiceActivator *) (*userData))->listener = NULL;
-	((struct shellServiceActivator *) (*userData))->psCommand = NULL;
-	((struct shellServiceActivator *) (*userData))->startCommand = NULL;
-	((struct shellServiceActivator *) (*userData))->stopCommand = NULL;
-	((struct shellServiceActivator *) (*userData))->installCommand = NULL;
-	((struct shellServiceActivator *) (*userData))->uninstallCommand = NULL;
-	((struct shellServiceActivator *) (*userData))->updateCommand = NULL;
-	((struct shellServiceActivator *) (*userData))->logCommand = NULL;
-	((struct shellServiceActivator *) (*userData))->inspectCommand = NULL;
-	((struct shellServiceActivator *) (*userData))->helpCommand = NULL;
-	((struct shellServiceActivator *) (*userData))->registration = NULL;
-	((struct shellServiceActivator *) (*userData))->pool = pool;
-
-	//(*userData) = &(*activator);
-
-	return CELIX_SUCCESS;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
-    celix_status_t status;
-
-	struct shellServiceActivator * activator = (struct shellServiceActivator *) userData;
-	activator->shell->bundleContext = context;
-
-	activator->shellService = (shell_service_pt) malloc(sizeof(*activator->shellService));
-	activator->shellService->shell = activator->shell;
-	activator->shellService->getCommands = shell_getCommands;
-	activator->shellService->getCommandDescription = shell_getCommandDescription;
-	activator->shellService->getCommandUsage = shell_getCommandUsage;
-	activator->shellService->getCommandReference = shell_getCommandReference;
-	activator->shellService->executeCommand = shell_executeCommand;
-
-	status = bundleContext_registerService(context, (char *) OSGI_SHELL_SERVICE_NAME, activator->shellService, NULL, &activator->registration);
-
-	if (status == CELIX_SUCCESS) {
-	    service_listener_pt listener = (service_listener_pt) malloc(sizeof(*listener));
-	    activator->listener = listener;
-	    listener->handle = activator->shell;
-	    listener->serviceChanged = (void *) shell_serviceChanged;
-	    status = bundleContext_addServiceListener(context, listener, "(objectClass=commandService)");
-
-	    array_list_pt references = NULL;
-	    status = bundleContext_getServiceReferences(context, "commandService", NULL, &references);
-	    if (status == CELIX_SUCCESS) {
-	        int i = 0;
-	        for (i = 0; i < arrayList_size(references); i++) {
-	            shell_addCommand(activator->shell, arrayList_get(references, i));
-	        }
-	    }
-
-	    if (status == CELIX_SUCCESS) {
-	        activator->psCmd = psCommand_create(context);
-	        shell_createCommandService(activator->pool, activator->psCmd, &activator->psCmdSrv);
-	        bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->psCmdSrv, NULL, &activator->psCommand);
-
-	        activator->startCmd = startCommand_create(context);
-	        shell_createCommandService(activator->pool, activator->startCmd, &activator->startCmdSrv);
-	        bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->startCmdSrv, NULL, &activator->startCommand);
-
-	        activator->stopCmd = stopCommand_create(context);
-	        shell_createCommandService(activator->pool, activator->stopCmd, &activator->stopCmdSrv);
-	        bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->stopCmdSrv, NULL, &activator->stopCommand);
-
-	        activator->installCmd = installCommand_create(context);
-	        shell_createCommandService(activator->pool, activator->installCmd, &activator->installCmdSrv);
-	        bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->installCmdSrv, NULL, &activator->installCommand);
-
-	        activator->uninstallCmd = uninstallCommand_create(context);
-	        shell_createCommandService(activator->pool, activator->uninstallCmd, &activator->uninstallCmdSrv);
-	        bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->uninstallCmdSrv, NULL, &activator->uninstallCommand);
-
-	        activator->updateCmd = updateCommand_create(context);
-	        shell_createCommandService(activator->pool, activator->updateCmd, &activator->updateCmdSrv);
-	        bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->updateCmdSrv, NULL, &activator->updateCommand);
-
-	        activator->logCmd = logCommand_create(context);
-	        shell_createCommandService(activator->pool, activator->logCmd, &activator->logCmdSrv);
-            bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->logCmdSrv, NULL, &activator->logCommand);
-
-            activator->inspectCmd = inspectCommand_create(context);
-            shell_createCommandService(activator->pool, activator->inspectCmd, &activator->inspectCmdSrv);
-			bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->inspectCmdSrv, NULL, &activator->inspectCommand);
-
-			activator->helpCmd = helpCommand_create(context);
-			shell_createCommandService(activator->pool, activator->helpCmd, &activator->helpCmdSrv);
-			bundleContext_registerService(context, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME, activator->helpCmdSrv, NULL, &activator->helpCommand);
-	    }
+		shell_removeCommand(shell, event->reference);
 	}
-
-	return status;
 }
 
-static celix_status_t shell_createCommandService(apr_pool_t *pool, command_pt command, command_service_pt *commandService) {
-	*commandService = apr_palloc(pool, sizeof(**commandService));
-	(*commandService)->command = command;
-	(*commandService)->executeCommand = command->executeCommand;
-	(*commandService)->getName = command_getName;
-	(*commandService)->getShortDescription = command_getShortDescription;
-	(*commandService)->getUsage = command_getUsage;
-
-	return CELIX_SUCCESS;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
-    celix_status_t status = CELIX_SUCCESS;
-	struct shellServiceActivator * activator = (struct shellServiceActivator *) userData;
-	serviceRegistration_unregister(activator->registration);
-	serviceRegistration_unregister(activator->psCommand);
-	serviceRegistration_unregister(activator->startCommand);
-	serviceRegistration_unregister(activator->stopCommand);
-	serviceRegistration_unregister(activator->installCommand);
-	serviceRegistration_unregister(activator->uninstallCommand);
-	serviceRegistration_unregister(activator->updateCommand);
-	serviceRegistration_unregister(activator->logCommand);
-	serviceRegistration_unregister(activator->inspectCommand);
-	serviceRegistration_unregister(activator->helpCommand);
-	status = bundleContext_removeServiceListener(context, activator->listener);
-
-	if (status == CELIX_SUCCESS) {
-        psCommand_destroy(activator->psCmd);
-        startCommand_destroy(activator->startCmd);
-        stopCommand_destroy(activator->stopCmd);
-        installCommand_destroy(activator->installCmd);
-        uninstallCommand_destroy(activator->uninstallCmd);
-        updateCommand_destroy(activator->updateCmd);
-        logCommand_destroy(activator->logCmd);
-        inspectCommand_destroy(activator->inspectCmd);
-        inspectCommand_destroy(activator->helpCmd);
-
-        free(activator->shellService);
-        activator->shellService = NULL;
-
-        free(activator->listener);
-        activator->listener = NULL;
-	}
-
-	return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
-	struct shellServiceActivator * activator = (struct shellServiceActivator *) userData;
-	shell_destroy(activator->shell);
-	free(activator);
-
-	return CELIX_SUCCESS;
-}

Modified: celix/branches/celix_config_admin/shell_bonjour/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/shell_bonjour/CMakeLists.txt?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/shell_bonjour/CMakeLists.txt (original)
+++ celix/branches/celix_config_admin/shell_bonjour/CMakeLists.txt Mon Jan 19 12:26:54 2015
@@ -38,7 +38,7 @@ if (SHELL_BONJOUR)
 		 	private/src/bonjour_shell.c
 	)
 	
-	target_link_libraries(bonjour_shell ${CELIX_LIBRARIES} ${APR_LIBRARIES} ${LIBXML2_LIBRARIES} ${DNS_SD_LIB})
+	target_link_libraries(bonjour_shell celix_framework celix_utils ${LIBXML2_LIBRARIES} ${DNS_SD_LIB})
 
 endif (SHELL_BONJOUR)
 

Modified: celix/branches/celix_config_admin/shell_tui/private/src/shell_tui.c
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/shell_tui/private/src/shell_tui.c?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/shell_tui/private/src/shell_tui.c (original)
+++ celix/branches/celix_config_admin/shell_tui/private/src/shell_tui.c Mon Jan 19 12:26:54 2015
@@ -26,9 +26,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-
-#include <apr_general.h>
-#include <apr_thread_proc.h>
+#include <sys/time.h>
+#include <sys/select.h>
 
 #include "bundle_context.h"
 #include "bundle_activator.h"
@@ -41,8 +40,7 @@ struct shellTuiActivator {
 	service_reference_pt reference;
 	struct serviceListener * listener;
 	bool running;
-	apr_thread_t *runnable;
-	apr_pool_t *pool;
+	celix_thread_t runnable;
 };
 
 typedef struct shellTuiActivator * shell_tui_activator_pt;
@@ -51,34 +49,44 @@ void shellTui_write(char * line) {
 	fprintf(stdout, "%s", line);
 }
 
-static void *APR_THREAD_FUNC shellTui_runnable(apr_thread_t *thd, void *data) {
+static void* shellTui_runnable(void *data) {
 	shell_tui_activator_pt act = (shell_tui_activator_pt) data;
 
 	char in[256];
+	char dline[256];
 	bool needPrompt = true;
+
+	fd_set rfds;
+	struct timeval tv;
+
 	while (act->running) {
-		char * dline = NULL;
 		char * line = NULL;
 		if (needPrompt) {
 			printf("-> ");
+			fflush(stdout);
 			needPrompt = false;
 		}
-		fgets(in, 256, stdin);
-		needPrompt = true;
-		dline = strdup(in);
-		line = utils_stringTrim(dline);
-		if (strlen(line) == 0) {
-		    free(dline);
-			continue;
-		}
-		if (act->shell == NULL) {
-		    free(dline);
-			continue;
+		FD_ZERO(&rfds);
+		FD_SET(0, &rfds);
+
+		tv.tv_sec = 1;
+		tv.tv_usec = 0;
+
+		if (select(1, &rfds, NULL, NULL, &tv)) {
+			fgets(in, 256, stdin);
+			needPrompt = true;
+			memset(dline, 0, 256);
+			strncpy(dline, in, 256);
+
+			line = utils_stringTrim(dline);
+			if ((strlen(line) == 0) || (act->shell == NULL)) {
+				continue;
+			}
+
+			act->shell->executeCommand(act->shell->shell, line, shellTui_write, shellTui_write);
 		}
-		act->shell->executeCommand(act->shell->shell, line, shellTui_write, shellTui_write);
-		free(dline);
 	}
-	apr_thread_exit(thd, APR_SUCCESS);
+
 	return NULL;
 }
 
@@ -86,19 +94,19 @@ void shellTui_initializeService(shell_tu
 	if (activator->shell == NULL) {
 		bundleContext_getServiceReference(activator->context, (char *) OSGI_SHELL_SERVICE_NAME, &activator->reference);
 		if (activator->reference != NULL) {
-		    void *shell_svc = NULL;
-		    bundleContext_getService(activator->context, activator->reference, &shell_svc);
-		    activator->shell = (shell_service_pt) shell_svc;
+			void *shell_svc = NULL;
+			bundleContext_getService(activator->context, activator->reference, &shell_svc);
+			activator->shell = (shell_service_pt) shell_svc;
 		}
 	}
 }
 
 void shellTui_serviceChanged(service_listener_pt listener, service_event_pt event) {
 	bool result = false;
-    shell_tui_activator_pt act = (shell_tui_activator_pt) listener->handle;
-    bool equals = false;
+	shell_tui_activator_pt act = (shell_tui_activator_pt) listener->handle;
+	bool equals = false;
 
-    serviceReference_equals(act->reference, event->reference, &equals);
+	serviceReference_equals(act->reference, event->reference, &equals);
 
 	if ((event->type == OSGI_FRAMEWORK_SERVICE_EVENT_REGISTERED) && (act->reference == NULL)) {
 		shellTui_initializeService(act);
@@ -112,18 +120,23 @@ void shellTui_serviceChanged(service_lis
 }
 
 celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
-	apr_pool_t *pool = NULL;
-	apr_pool_create(&pool, NULL);
-	shell_tui_activator_pt activator = (shell_tui_activator_pt) apr_palloc(pool, sizeof(*activator));
-	//shell_tui_activator_pt activator = (shell_tui_activator_pt) malloc(sizeof(*activator));
-	activator->shell = NULL;
-	activator->pool = pool;
-	(*userData) = activator;
-	return CELIX_SUCCESS;
+	celix_status_t status = CELIX_SUCCESS;
+
+	shell_tui_activator_pt activator = (shell_tui_activator_pt) calloc(1, sizeof(*activator));
+
+	if (activator) {
+		activator->shell = NULL;
+		(*userData) = activator;
+	}
+	else {
+		status = CELIX_ENOMEM;
+	}
+
+	return status;
 }
 
 celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
-    celix_status_t status;
+	celix_status_t status;
 
 	shell_tui_activator_pt act = (shell_tui_activator_pt) userData;
 	service_listener_pt listener = (service_listener_pt) malloc(sizeof(*listener));
@@ -137,32 +150,36 @@ celix_status_t bundleActivator_start(voi
 	status = bundleContext_addServiceListener(context, act->listener, "(objectClass=shellService)");
 
 	if (status == CELIX_SUCCESS) {
-        shellTui_initializeService(act);
-		apr_thread_create(&act->runnable, NULL, shellTui_runnable, act, act->pool);
+		shellTui_initializeService(act);
+		celixThread_create(&act->runnable, NULL, shellTui_runnable, act);
 	}
 
 	return status;
 }
 
 celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
-    celix_status_t status;
-	shell_tui_activator_pt act = (shell_tui_activator_pt) userData;
-	status = bundleContext_removeServiceListener(context, act->listener);
+	celix_status_t status;
+	shell_tui_activator_pt activator = (shell_tui_activator_pt) userData;
+	status = bundleContext_removeServiceListener(context, activator->listener);
 
 	if (status == CELIX_SUCCESS) {
-		apr_status_t join;
-        free(act->listener);
-        act->listener = NULL;
-        act->context = NULL;
-        act->running = false;
-        apr_thread_join(&join, act->runnable);
+		free(activator->listener);
+
+		activator->running = false;
+		activator->listener = NULL;
+		activator->context = NULL;
+		activator->running = false;
+
+		celixThread_join(activator->runnable, NULL);
 	}
 
 	return status;
 }
 
 celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
-    shell_tui_activator_pt act = (shell_tui_activator_pt) userData;
-    apr_pool_destroy(act->pool);
+	shell_tui_activator_pt activator = (shell_tui_activator_pt) userData;
+
+	free(activator);
+
 	return CELIX_SUCCESS;
 }

Modified: celix/branches/celix_config_admin/utils/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/utils/CMakeLists.txt?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/utils/CMakeLists.txt (original)
+++ celix/branches/celix_config_admin/utils/CMakeLists.txt Mon Jan 19 12:26:54 2015
@@ -15,7 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
-celix_subproject(UTILS "Option to build the utilities library" "ON")
+celix_subproject(UTILS "Option to build the utilities library" "OFF")
 if (UTILS) 
     cmake_minimum_required(VERSION 2.6)
     

Modified: celix/branches/celix_config_admin/utils/private/src/celix_threads.c
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/utils/private/src/celix_threads.c?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/utils/private/src/celix_threads.c (original)
+++ celix/branches/celix_config_admin/utils/private/src/celix_threads.c Mon Jan 19 12:26:54 2015
@@ -23,11 +23,21 @@
  *  \author     <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
  *  \copyright  Apache License, Version 2.0
  */
-
+#include <stdlib.h>
 #include "celix_threads.h"
 
+
 celix_status_t celixThread_create(celix_thread_t *new_thread, celix_thread_attr_t *attr, celix_thread_start_t func, void *data) {
-    return pthread_create(new_thread, attr, func, data);
+    celix_status_t status = CELIX_SUCCESS;
+
+	if (pthread_create(&(*new_thread).thread, attr, func, data) != 0) {
+		status = CELIX_BUNDLE_EXCEPTION;
+	}
+	else {
+		(*new_thread).threadInitialized = true;
+	}
+
+	return status;
 }
 
 celix_status_t celixThread_exit(void *exitStatus) {
@@ -37,21 +47,39 @@ celix_status_t celixThread_exit(void *ex
 }
 
 celix_status_t celixThread_detach(celix_thread_t thread) {
-    return pthread_detach(thread);
+    return pthread_detach(thread.thread);
 }
 
-celix_status_t celixThread_join(celix_thread_t thread, void **status) {
-    return pthread_join(thread, status);
+celix_status_t celixThread_join(celix_thread_t thread, void **retVal) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	if (pthread_join(thread.thread, retVal) != 0) {
+		status = CELIX_BUNDLE_EXCEPTION;
+	}
+
+	thread.threadInitialized = false;
+
+    return status;
 }
 
 celix_thread_t celixThread_self() {
-    return pthread_self();
+	celix_thread_t thread;
+
+	thread.thread = pthread_self();
+	thread.threadInitialized = true;
+
+	return thread;
 }
 
 int celixThread_equals(celix_thread_t thread1, celix_thread_t thread2) {
-    return pthread_equal(thread1, thread2);
+    return pthread_equal(thread1.thread, thread2.thread);
 }
 
+bool celixThread_initalized(celix_thread_t thread) {
+    return thread.threadInitialized;
+}
+
+
 celix_status_t celixThreadMutex_create(celix_thread_mutex_t *mutex, celix_thread_mutexattr_t *attr) {
     return pthread_mutex_init(mutex, attr);
 }
@@ -102,6 +130,10 @@ celix_status_t celixThreadCondition_init
     return pthread_cond_init(condition, attr);
 }
 
+celix_status_t celixThreadCondition_destroy(celix_thread_cond_t *condition) {
+    return pthread_cond_destroy(condition);
+}
+
 celix_status_t celixThreadCondition_wait(celix_thread_cond_t *cond, celix_thread_mutex_t *mutex) {
     return pthread_cond_wait(cond, mutex);
 }

Modified: celix/branches/celix_config_admin/utils/public/include/celix_threads.h
URL: http://svn.apache.org/viewvc/celix/branches/celix_config_admin/utils/public/include/celix_threads.h?rev=1652984&r1=1652983&r2=1652984&view=diff
==============================================================================
--- celix/branches/celix_config_admin/utils/public/include/celix_threads.h (original)
+++ celix/branches/celix_config_admin/utils/public/include/celix_threads.h Mon Jan 19 12:26:54 2015
@@ -28,20 +28,33 @@
 #define CELIX_THREADS_H_
 
 #include <pthread.h>
+#include <stdbool.h>
 
 #include "celix_errno.h"
 
-typedef pthread_t celix_thread_t;
+
+struct celix_thread {
+	bool threadInitialized;
+	pthread_t thread;
+};
+
+
+typedef struct celix_thread celix_thread_t;
 typedef pthread_attr_t celix_thread_attr_t;
 
 typedef void *(*celix_thread_start_t)(void*);
 
+static const celix_thread_t celix_thread_default = { .threadInitialized = false };
+
+
 celix_status_t celixThread_create(celix_thread_t *new_thread, celix_thread_attr_t *attr, celix_thread_start_t func, void *data);
 celix_status_t celixThread_exit(void *exitStatus);
 celix_status_t celixThread_detach(celix_thread_t thread);
 celix_status_t celixThread_join(celix_thread_t thread, void **status);
 celix_thread_t celixThread_self();
 int celixThread_equals(celix_thread_t thread1, celix_thread_t thread2);
+bool celixThread_initalized(celix_thread_t thread);
+
 
 typedef pthread_mutex_t celix_thread_mutex_t;
 typedef pthread_mutexattr_t celix_thread_mutexattr_t;
@@ -68,6 +81,7 @@ typedef pthread_cond_t celix_thread_cond
 typedef pthread_condattr_t celix_thread_condattr_t;
 
 celix_status_t celixThreadCondition_init(celix_thread_cond_t *condition, celix_thread_condattr_t *attr);
+celix_status_t celixThreadCondition_destroy(celix_thread_cond_t *condition);
 celix_status_t celixThreadCondition_wait(celix_thread_cond_t *cond, celix_thread_mutex_t *mutex);
 celix_status_t celixThreadCondition_broadcast(celix_thread_cond_t *cond);
 celix_status_t celixThreadCondition_signal(celix_thread_cond_t *cond);



Mime
View raw message