celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [18/21] celix git commit: CELIX-272: Fix threading issue remote_shell
Date Mon, 16 Nov 2015 20:17:32 GMT
CELIX-272: Fix threading issue remote_shell


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

Branch: refs/heads/feature/CELIX-272_synchronization_service_registry
Commit: 93c6a622126c24ce81d4d07b9c73d5086b75ff2b
Parents: e4259db
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Mon Nov 16 21:14:19 2015 +0100
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Mon Nov 16 21:14:19 2015 +0100

----------------------------------------------------------------------
 remote_shell/private/include/shell_mediator.h |  1 +
 remote_shell/private/src/activator.c          |  1 +
 remote_shell/private/src/shell_mediator.c     | 39 +++++++++++-----------
 3 files changed, 21 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/93c6a622/remote_shell/private/include/shell_mediator.h
----------------------------------------------------------------------
diff --git a/remote_shell/private/include/shell_mediator.h b/remote_shell/private/include/shell_mediator.h
index faf86e8..24e8250 100644
--- a/remote_shell/private/include/shell_mediator.h
+++ b/remote_shell/private/include/shell_mediator.h
@@ -47,6 +47,7 @@ struct shell_mediator {
 typedef struct shell_mediator *shell_mediator_pt;
 
 celix_status_t shellMediator_create(bundle_context_pt context, shell_mediator_pt *instance);
+celix_status_t shellMediator_stop(shell_mediator_pt instance);
 celix_status_t shellMediator_destroy(shell_mediator_pt instance);
 celix_status_t shellMediator_executeCommand(shell_mediator_pt instance, char *command, FILE
*out, FILE *err);
 

http://git-wip-us.apache.org/repos/asf/celix/blob/93c6a622/remote_shell/private/src/activator.c
----------------------------------------------------------------------
diff --git a/remote_shell/private/src/activator.c b/remote_shell/private/src/activator.c
index 062420d..4344258 100644
--- a/remote_shell/private/src/activator.c
+++ b/remote_shell/private/src/activator.c
@@ -102,6 +102,7 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt
context)
 	bundle_instance_pt bi = (bundle_instance_pt) userData;
 
 	connectionListener_stop(bi->connectionListener);
+	shellMediator_stop(bi->shellMediator);
 	shellMediator_destroy(bi->shellMediator);
 
 	remoteShell_stopConnections(bi->remoteShell);

http://git-wip-us.apache.org/repos/asf/celix/blob/93c6a622/remote_shell/private/src/shell_mediator.c
----------------------------------------------------------------------
diff --git a/remote_shell/private/src/shell_mediator.c b/remote_shell/private/src/shell_mediator.c
index ab60f3e..9b08035 100644
--- a/remote_shell/private/src/shell_mediator.c
+++ b/remote_shell/private/src/shell_mediator.c
@@ -36,9 +36,7 @@
 #include "log_service.h"
 #include "shell_mediator.h"
 
-static celix_status_t shellMediator_addingService(void *handler, service_reference_pt reference,
void **service);
 static celix_status_t shellMediator_addedService(void *handler, service_reference_pt reference,
void * service);
-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(bundle_context_pt context, shell_mediator_pt *instance)
{
@@ -56,8 +54,8 @@ celix_status_t shellMediator_create(bundle_context_pt context, shell_mediator_pt
 
 		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, serviceTrackerCustomizer_create((*instance), NULL, shellMediator_addedService,
+				NULL, shellMediator_removedService, &customizer));
 		status = CELIX_DO_IF(status, serviceTracker_create(context, (char * )OSGI_SHELL_SERVICE_NAME,
customizer, &(*instance)->tracker));
 
 		if (status == CELIX_SUCCESS) {
@@ -74,18 +72,31 @@ celix_status_t shellMediator_create(bundle_context_pt context, shell_mediator_pt
 	return status;
 }
 
+celix_status_t shellMediator_stop(shell_mediator_pt instance) {
+	service_tracker_pt tracker;
+	celixThreadMutex_lock(&instance->mutex);
+	tracker = instance->tracker;
+	celixThreadMutex_unlock(&instance->mutex);
+
+	if (tracker != NULL) {
+		serviceTracker_close(tracker);
+	}
+}
+
 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);
-
+	serviceTracker_destroy(instance->tracker);
 	logHelper_stop(instance->loghelper);
-
 	status = logHelper_destroy(&instance->loghelper);
+	celixThreadMutex_destroy(&instance->mutex);
+
+
+	free(instance);
+
 
 	return status;
 }
@@ -105,13 +116,6 @@ celix_status_t shellMediator_executeCommand(shell_mediator_pt instance,
char *co
 	return status;
 }
 
-static celix_status_t shellMediator_addingService(void *handler, service_reference_pt reference,
void **service) {
-	celix_status_t status = CELIX_SUCCESS;
-	shell_mediator_pt instance = (shell_mediator_pt) handler;
-	bundleContext_getService(instance->context, reference, service);
-	return status;
-}
-
 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;
@@ -121,11 +125,6 @@ static celix_status_t shellMediator_addedService(void *handler, service_referenc
 	return status;
 }
 
-static celix_status_t shellMediator_modifiedService(void *handler, service_reference_pt reference,
void * service) {
-	celix_status_t status = CELIX_SUCCESS;
-	//ignore
-	return status;
-}
 
 static celix_status_t shellMediator_removedService(void *handler, service_reference_pt reference,
void * service) {
 	celix_status_t status = CELIX_SUCCESS;


Mime
View raw message