You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by ab...@apache.org on 2014/08/13 10:46:10 UTC
svn commit: r1617689 [1/2] - in /celix/trunk: framework/private/src/
framework/public/include/ remote_services/
remote_services/calculator_endpoint/
remote_services/calculator_endpoint/private/src/
remote_services/calculator_proxy/ remote_services/calc...
Author: abroekhuis
Date: Wed Aug 13 08:46:09 2014
New Revision: 1617689
URL: http://svn.apache.org/r1617689
Log:
CELIX-136: Applied patch.
Added:
celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_common.h
celix/trunk/remote_services/discovery_configured/private/include/endpoint_discovery_server.h
celix/trunk/remote_services/discovery_configured/private/src/endpoint_discovery_server.c
celix/trunk/remote_services/utils/private/
celix/trunk/remote_services/utils/private/include/
celix/trunk/remote_services/utils/private/include/civetweb.h
- copied, changed from r1613832, celix/trunk/remote_services/remote_service_admin_http/private/include/civetweb.h
celix/trunk/remote_services/utils/private/src/
celix/trunk/remote_services/utils/private/src/civetweb.c
- copied, changed from r1613832, celix/trunk/remote_services/remote_service_admin_http/private/src/civetweb.c
celix/trunk/remote_services/utils/private/src/md5.inl
- copied, changed from r1613832, celix/trunk/remote_services/remote_service_admin_http/private/src/md5.inl
Removed:
celix/trunk/remote_services/remote_service_admin_http/private/include/civetweb.h
celix/trunk/remote_services/remote_service_admin_http/private/src/civetweb.c
celix/trunk/remote_services/remote_service_admin_http/private/src/md5.inl
Modified:
celix/trunk/framework/private/src/utils.c
celix/trunk/framework/public/include/service_tracker.h
celix/trunk/remote_services/calculator_endpoint/CMakeLists.txt
celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_impl.c
celix/trunk/remote_services/calculator_proxy/CMakeLists.txt
celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c
celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c
celix/trunk/remote_services/calculator_service/CMakeLists.txt
celix/trunk/remote_services/calculator_service/public/include/calculator_service.h
celix/trunk/remote_services/calculator_shell/CMakeLists.txt
celix/trunk/remote_services/deploy.cmake
celix/trunk/remote_services/discovery_configured/CMakeLists.txt
celix/trunk/remote_services/discovery_configured/private/include/discovery.h
celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_reader.h
celix/trunk/remote_services/discovery_configured/private/include/endpoint_discovery_poller.h
celix/trunk/remote_services/discovery_configured/private/src/discovery.c
celix/trunk/remote_services/discovery_configured/private/src/discovery_activator.c
celix/trunk/remote_services/discovery_configured/private/src/endpoint_descriptor_reader.c
celix/trunk/remote_services/discovery_configured/private/src/endpoint_descriptor_writer.c
celix/trunk/remote_services/discovery_configured/private/src/endpoint_discovery_poller.c
celix/trunk/remote_services/remote_service_admin/private/src/endpoint_description.c
celix/trunk/remote_services/remote_service_admin/public/include/endpoint_description.h
celix/trunk/remote_services/remote_service_admin_http/CMakeLists.txt
celix/trunk/remote_services/remote_service_admin_http/private/src/import_registration_impl.c
celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
celix/trunk/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
celix/trunk/remote_services/topology_manager/private/src/topology_manager.c
celix/trunk/remote_services/utils/public/include/remote_constants.h
Modified: celix/trunk/framework/private/src/utils.c
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/src/utils.c?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/framework/private/src/utils.c (original)
+++ celix/trunk/framework/private/src/utils.c Wed Aug 13 08:46:09 2014
@@ -68,14 +68,16 @@ char * utils_stringTrim(char * string) {
char *end;
// Trim leading space
- while(isspace(*copy)) copy++;
+ while (isspace(*copy)) {
+ copy++;
+ }
// Trim trailing space
end = copy + strlen(copy) - 1;
- while(end > copy && isspace(*end)) end--;
-
- // Write new null terminator
- *(end+1) = 0;
+ while(end > copy && isspace(*end)) {
+ *(end) = 0;
+ end--;
+ }
return copy;
}
Modified: celix/trunk/framework/public/include/service_tracker.h
URL: http://svn.apache.org/viewvc/celix/trunk/framework/public/include/service_tracker.h?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/framework/public/include/service_tracker.h (original)
+++ celix/trunk/framework/public/include/service_tracker.h Wed Aug 13 08:46:09 2014
@@ -40,6 +40,7 @@ FRAMEWORK_EXPORT celix_status_t serviceT
FRAMEWORK_EXPORT celix_status_t serviceTracker_open(service_tracker_pt tracker);
FRAMEWORK_EXPORT celix_status_t serviceTracker_close(service_tracker_pt tracker);
+FRAMEWORK_EXPORT celix_status_t serviceTracker_destroy(service_tracker_pt tracker);
FRAMEWORK_EXPORT service_reference_pt serviceTracker_getServiceReference(service_tracker_pt tracker);
FRAMEWORK_EXPORT array_list_pt serviceTracker_getServiceReferences(service_tracker_pt tracker);
Modified: celix/trunk/remote_services/calculator_endpoint/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_endpoint/CMakeLists.txt?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_endpoint/CMakeLists.txt (original)
+++ celix/trunk/remote_services/calculator_endpoint/CMakeLists.txt Wed Aug 13 08:46:09 2014
@@ -17,7 +17,7 @@
find_package(Jansson REQUIRED)
-include_directories(${JANSSON_INCLUDE_DIRS})
+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")
@@ -26,11 +26,11 @@ include_directories("${PROJECT_SOURCE_DI
SET(BUNDLE_SYMBOLICNAME "apache_celix_remoting_calculator_endpoint")
SET(BUNDLE_VERSION "0.0.1")
-bundle(org.example.api.Calculator_endpoint SOURCES
+bundle(org.apache.celix.calc.api.Calculator_endpoint SOURCES
private/src/calculator_endpoint_activator
private/src/calculator_endpoint_impl.c
private/include/calculator_endpoint_impl.h
)
-target_link_libraries(org.example.api.Calculator_endpoint celix_framework ${JANSSON_LIBRARIES})
+target_link_libraries(org.apache.celix.calc.api.Calculator_endpoint celix_framework ${JANSSON_LIBRARIES})
Modified: celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_impl.c?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_impl.c (original)
+++ celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_impl.c Wed Aug 13 08:46:09 2014
@@ -92,7 +92,7 @@ celix_status_t calculatorEndpoint_add(re
json_t *resultRoot;
calculator_service_pt service = endpoint->service;
service->add(service->calculator, a, b, &result);
- resultRoot = json_pack("[f]", result);
+ resultRoot = json_pack("f", result);
char *c = json_dumps(resultRoot, JSON_ENCODE_ANY);
*reply = c;
@@ -123,7 +123,7 @@ celix_status_t calculatorEndpoint_sub(re
json_t *resultRoot;
calculator_service_pt service = endpoint->service;
service->sub(service->calculator, a, b, &result);
- resultRoot = json_pack("[f]", result);
+ resultRoot = json_pack("f", result);
char *c = json_dumps(resultRoot, JSON_ENCODE_ANY);
*reply = c;
@@ -153,7 +153,7 @@ celix_status_t calculatorEndpoint_sqrt(r
json_t *resultRoot;
calculator_service_pt service = endpoint->service;
service->sqrt(service->calculator, a, &result);
- resultRoot = json_pack("[f]", result);
+ resultRoot = json_pack("f", result);
char *c = json_dumps(resultRoot, JSON_ENCODE_ANY);
*reply = c;
Modified: celix/trunk/remote_services/calculator_proxy/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_proxy/CMakeLists.txt?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_proxy/CMakeLists.txt (original)
+++ celix/trunk/remote_services/calculator_proxy/CMakeLists.txt Wed Aug 13 08:46:09 2014
@@ -17,7 +17,7 @@
find_package(Jansson REQUIRED)
-include_directories(${JANSSON_INCLUDE_DIRS})
+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_proxy/private/include")
@@ -27,11 +27,11 @@ include_directories("${PROJECT_SOURCE_DI
SET(BUNDLE_SYMBOLICNAME "apache_celix_remoting_calculator_proxy")
SET(BUNDLE_VERSION "0.0.1")
-bundle(org.example.api.Calculator_proxy SOURCES
+bundle(org.apache.celix.calc.api.Calculator_proxy SOURCES
private/src/calculator_proxy_activator
private/src/calculator_proxy_impl.c
private/include/calculator_proxy_impl.h
)
-target_link_libraries(org.example.api.Calculator_proxy celix_framework ${JANSSON_LIBRARIES})
+target_link_libraries(org.apache.celix.calc.api.Calculator_proxy celix_framework ${JANSSON_LIBRARIES})
Modified: celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c (original)
+++ celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_activator.c Wed Aug 13 08:46:09 2014
@@ -77,7 +77,7 @@ celix_status_t bundleActivator_start(voi
properties_pt props = properties_create();
properties_set(props, (char *) "proxy.interface", (char *) CALCULATOR_SERVICE);
- if (bundleContext_registerService(context, OSGI_RSA_REMOTE_PROXY_FACTORY, calculatorProxyFactoryService, props, &activator->proxyFactoryService) == CELIX_SUCCESS);
+ if (bundleContext_registerService(context, OSGI_RSA_REMOTE_PROXY_FACTORY, calculatorProxyFactoryService, props, &activator->proxyFactoryService) == CELIX_SUCCESS)
{
printf("CALCULATOR_PROXY: Proxy registered OSGI_RSA_REMOTE_PROXY_FACTORY (%s)\n", OSGI_RSA_REMOTE_PROXY_FACTORY);
}
Modified: celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c (original)
+++ celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c Wed Aug 13 08:46:09 2014
@@ -50,7 +50,6 @@ celix_status_t calculatorProxy_create(ap
(*calculator)->endpoint = NULL;
(*calculator)->sendToCallback=NULL;
(*calculator)->sendToHandler=NULL;
-
}
return status;
@@ -65,21 +64,27 @@ celix_status_t calculatorProxy_add(calcu
root = json_pack("{s:s, s:[ff]}", "m", "add(DD)D", "a", a, b);
char *data = json_dumps(root, 0);
- char *reply = calloc(128, sizeof(char));
+ char *reply = malloc(256);
int replyStatus = 0;
- printf("Send: %s\n", data);
-
calculator->sendToCallback(calculator->sendToHandler, calculator->endpoint, data, &reply, &replyStatus);
if (status == CELIX_SUCCESS) {
- json_error_t jsonError;
- json_t *js_reply = json_loads(reply, 0, &jsonError);
- json_unpack(js_reply, "[f]", result);
+ json_error_t error;
+ json_t *js_reply = json_loads(reply, JSON_DECODE_ANY, &error);
+ if (js_reply) {
+ json_unpack(js_reply, "f", result);
+ } else {
+ printf("PROXY: got error '%s' for '%s'\n", error.text, reply);
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
}
+ free(data);
+ free(reply);
} else {
printf("CALCULATOR_PROXY: No endpoint information available\n");
+ status = CELIX_BUNDLE_EXCEPTION;
}
return status;
@@ -92,18 +97,27 @@ celix_status_t calculatorProxy_sub(calcu
root = json_pack("{s:s, s:[ff]}", "m", "sub(DD)D", "a", a, b);
char *data = json_dumps(root, 0);
- char *reply = calloc(128, sizeof(char));
+ char *reply = malloc(128);
int replyStatus = 0;
calculator->sendToCallback(calculator->sendToHandler, calculator->endpoint, data, &reply, &replyStatus);
if (status == CELIX_SUCCESS) {
- json_error_t jsonError;
- json_t *js_reply = json_loads(reply, 0, &jsonError);
- json_unpack(js_reply, "[f]", result);
+ json_error_t error;
+ json_t *js_reply = json_loads(reply, JSON_DECODE_ANY, &error);
+ if (js_reply) {
+ json_unpack(js_reply, "f", result);
+ } else {
+ printf("PROXY: got error '%s' for '%s'\n", error.text, reply);
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
}
+
+ free(data);
+ free(reply);
} else {
printf("CALCULATOR_PROXY: No endpoint information available\n");
+ status = CELIX_BUNDLE_EXCEPTION;
}
return status;
@@ -116,18 +130,27 @@ celix_status_t calculatorProxy_sqrt(calc
root = json_pack("{s:s, s:[f]}", "m", "sqrt(D)D", "a", a);
char *data = json_dumps(root, 0);
- char *reply = calloc(128, sizeof(char));
+ char *reply = malloc(128);
int replyStatus;
calculator->sendToCallback(calculator->sendToHandler, calculator->endpoint, data, &reply, &replyStatus);
if (status == CELIX_SUCCESS) {
- json_error_t jsonError;
- json_t *js_reply = json_loads(reply, 0, &jsonError);
- json_unpack(js_reply, "[f]", result);
+ json_error_t error;
+ json_t *js_reply = json_loads(reply, JSON_DECODE_ANY, &error);
+ if (js_reply) {
+ json_unpack(js_reply, "f", result);
+ } else {
+ printf("PROXY: got error '%s' for '%s'\n", error.text, reply);
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
}
+
+ free(data);
+ free(reply);
} else {
printf("CALCULATOR_PROXY: No endpoint information available\n");
+ status = CELIX_BUNDLE_EXCEPTION;
}
return status;
Modified: celix/trunk/remote_services/calculator_service/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_service/CMakeLists.txt?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_service/CMakeLists.txt (original)
+++ celix/trunk/remote_services/calculator_service/CMakeLists.txt Wed Aug 13 08:46:09 2014
@@ -21,7 +21,7 @@ include_directories("${PROJECT_SOURCE_DI
include_directories("${PROJECT_SOURCE_DIR}/remote_services/calculator_service/private/include")
include_directories("${PROJECT_SOURCE_DIR}/remote_services/calculator_service/public/include")
-SET(BUNDLE_SYMBOLICNAME "apache_celix_remoting_calculator")
+SET(BUNDLE_SYMBOLICNAME "apache_celix_remoting_calculator_impl")
SET(BUNDLE_VERSION "0.0.1")
bundle(calculator SOURCES
Modified: celix/trunk/remote_services/calculator_service/public/include/calculator_service.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_service/public/include/calculator_service.h?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_service/public/include/calculator_service.h (original)
+++ celix/trunk/remote_services/calculator_service/public/include/calculator_service.h Wed Aug 13 08:46:09 2014
@@ -27,12 +27,21 @@
#ifndef CALCULATOR_SERVICE_H_
#define CALCULATOR_SERVICE_H_
-#define CALCULATOR_SERVICE "org.example.api.Calculator"
+#define CALCULATOR_SERVICE "org.apache.celix.calc.api.Calculator"
typedef struct calculator *calculator_pt;
typedef struct calculator_service *calculator_service_pt;
+/*
+ * The calculator service definition corresponds to the following Java interface:
+ *
+ * interface Calculator {
+ * double add(double a, double b);
+ * double sub(double a, double b);
+ * double sqrt(double a);
+ * }
+ */
struct calculator_service {
calculator_pt calculator;
celix_status_t (*add)(calculator_pt calculator, double a, double b, double *result);
@@ -41,12 +50,5 @@ struct calculator_service {
};
-/*
- * interface calculator_service {
- * double add(double a, double b);
- * double sub(double a, double b);
- * double sqrt(double a);
- * }
- */
#endif /* CALCULATOR_SERVICE_H_ */
Modified: celix/trunk/remote_services/calculator_shell/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_shell/CMakeLists.txt?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_shell/CMakeLists.txt (original)
+++ celix/trunk/remote_services/calculator_shell/CMakeLists.txt Wed Aug 13 08:46:09 2014
@@ -15,14 +15,19 @@
# specific language governing permissions and limitations
# under the License.
+include_directories("${PROJECT_SOURCE_DIR}/remote_services/calculator_shell/private/include")
+include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
+include_directories("${PROJECT_SOURCE_DIR}/remote_services/calculator_service/public/include")
+include_directories("${PROJECT_SOURCE_DIR}/shell/public/include")
+
SET(BUNDLE_SYMBOLICNAME "apache_celix_remoting_calculator_shell")
SET(BUNDLE_VERSION "0.0.1")
bundle(calculator_shell SOURCES
- private/src/add_command
- private/src/sub_command
- private/src/sqrt_command
- private/src/calculator_shell_activator
+ private/src/add_command
+ private/src/sub_command
+ private/src/sqrt_command
+ private/src/calculator_shell_activator
private/include/add_command.h
private/include/sqrt_command.h
@@ -30,9 +35,4 @@ bundle(calculator_shell SOURCES
${PROJECT_SOURCE_DIR}/shell/public/src/command.c
)
-include_directories("${PROJECT_SOURCE_DIR}/remote_services/calculator_shell/private/include")
-include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/remote_services/calculator_service/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/shell/public/include")
target_link_libraries(calculator_shell celix_framework)
-
Modified: celix/trunk/remote_services/deploy.cmake
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/deploy.cmake?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/remote_services/deploy.cmake (original)
+++ celix/trunk/remote_services/deploy.cmake Wed Aug 13 08:46:09 2014
@@ -17,13 +17,20 @@
is_enabled(REMOTE_SERVICE_ADMIN)
if (REMOTE_SERVICE_ADMIN)
deploy("remote-services-bj" BUNDLES discovery_bonjour topology_manager remote_service_admin_http calculator shell shell_tui log_service log_writer
- ENDPOINTS org.example.api.Calculator_endpoint)
+ ENDPOINTS org.apache.celix.calc.api.Calculator_endpoint)
deploy("remote-services-bj-client" BUNDLES topology_manager remote_service_admin_http shell shell_tui log_service log_writer calculator_shell discovery_bonjour
- ENDPOINTS org.example.api.Calculator_proxy)
-
- deploy("remote-services" BUNDLES discovery_slp topology_manager remote_service_admin_http calculator org.example.api.Calculator_endpoint shell shell_tui log_service log_writer)
- deploy("remote-services-client" BUNDLES topology_manager remote_service_admin_http org.example.api.Calculator_proxy shell shell_tui log_service log_writer calculator_shell discovery_slp)
-
+ ENDPOINTS org.apache.celix.calc.api.Calculator_proxy)
+
+ deploy("remote-services-slp" BUNDLES discovery_slp topology_manager remote_service_admin_http calculator shell shell_tui log_service log_writer
+ ENDPOINTS org.apache.celix.calc.api.Calculator_endpoint)
+ deploy("remote-services-slp-client" BUNDLES topology_manager remote_service_admin_http shell shell_tui log_service log_writer calculator_shell discovery_slp
+ ENDPOINTS org.apache.celix.calc.api.Calculator_proxy)
+
+ 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)
+ 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)
+
#TODO for remote-service-client the discovery should be added as last. If this is not done,
#discovery will discover services before the topology manager is registered as
#endpoint listener and services will be lost. This needs further study.
@@ -34,8 +41,8 @@ if (RSA_BUNDLES_REMOTE_SERVICE_ADMIN_SHM
is_enabled(RSA_BUNDLES_DISCOVERY_SHM)
if (RSA_BUNDLES_DISCOVERY_SHM)
deploy("remote-services-shm" BUNDLES discovery_shm topology_manager remote_service_admin_shm calculator shell shell_tui log_service log_writer
- ENDPOINTS org.example.api.Calculator_endpoint)
+ ENDPOINTS org.apache.celix.calc.api.Calculator_endpoint)
deploy("remote-services-shm-client" BUNDLES topology_manager remote_service_admin_shm shell shell_tui log_service log_writer calculator_shell discovery_shm
- ENDPOINTS org.example.api.Calculator_proxy)
+ ENDPOINTS org.apache.celix.calc.api.Calculator_proxy)
endif (RSA_BUNDLES_DISCOVERY_SHM)
endif (RSA_BUNDLES_REMOTE_SERVICE_ADMIN_SHM)
Modified: celix/trunk/remote_services/discovery_configured/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery_configured/CMakeLists.txt?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/remote_services/discovery_configured/CMakeLists.txt (original)
+++ celix/trunk/remote_services/discovery_configured/CMakeLists.txt Wed Aug 13 08:46:09 2014
@@ -15,46 +15,49 @@
# specific language governing permissions and limitations
# under the License.
-#TODO find_package(DNS-SD REQUIRED)
-
find_package(CURL REQUIRED)
find_package(LibXml2 REQUIRED)
-include_directories(${LIBXML2_INCLUDE_DIR})
-
-include_directories("/usr/include") #TODO check if this has impact on the generated project indexer paths
+include_directories("${CURL_INCLUDE_DIR}")
+include_directories("${LIBXML2_INCLUDE_DIR}")
include_directories("${PROJECT_SOURCE_DIR}/utils/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/discovery_configured/private/include")
include_directories("${PROJECT_SOURCE_DIR}/remote_services/endpoint_listener/public/include")
include_directories("${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include")
include_directories(private/include)
-include_directories("${CURL_INCLUDE_DIR}")
-
SET_HEADER(BUNDLE_SYMBOLICNAME "apache_celix_rsa_discovery_configured")
SET_HEADERS("Bundle-Name: Apache Celix RSA Configured Discovery")
bundle(discovery_configured SOURCES
private/src/discovery.c
private/src/discovery_activator.c
+ private/src/endpoint_descriptor_reader.c
+ private/src/endpoint_descriptor_writer.c
private/src/endpoint_discovery_poller.c
+ private/src/endpoint_discovery_server.c
+ ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
+ ${PROJECT_SOURCE_DIR}/remote_services/utils/private/src/civetweb.c
)
install_bundle(discovery_configured)
-target_link_libraries(discovery_configured celix_framework ${CURL_LIBRARIES} ${APRUTIL_LIBRARY})
-
-add_executable(descparser
- private/src/endpoint_descriptor_reader.c
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c)
-
-target_link_libraries(descparser ${LIBXML2_LIBRARIES} celix_framework celix_utils)
-
-
-add_executable(descwriter
- private/src/endpoint_descriptor_writer.c
- ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c)
-
-target_link_libraries(descwriter ${LIBXML2_LIBRARIES} celix_framework celix_utils)
+target_link_libraries(discovery_configured celix_framework ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} ${APRUTIL_LIBRARY})
+if (RSA_ENDPOINT_TEST_READER)
+ add_executable(descparser
+ private/src/endpoint_descriptor_reader.c
+ ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c)
+
+ target_link_libraries(descparser ${LIBXML2_LIBRARIES} celix_framework celix_utils)
+endif (RSA_ENDPOINT_TEST_READER)
+
+if (RSA_ENDPOINT_TEST_WRITER)
+ add_executable(descwriter
+ private/src/endpoint_descriptor_writer.c
+ ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c)
+
+ target_link_libraries(descwriter ${LIBXML2_LIBRARIES} celix_framework celix_utils)
+endif(RSA_ENDPOINT_TEST_WRITER)
\ No newline at end of file
Modified: celix/trunk/remote_services/discovery_configured/private/include/discovery.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery_configured/private/include/discovery.h?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/remote_services/discovery_configured/private/include/discovery.h (original)
+++ celix/trunk/remote_services/discovery_configured/private/include/discovery.h Wed Aug 13 08:46:09 2014
@@ -27,16 +27,18 @@
#ifndef DISCOVERY_H_
#define DISCOVERY_H_
-#include <apr_general.h>
-
#include "bundle_context.h"
#include "service_reference.h"
+#include "endpoint_description.h"
#include "endpoint_listener.h"
typedef struct discovery *discovery_pt;
-celix_status_t discovery_create(apr_pool_t *pool, bundle_context_pt context, discovery_pt *discovery);
+celix_status_t discovery_create(bundle_context_pt context, discovery_pt *discovery);
+celix_status_t discovery_destroy(discovery_pt *discovery);
+
+celix_status_t discovery_start(discovery_pt discovery);
celix_status_t discovery_stop(discovery_pt discovery);
celix_status_t discovery_endpointAdded(void *handle, endpoint_description_pt endpoint, char *machtedFilter);
@@ -49,5 +51,7 @@ celix_status_t discovery_endpointListene
celix_status_t discovery_updateEndpointListener(discovery_pt discovery, service_reference_pt reference, endpoint_listener_pt service);
+celix_status_t discovery_addDiscoveredEndpoint(discovery_pt discovery, endpoint_description_pt endpoint);
+celix_status_t discovery_removeDiscoveredEndpoint(discovery_pt discovery, endpoint_description_pt endpoint);
#endif /* DISCOVERY_H_ */
Added: celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_common.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_common.h?rev=1617689&view=auto
==============================================================================
--- celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_common.h (added)
+++ celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_common.h Wed Aug 13 08:46:09 2014
@@ -0,0 +1,65 @@
+/**
+ * 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.
+ */
+/*
+ * endpoint_descriptor_common.h
+ *
+ * \date Aug 8, 2014
+ * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef ENDPOINT_DESCRIPTOR_COMMON_H_
+#define ENDPOINT_DESCRIPTOR_COMMON_H_
+
+/*
+ * Private constant & enum definitions for endpoint descriptor reader and writer, not needed for normal usage of the reader and writer.
+ */
+
+typedef enum {
+ VALUE_TYPE_STRING,
+ VALUE_TYPE_LONG,
+ VALUE_TYPE_DOUBLE,
+ VALUE_TYPE_FLOAT,
+ VALUE_TYPE_INTEGER,
+ VALUE_TYPE_BYTE,
+ VALUE_TYPE_CHAR,
+ VALUE_TYPE_BOOLEAN,
+ VALUE_TYPE_SHORT,
+} valueType;
+
+
+static valueType valueTypeFromString(char *name);
+static char* valueTypeToString(valueType type);
+
+static const xmlChar* XML = (const xmlChar*) "xml";
+static const xmlChar* XMLNS = (const xmlChar*) "http://www.osgi.org/xmlns/rsa/v1.0.0";
+
+static const xmlChar* ENDPOINT_DESCRIPTIONS = (const xmlChar*) "endpoint-descriptions";
+static const xmlChar* ENDPOINT_DESCRIPTION = (const xmlChar*) "endpoint-description";
+
+static const xmlChar* ARRAY = (const xmlChar*) "array";
+static const xmlChar* LIST = (const xmlChar*) "list";
+static const xmlChar* SET = (const xmlChar*) "set";
+
+static const xmlChar* PROPERTY = (const xmlChar*) "property";
+static const xmlChar* NAME = (const xmlChar*) "name";
+static const xmlChar* VALUE = (const xmlChar*) "value";
+static const xmlChar* VALUE_TYPE = (const xmlChar*) "value-type";
+
+#endif /* ENDPOINT_DESCRIPTOR_COMMON_H_ */
Modified: celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_reader.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_reader.h?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_reader.h (original)
+++ celix/trunk/remote_services/discovery_configured/private/include/endpoint_descriptor_reader.h Wed Aug 13 08:46:09 2014
@@ -33,6 +33,8 @@
typedef struct endpoint_descriptor_reader *endpoint_descriptor_reader_pt;
celix_status_t endpointDescriptorReader_create(endpoint_descriptor_reader_pt *reader);
+celix_status_t endpointDescriptorReader_destroy(endpoint_descriptor_reader_pt reader);
+
celix_status_t endpointDescriptorReader_parseDocument(endpoint_descriptor_reader_pt reader, char *document, array_list_pt *endpoints);
Modified: celix/trunk/remote_services/discovery_configured/private/include/endpoint_discovery_poller.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery_configured/private/include/endpoint_discovery_poller.h?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/remote_services/discovery_configured/private/include/endpoint_discovery_poller.h (original)
+++ celix/trunk/remote_services/discovery_configured/private/include/endpoint_discovery_poller.h Wed Aug 13 08:46:09 2014
@@ -1,27 +1,27 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* endpoint_discovery_poller.h
*
- * \date 3 Jul 2014
- * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \date 3 Jul 2014
+ * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
#ifndef ENDPOINT_DISCOVERY_POLLER_H_
@@ -32,10 +32,11 @@
typedef struct endpoint_discovery_poller *endpoint_discovery_poller_pt;
-celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, endpoint_discovery_poller_pt *poller);
+celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_poller_pt *poller);
+celix_status_t endpointDiscoveryPoller_destroy(endpoint_discovery_poller_pt *poller);
+
celix_status_t endpointDiscoveryPoller_addDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url);
celix_status_t endpointDiscoveryPoller_removeDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url);
-
#endif /* ENDPOINT_DISCOVERY_POLLER_H_ */
Added: celix/trunk/remote_services/discovery_configured/private/include/endpoint_discovery_server.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery_configured/private/include/endpoint_discovery_server.h?rev=1617689&view=auto
==============================================================================
--- celix/trunk/remote_services/discovery_configured/private/include/endpoint_discovery_server.h (added)
+++ celix/trunk/remote_services/discovery_configured/private/include/endpoint_discovery_server.h Wed Aug 13 08:46:09 2014
@@ -0,0 +1,71 @@
+/**
+ * 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.
+ */
+/*
+ * endpoint_discovery_server.h
+ *
+ * \date Aug 12, 2014
+ * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
+ */
+
+#ifndef ENDPOINT_DISCOVERY_SERVER_H_
+#define ENDPOINT_DISCOVERY_SERVER_H_
+
+#include "celix_errno.h"
+#include "discovery.h"
+
+typedef struct endpoint_discovery_server *endpoint_discovery_server_pt;
+
+/**
+ * Creates and starts a new instance of an endpoint discovery server.
+ *
+ * @param discovery [in] the discovery service itself;
+ * @param context [in] the bundle context;
+ * @param server [out] the pointer to the created instance.
+ * @return CELIX_SUCCESS when successful.
+ */
+celix_status_t endpointDiscoveryServer_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_server_pt *server);
+
+/**
+ * Stops and destroys a given instance of an endpoint discovery server.
+ *
+ * @param server [out] the pointer to the instance to destroy.
+ * @return CELIX_SUCCESS when successful.
+ */
+celix_status_t endpointDiscoveryServer_destroy(endpoint_discovery_server_pt *server);
+
+/**
+ * Adds a given endpoint description to expose through the given discovery server.
+ *
+ * @param server [in] the endpoint discovery server to expose the endpoint through;
+ * @param endpoint [in] the endpoint description to expose.
+ * @return CELIX_SUCCESS when successful.
+ */
+celix_status_t endpointDiscoveryServer_addEndpoint(endpoint_discovery_server_pt server, endpoint_description_pt endpoint);
+
+/**
+ * Removes a given endpoint description from exposure through the given discovery server.
+ *
+ * @param server [in] the endpoint discovery server to remove the endpoint from;
+ * @param endpoint [in] the endpoint description to remove.
+ * @return CELIX_SUCCESS when successful.
+ */
+celix_status_t endpointDiscoveryServer_removeEndpoint( endpoint_discovery_server_pt server, endpoint_description_pt endpoint);
+
+#endif /* ENDPOINT_DISCOVERY_SERVER_H_ */
Modified: celix/trunk/remote_services/discovery_configured/private/src/discovery.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery_configured/private/src/discovery.c?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/remote_services/discovery_configured/private/src/discovery.c (original)
+++ celix/trunk/remote_services/discovery_configured/private/src/discovery.c Wed Aug 13 08:46:09 2014
@@ -1,40 +1,37 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* discovery.c
*
- * \date Sep 1, 2013
- * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \date Aug 8, 2014
+ * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
-#include <apr_thread_proc.h>
-#include <apr_strings.h>
#include <netdb.h>
#include <netinet/in.h>
-#include <dns_sd.h>
-
#include "constants.h"
+#include "celix_threads.h"
#include "bundle_context.h"
#include "array_list.h"
#include "utils.h"
@@ -46,356 +43,145 @@
#include "discovery.h"
#include "endpoint_discovery_poller.h"
+#include "endpoint_discovery_server.h"
-static const char * const OSGI_DISCOVERY_TYPE = "_osgid._udp";
-static const char * const OSGI_DISCOVERY_NAME = "Amdatu Remote Service Endpoint (Bonjour)";
-static void *APR_THREAD_FUNC discovery_pollDiscovery(apr_thread_t *thd, void *data);
-
-static celix_status_t discovery_start(discovery_pt discovery);
-static void discovery_browseDiscoveryCallback(DNSServiceRef sdRef, DNSServiceFlags flags,
- uint32_t interfaceIndex, DNSServiceErrorType errorCode,
- const char *serviceName, const char *regtype, const char *replyDomain,
- void *context);
-
-
-static void discovery_browseCallback(DNSServiceRef sdRef, DNSServiceFlags flags,
- uint32_t interfaceIndex, DNSServiceErrorType errorCode,
- const char *serviceName, const char *regtype, const char *replyDomain,
- void *context);
-static void discovery_resolveAddCallback(DNSServiceRef sdRef,
- DNSServiceFlags flags, uint32_t interfaceIndex,
- DNSServiceErrorType errorCode, const char *fullname,
- const char *hosttarget, uint16_t port, /* In network byte order */
- uint16_t txtLen, const unsigned char *txtRecord, void *context);
-static void discovery_resolveRemoveCallback(DNSServiceRef sdRef,
- DNSServiceFlags flags, uint32_t interfaceIndex,
- DNSServiceErrorType errorCode, const char *fullname,
- const char *hosttarget, uint16_t port, /* In network byte order */
- uint16_t txtLen, const unsigned char *txtRecord, void *context);
static celix_status_t discovery_informEndpointListeners(discovery_pt discovery, endpoint_description_pt endpoint, bool addingService);
-static const char * const DEFAULT_DISCOVERY_PORT = "8889";
-static const char * const OSGI_SERVICE_TYPE = "_osgi._udp";
-
-typedef struct discovered_endpoint_entry {
- apr_pool_t *pool;
- endpoint_description_pt endpointDescription;
-} * discovered_endpoint_entry_pt;
-
-typedef struct disclosed_endpoint_entry {
- apr_pool_t *pool;
- endpoint_description_pt endpointDescription;
- TXTRecordRef *txtRecord;
- DNSServiceRef dnsServiceRef;
-} * disclosed_endpoint_entry_pt;
-
-
struct discovery {
bundle_context_pt context;
- apr_pool_t *pool;
+ celix_thread_mutex_t listenerReferencesMutex;
+ celix_thread_mutex_t discoveredServicesMutex;
- apr_thread_mutex_t *listenerReferencesMutex;
- apr_thread_mutex_t *discoveredServicesMutex;
- apr_thread_mutex_t *disclosedServicesMutex;
-
- hash_map_pt listenerReferences; //key=serviceReference, value=?? TODO
- hash_map_pt discoveredServices; //key=endpointId (string), value=discovered_endpoint_entry_pt;
- hash_map_pt disclosedServices; //key=endpointId (string), value=disclosed_endpoint_entry_pt;
-
- volatile bool running;
- apr_thread_t *poll;
- apr_thread_t *pollDiscovery;
- DNSServiceRef browseRef;
- DNSServiceRef browseDiscoveryRef;
- DNSServiceRef discoveryRef;
+ hash_map_pt listenerReferences; //key=serviceReference, value=nop
+ hash_map_pt discoveredServices; //key=endpointId (string), value=endpoint_description_pt
- char *discoveryPort;
- char *frameworkUuid;
endpoint_discovery_poller_pt poller;
+ endpoint_discovery_server_pt server;
};
-celix_status_t discovery_create(apr_pool_t *pool, bundle_context_pt context, discovery_pt *discovery) {
+celix_status_t discovery_create(bundle_context_pt context, discovery_pt *discovery) {
celix_status_t status = CELIX_SUCCESS;
- *discovery = apr_palloc(pool, sizeof(**discovery));
+ *discovery = malloc(sizeof(struct discovery));
if (!*discovery) {
- status = CELIX_ENOMEM;
- } else {
- (*discovery)->context = context;
- (*discovery)->pool = pool;
- (*discovery)->listenerReferences = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
- (*discovery)->discoveredServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- (*discovery)->disclosedServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- (*discovery)->running = true;
- (*discovery)->browseRef = NULL;
- (*discovery)->discoveryPort = NULL;
- (*discovery)->listenerReferencesMutex = NULL;
- (*discovery)->discoveredServicesMutex = NULL;
- (*discovery)->disclosedServicesMutex = NULL;
- (*discovery)->frameworkUuid = NULL;
- (*discovery)->poller = NULL;
-
- bundleContext_getProperty(context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &(*discovery)->frameworkUuid);
-
- CELIX_DO_IF(status, status = apr_thread_mutex_create(&(*discovery)->listenerReferencesMutex, APR_THREAD_MUTEX_DEFAULT, pool));
- CELIX_DO_IF(status, status = apr_thread_mutex_create(&(*discovery)->discoveredServicesMutex, APR_THREAD_MUTEX_DEFAULT, pool));
- CELIX_DO_IF(status, status = apr_thread_mutex_create(&(*discovery)->disclosedServicesMutex, APR_THREAD_MUTEX_DEFAULT, pool));
-
- char *port = NULL;
- bundleContext_getProperty(context, "DISCOVERY_PORT", &port);
- if (port == NULL) {
- (*discovery)->discoveryPort = (char *) DEFAULT_DISCOVERY_PORT;
- } else {
- (*discovery)->discoveryPort = apr_pstrdup(pool, port);
- }
-
- discovery_start(*discovery);
+ return CELIX_ENOMEM;
}
- return status;
-}
-
-static celix_status_t discovery_start(discovery_pt discovery) {
- celix_status_t status = CELIX_SUCCESS;
+ (*discovery)->context = context;
+ (*discovery)->poller = NULL;
+ (*discovery)->server = NULL;
- CELIX_DO_IF(status, status = endpointDiscoveryPoller_create(discovery, &discovery->poller));
+ (*discovery)->listenerReferences = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
+ (*discovery)->discoveredServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- char *path = NULL;
- bundleContext_getProperty(discovery->context, "DISCOVERY_PATH", &path);
- if (path == NULL) {
- path = "path";
- }
+ status = celixThreadMutex_create(&(*discovery)->listenerReferencesMutex, NULL);
+ status = celixThreadMutex_create(&(*discovery)->discoveredServicesMutex, NULL);
- TXTRecordRef txtRecord;
-
- TXTRecordCreate(&txtRecord, 512, NULL);
- TXTRecordSetValue(&txtRecord, "path", strlen(path), path);
+ return status;
+}
- int port = atoi(discovery->discoveryPort);
- int portInNetworkByteOrder = ((port << 8) & 0xFF00) | ((port >> 8) & 0xFF); //FIXME assuming little endian
+celix_status_t discovery_start(discovery_pt discovery) {
+ celix_status_t status = CELIX_SUCCESS;
- DNSServiceErrorType error = DNSServiceRegister(&discovery->discoveryRef, 0, 0, OSGI_DISCOVERY_NAME, OSGI_DISCOVERY_TYPE, NULL, NULL, portInNetworkByteOrder,
- TXTRecordGetLength(&txtRecord), TXTRecordGetBytesPtr(&txtRecord), NULL, NULL);
- if (error != kDNSServiceErr_NoError) {
- status = CELIX_ILLEGAL_STATE;
- printf("============= 11 ERROR %d\n", error);
+ status = endpointDiscoveryPoller_create(discovery, discovery->context, &discovery->poller);
+ if (status != CELIX_SUCCESS) {
+ return CELIX_BUNDLE_EXCEPTION;
}
- error = DNSServiceBrowse(&discovery->browseDiscoveryRef, 0, 0, OSGI_DISCOVERY_TYPE, NULL, discovery_browseDiscoveryCallback, discovery);
- if (error != kDNSServiceErr_NoError) {
- status = CELIX_ILLEGAL_STATE;
- printf("============= 22 ERROR %d\n", error);
+ status = endpointDiscoveryServer_create(discovery, discovery->context, &discovery->server);
+ if (status != CELIX_SUCCESS) {
+ return CELIX_BUNDLE_EXCEPTION;
}
- status = CELIX_DO_IF(status, apr_thread_create(&discovery->pollDiscovery, NULL, discovery_pollDiscovery, discovery, discovery->pool));
return status;
}
-static void *APR_THREAD_FUNC discovery_pollDiscovery(apr_thread_t *thd, void *data) {
- discovery_pt discovery = data;
-
- while (discovery->running) {
- DNSServiceProcessResult(discovery->browseDiscoveryRef);
- }
- apr_thread_exit(thd, APR_SUCCESS);
+celix_status_t discovery_stop(discovery_pt discovery) {
+ celix_status_t status;
- return NULL;
-}
+ status = endpointDiscoveryServer_destroy(&discovery->server);
+ if (status != CELIX_SUCCESS) {
+ return CELIX_BUNDLE_EXCEPTION;
+ }
-static void discovery_browseDiscoveryCallback(DNSServiceRef sdRef, DNSServiceFlags flags,
- uint32_t interfaceIndex, DNSServiceErrorType errorCode,
- const char *serviceName, const char *regtype, const char *replyDomain,
- void *context) {
- discovery_pt discovery = context;
- if (flags & kDNSServiceFlagsAdd) {
- printf("Added discovery with %s %s %s\n", serviceName, regtype, replyDomain);
- DNSServiceRef resolveRef = NULL;
- DNSServiceErrorType resolveError = DNSServiceResolve(&resolveRef, 0, 0, serviceName, regtype, replyDomain, discovery_resolveAddCallback, context);
- printf("Resolve return with error %i\n", resolveError);
- if (resolveError == kDNSServiceErr_NoError) {
- DNSServiceProcessResult(resolveRef);
- } else {
- //TODO print error / handle error?
- }
- } else {
- printf("Removed discovery with %s %s %s\n", serviceName, regtype,
- replyDomain);
-// DNSServiceRef resolveRef = NULL;
-// DNSServiceErrorType resolveError = DNSServiceResolve(&resolveRef, 0, 0,
-// serviceName, regtype, replyDomain, discovery_resolveRemoveCallback,
-// context);
-// if (resolveError == kDNSServiceErr_NoError) {
-// DNSServiceProcessResult(resolveRef);
-// } else {
-// //TODO print error / handle error?
-// }
- }
-}
+ status = endpointDiscoveryPoller_destroy(&discovery->poller);
+ if (status != CELIX_SUCCESS) {
+ return CELIX_BUNDLE_EXCEPTION;
+ }
-static void discovery_resolveAddCallback(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *fullname,
- const char *hosttarget, uint16_t port, uint16_t txtLen, const unsigned char *txtRecord, void *context) {
- discovery_pt discovery = context;
+ hash_map_iterator_pt iter;
- printf("Added discovery with %s %s %s\n", fullname, hosttarget, txtRecord);
+ celixThreadMutex_lock(&discovery->discoveredServicesMutex);
- uint8_t valueLen;
- char *path = (char *) TXTRecordGetValuePtr(txtLen, txtRecord, "path", &valueLen);
- char *host = strdup(gethostbyname(hosttarget)->h_name);
- uint16_t hPort = ntohs(port);
+ iter = hashMapIterator_create(discovery->discoveredServices);
+ while (hashMapIterator_hasNext(iter)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+ endpoint_description_pt endpoint = hashMapEntry_getValue(entry);
- printf("Path: %s, Host: %s\n", path, host);
+ discovery_informEndpointListeners(discovery, endpoint, false);
+ }
+ hashMapIterator_destroy(iter);
- char url[1024];
- snprintf(url, sizeof(url), "%s:%d/%s", host, hPort, path);
+ celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
- printf("Discovery URL: %s\n", url);
+ return status;
}
-celix_status_t discovery_stop(discovery_pt discovery) {
- celix_status_t status;
+celix_status_t discovery_destroy(discovery_pt *discovery) {
+ celix_status_t status = CELIX_SUCCESS;
+ hash_map_iterator_pt iter;
- apr_status_t tstat;
- discovery->running = false;
- DNSServiceRefDeallocate(discovery->browseRef);
- apr_status_t stat = apr_thread_join(&tstat, discovery->poll);
- if (stat != APR_SUCCESS && tstat != APR_SUCCESS) {
- status = CELIX_BUNDLE_EXCEPTION;
- }
+ (*discovery)->context = NULL;
+ (*discovery)->poller = NULL;
+ (*discovery)->server = NULL;
- apr_thread_mutex_lock(discovery->disclosedServicesMutex);
- hash_map_iterator_pt iter = hashMapIterator_create(discovery->disclosedServices);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- disclosed_endpoint_entry_pt endpointEntry = hashMapEntry_getValue(entry);
- DNSServiceRefDeallocate(endpointEntry->dnsServiceRef);
- }
- hashMapIterator_destroy(iter);
+ celixThreadMutex_lock(&(*discovery)->discoveredServicesMutex);
- iter = hashMapIterator_create(discovery->discoveredServices);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- discovered_endpoint_entry_pt endpointEntry = hashMapEntry_getValue(entry);
- discovery_informEndpointListeners(discovery, endpointEntry->endpointDescription, false);
- }
- hashMapIterator_destroy(iter);
+ hashMap_destroy((*discovery)->discoveredServices, false, false);
+ (*discovery)->discoveredServices = NULL;
- hashMap_destroy(discovery->disclosedServices, false, false);
+ celixThreadMutex_unlock(&(*discovery)->discoveredServicesMutex);
- discovery->disclosedServices = NULL;
- apr_thread_mutex_unlock(discovery->disclosedServicesMutex);
+ celixThreadMutex_destroy(&(*discovery)->discoveredServicesMutex);
- apr_thread_mutex_lock(discovery->discoveredServicesMutex);
- hashMap_destroy(discovery->discoveredServices, false, false);
- discovery->discoveredServices = NULL;
- apr_thread_mutex_unlock(discovery->discoveredServicesMutex);
+ celixThreadMutex_lock(&(*discovery)->listenerReferencesMutex);
- apr_thread_mutex_lock(discovery->listenerReferencesMutex);
- hashMap_destroy(discovery->listenerReferences, false, false);
- discovery->listenerReferences = NULL;
- apr_thread_mutex_unlock(discovery->listenerReferencesMutex);
+ hashMap_destroy((*discovery)->listenerReferences, false, false);
+ (*discovery)->listenerReferences = NULL;
+
+ celixThreadMutex_unlock(&(*discovery)->listenerReferencesMutex);
+
+ celixThreadMutex_destroy(&(*discovery)->listenerReferencesMutex);
+
+ free(*discovery);
return status;
}
-celix_status_t discovery_endpointAdded(void *handle, endpoint_description_pt endpoint, char *machtedFilter) {
+celix_status_t discovery_endpointAdded(void *handle, endpoint_description_pt endpoint, char *matchedFilter) {
celix_status_t status = CELIX_SUCCESS;
discovery_pt discovery = handle;
- printf("DISCOVERY: Endpoint for %s, with filter \"%s\" added\n", endpoint->service, machtedFilter);
- disclosed_endpoint_entry_pt entry = NULL;
- apr_pool_t *childPool = NULL;
- status = apr_pool_create(&childPool, discovery->pool);
-
- if (status == CELIX_SUCCESS) {
- entry = apr_palloc(childPool, sizeof(*entry));
- if (entry == NULL) {
- status = CELIX_ENOMEM;
- apr_pool_destroy(childPool);
- } else {
- entry->pool = childPool;
- entry->endpointDescription = endpoint;
- }
- }
-
- if (status == CELIX_SUCCESS) {
- DNSServiceRef sdRef = NULL;
- DNSServiceErrorType error;
- TXTRecordRef txtRecord;
-
- TXTRecordCreate(&txtRecord, 256, NULL ); //TODO search for correct default record size
- char serviceId[16];
- sprintf(serviceId, "%li", endpoint->serviceId);
-
- TXTRecordSetValue(&txtRecord, "service", strlen(endpoint->service),
- endpoint->service);
- TXTRecordSetValue(&txtRecord, "service.id", strlen(serviceId),
- serviceId);
- TXTRecordSetValue(&txtRecord, "endpoint.id", strlen(endpoint->id),
- endpoint->id);
- TXTRecordSetValue(&txtRecord, "framework.uuid", strlen(discovery->frameworkUuid), discovery->frameworkUuid);
-
- hash_map_iterator_pt iter = hashMapIterator_create(
- endpoint->properties);
- while (hashMapIterator_hasNext(iter)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
- char *key = hashMapEntry_getKey(entry);
- char *value = hashMapEntry_getValue(entry);
- TXTRecordSetValue(&txtRecord, key, strlen(value), value);
- }
- hashMapIterator_destroy(iter);
-
- int port = atoi(discovery->discoveryPort);
- int portInNetworkByteOrder = ((port << 8) & 0xFF00)
- | ((port >> 8) & 0xFF); //FIXME assuming little endian
-
- error = DNSServiceRegister(&sdRef, 0, 0, endpoint->service,
- OSGI_SERVICE_TYPE, NULL,
- NULL, portInNetworkByteOrder, /* In network byte order */
- TXTRecordGetLength(&txtRecord), TXTRecordGetBytesPtr(&txtRecord),
- NULL, NULL );
-
- if (error != kDNSServiceErr_NoError) {
- status = CELIX_ILLEGAL_STATE;
-// printf("Registered record in dns-sd got error code %i\n", error);
- } else {
- //entry->txtRecord=txtRecord; TODO
- entry->dnsServiceRef = sdRef;
- apr_thread_mutex_lock(discovery->disclosedServicesMutex);
- if (discovery->disclosedServices != NULL) {
- hashMap_put(discovery->disclosedServices, endpoint->id, entry);
- }
- apr_thread_mutex_unlock(discovery->disclosedServicesMutex);
- }
- }
-
+ printf("DISCOVERY_CONFIGURED: Endpoint for %s, with filter \"%s\" added...\n", endpoint->service, matchedFilter);
+ status = endpointDiscoveryServer_addEndpoint(discovery->server, endpoint);
return status;
}
-celix_status_t discovery_endpointRemoved(void *handle, endpoint_description_pt endpoint, char *machtedFilter) {
+celix_status_t discovery_endpointRemoved(void *handle, endpoint_description_pt endpoint, char *matchedFilter) {
celix_status_t status = CELIX_SUCCESS;
discovery_pt discovery = handle;
- disclosed_endpoint_entry_pt entry = NULL;
- apr_thread_mutex_lock(discovery->disclosedServicesMutex);
- if (discovery->disclosedServices != NULL) {
- entry = hashMap_remove(discovery->disclosedServices, endpoint->id);
- }
- if (entry != NULL) {
- DNSServiceRefDeallocate(entry->dnsServiceRef);
- apr_pool_destroy(entry->pool);
- } else {
- status = CELIX_ILLEGAL_STATE;
- }
- apr_thread_mutex_unlock(discovery->disclosedServicesMutex);
+ printf("DISCOVERY_CONFIGURED: Endpoint for %s, with filter \"%s\" removed...\n", endpoint->service, matchedFilter);
+ status = endpointDiscoveryServer_removeEndpoint(discovery->server, endpoint);
return status;
}
-celix_status_t discovery_endpointListenerAdding(void * handle, service_reference_pt reference, void **service) {
+celix_status_t discovery_endpointListenerAdding(void* handle, service_reference_pt reference, void** service) {
celix_status_t status = CELIX_SUCCESS;
discovery_pt discovery = handle;
@@ -404,48 +190,52 @@ celix_status_t discovery_endpointListene
return status;
}
-celix_status_t discovery_endpointListenerAdded(void * handle, service_reference_pt reference, void * service) {
+celix_status_t discovery_endpointListenerAdded(void* handle, service_reference_pt reference, void* service) {
celix_status_t status = CELIX_SUCCESS;
discovery_pt discovery = handle;
service_registration_pt registration = NULL;
serviceReference_getServiceRegistration(reference, ®istration);
+
properties_pt serviceProperties = NULL;
serviceRegistration_getProperties(registration, &serviceProperties);
+
char *discoveryListener = properties_get(serviceProperties, "DISCOVERY");
+ char *scope = properties_get(serviceProperties, (char *) OSGI_ENDPOINT_LISTENER_SCOPE);
+ filter_pt filter = filter_create(scope);
if (discoveryListener != NULL && strcmp(discoveryListener, "true") == 0) {
printf("DISCOVERY: EndpointListener Ignored - Discovery listener\n");
} else {
- printf("DISCOVERY: EndpointListener Added - Add Scope\n");
+ celixThreadMutex_lock(&discovery->discoveredServicesMutex);
- apr_thread_mutex_lock(discovery->discoveredServicesMutex);
- if (discovery->discoveredServices != NULL) {
- hash_map_iterator_pt iter = hashMapIterator_create(discovery->discoveredServices);
- while (hashMapIterator_hasNext(iter)) {
- endpoint_description_pt endpoint = hashMapIterator_nextKey(iter);
+ hash_map_iterator_pt iter = hashMapIterator_create(discovery->discoveredServices);
+ while (hashMapIterator_hasNext(iter)) {
+ endpoint_description_pt endpoint = hashMapIterator_nextKey(iter);
+
+ bool matchResult = false;
+ filter_match(filter, endpoint->properties, &matchResult);
+ if (matchResult) {
endpoint_listener_pt listener = service;
- char *scope = properties_get(serviceProperties,
- (char *) OSGI_ENDPOINT_LISTENER_SCOPE);
- filter_pt filter = filter_create(scope); //FIXME memory leak
- bool matchResult = false;
- filter_match(filter, endpoint->properties, &matchResult);
- if (matchResult) {
- listener->endpointAdded(listener, endpoint, NULL);
- }
+ printf("DISCOVERY: EndpointListener Added - Add Scope\n");
+
+ listener->endpointAdded(listener, endpoint, NULL);
}
- hashMapIterator_destroy(iter);
}
- apr_thread_mutex_unlock(discovery->discoveredServicesMutex);
+ hashMapIterator_destroy(iter);
- apr_thread_mutex_lock(discovery->listenerReferencesMutex);
- if (discovery->listenerReferences != NULL) {
- hashMap_put(discovery->listenerReferences, reference, NULL /*TODO is the scope value needed?*/);
- }
- apr_thread_mutex_unlock(discovery->listenerReferencesMutex);
+ celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
+
+ celixThreadMutex_lock(&discovery->listenerReferencesMutex);
+
+ hashMap_put(discovery->listenerReferences, reference, NULL);
+
+ celixThreadMutex_unlock(&discovery->listenerReferencesMutex);
}
+ filter_destroy(filter);
+
return status;
}
@@ -453,64 +243,109 @@ celix_status_t discovery_endpointListene
celix_status_t status = CELIX_SUCCESS;
discovery_pt discovery = handle;
-// printf("DISCOVERY: EndpointListener Modified - Update Scope TODO\n");
+ status = discovery_endpointListenerRemoved(handle, reference, service);
+ status = discovery_endpointListenerAdded(handle, reference, service);
return status;
}
-
-
celix_status_t discovery_endpointListenerRemoved(void * handle, service_reference_pt reference, void * service) {
celix_status_t status = CELIX_SUCCESS;
discovery_pt discovery = handle;
- printf("DISCOVERY: EndpointListener Removed\n");
- apr_thread_mutex_lock(discovery->listenerReferencesMutex);
+ status = celixThreadMutex_lock(&discovery->listenerReferencesMutex);
+
if (discovery->listenerReferences != NULL) {
- hashMap_remove(discovery->listenerReferences, reference);
+ if (hashMap_remove(discovery->listenerReferences, reference)) {
+ printf("DISCOVERY: EndpointListener Removed\n");
+ }
}
- apr_thread_mutex_unlock(discovery->listenerReferencesMutex);
+
+ status = celixThreadMutex_unlock(&discovery->listenerReferencesMutex);
return status;
}
-
static celix_status_t discovery_informEndpointListeners(discovery_pt discovery, endpoint_description_pt endpoint, bool endpointAdded) {
celix_status_t status = CELIX_SUCCESS;
// Inform listeners of new endpoint
- apr_thread_mutex_lock(discovery->listenerReferencesMutex);
+ status = celixThreadMutex_lock(&discovery->listenerReferencesMutex);
+
if (discovery->listenerReferences != NULL) {
hash_map_iterator_pt iter = hashMapIterator_create(discovery->listenerReferences);
while (hashMapIterator_hasNext(iter)) {
hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+
service_reference_pt reference = hashMapEntry_getKey(entry);
endpoint_listener_pt listener = NULL;
service_registration_pt registration = NULL;
serviceReference_getServiceRegistration(reference, ®istration);
+
properties_pt serviceProperties = NULL;
serviceRegistration_getProperties(registration, &serviceProperties);
- char *scope = properties_get(serviceProperties,
- (char *) OSGI_ENDPOINT_LISTENER_SCOPE);
+ char *scope = properties_get(serviceProperties, (char *) OSGI_ENDPOINT_LISTENER_SCOPE);
+
filter_pt filter = filter_create(scope);
bool matchResult = false;
- filter_match(filter, endpoint->properties, &matchResult);
+
+ status = filter_match(filter, endpoint->properties, &matchResult);
if (matchResult) {
- printf("DISCOVERY: Add service (%s)\n", endpoint->service);
- bundleContext_getService(discovery->context, reference,
- (void**) &listener);
+ bundleContext_getService(discovery->context, reference, (void**) &listener);
if (endpointAdded) {
- listener->endpointAdded(listener->handle, endpoint, NULL );
+ printf("DISCOVERY_CONFIGURED: Adding service (%s)\n", endpoint->service);
+
+ listener->endpointAdded(listener->handle, endpoint, scope);
} else {
- listener->endpointRemoved(listener->handle, endpoint, NULL );
- }
+ printf("DISCOVERY_CONFIGURED: Removing service (%s)\n", endpoint->service);
+ listener->endpointRemoved(listener->handle, endpoint, scope);
+ }
}
}
hashMapIterator_destroy(iter);
}
- apr_thread_mutex_unlock(discovery->listenerReferencesMutex);
+
+ status = celixThreadMutex_unlock(&discovery->listenerReferencesMutex);
+
+ return status;
+}
+
+celix_status_t discovery_addDiscoveredEndpoint(discovery_pt discovery, endpoint_description_pt endpoint) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ status = celixThreadMutex_lock(&discovery->discoveredServicesMutex);
+
+ char* endpointId = endpoint->id;
+ bool exists = hashMap_get(discovery->discoveredServices, endpointId) != NULL;
+ if (!exists) {
+ hashMap_put(discovery->discoveredServices, endpointId, endpoint);
+ }
+
+ status = celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
+
+ if (!exists) {
+ // notify our listeners that a new endpoint is available...
+ discovery_informEndpointListeners(discovery, endpoint, true /* addingService */);
+ }
+
+ return status;
+}
+
+celix_status_t discovery_removeDiscoveredEndpoint(discovery_pt discovery, endpoint_description_pt endpoint) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ status = celixThreadMutex_lock(&discovery->discoveredServicesMutex);
+
+ char* endpointId = endpoint->id;
+ void* oldValue = hashMap_remove(discovery->discoveredServices, endpointId);
+
+ status = celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
+
+ if (oldValue) {
+ status = discovery_informEndpointListeners(discovery, endpoint, false /* addingService */);
+ }
return status;
}
Modified: celix/trunk/remote_services/discovery_configured/private/src/discovery_activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery_configured/private/src/discovery_activator.c?rev=1617689&r1=1617688&r2=1617689&view=diff
==============================================================================
--- celix/trunk/remote_services/discovery_configured/private/src/discovery_activator.c (original)
+++ celix/trunk/remote_services/discovery_configured/private/src/discovery_activator.c Wed Aug 13 08:46:09 2014
@@ -1,35 +1,32 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
- * dependency_activator.c
+ * discovery_activator.c
*
- * \date Sep 29, 2011
- * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \date Aug 8, 2014
+ * \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
#include <stdio.h>
#include <stdlib.h>
-#include <apr_strings.h>
-#include <apr_uuid.h>
-
#include "bundle_activator.h"
#include "service_tracker.h"
#include "service_registration.h"
@@ -40,64 +37,49 @@
#include "remote_constants.h"
struct activator {
- apr_pool_t *pool;
bundle_context_pt context;
-
discovery_pt discovery;
service_tracker_pt endpointListenerTracker;
service_registration_pt endpointListenerService;
};
-celix_status_t discoveryActivator_createEPLTracker(struct activator *activator,
- service_tracker_pt *tracker);
-
-celix_status_t bundleActivator_create(bundle_context_pt context,
- void **userData) {
+celix_status_t bundleActivator_createEPLTracker(struct activator *activator, service_tracker_pt *tracker) {
celix_status_t status = CELIX_SUCCESS;
- apr_pool_t *parentPool = NULL;
- apr_pool_t *pool = NULL;
- struct activator *activator = NULL;
-
- bundleContext_getMemoryPool(context, &parentPool);
- apr_pool_create(&pool, parentPool);
- activator = apr_palloc(pool, sizeof(*activator));
- if (!activator) {
- status = CELIX_ENOMEM;
- } else {
- activator->pool = pool;
- activator->context = context;
- activator->endpointListenerTracker = NULL;
- activator->endpointListenerService = NULL;
- discovery_create(pool, context, &activator->discovery);
+ service_tracker_customizer_pt customizer = NULL;
- discoveryActivator_createEPLTracker(activator,
- &activator->endpointListenerTracker);
+ status = serviceTrackerCustomizer_create(activator->discovery,
+ discovery_endpointListenerAdding, discovery_endpointListenerAdded, discovery_endpointListenerModified, discovery_endpointListenerRemoved,
+ &customizer);
- *userData = activator;
+ if (status == CELIX_SUCCESS) {
+ status = serviceTracker_create(activator->context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, customizer, tracker);
}
return status;
}
-celix_status_t discoveryActivator_createEPLTracker(struct activator *activator,
- service_tracker_pt *tracker) {
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
celix_status_t status = CELIX_SUCCESS;
- service_tracker_customizer_pt customizer = NULL;
+ struct activator* activator = malloc(sizeof(struct activator));
+ if (!activator) {
+ return CELIX_ENOMEM;
+ }
- status = serviceTrackerCustomizer_create(
- activator->discovery, discovery_endpointListenerAdding,
- discovery_endpointListenerAdded, discovery_endpointListenerModified,
- discovery_endpointListenerRemoved, &customizer);
+ status = discovery_create(context, &activator->discovery);
+ if (status != CELIX_SUCCESS) {
+ return status;
+ }
- if (status == CELIX_SUCCESS) {
- status = serviceTracker_create(activator->context,
- (char *) OSGI_ENDPOINT_LISTENER_SERVICE, customizer, tracker);
+ activator->context = context;
+ activator->endpointListenerTracker = NULL;
+ activator->endpointListenerService = NULL;
- serviceTracker_open(activator->endpointListenerTracker);
- }
+ status = bundleActivator_createEPLTracker(activator, &activator->endpointListenerTracker);
+
+ *userData = activator;
return status;
}
@@ -105,25 +87,47 @@ celix_status_t discoveryActivator_create
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
celix_status_t status = CELIX_SUCCESS;
struct activator *activator = userData;
- apr_pool_t *pool = NULL;
- apr_pool_create(&pool, activator->pool);
- endpoint_listener_pt endpointListener = apr_palloc(pool,
- sizeof(*endpointListener));
+ char *uuid = NULL;
+ status = bundleContext_getProperty(context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
+ if (!uuid) {
+ printf("DISCOVERY_CONFIGURED: no framework UUID defined?!\n");
+ return CELIX_ILLEGAL_STATE;
+ }
+
+ size_t len = 11 + strlen(OSGI_FRAMEWORK_OBJECTCLASS) + strlen(OSGI_RSA_ENDPOINT_FRAMEWORK_UUID) + strlen(uuid);
+ char *scope = malloc(len);
+ if (!scope) {
+ return CELIX_ENOMEM;
+ }
+
+ sprintf(scope, "(&(%s=*)(%s=%s))", OSGI_FRAMEWORK_OBJECTCLASS, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
+ scope[len] = 0;
+
+ printf("DISCOVERY_CONFIGURED: using scope %s.\n", scope);
+
+ endpoint_listener_pt endpointListener = malloc(sizeof(struct endpoint_listener));
+ if (!endpointListener) {
+ return CELIX_ENOMEM;
+ }
+
endpointListener->handle = activator->discovery;
endpointListener->endpointAdded = discovery_endpointAdded;
endpointListener->endpointRemoved = discovery_endpointRemoved;
properties_pt props = properties_create();
properties_set(props, "DISCOVERY", "true");
- char *uuid = NULL;
- bundleContext_getProperty(context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
- char *scope = apr_pstrcat(activator->pool, "(&(", OSGI_FRAMEWORK_OBJECTCLASS, "=*)(", OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, "=", uuid, "))", NULL);
- printf("DISCOVERY SCOPE IS: %s\n", scope);
properties_set(props, (char *) OSGI_ENDPOINT_LISTENER_SCOPE, scope);
- status = bundleContext_registerService(context,
- (char *) OSGI_ENDPOINT_LISTENER_SERVICE, endpointListener, props,
- &activator->endpointListenerService);
+
+ status = bundleContext_registerService(context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, endpointListener, props, &activator->endpointListenerService);
+
+ if (status == CELIX_SUCCESS) {
+ status = serviceTracker_open(activator->endpointListenerTracker);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ status = discovery_start(activator->discovery);
+ }
return status;
}
@@ -132,15 +136,29 @@ celix_status_t bundleActivator_stop(void
celix_status_t status = CELIX_SUCCESS;
struct activator *activator = userData;
- serviceTracker_close(activator->endpointListenerTracker);
- serviceRegistration_unregister(activator->endpointListenerService);
- discovery_stop(activator->discovery);
+ status = serviceTracker_close(activator->endpointListenerTracker);
+
+ status = serviceRegistration_unregister(activator->endpointListenerService);
+
+ status = discovery_stop(activator->discovery);
return status;
}
-celix_status_t bundleActivator_destroy(void * userData,
- bundle_context_pt context) {
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
celix_status_t status = CELIX_SUCCESS;
+ struct activator *activator = userData;
+
+ status = serviceTracker_destroy(activator->endpointListenerTracker);
+
+ status = serviceRegistration_destroy(activator->endpointListenerService);
+
+ status = discovery_destroy(activator->discovery);
+
+ activator->endpointListenerTracker = NULL;
+ activator->endpointListenerService = NULL;
+ activator->discovery = NULL;
+ activator->context = NULL;
+
return status;
}