celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpe...@apache.org
Subject svn commit: r1639074 - in /celix/trunk: log_service/public/include/ log_service/public/src/ remote_shell/ remote_shell/private/include/ remote_shell/private/src/
Date Wed, 12 Nov 2014 21:43:02 GMT
Author: bpetri
Date: Wed Nov 12 21:43:02 2014
New Revision: 1639074

URL: http://svn.apache.org/r1639074
Log:
CELIX-182: added log_helper

Added:
    celix/trunk/log_service/public/include/log_helper.h
    celix/trunk/log_service/public/src/
    celix/trunk/log_service/public/src/log_helper.c
Modified:
    celix/trunk/remote_shell/CMakeLists.txt
    celix/trunk/remote_shell/private/include/remote_shell.h
    celix/trunk/remote_shell/private/include/shell_mediator.h
    celix/trunk/remote_shell/private/src/activator.c
    celix/trunk/remote_shell/private/src/connection_listener.c
    celix/trunk/remote_shell/private/src/remote_shell.c
    celix/trunk/remote_shell/private/src/shell_mediator.c

Added: celix/trunk/log_service/public/include/log_helper.h
URL: http://svn.apache.org/viewvc/celix/trunk/log_service/public/include/log_helper.h?rev=1639074&view=auto
==============================================================================
--- celix/trunk/log_service/public/include/log_helper.h (added)
+++ celix/trunk/log_service/public/include/log_helper.h Wed Nov 12 21:43:02 2014
@@ -0,0 +1,35 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership.  The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+
+#ifndef LOGHELPER_H_
+#define LOGHELPER_H_
+
+#include "bundle_context.h"
+#include "log_service.h"
+
+typedef struct log_helper* log_helper_pt;
+
+celix_status_t logHelper_create(bundle_context_pt context, log_helper_pt* log_helper);
+celix_status_t logHelper_start(log_helper_pt loghelper);
+celix_status_t logHelper_stop(log_helper_pt loghelper);
+celix_status_t logHelper_destroy(log_helper_pt* loghelper);
+celix_status_t logHelper_log(log_helper_pt loghelper, log_level_t level, char* message, ...
);
+
+#endif /* LOGHELPER_H_ */

Added: celix/trunk/log_service/public/src/log_helper.c
URL: http://svn.apache.org/viewvc/celix/trunk/log_service/public/src/log_helper.c?rev=1639074&view=auto
==============================================================================
--- celix/trunk/log_service/public/src/log_helper.c (added)
+++ celix/trunk/log_service/public/src/log_helper.c Wed Nov 12 21:43:02 2014
@@ -0,0 +1,175 @@
+
+#include <stdlib.h>
+#include <stdarg.h>
+
+
+#include "bundle_context.h"
+#include "service_tracker.h"
+#include "celix_threads.h"
+#include "array_list.h"
+
+#include "celix_errno.h"
+#include "log_service.h"
+
+#include "log_helper.h"
+
+struct log_helper {
+	bundle_context_pt bundleContext;
+    service_tracker_pt logServiceTracker;
+	celix_thread_mutex_t logListLock;
+	array_list_pt logServices;
+};
+
+celix_status_t logHelper_logServiceAdded(void *handle, service_reference_pt reference, void
*service);
+celix_status_t logHelper_logServiceRemoved(void *handle, service_reference_pt reference,
void *service);
+
+
+celix_status_t logHelper_create(bundle_context_pt context, log_helper_pt* loghelper)
+{
+	celix_status_t status = CELIX_SUCCESS;
+
+	(*loghelper) = calloc(1, sizeof(**loghelper));
+
+	if (!(*loghelper))
+	{
+		status = CELIX_ENOMEM;
+	}
+	else
+	{
+		(*loghelper)->bundleContext = context;
+		(*loghelper)->logServiceTracker = NULL;
+
+		pthread_mutex_init(&(*loghelper)->logListLock, NULL);
+        arrayList_create(&(*loghelper)->logServices);
+	}
+
+	return status;
+}
+
+celix_status_t logHelper_start(log_helper_pt loghelper)
+{
+	celix_status_t status = CELIX_SUCCESS;
+	service_tracker_customizer_pt logTrackerCustomizer = NULL;
+
+	status = serviceTrackerCustomizer_create(loghelper, NULL, logHelper_logServiceAdded, NULL,
logHelper_logServiceRemoved, &logTrackerCustomizer);
+
+	if (status == CELIX_SUCCESS) {
+		status = serviceTracker_create(loghelper->bundleContext, (char*) OSGI_LOGSERVICE_NAME,
logTrackerCustomizer, &loghelper->logServiceTracker);
+	}
+
+	if (status == CELIX_SUCCESS) {
+		status = serviceTracker_open(loghelper->logServiceTracker);
+	}
+
+	return status;
+}
+
+
+
+celix_status_t logHelper_logServiceAdded(void *handle, service_reference_pt reference, void
*service)
+{
+	log_helper_pt loghelper = handle;
+
+	pthread_mutex_lock(&loghelper->logListLock);
+	arrayList_add(loghelper->logServices, service);
+	pthread_mutex_unlock(&loghelper->logListLock);
+
+	return CELIX_SUCCESS;
+}
+
+celix_status_t logHelper_logServiceRemoved(void *handle, service_reference_pt reference,
void *service)
+{
+	log_helper_pt loghelper = handle;
+
+	pthread_mutex_lock(&loghelper->logListLock);
+	arrayList_removeElement(loghelper->logServices, service);
+	pthread_mutex_unlock(&loghelper->logListLock);
+
+	return CELIX_SUCCESS;
+}
+
+
+celix_status_t logHelper_stop(log_helper_pt loghelper) {
+	celix_status_t status = CELIX_SUCCESS;
+
+    status = serviceTracker_close(loghelper->logServiceTracker);
+
+    return status;
+}
+
+celix_status_t logHelper_destroy(log_helper_pt* loghelper) {
+        celix_status_t status = CELIX_SUCCESS;
+
+        serviceTracker_destroy((*loghelper)->logServiceTracker);
+
+        pthread_mutex_lock(&(*loghelper)->logListLock);
+        arrayList_destroy((*loghelper)->logServices);
+    	pthread_mutex_unlock(&(*loghelper)->logListLock);
+
+        pthread_mutex_destroy(&(*loghelper)->logListLock);
+
+        free(*loghelper);
+        *loghelper = NULL;
+        return status;
+}
+
+
+
+
+celix_status_t logHelper_log(log_helper_pt loghelper, log_level_t level, char* message, ...
)
+{
+    celix_status_t status = CELIX_SUCCESS;
+	va_list listPointer;
+    char msg[512];
+    bool logged = false;
+
+	va_start(listPointer, message);
+	vsprintf(msg, message, listPointer);
+
+	if (loghelper != NULL) {
+		pthread_mutex_lock(&loghelper->logListLock);
+
+		if (arrayList_size(loghelper->logServices) > 0) {
+			int i = 0;
+
+			for (; i < arrayList_size(loghelper->logServices); i++) {
+
+				log_service_pt logService = arrayList_get(loghelper->logServices, i);
+
+				if (logService != NULL) {
+					(logService->log)(logService->logger, level, message);
+					logged = true;
+				}
+			}
+
+		}
+
+		pthread_mutex_unlock(&loghelper->logListLock);
+	}
+
+
+    if (!logged) {
+        char *levelStr = NULL;
+
+        switch (level) {
+            case OSGI_FRAMEWORK_LOG_ERROR:
+                levelStr = "ERROR";
+                break;
+            case OSGI_FRAMEWORK_LOG_WARNING:
+                levelStr = "WARNING";
+                break;
+            case OSGI_FRAMEWORK_LOG_INFO:
+                levelStr = "INFO";
+                break;
+            case OSGI_FRAMEWORK_LOG_DEBUG:
+            default:
+                levelStr = "DEBUG";
+                break;
+        }
+
+        printf("%s: %s\n", levelStr, msg);
+    }
+
+
+	return status;
+}

Modified: celix/trunk/remote_shell/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/trunk/remote_shell/CMakeLists.txt?rev=1639074&r1=1639073&r2=1639074&view=diff
==============================================================================
--- celix/trunk/remote_shell/CMakeLists.txt (original)
+++ celix/trunk/remote_shell/CMakeLists.txt Wed Nov 12 21:43:02 2014
@@ -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)
 endif (REMOTE_SHELL)
\ No newline at end of file

Modified: celix/trunk/remote_shell/private/include/remote_shell.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_shell/private/include/remote_shell.h?rev=1639074&r1=1639073&r2=1639074&view=diff
==============================================================================
--- celix/trunk/remote_shell/private/include/remote_shell.h (original)
+++ celix/trunk/remote_shell/private/include/remote_shell.h Wed Nov 12 21:43:02 2014
@@ -32,6 +32,14 @@
 
 #include "shell_mediator.h"
 
+struct remote_shell {
+	log_helper_pt* loghelper;
+	shell_mediator_pt mediator;
+	celix_thread_mutex_t mutex;
+	int maximumConnections;
+
+	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);

Modified: celix/trunk/remote_shell/private/include/shell_mediator.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_shell/private/include/shell_mediator.h?rev=1639074&r1=1639073&r2=1639074&view=diff
==============================================================================
--- celix/trunk/remote_shell/private/include/shell_mediator.h (original)
+++ celix/trunk/remote_shell/private/include/shell_mediator.h Wed Nov 12 21:43:02 2014
@@ -29,8 +29,21 @@
 #define shellMediator_H_
 
 #include <bundle_context.h>
+#include <service_tracker.h>
 #include <celix_errno.h>
 
+#include <shell.h>
+
+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_create(bundle_context_pt context, shell_mediator_pt *instance);

Modified: celix/trunk/remote_shell/private/src/activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_shell/private/src/activator.c?rev=1639074&r1=1639073&r2=1639074&view=diff
==============================================================================
--- celix/trunk/remote_shell/private/src/activator.c (original)
+++ celix/trunk/remote_shell/private/src/activator.c Wed Nov 12 21:43:02 2014
@@ -31,6 +31,7 @@
 #include "bundle_activator.h"
 #include "bundle_context.h"
 
+#include "log_helper.h"
 #include "connection_listener.h"
 #include "shell_mediator.h"
 #include "remote_shell.h"
@@ -42,6 +43,7 @@
 #define DEFAULT_REMOTE_SHELL_TELNET_MAXCONN 		2
 
 struct bundle_instance {
+	log_helper_pt loghelper;
 	shell_mediator_pt shellMediator;
 	remote_shell_pt remoteShell;
 	connection_listener_pt connectionListener;
@@ -49,9 +51,9 @@ struct bundle_instance {
 
 typedef struct bundle_instance *bundle_instance_pt;
 
-static int bundleActivator_getPort(bundle_context_pt context);
-static int bundleActivator_getMaximumConnections(bundle_context_pt context);
-static int bundleActivator_getProperty(bundle_context_pt context, char * propertyName, int
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;
@@ -66,6 +68,9 @@ celix_status_t bundleActivator_create(bu
 		bi->shellMediator = NULL;
 		bi->remoteShell = NULL;
 		bi->connectionListener = NULL;
+
+		status = logHelper_create(context, &bi->loghelper);
+
 		(*userData) = bi;
 	} else {
 		status = CELIX_ILLEGAL_ARGUMENT;
@@ -79,10 +84,12 @@ celix_status_t bundleActivator_start(voi
 	celix_status_t status = CELIX_SUCCESS;
 	bundle_instance_pt bi = (bundle_instance_pt) userData;
 
-	int port = bundleActivator_getPort(context);
-	int maxConn = bundleActivator_getMaximumConnections(context);
+	int port = bundleActivator_getPort(bi, context);
+	int maxConn = bundleActivator_getMaximumConnections(bi, context);
+
+	status = logHelper_start(bi->loghelper);
 
-	status = shellMediator_create(context, &bi->shellMediator);
+	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));
@@ -95,29 +102,34 @@ celix_status_t bundleActivator_stop(void
 	bundle_instance_pt bi = (bundle_instance_pt) userData;
 
 	shellMediator_destroy(bi->shellMediator);
+
 	connectionListener_stop(bi->connectionListener);
 	remoteShell_stopConnections(bi->remoteShell);
 
+	status = logHelper_stop(bi->loghelper);
+
 	return status;
 }
 
 celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+	celix_status_t status = CELIX_SUCCESS;
 	bundle_instance_pt bi = (bundle_instance_pt) userData;
+
 	connectionListener_destroy(bi->connectionListener);
+	status = logHelper_destroy(&bi->loghelper);
 
-	return CELIX_SUCCESS;
+	return status;
 }
 
-static int 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 int 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 int bundleActivator_getProperty(bundle_context_pt context, char* propertyName, int
defaultValue) {
-
+static int bundleActivator_getProperty(bundle_instance_pt bi, bundle_context_pt context,
char* propertyName, int defaultValue) {
 	char *strValue = NULL;
 	int value;
 
@@ -128,7 +140,7 @@ static int bundleActivator_getProperty(b
 		errno = 0;
 		value = strtol(strValue, &endptr, 10);
 		if (*endptr || errno != 0) {
-			printf("incorrect format for %s\n", propertyName);
+			logHelper_log(bi->loghelper, OSGI_LOGSERVICE_WARNING, "incorrect format for %s", propertyName);
 			value = defaultValue;
 		}
 	}

Modified: celix/trunk/remote_shell/private/src/connection_listener.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_shell/private/src/connection_listener.c?rev=1639074&r1=1639073&r2=1639074&view=diff
==============================================================================
--- celix/trunk/remote_shell/private/src/connection_listener.c (original)
+++ celix/trunk/remote_shell/private/src/connection_listener.c Wed Nov 12 21:43:02 2014
@@ -36,6 +36,9 @@
 #include <netdb.h>
 #include <fcntl.h>
 
+#include "log_service.h"
+#include "log_helper.h"
+
 #include "connection_listener.h"
 
 #include "shell_mediator.h"
@@ -46,6 +49,7 @@
 struct connection_listener {
 	//constant
 	int port;
+	log_helper_pt* loghelper;
 	remote_shell_pt remoteShell;
 	celix_thread_mutex_t mutex;
 
@@ -65,6 +69,7 @@ celix_status_t connectionListener_create
 		(*instance)->port = port;
 		(*instance)->remoteShell = remoteShell;
 		(*instance)->running = false;
+		(*instance)->loghelper = remoteShell->loghelper;
 
 		FD_ZERO(&(*instance)-> pollset);
 
@@ -91,7 +96,7 @@ celix_status_t connectionListener_stop(c
 	instance->running = false;
 	FD_ZERO(&pollset);
 
-	fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "CONNECTION_LISTENER: Stopping thread\n");
+	logHelper_log(*instance->loghelper, OSGI_FRAMEWORK_LOG_INFO, "CONNECTION_LISTENER: Stopping
thread\n");
 
 	celixThreadMutex_lock(&instance->mutex);
 	thread = instance->thread;
@@ -141,16 +146,16 @@ static void* connection_listener_thread(
 		/* Create socket */
 		listenSocket = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
 		if (listenSocket < 0) {
-			fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Error creating socket: %s", strerror(errno));
+			logHelper_log(*instance->loghelper, OSGI_FRAMEWORK_LOG_ERROR, "Error creating socket:
%s", strerror(errno));
 		}
 		else if (setsockopt(listenSocket, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on))
< 0) {
-			fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "cannot set socket option: %s", strerror(errno));
+			logHelper_log(*instance->loghelper, OSGI_FRAMEWORK_LOG_ERROR, "cannot set socket option:
%s", strerror(errno));
 		}
 		else if (bind(listenSocket, rp->ai_addr, rp->ai_addrlen) < 0) {
-			fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "cannot bind: %s", strerror(errno));
+			logHelper_log(*instance->loghelper, OSGI_FRAMEWORK_LOG_ERROR, "cannot bind: %s", strerror(errno));
 		}
 		else if (listen(listenSocket, 5) < 0) {
-			fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "listen failed: %s", strerror(errno));
+			logHelper_log(*instance->loghelper, OSGI_FRAMEWORK_LOG_ERROR, "listen failed: %s",
strerror(errno));
 		}
 		else {
 			status = CELIX_SUCCESS;
@@ -159,7 +164,7 @@ static void* connection_listener_thread(
 
 	if (status == CELIX_SUCCESS) {
 
-		fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "Remote Shell accepting connections on port %d",
instance->port);
+		logHelper_log(*instance->loghelper, OSGI_FRAMEWORK_LOG_INFO, "Remote Shell accepting
connections on port %d", instance->port);
 
 		celixThreadMutex_lock(&instance->mutex);
 		instance->pollset = active_fd_set;
@@ -179,7 +184,7 @@ static void* connection_listener_thread(
 				selectRet = select(listenSocket + 1, &active_fd_set, NULL, NULL, &timeout);
 			} while (selectRet == -1 && errno == EINTR && instance->running ==
true);
 			if (selectRet < 0) {
-				fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "select on listenSocket failed: %s", strerror(errno));
+				logHelper_log(*instance->loghelper, OSGI_FRAMEWORK_LOG_ERROR, "select on listenSocket
failed: %s", strerror(errno));
 				status = CELIX_BUNDLE_EXCEPTION;
 			}
 			else if (selectRet == 0) {
@@ -189,16 +194,16 @@ static void* connection_listener_thread(
 				int acceptedSocket = accept(listenSocket, NULL, NULL);
 
 				if (acceptedSocket < 0) {
-					perror("accept");
+					logHelper_log(*instance->loghelper, OSGI_FRAMEWORK_LOG_ERROR, "REMOTE_SHELL: accept
failed: %s.", strerror(errno));
 					status = CELIX_BUNDLE_EXCEPTION;
 				}
 				else {
-					fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "REMOTE_SHELL: connection established.");
+					logHelper_log(*instance->loghelper, OSGI_FRAMEWORK_LOG_INFO, "REMOTE_SHELL: connection
established.");
 					remoteShell_addConnection(instance->remoteShell, acceptedSocket);
 				}
 			}
 			else {
-				fw_log(logger, OSGI_FRAMEWORK_LOG_DEBUG, "REMOTE_SHELL: received data on a not-expected
file-descriptor?");
+				logHelper_log(*instance->loghelper, OSGI_FRAMEWORK_LOG_DEBUG, "REMOTE_SHELL: received
data on a not-expected file-descriptor?");
 			}
 		}
 	}

Modified: celix/trunk/remote_shell/private/src/remote_shell.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_shell/private/src/remote_shell.c?rev=1639074&r1=1639073&r2=1639074&view=diff
==============================================================================
--- celix/trunk/remote_shell/private/src/remote_shell.c (original)
+++ celix/trunk/remote_shell/private/src/remote_shell.c Wed Nov 12 21:43:02 2014
@@ -30,6 +30,9 @@
 #include <utils.h>
 #include <array_list.h>
 
+#include "log_helper.h"
+
+#include "log_service.h"
 #include "remote_shell.h"
 
 #define COMMAND_BUFF_SIZE (256)
@@ -42,13 +45,7 @@
 
 #define CONNECTION_LISTENER_TIMEOUT_SEC		5
 
-struct remote_shell {
-	shell_mediator_pt mediator;
-	celix_thread_mutex_t mutex;
-	int maximumConnections;
 
-	array_list_pt connections;
-};
 
 struct connection {
 	remote_shell_pt parent;
@@ -70,9 +67,13 @@ celix_status_t remoteShell_create(shell_
 		(*instance)->mediator = mediator;
 		(*instance)->maximumConnections = maximumConnections;
 		(*instance)->connections = NULL;
+		(*instance)->loghelper = &mediator->loghelper;
 
 		status = celixThreadMutex_create(&(*instance)->mutex, NULL);
-		status = arrayList_create(&(*instance)->connections);
+
+		if (status == CELIX_SUCCESS) {
+			status = arrayList_create(&(*instance)->connections);
+		}
 	} else {
 		status = CELIX_ENOMEM;
 	}
@@ -80,13 +81,15 @@ celix_status_t remoteShell_create(shell_
 }
 
 celix_status_t remoteShell_destroy(remote_shell_pt instance) {
+	celix_status_t status = CELIX_SUCCESS;
+
 	remoteShell_stopConnections(instance);
 
 	celixThreadMutex_lock(&instance->mutex);
 	arrayList_destroy(instance->connections);
 	celixThreadMutex_unlock(&instance->mutex);
 
-	return CELIX_SUCCESS;
+	return status;
 }
 
 celix_status_t remoteShell_addConnection(remote_shell_pt instance, int socket) {
@@ -181,14 +184,14 @@ void *remoteShell_connection_run(void *d
 				}
 
 			} else {
-				fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "REMOTE_SHELL: Error while retrieving data");
+				logHelper_log(*connection->parent->loghelper, OSGI_FRAMEWORK_LOG_ERROR, "REMOTE_SHELL:
Error while retrieving data");
 			}
 		}
 	}
 
 	remoteShell_connection_print(connection, RS_GOODBYE);
 
-	fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "REMOTE_SHELL: Closing socket");
+	logHelper_log(*connection->parent->loghelper, OSGI_FRAMEWORK_LOG_INFO, "REMOTE_SHELL:
Closing socket");
 	celixThreadMutex_lock(&connection->parent->mutex);
 	arrayList_removeElement(connection->parent->connections, connection);
 	celixThreadMutex_unlock(&connection->parent->mutex);

Modified: celix/trunk/remote_shell/private/src/shell_mediator.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_shell/private/src/shell_mediator.c?rev=1639074&r1=1639073&r2=1639074&view=diff
==============================================================================
--- celix/trunk/remote_shell/private/src/shell_mediator.c (original)
+++ celix/trunk/remote_shell/private/src/shell_mediator.c Wed Nov 12 21:43:02 2014
@@ -31,18 +31,10 @@
 #include <service_tracker.h>
 #include <command.h>
 
+#include "log_helper.h"
+#include "log_service.h"
 #include "shell_mediator.h"
 
-struct shell_mediator {
-
-	bundle_context_pt context;
-	service_tracker_pt tracker;
-	celix_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 int currentOutputSocket = NULL;
@@ -65,13 +57,16 @@ celix_status_t shellMediator_create(bund
 		(*instance)->tracker = NULL;
 		(*instance)->shellService = NULL;
 
-		status = celixThreadMutex_create(&(*instance)->mutex, NULL);
+		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));
 
 		if (status == CELIX_SUCCESS) {
+			logHelper_start((*instance)->loghelper);
 			serviceTracker_open((*instance)->tracker);
 		}
 	} else {
@@ -79,19 +74,25 @@ celix_status_t shellMediator_create(bund
 	}
 
 	if (status != CELIX_SUCCESS) {
-		printf("Error creating shell_mediator, error code is %i\n", status);
+		logHelper_log((*instance)->loghelper, OSGI_LOGSERVICE_ERROR, "Error creating shell_mediator,
error code is %i\n", status);
 	}
 	return status;
 }
 
 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);
 	celixThreadMutex_unlock(&instance->mutex);
 
-	return CELIX_SUCCESS;
+	logHelper_stop(instance->loghelper);
+
+	status = logHelper_destroy(&instance->loghelper);
+
+	return status;
 }
 
 static void shellMediator_writeOnCurrentSocket(char *buff) {



Mime
View raw message