celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1632598 - in /celix/trunk: framework/private/src/ remote_services/ remote_services/calculator_endpoint2/ remote_services/calculator_endpoint2/private/ remote_services/calculator_endpoint2/private/include/ remote_services/calculator_endpoin...
Date Fri, 17 Oct 2014 14:52:00 GMT
Author: abroekhuis
Date: Fri Oct 17 14:51:59 2014
New Revision: 1632598

URL: http://svn.apache.org/r1632598
Log:
CELIX-170: The installBundle function should always release its lock and not set the return
status.

Added:
    celix/trunk/remote_services/calculator_endpoint2/
    celix/trunk/remote_services/calculator_endpoint2/CMakeLists.txt
    celix/trunk/remote_services/calculator_endpoint2/private/
    celix/trunk/remote_services/calculator_endpoint2/private/include/
    celix/trunk/remote_services/calculator_endpoint2/private/include/calculator_endpoint_impl.h
    celix/trunk/remote_services/calculator_endpoint2/private/src/
    celix/trunk/remote_services/calculator_endpoint2/private/src/calculator_endpoint_activator.c
      - copied, changed from r1632597, celix/trunk/remote_services/calculator_service/private/src/calculator_activator.c
    celix/trunk/remote_services/calculator_endpoint2/private/src/calculator_endpoint_impl.c
Modified:
    celix/trunk/framework/private/src/framework.c
    celix/trunk/remote_services/CMakeLists.txt
    celix/trunk/remote_services/calculator_service/private/src/calculator_activator.c
    celix/trunk/remote_services/deploy.cmake

Modified: celix/trunk/framework/private/src/framework.c
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/src/framework.c?rev=1632598&r1=1632597&r2=1632598&view=diff
==============================================================================
--- celix/trunk/framework/private/src/framework.c (original)
+++ celix/trunk/framework/private/src/framework.c Fri Oct 17 14:51:59 2014
@@ -550,7 +550,7 @@ celix_status_t fw_installBundle2(framewo
             }
         }
     }
-    status = CELIX_DO_IF(status, framework_releaseInstallLock(framework, location));
+    framework_releaseInstallLock(framework, location);
 
     if (status != CELIX_SUCCESS) {
     	fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, "Could not install
bundle");

Modified: celix/trunk/remote_services/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/CMakeLists.txt?rev=1632598&r1=1632597&r2=1632598&view=diff
==============================================================================
--- celix/trunk/remote_services/CMakeLists.txt (original)
+++ celix/trunk/remote_services/CMakeLists.txt Fri Oct 17 14:51:59 2014
@@ -41,6 +41,7 @@ if (REMOTE_SERVICE_ADMIN)
     
     add_subdirectory(calculator_service)
     add_subdirectory(calculator_endpoint)
+    add_subdirectory(calculator_endpoint2)
     add_subdirectory(calculator_proxy)
     add_subdirectory(calculator_shell)
 endif (REMOTE_SERVICE_ADMIN)

Added: celix/trunk/remote_services/calculator_endpoint2/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_endpoint2/CMakeLists.txt?rev=1632598&view=auto
==============================================================================
--- celix/trunk/remote_services/calculator_endpoint2/CMakeLists.txt (added)
+++ celix/trunk/remote_services/calculator_endpoint2/CMakeLists.txt Fri Oct 17 14:51:59 2014
@@ -0,0 +1,36 @@
+# 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.
+
+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_service/public/include")
+
+SET(BUNDLE_SYMBOLICNAME "apache_celix_remoting_calculator2_endpoint")
+SET(BUNDLE_VERSION "0.0.1")
+
+bundle(org.apache.celix.calc.api.Calculator2_endpoint SOURCES 
+	private/src/calculator_endpoint_activator
+	private/src/calculator_endpoint_impl.c
+    
+    private/include/calculator_endpoint_impl.h
+)
+
+target_link_libraries(org.apache.celix.calc.api.Calculator2_endpoint celix_framework ${JANSSON_LIBRARIES})

Added: celix/trunk/remote_services/calculator_endpoint2/private/include/calculator_endpoint_impl.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_endpoint2/private/include/calculator_endpoint_impl.h?rev=1632598&view=auto
==============================================================================
--- celix/trunk/remote_services/calculator_endpoint2/private/include/calculator_endpoint_impl.h
(added)
+++ celix/trunk/remote_services/calculator_endpoint2/private/include/calculator_endpoint_impl.h
Fri Oct 17 14:51:59 2014
@@ -0,0 +1,47 @@
+/**
+ *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.
+ */
+/*
+ * calculator_endpoint.h
+ *
+ *  \date       Oct 7, 2011
+ *  \author    	<a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project
Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+
+#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_setService(remote_endpoint_pt endpoint, void *service);
+
+celix_status_t calculatorEndpoint_handleRequest(remote_endpoint_pt endpoint, char *data,
char **reply);
+
+celix_status_t calculatorEndpoint_add(remote_endpoint_pt endpoint, char *data, char **reply);
+celix_status_t calculatorEndpoint_sub(remote_endpoint_pt endpoint, char *data, char **reply);
+celix_status_t calculatorEndpoint_sqrt(remote_endpoint_pt endpoint, char *data, char **reply);
+
+#endif /* CALCULATOR_ENDPOINT_IMPL_H_ */

Copied: celix/trunk/remote_services/calculator_endpoint2/private/src/calculator_endpoint_activator.c
(from r1632597, celix/trunk/remote_services/calculator_service/private/src/calculator_activator.c)
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_endpoint2/private/src/calculator_endpoint_activator.c?p2=celix/trunk/remote_services/calculator_endpoint2/private/src/calculator_endpoint_activator.c&p1=celix/trunk/remote_services/calculator_service/private/src/calculator_activator.c&r1=1632597&r2=1632598&rev=1632598&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_service/private/src/calculator_activator.c (original)
+++ celix/trunk/remote_services/calculator_endpoint2/private/src/calculator_endpoint_activator.c
Fri Oct 17 14:51:59 2014
@@ -17,42 +17,46 @@
  *under the License.
  */
 /*
- * calculator_activator.c
+ * calculator_endpoint_activator.c
  *
- *  \date       Oct 5, 2011
+ *  \date       Oct 10, 2011
  *  \author    	<a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project
Team</a>
  *  \copyright	Apache License, Version 2.0
  */
 #include <stdlib.h>
 
 #include "bundle_activator.h"
-#include "bundle_context.h"
-#include "service_registration.h"
 
-#include "calculator_impl.h"
-#include "remote_constants.h"
+#include "calculator_endpoint_impl.h"
+#include "service_registration.h"
 
 struct activator {
 	apr_pool_t *pool;
-	service_registration_pt calculatorReg;
+
+	service_registration_pt endpoint;
 };
 
 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 *parentPool = NULL;
 	apr_pool_t *pool = NULL;
 	struct activator *activator;
 
-	status = bundleContext_getMemoryPool(context, &parentpool);
+	status = bundleContext_getMemoryPool(context, &parentPool);
 	if (status == CELIX_SUCCESS) {
-		if (apr_pool_create(&pool, parentpool) != APR_SUCCESS) {
+		if (apr_pool_create(&pool, parentPool) != APR_SUCCESS) {
 			status = CELIX_BUNDLE_EXCEPTION;
 		} else {
 			activator = apr_palloc(pool, sizeof(*activator));
-			activator->pool = pool;
-			activator->calculatorReg = NULL;
+			if (!activator) {
+				status = CELIX_ENOMEM;
+			} else {
+				activator->pool = pool;
+				activator->endpoint = NULL;
 
-			*userData = activator;
+				*userData = activator;
+			}
 		}
 	}
 
@@ -62,27 +66,20 @@ celix_status_t bundleActivator_create(bu
 celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
 	celix_status_t status = CELIX_SUCCESS;
 	struct activator *activator = userData;
-	calculator_pt calculator = NULL;
-	calculator_service_pt service = NULL;
-	properties_pt properties = NULL;
+	remote_endpoint_pt endpoint = NULL;
+	remote_endpoint_service_pt endpointService = NULL;
 
-	status = calculator_create(activator->pool, &calculator);
-	if (status == CELIX_SUCCESS) {
-		service = apr_palloc(activator->pool, sizeof(*service));
-		if (!service) {
-			status = CELIX_ENOMEM;
-		} else {
-			service->calculator = calculator;
-			service->add = calculator_add;
-			service->sub = calculator_sub;
-			service->sqrt = calculator_sqrt;
+	calculatorEndpoint_create(activator->pool, &endpoint);
+	endpointService = apr_palloc(activator->pool, sizeof(*endpointService));
+	endpointService->endpoint = endpoint;
+	endpointService->handleRequest = calculatorEndpoint_handleRequest;
+	endpointService->setService = calculatorEndpoint_setService;
 
-			properties = properties_create();
-			properties_set(properties, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, (char *) CALCULATOR_SERVICE);
+	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, (char *) CALCULATOR_SERVICE, service, properties,
&activator->calculatorReg);
-		}
-	}
 
 	return status;
 }
@@ -91,13 +88,12 @@ celix_status_t bundleActivator_stop(void
 	celix_status_t status = CELIX_SUCCESS;
 	struct activator *activator = userData;
 
-	serviceRegistration_unregister(activator->calculatorReg);
+	serviceRegistration_unregister(activator->endpoint);
 
 	return status;
 }
 
 celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
 	celix_status_t status = CELIX_SUCCESS;
-
 	return status;
 }

Added: celix/trunk/remote_services/calculator_endpoint2/private/src/calculator_endpoint_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_endpoint2/private/src/calculator_endpoint_impl.c?rev=1632598&view=auto
==============================================================================
--- celix/trunk/remote_services/calculator_endpoint2/private/src/calculator_endpoint_impl.c
(added)
+++ celix/trunk/remote_services/calculator_endpoint2/private/src/calculator_endpoint_impl.c
Fri Oct 17 14:51:59 2014
@@ -0,0 +1,164 @@
+/**
+ *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.
+ */
+/*
+ * calculator_endpoint_impl.c
+ *
+ *  \date       Oct 7, 2011
+ *  \author    	<a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project
Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#include <jansson.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 status = CELIX_SUCCESS;
+	*endpoint = apr_palloc(pool, sizeof(**endpoint));
+	if (!*endpoint) {
+		status = CELIX_ENOMEM;
+	} else {
+		(*endpoint)->service = NULL;
+	}
+
+	return status;
+}
+
+celix_status_t calculatorEndpoint_setService(remote_endpoint_pt endpoint, void *service)
{
+	celix_status_t status = CELIX_SUCCESS;
+	endpoint->service = service;
+	return status;
+}
+
+/**
+ * Request: http://host:port/services/{service}
+ */
+celix_status_t calculatorEndpoint_handleRequest(remote_endpoint_pt endpoint, char *data,
char **reply) {
+	celix_status_t status = CELIX_SUCCESS;
+	json_error_t jsonError;
+    json_t *root = json_loads(data, 0, &jsonError);
+    const char *sig;
+    json_unpack(root, "{s:s}", "m", &sig);
+
+	printf("CALCULATOR_ENDPOINT: Handle request \"%s\" with data \"%s\"\n", sig, data);
+	if (strcmp(sig, "add(DD)D") == 0) {
+		calculatorEndpoint_add(endpoint, data, reply);
+	} else if (strcmp(sig, "sub(DD)D") == 0) {
+		calculatorEndpoint_sub(endpoint, data, reply);
+	} else if (strcmp(sig, "sqrt(D)D") == 0) {
+		calculatorEndpoint_sqrt(endpoint, data, reply);
+	} else {
+		status = CELIX_ILLEGAL_ARGUMENT;
+	}
+
+	return status;
+}
+
+celix_status_t calculatorEndpoint_add(remote_endpoint_pt endpoint, char *data, char **reply)
{
+	celix_status_t status = CELIX_SUCCESS;
+	json_error_t jsonError;
+	json_t *root;
+
+	root = json_loads(data, 0, &jsonError);
+	if (!root) {
+		status = CELIX_ILLEGAL_ARGUMENT;
+	} else {
+		double a;
+		double b;
+		json_unpack(root, "{s:[ff]}", "a", &a, &b);
+
+		if (endpoint->service != NULL) {
+			double result;
+			json_t *resultRoot;
+			calculator_service_pt service = endpoint->service;
+			service->add(service->calculator, a, b, &result);
+			resultRoot = json_pack("{s:f}", "r", result);
+
+			char *c = json_dumps(resultRoot, 0);
+			*reply = c;
+		} else {
+			printf("CALCULATOR_ENDPOINT: No service available");
+			status = CELIX_BUNDLE_EXCEPTION;
+		}
+	}
+
+	return status;
+}
+
+celix_status_t calculatorEndpoint_sub(remote_endpoint_pt endpoint, char *data, char **reply)
{
+	celix_status_t status = CELIX_SUCCESS;
+	json_error_t jsonError;
+	json_t *root;
+
+	root = json_loads(data, 0, &jsonError);
+	if (!root) {
+		status = CELIX_ILLEGAL_ARGUMENT;
+	} else {
+		double a;
+		double b;
+		json_unpack(root, "{s:[ff]}", "a", &a, &b);
+
+		if (endpoint->service != NULL) {
+			double result;
+			json_t *resultRoot;
+			calculator_service_pt service = endpoint->service;
+			service->sub(service->calculator, a, b, &result);
+			resultRoot = json_pack("{s:f}", "r", result);
+
+			char *c = json_dumps(resultRoot, JSON_ENCODE_ANY);
+			*reply = c;
+		} else {
+			printf("CALCULATOR_ENDPOINT: No service available");
+			status = CELIX_BUNDLE_EXCEPTION;
+		}
+	}
+
+	return status;
+}
+
+celix_status_t calculatorEndpoint_sqrt(remote_endpoint_pt endpoint, char *data, char **reply)
{
+	celix_status_t status = CELIX_SUCCESS;
+	json_error_t jsonError;
+	json_t *root;
+
+	root = json_loads(data, 0, &jsonError);
+	if (!root) {
+		status = CELIX_ILLEGAL_ARGUMENT;
+	} else {
+		double a;
+		json_unpack(root, "{s:[f]}", "a", &a);
+
+		if (endpoint->service != NULL) {
+			double result;
+			json_t *resultRoot;
+			calculator_service_pt service = endpoint->service;
+			service->sqrt(service->calculator, a, &result);
+			resultRoot = json_pack("{s:f}", "r", result);
+
+			char *c = json_dumps(resultRoot, JSON_ENCODE_ANY);
+			*reply = c;
+		} else {
+			printf("CALCULATOR_ENDPOINT: No service available");
+			status = CELIX_BUNDLE_EXCEPTION;
+		}
+	}
+
+	return status;
+}

Modified: celix/trunk/remote_services/calculator_service/private/src/calculator_activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_service/private/src/calculator_activator.c?rev=1632598&r1=1632597&r2=1632598&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_service/private/src/calculator_activator.c (original)
+++ celix/trunk/remote_services/calculator_service/private/src/calculator_activator.c Fri
Oct 17 14:51:59 2014
@@ -35,6 +35,7 @@
 struct activator {
 	apr_pool_t *pool;
 	service_registration_pt calculatorReg;
+	service_registration_pt calculatorReg2;
 };
 
 celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
@@ -51,6 +52,7 @@ celix_status_t bundleActivator_create(bu
 			activator = apr_palloc(pool, sizeof(*activator));
 			activator->pool = pool;
 			activator->calculatorReg = NULL;
+			activator->calculatorReg2 = NULL;
 
 			*userData = activator;
 		}
@@ -81,6 +83,10 @@ celix_status_t bundleActivator_start(voi
 			properties_set(properties, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, (char *) CALCULATOR_SERVICE);
 
 			bundleContext_registerService(context, (char *) CALCULATOR_SERVICE, service, properties,
&activator->calculatorReg);
+
+			properties_pt properties2 = properties_create();
+            properties_set(properties2, (char *) OSGI_RSA_SERVICE_EXPORTED_INTERFACES, (char
*) "org.apache.celix.calc.api.Calculator2");
+			bundleContext_registerService(context, "org.apache.celix.calc.api.Calculator2", service,
properties2, &activator->calculatorReg2);
 		}
 	}
 
@@ -92,6 +98,7 @@ celix_status_t bundleActivator_stop(void
 	struct activator *activator = userData;
 
 	serviceRegistration_unregister(activator->calculatorReg);
+	serviceRegistration_unregister(activator->calculatorReg2);
 
 	return status;
 }

Modified: celix/trunk/remote_services/deploy.cmake
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/deploy.cmake?rev=1632598&r1=1632597&r2=1632598&view=diff
==============================================================================
--- celix/trunk/remote_services/deploy.cmake (original)
+++ celix/trunk/remote_services/deploy.cmake Fri Oct 17 14:51:59 2014
@@ -17,7 +17,9 @@
 is_enabled(REMOTE_SERVICE_ADMIN)
 if (REMOTE_SERVICE_ADMIN)
     deploy("remote-services-cfg" BUNDLES discovery_configured topology_manager remote_service_admin_http
calculator shell shell_tui log_service log_writer
-                                 ENDPOINTS org.apache.celix.calc.api.Calculator_endpoint)
+                                 ENDPOINTS 
+                                    org.apache.celix.calc.api.Calculator_endpoint
+                                    org.apache.celix.calc.api.Calculator2_endpoint)
     deploy("remote-services-cfg-client" BUNDLES topology_manager remote_service_admin_http
shell shell_tui log_service log_writer calculator_shell discovery_configured
                                         ENDPOINTS org.apache.celix.calc.api.Calculator_proxy)
 



Mime
View raw message