You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2017/11/20 20:33:05 UTC
[08/46] celix git commit: CELIX-417: Initial refactoring for CMake
usage
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/examples/calculator_endpoint2/private/src/calculator_endpoint_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_endpoint2/private/src/calculator_endpoint_impl.c b/remote_services/examples/calculator_endpoint2/private/src/calculator_endpoint_impl.c
deleted file mode 100644
index b9a973f..0000000
--- a/remote_services/examples/calculator_endpoint2/private/src/calculator_endpoint_impl.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/**
- *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:dev@celix.apache.org">Apache Celix Project Team</a>
- * \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(remote_endpoint_pt *endpoint) {
- celix_status_t status = CELIX_SUCCESS;
- *endpoint = calloc(1, sizeof(**endpoint));
- if (!*endpoint) {
- status = CELIX_ENOMEM;
- } else {
- (*endpoint)->service = NULL;
- }
-
- 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;
- 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;
- }
-
- json_decref(root);
-
- 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;
-
- json_decref(resultRoot);
- } else {
- printf("CALCULATOR_ENDPOINT: No service available");
- status = CELIX_BUNDLE_EXCEPTION;
- }
- json_decref(root);
- }
-
- 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;
-
- json_decref(resultRoot);
- } else {
- printf("CALCULATOR_ENDPOINT: No service available");
- status = CELIX_BUNDLE_EXCEPTION;
- }
- json_decref(root);
- }
-
- 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;
-
- json_decref(resultRoot);
- } else {
- printf("CALCULATOR_ENDPOINT: No service available");
- status = CELIX_BUNDLE_EXCEPTION;
- }
- json_decref(root);
- }
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/examples/calculator_proxy/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_proxy/CMakeLists.txt b/remote_services/examples/calculator_proxy/CMakeLists.txt
deleted file mode 100644
index 9bbf089..0000000
--- a/remote_services/examples/calculator_proxy/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# 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("../../../utils/public/include")
-include_directories("../../remote_service_admin/public/include")
-include_directories("private/include")
-include_directories("../calculator_service/public/include")
-include_directories("../../endpoint_listener/public/include")
-
-add_bundle(org.apache.celix.calc.api.Calculator_proxy SOURCES
- private/src/calculator_proxy_activator
- private/src/calculator_proxy_impl.c
- ../../remote_service_admin/private/src/remote_proxy_factory_impl.c
-
- private/include/calculator_proxy_impl.h
- VERSION 0.0.1
- SYMBOLIC_NAME "apache_celix_remoting_calculator_proxy"
-)
-
-target_link_libraries(org.apache.celix.calc.api.Calculator_proxy celix_framework ${JANSSON_LIBRARIES})
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/examples/calculator_proxy/private/include/calculator_proxy_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_proxy/private/include/calculator_proxy_impl.h b/remote_services/examples/calculator_proxy/private/include/calculator_proxy_impl.h
deleted file mode 100644
index 86f97b4..0000000
--- a/remote_services/examples/calculator_proxy/private/include/calculator_proxy_impl.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- *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_proxy_impl.h
- *
- * \date Oct 13, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef CALCULATOR_PROXY_IMPL_H_
-#define CALCULATOR_PROXY_IMPL_H_
-
-#include "celix_errno.h"
-
-#include "calculator_service.h"
-#include "remote_proxy.h"
-#include "constants.h"
-#include "bundle_context.h"
-#include "hash_map.h"
-
-#include "endpoint_listener.h"
-
-
-struct calculator {
- bundle_context_pt context;
-
- endpoint_description_pt endpoint;
- sendToHandle sendToCallback;
- void * sendToHandler;
-};
-
-
-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);
-
-celix_status_t calculatorProxy_registerProxyService(void* proxyFactoryService, endpoint_description_pt endpoint, void* handler, sendToHandle callback);
-celix_status_t calculatorProxy_unregisterProxyService(void* proxyFactoryService, endpoint_description_pt endpoint);
-
-#endif /* CALCULATOR_PROXY_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/examples/calculator_proxy/private/src/calculator_proxy_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_proxy/private/src/calculator_proxy_activator.c b/remote_services/examples/calculator_proxy/private/src/calculator_proxy_activator.c
deleted file mode 100644
index acc0651..0000000
--- a/remote_services/examples/calculator_proxy/private/src/calculator_proxy_activator.c
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- *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_proxy_activator.c
- *
- * \date Oct 10, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-
-#include "bundle_activator.h"
-#include "service_registration.h"
-#include "remote_proxy.h"
-
-#include "calculator_proxy_impl.h"
-
-struct activator {
- bundle_context_pt context;
- remote_proxy_factory_pt factory_ptr;
-};
-
-static celix_status_t calculatorProxyFactory_create(void *handle, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback, properties_pt properties, void **service);
-static celix_status_t calculatorProxyFactory_destroy(void *handle, void *service);
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status = CELIX_SUCCESS;
-
- struct activator *activator;
-
- activator = calloc(1, sizeof(*activator));
- if (!activator) {
- status = CELIX_ENOMEM;
- } else {
- activator->factory_ptr = NULL;
- activator->context = context;
-
- *userData = activator;
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- remoteProxyFactory_create(context, (char *) CALCULATOR_SERVICE, activator,
- calculatorProxyFactory_create, calculatorProxyFactory_destroy,
- &activator->factory_ptr);
- remoteProxyFactory_register(activator->factory_ptr);
-
- return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- remoteProxyFactory_unregister(activator->factory_ptr);
- remoteProxyFactory_destroy(&activator->factory_ptr);
-
- 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;
-}
-
-static celix_status_t calculatorProxyFactory_create(void *handle, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback, properties_pt properties, void **service) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = handle;
-
- calculator_service_pt calculatorService = calloc(1, sizeof(*calculatorService));
- calculatorProxy_create(activator->context, &calculatorService->calculator);
- calculatorService->add = calculatorProxy_add;
- calculatorService->sub = calculatorProxy_sub;
- calculatorService->sqrt = calculatorProxy_sqrt;
-
- calculatorService->calculator->endpoint = endpointDescription;
- calculatorService->calculator->sendToHandler = rsa;
- calculatorService->calculator->sendToCallback = sendToCallback;
-
- *service = calculatorService;
-
- return status;
-}
-
-static celix_status_t calculatorProxyFactory_destroy(void *handle, void *service) {
- celix_status_t status = CELIX_SUCCESS;
- calculator_service_pt calculatorService = service;
-
- if (!calculatorService) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- calculatorProxy_destroy(&calculatorService->calculator);
- free(calculatorService);
- }
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/examples/calculator_proxy/private/src/calculator_proxy_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_proxy/private/src/calculator_proxy_impl.c b/remote_services/examples/calculator_proxy/private/src/calculator_proxy_impl.c
deleted file mode 100644
index fc21412..0000000
--- a/remote_services/examples/calculator_proxy/private/src/calculator_proxy_impl.c
+++ /dev/null
@@ -1,173 +0,0 @@
-/**
- *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_proxy_impl.c
- *
- * \date Oct 7, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <jansson.h>
-
-#include <string.h>
-#include <stddef.h>
-
-#include "celix_errno.h"
-#include "array_list.h"
-#include "calculator_proxy_impl.h"
-
-/* Allows the use of Jansson < 2.3 */
-#ifndef JSON_DECODE_ANY
-#define JSON_DECODE_ANY 0
-#endif
-
-celix_status_t calculatorProxy_create(bundle_context_pt context, calculator_pt *calculator) {
- celix_status_t status = CELIX_SUCCESS;
- *calculator = calloc(1, sizeof(**calculator));
- if (!*calculator) {
- status = CELIX_ENOMEM;
- } else {
- (*calculator)->context = context;
- (*calculator)->endpoint = NULL;
- (*calculator)->sendToCallback=NULL;
- (*calculator)->sendToHandler=NULL;
- }
-
- 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;
-
- if (calculator->endpoint != NULL) {
- json_t *root;
- root = json_pack("{s:s, s:[ff]}", "m", "add(DD)D", "a", a, b);
-
- char *data = json_dumps(root, 0);
- char *reply = NULL;
- int replyStatus = 0;
-
- calculator->sendToCallback(calculator->sendToHandler, calculator->endpoint, data, &reply, &replyStatus);
-
- if (status == CELIX_SUCCESS) {
- printf("Handle reply: %s\n", reply);
- json_error_t error;
- json_t *js_reply = json_loads(reply, 0, &error);
- if (js_reply) {
- json_unpack(js_reply, "{s:f}", "r", result);
- json_decref(js_reply);
- } else {
- printf("PROXY: got error '%s' for '%s'\n", error.text, reply);
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
- json_decref(root);
-
- free(data);
- free(reply);
- } else {
- printf("CALCULATOR_PROXY: No endpoint information available\n");
- status = CELIX_BUNDLE_EXCEPTION;
- }
-
- return status;
-}
-
-celix_status_t calculatorProxy_sub(calculator_pt calculator, double a, double b, double *result) {
- celix_status_t status = CELIX_SUCCESS;
- if (calculator->endpoint != NULL) {
- json_t *root;
- root = json_pack("{s:s, s:[ff]}", "m", "sub(DD)D", "a", a, b);
-
- char *data = json_dumps(root, 0);
- char *reply = NULL;
- int replyStatus = 0;
-
- calculator->sendToCallback(calculator->sendToHandler, calculator->endpoint, data, &reply, &replyStatus);
-
- if (status == CELIX_SUCCESS) {
- json_error_t error;
- json_t *js_reply = json_loads(reply, 0, &error);
- if (js_reply) {
- json_unpack(js_reply, "{s:f}", "r", result);
- json_decref(js_reply);
- } else {
- printf("PROXY: got error '%s' for '%s'\n", error.text, reply);
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
-
- json_decref(root);
-
- free(data);
- free(reply);
- } else {
- printf("CALCULATOR_PROXY: No endpoint information available\n");
- status = CELIX_BUNDLE_EXCEPTION;
- }
-
- return status;
-}
-
-celix_status_t calculatorProxy_sqrt(calculator_pt calculator, double a, double *result) {
- celix_status_t status = CELIX_SUCCESS;
- if (calculator->endpoint != NULL) {
- json_t *root;
- root = json_pack("{s:s, s:[f]}", "m", "sqrt(D)D", "a", a);
-
- char *data = json_dumps(root, 0);
- char *reply = NULL;
- int replyStatus;
-
- calculator->sendToCallback(calculator->sendToHandler, calculator->endpoint, data, &reply, &replyStatus);
-
- if (status == CELIX_SUCCESS) {
- json_error_t error;
- json_t *js_reply = json_loads(reply, JSON_DECODE_ANY, &error);
- if (js_reply) {
- json_unpack(js_reply, "{s:f}", "r", result);
- json_decref(js_reply);
- } else {
- printf("PROXY: got error '%s' for '%s'\n", error.text, reply);
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
-
- json_decref(root);
-
- free(data);
- free(reply);
- } else {
- printf("CALCULATOR_PROXY: No endpoint information available\n");
- status = CELIX_BUNDLE_EXCEPTION;
- }
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/examples/calculator_proxy2/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_proxy2/CMakeLists.txt b/remote_services/examples/calculator_proxy2/CMakeLists.txt
deleted file mode 100644
index 01556e3..0000000
--- a/remote_services/examples/calculator_proxy2/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# 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("../../../utils/public/include")
-include_directories("../../remote_service_admin/public/include")
-include_directories("private/include")
-include_directories("../calculator_service/public/include")
-include_directories("../../endpoint_listener/public/include")
-
-add_bundle(org.apache.celix.calc.api.Calculator2_proxy SOURCES
- private/src/calculator_proxy_activator
- private/src/calculator_proxy_impl.c
- ../../remote_service_admin/private/src/remote_proxy_factory_impl.c
-
- private/include/calculator_proxy_impl.h
- VERSION 0.0.1
- SYMBOLIC_NAME "apache_celix_remoting_calculator2_proxy"
-)
-
-target_link_libraries(org.apache.celix.calc.api.Calculator2_proxy celix_framework ${JANSSON_LIBRARIES})
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/examples/calculator_proxy2/private/include/calculator_proxy_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_proxy2/private/include/calculator_proxy_impl.h b/remote_services/examples/calculator_proxy2/private/include/calculator_proxy_impl.h
deleted file mode 100644
index 86f97b4..0000000
--- a/remote_services/examples/calculator_proxy2/private/include/calculator_proxy_impl.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- *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_proxy_impl.h
- *
- * \date Oct 13, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef CALCULATOR_PROXY_IMPL_H_
-#define CALCULATOR_PROXY_IMPL_H_
-
-#include "celix_errno.h"
-
-#include "calculator_service.h"
-#include "remote_proxy.h"
-#include "constants.h"
-#include "bundle_context.h"
-#include "hash_map.h"
-
-#include "endpoint_listener.h"
-
-
-struct calculator {
- bundle_context_pt context;
-
- endpoint_description_pt endpoint;
- sendToHandle sendToCallback;
- void * sendToHandler;
-};
-
-
-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);
-
-celix_status_t calculatorProxy_registerProxyService(void* proxyFactoryService, endpoint_description_pt endpoint, void* handler, sendToHandle callback);
-celix_status_t calculatorProxy_unregisterProxyService(void* proxyFactoryService, endpoint_description_pt endpoint);
-
-#endif /* CALCULATOR_PROXY_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/examples/calculator_proxy2/private/src/calculator_proxy_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_proxy2/private/src/calculator_proxy_activator.c b/remote_services/examples/calculator_proxy2/private/src/calculator_proxy_activator.c
deleted file mode 100644
index 6b9af72..0000000
--- a/remote_services/examples/calculator_proxy2/private/src/calculator_proxy_activator.c
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- *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_proxy_activator.c
- *
- * \date Oct 10, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-
-#include "bundle_activator.h"
-#include "service_registration.h"
-#include "remote_proxy.h"
-
-#include "calculator_proxy_impl.h"
-
-struct activator {
- bundle_context_pt context;
- remote_proxy_factory_pt factory_ptr;
-};
-
-static celix_status_t calculatorProxyFactory_create(void *handle, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback, properties_pt properties, void **service);
-static celix_status_t calculatorProxyFactory_destroy(void *handle, void *service);
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status = CELIX_SUCCESS;
-
- struct activator *activator;
-
- activator = calloc(1, sizeof(*activator));
- if (!activator) {
- status = CELIX_ENOMEM;
- } else {
- activator->factory_ptr = NULL;
- activator->context = context;
-
- *userData = activator;
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- remoteProxyFactory_create(context, CALCULATOR2_SERVICE, activator,
- calculatorProxyFactory_create, calculatorProxyFactory_destroy,
- &activator->factory_ptr);
- remoteProxyFactory_register(activator->factory_ptr);
-
- return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- remoteProxyFactory_unregister(activator->factory_ptr);
- remoteProxyFactory_destroy(&activator->factory_ptr);
-
- 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;
-}
-
-static celix_status_t calculatorProxyFactory_create(void *handle, endpoint_description_pt endpointDescription, remote_service_admin_pt rsa, sendToHandle sendToCallback, properties_pt properties, void **service) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = handle;
-
- calculator_service_pt calculatorService = calloc(1, sizeof(*calculatorService));
- calculatorProxy_create(activator->context, &calculatorService->calculator);
- calculatorService->add = calculatorProxy_add;
- calculatorService->sub = calculatorProxy_sub;
- calculatorService->sqrt = calculatorProxy_sqrt;
-
- calculatorService->calculator->endpoint = endpointDescription;
- calculatorService->calculator->sendToHandler = rsa;
- calculatorService->calculator->sendToCallback = sendToCallback;
-
- *service = calculatorService;
-
- return status;
-}
-
-static celix_status_t calculatorProxyFactory_destroy(void *handle, void *service) {
- celix_status_t status = CELIX_SUCCESS;
- calculator_service_pt calculatorService = service;
-
- if (!calculatorService) {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- if (status == CELIX_SUCCESS) {
- calculatorProxy_destroy(&calculatorService->calculator);
- free(calculatorService);
- }
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/examples/calculator_proxy2/private/src/calculator_proxy_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_proxy2/private/src/calculator_proxy_impl.c b/remote_services/examples/calculator_proxy2/private/src/calculator_proxy_impl.c
deleted file mode 100644
index fc21412..0000000
--- a/remote_services/examples/calculator_proxy2/private/src/calculator_proxy_impl.c
+++ /dev/null
@@ -1,173 +0,0 @@
-/**
- *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_proxy_impl.c
- *
- * \date Oct 7, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <jansson.h>
-
-#include <string.h>
-#include <stddef.h>
-
-#include "celix_errno.h"
-#include "array_list.h"
-#include "calculator_proxy_impl.h"
-
-/* Allows the use of Jansson < 2.3 */
-#ifndef JSON_DECODE_ANY
-#define JSON_DECODE_ANY 0
-#endif
-
-celix_status_t calculatorProxy_create(bundle_context_pt context, calculator_pt *calculator) {
- celix_status_t status = CELIX_SUCCESS;
- *calculator = calloc(1, sizeof(**calculator));
- if (!*calculator) {
- status = CELIX_ENOMEM;
- } else {
- (*calculator)->context = context;
- (*calculator)->endpoint = NULL;
- (*calculator)->sendToCallback=NULL;
- (*calculator)->sendToHandler=NULL;
- }
-
- 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;
-
- if (calculator->endpoint != NULL) {
- json_t *root;
- root = json_pack("{s:s, s:[ff]}", "m", "add(DD)D", "a", a, b);
-
- char *data = json_dumps(root, 0);
- char *reply = NULL;
- int replyStatus = 0;
-
- calculator->sendToCallback(calculator->sendToHandler, calculator->endpoint, data, &reply, &replyStatus);
-
- if (status == CELIX_SUCCESS) {
- printf("Handle reply: %s\n", reply);
- json_error_t error;
- json_t *js_reply = json_loads(reply, 0, &error);
- if (js_reply) {
- json_unpack(js_reply, "{s:f}", "r", result);
- json_decref(js_reply);
- } else {
- printf("PROXY: got error '%s' for '%s'\n", error.text, reply);
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
- json_decref(root);
-
- free(data);
- free(reply);
- } else {
- printf("CALCULATOR_PROXY: No endpoint information available\n");
- status = CELIX_BUNDLE_EXCEPTION;
- }
-
- return status;
-}
-
-celix_status_t calculatorProxy_sub(calculator_pt calculator, double a, double b, double *result) {
- celix_status_t status = CELIX_SUCCESS;
- if (calculator->endpoint != NULL) {
- json_t *root;
- root = json_pack("{s:s, s:[ff]}", "m", "sub(DD)D", "a", a, b);
-
- char *data = json_dumps(root, 0);
- char *reply = NULL;
- int replyStatus = 0;
-
- calculator->sendToCallback(calculator->sendToHandler, calculator->endpoint, data, &reply, &replyStatus);
-
- if (status == CELIX_SUCCESS) {
- json_error_t error;
- json_t *js_reply = json_loads(reply, 0, &error);
- if (js_reply) {
- json_unpack(js_reply, "{s:f}", "r", result);
- json_decref(js_reply);
- } else {
- printf("PROXY: got error '%s' for '%s'\n", error.text, reply);
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
-
- json_decref(root);
-
- free(data);
- free(reply);
- } else {
- printf("CALCULATOR_PROXY: No endpoint information available\n");
- status = CELIX_BUNDLE_EXCEPTION;
- }
-
- return status;
-}
-
-celix_status_t calculatorProxy_sqrt(calculator_pt calculator, double a, double *result) {
- celix_status_t status = CELIX_SUCCESS;
- if (calculator->endpoint != NULL) {
- json_t *root;
- root = json_pack("{s:s, s:[f]}", "m", "sqrt(D)D", "a", a);
-
- char *data = json_dumps(root, 0);
- char *reply = NULL;
- int replyStatus;
-
- calculator->sendToCallback(calculator->sendToHandler, calculator->endpoint, data, &reply, &replyStatus);
-
- if (status == CELIX_SUCCESS) {
- json_error_t error;
- json_t *js_reply = json_loads(reply, JSON_DECODE_ANY, &error);
- if (js_reply) {
- json_unpack(js_reply, "{s:f}", "r", result);
- json_decref(js_reply);
- } else {
- printf("PROXY: got error '%s' for '%s'\n", error.text, reply);
- status = CELIX_BUNDLE_EXCEPTION;
- }
- }
-
- json_decref(root);
-
- free(data);
- free(reply);
- } else {
- printf("CALCULATOR_PROXY: No endpoint information available\n");
- status = CELIX_BUNDLE_EXCEPTION;
- }
-
- return status;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/examples/calculator_service/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_service/CMakeLists.txt b/remote_services/examples/calculator_service/CMakeLists.txt
index a18f22b..5e8040c 100644
--- a/remote_services/examples/calculator_service/CMakeLists.txt
+++ b/remote_services/examples/calculator_service/CMakeLists.txt
@@ -33,5 +33,3 @@ add_bundle(calculator SOURCES
bundle_files(calculator public/include/org.apache.celix.calc.api.Calculator2.descriptor
DESTINATION .)
-
-target_link_libraries(calculator celix_framework)
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/examples/calculator_shell/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/examples/calculator_shell/CMakeLists.txt b/remote_services/examples/calculator_shell/CMakeLists.txt
index 361b688..980fa1a 100644
--- a/remote_services/examples/calculator_shell/CMakeLists.txt
+++ b/remote_services/examples/calculator_shell/CMakeLists.txt
@@ -18,7 +18,6 @@
include_directories("private/include")
include_directories("../../../utils/public/include")
include_directories("../calculator_service/public/include")
-include_directories("../../../shell/public/include")
add_bundle(calculator_shell SOURCES
private/src/add_command
@@ -40,4 +39,4 @@ bundle_files(calculator_shell
DESTINATION .
)
-target_link_libraries(calculator_shell celix_framework)
+target_link_libraries(calculator_shell PRIVATE Celix::shell_api)
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt b/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
index 7e2675c..01ab9bd 100644
--- a/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/rsa/CMakeLists.txt
@@ -41,8 +41,7 @@ add_bundle(remote_service_admin_dfi
${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
${PROJECT_SOURCE_DIR}/remote_services/utils/private/src/civetweb.c
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
)
-target_link_libraries(remote_service_admin_dfi celix_framework celix_utils celix_dfi ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
+target_link_libraries(remote_service_admin_dfi PRIVATE Celix::dfi Celix::log_helper ${CURL_LIBRARIES} ${JANSSON_LIBRARIES})
install_bundle(remote_service_admin_dfi)
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt b/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
index d28ad0b..543d5a1 100644
--- a/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/CMakeLists.txt
@@ -16,9 +16,6 @@
# under the License.
include_directories(
- ${PROJECT_SOURCE_DIR}/framework/public/include
- ${PROJECT_SOURCE_DIR}/utils/public/include
- ${PROJECT_SOURCE_DIR}/utils/public/include
${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include
${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include
bundle
@@ -37,7 +34,7 @@ add_executable(test_rsa_dfi
${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
)
-target_link_libraries(test_rsa_dfi celix_framework celix_utils ${CURL_LIBRARIES} ${CPPUTEST_LIBRARY})
+target_link_libraries(test_rsa_dfi Celix::framework ${CURL_LIBRARIES} ${CPPUTEST_LIBRARY})
get_property(rsa_bundle_file TARGET remote_service_admin_dfi PROPERTY BUNDLE_FILE)
get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE_FILE)
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt
index d172087..27c3804 100644
--- a/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt
+++ b/remote_services/remote_service_admin_dfi/rsa_tst/bundle/CMakeLists.txt
@@ -34,4 +34,4 @@ bundle_files(rsa_dfi_tst_bundle
DESTINATION .
)
-target_link_libraries(rsa_dfi_tst_bundle ${CPPUTEST_LIBRARY} celix_framework celix_utils)
+target_link_libraries(rsa_dfi_tst_bundle PRIVATE ${CPPUTEST_LIBRARY} )
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/remote_service_admin_http/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/CMakeLists.txt b/remote_services/remote_service_admin_http/CMakeLists.txt
deleted file mode 100644
index cc1b99a..0000000
--- a/remote_services/remote_service_admin_http/CMakeLists.txt
+++ /dev/null
@@ -1,55 +0,0 @@
-# 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.
-celix_subproject(RSA_REMOTE_SERVICE_ADMIN_HTTP "Option to enable building the Remote Service Admin Service HTTP bundle" ON)
-if (RSA_REMOTE_SERVICE_ADMIN_HTTP)
- find_package(CURL REQUIRED)
- find_package(UUID REQUIRED)
-
- include_directories(${CURL_INCLUDE_DIRS})
- include_directories(${UUID_INCLUDE_DIR})
- include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/utils/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin_http/private/include")
- include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
-
- add_bundle(remote_service_admin_http
- VERSION 0.9.0
- SYMBOLIC_NAME "apache_celix_remote_service_admin_http"
- NAME "Apache Celix Remote Service Admin HTTP"
- SOURCES
- private/src/remote_service_admin_impl
- private/src/remote_service_admin_activator
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/export_registration_impl
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/import_registration_impl
- ${PROJECT_SOURCE_DIR}/remote_services/utils/private/src/civetweb.c
- ${PROJECT_SOURCE_DIR}/log_service/public/src/log_helper.c
- )
-
- install_bundle(remote_service_admin_http)
-
- target_link_libraries(remote_service_admin_http celix_framework ${CURL_LIBRARIES} ${UUID})
-
- if (ENABLE_TESTING)
- find_package(CppUTest REQUIRED)
- include_directories(${CPPUTEST_INCLUDE_DIR})
- add_subdirectory(private/test)
- endif()
-endif (RSA_REMOTE_SERVICE_ADMIN_HTTP)
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/remote_service_admin_http/private/include/remote_service_admin_http_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/include/remote_service_admin_http_impl.h b/remote_services/remote_service_admin_http/private/include/remote_service_admin_http_impl.h
deleted file mode 100644
index dbf71c9..0000000
--- a/remote_services/remote_service_admin_http/private/include/remote_service_admin_http_impl.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- *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.
- */
-/*
- * remote_service_admin_http_impl.h
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
-#define REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_
-
-#include "remote_service_admin_impl.h"
-#include "log_helper.h"
-#include "civetweb.h"
-
-struct remote_service_admin {
- bundle_context_pt context;
- log_helper_pt loghelper;
-
- celix_thread_mutex_t exportedServicesLock;
- hash_map_pt exportedServices;
-
- celix_thread_mutex_t importedServicesLock;
- hash_map_pt importedServices;
-
- char *port;
- char *ip;
-
- struct mg_context *ctx;
-};
-
-celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin);
-
-#endif /* REMOTE_SERVICE_ADMIN_HTTP_IMPL_H_ */
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c b/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c
deleted file mode 100644
index 2851a29..0000000
--- a/remote_services/remote_service_admin_http/private/src/remote_service_admin_activator.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/**
- *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.
- */
-/*
- * remote_service_admin_activator.c
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-
-#include "bundle_activator.h"
-#include "service_registration.h"
-
-#include "remote_service_admin_http_impl.h"
-#include "export_registration_impl.h"
-#include "import_registration_impl.h"
-
-struct activator {
- remote_service_admin_pt admin;
- remote_service_admin_service_pt adminService;
- service_registration_pt registration;
-};
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator;
-
- activator = calloc(1, sizeof(*activator));
- if (!activator) {
- status = CELIX_ENOMEM;
- } else {
- activator->admin = NULL;
- activator->registration = NULL;
-
- *userData = activator;
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
- remote_service_admin_service_pt remoteServiceAdmin = NULL;
-
- status = remoteServiceAdmin_create(context, &activator->admin);
- if (status == CELIX_SUCCESS) {
- remoteServiceAdmin = calloc(1, sizeof(*remoteServiceAdmin));
- if (!remoteServiceAdmin) {
- status = CELIX_ENOMEM;
- } else {
- remoteServiceAdmin->admin = activator->admin;
- remoteServiceAdmin->exportService = remoteServiceAdmin_exportService;
-
- remoteServiceAdmin->getExportedServices = remoteServiceAdmin_getExportedServices;
- remoteServiceAdmin->getImportedEndpoints = remoteServiceAdmin_getImportedEndpoints;
- remoteServiceAdmin->importService = remoteServiceAdmin_importService;
-
- remoteServiceAdmin->exportReference_getExportedEndpoint = exportReference_getExportedEndpoint;
- remoteServiceAdmin->exportReference_getExportedService = exportReference_getExportedService;
-
- remoteServiceAdmin->exportRegistration_close = remoteServiceAdmin_removeExportedService;
- remoteServiceAdmin->exportRegistration_getException = exportRegistration_getException;
- remoteServiceAdmin->exportRegistration_getExportReference = exportRegistration_getExportReference;
-
- remoteServiceAdmin->importReference_getImportedEndpoint = importReference_getImportedEndpoint;
- remoteServiceAdmin->importReference_getImportedService = importReference_getImportedService;
-
- remoteServiceAdmin->importRegistration_close = remoteServiceAdmin_removeImportedService;
- remoteServiceAdmin->importRegistration_getException = importRegistration_getException;
- remoteServiceAdmin->importRegistration_getImportReference = importRegistration_getImportReference;
-
- status = bundleContext_registerService(context, OSGI_RSA_REMOTE_SERVICE_ADMIN, remoteServiceAdmin, NULL, &activator->registration);
- activator->adminService = remoteServiceAdmin;
- }
- }
-
- return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
- celix_status_t status = CELIX_SUCCESS;
- struct activator *activator = userData;
-
- serviceRegistration_unregister(activator->registration);
- activator->registration = NULL;
-
- remoteServiceAdmin_stop(activator->admin);
-
- remoteServiceAdmin_destroy(&activator->admin);
-
- free(activator->adminService);
-
- 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;
-}
-
-
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c b/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
deleted file mode 100644
index 0b05c1f..0000000
--- a/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
+++ /dev/null
@@ -1,822 +0,0 @@
-/**
- *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.
- */
-/*
- * remote_service_admin_impl.c
- *
- * \date Sep 30, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <netdb.h>
-
-#ifndef ANDROID
-#include <ifaddrs.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <uuid/uuid.h>
-
-#include <curl/curl.h>
-
-#include "remote_service_admin_http_impl.h"
-#include "export_registration_impl.h"
-#include "import_registration_impl.h"
-#include "remote_constants.h"
-#include "constants.h"
-#include "utils.h"
-#include "bundle_context.h"
-#include "bundle.h"
-#include "service_reference.h"
-#include "service_registration.h"
-#include "log_helper.h"
-#include "log_service.h"
-#include "celix_threads.h"
-
-// defines how often the webserver is restarted (with an increased port number)
-#define MAX_NUMBER_OF_RESTARTS 5
-
-struct post {
- const char *readptr;
- int size;
-};
-
-struct get {
- char *writeptr;
- int size;
-};
-
-static const char *data_response_headers =
- "HTTP/1.1 200 OK\r\n"
- "Cache: no-cache\r\n"
- "Content-Type: application/json\r\n"
- "\r\n";
-
-static const char *no_content_response_headers =
- "HTTP/1.1 204 OK\r\n";
-
-// TODO do we need to specify a non-Amdatu specific configuration type?!
-static const char * const CONFIGURATION_TYPE = "org.amdatu.remote.admin.http";
-static const char * const ENDPOINT_URL = "org.amdatu.remote.admin.http.url";
-
-static const char *DEFAULT_PORT = "8888";
-static const char *DEFAULT_IP = "127.0.0.1";
-
-static const unsigned int DEFAULT_TIMEOUT = 0;
-
-static int remoteServiceAdmin_callback(struct mg_connection *conn);
-
-celix_status_t remoteServiceAdmin_installEndpoint(remote_service_admin_pt admin, export_registration_pt registration, service_reference_pt reference, char *interface);
-celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference, properties_pt endpointProperties, char *interface, endpoint_description_pt *description);
-
-static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip);
-
-static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp);
-static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp);
-
-celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_service_admin_pt *admin) {
- celix_status_t status = CELIX_SUCCESS;
-
- *admin = calloc(1, sizeof(**admin));
-
- if (!*admin) {
- status = CELIX_ENOMEM;
- } else {
- unsigned int port_counter = 0;
- const char *port = NULL;
- const char *ip = NULL;
- char *detectedIp = NULL;
- (*admin)->context = context;
- (*admin)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL);
- (*admin)->importedServices = hashMap_create(NULL, NULL, NULL, NULL);
-
- celixThreadMutex_create(&(*admin)->exportedServicesLock, NULL);
- celixThreadMutex_create(&(*admin)->importedServicesLock, NULL);
-
- if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
- logHelper_start((*admin)->loghelper);
- }
-
- bundleContext_getProperty(context, "RSA_PORT", &port);
- if (port == NULL) {
- port = (char *)DEFAULT_PORT;
- }
-
- bundleContext_getProperty(context, "RSA_IP", &ip);
-
- #ifndef ANDROID
- if (ip == NULL) {
- const char *interface = NULL;
-
- bundleContext_getProperty(context, "RSA_INTERFACE", &interface);
- if ((interface != NULL) && (remoteServiceAdmin_getIpAdress((char*)interface, &detectedIp) != CELIX_SUCCESS)) {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: Could not retrieve IP adress for interface %s", interface);
- }
-
- if (ip == NULL) {
- remoteServiceAdmin_getIpAdress(NULL, &detectedIp);
- }
-
- ip = detectedIp;
- }
- #endif
-
- if (ip != NULL) {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Using %s for service annunciation", ip);
- (*admin)->ip = strdup(ip);
- }
- else {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No IP address for service annunciation set. Using %s", DEFAULT_IP);
- (*admin)->ip = strdup((char*) DEFAULT_IP);
- }
-
- if (detectedIp != NULL) {
- free(detectedIp);
- }
-
- // Prepare callbacks structure. We have only one callback, the rest are NULL.
- struct mg_callbacks callbacks;
- memset(&callbacks, 0, sizeof(callbacks));
- callbacks.begin_request = remoteServiceAdmin_callback;
-
- char newPort[10];
- do {
-
- const char *options[] = { "listening_ports", port, NULL};
-
- (*admin)->ctx = mg_start(&callbacks, (*admin), options);
-
- if ((*admin)->ctx != NULL) {
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Start webserver: %s", port);
- (*admin)->port = strdup(port);
- }
- else {
- char* endptr = (char*)port;
- int currentPort = strtol(port, &endptr, 10);
-
- errno = 0;
-
- if (*endptr || errno != 0) {
- currentPort = strtol(DEFAULT_PORT, NULL, 10);
- }
-
- port_counter++;
- snprintf(&newPort[0], 6, "%d", (currentPort+1));
-
- logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_ERROR, "Error while starting rsa server on port %s - retrying on port %s...", port, newPort);
- port = newPort;
- }
- } while(((*admin)->ctx == NULL) && (port_counter < MAX_NUMBER_OF_RESTARTS));
-
- }
- return status;
-}
-
-
-celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt *admin)
-{
- celix_status_t status = CELIX_SUCCESS;
-
- free((*admin)->ip);
- free((*admin)->port);
- free(*admin);
-
- *admin = NULL;
-
- return status;
-}
-
-celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin) {
- celix_status_t status = CELIX_SUCCESS;
-
- celixThreadMutex_lock(&admin->exportedServicesLock);
-
- array_list_pt exportRegistrationList = NULL;
-
- arrayList_create(&exportRegistrationList);
-
- hash_map_iterator_pt iter = hashMapIterator_create(admin->exportedServices);
- while (hashMapIterator_hasNext(iter)) {
- array_list_pt exports = hashMapIterator_nextValue(iter);
- int i;
-
- for (i = 0; i < arrayList_size(exports); i++) {
- export_registration_pt export = arrayList_get(exports, i);
- arrayList_add(exportRegistrationList, export);
- }
- }
- hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&admin->exportedServicesLock);
-
- int i;
-
- for (i = 0; i < arrayList_size(exportRegistrationList); i++) {
- export_registration_pt export = arrayList_get(exportRegistrationList, i);
- exportRegistration_stopTracking(export);
- }
-
- arrayList_destroy(exportRegistrationList);
-
- celixThreadMutex_lock(&admin->importedServicesLock);
-
- iter = hashMapIterator_create(admin->importedServices);
- while (hashMapIterator_hasNext(iter))
- {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
-
- import_registration_factory_pt importFactory = hashMapEntry_getValue(entry);
-
- if (importFactory != NULL) {
- int i;
- for (i = 0; i < arrayList_size(importFactory->registrations); i++)
- {
- import_registration_pt importRegistration = arrayList_get(importFactory->registrations, i);
-
- if (importFactory->trackedFactory != NULL)
- {
- importFactory->trackedFactory->unregisterProxyService(importFactory->trackedFactory->factory, importRegistration->endpointDescription);
- }
- }
-
- serviceTracker_close(importFactory->proxyFactoryTracker);
- importRegistrationFactory_close(importFactory);
-
- hashMapIterator_remove(iter);
- importRegistrationFactory_destroy(&importFactory);
- }
- }
- hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&admin->importedServicesLock);
-
- if (admin->ctx != NULL) {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Stopping webserver...");
- mg_stop(admin->ctx);
- admin->ctx = NULL;
- }
-
- hashMap_destroy(admin->exportedServices, false, false);
- hashMap_destroy(admin->importedServices, false, false);
-
- logHelper_stop(admin->loghelper);
- logHelper_destroy(&admin->loghelper);
-
- return status;
-}
-
-/**
- * Request: http://host:port/services/{service}/{request}
- */
-//void *remoteServiceAdmin_callback(enum mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info) {
-
-static int remoteServiceAdmin_callback(struct mg_connection *conn) {
- int result = 0; // zero means: let civetweb handle it further, any non-zero value means it is handled by us...
-
- const struct mg_request_info *request_info = mg_get_request_info(conn);
- if (request_info->uri != NULL) {
- remote_service_admin_pt rsa = request_info->user_data;
-
-
- if (strncmp(request_info->uri, "/service/", 9) == 0 && strcmp("POST", request_info->request_method) == 0) {
-
- // uri = /services/myservice/call
- const char *uri = request_info->uri;
- // rest = myservice/call
-
- const char *rest = uri+9;
- char *interfaceStart = strchr(rest, '/');
- int pos = interfaceStart - rest;
- char service[pos+1];
- strncpy(service, rest, pos);
- service[pos] = '\0';
-
- celixThreadMutex_lock(&rsa->exportedServicesLock);
-
- hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- array_list_pt exports = hashMapEntry_getValue(entry);
- int expIt = 0;
- for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
- export_registration_pt export = arrayList_get(exports, expIt);
- unsigned long serviceId = strtoul(service,NULL,10);
- if (serviceId == export->endpointDescription->serviceId && export->endpoint != NULL) {
- uint64_t datalength = request_info->content_length;
- char* data = malloc(datalength + 1);
- mg_read(conn, data, datalength);
- data[datalength] = '\0';
-
- char *response = NULL;
- export->endpoint->handleRequest(export->endpoint->endpoint, data, &response);
-
- if (response != NULL) {
- mg_write(conn, data_response_headers, strlen(data_response_headers));
- mg_write(conn, response, strlen(response));
-
- free(response);
- } else {
- mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
- }
- result = 1;
-
- free(data);
- }
- }
- }
- celixThreadMutex_unlock(&rsa->exportedServicesLock);
-
- hashMapIterator_destroy(iter);
- }
- }
-
- return result;
-}
-
-celix_status_t remoteServiceAdmin_handleRequest(remote_service_admin_pt rsa, char *service, char *data, char **reply) {
- celixThreadMutex_lock(&rsa->exportedServicesLock);
-
- hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- array_list_pt exports = hashMapEntry_getValue(entry);
- int expIt = 0;
- for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
- export_registration_pt export = arrayList_get(exports, expIt);
- if (strcmp(service, export->endpointDescription->service) == 0) {
- export->endpoint->handleRequest(export->endpoint->endpoint, data, reply);
- }
- }
- }
- hashMapIterator_destroy(iter);
-
- celixThreadMutex_unlock(&rsa->exportedServicesLock);
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations) {
- celix_status_t status = CELIX_SUCCESS;
- arrayList_create(registrations);
- array_list_pt references = NULL;
- service_reference_pt reference = NULL;
- char filter [256];
-
- snprintf(filter, 256, "(%s=%s)", (char *)OSGI_FRAMEWORK_SERVICE_ID, serviceId);
-
- bundleContext_getServiceReferences(admin->context, NULL, filter, &references);
-
- if(references!=NULL){
- if (arrayList_size(references) >= 1) {
- reference = arrayList_get(references, 0);
- }
- arrayList_destroy(references);
- }
-
- if (reference == NULL) {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "ERROR: expected a reference for service id %s.", serviceId);
- return CELIX_ILLEGAL_STATE;
- }
-
- const char *exportsProp = NULL;
- const char *providedProp = NULL;
- serviceReference_getProperty(reference, OSGI_RSA_SERVICE_EXPORTED_INTERFACES, &exportsProp);
- serviceReference_getProperty(reference, OSGI_FRAMEWORK_OBJECTCLASS, &providedProp);
-
- if (exportsProp == NULL || providedProp == NULL) {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No Services to export.");
- } else {
- char *exports = strndup(exportsProp, 1024*10);
- char *provided = strndup(providedProp, 1024*10);
-
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Export services (%s)", exports);
- array_list_pt interfaces = NULL;
- arrayList_create(&interfaces);
- if (strcmp(utils_stringTrim(exports), "*") == 0) {
- char *save_ptr = NULL;
- char *interface = strtok_r(provided, ",", &save_ptr);
- while (interface != NULL) {
- arrayList_add(interfaces, utils_stringTrim(interface));
- interface = strtok_r(NULL, ",", &save_ptr);
- }
- } else {
- char *provided_save_ptr = NULL;
- char *pinterface = strtok_r(provided, ",", &provided_save_ptr);
- while (pinterface != NULL) {
- char *exports_save_ptr = NULL;
- char *einterface = strtok_r(exports, ",", &exports_save_ptr);
- while (einterface != NULL) {
- if (strcmp(einterface, pinterface) == 0) {
- arrayList_add(interfaces, einterface);
- }
- einterface = strtok_r(NULL, ",", &exports_save_ptr);
- }
- pinterface = strtok_r(NULL, ",", &provided_save_ptr);
- }
- }
-
- if (arrayList_size(interfaces) != 0) {
- int iter = 0;
- for (iter = 0; iter < arrayList_size(interfaces); iter++) {
- char *interface = arrayList_get(interfaces, iter);
- export_registration_pt registration = NULL;
-
- exportRegistration_create(admin->loghelper, reference, NULL, admin, admin->context, ®istration);
- arrayList_add(*registrations, registration);
-
- remoteServiceAdmin_installEndpoint(admin, registration, reference, interface);
- exportRegistration_open(registration);
- exportRegistration_startTracking(registration);
- }
-
- celixThreadMutex_lock(&admin->exportedServicesLock);
- hashMap_put(admin->exportedServices, reference, *registrations);
- celixThreadMutex_unlock(&admin->exportedServicesLock);
-
- }
- arrayList_destroy(interfaces);
- free(exports);
- free(provided);
- }
-
-
-
- return status;
-}
-
-celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration) {
- celix_status_t status;
- export_reference_pt ref = NULL;
-
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_HTTP: Removing exported service");
-
- status = exportRegistration_getExportReference(registration, &ref);
-
- if (status == CELIX_SUCCESS && ref != NULL) {
- service_reference_pt servRef;
- celixThreadMutex_lock(&admin->exportedServicesLock);
- exportReference_getExportedService(ref, &servRef);
-
- array_list_pt registrations = (array_list_pt)hashMap_remove(admin->exportedServices, servRef);
- if(registrations!=NULL){
- arrayList_destroy(registrations);
- }
-
- exportRegistration_close(registration);
- exportRegistration_destroy(®istration);
-
- celixThreadMutex_unlock(&admin->exportedServicesLock);
-
- free(ref);
-
- } else {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "Cannot find reference for registration");
- }
-
- return status;
-}
-
-celix_status_t remoteServiceAdmin_installEndpoint(remote_service_admin_pt admin, export_registration_pt registration, service_reference_pt reference, char *interface) {
- celix_status_t status = CELIX_SUCCESS;
- properties_pt endpointProperties = properties_create();
-
-
- unsigned int size = 0;
- char **keys;
-
- serviceReference_getPropertyKeys(reference, &keys, &size);
- for (int i = 0; i < size; i++) {
- char *key = keys[i];
- const char *value = NULL;
-
- if (serviceReference_getProperty(reference, key, &value) == CELIX_SUCCESS
- && strcmp(key, (char*) OSGI_RSA_SERVICE_EXPORTED_INTERFACES) != 0
- && strcmp(key, (char*) OSGI_FRAMEWORK_OBJECTCLASS) != 0) {
- properties_set(endpointProperties, key, value);
- }
- }
-
- hash_map_entry_pt entry = hashMap_getEntry(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
-
- char* key = hashMapEntry_getKey(entry);
- char *serviceId = (char *) hashMap_remove(endpointProperties, (void *) OSGI_FRAMEWORK_SERVICE_ID);
- const char *uuid = NULL;
-
- char buf[512];
- snprintf(buf, 512, "/service/%s/%s", serviceId, interface);
-
- char url[1024];
- snprintf(url, 1024, "http://%s:%s%s", admin->ip, admin->port, buf);
-
- uuid_t endpoint_uid;
- uuid_generate(endpoint_uid);
- char endpoint_uuid[37];
- uuid_unparse_lower(endpoint_uid, endpoint_uuid);
-
- bundleContext_getProperty(admin->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
- properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
- properties_set(endpointProperties, (char*) OSGI_FRAMEWORK_OBJECTCLASS, interface);
- properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_SERVICE_ID, serviceId);
- properties_set(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID, endpoint_uuid);
- properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED, "true");
- properties_set(endpointProperties, (char*) OSGI_RSA_SERVICE_IMPORTED_CONFIGS, (char*) CONFIGURATION_TYPE);
- properties_set(endpointProperties, (char*) ENDPOINT_URL, url);
-
- endpoint_description_pt endpointDescription = NULL;
- remoteServiceAdmin_createEndpointDescription(admin, reference, endpointProperties, interface, &endpointDescription);
- exportRegistration_setEndpointDescription(registration, endpointDescription);
-
- free(key);
- free(serviceId);
- free(keys);
-
- return status;
-}
-#ifndef ANDROID
-static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip) {
- celix_status_t status = CELIX_BUNDLE_EXCEPTION;
-
- struct ifaddrs *ifaddr, *ifa;
-
- if (getifaddrs(&ifaddr) != -1)
- {
- for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next)
- {
- char host[NI_MAXHOST];
-
- if (ifa->ifa_addr == NULL)
- continue;
-
- if ((getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
- if (interface == NULL) {
- *ip = strdup(host);
- status = CELIX_SUCCESS;
- }
- else if (strcmp(ifa->ifa_name, interface) == 0) {
- *ip = strdup(host);
- status = CELIX_SUCCESS;
- }
- }
- }
-
- freeifaddrs(ifaddr);
- }
-
- return status;
-}
-#endif
-
-
-celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin, service_reference_pt reference,
- properties_pt endpointProperties, char *interface, endpoint_description_pt *description) {
- celix_status_t status = CELIX_SUCCESS;
-
- *description = calloc(1, sizeof(**description));
- if (!*description) {
- status = CELIX_ENOMEM;
- } else {
- (*description)->id = (char*)properties_get(endpointProperties, (char*) OSGI_RSA_ENDPOINT_ID);
- const char *serviceId = NULL;
- serviceReference_getProperty(reference, (char*)OSGI_FRAMEWORK_SERVICE_ID, &serviceId);
- (*description)->serviceId = strtoull(serviceId, NULL, 0);
- (*description)->frameworkUUID = (char*)properties_get(endpointProperties, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
- (*description)->service = strndup(interface, 1024*10);
- (*description)->properties = endpointProperties;
- }
-
- return status;
-}
-
-
-celix_status_t remoteServiceAdmin_destroyEndpointDescription(endpoint_description_pt *description)
-{
- celix_status_t status = CELIX_SUCCESS;
-
- properties_destroy((*description)->properties);
- free((*description)->service);
- free(*description);
-
- return status;
-}
-
-
-celix_status_t remoteServiceAdmin_getExportedServices(remote_service_admin_pt admin, array_list_pt *services) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-celix_status_t remoteServiceAdmin_getImportedEndpoints(remote_service_admin_pt admin, array_list_pt *services) {
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-
-
-celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, endpoint_description_pt endpointDescription, import_registration_pt *registration) {
- celix_status_t status = CELIX_SUCCESS;
-
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Import service %s", endpointDescription->service);
-
- celixThreadMutex_lock(&admin->importedServicesLock);
-
- import_registration_factory_pt registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
-
- // check whether we already have a registration_factory registered in the hashmap
- if (registration_factory == NULL)
- {
- status = importRegistrationFactory_install(admin->loghelper, endpointDescription->service, admin->context, ®istration_factory);
- if (status == CELIX_SUCCESS) {
- hashMap_put(admin->importedServices, endpointDescription->service, registration_factory);
- }
- }
-
- // factory available
- if (status != CELIX_SUCCESS || (registration_factory->trackedFactory == NULL))
- {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: no proxyFactory available.");
- if (status == CELIX_SUCCESS) {
- status = CELIX_SERVICE_EXCEPTION;
- }
- }
- else
- {
- // we create an importRegistration per imported service
- importRegistration_create(endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send, admin->context, registration);
- registration_factory->trackedFactory->registerProxyService(registration_factory->trackedFactory->factory, endpointDescription, admin, (sendToHandle) &remoteServiceAdmin_send);
-
- arrayList_add(registration_factory->registrations, *registration);
- }
-
- celixThreadMutex_unlock(&admin->importedServicesLock);
-
-
- return status;
-}
-
-
-celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration) {
- celix_status_t status = CELIX_SUCCESS;
- endpoint_description_pt endpointDescription = (endpoint_description_pt) registration->endpointDescription;
- import_registration_factory_pt registration_factory = NULL;
-
- celixThreadMutex_lock(&admin->importedServicesLock);
-
- registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices, endpointDescription->service);
-
- // factory available
- if (registration_factory == NULL)
- {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "RSA: Error while retrieving registration factory for imported service %s", endpointDescription->service);
- }
- else
- {
- if (registration_factory->trackedFactory != NULL) {
- registration_factory->trackedFactory->unregisterProxyService(registration_factory->trackedFactory->factory, endpointDescription);
- }
- arrayList_removeElement(registration_factory->registrations, registration);
- importRegistration_destroy(registration);
-
- if (arrayList_isEmpty(registration_factory->registrations))
- {
- logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: closing proxy.");
-
- serviceTracker_close(registration_factory->proxyFactoryTracker);
- importRegistrationFactory_close(registration_factory);
-
- hashMap_remove(admin->importedServices, endpointDescription->service);
-
- importRegistrationFactory_destroy(®istration_factory);
- }
- }
-
- celixThreadMutex_unlock(&admin->importedServicesLock);
-
- return status;
-}
-
-
-celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa, endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus) {
- celix_status_t status = CELIX_SUCCESS;
-
- struct post post;
- struct get get;
- char url[256];
- if (request != NULL) {
-
-
- post.readptr = request;
- post.size = strlen(request);
-
- get.size = 0;
- get.writeptr = malloc(1);
-
- const char* serviceUrl = properties_get(endpointDescription->properties, ENDPOINT_URL);
- if (serviceUrl != NULL) {
- snprintf(url, 256, "%s", serviceUrl);
- } else {
- status = CELIX_BUNDLE_EXCEPTION;
- logHelper_log(rsa->loghelper, OSGI_LOGSERVICE_INFO, "Endpoint Description does not contain mandatory property '%s'", ENDPOINT_URL);
- }
- } else {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
-
- // assume the default timeout
- int timeout = DEFAULT_TIMEOUT;
-
- if (status == CELIX_SUCCESS) {
- const char *timeoutStr = NULL;
-
- // Check if the endpoint has a timeout, if so, use it.
- timeoutStr = (char*)properties_get(endpointDescription->properties, OSGI_RSA_REMOTE_PROXY_TIMEOUT);
- if (timeoutStr == NULL) {
- // If not, get the global variable and use that one.
- status = bundleContext_getProperty(rsa->context, OSGI_RSA_REMOTE_PROXY_TIMEOUT, &timeoutStr);
- }
-
- // Update timeout if a property is used to set it.
- if (timeoutStr != NULL) {
- timeout = atoi(timeoutStr);
- }
- }
-
- if (status == CELIX_SUCCESS) {
-
- CURL *curl;
- CURLcode res;
-
- curl = curl_easy_init();
- if (!curl) {
- status = CELIX_ILLEGAL_STATE;
- } else {
- curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
- curl_easy_setopt(curl, CURLOPT_URL, url);
- curl_easy_setopt(curl, CURLOPT_POST, 1L);
- curl_easy_setopt(curl, CURLOPT_READFUNCTION, remoteServiceAdmin_readCallback);
- curl_easy_setopt(curl, CURLOPT_READDATA, &post);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, remoteServiceAdmin_write);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &get);
- curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t) post.size);
- res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
-
- *reply = get.writeptr;
- *replyStatus = res;
- }
- }
-
- return status;
-}
-
-static size_t remoteServiceAdmin_readCallback(void *ptr, size_t size, size_t nmemb, void *userp) {
- struct post *post = userp;
-
- if (post->size) {
- *(char *) ptr = post->readptr[0];
- post->readptr++;
- post->size--;
- return 1;
- }
-
- return 0;
-}
-
-static size_t remoteServiceAdmin_write(void *contents, size_t size, size_t nmemb, void *userp) {
- size_t realsize = size * nmemb;
- struct get *mem = (struct get *)userp;
-
- mem->writeptr = realloc(mem->writeptr, mem->size + realsize + 1);
- if (mem->writeptr == NULL) {
- /* out of memory! */
- printf("not enough memory (realloc returned NULL)");
- exit(EXIT_FAILURE);
- }
-
- memcpy(&(mem->writeptr[mem->size]), contents, realsize);
- mem->size += realsize;
- mem->writeptr[mem->size] = 0;
-
- return realsize;
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/remote_service_admin_http/private/test/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/test/CMakeLists.txt b/remote_services/remote_service_admin_http/private/test/CMakeLists.txt
deleted file mode 100644
index a199bc2..0000000
--- a/remote_services/remote_service_admin_http/private/test/CMakeLists.txt
+++ /dev/null
@@ -1,58 +0,0 @@
-# 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.
-
-include_directories(
- ${PROJECT_SOURCE_DIR}/framework/public/include
- ${PROJECT_SOURCE_DIR}/utils/public/include
- ${PROJECT_SOURCE_DIR}/utils/public/include
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include
- ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include
- bundle
-)
-
-
-SET(CMAKE_SKIP_BUILD_RPATH FALSE) #TODO needed?
-SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) #TODO needed?
-SET(CMAKE_INSTALL_RPATH "${PROJECT_BINARY_DIR}/framework" "${PROJECT_BINARY_DIR}/utils")
-
-add_executable(test_rsa_http
- run_tests.cpp
- rsa_client_server_tests.cpp
-
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
-)
-target_link_libraries(test_rsa_http celix_framework celix_utils ${CURL_LIBRARIES} ${CPPUTEST_LIBRARY})
-
-get_property(rsa_bundle_file TARGET remote_service_admin_http PROPERTY BUNDLE_FILE)
-get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE_FILE)
-get_property(calculator_shell_bundle_file TARGET calculator_shell PROPERTY BUNDLE_FILE)
-get_property(discovery_configured_bundle_file TARGET discovery_configured PROPERTY BUNDLE_FILE)
-get_property(topology_manager_bundle_file TARGET topology_manager PROPERTY BUNDLE_FILE)
-get_property(calc_proxy_bundle_file TARGET org.apache.celix.calc.api.Calculator_proxy PROPERTY BUNDLE_FILE)
-get_property(calc_endpoint_bundle_file TARGET org.apache.celix.calc.api.Calculator_endpoint PROPERTY BUNDLE_FILE)
-
-get_filename_component(client_endpoints ${calc_proxy_bundle_file} PATH)
-get_filename_component(server_endpoints ${calc_endpoint_bundle_file} PATH)
-
-configure_file(client.properties.in client.properties @ONLY)
-configure_file(server.properties.in server.properties @ONLY)
-
-add_dependencies(test_rsa_http remote_service_admin_http calculator org.apache.celix.calc.api.Calculator_proxy org.apache.celix.calc.api.Calculator_endpoint)
-
-add_test(NAME run_test_rsa_http COMMAND test_rsa_http)
-SETUP_TARGET_FOR_COVERAGE(test_rsa_http_cov test_rsa_http ${CMAKE_BINARY_DIR}/coverage/test_rsa_http/test_rsa_http)
-
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/remote_services/remote_service_admin_http/private/test/client.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/test/client.properties.in b/remote_services/remote_service_admin_http/private/test/client.properties.in
deleted file mode 100644
index b923a1e..0000000
--- a/remote_services/remote_service_admin_http/private/test/client.properties.in
+++ /dev/null
@@ -1,26 +0,0 @@
-# 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.
-
-cosgi.auto.start.1=@rsa_bundle_file@ @calculator_shell_bundle_file@ @discovery_configured_bundle_file@ @topology_manager_bundle_file@ @tst_bundle_file@
-LOGHELPER_ENABLE_STDOUT_FALLBACK=true
-ENDPOINTS=@client_endpoints@
-RSA_PORT=50881
-DISCOVERY_CFG_SERVER_PORT=50991
-DISCOVERY_CFG_POLL_ENDPOINTS=http://127.0.0.1:50992/org.apache.celix.discovery.configured
-org.osgi.framework.storage.clean=onFirstInit
-org.osgi.framework.storage=.cacheClient
-DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file