celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpe...@apache.org
Subject svn commit: r1646587 - in /celix/trunk/remote_services: calculator_endpoint/private/include/ calculator_endpoint/private/src/ calculator_endpoint2/ calculator_proxy/private/include/ calculator_proxy/private/src/
Date Thu, 18 Dec 2014 23:57:25 GMT
Author: bpetri
Date: Thu Dec 18 23:57:24 2014
New Revision: 1646587

URL: http://svn.apache.org/r1646587
Log:
CELIX-190,CELIX-182: removed apr from calculator endpoint&proxy, fixed some memory leaks

Modified:
    celix/trunk/remote_services/calculator_endpoint/private/include/calculator_endpoint_impl.h
    celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_activator.c
    celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_impl.c
    celix/trunk/remote_services/calculator_endpoint2/CMakeLists.txt
    celix/trunk/remote_services/calculator_proxy/private/include/calculator_proxy_impl.h
    celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c
    celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c

Modified: celix/trunk/remote_services/calculator_endpoint/private/include/calculator_endpoint_impl.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_endpoint/private/include/calculator_endpoint_impl.h?rev=1646587&r1=1646586&r2=1646587&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_endpoint/private/include/calculator_endpoint_impl.h
(original)
+++ celix/trunk/remote_services/calculator_endpoint/private/include/calculator_endpoint_impl.h
Thu Dec 18 23:57:24 2014
@@ -27,14 +27,13 @@
 #ifndef CALCULATOR_ENDPOINT_IMPL_H_
 #define CALCULATOR_ENDPOINT_IMPL_H_
 
-#include <apr_general.h>
-
 #include "celix_errno.h"
 #include "remote_endpoint_impl.h"
 
 #include "calculator_service.h"
 
-celix_status_t calculatorEndpoint_create(apr_pool_t *pool, remote_endpoint_pt *endpoint);
+celix_status_t calculatorEndpoint_create(remote_endpoint_pt *endpoint);
+celix_status_t calculatorEndpoint_destroy(remote_endpoint_pt *endpoint);
 
 celix_status_t calculatorEndpoint_setService(remote_endpoint_pt endpoint, void *service);
 

Modified: celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_activator.c?rev=1646587&r1=1646586&r2=1646587&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_activator.c
(original)
+++ celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_activator.c
Thu Dec 18 23:57:24 2014
@@ -31,33 +31,23 @@
 #include "service_registration.h"
 
 struct activator {
-	apr_pool_t *pool;
-
-	service_registration_pt endpoint;
+	remote_endpoint_service_pt endpointService;
+	service_registration_pt endpointServiceRegistration;
 };
 
 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->endpoint = NULL;
-
-				*userData = activator;
-			}
-		}
+	activator = calloc(1, sizeof(*activator));
+	if (!activator) {
+		status = CELIX_ENOMEM;
+	} else {
+		activator->endpointService = NULL;
+		activator->endpointServiceRegistration = NULL;
+
+		*userData = activator;
 	}
 
 	return status;
@@ -69,8 +59,8 @@ celix_status_t bundleActivator_start(voi
 	remote_endpoint_pt endpoint = NULL;
 	remote_endpoint_service_pt endpointService = NULL;
 
-	calculatorEndpoint_create(activator->pool, &endpoint);
-	endpointService = apr_palloc(activator->pool, sizeof(*endpointService));
+	calculatorEndpoint_create(&endpoint);
+	endpointService = calloc(1, sizeof(*endpointService));
 	endpointService->endpoint = endpoint;
 	endpointService->handleRequest = calculatorEndpoint_handleRequest;
 	endpointService->setService = calculatorEndpoint_setService;
@@ -78,8 +68,9 @@ celix_status_t bundleActivator_start(voi
 	properties_pt props = properties_create();
 	properties_set(props, (char *) "remote.interface", (char *) CALCULATOR_SERVICE);
 
-	bundleContext_registerService(context, OSGI_RSA_REMOTE_ENDPOINT, endpointService, props,
&activator->endpoint);
+	bundleContext_registerService(context, OSGI_RSA_REMOTE_ENDPOINT, endpointService, props,
&activator->endpointServiceRegistration);
 
+	activator->endpointService = endpointService;
 
 	return status;
 }
@@ -88,12 +79,18 @@ celix_status_t bundleActivator_stop(void
 	celix_status_t status = CELIX_SUCCESS;
 	struct activator *activator = userData;
 
-	serviceRegistration_unregister(activator->endpoint);
+	serviceRegistration_unregister(activator->endpointServiceRegistration);
+
+	free(activator->endpointService->endpoint);
+	free(activator->endpointService);
 
 	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/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_impl.c?rev=1646587&r1=1646586&r2=1646587&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_impl.c
(original)
+++ celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_impl.c
Thu Dec 18 23:57:24 2014
@@ -24,14 +24,15 @@
  *  \copyright	Apache License, Version 2.0
  */
 #include <jansson.h>
+#include <string.h>
 
 #include "celix_errno.h"
 
 #include "calculator_endpoint_impl.h"
 
-celix_status_t calculatorEndpoint_create(apr_pool_t *pool, remote_endpoint_pt *endpoint)
{
+celix_status_t calculatorEndpoint_create(remote_endpoint_pt *endpoint) {
 	celix_status_t status = CELIX_SUCCESS;
-	*endpoint = apr_palloc(pool, sizeof(**endpoint));
+	*endpoint = calloc(1, sizeof(**endpoint));
 	if (!*endpoint) {
 		status = CELIX_ENOMEM;
 	} else {
@@ -41,6 +42,14 @@ celix_status_t calculatorEndpoint_create
 	return status;
 }
 
+celix_status_t calculatorEndpoint_destroy(remote_endpoint_pt *endpoint) {
+	celix_status_t status = CELIX_SUCCESS;
+	free(*endpoint);
+	*endpoint = NULL;
+
+	return status;
+}
+
 celix_status_t calculatorEndpoint_setService(remote_endpoint_pt endpoint, void *service)
{
 	celix_status_t status = CELIX_SUCCESS;
 	endpoint->service = service;
@@ -68,6 +77,8 @@ celix_status_t calculatorEndpoint_handle
 		status = CELIX_ILLEGAL_ARGUMENT;
 	}
 
+	json_decref(root);
+
 	return status;
 }
 
@@ -93,10 +104,13 @@ celix_status_t calculatorEndpoint_add(re
 
 			char *c = json_dumps(resultRoot, 0);
 			*reply = c;
+
+			json_decref(resultRoot);
 		} else {
 			printf("CALCULATOR_ENDPOINT: No service available");
 			status = CELIX_BUNDLE_EXCEPTION;
 		}
+		json_decref(root);
 	}
 
 	return status;
@@ -124,10 +138,13 @@ celix_status_t calculatorEndpoint_sub(re
 
 			char *c = json_dumps(resultRoot, JSON_ENCODE_ANY);
 			*reply = c;
+
+			json_decref(resultRoot);
 		} else {
 			printf("CALCULATOR_ENDPOINT: No service available");
 			status = CELIX_BUNDLE_EXCEPTION;
 		}
+		json_decref(root);
 	}
 
 	return status;
@@ -154,10 +171,13 @@ celix_status_t calculatorEndpoint_sqrt(r
 
 			char *c = json_dumps(resultRoot, JSON_ENCODE_ANY);
 			*reply = c;
+
+			json_decref(resultRoot);
 		} else {
 			printf("CALCULATOR_ENDPOINT: No service available");
 			status = CELIX_BUNDLE_EXCEPTION;
 		}
+		json_decref(root);
 	}
 
 	return status;

Modified: celix/trunk/remote_services/calculator_endpoint2/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_endpoint2/CMakeLists.txt?rev=1646587&r1=1646586&r2=1646587&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_endpoint2/CMakeLists.txt (original)
+++ celix/trunk/remote_services/calculator_endpoint2/CMakeLists.txt Thu Dec 18 23:57:24 2014
@@ -20,7 +20,7 @@ find_package(Jansson REQUIRED)
 include_directories("${JANSSON_INCLUDE_DIRS}")
 include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
 include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/remote_services/calculator_endpoint/private/include")
+include_directories("${PROJECT_SOURCE_DIR}/remote_services/calculator_endpoint2/private/include")
 include_directories("${PROJECT_SOURCE_DIR}/remote_services/calculator_service/public/include")
 
 SET(BUNDLE_SYMBOLICNAME "apache_celix_remoting_calculator2_endpoint")

Modified: celix/trunk/remote_services/calculator_proxy/private/include/calculator_proxy_impl.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_proxy/private/include/calculator_proxy_impl.h?rev=1646587&r1=1646586&r2=1646587&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_proxy/private/include/calculator_proxy_impl.h (original)
+++ celix/trunk/remote_services/calculator_proxy/private/include/calculator_proxy_impl.h Thu
Dec 18 23:57:24 2014
@@ -27,8 +27,6 @@
 #ifndef CALCULATOR_PROXY_IMPL_H_
 #define CALCULATOR_PROXY_IMPL_H_
 
-#include <apr_general.h>
-
 #include "celix_errno.h"
 
 #include "calculator_service.h"
@@ -41,7 +39,6 @@
 
 
 struct calculator {
-	apr_pool_t *pool;
 	bundle_context_pt context;
 
 	endpoint_description_pt endpoint;
@@ -50,7 +47,8 @@ struct calculator {
 };
 
 
-celix_status_t calculatorProxy_create(apr_pool_t *pool, bundle_context_pt context, calculator_pt
*endpoint);
+celix_status_t calculatorProxy_create(bundle_context_pt context, calculator_pt *endpoint);
+celix_status_t calculatorProxy_destroy(calculator_pt *endpoint);
 celix_status_t calculatorProxy_add(calculator_pt calculator, double a, double b, double *result);
 celix_status_t calculatorProxy_sub(calculator_pt calculator, double a, double b, double *result);
 celix_status_t calculatorProxy_sqrt(calculator_pt calculator, double a, double *result);

Modified: celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c?rev=1646587&r1=1646586&r2=1646587&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c
(original)
+++ celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c
Thu Dec 18 23:57:24 2014
@@ -31,32 +31,23 @@
 #include "calculator_proxy_impl.h"
 
 struct activator {
-	apr_pool_t *pool;
-	service_registration_pt proxyFactoryService;
+	service_registration_pt proxyFactoryServiceRegistration;
+	remote_proxy_factory_service_pt proxyFactoryService;
 };
 
 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->proxyFactoryService = NULL;
+	activator = calloc(1, sizeof(*activator));
+	if (!activator) {
+		status = CELIX_ENOMEM;
+	} else {
+		activator->proxyFactoryServiceRegistration = NULL;
+		activator->proxyFactoryService = NULL;
 
-				*userData = activator;
-			}
-		}
+		*userData = activator;
 	}
 
 	return status;
@@ -67,21 +58,23 @@ celix_status_t bundleActivator_start(voi
 	struct activator *activator = userData;
 	remote_proxy_factory_service_pt calculatorProxyFactoryService;
 
-	calculatorProxyFactoryService = apr_palloc(activator->pool, sizeof(*calculatorProxyFactoryService));
-	calculatorProxyFactoryService->pool = activator->pool;
+	calculatorProxyFactoryService = calloc(1, sizeof(*calculatorProxyFactoryService));
 	calculatorProxyFactoryService->context = context;
 	calculatorProxyFactoryService->proxy_registrations = hashMap_create(NULL, NULL, NULL,
NULL);
+	calculatorProxyFactoryService->proxy_instances = hashMap_create(NULL, NULL, NULL, NULL);
 	calculatorProxyFactoryService->registerProxyService = calculatorProxy_registerProxyService;
 	calculatorProxyFactoryService->unregisterProxyService = calculatorProxy_unregisterProxyService;
 
 	properties_pt props = properties_create();
 	properties_set(props, (char *) "proxy.interface", (char *) CALCULATOR_SERVICE);
 
-	if (bundleContext_registerService(context, OSGI_RSA_REMOTE_PROXY_FACTORY, calculatorProxyFactoryService,
props, &activator->proxyFactoryService) == CELIX_SUCCESS)
+	if (bundleContext_registerService(context, OSGI_RSA_REMOTE_PROXY_FACTORY, calculatorProxyFactoryService,
props, &activator->proxyFactoryServiceRegistration) == CELIX_SUCCESS)
 	{
 		printf("CALCULATOR_PROXY: Proxy registered OSGI_RSA_REMOTE_PROXY_FACTORY (%s)\n", OSGI_RSA_REMOTE_PROXY_FACTORY);
 	}
 
+	activator->proxyFactoryService = calculatorProxyFactoryService;
+
 	return status;
 }
 
@@ -90,14 +83,36 @@ celix_status_t bundleActivator_stop(void
 	struct activator *activator = userData;
 
 	// TODO: unregister proxy registrations
-	serviceRegistration_unregister(activator->proxyFactoryService);
-	activator->proxyFactoryService = NULL;
+	serviceRegistration_unregister(activator->proxyFactoryServiceRegistration);
+	activator->proxyFactoryServiceRegistration = NULL;
+
+	hashMap_destroy(activator->proxyFactoryService->proxy_registrations, false, false);
+
+	hash_map_iterator_pt iter = hashMapIterator_create(activator->proxyFactoryService->proxy_instances);
+
+	while(hashMapIterator_hasNext(iter)) {
+		calculator_service_pt calculatorService = (calculator_service_pt) hashMapIterator_nextValue(iter);
+
+		if (calculatorService != NULL) {
+			free(calculatorService->calculator);
+			free(calculatorService);
+		}
+	}
+
+	hashMapIterator_destroy((iter));
+
+	hashMap_destroy(activator->proxyFactoryService->proxy_instances, false, false);
+
+	free(activator->proxyFactoryService);
 
 	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/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c?rev=1646587&r1=1646586&r2=1646587&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c (original)
+++ celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c Thu Dec
18 23:57:24 2014
@@ -26,8 +26,6 @@
 #include <jansson.h>
 
 #include <string.h>
-#include <apr_strings.h>
-
 #include <stddef.h>
 
 #include "celix_errno.h"
@@ -44,13 +42,12 @@ celix_status_t calculatorProxy_setHandle
 celix_status_t calculatorProxy_setCallback(void *proxy, sendToHandle callback);
 
 
-celix_status_t calculatorProxy_create(apr_pool_t *pool, bundle_context_pt context, calculator_pt
*calculator)  {
+celix_status_t calculatorProxy_create(bundle_context_pt context, calculator_pt *calculator)
 {
 	celix_status_t status = CELIX_SUCCESS;
-	*calculator = apr_palloc(pool, sizeof(**calculator));
+	*calculator = calloc(1, sizeof(**calculator));
 	if (!*calculator) {
 		status = CELIX_ENOMEM;
 	} else {
-		(*calculator)->pool = pool;
 		(*calculator)->context = context;
 		(*calculator)->endpoint = NULL;
 		(*calculator)->sendToCallback=NULL;
@@ -60,6 +57,16 @@ celix_status_t calculatorProxy_create(ap
 	return status;
 }
 
+
+celix_status_t calculatorProxy_destroy(calculator_pt *calculator)  {
+	celix_status_t status = CELIX_SUCCESS;
+
+	free(*calculator);
+	*calculator = NULL;
+
+	return status;
+}
+
 // { "m": "" "a":["arg1", "arg2"] }
 celix_status_t calculatorProxy_add(calculator_pt calculator, double a, double b, double *result)
{
 	celix_status_t status = CELIX_SUCCESS;
@@ -179,8 +186,8 @@ celix_status_t calculatorProxy_registerP
 	calculator_pt calculator = NULL;
 	calculator_service_pt calculatorService = NULL;
 
-	calculatorProxy_create(calculatorProxyFactoryService->pool, calculatorProxyFactoryService->context,
&calculator);
-	calculatorService = apr_palloc(calculatorProxyFactoryService->pool, sizeof(*calculatorService));
+	calculatorProxy_create(calculatorProxyFactoryService->context, &calculator);
+	calculatorService = calloc(1, sizeof(*calculatorService));
 	calculatorService->calculator = calculator;
 	calculatorService->add = calculatorProxy_add;
 	calculatorService->sub = calculatorProxy_sub;
@@ -202,7 +209,7 @@ celix_status_t calculatorProxy_registerP
 	}
 
 	hashMap_put(calculatorProxyFactoryService->proxy_registrations, endpointDescription,
proxyReg);
-
+	hashMap_put(calculatorProxyFactoryService->proxy_instances, endpointDescription, calculatorService);
 
 	return status;
 }
@@ -213,12 +220,17 @@ celix_status_t calculatorProxy_unregiste
 
 	remote_proxy_factory_service_pt calculatorProxyFactoryService = (remote_proxy_factory_service_pt)
proxyFactoryService;
 	service_registration_pt proxyReg = hashMap_get(calculatorProxyFactoryService->proxy_registrations,
endpointDescription);
+	calculator_service_pt calculatorService = hashMap_get(calculatorProxyFactoryService->proxy_instances,
endpointDescription);
 
-	if (proxyReg != NULL)
-	{
+	if (proxyReg != NULL) {
 		serviceRegistration_unregister(proxyReg);
 	}
 
+	if (calculatorService != NULL) {
+		free(calculatorService->calculator);
+		free(calculatorService);
+	}
+
 	return status;
 }
 



Mime
View raw message