diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index fbf6ac77c..7235f55e8 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -150,7 +150,6 @@ jobs: -DRSA_JSON_RPC=ON -DRSA_SHM=ON -DRSA_REMOTE_SERVICE_ADMIN_SHM_V2=ON - -DSHELL_BONJOUR=ON -DENABLE_TESTING_ON_CI=ON -DCMAKE_BUILD_TYPE=${{ matrix.type }} -DENABLE_CCACHE=ON diff --git a/CHANGES.md b/CHANGES.md index 5db41a36f..b1dc8756b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -27,6 +27,10 @@ limitations under the License. - The libs `dependency_manager_static`, `shell_dm` and `dependency_manager_cxx_static` are removed. These libraries are not needed anymore. The dependency manager is an integral part of the framework lib and the `dm` command is part of the standard shell commands. +- Shell v2 api is removed and no longer supported. +- Logging v2 api is removed and no longer supported. +- Bonjour Shell bundle is removed and no longer supported. +- pubsub_serializer.h is removed and no longer supported. Use pubsub_message_serialization_service.h instead. # Noteworthy Changes for 2.4.0 (2023-09-27) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8773e203a..8ddc5d62b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,7 +157,6 @@ if (ENABLE_TESTING) enable_testing() endif() -option(CELIX_INSTALL_DEPRECATED_API "whether to install (and use) deprecated apis (i.e. header without a celix_ prefix." ON) option(CELIX_USE_ZIP_INSTEAD_OF_JAR "Default Celix cmake command will use jar to package bundle (if found). This option enforces Celix to use zip instead." OFF) option(CELIX_CXX14 "Build C++14 libraries and bundles. Note for tests C++ is always used." ON) @@ -170,9 +169,9 @@ option(ENABLE_TESTING_DEPENDENCY_MANAGER_FOR_CXX11 "Test the Dependency Manager option(ENABLE_TESTING_FOR_CXX14 "Test celix utils and framework C++ header for C++14 support" OFF) option(ENABLE_CMAKE_WARNING_TESTS "Enable cmake warning tests to test warning prints" OFF) option(ENABLE_TESTING_ON_CI "Whether to enable testing on CI. This influence allowed timing errors during unit tests" OFF) +option(ENABLE_DEPRECATED_WARNINGS "Enable compiler warnings for usage of deprecated functionality" OFF) -if (CELIX_INSTALL_DEPRECATED_API) - #ignore deprecated warnings +if (NOT ENABLE_DEPRECATED_WARNINGS) set(CMAKE_C_FLAGS "-Wno-deprecated-declarations ${CMAKE_C_FLAGS}") set(CMAKE_CXX_FLAGS "-Wno-deprecated-declarations ${CMAKE_CXX_FLAGS}") endif () diff --git a/bundles/logging/CMakeLists.txt b/bundles/logging/CMakeLists.txt index 1d3604bb0..abe71980f 100644 --- a/bundles/logging/CMakeLists.txt +++ b/bundles/logging/CMakeLists.txt @@ -21,12 +21,6 @@ add_subdirectory(log_helper) celix_subproject(LOG_SERVICE "Option to enable building the Log Service bundles" ON) if (LOG_SERVICE) - #Version 2 API (deprecated) - if (CELIX_INSTALL_DEPRECATED_API) - add_subdirectory(log_service_v2) - endif () - - #Version 3 API add_subdirectory(log_admin) add_subdirectory(log_writers) endif () diff --git a/bundles/logging/log_helper/CMakeLists.txt b/bundles/logging/log_helper/CMakeLists.txt index 2fa17133d..50fd467a5 100644 --- a/bundles/logging/log_helper/CMakeLists.txt +++ b/bundles/logging/log_helper/CMakeLists.txt @@ -17,26 +17,13 @@ celix_subproject(LOG_HELPER "Option to enable building the log helper library" ON) if (LOG_HELPER) - if (CELIX_INSTALL_DEPRECATED_API) - set(SOURCES src/celix_log_helper.c src/log_helper.c) - else () - set(SOURCES src/celix_log_helper.c) - endif () - - add_library(log_helper STATIC ${SOURCES}) + add_library(log_helper STATIC src/celix_log_helper.c) set_target_properties(log_helper PROPERTIES OUTPUT_NAME "celix_log_utils") target_include_directories(log_helper PUBLIC $ ) target_link_libraries(log_helper PUBLIC Celix::log_service_api Celix::framework PRIVATE Celix::utils) - if (CELIX_INSTALL_DEPRECATED_API) - target_include_directories(log_helper PUBLIC - $ - ) - install(DIRECTORY include_v1/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/log_helper) - endif () - install(TARGETS log_helper EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT logging INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/log_helper) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/log_helper COMPONENT logging) diff --git a/bundles/logging/log_helper/include_v1/log_helper.h b/bundles/logging/log_helper/include_v1/log_helper.h deleted file mode 100644 index 828d37dd8..000000000 --- a/bundles/logging/log_helper/include_v1/log_helper.h +++ /dev/null @@ -1,42 +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. - */ - -#ifndef LOGHELPER_H_ -#define LOGHELPER_H_ - -#include "bundle_context.h" -#include "log_service.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct log_helper log_helper_t; - -celix_status_t logHelper_create(celix_bundle_context_t *context, log_helper_t **log_helper); -celix_status_t logHelper_start(log_helper_t *loghelper); -celix_status_t logHelper_stop(log_helper_t *loghelper); -celix_status_t logHelper_destroy(log_helper_t **loghelper); -celix_status_t logHelper_log(log_helper_t *loghelper, log_level_t level, const char* message, ... ); - -#ifdef __cplusplus -} -#endif - -#endif /* LOGHELPER_H_ */ diff --git a/bundles/logging/log_helper/src/log_helper.c b/bundles/logging/log_helper/src/log_helper.c deleted file mode 100644 index 677564e43..000000000 --- a/bundles/logging/log_helper/src/log_helper.c +++ /dev/null @@ -1,262 +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. - */ -/** - * log_helper.c - * - * \date Nov 10, 2014 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include -#include - -#include "bundle_context.h" -#include "service_tracker.h" -#include "celix_threads.h" -#include "array_list.h" - -#include "celix_errno.h" -#include "log_service.h" - -#include "log_helper.h" - -#define LOGHELPER_ENABLE_STDOUT_FALLBACK_NAME "LOGHELPER_ENABLE_STDOUT_FALLBACK" -#define LOGHELPER_ENABLE_STDOUT_FALLBACK_DEFAULT true - -#define LOGHELPER_STDOUT_FALLBACK_INCLUDE_DEBUG_NAME "LOGHELPER_STDOUT_FALLBACK_INCLUDE_DEBUG" -#define LOGHELPER_STDOUT_FALLBACK_INCLUDE_DEBUG_DEFAULT false - - -#ifdef __linux__ -//includes for the backtrace function -#include -#include -#include -#endif - -#ifdef __linux__ -static char* logHelper_backtrace(void) { - void *bbuf[64]; - int nrOfTraces = backtrace(bbuf, 64); - char **lines = backtrace_symbols(bbuf, nrOfTraces); - - char *result = NULL; - size_t size = 0; - FILE *os = open_memstream(&result, &size); - fprintf(os, "Backtrace:\n"); - for (int i = 0; i < nrOfTraces; ++i) { - char *line = lines[i]; - fprintf(os, "%s\n", line); - } - free(lines); - fclose(os); - return result; -} -#else -static char* logHelper_backtrace(void) { - return NULL; -} -#endif - -struct log_helper { - celix_bundle_context_t *bundleContext; - celix_service_tracker_t *logServiceTracker; - celix_thread_mutex_t logListLock; - array_list_pt logServices; - bool stdOutFallback; - bool stdOutFallbackIncludeDebug; -}; - -celix_status_t logHelper_logServiceAdded(void *handle, service_reference_pt reference, void *service); -celix_status_t logHelper_logServiceRemoved(void *handle, service_reference_pt reference, void *service); - - -celix_status_t logHelper_create(bundle_context_pt context, log_helper_t **loghelper) -{ - celix_status_t status = CELIX_SUCCESS; - - (*loghelper) = calloc(1, sizeof(**loghelper)); - - if (!(*loghelper)) - { - status = CELIX_ENOMEM; - } - else - { - (*loghelper)->bundleContext = context; - (*loghelper)->logServiceTracker = NULL; - (*loghelper)->stdOutFallback = false; - - (*loghelper)->stdOutFallback = celix_bundleContext_getPropertyAsBool(context, LOGHELPER_ENABLE_STDOUT_FALLBACK_NAME, LOGHELPER_ENABLE_STDOUT_FALLBACK_DEFAULT); - (*loghelper)->stdOutFallbackIncludeDebug = celix_bundleContext_getPropertyAsBool(context, LOGHELPER_STDOUT_FALLBACK_INCLUDE_DEBUG_NAME, LOGHELPER_STDOUT_FALLBACK_INCLUDE_DEBUG_DEFAULT); - - pthread_mutex_init(&(*loghelper)->logListLock, NULL); - arrayList_create(&(*loghelper)->logServices); - } - - return status; -} - -celix_status_t logHelper_start(log_helper_t *loghelper) -{ - celix_status_t status; - service_tracker_customizer_pt logTrackerCustomizer = NULL; - - status = serviceTrackerCustomizer_create(loghelper, NULL, logHelper_logServiceAdded, NULL, logHelper_logServiceRemoved, &logTrackerCustomizer); - - if (status == CELIX_SUCCESS) { - loghelper->logServiceTracker = NULL; - status = serviceTracker_create(loghelper->bundleContext, (char*) OSGI_LOGSERVICE_NAME, logTrackerCustomizer, &loghelper->logServiceTracker); - } - - if (status == CELIX_SUCCESS) { - status = serviceTracker_open(loghelper->logServiceTracker); - } - - return status; -} - - - -celix_status_t logHelper_logServiceAdded(void *handle, service_reference_pt reference, void *service) -{ - log_helper_t *loghelper = handle; - - pthread_mutex_lock(&loghelper->logListLock); - arrayList_add(loghelper->logServices, service); - pthread_mutex_unlock(&loghelper->logListLock); - - return CELIX_SUCCESS; -} - -celix_status_t logHelper_logServiceRemoved(void *handle, service_reference_pt reference, void *service) -{ - log_helper_t *loghelper = handle; - - pthread_mutex_lock(&loghelper->logListLock); - arrayList_removeElement(loghelper->logServices, service); - pthread_mutex_unlock(&loghelper->logListLock); - - return CELIX_SUCCESS; -} - - -celix_status_t logHelper_stop(log_helper_t *loghelper) { - celix_status_t status; - - status = serviceTracker_close(loghelper->logServiceTracker); - - return status; -} - -celix_status_t logHelper_destroy(log_helper_t **loghelper) { - celix_status_t status = CELIX_SUCCESS; - - if((*loghelper)->logServiceTracker){ - serviceTracker_destroy((*loghelper)->logServiceTracker); - } - - pthread_mutex_lock(&(*loghelper)->logListLock); - arrayList_destroy((*loghelper)->logServices); - pthread_mutex_unlock(&(*loghelper)->logListLock); - - pthread_mutex_destroy(&(*loghelper)->logListLock); - - free(*loghelper); - *loghelper = NULL; - return status; -} - - - - -celix_status_t logHelper_log(log_helper_t *loghelper, log_level_t level, const char* message, ... ) -{ - celix_status_t status = CELIX_SUCCESS; - va_list listPointer; - char msg[1024]; - msg[0] = '\0'; - bool logged = false; - - if(loghelper == NULL){ - return CELIX_ILLEGAL_ARGUMENT; - } - - va_start(listPointer, message); - vsnprintf(msg, 1024, message, listPointer); - - pthread_mutex_lock(&loghelper->logListLock); - - int i = 0; - for (; i < arrayList_size(loghelper->logServices); i++) { - log_service_t *logService = arrayList_get(loghelper->logServices, i); - if (logService != NULL) { - (logService->log)(logService->logger, level, msg); //TODO add backtrace to msg if the level is ERROR - if (level == OSGI_LOGSERVICE_ERROR) { - char *backtrace = logHelper_backtrace(); - logService->log(logService->logger, level, backtrace); - free(backtrace); - } - logged = true; - } - } - - pthread_mutex_unlock(&loghelper->logListLock); - - if (!logged && loghelper->stdOutFallback) { - char *levelStr = NULL; - bool print = true; - - switch (level) { - case OSGI_LOGSERVICE_ERROR: - levelStr = "ERROR"; - break; - case OSGI_LOGSERVICE_WARNING: - levelStr = "WARNING"; - break; - case OSGI_LOGSERVICE_INFO: - levelStr = "INFO"; - break; - case OSGI_LOGSERVICE_DEBUG: - default: - levelStr = "DEBUG"; - print = loghelper->stdOutFallbackIncludeDebug; - break; - } - - if (print) { - if (level == OSGI_LOGSERVICE_ERROR) { - fprintf(stderr, "%s: %s\n", levelStr, msg); - if (level == OSGI_LOGSERVICE_ERROR) { - char *backtrace = logHelper_backtrace(); - fprintf(stderr, "%s", backtrace); - free(backtrace); - } - } else { - printf("%s: %s\n", levelStr, msg); - } - - } - } - - va_end(listPointer); - - return status; -} diff --git a/bundles/logging/log_service_api/CMakeLists.txt b/bundles/logging/log_service_api/CMakeLists.txt index afd92dc7e..7acb82275 100644 --- a/bundles/logging/log_service_api/CMakeLists.txt +++ b/bundles/logging/log_service_api/CMakeLists.txt @@ -23,14 +23,6 @@ if (LOG_SERVICE_API) ) target_link_libraries(log_service_api INTERFACE Celix::utils) - if (CELIX_INSTALL_DEPRECATED_API) - target_link_libraries(log_service_api INTERFACE Celix::framework) - target_include_directories(log_service_api INTERFACE - $ - ) - install(DIRECTORY include_v2/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/log_service) - endif () - install(TARGETS log_service_api EXPORT celix INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/log_service) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/log_service) diff --git a/bundles/logging/log_service_api/include_v2/log_entry.h b/bundles/logging/log_service_api/include_v2/log_entry.h deleted file mode 100644 index 5e0a4fd35..000000000 --- a/bundles/logging/log_service_api/include_v2/log_entry.h +++ /dev/null @@ -1,49 +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. - */ - -#ifndef LOG_ENTRY_H_ -#define LOG_ENTRY_H_ - -#include "log_service.h" - -struct log_entry { - int errorCode; - log_level_t level; - char *message; - time_t time; - - long bundleId; - char* bundleSymbolicName; -}; - -typedef struct log_entry log_entry_t; -typedef struct log_entry *log_entry_pt CELIX_DEPRECATED_ATTR; - -celix_status_t logEntry_create(long bundleId, const char* bundleSymbolicName , service_reference_pt reference, - log_level_t level, char *message, int errorCode, - log_entry_t **entry); -celix_status_t logEntry_destroy(log_entry_t **entry); -celix_status_t logEntry_getBundleSymbolicName(log_entry_t *entry, const char** bundleSymbolicName); -celix_status_t logEntry_getBundleId(log_entry_t *entry, long *bundleId); -celix_status_t logEntry_getErrorCode(log_entry_t *entry, int *errorCode); -celix_status_t logEntry_getLevel(log_entry_t *entry, log_level_t *level); -celix_status_t logEntry_getMessage(log_entry_t *entry, const char** message); -celix_status_t logEntry_getTime(log_entry_t *entry, time_t *time); - -#endif /* LOG_ENTRY_H_ */ diff --git a/bundles/logging/log_service_api/include_v2/log_listener.h b/bundles/logging/log_service_api/include_v2/log_listener.h deleted file mode 100644 index defc03fe7..000000000 --- a/bundles/logging/log_service_api/include_v2/log_listener.h +++ /dev/null @@ -1,35 +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. - */ - -#ifndef LOG_LISTENER_H_ -#define LOG_LISTENER_H_ - -#include "log_entry.h" -#include "celix_errno.h" - -struct log_listener { - void *handle; - celix_status_t (*logged)(void *handle, log_entry_t *entry); -}; - -typedef struct log_listener log_listener_t; -typedef struct log_listener *log_listener_pt CELIX_DEPRECATED_ATTR; - - -#endif /* LOG_LISTENER_H_ */ diff --git a/bundles/logging/log_service_api/include_v2/log_reader_service.h b/bundles/logging/log_service_api/include_v2/log_reader_service.h deleted file mode 100644 index e9d3b390b..000000000 --- a/bundles/logging/log_service_api/include_v2/log_reader_service.h +++ /dev/null @@ -1,43 +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. - */ - -#ifndef LOG_READER_SERVICE_H_ -#define LOG_READER_SERVICE_H_ - - -#include "celix_errno.h" -#include "linked_list.h" -#include "log_listener.h" - -static const char * const OSGI_LOGSERVICE_READER_SERVICE_NAME = "log_reader_service"; - -typedef struct log_reader_data log_reader_data_t; - -struct log_reader_service { - log_reader_data_t *reader; - celix_status_t (*getLog)(log_reader_data_t *reader, linked_list_pt *list); - celix_status_t (*addLogListener)(log_reader_data_t *reader, log_listener_t *listener); - celix_status_t (*removeLogListener)(log_reader_data_t *reader, log_listener_t *listener); - celix_status_t (*removeAllLogListener)(log_reader_data_t *reader); -}; - -typedef struct log_reader_service log_reader_service_t; -typedef struct log_reader_service *log_reader_service_pt CELIX_DEPRECATED_ATTR; - -#endif /* LOG_READER_SERVICE_H_ */ diff --git a/bundles/logging/log_service_api/include_v2/log_service.h b/bundles/logging/log_service_api/include_v2/log_service.h deleted file mode 100644 index 2ae497751..000000000 --- a/bundles/logging/log_service_api/include_v2/log_service.h +++ /dev/null @@ -1,51 +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. - */ - -#ifndef LOG_SERVICE_H_ -#define LOG_SERVICE_H_ - -#include "celix_errno.h" -#include "service_reference.h" - -static const char * const OSGI_LOGSERVICE_NAME = "log_service"; - -typedef struct log_service_data log_service_data_t; - -enum log_level -{ - OSGI_LOGSERVICE_ERROR = 0x00000001, - OSGI_LOGSERVICE_WARNING = 0x00000002, - OSGI_LOGSERVICE_INFO = 0x00000003, - OSGI_LOGSERVICE_DEBUG = 0x00000004, -}; - -typedef enum log_level log_level_t; - -struct log_service { - log_service_data_t *logger; - celix_status_t (*log)(log_service_data_t *logger, log_level_t level, char *message); - celix_status_t (*logSr)(log_service_data_t *logger, service_reference_pt reference, log_level_t level, char *message); -}; - -typedef struct log_service log_service_t; -typedef struct log_service *log_service_pt CELIX_DEPRECATED_ATTR; - - - -#endif /* LOG_SERVICE_H_ */ diff --git a/bundles/logging/log_service_v2/CMakeLists.txt b/bundles/logging/log_service_v2/CMakeLists.txt deleted file mode 100644 index 17596fad4..000000000 --- a/bundles/logging/log_service_v2/CMakeLists.txt +++ /dev/null @@ -1,54 +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. - -add_celix_bundle(log_service - SYMBOLIC_NAME "apache_celix_log_service" - NAME "Apache Celix Log Service" - FILENAME celix_log_service - GROUP "Celix/Logging" - VERSION "1.1.0" - SOURCES - #v2 api - src/log.c - src/log_entry.c - src/log_factory.c - src/log_service_impl.c - src/log_service_activator.c - src/log_reader_service_impl.c -) -target_include_directories(log_service PRIVATE src) -target_link_libraries(log_service PRIVATE Celix::log_service_api) -celix_deprecated_utils_headers(log_service) -celix_deprecated_framework_headers(log_service) -install_celix_bundle(log_service EXPORT celix COMPONENT logging) - -add_celix_bundle(log_writer_stdout - SYMBOLIC_NAME "apache_celix_log_writer_stdout" - NAME "Apache Celix Log Writer Stdout" - FILENAME celix_log_writer_stdout - GROUP "Celix/Logging" - VERSION "1.1.0" - SOURCES - #v2 api - src/deprecated_log_writer_stdout_activator.c -) -celix_deprecated_utils_headers(log_writer_stdout) -install_celix_bundle(log_writer_stdout EXPORT celix COMPONENT logging) - -#Setup target aliases to match external usage -add_library(Celix::log_service ALIAS log_service) -add_library(Celix::log_writer_stdout ALIAS log_writer_stdout) diff --git a/bundles/logging/log_service_v2/src/deprecated_log_writer_stdout_activator.c b/bundles/logging/log_service_v2/src/deprecated_log_writer_stdout_activator.c deleted file mode 100644 index ed903bf1f..000000000 --- a/bundles/logging/log_service_v2/src/deprecated_log_writer_stdout_activator.c +++ /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. - */ - -#include "celix_bundle_activator.h" -#include "celix_compiler.h" - -typedef struct deprecated_log_writer_stdout_activator { - //nop -} deprecated_log_writer_stdout_activator_t; - -celix_status_t logWriterStdOut_start(deprecated_log_writer_stdout_activator_t* act CELIX_UNUSED, celix_bundle_context_t* ctx CELIX_UNUSED) { - fprintf(stderr, "Celix::log_writer_stdout bundle is deprecated. Please use Celix::log_admin instead of Celix::log_service and Celix::log_writer_stdout\n"); - return CELIX_SUCCESS; -} - -celix_status_t logWriterStdOut_stop(deprecated_log_writer_stdout_activator_t* act CELIX_UNUSED, celix_bundle_context_t* ctx CELIX_UNUSED) { - //nop; - return CELIX_SUCCESS; -} - -CELIX_GEN_BUNDLE_ACTIVATOR(deprecated_log_writer_stdout_activator_t, logWriterStdOut_start, logWriterStdOut_stop) \ No newline at end of file diff --git a/bundles/logging/log_service_v2/src/log.c b/bundles/logging/log_service_v2/src/log.c deleted file mode 100644 index ebc6405ae..000000000 --- a/bundles/logging/log_service_v2/src/log.c +++ /dev/null @@ -1,340 +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. - */ -/** - * log.c - * - * \date Jun 26, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include - -#include "log.h" -#include "linked_list_iterator.h" -#include "array_list.h" - -struct log { - linked_list_pt entries; - celix_thread_mutex_t lock; - - array_list_pt listeners; - array_list_pt listenerEntries; - - celix_thread_t listenerThread; - bool running; - - celix_thread_cond_t entriesToDeliver; - celix_thread_mutex_t deliverLock; - celix_thread_mutex_t listenerLock; - - int max_size; - bool store_debug; -}; - -static celix_status_t log_startListenerThread(log_t *logger); -static celix_status_t log_stopListenerThread(log_t *logger); - - -static void *log_listenerThread(void *data); - -celix_status_t log_create(int max_size, bool store_debug, log_t **logger) { - celix_status_t status = CELIX_ENOMEM; - - *logger = calloc(1, sizeof(**logger)); - - if (*logger != NULL) { - linkedList_create(&(*logger)->entries); - - status = celixThreadMutex_create(&(*logger)->lock, NULL); - - (*logger)->listeners = NULL; - (*logger)->listenerEntries = NULL; - (*logger)->listenerThread = celix_thread_default; - (*logger)->running = false; - - (*logger)->max_size = max_size; - (*logger)->store_debug = store_debug; - - arrayList_create(&(*logger)->listeners); - arrayList_create(&(*logger)->listenerEntries); - - if (celixThreadCondition_init(&(*logger)->entriesToDeliver, NULL) != CELIX_SUCCESS) { - status = CELIX_INVALID_SYNTAX; - } - else if (celixThreadMutex_create(&(*logger)->deliverLock, NULL) != CELIX_SUCCESS) { - status = CELIX_INVALID_SYNTAX; - } - else if (celixThreadMutex_create(&(*logger)->listenerLock, NULL) != CELIX_SUCCESS) { - status = CELIX_INVALID_SYNTAX; - } - else { - status = CELIX_SUCCESS; - } - } - - return status; -} - -celix_status_t log_destroy(log_t *logger) { - celix_status_t status = CELIX_SUCCESS; - - celixThreadMutex_destroy(&logger->listenerLock); - celixThreadMutex_destroy(&logger->deliverLock); - celixThreadCondition_destroy(&logger->entriesToDeliver); - - arrayList_destroy(logger->listeners); - linked_list_iterator_pt iter = linkedListIterator_create(logger->entries, 0); - while (linkedListIterator_hasNext(iter)) { - log_entry_t *entry = linkedListIterator_next(iter); - if (arrayList_contains(logger->listenerEntries, entry)) { - arrayList_removeElement(logger->listenerEntries, entry); - } - logEntry_destroy(&entry); - } - linkedListIterator_destroy(iter); - - array_list_iterator_pt entryIter = arrayListIterator_create(logger->listenerEntries); - - while (arrayListIterator_hasNext(entryIter)) { - log_entry_t *entry = arrayListIterator_next(entryIter); - logEntry_destroy(&entry); - } - arrayListIterator_destroy(entryIter); - - arrayList_destroy(logger->listenerEntries); - linkedList_destroy(logger->entries); - - celixThreadMutex_destroy(&logger->lock); - - free(logger); - - return status; -} - -celix_status_t log_addEntry(log_t *log, log_entry_t *entry) { - celixThreadMutex_lock(&log->lock); - - if (log->max_size != 0) { - if (log->store_debug || entry->level != OSGI_LOGSERVICE_DEBUG) { - linkedList_addElement(log->entries, entry); - } - } - - celixThreadMutex_lock(&log->deliverLock); - arrayList_add(log->listenerEntries, entry); - celixThreadMutex_unlock(&log->deliverLock); - - celixThreadCondition_signal(&log->entriesToDeliver); - - if (log->max_size != 0) { - if (log->max_size != -1) { - if (linkedList_size(log->entries) > log->max_size) { - log_entry_t *rentry = linkedList_removeFirst(log->entries); - if (rentry) { - celixThreadMutex_lock(&log->deliverLock); - arrayList_removeElement(log->listenerEntries, rentry); - logEntry_destroy(&rentry); - celixThreadMutex_unlock(&log->deliverLock); - } - } - } - } - - celixThreadMutex_unlock(&log->lock); - - return CELIX_SUCCESS; -} - -celix_status_t log_getEntries(log_t *log, linked_list_pt *list) { - linked_list_pt entries = NULL; - if (linkedList_create(&entries) == CELIX_SUCCESS) { - linked_list_iterator_pt iter = NULL; - - celixThreadMutex_lock(&log->lock); - - iter = linkedListIterator_create(log->entries, 0); - while (linkedListIterator_hasNext(iter)) { - linkedList_addElement(entries, linkedListIterator_next(iter)); - } - linkedListIterator_destroy(iter); - - *list = entries; - - celixThreadMutex_unlock(&log->lock); - - return CELIX_SUCCESS; - } else { - return CELIX_ENOMEM; - } -} - -celix_status_t log_bundleChanged(void *listener, celix_bundle_event_t *event) { - //deprecated nop - (void)listener; - (void)event; - return CELIX_SUCCESS; -} - -celix_status_t log_frameworkEvent(void *listener, framework_event_pt event) { - //deprecated nop - (void)listener; - (void)event; - return CELIX_SUCCESS; -} - -celix_status_t log_addLogListener(log_t *logger, log_listener_t *listener) { - celix_status_t status; - - status = celixThreadMutex_lock(&logger->listenerLock); - - if (status == CELIX_SUCCESS) { - arrayList_add(logger->listeners, listener); - log_startListenerThread(logger); - - status = celixThreadMutex_unlock(&logger->listenerLock); - } - - return status; -} - -celix_status_t log_removeLogListener(log_t *logger, log_listener_t *listener) { - celix_status_t status = CELIX_SUCCESS; - - status += celixThreadMutex_lock(&logger->deliverLock); - status += celixThreadMutex_lock(&logger->listenerLock); - - if (status == CELIX_SUCCESS) { - bool last = false; - - arrayList_removeElement(logger->listeners, listener); - if (arrayList_size(logger->listeners) == 0) { - status = log_stopListenerThread(logger); - last = true; - } - - status += celixThreadMutex_unlock(&logger->listenerLock); - status += celixThreadMutex_unlock(&logger->deliverLock); - - if (last) { - status += celixThread_join(logger->listenerThread, NULL); - } - } - - if (status != CELIX_SUCCESS) { - status = CELIX_SERVICE_EXCEPTION; - } - - return status; -} - -celix_status_t log_removeAllLogListener(log_t *logger) { - celix_status_t status; - - status = celixThreadMutex_lock(&logger->listenerLock); - - if (status == CELIX_SUCCESS) { - arrayList_clear(logger->listeners); - - status = celixThreadMutex_unlock(&logger->listenerLock); - } - - return status; -} - -static celix_status_t log_startListenerThread(log_t *logger) { - celix_status_t status; - - logger->running = true; - logger->running = true; - status = celixThread_create(&logger->listenerThread, NULL, log_listenerThread, logger); - - return status; -} - -static celix_status_t log_stopListenerThread(log_t *logger) { - celix_status_t status; - - logger->running = false; - - status = celixThreadCondition_signal(&logger->entriesToDeliver); - - return status; -} - -static void * log_listenerThread(void *data) { - celix_status_t status = CELIX_SUCCESS; - - log_t *logger = data; - - while (logger->running) { - - status = celixThreadMutex_lock(&logger->deliverLock); - - if ( status != CELIX_SUCCESS) { - logger->running = false; - } - else { - if (!arrayList_isEmpty(logger->listenerEntries)) { - log_entry_t *entry = (log_entry_t *) arrayList_remove(logger->listenerEntries, 0); - - if (entry) { - status = celixThreadMutex_lock(&logger->listenerLock); - if (status != CELIX_SUCCESS) { - logger->running = false; - break; - } else { - array_list_iterator_pt it = arrayListIterator_create(logger->listeners); - while (arrayListIterator_hasNext(it)) { - log_listener_t *listener = arrayListIterator_next(it); - listener->logged(listener, entry); - } - arrayListIterator_destroy(it); - - // destroy not-stored entries - if (!(logger->store_debug || entry->level != OSGI_LOGSERVICE_DEBUG)) { - logEntry_destroy(&entry); - } - - status = celixThreadMutex_unlock(&logger->listenerLock); - if (status != CELIX_SUCCESS) { - logger->running = false; - break; - } - } - } - } - - if (arrayList_isEmpty(logger->listenerEntries) && logger->running) { - celixThreadCondition_wait(&logger->entriesToDeliver, &logger->deliverLock); - } - - status = celixThreadMutex_unlock(&logger->deliverLock); - - if (status != CELIX_SUCCESS) { - logger->running = false; - break; - } - } - - } - - celixThread_exit(NULL); - return NULL; -} diff --git a/bundles/logging/log_service_v2/src/log.h b/bundles/logging/log_service_v2/src/log.h deleted file mode 100644 index 1da11f33f..000000000 --- a/bundles/logging/log_service_v2/src/log.h +++ /dev/null @@ -1,48 +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. - */ -/** - * log.h - * - * \date Jun 26, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef LOG_H_ -#define LOG_H_ - -#include "linked_list.h" -#include "log_entry.h" -#include "log_listener.h" - -typedef struct log log_t; - -celix_status_t log_create(int max_size, bool store_debug, log_t **logger); -celix_status_t log_destroy(log_t *logger); -celix_status_t log_addEntry(log_t *log, log_entry_t *entry); -celix_status_t log_getEntries(log_t *log, linked_list_pt *list); - -celix_status_t log_bundleChanged(void *listener, celix_bundle_event_t *event); -celix_status_t log_frameworkEvent(void *listener, framework_event_pt event); - -celix_status_t log_addLogListener(log_t *logger, log_listener_t *listener); -celix_status_t log_removeLogListener(log_t *logger, log_listener_t *listener); -celix_status_t log_removeAllLogListener(log_t *logger); - -#endif /* LOG_H_ */ diff --git a/bundles/logging/log_service_v2/src/log_entry.c b/bundles/logging/log_service_v2/src/log_entry.c deleted file mode 100644 index 284312f82..000000000 --- a/bundles/logging/log_service_v2/src/log_entry.c +++ /dev/null @@ -1,94 +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. - */ -/** - * log_entry.c - * - * \date Jun 26, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include -#include -#include - -#include "celix_errno.h" -#include "log_service.h" -#include "log_entry.h" - -celix_status_t logEntry_create(long bundleId, const char* bundleSymbolicName , service_reference_pt reference, - log_level_t level, char *message, int errorCode, - log_entry_t **entry) { - celix_status_t status = CELIX_SUCCESS; - - *entry = malloc(sizeof(**entry)); - if (*entry == NULL) { - status = CELIX_ENOMEM; - } else { - (*entry)->level = level; - (*entry)->message = strdup(message); - (*entry)->errorCode = errorCode; - (*entry)->time = time(NULL); - - (*entry)->bundleSymbolicName = strdup(bundleSymbolicName); - (*entry)->bundleId = bundleId; - } - - return status; -} - -celix_status_t logEntry_destroy(log_entry_t **entry) { - if (*entry) { - free((*entry)->bundleSymbolicName); - free((*entry)->message); - free(*entry); - *entry = NULL; - } - return CELIX_SUCCESS; -} - -celix_status_t logEntry_getBundleSymbolicName(log_entry_t *entry, const char** bundleSymbolicName) { - *bundleSymbolicName = entry->bundleSymbolicName; - return CELIX_SUCCESS; -} - -celix_status_t logEntry_getBundleId(log_entry_t *entry, long *bundleId) { - *bundleId = entry->bundleId; - return CELIX_SUCCESS; -} - -celix_status_t logEntry_getErrorCode(log_entry_t *entry, int *errorCode) { - *errorCode = entry->errorCode; - return CELIX_SUCCESS; -} - -celix_status_t logEntry_getLevel(log_entry_t *entry, log_level_t *level) { - *level = entry->level; - return CELIX_SUCCESS; -} - -celix_status_t logEntry_getMessage(log_entry_t *entry, const char **message) { - *message = entry->message; - return CELIX_SUCCESS; -} - -celix_status_t logEntry_getTime(log_entry_t *entry, time_t *time) { - *time = entry->time; - return CELIX_SUCCESS; -} diff --git a/bundles/logging/log_service_v2/src/log_factory.c b/bundles/logging/log_service_v2/src/log_factory.c deleted file mode 100644 index ac9be0f2e..000000000 --- a/bundles/logging/log_service_v2/src/log_factory.c +++ /dev/null @@ -1,100 +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. - */ -/** - * log_factory.c - * - * \date Jun 26, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include -#include - - -#include "service_factory.h" -#include "log_factory.h" -#include "log_service_impl.h" - -struct log_service_factory { - log_t *log; -}; - -celix_status_t logFactory_create(log_t *log, service_factory_pt *factory) { - celix_status_t status = CELIX_SUCCESS; - - *factory = calloc(1, sizeof(**factory)); - if (*factory == NULL) { - status = CELIX_ENOMEM; - } else { - log_service_factory_t *factoryData = calloc(1, sizeof(*factoryData)); - if (factoryData == NULL) { - status = CELIX_ENOMEM; - } else { - factoryData->log = log; - - (*factory)->handle = factoryData; - (*factory)->getService = logFactory_getService; - (*factory)->ungetService = logFactory_ungetService; - } - } - - return status; -} - -celix_status_t logFactory_destroy(service_factory_pt *factory) { - celix_status_t status = CELIX_SUCCESS; - - - free((*factory)->handle); - free(*factory); - - factory = NULL; - - return status; -} - - -celix_status_t logFactory_getService(void *factory, bundle_pt bundle, service_registration_pt registration, void **service) { - log_service_factory_t *log_factory = factory; - log_service_t *log_service = NULL; - log_service_data_t *log_service_data = NULL; - - logService_create(log_factory->log, bundle, &log_service_data); - - log_service = calloc(1, sizeof(*log_service)); - log_service->logger = log_service_data; - log_service->log = logService_log; - // log_service->logSr = logService_logSr; - - (*service) = log_service; - - return CELIX_SUCCESS; -} - -celix_status_t logFactory_ungetService(void *factory, celix_bundle_t *bundle, service_registration_pt registration, void **service) { - log_service_t *log_service = *service; - - logService_destroy(&log_service->logger); - - free(*service); - *service = NULL; - - return CELIX_SUCCESS; -} diff --git a/bundles/logging/log_service_v2/src/log_factory.h b/bundles/logging/log_service_v2/src/log_factory.h deleted file mode 100644 index ae7f66669..000000000 --- a/bundles/logging/log_service_v2/src/log_factory.h +++ /dev/null @@ -1,41 +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. - */ -/** - * log_factory.h - * - * \date Jun 26, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef LOG_FACTORY_H_ -#define LOG_FACTORY_H_ - -#include "log.h" - -typedef struct log_service_factory log_service_factory_t; -typedef struct log_service_factory *log_service_factory_pt; - -celix_status_t logFactory_create(log_t *log, service_factory_pt *factory); -celix_status_t logFactory_destroy(service_factory_pt *factory); -celix_status_t logFactory_getService(void *factory, celix_bundle_t *bundle, service_registration_pt registration, void **service); -celix_status_t logFactory_ungetService(void *factory, celix_bundle_t *bundle, service_registration_pt registration, void **service); - - -#endif /* LOG_FACTORY_H_ */ diff --git a/bundles/logging/log_service_v2/src/log_reader_service_impl.c b/bundles/logging/log_service_v2/src/log_reader_service_impl.c deleted file mode 100644 index 232d14171..000000000 --- a/bundles/logging/log_service_v2/src/log_reader_service_impl.c +++ /dev/null @@ -1,81 +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. - */ -/** - * log_reader_service_impl.c - * - * \date Jun 26, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include -#include - -#include "log_reader_service_impl.h" - -struct log_reader_data { - log_t *log; -}; - -celix_status_t logReaderService_create(log_t *log, log_reader_data_t **reader) { - celix_status_t status = CELIX_SUCCESS; - - *reader = (log_reader_data_t *) calloc(1, sizeof(**reader)); - - if (*reader == NULL) { - status = CELIX_ENOMEM; - } else { - (*reader)->log = log; - } - - return status; -} - -celix_status_t logReaderService_destroy(log_reader_data_t **reader) { - celix_status_t status = CELIX_SUCCESS; - - free(*reader); - reader = NULL; - - return status; -} - - - -celix_status_t logReaderService_getLog(log_reader_data_t *reader, linked_list_pt *list) { - celix_status_t status = CELIX_SUCCESS; - - status = log_getEntries(reader->log, list); - - return status; -} - -celix_status_t logReaderService_addLogListener(log_reader_data_t *reader, log_listener_t *listener) { - return log_addLogListener(reader->log, listener); -} - -celix_status_t logReaderService_removeLogListener(log_reader_data_t *reader, log_listener_t *listener) { - return log_removeLogListener(reader->log, listener); -} - -celix_status_t logReaderService_removeAllLogListener(log_reader_data_t *reader) { - return log_removeAllLogListener(reader->log); -} - - diff --git a/bundles/logging/log_service_v2/src/log_reader_service_impl.h b/bundles/logging/log_service_v2/src/log_reader_service_impl.h deleted file mode 100644 index 9391dd49b..000000000 --- a/bundles/logging/log_service_v2/src/log_reader_service_impl.h +++ /dev/null @@ -1,43 +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. - */ -/** - * log_reader_service_impl.h - * - * \date Jun 26, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef LOG_READER_SERVICE_IMPL_H_ -#define LOG_READER_SERVICE_IMPL_H_ - -#include "log_reader_service.h" -#include "log.h" - -celix_status_t logReaderService_create(log_t *log, log_reader_data_t **reader); -celix_status_t logReaderService_destroy(log_reader_data_t **reader); - -celix_status_t logReaderService_getLog(log_reader_data_t *reader, linked_list_pt *list); - -celix_status_t logReaderService_addLogListener(log_reader_data_t *reader, log_listener_t *listener); -celix_status_t logReaderService_removeLogListener(log_reader_data_t *reader, log_listener_t *listener); -celix_status_t logReaderService_removeAllLogListener(log_reader_data_t *reader); - - -#endif /* LOG_READER_SERVICE_IMPL_H_ */ diff --git a/bundles/logging/log_service_v2/src/log_service_activator.c b/bundles/logging/log_service_v2/src/log_service_activator.c deleted file mode 100644 index a1d1ccf23..000000000 --- a/bundles/logging/log_service_v2/src/log_service_activator.c +++ /dev/null @@ -1,195 +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. - */ -/** - * log_service_activator.c - * - * \date Jun 25, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include -#include -#include "celix_constants.h" - -#include "celix_bundle_activator.h" -#include "log_service_impl.h" -#include "service_factory.h" -#include "log_factory.h" -#include "log.h" -#include "log_reader_service_impl.h" -#include "service_registration.h" - -#define DEFAULT_MAX_SIZE 100 -#define DEFAULT_STORE_DEBUG false - -#define MAX_SIZE_PROPERTY "CELIX_LOG_MAX_SIZE" -#define STORE_DEBUG_PROPERTY "CELIX_LOG_STORE_DEBUG" - -struct logActivator { - celix_bundle_context_t *bundleContext; - service_registration_t *logServiceFactoryReg; - service_registration_t *logReaderServiceReg; - - bundle_listener_t *bundleListener; - framework_listener_t *frameworkListener; - - log_t *logger; - service_factory_pt factory; - log_reader_data_t *reader; - log_reader_service_t *reader_service; -}; - -static celix_status_t bundleActivator_getMaxSize(struct logActivator *activator, int *max_size); -static celix_status_t bundleActivator_getStoreDebug(struct logActivator *activator, bool *store_debug); - -celix_status_t celix_bundleActivator_create(celix_bundle_context_t *context, void **userData) { - celix_status_t status = CELIX_SUCCESS; - struct logActivator * activator = NULL; - - activator = (struct logActivator *) calloc(1, sizeof(struct logActivator)); - - if (activator == NULL) { - status = CELIX_ENOMEM; - } else { - activator->bundleContext = context; - activator->logServiceFactoryReg = NULL; - activator->logReaderServiceReg = NULL; - - activator->logger = NULL; - activator->factory = NULL; - activator->reader = NULL; - activator->reader_service = NULL; - - *userData = activator; - } - - return status; -} - -celix_status_t celix_bundleActivator_start(void * userData, celix_bundle_context_t *context) { - struct logActivator * activator = (struct logActivator *) userData; - celix_status_t status = CELIX_SUCCESS; - - int max_size = 0; - bool store_debug = false; - - bundleActivator_getMaxSize(activator, &max_size); - bundleActivator_getStoreDebug(activator, &store_debug); - - log_create(max_size, store_debug, &activator->logger); - - // Add logger as Bundle- and FrameworkEvent listener - activator->bundleListener = calloc(1, sizeof(*activator->bundleListener)); - activator->bundleListener->handle = activator->logger; - activator->bundleListener->bundleChanged = log_bundleChanged; - bundleContext_addBundleListener(context, activator->bundleListener); - - activator->frameworkListener = calloc(1, sizeof(*activator->frameworkListener)); - activator->frameworkListener->handle = activator->logger; - activator->frameworkListener->frameworkEvent = log_frameworkEvent; - bundleContext_addFrameworkListener(context, activator->frameworkListener); - - logFactory_create(activator->logger, &activator->factory); - - celix_properties_t *props = celix_properties_create(); - - - bundleContext_registerServiceFactory(context, (char *) OSGI_LOGSERVICE_NAME, activator->factory, props, &activator->logServiceFactoryReg); - - logReaderService_create(activator->logger, &activator->reader); - - activator->reader_service = calloc(1, sizeof(*activator->reader_service)); - activator->reader_service->reader = activator->reader; - activator->reader_service->getLog = logReaderService_getLog; - activator->reader_service->addLogListener = logReaderService_addLogListener; - activator->reader_service->removeLogListener = logReaderService_removeLogListener; - activator->reader_service->removeAllLogListener = logReaderService_removeAllLogListener; - - props = celix_properties_create(); - - bundleContext_registerService(context, (char *) OSGI_LOGSERVICE_READER_SERVICE_NAME, activator->reader_service, props, &activator->logReaderServiceReg); - return status; -} - -celix_status_t celix_bundleActivator_stop(void * userData, celix_bundle_context_t *context) { - struct logActivator * activator = (struct logActivator *) userData; - - serviceRegistration_unregister(activator->logReaderServiceReg); - activator->logReaderServiceReg = NULL; - serviceRegistration_unregister(activator->logServiceFactoryReg); - activator->logServiceFactoryReg = NULL; - - logReaderService_destroy(&activator->reader); - free(activator->reader_service); - - logFactory_destroy(&activator->factory); - - bundleContext_removeBundleListener(context, activator->bundleListener); - bundleContext_removeFrameworkListener(context, activator->frameworkListener); - - free(activator->bundleListener); - free(activator->frameworkListener); - - log_destroy(activator->logger); - - return CELIX_SUCCESS; -} - -celix_status_t celix_bundleActivator_destroy(void * userData, celix_bundle_context_t *context) { - struct logActivator * activator = (struct logActivator *) userData; - - free(activator); - - return CELIX_SUCCESS; -} - -static celix_status_t bundleActivator_getMaxSize(struct logActivator *activator, int *max_size) { - celix_status_t status = CELIX_SUCCESS; - - const char *max_size_str = NULL; - - *max_size = DEFAULT_MAX_SIZE; - - bundleContext_getProperty(activator->bundleContext, MAX_SIZE_PROPERTY, &max_size_str); - if (max_size_str) { - *max_size = atoi(max_size_str); - } - - return status; -} - -static celix_status_t bundleActivator_getStoreDebug(struct logActivator *activator, bool *store_debug) { - celix_status_t status = CELIX_SUCCESS; - - const char *store_debug_str = NULL; - - *store_debug = DEFAULT_STORE_DEBUG; - - bundleContext_getProperty(activator->bundleContext, STORE_DEBUG_PROPERTY, &store_debug_str); - if (store_debug_str) { - if (strcasecmp(store_debug_str, "true") == 0) { - *store_debug = true; - } else if (strcasecmp(store_debug_str, "false") == 0) { - *store_debug = false; - } - } - - return status; -} diff --git a/bundles/logging/log_service_v2/src/log_service_impl.c b/bundles/logging/log_service_v2/src/log_service_impl.c deleted file mode 100644 index efcfc636f..000000000 --- a/bundles/logging/log_service_v2/src/log_service_impl.c +++ /dev/null @@ -1,97 +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. - */ -/** - * log_service_impl.c - * - * \date Jun 22, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include - -#include "log_service_impl.h" -#include "module.h" -#include "bundle.h" - -struct log_service_data { - log_t *log; - celix_bundle_t *bundle; -}; - -celix_status_t logService_create(log_t *log, celix_bundle_t *bundle, log_service_data_t **logger) { - celix_status_t status = CELIX_SUCCESS; - *logger = calloc(1, sizeof(struct log_service_data)); - if (*logger == NULL) { - status = CELIX_ENOMEM; - } else { - (*logger)->bundle = bundle; - (*logger)->log = log; - } - - return status; -} - -celix_status_t logService_destroy(log_service_data_t **logger) { - celix_status_t status = CELIX_SUCCESS; - - free(*logger); - logger = NULL; - - return status; -} - -celix_status_t logService_log(log_service_data_t *logger, log_level_t level, char * message) { - return logService_logSr(logger, NULL, level, message); -} - -celix_status_t logService_logSr(log_service_data_t *logger, service_reference_pt reference, log_level_t level, char * message) { - celix_status_t status; - log_entry_t *entry = NULL; - celix_bundle_t *bundle = logger->bundle; - bundle_archive_pt archive = NULL; - module_pt module = NULL; - const char *symbolicName = NULL; - long bundleId = -1; - - if (reference != NULL) { - serviceReference_getBundle(reference, &bundle); - } - - status = bundle_getArchive(bundle, &archive); - - if (status == CELIX_SUCCESS) { - status = bundleArchive_getId(archive, &bundleId); - } - - if (status == CELIX_SUCCESS) { - status = bundle_getCurrentModule(bundle, &module); - - if (status == CELIX_SUCCESS) { - status = module_getSymbolicName(module, &symbolicName); - } - } - - if(status == CELIX_SUCCESS && symbolicName != NULL && message != NULL){ - status = logEntry_create(bundleId, symbolicName, reference, level, message, 0, &entry); - log_addEntry(logger->log, entry); - } - - return status; -} diff --git a/bundles/logging/log_service_v2/src/log_service_impl.h b/bundles/logging/log_service_v2/src/log_service_impl.h deleted file mode 100644 index 7038435e7..000000000 --- a/bundles/logging/log_service_v2/src/log_service_impl.h +++ /dev/null @@ -1,39 +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. - */ -/** - * log_service_impl.h - * - * \date Jun 22, 2011 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef LOG_SERVICE_IMPL_H_ -#define LOG_SERVICE_IMPL_H_ - -#include "log_service.h" -#include "log.h" - -celix_status_t logService_create(log_t *log, celix_bundle_t *bundle, log_service_data_t **logger); -celix_status_t logService_destroy(log_service_data_t **logger); -celix_status_t logService_log(log_service_data_t *logger, log_level_t level, char * message); -celix_status_t logService_logSr(log_service_data_t *logger, service_reference_pt reference, log_level_t level, char * message); - - -#endif /* LOG_SERVICE_IMPL_H_ */ diff --git a/bundles/logging/log_writers/syslog_writer/gtest/CMakeLists.txt b/bundles/logging/log_writers/syslog_writer/gtest/CMakeLists.txt index 87b4228e7..94dcc8d52 100644 --- a/bundles/logging/log_writers/syslog_writer/gtest/CMakeLists.txt +++ b/bundles/logging/log_writers/syslog_writer/gtest/CMakeLists.txt @@ -19,7 +19,7 @@ add_executable(test_syslog_writer src/SyslogWriterTestSuite.cc ) -target_link_libraries(test_syslog_writer PRIVATE Celix::log_service_api GTest::gtest GTest::gtest_main) +target_link_libraries(test_syslog_writer PRIVATE Celix::framework Celix::log_service_api GTest::gtest GTest::gtest_main) add_celix_bundle_dependencies(test_syslog_writer Celix::log_admin Celix::syslog_writer) target_compile_definitions(test_syslog_writer PRIVATE -DLOG_ADMIN_BUNDLE=\"$\") target_compile_definitions(test_syslog_writer PRIVATE -DSYSLOG_WRITER_BUNDLE=\"$\") diff --git a/bundles/pubsub/CMakeLists.txt b/bundles/pubsub/CMakeLists.txt index bf8fe5f60..11513943b 100644 --- a/bundles/pubsub/CMakeLists.txt +++ b/bundles/pubsub/CMakeLists.txt @@ -23,7 +23,6 @@ if (PUBSUB) add_subdirectory(pubsub_topology_manager) add_subdirectory(pubsub_admin_zmq) add_subdirectory(pubsub_admin_tcp) - add_subdirectory(pubsub_admin_udp_mc) add_subdirectory(pubsub_admin_websocket) add_subdirectory(pubsub_discovery) add_subdirectory(pubsub_serializer_json) diff --git a/bundles/pubsub/examples/CMakeLists.txt b/bundles/pubsub/examples/CMakeLists.txt index cdb570029..5afeb5a67 100644 --- a/bundles/pubsub/examples/CMakeLists.txt +++ b/bundles/pubsub/examples/CMakeLists.txt @@ -22,82 +22,6 @@ if (PUBSUB_EXAMPLES) find_program(ETCD_CMD NAMES etcd) find_program(XTERM_CMD NAMES xterm) - # UDP Multicast - if (BUILD_PUBSUB_PSA_UDP_MC AND BUILD_LAUNCHER) - add_celix_container(pubsub_publisher_udp_mc - LAUNCHER Celix::launcher - GROUP pubsub - BUNDLES - Celix::log_admin - Celix::shell - Celix::shell_tui - Celix::celix_pubsub_serializer_json - Celix::celix_pubsub_discovery_etcd - Celix::celix_pubsub_topology_manager - Celix::celix_pubsub_admin_udp_multicast - celix_pubsub_poi_publisher - celix_pubsub_poi_publisher2 - USE_CONFIG - PROPERTIES - PSA_UDPMC_VERBOSE=true - PUBSUB_ETCD_DISCOVERY_VERBOSE=true - PUBSUB_TOPOLOGY_MANAGER_VERBOSE=true - ) - - add_celix_container(pubsub_subscriber_udp_mc - LAUNCHER Celix::launcher - GROUP pubsub - BUNDLES - Celix::log_admin - Celix::shell - Celix::shell_tui - Celix::celix_pubsub_serializer_json - Celix::celix_pubsub_discovery_etcd - Celix::celix_pubsub_topology_manager - Celix::celix_pubsub_admin_udp_multicast - celix_pubsub_poi_subscriber - USE_CONFIG - PROPERTIES - PSA_UDPMC_VERBOSE=true - PUBSUB_ETCD_DISCOVERY_VERBOSE=true - PUBSUB_TOPOLOGY_MANAGER_VERBOSE=true - ) - - add_celix_container(pubsub_subscriber2_udp_mc - LAUNCHER Celix::launcher - GROUP pubsub - BUNDLES - Celix::log_admin - Celix::shell - Celix::shell_tui - Celix::celix_pubsub_serializer_json - Celix::celix_pubsub_discovery_etcd - Celix::celix_pubsub_topology_manager - Celix::celix_pubsub_admin_udp_multicast - celix_pubsub_poi_subscriber - USE_CONFIG - PROPERTIES - PSA_UDPMC_VERBOSE=true - PUBSUB_ETCD_DISCOVERY_VERBOSE=true - PUBSUB_TOPOLOGY_MANAGER_VERBOSE=true - ) - - if (ETCD_CMD AND XTERM_CMD) - # Runtime starting a publish and subscriber for udp mc - add_celix_runtime(pubsub_rt_upd_mc - NAME udp_mc - GROUP pubsub - CONTAINERS - pubsub_publisher_udp_mc - pubsub_subscriber_udp_mc - pubsub_subscriber2_udp_mc - COMMANDS - etcd - USE_TERM - ) - endif () - endif() - if (BUILD_PUBSUB_PSA_TCP AND BUILD_LAUNCHER) # TCP add_celix_container(pubsub_publisher_tcp @@ -179,7 +103,7 @@ if (PUBSUB_EXAMPLES) if (BUILD_PUBSUB_PSA_ZMQ AND BUILD_LAUNCHER) - if (BUILD_PUBSUB_PSA_TCP AND BUILD_PUBSUB_PSA_UDP_MC) + if (BUILD_PUBSUB_PSA_TCP) # Dynamic ZMQ / UDP / TCP admin add_celix_container(pubsub_publisher LAUNCHER Celix::launcher @@ -191,7 +115,6 @@ if (PUBSUB_EXAMPLES) Celix::celix_pubsub_discovery_etcd Celix::celix_pubsub_topology_manager Celix::celix_pubsub_admin_zmq - Celix::celix_pubsub_admin_udp_multicast Celix::celix_pubsub_admin_tcp Celix::celix_pubsub_protocol_wire_v1 celix_pubsub_poi_publisher @@ -209,7 +132,6 @@ if (PUBSUB_EXAMPLES) Celix::celix_pubsub_discovery_etcd Celix::celix_pubsub_topology_manager Celix::celix_pubsub_admin_zmq - Celix::celix_pubsub_admin_udp_multicast Celix::celix_pubsub_admin_tcp Celix::celix_pubsub_protocol_wire_v1 celix_pubsub_poi_subscriber diff --git a/bundles/pubsub/integration/CMakeLists.txt b/bundles/pubsub/integration/CMakeLists.txt index 73cd7ce7b..64ce44142 100644 --- a/bundles/pubsub/integration/CMakeLists.txt +++ b/bundles/pubsub/integration/CMakeLists.txt @@ -143,59 +143,6 @@ if (PUBSUB_INTEGRATION) target_include_directories(pubsub_serializer PRIVATE gtest) target_link_libraries(pubsub_serializer PRIVATE Celix::pubsub_api Celix::pubsub_spi) - if (BUILD_PUBSUB_PSA_UDP_MC) - add_celix_container(pubsub_udpmc_tests - USE_CONFIG #ensures that a config.properties will be created with the launch bundles. - LAUNCHER_SRC ${CMAKE_CURRENT_LIST_DIR}/gtest/PubSubIntegrationTestSuite.cc - DIR ${CMAKE_CURRENT_BINARY_DIR} - PROPERTIES - LOGHELPER_STDOUT_FALLBACK_INCLUDE_DEBUG=true - CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL=trace - BUNDLES - Celix::celix_pubsub_serializer_json - Celix::celix_pubsub_topology_manager - Celix::celix_pubsub_admin_udp_multicast - pubsub_sut - pubsub_tst - ) - target_link_libraries(pubsub_udpmc_tests PRIVATE Celix::pubsub_api GTest::gtest GTest::gtest_main) - target_include_directories(pubsub_udpmc_tests SYSTEM PRIVATE gtest) - add_test(NAME pubsub_udpmc_tests COMMAND pubsub_udpmc_tests WORKING_DIRECTORY $) - setup_target_for_coverage(pubsub_udpmc_tests SCAN_DIR ..) - - add_celix_container(pstm_deadlock_udpmc_test - USE_CONFIG #ensures that a config.properties will be created with the launch bundles. - LAUNCHER_SRC ${CMAKE_CURRENT_LIST_DIR}/pstm_deadlock_test/test_runner.cc - DIR ${CMAKE_CURRENT_BINARY_DIR} - PROPERTIES - LOGHELPER_STDOUT_FALLBACK_INCLUDE_DEBUG=true - CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL=trace - BUNDLES - Celix::celix_pubsub_serializer_json - Celix::celix_pubsub_protocol_wire_v2 - Celix::celix_pubsub_topology_manager - Celix::celix_pubsub_admin_udp_multicast - Celix::shell - Celix::shell_tui - ) - target_compile_definitions(pstm_deadlock_udpmc_test PRIVATE -DDEADLOCK_SUT_BUNDLE_FILE=\"${DEADLOCK_SUT_BUNDLE_FILE}\") - target_link_libraries(pstm_deadlock_udpmc_test PRIVATE Celix::pubsub_api GTest::gtest GTest::gtest_main) - target_include_directories(pstm_deadlock_udpmc_test SYSTEM PRIVATE pstm_deadlock_udpmc_test) - - add_celix_bundle_dependencies(pstm_deadlock_udpmc_test pubsub_deadlock_sut) - - #Framework "bundle" has no cache dir. Default as "cache dir" the cwd is used. - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/meta_data/msg.descriptor ${CMAKE_CURRENT_BINARY_DIR}/pstm_deadlock_udpmc_gtest/META-INF/descriptors/msg.descriptor COPYONLY) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/meta_data/deadlock.scope.properties ${CMAKE_CURRENT_BINARY_DIR}/pstm_deadlock_udpmc_gtest/META-INF/topics/pub/deadlock.properties COPYONLY) - - add_test(NAME pstm_deadlock_udpmc_test COMMAND pstm_deadlock_udpmc_test WORKING_DIRECTORY $) - setup_target_for_coverage(pstm_deadlock_udpmc_test SCAN_DIR ..) - - #TODO fix issues with UDPMC and reanble test again - #add_test(NAME pubsub_udpmc_tests COMMAND pubsub_udpmc_tests WORKING_DIRECTORY $) - #setup_target_for_coverage(pubsub_udpmc_tests SCAN_DIR ..) - endif() - if (BUILD_PUBSUB_PSA_TCP) # TCP v2 tests diff --git a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_admin.c b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_admin.c index 608b004eb..8d7898c6c 100644 --- a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_admin.c +++ b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_admin.c @@ -19,7 +19,6 @@ #include #include -#include #include #include diff --git a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_topic_receiver.c b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_topic_receiver.c index f448269a7..8f862e8ed 100644 --- a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_topic_receiver.c +++ b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_topic_receiver.c @@ -17,7 +17,6 @@ * under the License. */ -#include #include #include #include diff --git a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_topic_sender.c b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_topic_sender.c index 2ed0bb027..4332fc54d 100644 --- a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_topic_sender.c +++ b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_topic_sender.c @@ -17,7 +17,6 @@ * under the License. */ -#include #include #include #include diff --git a/bundles/pubsub/pubsub_admin_udp_mc/CMakeLists.txt b/bundles/pubsub/pubsub_admin_udp_mc/CMakeLists.txt deleted file mode 100644 index 1826b8d2a..000000000 --- a/bundles/pubsub/pubsub_admin_udp_mc/CMakeLists.txt +++ /dev/null @@ -1,44 +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(PUBSUB_PSA_UDP_MC "Build UDP MC PubSub Admin" ON) -if (PUBSUB_PSA_UDP_MC) - add_celix_bundle(celix_pubsub_admin_udp_multicast - BUNDLE_SYMBOLICNAME "apache_celix_pubsub_admin_udp_multicast" - VERSION "1.1.0" - GROUP "Celix/PubSub" - SOURCES - src/psa_activator.c - src/pubsub_udpmc_admin.c - src/pubsub_udpmc_topic_sender.c - src/pubsub_udpmc_topic_receiver.c - src/pubsub_udpmc_common.c - src/large_udp.c - ) - target_include_directories(celix_pubsub_admin_udp_multicast PRIVATE - src - ) - target_link_libraries(celix_pubsub_admin_udp_multicast PRIVATE Celix::log_helper Celix::shell_api) - target_link_libraries(celix_pubsub_admin_udp_multicast PRIVATE Celix::pubsub_spi Celix::pubsub_utils ) - celix_deprecated_utils_headers(celix_pubsub_admin_udp_multicast) - celix_deprecated_framework_headers(celix_pubsub_admin_udp_multicast) - install_celix_bundle(celix_pubsub_admin_udp_multicast EXPORT celix COMPONENT pubsub) - - add_library(Celix::celix_pubsub_admin_udp_multicast ALIAS celix_pubsub_admin_udp_multicast) -endif (PUBSUB_PSA_UDP_MC) - - diff --git a/bundles/pubsub/pubsub_admin_udp_mc/README.md b/bundles/pubsub/pubsub_admin_udp_mc/README.md deleted file mode 100644 index 42cbaa42f..000000000 --- a/bundles/pubsub/pubsub_admin_udp_mc/README.md +++ /dev/null @@ -1,83 +0,0 @@ ---- -title: PSA UDP Multicast ---- - - - -# PUBSUB-Admin UDP Multicast - ---- - -## Description - -This description is particular for the UDP-Multicast PUB-SUB. - -The UDP multicast pubsub admin is used to transfer user data transparent via UDP multicast. UDP packets can contain approximately -64kB . To overcome this limit the admin has a protocol on top of UDP which fragments the data to be send and these -fragments are reassembled at the reception side. - -### IP Addresses - -To use UDP-multicast 2 IP addresses are needed: - -1. IP address which is bound to an (ethernet) interface -2. The multicast address (in the range 224.X.X.X - 239.X.X.X) - -When the PubSubAdmin starts it determines the bound IP address. This is done in the order: - -1. The first IP number bound to the interface which is set by the "PSA_INTERFACE" property -2. The interfaces are iterated and the first IP number found is used. (typically this is 127.0.0.1 (localhost) - -The multicast IP address is determined in the order: - -1. If the `PSA_IP` property is defined, this IP will be used as multicast. -2. If the `PSA_MC_PREFIX` property, is defined, this property is used as the first 2 numbers of the multicast address extended with the last 2 numbers of the bound IP. -3. If the `PSA_MC_PREFIX` property is not defined `224.100` is used. - -### Discovery - -When a publisher request for a topic a TopicSender is created by a ServiceFactory. This TopicSender uses the multicast address as described above with a random chosen portnumber. The combination of the multicast-IP address with the portnumber and protocol(udp) is the endpoint. -This endpoint is published by the PubSubDiscovery within its topic in ETCD (i.e. udp://224.100.10.20:40123). - -A subscriber, interested in the topic, is informed by the the TopologyManager that there is a new endpoint. The TopicReceiver at the subscriber side creates a listening socket based on this endpoint. - -Now a data-connection is created and data send by the publisher will be received by the subscriber. - ---- - -## Properties - - - - - - -
PropertyDescription
PSA_INTERFACEInterface which has to be used for multicast communication
PSA_IPMulticast IP address used by the bundle
PSA_MC_PREFIXFirst 2 digits of the MC IP address
- ---- - -## Shortcomings - -1. Per topic a random portnr is used for creating an endpoint. It is theoretical possible that for 2 topic the same endpoint is created. -2. For every message a 32 bit random message ID is generated to discriminate segments of different messages which could be sent at the same time. It is theoretically possible that there are 2 equal message ID's at the same time. But since the message ID is valid only during the transmission of a message (maximum some milliseconds with large messages) this is not very plausible. -3. When sending large messages, these messages are segmented and sent after each other. This could cause UDP-buffer overflows in the kernel. A solution could be to add a delay between sending of the segments but this will introduce extra latency. -4. A Hash is created, using the message definition, to identify the message type. When 2 messages generate the same hash something will terribly go wrong. A check should be added to prevent this (or another way to identify the message type). This problem is also valid for the other admins. - - - - diff --git a/bundles/pubsub/pubsub_admin_udp_mc/src/large_udp.c b/bundles/pubsub/pubsub_admin_udp_mc/src/large_udp.c deleted file mode 100644 index aeedff59b..000000000 --- a/bundles/pubsub/pubsub_admin_udp_mc/src/large_udp.c +++ /dev/null @@ -1,366 +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. - */ -/** - * large_udp.c - * - * \date Mar 1, 2016 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include "large_udp.h" - -#include -#include -#include -#include -#include -#include -#include - -#define MAX_UDP_MSG_SIZE 65535 /* 2^16 -1 */ -#define IP_HEADER_SIZE 20 -#define UDP_HEADER_SIZE 8 -//#define MTU_SIZE 1500 -#define MTU_SIZE 8000 -#define MAX_MSG_VECTOR_LEN 64 - -//#define NO_IP_FRAGMENTATION - -struct largeUdp { - unsigned int maxNrLists; - array_list_pt udpPartLists; - pthread_mutex_t dbLock; -}; - -typedef struct udpPartList { - unsigned int msg_ident; - unsigned int msg_size; - unsigned int nrPartsRemaining; - char *data; -} udpPartList_t; - - -typedef struct msg_part_header { - unsigned int msg_ident; - unsigned int total_msg_size; - unsigned int part_msg_size; - unsigned int offset; -} msg_part_header_t; - -#ifdef NO_IP_FRAGMENTATION -#define MAX_PART_SIZE (MTU_SIZE - (IP_HEADER_SIZE + UDP_HEADER_SIZE + sizeof(struct msg_part_header) )) -#else -#define MAX_PART_SIZE (MAX_UDP_MSG_SIZE - (IP_HEADER_SIZE + UDP_HEADER_SIZE + sizeof(struct msg_part_header) )) -#endif - -// -// Create a handle -// -largeUdp_t *largeUdp_create(unsigned int maxNrUdpReceptions) -{ - printf("## Creating large UDP\n"); - largeUdp_t *handle = calloc(sizeof(*handle), 1); - if (handle != NULL) { - handle->maxNrLists = maxNrUdpReceptions; - if (arrayList_create(&handle->udpPartLists) != CELIX_SUCCESS) { - free(handle); - handle = NULL; - } - pthread_mutex_init(&handle->dbLock, 0); - } - - return handle; -} - -// -// Destroys the handle -// -void largeUdp_destroy(largeUdp_t *handle) -{ - printf("### Destroying large UDP\n"); - if (handle != NULL) { - pthread_mutex_lock(&handle->dbLock); - int nrUdpLists = arrayList_size(handle->udpPartLists); - int i; - for (i=0; i < nrUdpLists; i++) { - udpPartList_t *udpPartList = arrayList_remove(handle->udpPartLists, i); - if (udpPartList) { - if (udpPartList->data) { - free(udpPartList->data); - udpPartList->data = NULL; - } - free(udpPartList); - } - } - arrayList_destroy(handle->udpPartLists); - handle->udpPartLists = NULL; - pthread_mutex_unlock(&handle->dbLock); - pthread_mutex_destroy(&handle->dbLock); - free(handle); - } -} - -// -// Write large data to UDP. This function splits the data in chunks and sends these chunks with a header over UDP. -// -int largeUdp_sendmsg(largeUdp_t *handle, int fd, struct iovec *largeMsg_iovec, int len, int flags, struct sockaddr_in *dest_addr, size_t addrlen) -{ - int n; - int result = 0; - msg_part_header_t header; - - int written = 0; - header.msg_ident = (unsigned int)random(); - header.total_msg_size = 0; - for (n = 0; n < len ;n++) { - header.total_msg_size += largeMsg_iovec[n].iov_len; - } - int nr_buffers = (header.total_msg_size / MAX_PART_SIZE) + 1; - - struct iovec msg_iovec[MAX_MSG_VECTOR_LEN]; - struct msghdr msg; - msg.msg_name = dest_addr; - msg.msg_namelen = addrlen; - msg.msg_flags = 0; - msg.msg_iov = msg_iovec; - msg.msg_iovlen = 2; // header and payload; - msg.msg_control = NULL; - msg.msg_controllen = 0; - - msg.msg_iov[0].iov_base = &header; - msg.msg_iov[0].iov_len = sizeof(header); - - for (n = 0; n < nr_buffers; n++) { - - header.part_msg_size = (((header.total_msg_size - n * MAX_PART_SIZE) > MAX_PART_SIZE) ? MAX_PART_SIZE : (header.total_msg_size - n * MAX_PART_SIZE)); - header.offset = n * MAX_PART_SIZE; - int remainingOffset = header.offset; - int recvPart = 0; - // find the start of the part - while (remainingOffset > largeMsg_iovec[recvPart].iov_len) { - remainingOffset -= largeMsg_iovec[recvPart].iov_len; - recvPart++; - } - int remainingData = header.part_msg_size; - int sendPart = 1; - msg.msg_iovlen = 1; - - // fill in the output iovec from the input iovec in such a way that all UDP frames are filled maximal. - while (remainingData > 0) { - int partLen = ( (largeMsg_iovec[recvPart].iov_len - remainingOffset) <= remainingData ? (largeMsg_iovec[recvPart].iov_len -remainingOffset) : remainingData); - msg.msg_iov[sendPart].iov_base = largeMsg_iovec[recvPart].iov_base + remainingOffset; - msg.msg_iov[sendPart].iov_len = partLen; - remainingData -= partLen; - remainingOffset = 0; - sendPart++; - recvPart++; - msg.msg_iovlen++; - } - int tmp, tmptot; - for (tmp = 0, tmptot=0; tmp < msg.msg_iovlen; tmp++) { - tmptot += msg.msg_iov[tmp].iov_len; - } - - int w = sendmsg(fd, &msg, 0); - if (w == -1) { - perror("send()"); - result = -1; - break; - } - written += w; - } - - return (result == 0 ? written : result); -} - -// -// Write large data to UDP. This function splits the data in chunks and sends these chunks with a header over UDP. -// -int largeUdp_sendto(largeUdp_t *handle, int fd, void *buf, size_t count, int flags, struct sockaddr_in *dest_addr, size_t addrlen) -{ - int n; - int nr_buffers = (count / MAX_PART_SIZE) + 1; - int result = 0; - msg_part_header_t header; - - int written = 0; - header.msg_ident = (unsigned int)random(); - header.total_msg_size = count; - char *databuf = buf; - - struct iovec msg_iovec[2]; - struct msghdr msg; - msg.msg_name = dest_addr; - msg.msg_namelen = addrlen; - msg.msg_flags = 0; - msg.msg_iov = msg_iovec; - msg.msg_iovlen = 2; // header and payload; - msg.msg_control = NULL; - msg.msg_controllen = 0; - - msg.msg_iov[0].iov_base = &header; - msg.msg_iov[0].iov_len = sizeof(header); - - for (n = 0; n < nr_buffers; n++) { - - header.part_msg_size = (((header.total_msg_size - n * MAX_PART_SIZE) > MAX_PART_SIZE) ? MAX_PART_SIZE : (header.total_msg_size - n * MAX_PART_SIZE)); - header.offset = n * MAX_PART_SIZE; - msg.msg_iov[1].iov_base = &databuf[header.offset]; - msg.msg_iov[1].iov_len = header.part_msg_size; - int w = sendmsg(fd, &msg, 0); - if (w == -1) { - perror("send()"); - result = -1; - break; - } - written += w; - //usleep(1000); // TODO: If not slept a UDP buffer overflow occurs and parts are missing at the reception side (at least via localhost) - } - - return (result == 0 ? written : result); -} - -// -// Reads data from the filedescriptor which has date (determined by epoll()) and stores it in the internal structure -// If the message is completely reassembled true is returned and the index and size have valid values -// -bool largeUdp_dataAvailable(largeUdp_t *handle, int fd, unsigned int *index, unsigned int *size) { - msg_part_header_t header; - int result = false; - // Only read the header, we don't know yet where to store the payload - if (recv(fd, &header, sizeof(header), MSG_PEEK) < 0) { - perror("read()"); - return false; - } - - struct iovec msg_vec[2]; - struct msghdr msg; - msg.msg_name = NULL; - msg.msg_namelen = 0; - msg.msg_flags = 0; - msg.msg_iov = msg_vec; - msg.msg_iovlen = 2; // header and payload; - msg.msg_control = NULL; - msg.msg_controllen = 0; - - msg.msg_iov[0].iov_base = &header; - msg.msg_iov[0].iov_len = sizeof(header); - - pthread_mutex_lock(&handle->dbLock); - - int nrUdpLists = arrayList_size(handle->udpPartLists); - int i; - bool found = false; - for (i = 0; i < nrUdpLists; i++) { - udpPartList_t *udpPartList = arrayList_get(handle->udpPartLists, i); - if (udpPartList->msg_ident == header.msg_ident) { - found = true; - - //sanity check - if (udpPartList->msg_size != header.total_msg_size) { - // Corruption occurred. Remove the existing administration and build up a new one. - arrayList_remove(handle->udpPartLists, i); - free(udpPartList->data); - free(udpPartList); - found = false; - break; - } - - msg.msg_iov[1].iov_base = &udpPartList->data[header.offset]; - msg.msg_iov[1].iov_len = header.part_msg_size; - if (recvmsg(fd, &msg, 0)<0) { - found=true; - result=false; - break; - } - - udpPartList->nrPartsRemaining--; - if (udpPartList->nrPartsRemaining == 0) { - *index = i; - *size = udpPartList->msg_size; - result = true; - break; - } else { - result = false; // not complete - break; - } - } - } - - if (found == false) { - udpPartList_t *udpPartList = NULL; - if (nrUdpLists == handle->maxNrLists) { - // remove list at index 0 - udpPartList = arrayList_remove(handle->udpPartLists, 0); - fprintf(stderr, "ERROR: Removing entry for id %d: %d parts not received\n",udpPartList->msg_ident, udpPartList->nrPartsRemaining ); - free(udpPartList->data); - free(udpPartList); - nrUdpLists--; - } - udpPartList = calloc(sizeof(*udpPartList), 1); - udpPartList->msg_ident = header.msg_ident; - udpPartList->msg_size = header.total_msg_size; - udpPartList->nrPartsRemaining = header.total_msg_size / MAX_PART_SIZE; - udpPartList->data = calloc(sizeof(char), header.total_msg_size); - - msg.msg_iov[1].iov_base = &udpPartList->data[header.offset]; - msg.msg_iov[1].iov_len = header.part_msg_size; - if (recvmsg(fd, &msg, 0)<0) { - free(udpPartList->data); - free(udpPartList); - result=false; - } else { - arrayList_add(handle->udpPartLists, udpPartList); - - if (udpPartList->nrPartsRemaining == 0) { - *index = nrUdpLists; - *size = udpPartList->msg_size; - result = true; - } else { - result = false; - } - } - - } - - pthread_mutex_unlock(&handle->dbLock); - - return result; -} - -// -// Read out the message which is indicated available by the largeUdp_dataAvailable function -// -int largeUdp_read(largeUdp_t *handle, unsigned int index, void ** buffer, unsigned int size) -{ - int result = 0; - pthread_mutex_lock(&handle->dbLock); - - udpPartList_t *udpPartList = arrayList_remove(handle->udpPartLists, index); - if (udpPartList) { - *buffer = udpPartList->data; - free(udpPartList); - } else { - result = -1; - } - pthread_mutex_unlock(&handle->dbLock); - - return result; -} diff --git a/bundles/pubsub/pubsub_admin_udp_mc/src/large_udp.h b/bundles/pubsub/pubsub_admin_udp_mc/src/large_udp.h deleted file mode 100644 index 785838493..000000000 --- a/bundles/pubsub/pubsub_admin_udp_mc/src/large_udp.h +++ /dev/null @@ -1,46 +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. - */ -/** - * large_udp.h - * - * \date Mar 1, 2016 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef _LARGE_UDP_H_ -#define _LARGE_UDP_H_ - -#include -#include -#include -#include -#include - -typedef struct largeUdp largeUdp_t; - -largeUdp_t *largeUdp_create(unsigned int maxNrUdpReceptions); -void largeUdp_destroy(largeUdp_t *handle); - -int largeUdp_sendto(largeUdp_t *handle, int fd, void *buf, size_t count, int flags, struct sockaddr_in *dest_addr, size_t addrlen); -int largeUdp_sendmsg(largeUdp_t *handle, int fd, struct iovec *largeMsg_iovec, int len, int flags, struct sockaddr_in *dest_addr, size_t addrlen); -bool largeUdp_dataAvailable(largeUdp_t *handle, int fd, unsigned int *index, unsigned int *size); -int largeUdp_read(largeUdp_t *handle, unsigned int index, void ** buffer, unsigned int size); - -#endif /* _LARGE_UDP_H_ */ diff --git a/bundles/pubsub/pubsub_admin_udp_mc/src/psa_activator.c b/bundles/pubsub/pubsub_admin_udp_mc/src/psa_activator.c deleted file mode 100644 index 0cc543c5a..000000000 --- a/bundles/pubsub/pubsub_admin_udp_mc/src/psa_activator.c +++ /dev/null @@ -1,111 +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 - -#include "celix_api.h" -#include "pubsub_serializer.h" -#include "celix_log_helper.h" - -#include "pubsub_admin.h" -#include "pubsub_udpmc_admin.h" -#include "celix_shell_command.h" - -typedef struct psa_udpmc_activator { - celix_log_helper_t *logHelper; - - pubsub_udpmc_admin_t *admin; - - long serializersTrackerId; - - pubsub_admin_service_t adminService; - long adminSvcId; - - celix_shell_command_t cmdSvc; - long cmdSvcId; -} psa_udpmc_activator_t; - -int psa_udpmc_start(psa_udpmc_activator_t *act, celix_bundle_context_t *ctx) { - act->adminSvcId = -1L; - act->cmdSvcId = -1L; - act->serializersTrackerId = -1L; - - - act->logHelper = celix_logHelper_create(ctx, "celix_psa_admin_udpmc"); - - act->admin = pubsub_udpmcAdmin_create(ctx, act->logHelper); - celix_status_t status = act->admin != NULL ? CELIX_SUCCESS : CELIX_BUNDLE_EXCEPTION; - - //track serializers - if (status == CELIX_SUCCESS) { - celix_service_tracking_options_t opts = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS; - opts.filter.serviceName = PUBSUB_SERIALIZER_SERVICE_NAME; - opts.filter.ignoreServiceLanguage = true; - opts.callbackHandle = act->admin; - opts.addWithProperties = pubsub_udpmcAdmin_addSerializerSvc; - opts.removeWithProperties = pubsub_udpmcAdmin_removeSerializerSvc; - act->serializersTrackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts); - } - - //register pubsub admin service - if (status == CELIX_SUCCESS) { - pubsub_admin_service_t *psaSvc = &act->adminService; - psaSvc->handle = act->admin; - psaSvc->matchPublisher = pubsub_udpmcAdmin_matchPublisher; - psaSvc->matchSubscriber = pubsub_udpmcAdmin_matchSubscriber; - psaSvc->matchDiscoveredEndpoint = pubsub_udpmcAdmin_matchEndpoint; - psaSvc->setupTopicSender = pubsub_udpmcAdmin_setupTopicSender; - psaSvc->teardownTopicSender = pubsub_udpmcAdmin_teardownTopicSender; - psaSvc->setupTopicReceiver = pubsub_udpmcAdmin_setupTopicReceiver; - psaSvc->teardownTopicReceiver = pubsub_udpmcAdmin_teardownTopicReceiver; - psaSvc->addDiscoveredEndpoint = pubsub_udpmcAdmin_addEndpoint; - psaSvc->removeDiscoveredEndpoint = pubsub_udpmcAdmin_removeEndpoint; - - celix_properties_t *props = celix_properties_create(); - celix_properties_set(props, PUBSUB_ADMIN_SERVICE_TYPE, PUBSUB_UDPMC_ADMIN_TYPE); - - act->adminSvcId = celix_bundleContext_registerService(ctx, psaSvc, PUBSUB_ADMIN_SERVICE_NAME, props); - } - - //register shell command service - { - act->cmdSvc.handle = act->admin; - act->cmdSvc.executeCommand = pubsub_udpmcAdmin_executeCommand; - celix_properties_t *props = celix_properties_create(); - celix_properties_set(props, CELIX_SHELL_COMMAND_NAME, "celix::psa_udpmc"); - celix_properties_set(props, CELIX_SHELL_COMMAND_USAGE, "psa_udpmc"); - celix_properties_set(props, CELIX_SHELL_COMMAND_DESCRIPTION, "Print the information about the TopicSender and TopicReceivers for the UDPMC PSA"); - act->cmdSvcId = celix_bundleContext_registerService(ctx, &act->cmdSvc, CELIX_SHELL_COMMAND_SERVICE_NAME, props); - } - - return status; -} - -int psa_udpmc_stop(psa_udpmc_activator_t *act, celix_bundle_context_t *ctx) { - celix_bundleContext_unregisterService(ctx, act->adminSvcId); - celix_bundleContext_unregisterService(ctx, act->cmdSvcId); - celix_bundleContext_stopTracker(ctx, act->serializersTrackerId); - pubsub_udpmcAdmin_destroy(act->admin); - - celix_logHelper_destroy(act->logHelper); - - return CELIX_SUCCESS; -} - -CELIX_GEN_BUNDLE_ACTIVATOR(psa_udpmc_activator_t, psa_udpmc_start, psa_udpmc_stop); diff --git a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_psa_udpmc_constants.h b/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_psa_udpmc_constants.h deleted file mode 100644 index 14820d2b7..000000000 --- a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_psa_udpmc_constants.h +++ /dev/null @@ -1,76 +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. - */ - -#ifndef PUBSUB_PSA_UDPMC_CONSTANTS_H_ -#define PUBSUB_PSA_UDPMC_CONSTANTS_H_ - - -#define PSA_UDPMC_PUBSUB_ADMIN_TYPE "udp_mc" - -#define PSA_UDPMC_DEFAULT_QOS_SAMPLE_SCORE 70 -#define PSA_UDPMC_DEFAULT_QOS_CONTROL_SCORE 30 -#define PSA_UDPMC_DEFAULT_SCORE 50 - -#define PSA_UDPMC_QOS_SAMPLE_SCORE_KEY "PSA_UDPMC_QOS_SAMPLE_SCORE" -#define PSA_UDPMC_QOS_CONTROL_SCORE_KEY "PSA_UDPMC_QOS_CONTROL_SCORE" -#define PSA_UDPMC_DEFAULT_SCORE_KEY "PSA_UDPMC_DEFAULT_SCORE" - - -#define PUBSUB_UDPMC_ADMIN_TYPE "udp_mc" -#define PUBSUB_UDPMC_SOCKET_ADDRESS_KEY "udpmc.socket_address" -#define PUBSUB_UDPMC_SOCKET_PORT_KEY "udpmc.socket_port" - -#define PUBSUB_UDPMC_IP_KEY "PSA_IP" -#define PUBSUB_UDPMC_ITF_KEY "PSA_INTERFACE" -#define PUBSUB_UDPMC_MULTICAST_IP_PREFIX_KEY "PSA_MC_PREFIX" -#define PUBSUB_UDPMC_VERBOSE_KEY "PSA_UDPMC_VERBOSE" - -#define PUBSUB_UDPMC_MULTICAST_IP_PREFIX_DEFAULT "224.100" -#define PUBSUB_UDPMC_MULTICAST_IP_DEFAULT "224.100.1.1" -#define PUBSUB_UDPMC_VERBOSE_DEFAULT true - -/** - * If set true on the endpoint, the udp mc TopicSender bind and/or discovery url is statically configured. - */ -#define PUBSUB_UDPMC_STATIC_CONFIGURED "updmc.static.configured" - -/** - * Name of environment variable with ip/url to bind to - * e.g. PUBSUB_UDPMC_STATIC_BIND_PORT_URL_FOR_topic_scope="4444" - */ -#define PUBSUB_UDPMC_STATIC_BIND_PORT_URL_FOR "PSA_UDPMC_STATIC_BIND_PORT_FOR_" - -/** - * Can be set in the topic properties to fix a static mc port for topic senders - */ -#define PUBSUB_UDPMC_STATIC_BIND_PORT "udpmc.static.bind.port" - -/** - * The static url which a subscriber should try to connect to. - * The urls are space separated - */ -#define PUBSUB_UDPMC_STATIC_CONNECT_SOCKET_ADDRESSES "udpmc.static.connect.socket_addresses" - -/** - * Name of environment variable with space-separated list of ips/urls to connect to - * e.g. PSA_UDPMC_STATIC_CONNECT_URLS_FOR_topic_scope="127.0.0.1:4444 127.0.0.2:4444" - */ -#define PUBSUB_UDPMC_STATIC_CONNECT_URLS_FOR "PSA_UDPMC_STATIC_CONNECT_URLS_FOR_" - -#endif /* PUBSUB_PSA_UDPMC_CONSTANTS_H_ */ diff --git a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_admin.c b/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_admin.c deleted file mode 100644 index aea8987ff..000000000 --- a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_admin.c +++ /dev/null @@ -1,700 +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 -#include -#include -#include -#include -#include -#include -#include -#include - -#include "pubsub_utils.h" -#include "pubsub_udpmc_admin.h" -#include "pubsub_psa_udpmc_constants.h" -#include "pubsub_udpmc_topic_sender.h" -#include "pubsub_udpmc_topic_receiver.h" -#include "celix_compiler.h" - - -#define L_DEBUG(...) \ - celix_logHelper_log(psa->log, CELIX_LOG_LEVEL_DEBUG, __VA_ARGS__) -#define L_INFO(...) \ - celix_logHelper_log(psa->log, CELIX_LOG_LEVEL_INFO, __VA_ARGS__) -#define L_WARN(...) \ - celix_logHelper_log(psa->log, CELIX_LOG_LEVEL_WARNING, __VA_ARGS__) -#define L_ERROR(...) \ - celix_logHelper_log(psa->log, CELIX_LOG_LEVEL_ERROR, __VA_ARGS__) - -struct pubsub_udpmc_admin { - celix_bundle_context_t *ctx; - celix_log_helper_t *log; - char *ifIpAddress; // The local interface which is used for multicast communication - char *mcIpAddress; // The multicast IP address - int sendSocket; - double qosSampleScore; - double qosControlScore; - double defaultScore; - bool verbose; - const char *fwUUID; - - struct { - celix_thread_mutex_t mutex; - hash_map_t *map; - } serializers; - - struct { - celix_thread_mutex_t mutex; - hash_map_t *map; //key = scope:topic key, value = pubsub_udpmc_topic_sender_t* - } topicSenders; - - struct { - celix_thread_mutex_t mutex; - hash_map_t *map; //key = scope:topic key, value = pubsub_udpmc_topic_receiver_t* - } topicReceivers; - - struct { - celix_thread_mutex_t mutex; - hash_map_t *map; //key = endpoint uuid, value = celix_properties_t* - } discoveredEndpoints; - -}; - -typedef struct psa_udpmc_serializer_entry { - const char *serType; - long svcId; - pubsub_serializer_service_t *svc; -} psa_udpmc_serializer_entry_t; - -static celix_status_t udpmc_getIpAddress(const char* interface, char** ip); -static celix_status_t pubsub_udpmcAdmin_connectEndpointToReceiver(pubsub_udpmc_admin_t* psa, pubsub_udpmc_topic_receiver_t *receiver, const celix_properties_t *endpoint); -static celix_status_t pubsub_udpmcAdmin_disconnectEndpointFromReceiver(pubsub_udpmc_admin_t* psa, pubsub_udpmc_topic_receiver_t *receiver, const celix_properties_t *endpoint); - -static bool pubsub_udpmcAdmin_endpointIsPublisher(const celix_properties_t *endpoint) { - const char *type = celix_properties_get(endpoint, PUBSUB_ENDPOINT_TYPE, NULL); - return type != NULL && strncmp(PUBSUB_PUBLISHER_ENDPOINT_TYPE, type, strlen(PUBSUB_PUBLISHER_ENDPOINT_TYPE)) == 0; -} - - -pubsub_udpmc_admin_t* pubsub_udpmcAdmin_create(celix_bundle_context_t *ctx, celix_log_helper_t *logHelper) { - pubsub_udpmc_admin_t *psa = calloc(1, sizeof(*psa)); - psa->ctx = ctx; - psa->log = logHelper; - psa->verbose = celix_bundleContext_getPropertyAsBool(ctx, PUBSUB_UDPMC_VERBOSE_KEY, PUBSUB_UDPMC_VERBOSE_DEFAULT); - psa->fwUUID = celix_bundleContext_getProperty(ctx, OSGI_FRAMEWORK_FRAMEWORK_UUID, NULL); - - int b0 = 0, b1 = 0, b2 = 0, b3 = 0; - - char *mc_ip = NULL; - char *if_ip = NULL; - int sendSocket = -1; - - const char *mcIpProp = celix_bundleContext_getProperty(ctx, PUBSUB_UDPMC_IP_KEY, NULL); - if (mcIpProp != NULL) { - if (strchr(mcIpProp, '/') != NULL) { - // IP with subnet prefix specified - if_ip = ipUtils_findIpBySubnet(mcIpProp); - if (if_ip == NULL) { - L_WARN("[PSA_UDPMC] Could not find interface for requested subnet %s", mcIpProp); - } - } else { - // IP address specified - mc_ip = strndup(mcIpProp, 1024); - } - } - - - const char *mc_prefix = celix_bundleContext_getProperty(ctx, PUBSUB_UDPMC_MULTICAST_IP_PREFIX_KEY, PUBSUB_UDPMC_MULTICAST_IP_PREFIX_DEFAULT); - const char *interface = celix_bundleContext_getProperty(ctx, PUBSUB_UDPMC_ITF_KEY, NULL); - if (!if_ip && udpmc_getIpAddress(interface, &if_ip) != CELIX_SUCCESS) { - L_WARN("[PSA_UDPMC] Could not retrieve IP address for interface %s", interface); - } else if (psa->verbose) { - L_INFO("[PSA_UDPMC] Using IP address %s", if_ip); - } - - if (if_ip && sscanf(if_ip, "%i.%i.%i.%i", &b0, &b1, &b2, &b3) != 4) { - celix_logHelper_log(psa->log, CELIX_LOG_LEVEL_WARNING, "[PSA_UDPMC] Could not parse IP address %s", if_ip); - b2 = 1; - b3 = 1; - } - - asprintf(&mc_ip, "%s.%d.%d",mc_prefix, b2, b3); - - sendSocket = socket(AF_INET, SOCK_DGRAM, 0); - if (sendSocket == -1) { - L_ERROR("[PSA_UDPMC] Error creating socket: %s", strerror(errno)); - } else { - char loop = 1; - int rc = setsockopt(sendSocket, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)); - if (rc != 0) { - L_ERROR("[PSA_UDPMC] Error setsockopt(IP_MULTICAST_LOOP): %s", strerror(errno)); - } - if (rc == 0) { - struct in_addr multicast_interface; - inet_aton(if_ip, &multicast_interface); - rc = setsockopt(sendSocket, IPPROTO_IP, IP_MULTICAST_IF, &multicast_interface, sizeof(multicast_interface)); - if (rc != 0) { - L_ERROR("[PSA_UDPMC] Error setsockopt(IP_MULTICAST_IF): %s", strerror(errno)); - } - } - if (rc == 0) { - psa->sendSocket = sendSocket; - } - } - - if (if_ip != NULL) { - psa->ifIpAddress = if_ip; - } else { - psa->ifIpAddress = strdup("127.0.0.1"); - - } - if (psa->verbose) { - L_INFO("[PSA_UDPMC] Using %s as interface for multicast communication", psa->ifIpAddress); - } - - - if (mc_ip != NULL) { - psa->mcIpAddress = mc_ip; - } else { - psa->mcIpAddress = strdup(PUBSUB_UDPMC_MULTICAST_IP_DEFAULT); - } - if (psa->verbose) { - L_INFO("[PSA_UDPMC] Using %s for service annunciation", psa->mcIpAddress); - } - - psa->defaultScore = celix_bundleContext_getPropertyAsDouble(ctx, PSA_UDPMC_DEFAULT_SCORE_KEY, PSA_UDPMC_DEFAULT_SCORE); - psa->qosSampleScore = celix_bundleContext_getPropertyAsDouble(ctx, PSA_UDPMC_QOS_SAMPLE_SCORE_KEY, PSA_UDPMC_DEFAULT_QOS_SAMPLE_SCORE); - psa->qosControlScore = celix_bundleContext_getPropertyAsDouble(ctx, PSA_UDPMC_QOS_CONTROL_SCORE_KEY, PSA_UDPMC_DEFAULT_QOS_CONTROL_SCORE); - - celixThreadMutex_create(&psa->serializers.mutex, NULL); - psa->serializers.map = hashMap_create(NULL, NULL, NULL, NULL); - - celixThreadMutex_create(&psa->topicSenders.mutex, NULL); - psa->topicSenders.map = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); - - celixThreadMutex_create(&psa->topicReceivers.mutex, NULL); - psa->topicReceivers.map = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); - - celixThreadMutex_create(&psa->discoveredEndpoints.mutex, NULL); - psa->discoveredEndpoints.map = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); - - return psa; -} - -void pubsub_udpmcAdmin_destroy(pubsub_udpmc_admin_t *psa) { - if (psa == NULL) { - return; - } - - //note assuming al psa register services and service tracker are removed. - - celixThreadMutex_lock(&psa->topicSenders.mutex); - hash_map_iterator_t iter = hashMapIterator_construct(psa->topicSenders.map); - while (hashMapIterator_hasNext(&iter)) { - pubsub_udpmc_topic_sender_t *sender = hashMapIterator_nextValue(&iter); - pubsub_udpmcTopicSender_destroy(sender); - } - celixThreadMutex_unlock(&psa->topicSenders.mutex); - - celixThreadMutex_lock(&psa->topicReceivers.mutex); - iter = hashMapIterator_construct(psa->topicReceivers.map); - while (hashMapIterator_hasNext(&iter)) { - pubsub_udpmc_topic_receiver_t *recv = hashMapIterator_nextValue(&iter); - pubsub_udpmcTopicReceiver_destroy(recv); - } - celixThreadMutex_unlock(&psa->topicReceivers.mutex); - - celixThreadMutex_lock(&psa->discoveredEndpoints.mutex); - iter = hashMapIterator_construct(psa->discoveredEndpoints.map); - while (hashMapIterator_hasNext(&iter)) { - celix_properties_t *ep = hashMapIterator_nextValue(&iter); - celix_properties_destroy(ep); - } - celixThreadMutex_unlock(&psa->discoveredEndpoints.mutex); - - celixThreadMutex_lock(&psa->serializers.mutex); - iter = hashMapIterator_construct(psa->serializers.map); - while (hashMapIterator_hasNext(&iter)) { - psa_udpmc_serializer_entry_t *entry = hashMapIterator_nextValue(&iter); - free(entry); - } - celixThreadMutex_unlock(&psa->serializers.mutex); - - celixThreadMutex_destroy(&psa->topicSenders.mutex); - hashMap_destroy(psa->topicSenders.map, true, false); - - celixThreadMutex_destroy(&psa->topicReceivers.mutex); - hashMap_destroy(psa->topicReceivers.map, true, false); - - celixThreadMutex_destroy(&psa->discoveredEndpoints.mutex); - hashMap_destroy(psa->discoveredEndpoints.map, false, false); - - celixThreadMutex_destroy(&psa->serializers.mutex); - hashMap_destroy(psa->serializers.map, false, false); - - free(psa->mcIpAddress); - free(psa->ifIpAddress); - free(psa); -} - -celix_status_t pubsub_udpmcAdmin_matchPublisher(void *handle, long svcRequesterBndId, const celix_filter_t *svcFilter, celix_properties_t **topicProperties, double *outScore, long *outSerializerSvcId, long *outProtocolSvcId) { - pubsub_udpmc_admin_t *psa = handle; - L_DEBUG("[PSA_UDPMC] pubsub_udpmcAdmin_matchPublisher"); - celix_status_t status = CELIX_SUCCESS; - double score = pubsubEndpoint_matchPublisher(psa->ctx, svcRequesterBndId, svcFilter->filterStr, PUBSUB_UDPMC_ADMIN_TYPE, - psa->qosSampleScore, psa->qosControlScore, psa->defaultScore, false, topicProperties, outSerializerSvcId, outProtocolSvcId); - *outScore = score; - - return status; -} - -celix_status_t pubsub_udpmcAdmin_matchSubscriber(void *handle, long svcProviderBndId, const celix_properties_t *svcProperties, celix_properties_t **topicProperties, double *outScore, long *outSerializerSvcId, long *outProtocolSvcId) { - pubsub_udpmc_admin_t *psa = handle; - L_DEBUG("[PSA_UDPMC] pubsub_udpmcAdmin_matchSubscriber"); - celix_status_t status = CELIX_SUCCESS; - double score = pubsubEndpoint_matchSubscriber(psa->ctx, svcProviderBndId, svcProperties, PUBSUB_UDPMC_ADMIN_TYPE, - psa->qosSampleScore, psa->qosControlScore, psa->defaultScore, false, topicProperties, outSerializerSvcId, outProtocolSvcId); - if (outScore != NULL) { - *outScore = score; - } - return status; -} - -celix_status_t pubsub_udpmcAdmin_matchEndpoint(void *handle, const celix_properties_t *endpoint, bool *outMatch) { - pubsub_udpmc_admin_t *psa = handle; - L_DEBUG("[PSA_UDPMC] pubsub_udpmcAdmin_matchEndpoint"); - celix_status_t status = CELIX_SUCCESS; - bool match = pubsubEndpoint_match(psa->ctx, psa->log, endpoint, PUBSUB_UDPMC_ADMIN_TYPE, false, NULL, NULL); - if (outMatch != NULL) { - *outMatch = match; - } - return status; -} - -celix_status_t pubsub_udpmcAdmin_setupTopicSender(void *handle, const char *scope, const char *topic, const celix_properties_t *topicProps, long serializerSvcId, long protocolSvcId, celix_properties_t **outPublisherEndpoint) { - pubsub_udpmc_admin_t *psa = handle; - celix_status_t status = CELIX_SUCCESS; - - //1) Create TopicSender - //2) Store TopicSender - //3) Connect existing endpoints - //4) set outPublisherEndpoint - - celix_properties_t *newEndpoint = NULL; - - char *key = pubsubEndpoint_createScopeTopicKey(scope, topic); - celixThreadMutex_lock(&psa->serializers.mutex); - celixThreadMutex_lock(&psa->topicSenders.mutex); - pubsub_udpmc_topic_sender_t *sender = hashMap_get(psa->topicSenders.map, key); - if (sender == NULL) { - psa_udpmc_serializer_entry_t *serEntry = hashMap_get(psa->serializers.map, (void*)serializerSvcId); - if (serEntry != NULL) { - sender = pubsub_udpmcTopicSender_create(psa->ctx, scope, topic, serializerSvcId, serEntry->svc, psa->sendSocket, psa->mcIpAddress, topicProps); - } - if (sender != NULL) { - const char *psaType = PSA_UDPMC_PUBSUB_ADMIN_TYPE; - const char *serType = serEntry->serType; - newEndpoint = pubsubEndpoint_create(psa->fwUUID, scope, topic, PUBSUB_PUBLISHER_ENDPOINT_TYPE, psaType, serType, NULL, NULL); - celix_properties_set(newEndpoint, PUBSUB_UDPMC_SOCKET_ADDRESS_KEY, pubsub_udpmcTopicSender_socketAddress(sender)); - celix_properties_setLong(newEndpoint, PUBSUB_UDPMC_SOCKET_PORT_KEY, pubsub_udpmcTopicSender_socketPort(sender)); - //if available also set container name - const char *cn = celix_bundleContext_getProperty(psa->ctx, "CELIX_CONTAINER_NAME", NULL); - if (cn != NULL) { - celix_properties_set(newEndpoint, "container_name", cn); - } - const char *configuredPort = celix_properties_get(topicProps, PUBSUB_UDPMC_STATIC_BIND_PORT, NULL); - celix_properties_setBool(newEndpoint, PUBSUB_UDPMC_STATIC_CONFIGURED, configuredPort != NULL); - hashMap_put(psa->topicSenders.map, key, sender); - } else { - free(key); - L_ERROR("[PSA UDPMC] Error creating a valid TopicSender. Endpoints are not valid %ld", serializerSvcId); - } - } else { - free(key); - L_ERROR("[PSA_UDPMC] Cannot setup already existing TopicSender for scope/topic %s/%s!", scope == NULL ? "(null)" : scope, topic); - } - celixThreadMutex_unlock(&psa->topicSenders.mutex); - celixThreadMutex_unlock(&psa->serializers.mutex); - - if (sender != NULL && newEndpoint != NULL) { - //TODO connect endpoints to sender, NOTE is this needed for a udpmc topic sender? - } - - if (newEndpoint != NULL && outPublisherEndpoint != NULL) { - *outPublisherEndpoint = newEndpoint; - } - - return status; -} - -celix_status_t pubsub_udpmcAdmin_teardownTopicSender(void *handle, const char *scope, const char *topic) { - pubsub_udpmc_admin_t *psa = handle; - celix_status_t status = CELIX_SUCCESS; - - //1) Find and remove TopicSender from map - //2) destroy topic sender - - char *key = pubsubEndpoint_createScopeTopicKey(scope, topic); - celixThreadMutex_lock(&psa->topicSenders.mutex); - hash_map_entry_t *entry = hashMap_getEntry(psa->topicSenders.map, key); - if (entry != NULL) { - char *mapKey = hashMapEntry_getKey(entry); - pubsub_udpmc_topic_sender_t *sender = hashMap_remove(psa->topicSenders.map, key); - free(mapKey); - //TODO disconnect endpoints to sender. note is this needed for a udpmc topic sender? - pubsub_udpmcTopicSender_destroy(sender); - } else { - L_ERROR("[PSA UDPMC] Cannot teardown TopicSender with scope/topic %s/%s. Does not exists", scope == NULL ? "(null)" : scope, topic); - } - celixThreadMutex_unlock(&psa->topicSenders.mutex); - free(key); - - return status; -} - -celix_status_t pubsub_udpmcAdmin_setupTopicReceiver(void *handle, const char *scope, const char *topic, const celix_properties_t *topicProps, long serializerSvcId, long protocolSvcId, celix_properties_t **outSubscriberEndpoint) { - pubsub_udpmc_admin_t *psa = handle; - - celix_properties_t *newEndpoint = NULL; - - char *key = pubsubEndpoint_createScopeTopicKey(scope, topic); - celixThreadMutex_lock(&psa->serializers.mutex); - celixThreadMutex_lock(&psa->topicReceivers.mutex); - pubsub_udpmc_topic_receiver_t *receiver = hashMap_get(psa->topicReceivers.map, key); - if (receiver == NULL) { - psa_udpmc_serializer_entry_t *serEntry = hashMap_get(psa->serializers.map, (void*)serializerSvcId); - if (serEntry != NULL) { - receiver = pubsub_udpmcTopicReceiver_create(psa->ctx, psa->log, scope, topic, psa->ifIpAddress, topicProps, serializerSvcId, serEntry->svc); - } - if (receiver != NULL) { - const char *psaType = PSA_UDPMC_PUBSUB_ADMIN_TYPE; - const char *serType = serEntry->serType; - newEndpoint = pubsubEndpoint_create(psa->fwUUID, scope, topic, - PUBSUB_SUBSCRIBER_ENDPOINT_TYPE, psaType, serType, NULL, NULL); - //if available also set container name - const char *cn = celix_bundleContext_getProperty(psa->ctx, "CELIX_CONTAINER_NAME", NULL); - if (cn != NULL) { - celix_properties_set(newEndpoint, "container_name", cn); - } - hashMap_put(psa->topicReceivers.map, key, receiver); - } else { - L_ERROR("[PSA UDPMC] Error creating a valid TopicReceiver. Endpoints are not valid"); - free(key); - } - } else { - free(key); - L_ERROR("[PSA_UDPMC] Cannot setup already existing TopicReceiver for scope/topic %s/%s!", scope == NULL ? "(null)" : scope, topic); - } - celixThreadMutex_unlock(&psa->topicReceivers.mutex); - celixThreadMutex_unlock(&psa->serializers.mutex); - - if (receiver != NULL && newEndpoint != NULL) { - celixThreadMutex_lock(&psa->discoveredEndpoints.mutex); - hash_map_iterator_t iter = hashMapIterator_construct(psa->discoveredEndpoints.map); - while (hashMapIterator_hasNext(&iter)) { - celix_properties_t *endpoint = hashMapIterator_nextValue(&iter); - if (pubsub_udpmcAdmin_endpointIsPublisher(endpoint) && pubsubEndpoint_matchWithTopicAndScope(endpoint, topic, scope)) { - pubsub_udpmcAdmin_connectEndpointToReceiver(psa, receiver, endpoint); - } - } - celixThreadMutex_unlock(&psa->discoveredEndpoints.mutex); - } - - if (newEndpoint != NULL && outSubscriberEndpoint != NULL) { - *outSubscriberEndpoint = newEndpoint; - } - - celix_status_t status = CELIX_SUCCESS; - return status; -} - -celix_status_t pubsub_udpmcAdmin_teardownTopicReceiver(void *handle, const char *scope, const char *topic) { - pubsub_udpmc_admin_t *psa = handle; - - char *key = pubsubEndpoint_createScopeTopicKey(scope, topic); - celixThreadMutex_lock(&psa->topicReceivers.mutex); - hash_map_entry_t *entry = hashMap_getEntry(psa->topicReceivers.map, key); - free(key); - if (entry != NULL) { - char *receiverKey = hashMapEntry_getKey(entry); - pubsub_udpmc_topic_receiver_t *receiver = hashMapEntry_getValue(entry); - hashMap_remove(psa->topicReceivers.map, receiverKey); - - free(receiverKey); - pubsub_udpmcTopicReceiver_destroy(receiver); - } - celixThreadMutex_unlock(&psa->topicReceivers.mutex); - - celix_status_t status = CELIX_SUCCESS; - return status; -} - -static celix_status_t pubsub_udpmcAdmin_connectEndpointToReceiver(pubsub_udpmc_admin_t* psa, pubsub_udpmc_topic_receiver_t *receiver, const celix_properties_t *endpoint) { - //note can be called with discoveredEndpoint.mutex lock - celix_status_t status = CELIX_SUCCESS; - - const char *sockAddress = celix_properties_get(endpoint, PUBSUB_UDPMC_SOCKET_ADDRESS_KEY, NULL); - long sockPort = celix_properties_getAsLong(endpoint, PUBSUB_UDPMC_SOCKET_PORT_KEY, -1L); - - if (sockAddress == NULL || sockPort < 0) { - L_WARN("[PSA UPDMC] Error got endpoint without udpmc socket address/port or endpoint type. Properties:"); - const char *key = NULL; - CELIX_PROPERTIES_FOR_EACH(endpoint, key) { - L_WARN("[PSA UPDMC] |- %s=%s\n", key, celix_properties_get(endpoint, key, NULL)); - } - status = CELIX_BUNDLE_EXCEPTION; - } else { - pubsub_udpmcTopicReceiver_connectTo(receiver, sockAddress, sockPort); - } - - return status; -} - -celix_status_t pubsub_udpmcAdmin_addEndpoint(void *handle, const celix_properties_t *endpoint) { - pubsub_udpmc_admin_t *psa = handle; - - if (pubsub_udpmcAdmin_endpointIsPublisher(endpoint)) { - celixThreadMutex_lock(&psa->topicReceivers.mutex); - hash_map_iterator_t iter = hashMapIterator_construct(psa->topicReceivers.map); - while (hashMapIterator_hasNext(&iter)) { - pubsub_udpmc_topic_receiver_t *receiver = hashMapIterator_nextValue(&iter); - if (pubsubEndpoint_matchWithTopicAndScope(endpoint, pubsub_udpmcTopicReceiver_topic(receiver), pubsub_udpmcTopicReceiver_scope(receiver))) { - pubsub_udpmcAdmin_connectEndpointToReceiver(psa, receiver, endpoint); - } - } - celixThreadMutex_unlock(&psa->topicReceivers.mutex); - } - - celixThreadMutex_lock(&psa->discoveredEndpoints.mutex); - celix_properties_t *cpy = celix_properties_copy(endpoint); - const char *uuid = celix_properties_get(cpy, PUBSUB_ENDPOINT_UUID, NULL); - hashMap_put(psa->discoveredEndpoints.map, (void*)uuid, cpy); - celixThreadMutex_unlock(&psa->discoveredEndpoints.mutex); - - celix_status_t status = CELIX_SUCCESS; - return status; -} - - -static celix_status_t pubsub_udpmcAdmin_disconnectEndpointFromReceiver(pubsub_udpmc_admin_t* psa, pubsub_udpmc_topic_receiver_t *receiver, const celix_properties_t *endpoint) { - //note can be called with discoveredEndpoint.mutex lock - celix_status_t status = CELIX_SUCCESS; - - const char *type = celix_properties_get(endpoint, PUBSUB_ENDPOINT_TYPE, NULL); - const char *sockAdress = celix_properties_get(endpoint, PUBSUB_UDPMC_SOCKET_ADDRESS_KEY, NULL); - long sockPort = celix_properties_getAsLong(endpoint, PUBSUB_UDPMC_SOCKET_PORT_KEY, -1L); - - if (type == NULL || sockAdress == NULL || sockPort < 0) { - L_WARN("[PSA UPDMC] Error disconnecting from endpoint without udpmc socket address/port or endpoint type."); - status = CELIX_BUNDLE_EXCEPTION; - } else { - pubsub_udpmcTopicReceiver_disconnectFrom(receiver, sockAdress, sockPort); - } - - return status; -} - -celix_status_t pubsub_udpmcAdmin_removeEndpoint(void *handle, const celix_properties_t *endpoint) { - pubsub_udpmc_admin_t *psa = handle; - - if (pubsub_udpmcAdmin_endpointIsPublisher(endpoint)) { - celixThreadMutex_lock(&psa->topicReceivers.mutex); - hash_map_iterator_t iter = hashMapIterator_construct(psa->topicReceivers.map); - while (hashMapIterator_hasNext(&iter)) { - pubsub_udpmc_topic_receiver_t *receiver = hashMapIterator_nextValue(&iter); - pubsub_udpmcAdmin_disconnectEndpointFromReceiver(psa, receiver, endpoint); - } - celixThreadMutex_unlock(&psa->topicReceivers.mutex); - } - - celixThreadMutex_lock(&psa->discoveredEndpoints.mutex); - const char *uuid = celix_properties_get(endpoint, PUBSUB_ENDPOINT_UUID, NULL); - celix_properties_t *found = hashMap_remove(psa->discoveredEndpoints.map, (void*)uuid); - celixThreadMutex_unlock(&psa->discoveredEndpoints.mutex); - - if (found != NULL) { - celix_properties_destroy(found); - } - - celix_status_t status = CELIX_SUCCESS; - return status; -} - -bool pubsub_udpmcAdmin_executeCommand(void *handle, const char *commandLine CELIX_UNUSED, FILE *out, FILE *errStream CELIX_UNUSED) { - pubsub_udpmc_admin_t *psa = handle; - - fprintf(out, "\n"); - fprintf(out, "Topic Senders:\n"); - celixThreadMutex_lock(&psa->serializers.mutex); - celixThreadMutex_lock(&psa->topicSenders.mutex); - hash_map_iterator_t iter = hashMapIterator_construct(psa->topicSenders.map); - while (hashMapIterator_hasNext(&iter)) { - pubsub_udpmc_topic_sender_t *sender = hashMapIterator_nextValue(&iter); - long serSvcId = pubsub_udpmcTopicSender_serializerSvcId(sender); - psa_udpmc_serializer_entry_t *serEntry = hashMap_get(psa->serializers.map, (void*)serSvcId); - const char *serType = serEntry == NULL ? "!Error!" : serEntry->serType; - const char *scope = pubsub_udpmcTopicSender_scope(sender); - const char *topic = pubsub_udpmcTopicSender_topic(sender); - const char *sockAddr = pubsub_udpmcTopicSender_socketAddress(sender); - long sockPort = pubsub_udpmcTopicSender_socketPort(sender); - const char *postAddr = pubsub_udpmcTopicSender_isStatic(sender) ? " (static port)" : ""; - fprintf(out, "|- Topic Sender %s/%s\n", scope == NULL ? "(null)" : scope, topic); - fprintf(out, " |- serializer type = %s\n", serType); - fprintf(out, " |- socket address = %s:%li%s\n", sockAddr, sockPort, postAddr); - } - celixThreadMutex_unlock(&psa->topicSenders.mutex); - celixThreadMutex_unlock(&psa->serializers.mutex); - - fprintf(out, "\n"); - fprintf(out, "\nTopic Receivers:\n"); - celixThreadMutex_lock(&psa->serializers.mutex); - celixThreadMutex_lock(&psa->topicReceivers.mutex); - iter = hashMapIterator_construct(psa->topicReceivers.map); - while (hashMapIterator_hasNext(&iter)) { - pubsub_udpmc_topic_receiver_t *receiver = hashMapIterator_nextValue(&iter); - long serSvcId = pubsub_udpmcTopicReceiver_serializerSvcId(receiver); - psa_udpmc_serializer_entry_t *serEntry = hashMap_get(psa->serializers.map, (void*)serSvcId); - const char *serType = serEntry == NULL ? "!Error!" : serEntry->serType; - const char *scope = pubsub_udpmcTopicReceiver_scope(receiver); - const char *topic = pubsub_udpmcTopicReceiver_topic(receiver); - celix_array_list_t *connections = celix_arrayList_create(); - pubsub_udpmcTopicReceiver_listConnections(receiver, connections); - - fprintf(out, "|- Topic Receiver %s/%s\n", scope == NULL ? "(null)" : scope, topic); - fprintf(out, " |- serializer type = %s\n", serType); - fprintf(out, " |- connections (%i):\n", celix_arrayList_size(connections)); - for (int i = 0 ; i < celix_arrayList_size(connections); ++i) { - char *conn = celix_arrayList_get(connections, i); - fprintf(out, " |- address = %s\n", conn); - free(conn); - } - celix_arrayList_destroy(connections); - } - celixThreadMutex_unlock(&psa->topicReceivers.mutex); - celixThreadMutex_unlock(&psa->serializers.mutex); - fprintf(out, "\n"); - - - return true; -} - -void pubsub_udpmcAdmin_addSerializerSvc(void *handle, void *svc, const celix_properties_t *props) { - pubsub_udpmc_admin_t *psa = handle; - - const char *serType = celix_properties_get(props, PUBSUB_SERIALIZER_TYPE_KEY, NULL); - long svcId = celix_properties_getAsLong(props, OSGI_FRAMEWORK_SERVICE_ID, -1L); - - if (serType == NULL) { - L_INFO("[PSA_UDPMC] Ignoring serializer service without %s property", PUBSUB_SERIALIZER_TYPE_KEY); - return; - } - L_WARN("[PSA_UDPM] adding serializer %s %ld", serType, svcId); - - celixThreadMutex_lock(&psa->serializers.mutex); - psa_udpmc_serializer_entry_t *entry = hashMap_get(psa->serializers.map, (void*)svcId); - if (entry == NULL) { - entry = calloc(1, sizeof(*entry)); - entry->serType = serType; - entry->svcId = svcId; - entry->svc = svc; - hashMap_put(psa->serializers.map, (void*)svcId, entry); - } - celixThreadMutex_unlock(&psa->serializers.mutex); -} - -void pubsub_udpmcAdmin_removeSerializerSvc(void *handle, void *svc, const celix_properties_t *props) { - pubsub_udpmc_admin_t *psa = handle; - long svcId = celix_properties_getAsLong(props, OSGI_FRAMEWORK_SERVICE_ID, -1L); - - //remove serializer - // 1) First find entry and - // 2) loop and destroy all topic sender using the serializer and - // 3) loop and destroy all topic receivers using the serializer - // Note that it is the responsibility of the topology manager to create new topic senders/receivers - - celixThreadMutex_lock(&psa->serializers.mutex); - psa_udpmc_serializer_entry_t *entry = hashMap_remove(psa->serializers.map, (void*)svcId); - if (entry != NULL) { - celixThreadMutex_lock(&psa->topicSenders.mutex); - hash_map_iterator_t iter = hashMapIterator_construct(psa->topicSenders.map); - while (hashMapIterator_hasNext(&iter)) { - hash_map_entry_t *senderEntry = hashMapIterator_nextEntry(&iter); - pubsub_udpmc_topic_sender_t *sender = hashMapEntry_getValue(senderEntry); - if (sender != NULL && entry->svcId == pubsub_udpmcTopicSender_serializerSvcId(sender)) { - char *key = hashMapEntry_getKey(senderEntry); - hashMapIterator_remove(&iter); - pubsub_udpmcTopicSender_destroy(sender); - free(key); - } - } - celixThreadMutex_unlock(&psa->topicSenders.mutex); - - celixThreadMutex_lock(&psa->topicReceivers.mutex); - iter = hashMapIterator_construct(psa->topicReceivers.map); - while (hashMapIterator_hasNext(&iter)) { - hash_map_entry_t *senderEntry = hashMapIterator_nextEntry(&iter); - pubsub_udpmc_topic_receiver_t *receiver = hashMapEntry_getValue(senderEntry); - if (receiver != NULL && entry->svcId == pubsub_udpmcTopicReceiver_serializerSvcId(receiver)) { - char *key = hashMapEntry_getKey(senderEntry); - hashMapIterator_remove(&iter); - pubsub_udpmcTopicReceiver_destroy(receiver); - free(key); - } - } - celixThreadMutex_unlock(&psa->topicReceivers.mutex); - - free(entry); - } - celixThreadMutex_unlock(&psa->serializers.mutex); -} - -#ifndef ANDROID -static celix_status_t udpmc_getIpAddress(const char* interface, char** ip) { - celix_status_t status = CELIX_BUNDLE_EXCEPTION; - - struct ifaddrs *ifaddr, *ifa; - char host[NI_MAXHOST]; - - if (getifaddrs(&ifaddr) != -1) - { - for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next) - { - 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 diff --git a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_admin.h b/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_admin.h deleted file mode 100644 index 14e21bb41..000000000 --- a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_admin.h +++ /dev/null @@ -1,51 +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. - */ - -#ifndef CELIX_PUBSUB_UDPMC_ADMIN_H -#define CELIX_PUBSUB_UDPMC_ADMIN_H - -#include "celix_api.h" -#include "celix_log_helper.h" -#include "pubsub_psa_udpmc_constants.h" - -typedef struct pubsub_udpmc_admin pubsub_udpmc_admin_t; - -pubsub_udpmc_admin_t* pubsub_udpmcAdmin_create(celix_bundle_context_t *ctx, celix_log_helper_t *logHelper); -void pubsub_udpmcAdmin_destroy(pubsub_udpmc_admin_t *psa); - -celix_status_t pubsub_udpmcAdmin_matchPublisher(void *handle, long svcRequesterBndId, const celix_filter_t *svcFilter, celix_properties_t **topicProperties, double *score, long *serializerSvcId, long *protocolSvcId); -celix_status_t pubsub_udpmcAdmin_matchSubscriber(void *handle, long svcProviderBndId, const celix_properties_t *svcProperties, celix_properties_t **topicProperties, double *score, long *serializerSvcId, long *protocolSvcId); -celix_status_t pubsub_udpmcAdmin_matchEndpoint(void *handle, const celix_properties_t *endpoint, bool *match); - -celix_status_t pubsub_udpmcAdmin_setupTopicSender(void *handle, const char *scope, const char *topic, const celix_properties_t *topicProperties, long serializerSvcId, long protocolSvcId, celix_properties_t **publisherEndpoint); -celix_status_t pubsub_udpmcAdmin_teardownTopicSender(void *handle, const char *scope, const char *topic); - -celix_status_t pubsub_udpmcAdmin_setupTopicReceiver(void *handle, const char *scope, const char *topic, const celix_properties_t *topicProperties, long serializerSvcId, long protocolSvcId, celix_properties_t **subscriberEndpoint); -celix_status_t pubsub_udpmcAdmin_teardownTopicReceiver(void *handle, const char *scope, const char *topic); - -void pubsub_udpmcAdmin_addSerializerSvc(void *handle, void *svc, const celix_properties_t *props); -void pubsub_udpmcAdmin_removeSerializerSvc(void *handle, void *svc, const celix_properties_t *props); - -celix_status_t pubsub_udpmcAdmin_addEndpoint(void *handle, const celix_properties_t *endpoint); -celix_status_t pubsub_udpmcAdmin_removeEndpoint(void *handle, const celix_properties_t *endpoint); - -bool pubsub_udpmcAdmin_executeCommand(void *handle, const char *commandLine, FILE *outStream, FILE *errStream); - -#endif //CELIX_PUBSUB_UDPMC_ADMIN_H - diff --git a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_common.c b/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_common.c deleted file mode 100644 index c6718d075..000000000 --- a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_common.c +++ /dev/null @@ -1,36 +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 "pubsub_udpmc_common.h" - -bool psa_udpmc_checkVersion(version_pt msgVersion, pubsub_udp_msg_header_t *hdr) { - bool check = false; - - if (msgVersion != NULL) { - int major = 0, minor = 0; - version_getMajor(msgVersion,&major); - version_getMinor(msgVersion,&minor); - - if (hdr->major == ((unsigned char) major)) { /* Different major means incompatible */ - check = (hdr->minor >= ((unsigned char) minor)); /* Compatible only if the provider has a minor equals or greater (means compatible update) */ - } - } - - return check; -} diff --git a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_common.h b/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_common.h deleted file mode 100644 index 0852ca49e..000000000 --- a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_common.h +++ /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. - */ - -#ifndef CELIX_PUBSUB_UDPMC_COMMON_H -#define CELIX_PUBSUB_UDPMC_COMMON_H - -#include - -#include "version.h" - -typedef struct pubsub_udp_msg_header { - unsigned int type; - unsigned char major; - unsigned char minor; -} pubsub_udp_msg_header_t; - - -bool psa_udpmc_checkVersion(version_pt msgVersion, pubsub_udp_msg_header_t *hdr); - - -#endif //CELIX_PUBSUB_UDPMC_COMMON_H diff --git a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_topic_receiver.c b/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_topic_receiver.c deleted file mode 100644 index a468b3eef..000000000 --- a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_topic_receiver.c +++ /dev/null @@ -1,635 +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 -#include -#include -#include -#include -#if defined(__APPLE__) -#include -#include -#include -#else -#include -#endif -#include -#include -#include -#include -#include -#include -#include "pubsub_udpmc_topic_receiver.h" -#include "pubsub_psa_udpmc_constants.h" -#include "large_udp.h" -#include "pubsub_udpmc_common.h" - -#define MAX_EVENTS 10 -#define RECV_THREAD_TIMEOUT 5 -#define UDP_BUFFER_SIZE 65535 -#define MAX_UDP_SESSIONS 16 - -#define L_DEBUG(...) \ - celix_logHelper_log(receiver->logHelper, CELIX_LOG_LEVEL_DEBUG, __VA_ARGS__) -#define L_INFO(...) \ - celix_logHelper_log(receiver->logHelper, CELIX_LOG_LEVEL_INFO, __VA_ARGS__) -#define L_WARN(...) \ - celix_logHelper_log(receiver->logHelper, CELIX_LOG_LEVEL_WARNING, __VA_ARGS__) -#define L_ERROR(...) \ - celix_logHelper_log(receiver->logHelper, CELIX_LOG_LEVEL_ERROR, __VA_ARGS__) - -struct pubsub_udpmc_topic_receiver { - celix_bundle_context_t *ctx; - celix_log_helper_t *logHelper; - long serializerSvcId; - pubsub_serializer_service_t *serializer; - char *scope; - char *topic; - char* ifIpAddress; - largeUdp_t *largeUdpHandle; - int topicEpollFd; // EPOLL filedescriptor where the sockets are registered. - - struct { - celix_thread_t thread; - celix_thread_mutex_t mutex; - bool running; - } recvThread; - - struct { - celix_thread_mutex_t mutex; - hash_map_t *map; //key = socketAddress, value = psa_udpmc_requested_connection_entry_t* - bool allConnected; //true if all requestedConnectection are connected - } requestedConnections; - - long subscriberTrackerId; - struct { - celix_thread_mutex_t mutex; - hash_map_t *map; //key = bnd id, value = psa_udpmc_subscriber_entry_t - bool allInitialized; - } subscribers; -}; - -typedef struct psa_udpmc_requested_connection_entry { - char *key; - char *socketAddress; - long socketPort; - int recvSocket; - - bool connected; - bool statically; //true if the connection is statically configured through the topic properties. -} psa_udpmc_requested_connection_entry_t; - -typedef struct psa_udpmc_subscriber_entry { - hash_map_t *msgTypes; //map from serializer svc - hash_map_t *subscriberServices; //key = servide id, value = pubsub_subscriber_t* - bool initialized; //true if the init function is called through the receive thread -} psa_udpmc_subscriber_entry_t; - -typedef struct pubsub_udp_msg { - pubsub_udp_msg_header_t header; - unsigned int payloadSize; - char payload[]; -} pubsub_udp_msg_t; - -static void pubsub_udpmcTopicReceiver_addSubscriber(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *owner); -static void pubsub_udpmcTopicReceiver_removeSubscriber(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *owner); -static void psa_udpmc_processMsg(pubsub_udpmc_topic_receiver_t *receiver, pubsub_udp_msg_t *msg); -static void* psa_udpmc_recvThread(void * data); -static void psa_udpmc_connectToAllRequestedConnections(pubsub_udpmc_topic_receiver_t *receiver); -static void psa_udpmc_initializeAllSubscribers(pubsub_udpmc_topic_receiver_t *receiver); - -pubsub_udpmc_topic_receiver_t* pubsub_udpmcTopicReceiver_create(celix_bundle_context_t *ctx, - celix_log_helper_t *logHelper, - const char *scope, - const char *topic, - const char *ifIP, - const celix_properties_t *topicProperties, - long serializerSvcId, - pubsub_serializer_service_t *serializer) { - pubsub_udpmc_topic_receiver_t *receiver = calloc(1, sizeof(*receiver)); - receiver->ctx = ctx; - receiver->logHelper = logHelper; - receiver->serializerSvcId = serializerSvcId; - receiver->serializer = serializer; - receiver->scope = scope == NULL ? NULL : strndup(scope, 1024 * 1024); - receiver->topic = strndup(topic, 1024 * 1024); - receiver->ifIpAddress = strndup(ifIP, 1024 * 1024); - receiver->recvThread.running = true; - receiver->largeUdpHandle = largeUdp_create(MAX_UDP_SESSIONS); -#if defined(__APPLE__) - receiver->topicEpollFd = kqueue(); -#else - receiver->topicEpollFd = epoll_create1(0); -#endif - celixThreadMutex_create(&receiver->subscribers.mutex, NULL); - celixThreadMutex_create(&receiver->requestedConnections.mutex, NULL); - celixThreadMutex_create(&receiver->recvThread.mutex, NULL); - - receiver->subscribers.map = hashMap_create(NULL, NULL, NULL, NULL); - receiver->subscribers.allInitialized = false; - receiver->requestedConnections.map = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); - receiver->requestedConnections.allConnected = false; - - //track subscribers - { - int size = snprintf(NULL, 0, "(%s=%s)", PUBSUB_SUBSCRIBER_TOPIC, topic); - char buf[size+1]; - snprintf(buf, (size_t)size+1, "(%s=%s)", PUBSUB_SUBSCRIBER_TOPIC, topic); - celix_service_tracking_options_t opts = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS; - opts.filter.ignoreServiceLanguage = true; - opts.filter.serviceName = PUBSUB_SUBSCRIBER_SERVICE_NAME; - opts.filter.filter = buf; - opts.callbackHandle = receiver; - opts.addWithOwner = pubsub_udpmcTopicReceiver_addSubscriber; - opts.removeWithOwner = pubsub_udpmcTopicReceiver_removeSubscriber; - - receiver->subscriberTrackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts); - } - - const char *staticConnects = pubsub_getEnvironmentVariableWithScopeTopic(ctx, PUBSUB_UDPMC_STATIC_CONNECT_URLS_FOR, topic, scope); - if(staticConnects == NULL) { - staticConnects = celix_properties_get(topicProperties, PUBSUB_UDPMC_STATIC_CONNECT_SOCKET_ADDRESSES, NULL); - } - if (staticConnects != NULL) { - char *copy = strndup(staticConnects, 1024*1024); - char* addr; - char* save = copy; - - while ((addr = strtok_r(save, " ", &save))) { - char *colon = strchr(addr, ':'); - if (colon == NULL) { - continue; - } - - char *sockAddr = NULL; - asprintf(&sockAddr, "%.*s", (int)(colon - addr), addr); - - long sockPort = atol((colon + 1)); - - char *key = NULL; - asprintf(&key, "%s:%li", sockAddr, sockPort); - - - if (sockPort > 0) { - psa_udpmc_requested_connection_entry_t *entry = calloc(1, sizeof(*entry)); - entry->key = key; - entry->socketAddress = sockAddr; - entry->socketPort = sockPort; - entry->connected = false; - entry->statically = true; - hashMap_put(receiver->requestedConnections.map, (void *) entry->key, entry); - } else { - L_WARN("[PSA_UDPMC_TR] Invalid static socket address %s", addr); - free(key); - free(sockAddr); - } - } - free(copy); - } - - celixThread_create(&receiver->recvThread.thread, NULL, psa_udpmc_recvThread, receiver); - - return receiver; -} - -void pubsub_udpmcTopicReceiver_destroy(pubsub_udpmc_topic_receiver_t *receiver) { - if (receiver != NULL) { - celix_bundleContext_stopTracker(receiver->ctx, receiver->subscriberTrackerId); - - celixThreadMutex_lock(&receiver->recvThread.mutex); - receiver->recvThread.running = false; - celixThreadMutex_unlock(&receiver->recvThread.mutex); - celixThread_join(receiver->recvThread.thread, NULL); - - celixThreadMutex_lock(&receiver->requestedConnections.mutex); - hash_map_iterator_t iter = hashMapIterator_construct(receiver->requestedConnections.map); - while (hashMapIterator_hasNext(&iter)) { - psa_udpmc_requested_connection_entry_t *entry = hashMapIterator_nextValue(&iter); - if (entry != NULL) { - free(entry->socketAddress); - free(entry->key); - free(entry); - } - } - celixThreadMutex_unlock(&receiver->requestedConnections.mutex); - hashMap_destroy(receiver->requestedConnections.map, false, false); - - celixThreadMutex_lock(&receiver->subscribers.mutex); - iter = hashMapIterator_construct(receiver->subscribers.map); - while (hashMapIterator_hasNext(&iter)) { - psa_udpmc_subscriber_entry_t *entry = hashMapIterator_nextValue(&iter); - if (entry != NULL) { - if (receiver->serializer != NULL && entry->msgTypes != NULL) { - receiver->serializer->destroySerializerMap(receiver->serializer->handle, entry->msgTypes); - } - hashMap_destroy(entry->subscriberServices, false, false); - free(entry); - } - } - celixThreadMutex_unlock(&receiver->subscribers.mutex); - hashMap_destroy(receiver->subscribers.map, false, false); - - - - celixThreadMutex_destroy(&receiver->subscribers.mutex); - celixThreadMutex_destroy(&receiver->requestedConnections.mutex); - celixThreadMutex_destroy(&receiver->recvThread.mutex); - - largeUdp_destroy(receiver->largeUdpHandle); - - free(receiver->scope); - free(receiver->topic); - free(receiver->ifIpAddress); - } - free(receiver); -} - -const char* pubsub_udpmcTopicReceiver_scope(pubsub_udpmc_topic_receiver_t *receiver) { - return receiver->scope; -} -const char* pubsub_udpmcTopicReceiver_topic(pubsub_udpmc_topic_receiver_t *receiver) { - return receiver->topic; -} - -long pubsub_udpmcTopicReceiver_serializerSvcId(pubsub_udpmc_topic_receiver_t *receiver) { - return receiver->serializerSvcId; -} - -void pubsub_udpmcTopicReceiver_connectTo(pubsub_udpmc_topic_receiver_t *receiver, const char *socketAddress, long socketPort) { - printf("[PSA UDPMC] TopicReceiver %s/%s connect to socket address = %s:%li\n", receiver->scope == NULL ? "(null)" : receiver->scope, receiver->topic, socketAddress, socketPort); - - char *key = NULL; - asprintf(&key, "%s:%li", socketAddress, socketPort); - - celixThreadMutex_lock(&receiver->requestedConnections.mutex); - psa_udpmc_requested_connection_entry_t *entry = hashMap_get(receiver->requestedConnections.map, key); - if (entry == NULL) { - entry = calloc(1, sizeof(*entry)); - entry->key = key; - entry->socketAddress = strndup(socketAddress, 1024 * 1024); - entry->socketPort = socketPort; - entry->connected = false; - entry->statically = false; - hashMap_put(receiver->requestedConnections.map, (void*)entry->key, entry); - receiver->requestedConnections.allConnected = false; - } else { - free(key); - } - celixThreadMutex_unlock(&receiver->requestedConnections.mutex); - - psa_udpmc_connectToAllRequestedConnections(receiver); -} - -void pubsub_udpmcTopicReceiver_disconnectFrom(pubsub_udpmc_topic_receiver_t *receiver, const char *socketAddress, long socketPort) { - printf("[PSA UDPMC] TopicReceiver %s/%s disconnect from socket address = %s:%li\n", receiver->scope == NULL ? "(null)" : receiver->scope, receiver->topic, socketAddress, socketPort); - - int len = snprintf(NULL, 0, "%s:%li", socketAddress, socketPort); - char *key = calloc((size_t)len+1, sizeof(char)); - snprintf(key, (size_t)len+1, "%s:%li", socketAddress, socketPort); - - celixThreadMutex_lock(&receiver->requestedConnections.mutex); - psa_udpmc_requested_connection_entry_t *entry = hashMap_remove(receiver->requestedConnections.map, key); - free(key); - if (entry != NULL && entry->connected) { -#if defined(__APPLE__) - struct kevent ev; - EV_SET (&ev, entry->recvSocket, EVFILT_READ, EV_DELETE, 0, 0, 0); - int rc = kevent (receiver->topicEpollFd, &ev, 1, NULL, 0, NULL); -#else - struct epoll_event ev; - memset(&ev, 0, sizeof(ev)); - int rc = epoll_ctl(receiver->topicEpollFd, EPOLL_CTL_DEL, entry->recvSocket, &ev); -#endif - if (rc < 0) { - fprintf(stderr, "[PSA UDPMC] Error disconnecting TopicReceiver %s/%s to %s:%li.\n%s", receiver->scope == NULL ? "(null)" : receiver->scope, receiver->topic, socketAddress, socketPort, strerror(errno)); - } - } - if (entry != NULL) { - free(entry->key); - free(entry->socketAddress); - free(entry); - } - celixThreadMutex_unlock(&receiver->requestedConnections.mutex); -} - -static void pubsub_udpmcTopicReceiver_addSubscriber(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *bnd) { - pubsub_udpmc_topic_receiver_t *receiver = handle; - - long bndId = celix_bundle_getId(bnd); - long svcId = celix_properties_getAsLong(props, OSGI_FRAMEWORK_SERVICE_ID, -1); - const char *subScope = celix_properties_get(props, PUBSUB_SUBSCRIBER_SCOPE, NULL); - if (receiver->scope == NULL) { - if (subScope != NULL) { - return; - } - } else if (subScope != NULL) { - if (strncmp(subScope, receiver->scope, strlen(receiver->scope)) != 0) { - //not the same scope. ignore - return; - } - } else { - //receiver scope is not NULL, but subScope is NULL -> ignore - return; - } - - celixThreadMutex_lock(&receiver->subscribers.mutex); - psa_udpmc_subscriber_entry_t *entry = hashMap_get(receiver->subscribers.map, (void*)bndId); - if (entry != NULL) { - hashMap_put(entry->subscriberServices, (void*)svcId, svc); - } else { - //new create entry - entry = calloc(1, sizeof(*entry)); - entry->subscriberServices = hashMap_create(NULL, NULL, NULL, NULL); - entry->initialized = false; - receiver->subscribers.allInitialized = false; - hashMap_put(entry->subscriberServices, (void*)svcId, svc); - - int rc = receiver->serializer->createSerializerMap(receiver->serializer->handle, (celix_bundle_t*)bnd, &entry->msgTypes); - if (rc == 0) { - hashMap_put(receiver->subscribers.map, (void*)bndId, entry); - } else { - free(entry); - fprintf(stderr, "Cannot find serializer for TopicReceiver %s/%s", receiver->scope == NULL ? "(null)" : receiver->scope, receiver->topic); - } - } - celixThreadMutex_unlock(&receiver->subscribers.mutex); -} - -static void pubsub_udpmcTopicReceiver_removeSubscriber(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *bnd) { - pubsub_udpmc_topic_receiver_t *receiver = handle; - - long bndId = celix_bundle_getId(bnd); - long svcId = celix_properties_getAsLong(props, OSGI_FRAMEWORK_SERVICE_ID, -1); - - celixThreadMutex_lock(&receiver->subscribers.mutex); - psa_udpmc_subscriber_entry_t *entry = hashMap_get(receiver->subscribers.map, (void*)bndId); - if (entry != NULL) { - hashMap_remove(entry->subscriberServices, (void*)svcId); - } - if (entry != NULL && hashMap_size(entry->subscriberServices) == 0) { - //remove entry - hashMap_remove(receiver->subscribers.map, (void*)bndId); - int rc = receiver->serializer->destroySerializerMap(receiver->serializer->handle, entry->msgTypes); - if (rc != 0) { - fprintf(stderr, "Cannot find serializer for TopicReceiver %s/%s", receiver->scope == NULL ? "(null)" : receiver->scope, receiver->topic); - } - hashMap_destroy(entry->subscriberServices, false, false); - free(entry); - } - celixThreadMutex_unlock(&receiver->subscribers.mutex); -} - -static void* psa_udpmc_recvThread(void * data) { - pubsub_udpmc_topic_receiver_t *receiver = data; - - celixThreadMutex_lock(&receiver->recvThread.mutex); - bool running = receiver->recvThread.running; - celixThreadMutex_unlock(&receiver->recvThread.mutex); - - celixThreadMutex_lock(&receiver->requestedConnections.mutex); - bool allConnected = receiver->requestedConnections.allConnected; - celixThreadMutex_unlock(&receiver->requestedConnections.mutex); - - celixThreadMutex_lock(&receiver->subscribers.mutex); - bool allInitialized = receiver->subscribers.allInitialized; - celixThreadMutex_unlock(&receiver->subscribers.mutex); - - while (running) { - if (!allConnected) { - psa_udpmc_connectToAllRequestedConnections(receiver); - } - if (!allInitialized) { - psa_udpmc_initializeAllSubscribers(receiver); - } - - unsigned int timeout = RECV_THREAD_TIMEOUT * 1000; -#if defined(__APPLE__) - struct kevent events[MAX_EVENTS]; - struct timespec ts = {timeout / 1000, (timeout % 1000) * 1000000}; - int nfds = kevent (receiver->topicEpollFd, NULL, 0, &events[0], MAX_EVENTS, timeout ? &ts : NULL); -#else - struct epoll_event events[MAX_EVENTS]; - int nfds = epoll_wait(receiver->topicEpollFd, events, MAX_EVENTS, timeout); -#endif - int i; - for (i = 0; i < nfds; i++ ) { - unsigned int index; - unsigned int size; -#if defined(__APPLE__) - int fd = events[i].ident; -#else - int fd = events[i].data.fd; -#endif - if (largeUdp_dataAvailable(receiver->largeUdpHandle, fd, &index, &size) == true) { - // Handle data - pubsub_udp_msg_t *udpMsg = NULL; - if (largeUdp_read(receiver->largeUdpHandle, index, (void**) &udpMsg, size) != 0) { - printf("[PSA_UDPMC]: ERROR largeUdp_read with index %d\n", index); - continue; - } - - psa_udpmc_processMsg(receiver, udpMsg); - - free(udpMsg); - } - } - - celixThreadMutex_lock(&receiver->recvThread.mutex); - running = receiver->recvThread.running; - celixThreadMutex_unlock(&receiver->recvThread.mutex); - - celixThreadMutex_lock(&receiver->requestedConnections.mutex); - allConnected = receiver->requestedConnections.allConnected; - celixThreadMutex_unlock(&receiver->requestedConnections.mutex); - - celixThreadMutex_lock(&receiver->subscribers.mutex); - allInitialized = receiver->subscribers.allInitialized; - celixThreadMutex_unlock(&receiver->subscribers.mutex); - } - - return NULL; -} - -static void psa_udpmc_processMsg(pubsub_udpmc_topic_receiver_t *receiver, pubsub_udp_msg_t *msg) { - celixThreadMutex_lock(&receiver->subscribers.mutex); - hash_map_iterator_t iter = hashMapIterator_construct(receiver->subscribers.map); - while (hashMapIterator_hasNext(&iter)) { - psa_udpmc_subscriber_entry_t *entry = hashMapIterator_nextValue(&iter); - - pubsub_msg_serializer_t *msgSer = NULL; - if (entry->msgTypes != NULL) { - msgSer = hashMap_get(entry->msgTypes, (void *) (uintptr_t) msg->header.type); - } - if (msgSer == NULL) { - L_WARN("[PSA_UDPMC] Serializer not available for message %d.\n", msg->header.type); - } else { - void *msgInst = NULL; - bool validVersion = psa_udpmc_checkVersion(msgSer->msgVersion, &msg->header); - - if (validVersion) { - struct iovec deSerializeBuffer; - deSerializeBuffer.iov_base = msg->payload; - deSerializeBuffer.iov_len = msg->payloadSize; - celix_status_t status = msgSer->deserialize(msgSer->handle, &deSerializeBuffer, 0, &msgInst); - - if (status == CELIX_SUCCESS) { - hash_map_iterator_t iter2 = hashMapIterator_construct(entry->subscriberServices); - bool release = true; - while (hashMapIterator_hasNext(&iter2)) { - pubsub_subscriber_t *svc = hashMapIterator_nextValue(&iter2); - svc->receive(svc->handle, msgSer->msgName, msg->header.type, msgInst, NULL, &release); - if (!release && hashMapIterator_hasNext(&iter2)) { - //receive function has taken ownership and still more receive function to come .. - //deserialize again for new message - status = msgSer->deserialize(msgSer->handle, &deSerializeBuffer, 0, &msgInst); - if (status != CELIX_SUCCESS) { - L_WARN("[PSA_UDPMC] Cannot deserialize msgType %s.\n",msgSer->msgName); - break; - } - release = true; - } - } - if (release) { - msgSer->freeDeserializeMsg(msgSer->handle, msgInst); - } - } else { - L_WARN("[PSA_UDPMC] Cannot deserialize msgType %s.\n",msgSer->msgName); - } - - } else { - int major = 0, minor = 0; - version_getMajor(msgSer->msgVersion, &major); - version_getMinor(msgSer->msgVersion, &minor); - L_WARN("[PSA_UDPMC] Version mismatch for primary message '%s' (have %d.%d, received %u.%u). NOT sending any part of the whole message.\n", - msgSer->msgName,major,minor,msg->header.major,msg->header.minor); - } - - } - } - celixThreadMutex_unlock(&receiver->subscribers.mutex); -} - -void pubsub_udpmcTopicReceiver_listConnections(pubsub_udpmc_topic_receiver_t *receiver, celix_array_list_t *connections) { - celixThreadMutex_lock(&receiver->requestedConnections.mutex); - hash_map_iterator_t iter = hashMapIterator_construct(receiver->requestedConnections.map); - while (hashMapIterator_hasNext(&iter)) { - psa_udpmc_requested_connection_entry_t *entry = hashMapIterator_nextValue(&iter); - char *url = NULL; - const char *post = entry->statically ? " (static)" : ""; - asprintf(&url, "%s:%li%s", entry->socketAddress, entry->socketPort, post); - celix_arrayList_add(connections, url); - } - celixThreadMutex_unlock(&receiver->requestedConnections.mutex); -} - -static bool psa_udpmc_connectToEntry(pubsub_udpmc_topic_receiver_t *receiver, psa_udpmc_requested_connection_entry_t *entry) { - bool connected = true; - int rc = 0; - entry->recvSocket = socket(AF_INET, SOCK_DGRAM, 0); - if (entry->recvSocket >= 0) { - int reuse = 1; - rc = setsockopt(entry->recvSocket, SOL_SOCKET, SO_REUSEADDR, (char*) &reuse, sizeof(reuse)); - } - if (entry->recvSocket >= 0 && rc >= 0) { - struct ip_mreq mc_addr; - mc_addr.imr_multiaddr.s_addr = inet_addr(entry->socketAddress); - mc_addr.imr_interface.s_addr = inet_addr(receiver->ifIpAddress); - L_INFO("[PSA_UDPMC_TR] Add MC %s at interface %s\n", entry->socketAddress, receiver->ifIpAddress); - rc = setsockopt(entry->recvSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mc_addr, sizeof(mc_addr)); - } - if (entry->recvSocket >= 0 && rc >= 0) { - struct sockaddr_in mcListenAddr; - mcListenAddr.sin_family = AF_INET; - mcListenAddr.sin_addr.s_addr = INADDR_ANY; - mcListenAddr.sin_port = htons((uint16_t )entry->socketPort); - rc = bind(entry->recvSocket, (struct sockaddr*)&mcListenAddr, sizeof(mcListenAddr)); - } - if (entry->recvSocket >= 0 && rc >= 0) { -#if defined(__APPLE__) - struct kevent ev; - EV_SET (&ev, entry->recvSocket, EVFILT_READ, EV_ADD | EV_ENABLE , 0, 0, 0); - rc = kevent (receiver->topicEpollFd, &ev, 1, NULL, 0, NULL); -#else - struct epoll_event ev; - memset(&ev, 0, sizeof(ev)); - ev.events = EPOLLIN; - ev.data.fd = entry->recvSocket; - rc = epoll_ctl(receiver->topicEpollFd, EPOLL_CTL_ADD, entry->recvSocket, &ev); -#endif - } - - if (entry->recvSocket < 0 || rc < 0) { - L_WARN("[PSA UDPMC] Error connecting TopicReceiver %s/%s to %s:%li. (%s)\n", receiver->scope == NULL ? "(null)" : receiver->scope, receiver->topic, entry->socketAddress, entry->socketPort, strerror(errno)); - connected = false; - } - return connected; -} - - -static void psa_udpmc_connectToAllRequestedConnections(pubsub_udpmc_topic_receiver_t *receiver) { - celixThreadMutex_lock(&receiver->requestedConnections.mutex); - if (!receiver->requestedConnections.allConnected) { - bool allConnected = true; - hash_map_iterator_t iter = hashMapIterator_construct(receiver->requestedConnections.map); - while (hashMapIterator_hasNext(&iter)) { - psa_udpmc_requested_connection_entry_t *entry = hashMapIterator_nextValue(&iter); - if (!entry->connected) { - if (psa_udpmc_connectToEntry(receiver, entry)) { - entry->connected = true; - } else { - L_WARN("[PSA_UDPMC_TR] Error connecting to address %s. (%s)", entry->socketAddress, strerror(errno)); - allConnected = false; - } - } - } - receiver->requestedConnections.allConnected = allConnected; - } - celixThreadMutex_unlock(&receiver->requestedConnections.mutex); -} - -static void psa_udpmc_initializeAllSubscribers(pubsub_udpmc_topic_receiver_t *receiver) { - celixThreadMutex_lock(&receiver->subscribers.mutex); - if (!receiver->subscribers.allInitialized) { - bool allInitialized = true; - hash_map_iterator_t iter = hashMapIterator_construct(receiver->subscribers.map); - while (hashMapIterator_hasNext(&iter)) { - psa_udpmc_subscriber_entry_t *entry = hashMapIterator_nextValue(&iter); - if (!entry->initialized) { - - hash_map_iterator_t iter2 = hashMapIterator_construct(entry->subscriberServices); - while (hashMapIterator_hasNext(&iter2)) { - pubsub_subscriber_t *svc = hashMapIterator_nextValue(&iter2); - int rc = 0; - if (svc != NULL && svc->init != NULL) { - rc = svc->init(svc->handle); - } - if (rc == 0) { - //note now only initialized on first subscriber entries added. - entry->initialized = true; - } else { - L_WARN("Cannot initialize subscriber svc. Got rc %i", rc); - allInitialized = false; - } - } - } - } - receiver->subscribers.allInitialized = allInitialized; - } - celixThreadMutex_unlock(&receiver->subscribers.mutex); -} \ No newline at end of file diff --git a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_topic_receiver.h b/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_topic_receiver.h deleted file mode 100644 index c2c2f3bfe..000000000 --- a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_topic_receiver.h +++ /dev/null @@ -1,49 +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. - */ - -#ifndef CELIX_PUBSUB_UDPMC_TOPIC_RECEIVER_H -#define CELIX_PUBSUB_UDPMC_TOPIC_RECEIVER_H - -#include "celix_bundle_context.h" -#include "pubsub_serializer.h" -#include "celix_log_helper.h" - -typedef struct pubsub_udpmc_topic_receiver pubsub_udpmc_topic_receiver_t; - -pubsub_udpmc_topic_receiver_t* pubsub_udpmcTopicReceiver_create(celix_bundle_context_t *ctx, - celix_log_helper_t *logHelper, - const char *scope, - const char *topic, - const char *ifIP, - const celix_properties_t *topicProperties, - long serializerSvcId, - pubsub_serializer_service_t *serializer); -void pubsub_udpmcTopicReceiver_destroy(pubsub_udpmc_topic_receiver_t *receiver); - -const char* pubsub_udpmcTopicReceiver_scope(pubsub_udpmc_topic_receiver_t *receiver); -const char* pubsub_udpmcTopicReceiver_topic(pubsub_udpmc_topic_receiver_t *receiver); -const char* pubsub_udpmcTopicReceiver_socketAddress(pubsub_udpmc_topic_receiver_t *receiver); -void pubsub_udpmcTopicReceiver_listConnections(pubsub_udpmc_topic_receiver_t *receiver, celix_array_list_t *connections); - -long pubsub_udpmcTopicReceiver_serializerSvcId(pubsub_udpmc_topic_receiver_t *receiver); - -void pubsub_udpmcTopicReceiver_connectTo(pubsub_udpmc_topic_receiver_t *receiver, const char *socketAddress, long socketPort); -void pubsub_udpmcTopicReceiver_disconnectFrom(pubsub_udpmc_topic_receiver_t *receiver, const char *socketAddress, long socketPort); - -#endif //CELIX_PUBSUB_UDPMC_TOPIC_RECEIVER_H diff --git a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_topic_sender.c b/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_topic_sender.c deleted file mode 100644 index 4197562ce..000000000 --- a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_topic_sender.c +++ /dev/null @@ -1,368 +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 -#include -#include -#include -#include -#include -#include -#include -#include -#include "pubsub_udpmc_topic_sender.h" -#include "pubsub_psa_udpmc_constants.h" -#include "large_udp.h" -#include "pubsub_udpmc_common.h" -#include "celix_compiler.h" - -#define FIRST_SEND_DELAY_IN_SECONDS 2 - -//TODO make configurable -#define UDP_BASE_PORT 49152 -#define UDP_MAX_PORT 65000 - - -struct pubsub_udpmc_topic_sender { - celix_bundle_context_t *ctx; - long serializerSvcId; - pubsub_serializer_service_t *serializer; - char *scope; - char *topic; - char *socketAddress; - long socketPort; - bool staticallyConfigured; - - int sendSocket; - struct sockaddr_in destAddr; - - struct { - long svcId; - celix_service_factory_t factory; - } publisher; - - struct { - celix_thread_mutex_t mutex; - hash_map_t *map; //key = bndId, value = psa_udpmc_bounded_service_entry_t - } boundedServices; -}; - -typedef struct psa_udpmc_bounded_service_entry { - pubsub_udpmc_topic_sender_t *parent; - pubsub_publisher_t service; - long bndId; - hash_map_t *msgTypes; - hash_map_t *msgTypeIds; - int getCount; - largeUdp_t *largeUdpHandle; -} psa_udpmc_bounded_service_entry_t; - -typedef struct pubsub_msg { - pubsub_udp_msg_header_t *header; - unsigned int payloadSize; - char *payload; -} pubsub_udp_msg_t; - -static int psa_udpmc_localMsgTypeIdForMsgType(void* handle, const char* msgType, unsigned int* msgTypeId); -static void* psa_udpmc_getPublisherService(void *handle, const celix_bundle_t *requestingBundle, const celix_properties_t *svcProperties); -static void psa_udpmc_ungetPublisherService(void *handle, const celix_bundle_t *requestingBundle, const celix_properties_t *svcProperties); -static int psa_udpmc_topicPublicationSend(void* handle, unsigned int msgTypeId, const void *inMsg, celix_properties_t *metadata); -static bool psa_udpmc_sendMsg(psa_udpmc_bounded_service_entry_t *entry, pubsub_udp_msg_t* msg); -static unsigned int rand_range(unsigned int min, unsigned int max); - -pubsub_udpmc_topic_sender_t* pubsub_udpmcTopicSender_create( - celix_bundle_context_t *ctx, - const char *scope, - const char *topic, - long serializerSvcId, - pubsub_serializer_service_t *serializer, - int sendSocket, - const char *bindIP, - const celix_properties_t *topicProperties) { - pubsub_udpmc_topic_sender_t *sender = calloc(1, sizeof(*sender)); - sender->ctx = ctx; - sender->serializerSvcId = serializerSvcId; - sender->serializer = serializer; - sender->scope = scope == NULL ? NULL : strndup(scope, 1024 * 1024); - sender->topic = strndup(topic, 1024 * 1024); - - celixThreadMutex_create(&sender->boundedServices.mutex, NULL); - sender->boundedServices.map = hashMap_create(NULL, NULL, NULL, NULL); - - unsigned int port = rand_range(UDP_BASE_PORT, UDP_MAX_PORT); - - const char *portEnvVar = pubsub_getEnvironmentVariableWithScopeTopic(ctx, PUBSUB_UDPMC_STATIC_BIND_PORT_URL_FOR, topic, scope); - long configuredPort = -1; - if(portEnvVar != NULL) { - char *endptr = NULL; - long p = strtol(portEnvVar, &endptr, 10); - if(endptr != portEnvVar && errno != ERANGE && p >= 0 && p <= 65535) { - configuredPort = p; - } - } - - if(configuredPort == -1) { - configuredPort = celix_properties_getAsLong(topicProperties, PUBSUB_UDPMC_STATIC_BIND_PORT, -1L); - } - - if (configuredPort > 0) { - port = (unsigned int)configuredPort; - sender->staticallyConfigured = true; - } else { - sender->staticallyConfigured = false; - } - - //setting up socket for UDPMC TopicSender - { - sender->sendSocket = sendSocket; - sender->destAddr.sin_family = AF_INET; - sender->destAddr.sin_addr.s_addr = inet_addr(bindIP); - sender->destAddr.sin_port = htons((uint16_t)port); - - sender->socketAddress = strndup(bindIP, 1024); - sender->socketPort = port; - } - - //register publisher services using a service factory - { - sender->publisher.factory.handle = sender; - sender->publisher.factory.getService = psa_udpmc_getPublisherService; - sender->publisher.factory.ungetService = psa_udpmc_ungetPublisherService; - - - //register publisher factory service - { - celix_properties_t *props = celix_properties_create(); - celix_properties_set(props, PUBSUB_PUBLISHER_TOPIC, sender->topic); - if (sender->scope != NULL) { - celix_properties_set(props, PUBSUB_PUBLISHER_SCOPE, sender->scope); - } - - celix_service_registration_options_t opts = CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS; - opts.factory = &sender->publisher.factory; - opts.serviceName = PUBSUB_PUBLISHER_SERVICE_NAME; - opts.serviceVersion = PUBSUB_PUBLISHER_SERVICE_VERSION; - opts.properties = props; - - sender->publisher.svcId = celix_bundleContext_registerServiceWithOptions(ctx, &opts); - } - } - - return sender; -} - -void pubsub_udpmcTopicSender_destroy(pubsub_udpmc_topic_sender_t *sender) { - if (sender != NULL) { - celix_bundleContext_unregisterService(sender->ctx, sender->publisher.svcId); - - celixThreadMutex_destroy(&sender->boundedServices.mutex); - - //TODO loop and cleanup? - hashMap_destroy(sender->boundedServices.map, false, true); - - if (sender->scope != NULL) { - free(sender->scope); - } - free(sender->topic); - free(sender->socketAddress); - free(sender); - } -} - -const char* pubsub_udpmcTopicSender_psaType(pubsub_udpmc_topic_sender_t *sender CELIX_UNUSED) { - return PSA_UDPMC_PUBSUB_ADMIN_TYPE; -} - - -const char* pubsub_udpmcTopicSender_scope(pubsub_udpmc_topic_sender_t *sender) { - return sender->scope; -} - -const char* pubsub_udpmcTopicSender_topic(pubsub_udpmc_topic_sender_t *sender) { - return sender->topic; -} - -const char* pubsub_udpmcTopicSender_socketAddress(pubsub_udpmc_topic_sender_t *sender) { - return sender->socketAddress; -} - -long pubsub_udpmcTopicSender_socketPort(pubsub_udpmc_topic_sender_t *sender) { - return sender->socketPort; -} - -void pubsub_udpmcTopicSender_connectTo(pubsub_udpmc_topic_sender_t *sender, const celix_properties_t *endpoint) { - //TODO subscriber count -> topic info -} - -void pubsub_udpmcTopicSender_disconnectFrom(pubsub_udpmc_topic_sender_t *sender, const celix_properties_t *endpoint) { - //TODO -} - -static int psa_udpmc_localMsgTypeIdForMsgType(void *handle, const char *msgType, unsigned int *msgTypeId) { - psa_udpmc_bounded_service_entry_t *entry = (psa_udpmc_bounded_service_entry_t *) handle; - *msgTypeId = (unsigned int)(uintptr_t) hashMap_get(entry->msgTypeIds, msgType); - return 0; -} - -static void* psa_udpmc_getPublisherService(void *handle, const celix_bundle_t *requestingBundle, const celix_properties_t *svcProperties CELIX_UNUSED) { - pubsub_udpmc_topic_sender_t *sender = handle; - long bndId = celix_bundle_getId(requestingBundle); - - pubsub_publisher_t *svc = NULL; - - celixThreadMutex_lock(&sender->boundedServices.mutex); - psa_udpmc_bounded_service_entry_t *entry = hashMap_get(sender->boundedServices.map, (void*)bndId); - if (entry != NULL) { - entry->getCount += 1; - } else { - entry = calloc(1, sizeof(*entry)); - entry->getCount = 1; - entry->parent = sender; - entry->bndId = bndId; - entry->largeUdpHandle = largeUdp_create(1); - entry->msgTypeIds = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); - - int rc = sender->serializer->createSerializerMap(sender->serializer->handle, (celix_bundle_t*)requestingBundle, &entry->msgTypes); - if (rc == 0) { - hash_map_iterator_t iter = hashMapIterator_construct(entry->msgTypes); - while (hashMapIterator_hasNext(&iter)) { - pubsub_msg_serializer_t *msgSer = hashMapIterator_nextValue(&iter); - hashMap_put(entry->msgTypeIds, strndup(msgSer->msgName, 1024), (void *)(uintptr_t) msgSer->msgId); - } - - entry->service.handle = entry; - entry->service.localMsgTypeIdForMsgType = psa_udpmc_localMsgTypeIdForMsgType; - entry->service.send = psa_udpmc_topicPublicationSend; - hashMap_put(sender->boundedServices.map, (void*)bndId, entry); - svc = &entry->service; - } else { - fprintf(stderr, "Error creating publisher service, serializer not available / cannot get msg serializer map\n"); - free(entry); - } - } - celixThreadMutex_unlock(&sender->boundedServices.mutex); - - return svc; -} - -static void psa_udpmc_ungetPublisherService(void *handle, const celix_bundle_t *requestingBundle, const celix_properties_t *svcProperties CELIX_UNUSED) { - pubsub_udpmc_topic_sender_t *sender = handle; - long bndId = celix_bundle_getId(requestingBundle); - - celixThreadMutex_lock(&sender->boundedServices.mutex); - psa_udpmc_bounded_service_entry_t *entry = hashMap_get(sender->boundedServices.map, (void*)bndId); - if (entry != NULL) { - entry->getCount -= 1; - } - if (entry != NULL && entry->getCount == 0) { - //free entry - hashMap_remove(sender->boundedServices.map, (void*)bndId); - - int rc = sender->serializer->destroySerializerMap(sender->serializer->handle, entry->msgTypes); - if (rc != 0) { - fprintf(stderr, "Error destroying publisher service, serializer not available / cannot get msg serializer map\n"); - } - - hashMap_destroy(entry->msgTypeIds, true, false); - largeUdp_destroy(entry->largeUdpHandle); - free(entry); - } - celixThreadMutex_unlock(&sender->boundedServices.mutex); -} - -static int psa_udpmc_topicPublicationSend(void* handle, unsigned int msgTypeId, const void *inMsg, celix_properties_t *metadata) { - psa_udpmc_bounded_service_entry_t *entry = handle; - int status = 0; - - pubsub_msg_serializer_t* msgSer = NULL; - if (entry->msgTypes != NULL) { - msgSer = hashMap_get(entry->msgTypes, (void*)(intptr_t)(msgTypeId)); - } - - if (msgSer != NULL) { - size_t serializedOutputLen = 0; - struct iovec* serializedOutput = NULL; - if (msgSer->serialize(msgSer->handle, inMsg, &serializedOutput, &serializedOutputLen) == CELIX_SUCCESS) { - pubsub_udp_msg_header_t *msg_hdr = calloc(1, sizeof(*msg_hdr)); - msg_hdr->type = msgTypeId; - - if (msgSer->msgVersion != NULL) { - int major = 0, minor = 0; - version_getMajor(msgSer->msgVersion, &major); - version_getMinor(msgSer->msgVersion, &minor); - msg_hdr->major = (unsigned char) major; - msg_hdr->minor = (unsigned char) minor; - } - - pubsub_udp_msg_t *msg = calloc(1, sizeof(*msg)); - msg->header = msg_hdr; - msg->payload = (char *) serializedOutput->iov_base; - msg->payloadSize = (unsigned int) serializedOutput->iov_len; - - if (psa_udpmc_sendMsg(entry, msg) == false) { - status = -1; - } - free(msg); - free(msg_hdr); - msgSer->freeSerializeMsg(msgSer->handle, serializedOutput, serializedOutputLen); - } else { - printf("[PSA_UDPMC/TopicSender] Serialization of msg type id %d failed\n", msgTypeId); - status = -1; - } - - } else { - printf("[PSA_UDPMC/TopicSender] No msg serializer available for msg type id %d\n", msgTypeId); - status = -1; - } - celix_properties_destroy(metadata); - return status; -} - -static bool psa_udpmc_sendMsg(psa_udpmc_bounded_service_entry_t *entry, pubsub_udp_msg_t* msg) { - const int iovec_len = 3; // header + size + payload - bool ret = true; - - struct iovec msg_iovec[iovec_len]; - msg_iovec[0].iov_base = msg->header; - msg_iovec[0].iov_len = sizeof(*msg->header); - msg_iovec[1].iov_base = &msg->payloadSize; - msg_iovec[1].iov_len = sizeof(msg->payloadSize); - msg_iovec[2].iov_base = msg->payload; - msg_iovec[2].iov_len = msg->payloadSize; - - if (largeUdp_sendmsg(entry->largeUdpHandle, entry->parent->sendSocket, msg_iovec, iovec_len, 0, &entry->parent->destAddr, sizeof(entry->parent->destAddr)) == -1) { - perror("send_pubsub_msg:sendSocket"); - ret = false; - } - - return ret; -} - -static unsigned int rand_range(unsigned int min, unsigned int max) { - double scaled = ((double)random())/((double)RAND_MAX); - return (unsigned int)((max-min+1)*scaled + min); -} - -long pubsub_udpmcTopicSender_serializerSvcId(pubsub_udpmc_topic_sender_t *sender) { - return sender->serializerSvcId; -} - -bool pubsub_udpmcTopicSender_isStatic(pubsub_udpmc_topic_sender_t *sender) { - return sender->staticallyConfigured; -} diff --git a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_topic_sender.h b/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_topic_sender.h deleted file mode 100644 index 83a9bbbdd..000000000 --- a/bundles/pubsub/pubsub_admin_udp_mc/src/pubsub_udpmc_topic_sender.h +++ /dev/null @@ -1,53 +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. - */ - -#ifndef CELIX_PUBSUB_UDPMC_TOPIC_SENDER_H -#define CELIX_PUBSUB_UDPMC_TOPIC_SENDER_H - -#include "celix_bundle_context.h" -#include "pubsub_serializer.h" - -typedef struct pubsub_udpmc_topic_sender pubsub_udpmc_topic_sender_t; - -pubsub_udpmc_topic_sender_t* pubsub_udpmcTopicSender_create( - celix_bundle_context_t *ctx, - const char *scope, - const char *topic, - long serializerSvcId, - pubsub_serializer_service_t *serializer, - int sendSocket, - const char *bindIP, - const celix_properties_t *topicProperties); -void pubsub_udpmcTopicSender_destroy(pubsub_udpmc_topic_sender_t *sender); - -const char* pubsub_udpmcTopicSender_scope(pubsub_udpmc_topic_sender_t *sender); -const char* pubsub_udpmcTopicSender_topic(pubsub_udpmc_topic_sender_t *sender); -const char* pubsub_udpmcTopicSender_socketAddress(pubsub_udpmc_topic_sender_t *sender); -long pubsub_udpmcTopicSender_socketPort(pubsub_udpmc_topic_sender_t *sender); -bool pubsub_udpmcTopicSender_isStatic(pubsub_udpmc_topic_sender_t *sender); - - -long pubsub_udpmcTopicSender_serializerSvcId(pubsub_udpmc_topic_sender_t *sender); - -//TODO connections etc - -void pubsub_udpmcTopicSender_connectTo(pubsub_udpmc_topic_sender_t *sender, const celix_properties_t *endpoint); -void pubsub_udpmcTopicSender_disconnectFrom(pubsub_udpmc_topic_sender_t *sender, const celix_properties_t *endpoint); - -#endif //CELIX_PUBSUB_UDPMC_TOPIC_SENDER_H diff --git a/bundles/pubsub/pubsub_admin_websocket/src/psa_activator.c b/bundles/pubsub/pubsub_admin_websocket/src/psa_activator.c index 33cc86f3f..1d4c7ab20 100644 --- a/bundles/pubsub/pubsub_admin_websocket/src/psa_activator.c +++ b/bundles/pubsub/pubsub_admin_websocket/src/psa_activator.c @@ -21,7 +21,6 @@ #include #include "celix_api.h" -#include "pubsub_serializer.h" #include "celix_log_helper.h" #include "pubsub_admin.h" diff --git a/bundles/pubsub/pubsub_admin_websocket/src/pubsub_websocket_admin.c b/bundles/pubsub/pubsub_admin_websocket/src/pubsub_websocket_admin.c index 8763fe609..747a62a46 100644 --- a/bundles/pubsub/pubsub_admin_websocket/src/pubsub_websocket_admin.c +++ b/bundles/pubsub/pubsub_admin_websocket/src/pubsub_websocket_admin.c @@ -22,7 +22,6 @@ #include "celix_compiler.h" #include "pubsub_endpoint.h" -#include "pubsub_serializer.h" #include "pubsub_matching.h" #include "pubsub_utils.h" #include "pubsub_websocket_admin.h" diff --git a/bundles/pubsub/pubsub_admin_websocket/src/pubsub_websocket_topic_receiver.c b/bundles/pubsub/pubsub_admin_websocket/src/pubsub_websocket_topic_receiver.c index 998dc0288..74d249e3e 100644 --- a/bundles/pubsub/pubsub_admin_websocket/src/pubsub_websocket_topic_receiver.c +++ b/bundles/pubsub/pubsub_admin_websocket/src/pubsub_websocket_topic_receiver.c @@ -17,7 +17,6 @@ * under the License. */ -#include #include #include #include diff --git a/bundles/pubsub/pubsub_admin_websocket/src/pubsub_websocket_topic_sender.c b/bundles/pubsub/pubsub_admin_websocket/src/pubsub_websocket_topic_sender.c index 59e58d75a..f8fe5a5e9 100644 --- a/bundles/pubsub/pubsub_admin_websocket/src/pubsub_websocket_topic_sender.c +++ b/bundles/pubsub/pubsub_admin_websocket/src/pubsub_websocket_topic_sender.c @@ -17,7 +17,6 @@ * under the License. */ -#include #include #include #include diff --git a/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_admin.c b/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_admin.c index 8fe53676d..d0cc95d2f 100644 --- a/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_admin.c +++ b/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_admin.c @@ -29,7 +29,6 @@ #include "celix_compiler.h" #include "pubsub_serializer_handler.h" #include "pubsub_endpoint.h" -#include "pubsub_serializer.h" #include "pubsub_protocol.h" #include "pubsub_matching.h" #include "pubsub_utils.h" diff --git a/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_topic_receiver.c b/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_topic_receiver.c index 31f3a7800..1d01f2299 100644 --- a/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_topic_receiver.c +++ b/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_topic_receiver.c @@ -17,7 +17,6 @@ * under the License. */ -#include #include #include #include diff --git a/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_topic_sender.c b/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_topic_sender.c index a5ce229e4..5fdb45b21 100644 --- a/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_topic_sender.c +++ b/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_topic_sender.c @@ -17,7 +17,6 @@ * under the License. */ -#include #include #include #include diff --git a/bundles/pubsub/pubsub_serializer_avrobin/CMakeLists.txt b/bundles/pubsub/pubsub_serializer_avrobin/CMakeLists.txt index c6b5402d5..57ca752ad 100644 --- a/bundles/pubsub/pubsub_serializer_avrobin/CMakeLists.txt +++ b/bundles/pubsub/pubsub_serializer_avrobin/CMakeLists.txt @@ -25,7 +25,6 @@ if (PUBSUB_AVROBIN_SERIALIZER) GROUP "Celix/PubSub" SOURCES src/ps_avrobin_serializer_activator.c - src/pubsub_avrobin_serializer_impl.c src/pubsub_avrobin_serialization_provider.c ) target_include_directories(celix_pubsub_serializer_avrobin PRIVATE diff --git a/bundles/pubsub/pubsub_serializer_avrobin/src/ps_avrobin_serializer_activator.c b/bundles/pubsub/pubsub_serializer_avrobin/src/ps_avrobin_serializer_activator.c index 275a72da7..d60343503 100644 --- a/bundles/pubsub/pubsub_serializer_avrobin/src/ps_avrobin_serializer_activator.c +++ b/bundles/pubsub/pubsub_serializer_avrobin/src/ps_avrobin_serializer_activator.c @@ -21,40 +21,18 @@ #include #include "celix_api.h" -#include "pubsub_avrobin_serializer_impl.h" #include "pubsub_avrobin_serialization_provider.h" typedef struct psav_activator { - pubsub_avrobin_serializer_t *serializer; - pubsub_serializer_service_t serializerSvc; pubsub_serialization_provider_t* avrobinSerializationProvider; - long serializerSvcId; } psav_activator_t; static int psav_start(psav_activator_t *act, celix_bundle_context_t *ctx) { - act->serializerSvcId = -1L; - - celix_status_t status = pubsubAvrobinSerializer_create(ctx, &(act->serializer)); act->avrobinSerializationProvider = pubsub_avrobinSerializationProvider_create(ctx); - if (status == CELIX_SUCCESS) { - act->serializerSvc.handle = act->serializer; - - act->serializerSvc.createSerializerMap = pubsubAvrobinSerializer_createSerializerMap; - act->serializerSvc.destroySerializerMap = pubsubAvrobinSerializer_destroySerializerMap; - - /* Set serializer type */ - celix_properties_t *props = celix_properties_create(); - celix_properties_set(props, PUBSUB_SERIALIZER_TYPE_KEY, PUBSUB_AVROBIN_SERIALIZER_TYPE); - - act->serializerSvcId = celix_bundleContext_registerService(ctx, &act->serializerSvc, PUBSUB_SERIALIZER_SERVICE_NAME, props); - } - return status; + return act->avrobinSerializationProvider ? CELIX_SUCCESS : CELIX_BUNDLE_EXCEPTION; } static int psav_stop(psav_activator_t *act, celix_bundle_context_t *ctx) { - celix_bundleContext_unregisterService(ctx, act->serializerSvcId); - act->serializerSvcId = -1L; - pubsubAvrobinSerializer_destroy(act->serializer); pubsub_avrobinSerializationProvider_destroy(act->avrobinSerializationProvider); return CELIX_SUCCESS; } diff --git a/bundles/pubsub/pubsub_serializer_avrobin/src/pubsub_avrobin_serializer_impl.c b/bundles/pubsub/pubsub_serializer_avrobin/src/pubsub_avrobin_serializer_impl.c deleted file mode 100644 index 93885d40d..000000000 --- a/bundles/pubsub/pubsub_serializer_avrobin/src/pubsub_avrobin_serializer_impl.c +++ /dev/null @@ -1,535 +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 -#include -#include -#include -#include -#include -#include - -#include "utils.h" -#include "hash_map.h" -#include "bundle_context.h" - -#include "celix_compiler.h" -#include "celix_log_helper.h" - -#include "avrobin_serializer.h" - -#include "pubsub_avrobin_serializer_impl.h" - -#define SYSTEM_BUNDLE_ARCHIVE_PATH "CELIX_FRAMEWORK_EXTENDER_PATH" -#define MAX_PATH_LEN 1024 - -typedef enum { - FIT_INVALID = 0, - FIT_DESCRIPTOR = 1, - FIT_AVPR = 2 -} FILE_INPUT_TYPE; - -struct pubsub_avrobin_serializer { - celix_bundle_context_t *bundle_context; - celix_log_helper_t *loghelper; -}; - -static celix_status_t pubsubMsgAvrobinSerializer_serialize(void *handle, const void *msg, struct iovec** output, size_t* outputIovLen); -static celix_status_t pubsubMsgAvrobinSerializer_deserialize(void *handle, const struct iovec *input, size_t inputIovLen, void **out); -static void pubsubMsgAvrobinSerializer_freeDeserializeMsg(void *handle, void *msg); -static void pubsubMsgAvrobinSerializer_freeSerializeMsg(void* handle, struct iovec* input, size_t inputIovLen); -static FILE* openFileStream(FILE_INPUT_TYPE file_input_type, const char* filename, const char* root, /*output*/ char* avpr_fqn, /*output*/ char* path); -static FILE_INPUT_TYPE getFileInputType(const char* filename); -static bool readPropertiesFile(const char* properties_file_name, const char* root, /*output*/ char* avpr_fqn, /*output*/ char* path); - -typedef struct pubsub_avrobin_msg_serializer_impl { - dyn_message_type *msgType; - unsigned int msgId; - const char *msgName; - version_pt msgVersion; -} pubsub_avrobin_msg_serializer_impl_t; - -static char *pubsubAvrobinSerializer_getMsgDescriptionDir(const celix_bundle_t *bundle); -static void pubsubAvrobinSerializer_addMsgSerializerFromBundle(const char *root, const celix_bundle_t *bundle, hash_map_pt msgTypesMap); -static void pubsubAvrobinSerializer_fillMsgSerializerMap(hash_map_pt msgTypesMap, const celix_bundle_t *bundle); - -static int pubsubMsgAvrobinSerializer_convertDescriptor(FILE* file_ptr, pubsub_msg_serializer_t* serializer); -static int pubsubMsgAvrobinSerializer_convertAvpr(FILE* file_ptr, pubsub_msg_serializer_t* serializer, const char* fqn); - -static void dfi_log(void *handle, int level, const char *file, int line, const char *msg, ...) { - va_list ap; - pubsub_avrobin_serializer_t *serializer = handle; - char *logStr = NULL; - va_start(ap, msg); - vasprintf(&logStr, msg, ap); - va_end(ap); - celix_logHelper_log(serializer->loghelper, level, "FILE:%s, LINE:%i, MSG:%s", file, line, logStr); - free(logStr); -} - -celix_status_t pubsubAvrobinSerializer_create(celix_bundle_context_t *context, pubsub_avrobin_serializer_t **serializer) { - celix_status_t status = CELIX_SUCCESS; - - *serializer = calloc(1, sizeof(**serializer)); - - if (*serializer == NULL) { - status = CELIX_ENOMEM; - } else { - - (*serializer)->bundle_context = context; - - (*serializer)->loghelper = celix_logHelper_create(context, "celix_psa_serializer_avrobin"); - - avrobinSerializer_logSetup(dfi_log, (*serializer), 1); - dynFunction_logSetup(dfi_log, (*serializer), 1); - dynType_logSetup(dfi_log, (*serializer), 1); - dynCommon_logSetup(dfi_log, (*serializer), 1); - } - - return status; -} - -celix_status_t pubsubAvrobinSerializer_destroy(pubsub_avrobin_serializer_t *serializer) { - celix_status_t status = CELIX_SUCCESS; - - celix_logHelper_destroy(serializer->loghelper); - - free(serializer); - - return status; -} - -celix_status_t pubsubAvrobinSerializer_createSerializerMap(void *handle, const celix_bundle_t *bundle, hash_map_pt *serializerMap) { - celix_status_t status = CELIX_SUCCESS; - pubsub_avrobin_serializer_t *serializer = handle; - - hash_map_pt map = hashMap_create(NULL, NULL, NULL, NULL); - - if (map != NULL) { - pubsubAvrobinSerializer_fillMsgSerializerMap(map, bundle); - } else { - celix_logHelper_log(serializer->loghelper, CELIX_LOG_LEVEL_ERROR, "Cannot allocate memory for msg map"); - status = CELIX_ENOMEM; - } - - if (status == CELIX_SUCCESS) { - *serializerMap = map; - } - - return status; -} - -celix_status_t pubsubAvrobinSerializer_destroySerializerMap(void *handle, hash_map_pt serializerMap) { - celix_status_t status = CELIX_SUCCESS; - - if (serializerMap == NULL) { - return CELIX_ILLEGAL_ARGUMENT; - } - - hash_map_iterator_t iter = hashMapIterator_construct(serializerMap); - while (hashMapIterator_hasNext(&iter)) { - pubsub_msg_serializer_t* msgSerializer = hashMapIterator_nextValue(&iter); - pubsub_avrobin_msg_serializer_impl_t *impl = msgSerializer->handle; - dynMessage_destroy(impl->msgType); - free(msgSerializer); //also contains the service struct. - free(impl); - } - - hashMap_destroy(serializerMap, false, false); - - return status; -} - -static celix_status_t pubsubMsgAvrobinSerializer_serialize(void *handle, const void *msg, struct iovec** output, size_t* outputIovLen) { - celix_status_t status = CELIX_SUCCESS; - - pubsub_avrobin_msg_serializer_impl_t *impl = handle; - - uint8_t *avroData = NULL; - size_t avroLen = -1; - dyn_type *dynType = NULL; - dynMessage_getMessageType(impl->msgType, &dynType); - - if (*output == NULL) { - *output = calloc(1, sizeof(struct iovec)); - if (outputIovLen) *outputIovLen = 1; - if (output == NULL) status = CELIX_BUNDLE_EXCEPTION; - } - if (avrobinSerializer_serialize(dynType, msg, &avroData, &avroLen) != 0) { - status = CELIX_BUNDLE_EXCEPTION; - } - - /*if (status == CELIX_SUCCESS) { - char *schema = NULL; - if (avrobinSerializer_generateSchema(dynType, &schema)==0) { - printf("%s\n", schema); - free(schema); - } - }*/ - - if (status == CELIX_SUCCESS) { - (**output).iov_base = (void*)avroData; - (**output).iov_len = avroLen; - if (outputIovLen) *outputIovLen = 1; - } - - return status; -} - -void pubsubMsgAvrobinSerializer_freeSerializeMsg(void* handle, struct iovec* input, size_t inputIovLen) { - pubsub_avrobin_msg_serializer_impl_t *impl = handle; - if (input == NULL) { - return; - } - if (impl->msgType != NULL) { - for (int i = 0; i < inputIovLen; i++) { - if (input[i].iov_base) free(input[i].iov_base); - input[i].iov_base = NULL; - input[i].iov_len = 0; - } - free(input); - } -} - - -static celix_status_t pubsubMsgAvrobinSerializer_deserialize(void *handle, const struct iovec* input, size_t inputIovLen CELIX_UNUSED, void **out) { - celix_status_t status = CELIX_SUCCESS; - if (input == NULL) return CELIX_BUNDLE_EXCEPTION; - pubsub_avrobin_msg_serializer_impl_t *impl = handle; - - void *msg = NULL; - dyn_type *dynType = NULL; - dynMessage_getMessageType(impl->msgType, &dynType); - - if (avrobinSerializer_deserialize(dynType, (const uint8_t*)input->iov_base, input->iov_len, &msg) != 0) { - status = CELIX_BUNDLE_EXCEPTION; - } else { - *out = msg; - } - - return status; -} - -static void pubsubMsgAvrobinSerializer_freeDeserializeMsg(void *handle, void *msg) { - pubsub_avrobin_msg_serializer_impl_t *impl = handle; - if (impl->msgType != NULL) { - dyn_type *dynType = NULL; - dynMessage_getMessageType(impl->msgType, &dynType); - dynType_free(dynType, msg); - } -} - -static char *pubsubAvrobinSerializer_getMsgDescriptionDir(const celix_bundle_t *bundle) { - char *root = NULL; - - bool isSystemBundle = false; - bundle_isSystemBundle(bundle, &isSystemBundle); - - if (isSystemBundle == true) { - celix_bundle_context_t *context; - bundle_getContext(bundle, &context); - - const char *prop = NULL; - - bundleContext_getProperty(context, SYSTEM_BUNDLE_ARCHIVE_PATH, &prop); - - if (prop != NULL) { - root = strdup(prop); - } else { - root = getcwd(NULL, 0); - } - } else { - bundle_getEntry(bundle, ".", &root); - } - - return root; -} - -static void pubsubAvrobinSerializer_addMsgSerializerFromBundle(const char *root, const celix_bundle_t *bundle, hash_map_pt msgTypesMap) { - char fqn[MAX_PATH_LEN]; - char path[MAX_PATH_LEN]; - const char* entry_name = NULL; - FILE_INPUT_TYPE fileInputType; - FILE* stream = NULL; - - const struct dirent *entry = NULL; - DIR* dir = opendir(root); - if (dir) { - entry = readdir(dir); - } - - for (; entry != NULL; entry = readdir(dir)) { - entry_name = entry->d_name; - printf("DMU: Parsing entry '%s'\n", entry_name); - fileInputType = getFileInputType(entry_name); - stream = openFileStream(fileInputType, entry_name, root, /*out*/fqn, /*out*/path); - if (!stream) { - printf("DMU: Cannot open descriptor file: '%s'.\n", path); - continue; // Go to next entry in directory - } - - pubsub_avrobin_msg_serializer_impl_t *impl = calloc(1, sizeof(*impl)); - pubsub_msg_serializer_t *msgSerializer = calloc(1,sizeof(*msgSerializer)); - msgSerializer->handle = impl; - - int translation_result = -1; - if (fileInputType == FIT_DESCRIPTOR) { - translation_result = pubsubMsgAvrobinSerializer_convertDescriptor(stream, msgSerializer); - } - else if (fileInputType == FIT_AVPR) { - translation_result = pubsubMsgAvrobinSerializer_convertAvpr(stream, msgSerializer, fqn); - } - fclose(stream); - - if (translation_result != 0) { - printf("DMU: could not create serializer for '%s'\n", entry_name); - free(impl); - free(msgSerializer); - continue; - } - - // serializer has been constructed, try to put in the map - if (hashMap_containsKey(msgTypesMap, (void *) (uintptr_t) msgSerializer->msgId)) { - printf("Cannot add msg %s. clash in msg id %d!!\n", msgSerializer->msgName, msgSerializer->msgId); - dynMessage_destroy(impl->msgType); - free(msgSerializer); - free(impl); - } else if (msgSerializer->msgId == 0) { - printf("Cannot add msg %s. clash in msg id %d!!\n", msgSerializer->msgName, msgSerializer->msgId); - dynMessage_destroy(impl->msgType); - free(msgSerializer); - free(impl); - } - else { - hashMap_put(msgTypesMap, (void *) (uintptr_t) msgSerializer->msgId, msgSerializer); - } - } - - if (dir) { - closedir(dir); - } -} - -static void pubsubAvrobinSerializer_fillMsgSerializerMap(hash_map_pt msgTypesMap, const celix_bundle_t *bundle) { - char *root = NULL; - char *metaInfPath = NULL; - - root = pubsubAvrobinSerializer_getMsgDescriptionDir(bundle); - - if (root != NULL) { - asprintf(&metaInfPath, "%s/META-INF/descriptors", root); - - pubsubAvrobinSerializer_addMsgSerializerFromBundle(root, bundle, msgTypesMap); - pubsubAvrobinSerializer_addMsgSerializerFromBundle(metaInfPath, bundle, msgTypesMap); - - free(metaInfPath); - free(root); - } -} - -static FILE* openFileStream(FILE_INPUT_TYPE file_input_type, const char* filename, const char* root, /*output*/ char* avpr_fqn, /*output*/ char* path) { - FILE* result = NULL; - memset(path, 0, MAX_PATH_LEN); - switch (file_input_type) { - case FIT_INVALID: - snprintf(path, MAX_PATH_LEN, "Because %s is not a valid file", filename); - break; - - case FIT_DESCRIPTOR: - snprintf(path, MAX_PATH_LEN, "%s/%s", root, filename); - result = fopen(path, "r"); - break; - - case FIT_AVPR: - if (readPropertiesFile(filename, root, avpr_fqn, path)) { - result = fopen(path, "r"); - } - break; - - default: - printf("DMU: Unknown file input type, returning NULL!\n"); - break; - } - - return result; -} - -static FILE_INPUT_TYPE getFileInputType(const char* filename) { - if (strstr(filename, ".descriptor")) { - return FIT_DESCRIPTOR; - } - else if (strstr(filename, ".properties")) { - return FIT_AVPR; - } - else { - return FIT_INVALID; - } -} - -static bool readPropertiesFile(const char* properties_file_name, const char* root, /*output*/ char* avpr_fqn, /*output*/ char* path) { - snprintf(path, MAX_PATH_LEN, "%s/%s", root, properties_file_name); // use path to create path to properties file - FILE *properties = fopen(path, "r"); - if (!properties) { - printf("DMU: Could not find or open %s as a properties file in %s\n", properties_file_name, root); - return false; - } - - *avpr_fqn = '\0'; - *path = '\0'; //re-use path to create path to avpr file - char *p_line = malloc(MAX_PATH_LEN); - size_t line_len = MAX_PATH_LEN; - while (getline(&p_line, &line_len, properties) >= 0) { - if (strncmp(p_line, "fqn=", strlen("fqn=")) == 0) { - snprintf(avpr_fqn, MAX_PATH_LEN, "%s", (p_line + strlen("fqn="))); - avpr_fqn[strcspn(avpr_fqn, "\n")] = 0; - } - else if (strncmp(p_line, "avpr=", strlen("avpr=")) == 0) { - snprintf(path, MAX_PATH_LEN, "%s/%s", root, (p_line + strlen("avpr="))); - path[strcspn(path, "\n")] = 0; - } - } - free(p_line); - fclose(properties); - - if (*avpr_fqn == '\0') { - printf("CMU: File %s does not contain a fully qualified name for the parser\n", properties_file_name); - return false; - } - - if (*path == '\0') { - printf("CMU: File %s does not contain a location for the avpr file\n", properties_file_name); - return false; - } - - return true; -} - -static int pubsubMsgAvrobinSerializer_convertDescriptor(FILE* file_ptr, pubsub_msg_serializer_t* serializer) { - dyn_message_type* msgType = NULL; - int rc = dynMessage_parse(file_ptr, &msgType); - if (rc != 0 || msgType == NULL) { - printf("DMU: cannot parse message from descriptor.\n"); - return -1; - } - - char* msgName = NULL; - rc += dynMessage_getName(msgType, &msgName); - - version_pt msgVersion = NULL; - rc += dynMessage_getVersion(msgType, &msgVersion); - - if (rc != 0 || msgName == NULL || msgVersion == NULL) { - printf("DMU: cannot retrieve name and/or version from msg\n"); - return -1; - } - - dyn_type * type = NULL; - dynMessage_getMessageType(msgType, &type); - - unsigned int msgId = 0; - - char *msgIdStr = NULL; - int rv = dynMessage_getAnnotationEntry(msgType, "msgId", &msgIdStr); - if (rv == CELIX_SUCCESS && msgIdStr != NULL) { - // custom msg id passed, use it - long customMsgId = strtol(msgIdStr, NULL, 10); - if (customMsgId > 0) - msgId = (unsigned int) customMsgId; - } - - if (msgId == 0) { - msgId = utils_stringHash(msgName); - } - - pubsub_avrobin_msg_serializer_impl_t * handle = (pubsub_avrobin_msg_serializer_impl_t*)serializer->handle; - handle->msgType = msgType; - handle->msgId = msgId; - handle->msgName = msgName; - handle->msgVersion = msgVersion; - - serializer->msgId = handle->msgId; - serializer->msgName = handle->msgName; - serializer->msgVersion = handle->msgVersion; - - serializer->serialize = (void*) pubsubMsgAvrobinSerializer_serialize; - serializer->deserialize = (void*) pubsubMsgAvrobinSerializer_deserialize; - serializer->freeSerializeMsg = (void*) pubsubMsgAvrobinSerializer_freeSerializeMsg; - serializer->freeDeserializeMsg = (void*) pubsubMsgAvrobinSerializer_freeDeserializeMsg; - return 0; -} - -static int pubsubMsgAvrobinSerializer_convertAvpr(FILE* file_ptr, pubsub_msg_serializer_t* serializer, const char* fqn) { - if (!file_ptr || !fqn || !serializer) return -2; - - //TODO FIXME, see #158 - //dyn_message_type* msgType = dynMessage_parseAvpr(file_ptr, fqn); - dyn_message_type* msgType = NULL; - - if (!msgType) { - printf("DMU: cannot parse avpr file for '%s'\n", fqn); - return -1; - } - - dyn_type* type = NULL; - dynMessage_getMessageType(msgType, &type); - - const char* msgName = dynType_getName(type); - - version_pt msgVersion = NULL; - celix_status_t s = version_createVersionFromString(dynType_getMetaInfo(type, "version"), &msgVersion); - - if (s != CELIX_SUCCESS || !msgName) { - printf("DMU: cannot retrieve name and/or version from msg\n"); - if (s == CELIX_SUCCESS) { - version_destroy(msgVersion); - } - return -1; - } - - unsigned int msgId = 0; - - const char *msgIdStr = dynType_getMetaInfo(type, "msgId"); - if (msgIdStr != NULL) { - // custom msg id passed, use it - long customMsgId = strtol(msgIdStr, NULL, 10); - if (customMsgId > 0) - msgId = (unsigned int) customMsgId; - } - - if (msgId == 0) { - msgId = utils_stringHash(msgName); - } - - pubsub_avrobin_msg_serializer_impl_t * handle = (pubsub_avrobin_msg_serializer_impl_t*) serializer->handle; - handle->msgType = msgType; - handle->msgId = msgId; - handle->msgName = msgName; - handle->msgVersion = msgVersion; - - serializer->msgId = handle->msgId; - serializer->msgName = handle->msgName; - serializer->msgVersion = handle->msgVersion; - - serializer->serialize = (void*) pubsubMsgAvrobinSerializer_serialize; - serializer->deserialize = (void*) pubsubMsgAvrobinSerializer_deserialize; - serializer->freeSerializeMsg = (void*) pubsubMsgAvrobinSerializer_freeSerializeMsg; - serializer->freeDeserializeMsg = (void*) pubsubMsgAvrobinSerializer_freeDeserializeMsg; - - return 0; -} diff --git a/bundles/pubsub/pubsub_serializer_avrobin/src/pubsub_avrobin_serializer_impl.h b/bundles/pubsub/pubsub_serializer_avrobin/src/pubsub_avrobin_serializer_impl.h deleted file mode 100644 index ab1494f29..000000000 --- a/bundles/pubsub/pubsub_serializer_avrobin/src/pubsub_avrobin_serializer_impl.h +++ /dev/null @@ -1,40 +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. - */ - -#ifndef PUBSUB_SERIALIZER_AVROBIN_H_ -#define PUBSUB_SERIALIZER_AVROBIN_H_ - -#include "dyn_common.h" -#include "dyn_type.h" -#include "dyn_message.h" -#include "celix_log_helper.h" - -#include "pubsub_serializer.h" - -#define PUBSUB_AVROBIN_SERIALIZER_TYPE "avrobin" - -typedef struct pubsub_avrobin_serializer pubsub_avrobin_serializer_t; - -celix_status_t pubsubAvrobinSerializer_create(celix_bundle_context_t *context, pubsub_avrobin_serializer_t **serializer); -celix_status_t pubsubAvrobinSerializer_destroy(pubsub_avrobin_serializer_t *serializer); - -celix_status_t pubsubAvrobinSerializer_createSerializerMap(void *handle, const celix_bundle_t *bundle, hash_map_pt *serializerMap); -celix_status_t pubsubAvrobinSerializer_destroySerializerMap(void *handle, hash_map_pt serializerMap); - -#endif /* PUBSUB_SERIALIZER_AVROBIN_H_ */ diff --git a/bundles/pubsub/pubsub_serializer_json/CMakeLists.txt b/bundles/pubsub/pubsub_serializer_json/CMakeLists.txt index 9b55c5be6..94d8a7c60 100644 --- a/bundles/pubsub/pubsub_serializer_json/CMakeLists.txt +++ b/bundles/pubsub/pubsub_serializer_json/CMakeLists.txt @@ -26,7 +26,6 @@ if (PUBSUB_JSON_SERIALIZER) GROUP "Celix/PubSub" SOURCES src/ps_json_serializer_activator.c - src/pubsub_serializer_impl.c src/pubsub_json_serialization_provider.c ) target_include_directories(celix_pubsub_serializer_json PRIVATE diff --git a/bundles/pubsub/pubsub_serializer_json/src/ps_json_serializer_activator.c b/bundles/pubsub/pubsub_serializer_json/src/ps_json_serializer_activator.c index 9df8e13f2..6cea86a79 100644 --- a/bundles/pubsub/pubsub_serializer_json/src/ps_json_serializer_activator.c +++ b/bundles/pubsub/pubsub_serializer_json/src/ps_json_serializer_activator.c @@ -22,37 +22,18 @@ #include "pubsub_json_serialization_provider.h" #include "celix_bundle_activator.h" -#include "pubsub_serializer_impl.h" typedef struct psjs_activator { - pubsub_json_serializer_t* serializer; pubsub_serialization_provider_t *provider; - - pubsub_serializer_service_t serializerSvc; long serializerSvcId; } psjs_activator_t; static int psjs_start(psjs_activator_t *act, celix_bundle_context_t *ctx) { - act->serializerSvcId = -1L; - - celix_status_t status = pubsubSerializer_create(ctx, &(act->serializer)); act->provider = pubsub_jsonSerializationProvider_create(ctx); - if (status == CELIX_SUCCESS) { - act->serializerSvc.handle = act->serializer; - act->serializerSvc.createSerializerMap = pubsubSerializer_createSerializerMap; - act->serializerSvc.destroySerializerMap = pubsubSerializer_destroySerializerMap; - /* Set serializer type */ - celix_properties_t *props = celix_properties_create(); - celix_properties_set(props, PUBSUB_SERIALIZER_TYPE_KEY, PUBSUB_JSON_SERIALIZER_TYPE); - act->serializerSvcId = celix_bundleContext_registerService(ctx, &act->serializerSvc, PUBSUB_SERIALIZER_SERVICE_NAME, props); - - } - return status; + return act->provider ? CELIX_SUCCESS : CELIX_BUNDLE_EXCEPTION; } -static int psjs_stop(psjs_activator_t *act, celix_bundle_context_t *ctx) { - celix_bundleContext_unregisterService(ctx, act->serializerSvcId); - pubsubSerializer_destroy(act->serializer); +static int psjs_stop(psjs_activator_t *act, celix_bundle_context_t *ctx __attribute__((unused))) { pubsub_jsonSerializationProvider_destroy(act->provider); return CELIX_SUCCESS; } diff --git a/bundles/pubsub/pubsub_serializer_json/src/pubsub_serializer_impl.c b/bundles/pubsub/pubsub_serializer_json/src/pubsub_serializer_impl.c deleted file mode 100644 index d958e2736..000000000 --- a/bundles/pubsub/pubsub_serializer_json/src/pubsub_serializer_impl.c +++ /dev/null @@ -1,531 +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 -#include -#include -#include -#include -#include - -#include "utils.h" -#include "hash_map.h" - -#include "celix_compiler.h" -#include "celix_log_helper.h" -#include "bundle_context.h" -#include "json_serializer.h" - -#include "pubsub_serializer_impl.h" - -#define SYSTEM_BUNDLE_ARCHIVE_PATH "CELIX_FRAMEWORK_EXTENDER_PATH" -#define MAX_PATH_LEN 1024 - -typedef enum -{ - FIT_INVALID = 0, - FIT_DESCRIPTOR = 1, - FIT_AVPR = 2 -} -FILE_INPUT_TYPE; - -struct pubsub_json_serializer { - celix_bundle_context_t *bundle_context; - celix_log_helper_t *log; -}; - -#define L_DEBUG(...) \ - celix_logHelper_log(serializer->log, CELIX_LOG_LEVEL_DEBUG, __VA_ARGS__) -#define L_INFO(...) \ - celix_logHelper_log(serializer->log, CELIX_LOG_LEVEL_INFO, __VA_ARGS__) -#define L_WARN(...) \ - celix_logHelper_log(serializer->log, CELIX_LOG_LEVEL_WARNING, __VA_ARGS__) -#define L_ERROR(...) \ - celix_logHelper_log(serializer->log, CELIX_LOG_LEVEL_ERROR, __VA_ARGS__) - - - -/* Start of serializer specific functions */ -static celix_status_t pubsubMsgSerializer_serialize(void* handle, const void* msg, struct iovec** output, size_t* outputIovLen); -static celix_status_t pubsubMsgSerializer_deserialize(void* handle,const struct iovec* input, size_t inputIovLen, void **out); -static void pubsubMsgSerializer_freeSerializeMsg(void* handle, struct iovec* input, size_t inputIovLen); -static void pubsubMsgSerializer_freeDeserializeMsg(void* handle, void *msg); -static FILE* openFileStream(pubsub_json_serializer_t* serializer, FILE_INPUT_TYPE file_input_type, const char* filename, const char* root, /*output*/ char* avpr_fqn, /*output*/ char* path); -static FILE_INPUT_TYPE getFileInputType(const char* filename); -static bool readPropertiesFile(pubsub_json_serializer_t* serializer, const char* properties_file_name, const char* root, /*output*/ char* avpr_fqn, /*output*/ char* path); - -typedef struct pubsub_json_msg_serializer_impl { - dyn_message_type *msgType; - - unsigned int msgId; - const char* msgName; - version_pt msgVersion; -} pubsub_json_msg_serializer_impl_t; - -static char* pubsubSerializer_getMsgDescriptionDir(const celix_bundle_t *bundle); -static void pubsubSerializer_addMsgSerializerFromBundle(pubsub_json_serializer_t* serializer, const char *root, const celix_bundle_t *bundle, hash_map_pt msgSerializers); -static void pubsubSerializer_fillMsgSerializerMap(pubsub_json_serializer_t* serializer, hash_map_pt msgSerializers, const celix_bundle_t *bundle); - -static int pubsubMsgSerializer_convertDescriptor(pubsub_json_serializer_t* serializer, FILE* file_ptr, pubsub_msg_serializer_t* msgSerializer); -static int pubsubMsgSerializer_convertAvpr(pubsub_json_serializer_t *serializer, FILE* file_ptr, pubsub_msg_serializer_t* msgSerializer, const char* fqn); - -static void dfi_log(void *handle, int level, const char *file, int line, const char *msg, ...) { - va_list ap; - pubsub_json_serializer_t *serializer = handle; - char *logStr = NULL; - va_start(ap, msg); - vasprintf(&logStr, msg, ap); - va_end(ap); - celix_logHelper_log(serializer->log, level, "FILE:%s, LINE:%i, MSG:%s", file, line, logStr); - free(logStr); -} - -celix_status_t pubsubSerializer_create(celix_bundle_context_t *context, pubsub_json_serializer_t** serializer) { - celix_status_t status = CELIX_SUCCESS; - - *serializer = calloc(1, sizeof(**serializer)); - - if (!*serializer) { - status = CELIX_ENOMEM; - } else { - (*serializer)->bundle_context= context; - (*serializer)->log = celix_logHelper_create(context, "celix_psa_serializer_json"); - jsonSerializer_logSetup(dfi_log, (*serializer), 1); - dynFunction_logSetup(dfi_log, (*serializer), 1); - dynType_logSetup(dfi_log, (*serializer), 1); - dynCommon_logSetup(dfi_log, (*serializer), 1); - - } - - return status; -} - -celix_status_t pubsubSerializer_destroy(pubsub_json_serializer_t* serializer) { - celix_status_t status = CELIX_SUCCESS; - - celix_logHelper_destroy(serializer->log); - - free(serializer); - - return status; -} - -celix_status_t pubsubSerializer_createSerializerMap(void *handle, const celix_bundle_t *bundle, hash_map_pt* serializerMap) { - pubsub_json_serializer_t *serializer = handle; - - hash_map_pt map = hashMap_create(NULL, NULL, NULL, NULL); - pubsubSerializer_fillMsgSerializerMap(serializer, map, bundle); - *serializerMap = map; - return CELIX_SUCCESS; -} - -celix_status_t pubsubSerializer_destroySerializerMap(void* handle CELIX_UNUSED, hash_map_pt serializerMap) { - celix_status_t status = CELIX_SUCCESS; - //pubsub_json_serializer_t *serializer = handle; - if (serializerMap == NULL) { - return CELIX_ILLEGAL_ARGUMENT; - } - - hash_map_iterator_t iter = hashMapIterator_construct(serializerMap); - while (hashMapIterator_hasNext(&iter)) { - pubsub_msg_serializer_t* msgSerializer = hashMapIterator_nextValue(&iter); - pubsub_json_msg_serializer_impl_t *impl = msgSerializer->handle; - dynMessage_destroy(impl->msgType); - free(msgSerializer); //also contains the service struct. - free(impl); - } - - hashMap_destroy(serializerMap, false, false); - - return status; -} - - -celix_status_t pubsubMsgSerializer_serialize(void *handle, const void* msg, struct iovec** output, size_t* outputIovLen) { - celix_status_t status = CELIX_SUCCESS; - - pubsub_json_msg_serializer_impl_t *impl = handle; - - if (*output == NULL) { - *output = calloc(1, sizeof(struct iovec)); - if (output == NULL) status = CELIX_BUNDLE_EXCEPTION; - } - - char *jsonOutput = NULL; - dyn_type* dynType; - dynMessage_getMessageType(impl->msgType, &dynType); - - if (jsonSerializer_serialize(dynType, msg, &jsonOutput) != 0) { - status = CELIX_BUNDLE_EXCEPTION; - } - - if (status == CELIX_SUCCESS) { - (**output).iov_base = (void*)jsonOutput; - (**output).iov_len = strlen(jsonOutput); - if (outputIovLen) *outputIovLen = 1; - } - - return status; -} - -celix_status_t pubsubMsgSerializer_deserialize(void* handle, const struct iovec* input, size_t inputIovLen CELIX_UNUSED, void **out) { - celix_status_t status = CELIX_SUCCESS; - if (input == NULL) return CELIX_BUNDLE_EXCEPTION; - pubsub_json_msg_serializer_impl_t *impl = handle; - void *msg = NULL; - dyn_type* dynType; - dynMessage_getMessageType(impl->msgType, &dynType); - - if (jsonSerializer_deserialize(dynType, (const char*)input->iov_base, input->iov_len, &msg) != 0) { - status = CELIX_BUNDLE_EXCEPTION; - } - else{ - *out = msg; - } - - return status; -} - -void pubsubMsgSerializer_freeSerializeMsg(void* handle, struct iovec* input, size_t inputIovLen) { - pubsub_json_msg_serializer_impl_t *impl = handle; - if (input == NULL) { - return; - } - if (impl->msgType != NULL) { - for (int i = 0; i < inputIovLen; i++) { - if (input[i].iov_base) free(input[i].iov_base); - input[i].iov_base = NULL; - input[i].iov_len = 0; - } - free(input); - } -} - - -void pubsubMsgSerializer_freeDeserializeMsg(void* handle, void *msg) { - pubsub_json_msg_serializer_impl_t *impl = handle; - if (impl->msgType != NULL) { - dyn_type* dynType; - dynMessage_getMessageType(impl->msgType, &dynType); - dynType_free(dynType, msg); - } -} - - -static void pubsubSerializer_fillMsgSerializerMap(pubsub_json_serializer_t* serializer, hash_map_pt msgSerializers, const celix_bundle_t *bundle) { - char* root = NULL; - char* metaInfPath = NULL; - - root = pubsubSerializer_getMsgDescriptionDir(bundle); - - if (root != NULL) { - asprintf(&metaInfPath, "%s/META-INF/descriptors", root); - - pubsubSerializer_addMsgSerializerFromBundle(serializer, root, bundle, msgSerializers); - pubsubSerializer_addMsgSerializerFromBundle(serializer, metaInfPath, bundle, msgSerializers); - - free(metaInfPath); - free(root); - } -} - -static char* pubsubSerializer_getMsgDescriptionDir(const celix_bundle_t *bundle) { - char *root = NULL; - - bool isSystemBundle = false; - bundle_isSystemBundle(bundle, &isSystemBundle); - - if (isSystemBundle == true) { - celix_bundle_context_t *context; - bundle_getContext(bundle, &context); - - const char *prop = NULL; - - bundleContext_getProperty(context, SYSTEM_BUNDLE_ARCHIVE_PATH, &prop); - - if (prop != NULL) { - root = strdup(prop); - } else { - root = getcwd(NULL, 0); - } - } else { - bundle_getEntry(bundle, ".", &root); - } - - return root; -} - -static void pubsubSerializer_addMsgSerializerFromBundle(pubsub_json_serializer_t* serializer, const char *root, const celix_bundle_t *bundle, hash_map_pt msgSerializers) { - char fqn[MAX_PATH_LEN]; - char pathOrError[MAX_PATH_LEN]; - const char* entry_name = NULL; - FILE_INPUT_TYPE fileInputType; - - const struct dirent *entry = NULL; - DIR* dir = opendir(root); - if (dir) { - entry = readdir(dir); - } - - for (; entry != NULL; entry = readdir(dir)) { - FILE* stream = NULL; - entry_name = entry->d_name; - fileInputType = getFileInputType(entry_name); - if (fileInputType != FIT_INVALID) { - L_DEBUG("[json serializer] Parsing entry '%s'\n", entry_name); - stream = openFileStream(serializer, fileInputType, entry_name, root, /*out*/fqn, /*out*/pathOrError); - if (!stream) { - L_WARN("[json serializer] Cannot open descriptor file: '%s'\n", pathOrError); - } - } - - if (!stream) { - continue; // Go to next entry in directory - } - - pubsub_json_msg_serializer_impl_t *impl = calloc(1, sizeof(*impl)); - pubsub_msg_serializer_t *msgSerializer = calloc(1,sizeof(*msgSerializer)); - msgSerializer->handle = impl; - - int translation_result = -1; - if (fileInputType == FIT_DESCRIPTOR) { - translation_result = pubsubMsgSerializer_convertDescriptor(serializer, stream, msgSerializer); - } - else if (fileInputType == FIT_AVPR) { - translation_result = pubsubMsgSerializer_convertAvpr(serializer, stream, msgSerializer, fqn); - } - fclose(stream); - - if (translation_result != 0) { - L_WARN("[json serializer] Could not craete serializer for '%s'\n", entry_name); - free(impl); - free(msgSerializer); - continue; - } - - // serializer has been constructed, try to put in the map - if (hashMap_containsKey(msgSerializers, (void *) (uintptr_t) msgSerializer->msgId)) { - L_WARN("Cannot add msg %s. Clash is msg id %d!\n", msgSerializer->msgName, msgSerializer->msgId); - dynMessage_destroy(impl->msgType); - free(msgSerializer); - free(impl); - } else if (msgSerializer->msgId == 0) { - L_WARN("Cannot add msg %s. Clash is msg id %d!\n", msgSerializer->msgName, msgSerializer->msgId); - dynMessage_destroy(impl->msgType); - free(msgSerializer); - free(impl); - } - else { - hashMap_put(msgSerializers, (void *) (uintptr_t) msgSerializer->msgId, msgSerializer); - } - } - - if (dir) { - closedir(dir); - } -} - -static FILE* openFileStream(pubsub_json_serializer_t *serializer, FILE_INPUT_TYPE file_input_type, const char* filename, const char* root, char* avpr_fqn, char* pathOrError) { - FILE* result = NULL; - memset(pathOrError, 0, MAX_PATH_LEN); - switch (file_input_type) { - case FIT_INVALID: - snprintf(pathOrError, MAX_PATH_LEN, "Because %s is not a valid file", filename); - break; - case FIT_DESCRIPTOR: - snprintf(pathOrError, MAX_PATH_LEN, "%s/%s", root, filename); - result = fopen(pathOrError, "r"); - break; - case FIT_AVPR: - if (readPropertiesFile(serializer, filename, root, avpr_fqn, pathOrError)) { - result = fopen(pathOrError, "r"); - } - break; - default: - L_WARN("[json serializer] Unknown file input type, returning NULL!\n"); - break; - } - - return result; -} - -static FILE_INPUT_TYPE getFileInputType(const char* filename) { - if (strstr(filename, ".descriptor")) { - return FIT_DESCRIPTOR; - } - else if (strstr(filename, ".properties")) { - return FIT_AVPR; - } - else { - return FIT_INVALID; - } -} - -static bool readPropertiesFile(pubsub_json_serializer_t* serializer, const char* properties_file_name, const char* root, char* avpr_fqn, char* path) { - snprintf(path, MAX_PATH_LEN, "%s/%s", root, properties_file_name); // use path to create path to properties file - FILE *properties = fopen(path, "r"); - if (!properties) { - L_WARN("[json serializer] Could not find or open %s as a properties file in %s\n", properties_file_name, root); - return false; - } - - *avpr_fqn = '\0'; - *path = '\0'; //re-use path to create path to avpr file - char *p_line = malloc(MAX_PATH_LEN); - size_t line_len = MAX_PATH_LEN; - while (getline(&p_line, &line_len, properties) >= 0) { - if (strncmp(p_line, "fqn=", strlen("fqn=")) == 0) { - snprintf(avpr_fqn, MAX_PATH_LEN, "%s", (p_line + strlen("fqn="))); - avpr_fqn[strcspn(avpr_fqn, "\n")] = 0; - } - else if (strncmp(p_line, "avpr=", strlen("avpr=")) == 0) { - snprintf(path, MAX_PATH_LEN, "%s/%s", root, (p_line + strlen("avpr="))); - path[strcspn(path, "\n")] = 0; - } - } - free(p_line); - fclose(properties); - - if (*avpr_fqn == '\0') { - L_WARN("[json serializer] File %s does not contain a fully qualified name for the parser\n", properties_file_name); - return false; - } - - if (*path == '\0') { - L_WARN("[json serializer] File %s does not contain a location for the avpr file\n", properties_file_name); - return false; - } - - return true; -} - -static int pubsubMsgSerializer_convertDescriptor(pubsub_json_serializer_t* serializer, FILE* file_ptr, pubsub_msg_serializer_t* msgSerializer) { - dyn_message_type *msgType = NULL; - int rc = dynMessage_parse(file_ptr, &msgType); - if (rc != 0 || msgType == NULL) { - L_WARN("[json serializer] Cannot parse message from descriptor.\n"); - return -1; - } - - char *msgName = NULL; - rc += dynMessage_getName(msgType, &msgName); - - version_pt msgVersion = NULL; - rc += dynMessage_getVersion(msgType, &msgVersion); - - if (rc != 0 || msgName == NULL || msgVersion == NULL) { - L_WARN("[json serializer] Cannot retrieve name and/or version from msg\n"); - return -1; - } - - dyn_type *type = NULL; - dynMessage_getMessageType(msgType, &type); - - unsigned int msgId = 0; - - char *msgIdStr = NULL; - int rv = dynMessage_getAnnotationEntry(msgType, "msgId", &msgIdStr); - if (rv == CELIX_SUCCESS && msgIdStr != NULL) { - // custom msg id passed, use it - long customMsgId = strtol(msgIdStr, NULL, 10); - if (customMsgId > 0) - msgId = (unsigned int) customMsgId; - } - - if (msgId == 0) { - msgId = utils_stringHash(msgName); - } - - pubsub_json_msg_serializer_impl_t *handle = (pubsub_json_msg_serializer_impl_t*)msgSerializer->handle; - handle->msgType = msgType; - handle->msgId = msgId; - handle->msgName = msgName; - handle->msgVersion = msgVersion; - - msgSerializer->msgId = handle->msgId; - msgSerializer->msgName = handle->msgName; - msgSerializer->msgVersion = handle->msgVersion; - - msgSerializer->serialize = (void*) pubsubMsgSerializer_serialize; - msgSerializer->deserialize = (void*) pubsubMsgSerializer_deserialize; - - msgSerializer->freeSerializeMsg = (void*) pubsubMsgSerializer_freeSerializeMsg; - msgSerializer->freeDeserializeMsg = (void*) pubsubMsgSerializer_freeDeserializeMsg; - - return 0; -} - -static int pubsubMsgSerializer_convertAvpr(pubsub_json_serializer_t *serializer, FILE* file_ptr, pubsub_msg_serializer_t* msgSerializer, const char* fqn) { - if (!file_ptr || !fqn || !serializer) return -2; - - //TODO FIXME, see #158 - //dyn_message_type* msgType = dynMessage_parseAvpr(file_ptr, fqn); - dyn_message_type* msgType = NULL; - - if (!msgType) { - L_WARN("[json serializer] Cannot parse avpr file '%s'\n", fqn); - return -1; - } - - dyn_type* type; - dynMessage_getMessageType(msgType, &type); - - const char *msgName = dynType_getName(type); - - version_pt msgVersion = NULL; - celix_status_t s = version_createVersionFromString(dynType_getMetaInfo(type, "version"), &msgVersion); - - if (s != CELIX_SUCCESS || !msgName) { - L_WARN("[json serializer] Cannot retrieve name and/or version from msg\n"); - if (s == CELIX_SUCCESS) { - version_destroy(msgVersion); - } - return -1; - } - - unsigned int msgId = 0; - const char *msgIdStr = dynType_getMetaInfo(type, "msgId"); - if (msgIdStr != NULL) { - // custom msg id passed, use it - long customMsgId = strtol(msgIdStr, NULL, 10); - if (customMsgId > 0) - msgId = (unsigned int) customMsgId; - } - - if (msgId == 0) { - msgId = utils_stringHash(msgName); - } - - pubsub_json_msg_serializer_impl_t *handle = (pubsub_json_msg_serializer_impl_t*) msgSerializer->handle; - handle->msgType = msgType; - handle->msgId = msgId; - handle->msgName = msgName; - handle->msgVersion = msgVersion; - - msgSerializer->msgId = handle->msgId; - msgSerializer->msgName = handle->msgName; - msgSerializer->msgVersion = handle->msgVersion; - - msgSerializer->serialize = (void*) pubsubMsgSerializer_serialize; - msgSerializer->deserialize = (void*) pubsubMsgSerializer_deserialize; - msgSerializer->freeSerializeMsg = (void*) pubsubMsgSerializer_freeSerializeMsg; - msgSerializer->freeDeserializeMsg = (void*) pubsubMsgSerializer_freeDeserializeMsg; - - return 0; -} diff --git a/bundles/pubsub/pubsub_serializer_json/src/pubsub_serializer_impl.h b/bundles/pubsub/pubsub_serializer_json/src/pubsub_serializer_impl.h deleted file mode 100644 index 1e9936d99..000000000 --- a/bundles/pubsub/pubsub_serializer_json/src/pubsub_serializer_impl.h +++ /dev/null @@ -1,42 +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. - */ - -#ifndef PUBSUB_SERIALIZER_JSON_H_ -#define PUBSUB_SERIALIZER_JSON_H_ - -#include "dyn_common.h" -#include "dyn_type.h" -#include "dyn_message.h" -#include "celix_log_helper.h" - -#include "pubsub_serializer.h" - -#define PUBSUB_JSON_SERIALIZER_TYPE "json" - -typedef struct pubsub_json_serializer pubsub_json_serializer_t; - -celix_status_t pubsubSerializer_create(celix_bundle_context_t *context, pubsub_json_serializer_t **serializer); -celix_status_t pubsubSerializer_destroy(pubsub_json_serializer_t* serializer); - -celix_status_t pubsubSerializer_createSerializerMap(void *handle, const celix_bundle_t *bundle, hash_map_pt* serializerMap); -celix_status_t pubsubSerializer_destroySerializerMap(void *handle, hash_map_pt serializerMap); - -void pubsubSerializer_onInstalled(void *handle, const celix_bundle_t *bundle); - -#endif /* PUBSUB_SERIALIZER_JSON_H_ */ diff --git a/bundles/pubsub/pubsub_spi/include/pubsub_endpoint.h b/bundles/pubsub/pubsub_spi/include/pubsub_endpoint.h index c03388f5b..5fc818bcb 100644 --- a/bundles/pubsub/pubsub_spi/include/pubsub_endpoint.h +++ b/bundles/pubsub/pubsub_spi/include/pubsub_endpoint.h @@ -74,122 +74,6 @@ pubsubEndpoint_isValid(const celix_properties_t *endpointProperties, bool requir */ char *pubsubEndpoint_createScopeTopicKey(const char *scope, const char *topic); -/** - * @deprecated Please use pubsub_utils_matchPublisher - * - * Match a publisher for a provided bnd (using the bundleId) and service filter. - * - * The match function will try to find a topic properties for the requesting bundle (bundleId) using the topic - * from the filter at META-INF/topics/pub/.properties - * - * If the topic properties is configured for the provided adminType (i.e. pubsub.config=ZMQ) a full match will - * be returned. If no specific admin is configured in the topic properties the sampleScore will be returned if sample - * qos is configured (i.e. qos=sample), the controlScore will be returned if control qos is configured - * (i.e. qos=control) and otherwise the defaultScore will be returned. - * - * The match function will also search for a valid serializer. If a serializer is configured in the topic properties - * (i.e. pubsub.serializer=json) that specific serializer will be searched. If no serializer is configured the - * highest ranking serializer service will be returned. If no serializer can be found, the outSerializerSvcId will - * be -1. - * - * The function will also returned the found topic properties and the matching serialized. - * The caller is owner of the outTopicProperties. - * - * @param ctx The bundle context. - * @param bundleId The requesting bundle id. - * @param filter The filter of the publisher (i.e. "(&(topic=example)(scope=subsystem))") - * @param adminType The admin type used for the match. - * @param sampleScore The sample score used for the match. - * @param controlScore The control score used for the match. - * @param defaultScore The default score used for the match. - * @param outTopicProperties Output pointer for the read topic properties. Return can be NULL. - * @param outSerializerSvcId Output svc id for the matching serializer. If not found will be -1L. - * @return The matching score. - */ -//__attribute__((__deprecated__)) -double pubsubEndpoint_matchPublisher( - celix_bundle_context_t *ctx, - long bundleId, - const char *filter, - const char *adminType, - double sampleScore, - double controlScore, - double defaultScore, - bool matchProtocol, - celix_properties_t **outTopicProperties, - long *outSerializerSvcId, - long *outProtocolSvcId); - -/** - * @deprecated Please use pubsub_utils_matchSubscriber - * - * Match a subscriber for a provided bnd (using the bundleId) and provided service properties. - * - * The match function will try to find a topic properties for the requesting bundle (bundleId) - using topic in the - * provided service properties - at META-INF/topics/sub/.properties - * - * If the topic properties is configured for the provided adminType (i.e. pubsub.config=ZMQ) a full match will - * be returned. If no specific admin is configured in the topic properties the sampleScore will be returned if sample - * qos is configured (i.e. qos=sample), the controlScore will be returned if control qos is configured - * (i.e. qos=control) and otherwise the defaultScore will be returned. - * - * The match function will also search for a valid serializer. If a serializer is configured in the topic properties - * (i.e. pubsub.serializer=json) that specific serializer will be searched. If no serializer is configured the - * highest ranking serializer service will be returned. If no serializer can be found, the outSerializerSvcId will - * be -1. - * - * The function will also returned the found topic properties and the matching serialized. - * The caller is owner of the outTopicProperties. - * - * @param ctx The bundle context. - * @param bundleId The requesting bundle id. - * @param svcProperties The service properties of the registered subscriber service. - * @param adminType The admin type used for the match. - * @param sampleScore The sample score used for the match. - * @param controlScore The control score used for the match. - * @param defaultScore The default score used for the match. - * @param outTopicProperties Output pointer for the read topic properties. Return can be NULL. - * @param outSerializerSvcId Output svc id for the matching serializer. If not found will be -1L. - * @return The matching score. - */ -//__attribute__((__deprecated__)) -double pubsubEndpoint_matchSubscriber( - celix_bundle_context_t *ctx, - long svcProviderBundleId, - const celix_properties_t *svcProperties, - const char *adminType, - double sampleScore, - double controlScore, - double defaultScore, - bool matchProtocol, - celix_properties_t **outTopicProperties, - long *outSerializerSvcId, - long *outProtocolSvcId); - -/** - * @deprecated Please use pubsub_utils_matchEndpoint - * - * Match an endpoint (subscriber or publisher endpoint) for the provided admin type. - * - * Also tries to found the matching serializer configured in the endpoint. - * - * @param ctx The bundle context. - * @param endpoint The endpoint to match. - * @param adminType The admin type (i.e. UDPMC) - * @param outSerializerSvcId The found serialized svc id based on the endpoint or -1 if no serializer is - * configured/found. - * @return true if there is a match. - */ -//__attribute__((__deprecated__)) -bool pubsubEndpoint_match( - celix_bundle_context_t *ctx, - celix_log_helper_t *logHelper, - const celix_properties_t *endpoint, - const char *adminType, - bool matchProtocol, - long *outSerializerSvcId, - long *outProtocolSvcId); - /** * Match an endpoint with a topic & scope. * @param endpoint The endpoints (mandatory) diff --git a/bundles/pubsub/pubsub_spi/include/pubsub_serializer.h b/bundles/pubsub/pubsub_spi/include/pubsub_serializer.h deleted file mode 100644 index 6e251b276..000000000 --- a/bundles/pubsub/pubsub_spi/include/pubsub_serializer.h +++ /dev/null @@ -1,71 +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. - */ - -#ifndef PUBSUB_SERIALIZER_SERVICE_H_ -#define PUBSUB_SERIALIZER_SERVICE_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "hash_map.h" -#include "version.h" -#include "celix_bundle.h" -#include "sys/uio.h" - -/** - * There should be a pubsub_serializer_t - * per msg type (msg id) per bundle - * - * The pubsub_serializer_service can create - * a serializer_map per bundle. Potentially using - * the extender pattern. - */ - -#define PUBSUB_SERIALIZER_SERVICE_NAME "pubsub_serializer" -#define PUBSUB_SERIALIZER_SERVICE_VERSION "1.0.0" -#define PUBSUB_SERIALIZER_SERVICE_RANGE "[1,2)" - -//NOTE deprecated used the pubsub_message_serialization_service instead -typedef struct pubsub_msg_serializer { - void* handle; - - unsigned int msgId; - const char* msgName; - version_pt msgVersion; - - celix_status_t (*serialize)(void* handle, const void* input, struct iovec** output, size_t* outputIovLen); - void (*freeSerializeMsg)(void* handle, const struct iovec* input, size_t inputIovLen); - celix_status_t (*deserialize)(void* handle, const struct iovec* input, size_t inputIovLen, void** out); //note inputLen can be 0 if predefined size is not needed - void (*freeDeserializeMsg)(void* handle, void* msg); - -} pubsub_msg_serializer_t; - -typedef struct pubsub_serializer_service { - void* handle; - - celix_status_t (*createSerializerMap)(void* handle, const celix_bundle_t *bundle, hash_map_pt* serializerMap); - celix_status_t (*destroySerializerMap)(void* handle, hash_map_pt serializerMap); - -} pubsub_serializer_service_t; - -#ifdef __cplusplus -} -#endif -#endif /* PUBSUB_SERIALIZER_SERVICE_H_ */ diff --git a/bundles/pubsub/pubsub_spi/src/pubsub_endpoint_match.c b/bundles/pubsub/pubsub_spi/src/pubsub_endpoint_match.c index ef328e06d..f141d7084 100644 --- a/bundles/pubsub/pubsub_spi/src/pubsub_endpoint_match.c +++ b/bundles/pubsub/pubsub_spi/src/pubsub_endpoint_match.c @@ -18,304 +18,11 @@ */ #include -#include -#include -#include -#include -#include -#include "service_reference.h" - -#include "pubsub_admin.h" - -#include "pubsub_utils.h" -#include "celix_compiler.h" +#include "pubsub_endpoint.h" +#include "celix_utils.h" #include "celix_constants.h" -static double getPSAScore(const char *requested_admin, const char *request_qos, const char *adminType, double sampleScore, double controlScore, double defaultScore) { - double score; - if (requested_admin != NULL && strncmp(requested_admin, adminType, strlen(adminType) + 1) == 0) { - /* We got precise specification on the pubsub_admin we want */ - //Full match - score = PUBSUB_ADMIN_FULL_MATCH_SCORE; - } else if (requested_admin != NULL) { - //admin type requested, but no match -> do not select this psa - score = PUBSUB_ADMIN_NO_MATCH_SCORE; - } else if (request_qos != NULL && strncmp(request_qos, PUBSUB_UTILS_QOS_TYPE_SAMPLE, strlen(PUBSUB_UTILS_QOS_TYPE_SAMPLE) + 1) == 0) { - //qos match - score = sampleScore; - } else if (request_qos != NULL && strncmp(request_qos, PUBSUB_UTILS_QOS_TYPE_CONTROL, strlen(PUBSUB_UTILS_QOS_TYPE_CONTROL) + 1) == 0) { - //qos match - score = controlScore; - } else if (request_qos != NULL) { - //note unsupported qos -> defaultScore - score = defaultScore; - } else { - //default match - score = defaultScore; - } - return score; -} - -static long getPSASerializer(celix_bundle_context_t *ctx, const char *requested_serializer) { - long svcId = -1L; - - if (requested_serializer != NULL) { - char filter[512]; - snprintf(filter, 512, "(%s=%s)", PUBSUB_SERIALIZER_TYPE_KEY, requested_serializer); - - celix_service_filter_options_t opts = CELIX_EMPTY_SERVICE_FILTER_OPTIONS; - opts.serviceName = PUBSUB_SERIALIZER_SERVICE_NAME; - opts.filter = filter; - - svcId = celix_bundleContext_findServiceWithOptions(ctx, &opts); - if (svcId == -1) { - fprintf(stderr, "Warning cannot find serializer with requested serializer type '%s'\n", requested_serializer); - } - } else { - celix_service_filter_options_t opts = CELIX_EMPTY_SERVICE_FILTER_OPTIONS; - opts.serviceName = PUBSUB_SERIALIZER_SERVICE_NAME; - opts.ignoreServiceLanguage = true; - - //note findService will automatically return the highest ranking service id - svcId = celix_bundleContext_findServiceWithOptions(ctx, &opts); - } - - return svcId; -} - -struct psa_protocol_selection_data { - const char *requested_protocol; - long matchingSvcId; -}; - -void psa_protocol_selection_callback(void *handle, void *svc CELIX_UNUSED, const celix_properties_t *props) { - struct psa_protocol_selection_data *data = handle; - const char *serType = celix_properties_get(props, PUBSUB_PROTOCOL_TYPE_KEY, NULL); - if (serType == NULL) { - fprintf(stderr, "Warning found protocol without mandatory protocol type key (%s)\n", PUBSUB_PROTOCOL_TYPE_KEY); - } else { - if (strncmp(data->requested_protocol, serType, 1024 * 1024) == 0) { - data->matchingSvcId = celix_properties_getAsLong(props, OSGI_FRAMEWORK_SERVICE_ID, -1L); - } - } -} - -static long getPSAProtocol(celix_bundle_context_t *ctx, const char *requested_protocol) { - long svcId; - - if (requested_protocol != NULL) { - struct psa_protocol_selection_data data; - data.requested_protocol = requested_protocol; - data.matchingSvcId = -1L; - - celix_service_use_options_t opts = CELIX_EMPTY_SERVICE_USE_OPTIONS; - opts.filter.serviceName = PUBSUB_PROTOCOL_SERVICE_NAME; - opts.filter.ignoreServiceLanguage = true; - opts.callbackHandle = &data; - opts.useWithProperties = psa_protocol_selection_callback; - celix_bundleContext_useServicesWithOptions(ctx, &opts); - svcId = data.matchingSvcId; - } else { - celix_service_filter_options_t opts = CELIX_EMPTY_SERVICE_FILTER_OPTIONS; - opts.serviceName = PUBSUB_PROTOCOL_SERVICE_NAME; - opts.ignoreServiceLanguage = true; - - //note findService will automatically return the highest ranking service id - svcId = celix_bundleContext_findServiceWithOptions(ctx, &opts); - } - - return svcId; -} - -double pubsubEndpoint_matchPublisher( - celix_bundle_context_t *ctx, - long bundleId, - const char *filter, - const char *adminType, - double sampleScore, - double controlScore, - double defaultScore, - bool matchProtocol, - celix_properties_t **outTopicProperties, - long *outSerializerSvcId, - long *outProtocolSvcId) { - - celix_properties_t *ep = pubsubEndpoint_createFromPublisherTrackerInfo(ctx, bundleId, filter); - const char *requested_admin = NULL; - const char *requested_qos = NULL; - if (ep != NULL) { - requested_admin = celix_properties_get(ep, PUBSUB_ENDPOINT_ADMIN_TYPE, NULL); - requested_qos = celix_properties_get(ep, PUBSUB_UTILS_QOS_ATTRIBUTE_KEY, NULL); - } - - double score = getPSAScore(requested_admin, requested_qos, adminType, sampleScore, controlScore, defaultScore); - - const char *requested_serializer = celix_properties_get(ep, PUBSUB_ENDPOINT_SERIALIZER, NULL); - long serializerSvcId = getPSASerializer(ctx, requested_serializer); - - if (serializerSvcId < 0) { - score = PUBSUB_ADMIN_NO_MATCH_SCORE; //no serializer, no match - } - - if (outSerializerSvcId != NULL) { - *outSerializerSvcId = serializerSvcId; - } - - if (matchProtocol) { - const char *requested_protocol = celix_properties_get(ep, PUBSUB_ENDPOINT_PROTOCOL, NULL); - long protocolSvcId = getPSAProtocol(ctx, requested_protocol); - - if (protocolSvcId < 0) { - score = PUBSUB_ADMIN_NO_MATCH_SCORE; - } - - if (outProtocolSvcId != NULL) { - *outProtocolSvcId = protocolSvcId; - } - } - - if (outTopicProperties != NULL) { - *outTopicProperties = ep; - } else if (ep != NULL) { - celix_properties_destroy(ep); - } - - return score; -} - -typedef struct pubsub_match_retrieve_topic_properties_data { - const char *topic; - const char *scope; - bool isPublisher; - - celix_properties_t *outEndpoint; -} pubsub_get_topic_properties_data_t; - -static void getTopicPropertiesCallback(void *handle, const celix_bundle_t *bnd) { - pubsub_get_topic_properties_data_t *data = handle; - data->outEndpoint = pubsub_utils_getTopicProperties(bnd, data->scope, data->topic, data->isPublisher); -} - -double pubsubEndpoint_matchSubscriber( - celix_bundle_context_t *ctx, - const long svcProviderBundleId, - const celix_properties_t *svcProperties, - const char *adminType, - double sampleScore, - double controlScore, - double defaultScore, - bool matchProtocol, - celix_properties_t **outTopicProperties, - long *outSerializerSvcId, - long *outProtocolSvcId) { - - pubsub_get_topic_properties_data_t data; - data.isPublisher = false; - data.scope = celix_properties_get(svcProperties, PUBSUB_SUBSCRIBER_SCOPE, NULL); - data.topic = celix_properties_get(svcProperties, PUBSUB_SUBSCRIBER_TOPIC, NULL); - data.outEndpoint = NULL; - celix_bundleContext_useBundle(ctx, svcProviderBundleId, &data, getTopicPropertiesCallback); - - celix_properties_t *ep = data.outEndpoint; - const char *requested_admin = NULL; - const char *requested_qos = NULL; - const char *requested_serializer = NULL; - const char *requested_protocol = NULL; - if (ep != NULL) { - requested_admin = celix_properties_get(ep, PUBSUB_ENDPOINT_ADMIN_TYPE, NULL); - requested_qos = celix_properties_get(ep, PUBSUB_UTILS_QOS_ATTRIBUTE_KEY, NULL); - requested_serializer = celix_properties_get(ep, PUBSUB_ENDPOINT_SERIALIZER, NULL); - if (matchProtocol) { - requested_protocol = celix_properties_get(ep, PUBSUB_ENDPOINT_PROTOCOL, NULL); - } - } - - double score = getPSAScore(requested_admin, requested_qos, adminType, sampleScore, controlScore, defaultScore); - - long serializerSvcId = getPSASerializer(ctx, requested_serializer); - if (serializerSvcId < 0) { - score = PUBSUB_ADMIN_NO_MATCH_SCORE; //no serializer, no match - } - - if (outSerializerSvcId != NULL) { - *outSerializerSvcId = serializerSvcId; - } - - if (matchProtocol) { - long protocolSvcId = getPSAProtocol(ctx, requested_protocol); - if (protocolSvcId < 0) { - score = PUBSUB_ADMIN_NO_MATCH_SCORE; //no protocol, no match - } - - if (outProtocolSvcId != NULL) { - *outProtocolSvcId = protocolSvcId; - } - } - - if (outTopicProperties != NULL) { - *outTopicProperties = ep; - } else if (ep != NULL) { - celix_properties_destroy(ep); - } - - return score; -} - -bool pubsubEndpoint_match( - celix_bundle_context_t *ctx, - celix_log_helper_t *logHelper, - const celix_properties_t *ep, - const char *adminType, - bool matchProtocol, - long *outSerializerSvcId, - long *outProtocolSvcId) { - - bool psaMatch = false; - const char *configured_admin = celix_properties_get(ep, PUBSUB_ENDPOINT_ADMIN_TYPE, NULL); - if (configured_admin != NULL) { - psaMatch = strncmp(configured_admin, adminType, strlen(adminType) + 1) == 0; - } - - bool serMatch = false; - long serializerSvcId = -1L; - if (psaMatch) { - const char *configured_serializer = celix_properties_get(ep, PUBSUB_ENDPOINT_SERIALIZER, NULL); - serializerSvcId = getPSASerializer(ctx, configured_serializer); - serMatch = serializerSvcId >= 0; - - if(!serMatch) { - celix_logHelper_log(logHelper, CELIX_LOG_LEVEL_ERROR, "Matching endpoint for technology %s but couldn't get serializer %s", configured_admin, configured_serializer); - } - } - - bool match = psaMatch && serMatch; - - if (matchProtocol) { - bool protMatch = false; - long protocolSvcId = -1L; - if (psaMatch) { - const char *configured_protocol = celix_properties_get(ep, PUBSUB_ENDPOINT_PROTOCOL, NULL); - protocolSvcId = getPSAProtocol(ctx, configured_protocol); - protMatch = protocolSvcId >= 0; - - if(!protMatch) { - celix_logHelper_log(logHelper, CELIX_LOG_LEVEL_ERROR, "Matching endpoint for technology %s but couldn't get protocol %s", configured_admin, configured_protocol); - } - } - match = match && protMatch; - - if (outProtocolSvcId != NULL) { - *outProtocolSvcId = protocolSvcId; - } - } - - if (outSerializerSvcId != NULL) { - *outSerializerSvcId = serializerSvcId; - } - - return match; -} bool pubsubEndpoint_matchWithTopicAndScope(const celix_properties_t* endpoint, const char *topic, const char *scope) { const char *endpointScope = celix_properties_get(endpoint, PUBSUB_ENDPOINT_TOPIC_SCOPE, PUBSUB_DEFAULT_ENDPOINT_SCOPE); diff --git a/bundles/shell/CMakeLists.txt b/bundles/shell/CMakeLists.txt index a7f29ba91..0cbab2a49 100644 --- a/bundles/shell/CMakeLists.txt +++ b/bundles/shell/CMakeLists.txt @@ -19,4 +19,3 @@ add_subdirectory(shell) add_subdirectory(shell_tui) add_subdirectory(shell_wui) add_subdirectory(remote_shell) -add_subdirectory(shell_bonjour) diff --git a/bundles/shell/shell/CMakeLists.txt b/bundles/shell/shell/CMakeLists.txt index 140f4ea4f..e9320e011 100644 --- a/bundles/shell/shell/CMakeLists.txt +++ b/bundles/shell/shell/CMakeLists.txt @@ -23,11 +23,6 @@ if (SHELL_API) ) target_link_libraries(shell_api INTERFACE Celix::utils) - target_include_directories(shell_api INTERFACE $) - if (CELIX_INSTALL_DEPRECATED_API) - install(DIRECTORY deprecated_api/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/shell COMPONENT shell) - endif () - install(TARGETS shell_api EXPORT celix COMPONENT shell INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/shell) install(DIRECTORY api/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/shell COMPONENT shell) @@ -68,11 +63,7 @@ if (SHELL) ) target_include_directories(shell PRIVATE src) target_link_libraries(shell PRIVATE shell_commands Celix::shell_api Celix::log_helper) - target_compile_options(shell PRIVATE -Wno-deprecated-declarations) celix_deprecated_utils_headers(shell) - if (CELIX_INSTALL_DEPRECATED_API) - target_compile_definitions(shell PRIVATE CELIX_INSTALL_DEPRECATED_API) - endif () install_celix_bundle(shell EXPORT celix COMPONENT shell) #Setup target aliases to match external usage diff --git a/bundles/shell/shell/deprecated_api/command.h b/bundles/shell/shell/deprecated_api/command.h deleted file mode 100644 index c3fae14b2..000000000 --- a/bundles/shell/shell/deprecated_api/command.h +++ /dev/null @@ -1,53 +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. - */ - -#ifndef COMMAND_H_ -#define COMMAND_H_ - -#include "celix_errno.h" -#include - -#define OSGI_SHELL_COMMAND_NAME "command.name" -#define OSGI_SHELL_COMMAND_USAGE "command.usage" -#define OSGI_SHELL_COMMAND_DESCRIPTION "command.description" - -#define OSGI_SHELL_COMMAND_SERVICE_NAME "commandService" -#define OSGI_SHELL_COMMAND_SERVICE_VERSION "1.0.0" - -typedef struct commandService command_service_t; -typedef command_service_t * command_service_pt; - - -/** - * The command service can be used to register additional shell commands. - * The service should be register with the following properties: - * - command.name: mandatory, name of the command e.g. 'lb' - * - command.usage: optional, string describing how tu use the command e.g. 'lb [-l | -s | -u]' - * - command.description: optional, string describing the command e.g. 'list bundles.' - * - * \deprecated Replaced by celix_shell_command_t - */ -struct commandService { - void *handle; - - celix_status_t (*executeCommand)(void *handle, char * commandLine, FILE *outStream, FILE *errorStream) __attribute__((deprecated("command_service_t is replaced by celix_shell_command_t in celix_shell_command.h"))); -}; - - -#endif /* COMMAND_H_ */ diff --git a/bundles/shell/shell/deprecated_api/shell.h b/bundles/shell/shell/deprecated_api/shell.h deleted file mode 100644 index 5a852ed22..000000000 --- a/bundles/shell/shell/deprecated_api/shell.h +++ /dev/null @@ -1,31 +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. - */ -#ifndef SHELL_H_ -#define SHELL_H_ - -#include "celix_shell.h" - -#define OSGI_SHELL_SERVICE_NAME CELIX_SHELL_SERVICE_NAME -#define OSGI_SHELL_SERVICE_VERSION CELIX_SHELL_SERVICE_VERSION - -//NOTE celix_shell_t is a backwards compatible service for - the deprecated - shell_service_t. -typedef celix_shell_t shell_service_t; //use celix_shell.h instead -typedef celix_shell_t* shell_service_pt; //use celix_shell.h instead - -#endif /* SHELL_H_ */ diff --git a/bundles/shell/shell/deprecated_api/shell_constants.h b/bundles/shell/shell/deprecated_api/shell_constants.h deleted file mode 100644 index 37f1750af..000000000 --- a/bundles/shell/shell/deprecated_api/shell_constants.h +++ /dev/null @@ -1,28 +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. - */ - -#ifndef SHELL_CONSTANTS_H_ -#define SHELL_CONSTANTS_H_ - -#include "celix_shell_constants.h" - -#define SHELL_USE_ANSI_COLORS CELIX_SHELL_USE_ANSI_COLORS -#define SHELL_USE_ANSI_COLORS_DEFAULT_VALUE CELIX_SHELL_USE_ANSI_COLORS_DEFAULT_VALUE - -#endif /* SHELL_CONSTANTS_H_ */ diff --git a/bundles/shell/shell/gtest/CMakeLists.txt b/bundles/shell/shell/gtest/CMakeLists.txt index 2167e07dd..91a50aef6 100644 --- a/bundles/shell/shell/gtest/CMakeLists.txt +++ b/bundles/shell/shell/gtest/CMakeLists.txt @@ -22,9 +22,6 @@ add_executable(test_shell target_link_libraries(test_shell PRIVATE Celix::framework Celix::shell_api GTest::gtest GTest::gtest_main) celix_target_bundle_set_definition(test_shell NAME TEST_BUNDLES Celix::shell) target_compile_options(test_shell PRIVATE -Wno-deprecated-declarations) -if (CELIX_INSTALL_DEPRECATED_API) - target_compile_definitions(test_shell PRIVATE CELIX_INSTALL_DEPRECATED_API) -endif () add_test(NAME test_shell COMMAND test_shell) setup_target_for_coverage(test_shell SCAN_DIR ..) diff --git a/bundles/shell/shell/gtest/src/ShellTestSuite.cc b/bundles/shell/shell/gtest/src/ShellTestSuite.cc index 8c43e016d..8ee7c0157 100644 --- a/bundles/shell/shell/gtest/src/ShellTestSuite.cc +++ b/bundles/shell/shell/gtest/src/ShellTestSuite.cc @@ -214,26 +214,6 @@ TEST_F(ShellTestSuite, localNameClashTest) { } -#ifdef CELIX_INSTALL_DEPRECATED_API -#include "command.h" -TEST_F(ShellTestSuite, legacyCommandTest) { - command_service_t cmdService; - cmdService.handle = nullptr; - cmdService.executeCommand = [](void *, char* cmdLine, FILE *, FILE *) -> celix_status_t { - EXPECT_TRUE(cmdLine != nullptr); - return CELIX_SUCCESS; - }; - - celix_properties_t *props = celix_properties_create(); - celix_properties_set(props, OSGI_SHELL_COMMAND_NAME, "testCommand"); - long svcId = celix_bundleContext_registerService(ctx.get(), &cmdService, OSGI_SHELL_COMMAND_SERVICE_NAME, props); - - callCommand(ctx, "testCommand", true); - - celix_bundleContext_unregisterService(ctx.get(), svcId); -} -#endif - #ifdef CXX_SHELL #include "celix/BundleContext.h" #include "celix/IShellCommand.h" diff --git a/bundles/shell/shell/src/c_shell.c b/bundles/shell/shell/src/c_shell.c index d4f063b10..ad386b6a7 100644 --- a/bundles/shell/shell/src/c_shell.c +++ b/bundles/shell/shell/src/c_shell.c @@ -113,62 +113,6 @@ celix_status_t shell_removeCommand(shell_t *shell, celix_shell_command_t *svc, c return status; } -#ifdef CELIX_INSTALL_DEPRECATED_API -celix_status_t shell_addLegacyCommand(shell_t *shell, command_service_t *svc, const celix_properties_t *props) { - celix_status_t status = CELIX_SUCCESS; - const char *name = celix_properties_get(props, OSGI_SHELL_COMMAND_NAME, NULL); - - if (name == NULL) { - celix_logHelper_log(shell->logHelper, CELIX_LOG_LEVEL_WARNING, "Command service must contain a '%s' property!", CELIX_SHELL_COMMAND_NAME); - status = CELIX_BUNDLE_EXCEPTION; - } else { - long svcId = celix_properties_getAsLong(props, OSGI_FRAMEWORK_SERVICE_ID, -1L); - celixThreadRwlock_writeLock(&shell->lock); - if (hashMap_containsKey(shell->legacyCommandServices, name)) { - celix_logHelper_log(shell->logHelper, CELIX_LOG_LEVEL_WARNING, "Command with name %s already registered!", name); - } else { - celix_legacy_command_entry_t *entry = calloc(1, sizeof(*entry)); - entry->svcId = svcId; - entry->svc = svc; - entry->props = props; - hashMap_put(shell->legacyCommandServices, (void*)name, entry); - } - celixThreadRwlock_unlock(&shell->lock); - } - - return status; -} -#endif - -#ifdef CELIX_INSTALL_DEPRECATED_API -celix_status_t shell_removeLegacyCommand(shell_t *shell, command_service_t *svc, const celix_properties_t *props) { - celix_status_t status = CELIX_SUCCESS; - const char *name = celix_properties_get(props, OSGI_SHELL_COMMAND_NAME, NULL); - - if (name == NULL) { - celix_logHelper_log(shell->logHelper, CELIX_LOG_LEVEL_WARNING, "Command service must contain a '%s' property!", OSGI_SHELL_COMMAND_NAME); - status = CELIX_BUNDLE_EXCEPTION; - } else { - long svcId = celix_properties_getAsLong(props, OSGI_FRAMEWORK_SERVICE_ID, -1L); - celixThreadRwlock_writeLock(&shell->lock); - if (hashMap_containsKey(shell->legacyCommandServices, name)) { - celix_legacy_command_entry_t *entry = hashMap_get(shell->legacyCommandServices, name); - if (entry->svcId == svcId) { - hashMap_remove(shell->legacyCommandServices, name); - free(entry); - } else { - celix_logHelper_log(shell->logHelper, CELIX_LOG_LEVEL_WARNING, "svc id for command with name %s does not match (%li == %li)!", name, svcId, entry->svcId); - } - } else { - celix_logHelper_log(shell->logHelper, CELIX_LOG_LEVEL_WARNING, "Cannot find shell command with name %s!", name); - } - celixThreadRwlock_unlock(&shell->lock); - } - - return status; -} -#endif - celix_status_t shell_getCommands(shell_t *shell, celix_array_list_t **outCommands) { celix_status_t status = CELIX_SUCCESS; celix_array_list_t *result = celix_arrayList_create(); diff --git a/bundles/shell/shell/src/c_shell_activator.c b/bundles/shell/shell/src/c_shell_activator.c index eaae2aaf8..6dcc0d5d9 100644 --- a/bundles/shell/shell/src/c_shell_activator.c +++ b/bundles/shell/shell/src/c_shell_activator.c @@ -36,7 +36,6 @@ struct shell_bundle_activator { long shellSvcId; long trackerId; - long legacyTrackerId; }; typedef struct shell_bundle_activator shell_bundle_activator_t; @@ -109,21 +108,8 @@ celix_status_t celix_bundleActivator_start(void *activatorData, celix_bundle_con opts.filter.ignoreServiceLanguage = true; opts.filter.serviceName = CELIX_SHELL_COMMAND_SERVICE_NAME; activator->trackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts); - activator->legacyTrackerId = -1L; } -#ifdef CELIX_INSTALL_DEPRECATED_API - if (status == CELIX_SUCCESS) { - celix_service_tracking_options_t opts = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS; - opts.callbackHandle = activator->shell; - opts.addWithProperties = (void*) shell_addLegacyCommand; - opts.removeWithProperties = (void*) shell_removeLegacyCommand; - opts.filter.ignoreServiceLanguage = true; - opts.filter.serviceName = OSGI_SHELL_COMMAND_SERVICE_NAME; - activator->legacyTrackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts); - } -#endif - return status; } @@ -136,8 +122,6 @@ celix_status_t celix_bundleActivator_stop(void *activatorData, celix_bundle_cont celix_stdCommands_destroy(activator->stdCommands); celix_bundleContext_unregisterService(ctx, activator->shellSvcId); celix_bundleContext_stopTracker(ctx, activator->trackerId); - celix_bundleContext_stopTracker(ctx, activator->legacyTrackerId); - } else { status = CELIX_ILLEGAL_ARGUMENT; } diff --git a/bundles/shell/shell_bonjour/CMakeLists.txt b/bundles/shell/shell_bonjour/CMakeLists.txt deleted file mode 100644 index 929c1b7f2..000000000 --- a/bundles/shell/shell_bonjour/CMakeLists.txt +++ /dev/null @@ -1,54 +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(SHELL_BONJOUR "Option to enable building the Bonjour Shell (shell access by chat clients)" OFF) -if (SHELL_BONJOUR) - message(WARNING "Celix::bonjour_shell is considered unstable, because develop of this bundle has been dormant for a while") - find_package(LibXml2 REQUIRED) - find_package(DNSSD REQUIRED) - - set(BUNDLE_SYMBOLICNAME "bonjour_shell") - set(BUNDLE_VERSION "0.1.0") - set(BUNDLE_NAME "bonjour_shell") - - add_celix_bundle(bonjour_shell - VERSION "1.0.0" - FILENAME celix_bonjour_shell - GROUP "Celix/Shell" - SOURCES - private/src/activator.c - private/src/bonjour_shell.c - ) - celix_deprecated_utils_headers(bonjour_shell) - celix_deprecated_framework_headers(bonjour_shell) - - target_include_directories(bonjour_shell PRIVATE - "${PROJECT_SOURCE_DIR}/utils/public/include" - "${LIBXML2_INCLUDE_DIR}" - private/include - ) - target_link_libraries(bonjour_shell PRIVATE ${LIBXML2_LIBRARIES} DNSSD::DNSSD Celix::shell_api) - install_celix_bundle(bonjour_shell EXPORT celix COMPONENT bonjour_shell) - add_library(Celix::bonjour_shell ALIAS bonjour_shell) - - add_celix_container("bonjour_shell_deploy" BUNDLES - Celix::shell - bonjour_shell - PROPERTIES "bonjour.shell.id=Apache Celix" - ) -endif (SHELL_BONJOUR) - diff --git a/bundles/shell/shell_bonjour/private/include/bonjour_shell.h b/bundles/shell/shell_bonjour/private/include/bonjour_shell.h deleted file mode 100644 index dea89bb17..000000000 --- a/bundles/shell/shell_bonjour/private/include/bonjour_shell.h +++ /dev/null @@ -1,43 +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. - */ -/** - * bonjour_shell.h - * - * \date Oct 20, 2014 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef BONJOUR_SHELL_H_ -#define BONJOUR_SHELL_H_ - -#include - -#include "celix_errno.h" - -typedef struct bonjour_shell *bonjour_shell_pt; - -celix_status_t bonjourShell_create(char *id, bonjour_shell_pt *shell); -celix_status_t bonjourShell_destroy(bonjour_shell_pt shell); - -celix_status_t bonjourShell_addShellService(void * handle, service_reference_pt reference, void * service); -celix_status_t bonjourShell_removeShellService(void * handle, service_reference_pt reference, void * service); - - -#endif /* BONJOUR_SHELL_H_ */ diff --git a/bundles/shell/shell_bonjour/private/src/activator.c b/bundles/shell/shell_bonjour/private/src/activator.c deleted file mode 100644 index 23e93f63e..000000000 --- a/bundles/shell/shell_bonjour/private/src/activator.c +++ /dev/null @@ -1,110 +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. - */ -/** - * activator.c - * - * \date Oct 20, 2014 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include - -#include - -#include "bundle_activator.h" -#include "bundle_context.h" -#include "celix_constants.h" - -#include "bonjour_shell.h" - -#include -#include -#include - -struct bundle_instance { - bonjour_shell_pt shell; - service_tracker_pt tracker; -}; - -typedef struct bundle_instance *bundle_instance_pt; - -celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) { - celix_status_t status = CELIX_SUCCESS; - struct bundle_instance *bi = calloc(1, sizeof(*bi)); - - if (bi) { - bi->shell = NULL; - bi->tracker = NULL; - (*userData) = bi; - } else { - status = CELIX_ENOMEM; - - } - return status; -} - -celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { - celix_status_t status = CELIX_SUCCESS; - bundle_instance_pt bi = (bundle_instance_pt) userData; - - const char *uuid = NULL; - bundleContext_getProperty(context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid); - const char *hostname = NULL; - bundleContext_getProperty(context, "HOSTNAME", &hostname); - const char *bonjourShellId = NULL; - bundleContext_getProperty(context, "bonjour.shell.id", &bonjourShellId); - - char id[128]; - if (bonjourShellId != NULL) { - snprintf(id, 128, "%s", bonjourShellId); - } else if (hostname != NULL) { - snprintf(id, 128, "Celix-%.8s@%s", uuid, hostname); - } else { - snprintf(id, 128, "Celix-%.8s", uuid); - } - status = bonjourShell_create(id, &bi->shell); - - service_tracker_customizer_pt cust = NULL; - serviceTrackerCustomizer_create(bi->shell, NULL, bonjourShell_addShellService, NULL, bonjourShell_removeShellService, &cust); - serviceTracker_create(context, (char *) OSGI_SHELL_SERVICE_NAME, cust, &bi->tracker); - serviceTracker_open(bi->tracker); - - - return status; -} - -celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) { - celix_status_t status = CELIX_SUCCESS; - bundle_instance_pt bi = (bundle_instance_pt) userData; - - serviceTracker_close(bi->tracker); - - return status; -} - -celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) { - celix_status_t status = CELIX_SUCCESS; - bundle_instance_pt bi = (bundle_instance_pt) userData; - - serviceTracker_destroy(bi->tracker); - bonjourShell_destroy(bi->shell); - - return status; -} diff --git a/bundles/shell/shell_bonjour/private/src/bonjour_shell.c b/bundles/shell/shell_bonjour/private/src/bonjour_shell.c deleted file mode 100644 index 8bceacf91..000000000 --- a/bundles/shell/shell_bonjour/private/src/bonjour_shell.c +++ /dev/null @@ -1,445 +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. - */ -/** - * bonjour_shell.c - * - * \date Oct 20, 2014 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include "bonjour_shell.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#if CELIX_UTILS_NO_MEMSTREAM_AVAILABLE -#include "open_memstream.h" -#include "fmemopen.h" -#endif - -#define MAX_BUFFER_SIZE 5120 - -//static xmlBufferPtr buf; //FOR DEBUG - -struct bonjour_shell { - char *id; - volatile bool running; - - //service member and mutex - pthread_mutex_t mutex; - shell_service_pt service; - - //tcp socket members - pthread_t listenThread; - int listenSocket; - uint16_t portInNetworkByteOrder; - - //dns_sd registration - DNSServiceRef sdRef; - TXTRecordRef txtRecord; - -}; - -struct connection_context { - bool gotCommand; - bool running; - int sockfd; - bonjour_shell_pt shell; - xmlTextWriterPtr writer; - xmlTextReaderPtr reader; - pthread_t sendThread; - pthread_mutex_t mutex; - pthread_cond_t dataAvailCond; - array_list_pt dataList; //protected by mutex - struct timeval lastUpdated; //protected by mutex -}; - -static struct connection_context *currentContext = NULL; //TODO update shell to accept void * data next to callback - -static void bonjourShell_addDataToCurrentContext(const char* out, const char* err); -static void bonjourShell_sendData(struct connection_context *context); - -static celix_status_t bonjourShell_register(bonjour_shell_pt shell); -static celix_status_t bonjourShell_listen(bonjour_shell_pt shell); - -static void bonjourShell_acceptConnection(bonjour_shell_pt shell, int connectionFd); - -static void bonjourShell_parse(bonjour_shell_pt shell, struct connection_context *context); -static void bonjourShell_parseXmlNode(bonjour_shell_pt shell, struct connection_context *context); - -static void bonjourShell_parseStream(bonjour_shell_pt shell, struct connection_context *context); -static void bonjourShell_parseCommand(bonjour_shell_pt shell, struct connection_context *context); - -celix_status_t bonjourShell_create(char *id, bonjour_shell_pt *result) { - celix_status_t status = CELIX_SUCCESS; - bonjour_shell_pt shell = (bonjour_shell_pt) calloc(1, sizeof(*shell)); - if (shell != NULL) { - shell->id = strdup(id); - shell->running = true; - shell->listenSocket = 0; - shell->service = NULL; - - pthread_mutex_init(&shell->mutex, NULL); - - pthread_create(&shell->listenThread, NULL, (void *)bonjourShell_listen, shell); - - (*result) = shell; - } else { - status = CELIX_ENOMEM; - } - return status; -} - -static celix_status_t bonjourShell_register(bonjour_shell_pt shell) { - celix_status_t status = CELIX_SUCCESS; - - uint16_t portInNetworkByteOrder = shell->portInNetworkByteOrder; - char *srvName = shell->id; - char portStr[64]; - sprintf(portStr, "%i", ntohs(portInNetworkByteOrder)); - - TXTRecordCreate(&shell->txtRecord, 256, NULL); - - TXTRecordSetValue(&shell->txtRecord, "txtver", 1, "1"); - TXTRecordSetValue(&shell->txtRecord, "version", 1, "1");; - TXTRecordSetValue(&shell->txtRecord, "1st", strlen(shell->id), shell->id); - TXTRecordSetValue(&shell->txtRecord, "port.p2pj", 5, portStr); - TXTRecordSetValue(&shell->txtRecord, "status", 5, "avail"); - - DNSServiceRegister(&shell->sdRef, 0, 0, - srvName, /* may be NULL */ - "_presence._tcp", - NULL, /* may be NULL */ - NULL, /* may be NULL */ - portInNetworkByteOrder, /* In network byte order */ - TXTRecordGetLength(&shell->txtRecord), TXTRecordGetBytesPtr(&shell->txtRecord), /* may be NULL */ - NULL, /* may be NULL */ - NULL /* may be NULL */ - ); - - //DNSServiceProcessResult(shell->sdRef); - - return status; -} - -static celix_status_t bonjourShell_listen(bonjour_shell_pt shell) { - celix_status_t status = CELIX_SUCCESS; - - - shell->listenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (shell->listenSocket < 0) { - printf("error opening socket\n"); - return CELIX_START_ERROR; - } - - struct sockaddr_in serv_addr; - memset(&serv_addr, 0, sizeof(serv_addr)); /* Clear struct */ - serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); /* Incoming addr */ - serv_addr.sin_family = AF_INET; /* Internet/IP */ - serv_addr.sin_port = 0; /* server port, don't specify let os decide */ - - if (bind(shell->listenSocket, (struct sockaddr *) &serv_addr, sizeof(struct sockaddr_in)) < 0) { - printf("error binding\n"); - return CELIX_START_ERROR; - } - - if (listen(shell->listenSocket, 1) < 0) { - printf("error listening"); - return CELIX_START_ERROR; - } - - struct sockaddr_in sin; - socklen_t len = sizeof(sin); - if (getsockname(shell->listenSocket, (struct sockaddr *)&sin, &len) == -1) { - perror("getsockname"); - return CELIX_START_ERROR; - } else { - shell->portInNetworkByteOrder = sin.sin_port; - } - - status = bonjourShell_register(shell); - if (status != CELIX_SUCCESS) { - return status; - } - - struct sockaddr_in connect_addr; - socklen_t slen = sizeof(struct sockaddr_in); - while (shell->running) { - int connectionSocket = accept(shell->listenSocket, (struct sockaddr *) &connect_addr, &slen); - if (connectionSocket < 0) { - printf("error accepting connection\n"); - return CELIX_START_ERROR; - } else { - bonjourShell_acceptConnection(shell, connectionSocket); - } - } - - return status; -} - -static void bonjourShell_acceptConnection(bonjour_shell_pt shell, int connectionFd) { - //printf("setting up parser\n"); - - struct connection_context context; - context.gotCommand = false; - context.running = true; - context.sockfd = connectionFd; - context.shell = shell; - - context.reader = xmlReaderForFd(context.sockfd, NULL, NULL, 0); - - xmlOutputBufferPtr outputBuff = xmlOutputBufferCreateFd(context.sockfd, - NULL); - context.writer = xmlNewTextWriter(outputBuff); - - //buf = xmlBufferCreate(); - //xmlTextWriterPtr writer = xmlNewTextWriterMemory(buf, 0); - - //init send thread and needed data types. - arrayList_create(&context.dataList); - pthread_cond_init(&context.dataAvailCond, NULL); //TODO destroy - pthread_mutex_init(&context.mutex, NULL); //TODO destroy - pthread_create(&context.sendThread, NULL, (void *)bonjourShell_sendData, &context); - - int sockStatus = 0; - if (context.reader != NULL && context.writer != NULL) { - while (sockStatus == 0 && shell->running && context.running) { - bonjourShell_parse(shell, &context); - - //check if socket is closed - int error = 0; - socklen_t len = sizeof(error); - sockStatus = getsockopt(context.sockfd, SOL_SOCKET, SO_ERROR, - &error, &len); - if (sockStatus != 0) { - printf("Got error from socket error is %i", error); - } - } - - if (sockStatus == 0) { //shell stopped still connected - usleep(1500); //wait until all data is send - xmlTextWriterEndElement(context.writer); //end stream - xmlTextWriterEndDocument(context.writer); - close(context.sockfd); - xmlFreeTextReader(context.reader); - xmlFreeTextWriter(context.writer); - } - //printf("after close + free of xml parser & socker\n"); - - context.running = false; - pthread_cond_signal(&context.dataAvailCond); - - pthread_join(context.sendThread, NULL); - pthread_mutex_destroy(&context.mutex); - pthread_cond_destroy(&context.dataAvailCond); - } else { - if (context.reader != NULL) { - xmlFreeTextReader(context.reader); - } - if (context.writer != NULL) { - xmlFreeTextWriter(context.writer); - } - } - arrayList_destroy(context.dataList); - -} - -static void bonjourShell_parse(bonjour_shell_pt shell, struct connection_context *context) { - xmlTextReaderRead(context->reader); - bonjourShell_parseXmlNode(shell, context); -} - -static void bonjourShell_parseXmlNode(bonjour_shell_pt shell, struct connection_context *context) { - xmlChar *name; - - int nodeType = xmlTextReaderNodeType(context->reader); - - if (nodeType == XML_READER_TYPE_ELEMENT) { - name = xmlTextReaderLocalName(context->reader); - //printf("found element with name %s\n", name); - if (strcmp((char *)name, "stream") == 0) { - bonjourShell_parseStream(shell, context); - } else if (strcmp((char *)name, "body") == 0 && context->gotCommand == false) { - bonjourShell_parseCommand(shell, context); //assuming first body element is command - } else if (strcmp((char *)name, "message") == 0) { - context->gotCommand = false; - } - xmlFree(name); - } else if (nodeType == XML_READER_TYPE_END_ELEMENT /*end element*/ ) { - name = xmlTextReaderLocalName(context->reader); - //printf("found END element with name %s\n", name); - if (strcmp((char *)name, "stream") == 0) { - context->running = false; - } - xmlFree(name); - } else { - //printf("found node type %i\n", nodeType); - } -} - -static void bonjourShell_parseStream(bonjour_shell_pt shell, struct connection_context *context) { - xmlChar *to = xmlTextReaderGetAttribute(context->reader, (xmlChar *)"from"); - xmlChar *from = xmlTextReaderGetAttribute(context->reader, (xmlChar *)"to"); - - xmlTextWriterStartDocument(context->writer, NULL, NULL, NULL); - xmlTextWriterStartElementNS(context->writer, (xmlChar *)"stream", (xmlChar *)"stream", (xmlChar *)"http://etherx.jabber.org/streams"); - xmlTextWriterWriteAttribute(context->writer, (xmlChar *)"xmlns", (xmlChar *)"jabber:client"); //TODO should use namespace method/ - xmlTextWriterWriteAttribute(context->writer, (xmlChar *)"to", to); - xmlTextWriterWriteAttribute(context->writer, (xmlChar *)"from", from); - xmlTextWriterWriteAttribute(context->writer, (xmlChar *)"version", (xmlChar *)"1.0"); - - xmlTextWriterWriteString(context->writer, (xmlChar *)"\n"); //Needed to flush to writer - xmlTextWriterFlush(context->writer); - //printf("current context buf: %s\n", (char *)buf->content); - - if (from != NULL) { - xmlFree(from); - } - if (to != NULL) { - xmlFree(to); - } -} - -static void bonjourShell_parseCommand(bonjour_shell_pt shell, struct connection_context *context) -{ - xmlChar *command = xmlTextReaderReadString(context->reader); - - if (command != NULL) { - context->gotCommand = true; - currentContext = context; - pthread_mutex_lock(&shell->mutex); - if (shell->service != NULL) { - char *outbuf; - size_t outsize; - char *errbuf; - size_t errsize; - - FILE *out = open_memstream(&outbuf, &outsize); - FILE *err = open_memstream(&errbuf, &errsize); - - shell->service->executeCommand(shell->service->handle, (char *) command, out, err); - - fclose(out); - fclose(err); - bonjourShell_addDataToCurrentContext(outbuf, errbuf); - free(outbuf); - free(errbuf); - } - pthread_mutex_unlock(&shell->mutex); - } - - if (command != NULL) { - xmlFree(command); - } -} - -static void bonjourShell_addDataToCurrentContext(const char* out, const char* err) { - pthread_mutex_lock(¤tContext->mutex); - if (out != NULL) { - arrayList_add(currentContext->dataList, strdup(out)); - } - if (err != NULL) { - arrayList_add(currentContext->dataList, strdup(err)); - } - gettimeofday(¤tContext->lastUpdated, NULL); - pthread_mutex_unlock(¤tContext->mutex); - pthread_cond_signal(¤tContext->dataAvailCond); -} - -static void bonjourShell_sendData(struct connection_context *context) { - while (context->running == true ) { - pthread_mutex_lock(&context->mutex); - pthread_cond_wait(&context->dataAvailCond, &context->mutex); //wait till some data is ready. - - struct timeval now; - while (context->running) { - gettimeofday(&now, NULL); - long elapsed = (now.tv_sec * 1000000 + now.tv_usec) - (context->lastUpdated.tv_sec * 1000000 + context->lastUpdated.tv_usec); - if (elapsed > 1000) { //usec passed without update of data. - break; - } - pthread_mutex_unlock(&context->mutex); - usleep(1000); - pthread_mutex_lock(&context->mutex); - } - - if (context->running) { - xmlTextWriterStartElement(currentContext->writer, (xmlChar *)"message"); - xmlTextWriterWriteAttribute(currentContext->writer, (xmlChar *)"type", (xmlChar *)"chat"); - xmlTextWriterStartElement(currentContext->writer, (xmlChar *)"body"); - xmlTextWriterWriteString(currentContext->writer, (xmlChar *)"\n"); - int i; - int size = arrayList_size(context->dataList); - for ( i = 0 ; i < size ; i += 1) { - char *entry = arrayList_get(context->dataList, i); - xmlTextWriterWriteString(currentContext->writer, (xmlChar *)entry); - //xmlTextWriterWriteString(currentContext->writer, (xmlChar *)"\r"); //needed for adium to create new line in UI - free(entry); - } - arrayList_clear(context->dataList); - xmlTextWriterEndElement(currentContext->writer); //end body - xmlTextWriterEndElement(currentContext->writer); //end message - xmlTextWriterWriteString(currentContext->writer, (xmlChar *)"\n"); //flush - xmlTextWriterFlush(currentContext->writer); - } - pthread_mutex_unlock(&context->mutex); - } -} - - -celix_status_t bonjourShell_destroy(bonjour_shell_pt shell) { - DNSServiceRefDeallocate(shell->sdRef); - TXTRecordDeallocate(&shell->txtRecord); - - close(shell->listenSocket); - pthread_join(shell->listenThread, NULL); - free(shell->id); - free(shell); - return CELIX_SUCCESS; -} - -celix_status_t bonjourShell_addShellService(void * handle, service_reference_pt reference, void * service) { - bonjour_shell_pt shell = handle; - pthread_mutex_lock(&shell->mutex); - shell->service = service; - pthread_mutex_unlock(&shell->mutex); - return CELIX_SUCCESS; -} - -celix_status_t bonjourShell_removeShellService(void * handle, service_reference_pt reference, void * service) { - bonjour_shell_pt shell = handle; - pthread_mutex_lock(&shell->mutex); - if (shell->service == service) { - shell->service = NULL; - } - pthread_mutex_unlock(&shell->mutex); - return CELIX_SUCCESS; -} diff --git a/conanfile.py b/conanfile.py index 5899c15e4..da2790851 100644 --- a/conanfile.py +++ b/conanfile.py @@ -64,7 +64,6 @@ class CelixConan(ConanFile): "build_pubsub_examples": False, "build_pubsub_integration": False, "build_pubsub_psa_tcp": False, - "build_pubsub_psa_udp_mc": False, "build_pubsub_psa_ws": False, "build_pubsub_discovery_etcd": False, "build_cxx_remote_service_admin": False, @@ -80,7 +79,6 @@ class CelixConan(ConanFile): "build_shell": False, "build_shell_api": False, "build_remote_shell": False, - "build_shell_bonjour": False, "build_shell_tui": False, "build_shell_wui": False, "build_components_ready_check": False, @@ -102,6 +100,7 @@ class CelixConan(ConanFile): "enable_testing_on_ci": False, "framework_curlinit": True, "enable_ccache": False, + "enable_deprecated_warnings": False, } options = { "celix_err_buffer_size": ["ANY"], @@ -126,9 +125,6 @@ def validate(self): if self.options.build_rsa_discovery_zeroconf and self.settings.os != "Linux": raise ConanInvalidConfiguration("Celix build_rsa_discovery_zeroconf is only supported for Linux") - if self.options.build_shell_bonjour and self.settings.os != "Linux": - raise ConanInvalidConfiguration("Celix build_shell_bonjour is only supported for Linux") - try: val = int(self.options.celix_err_buffer_size) if val <= 0: @@ -143,12 +139,12 @@ def package_id(self): del self.info.options.build_pubsub_examples del self.info.options.build_cxx_rsa_integration del self.info.options.build_examples - del self.info.options.build_shell_bonjour del self.info.options.enable_testing_dependency_manager_for_cxx11 del self.info.options.enable_testing_for_cxx14 del self.info.options.enable_cmake_warning_tests del self.info.options.enable_testing_on_ci del self.info.options.enable_ccache + del self.info.options.enable_deprecated_warnings def build_requirements(self): if self.options.enable_testing: @@ -173,7 +169,6 @@ def configure(self): if self.settings.os != "Linux": options["build_rsa_remote_service_admin_shm_v2"] = False options["build_rsa_discovery_zeroconf"] = False - options["build_shell_bonjour"] = False if options["enable_code_coverage"]: options["enable_testing"] = True @@ -184,9 +179,6 @@ def configure(self): options["build_log_service"] = True options["build_syslog_writer"] = True - if options["build_shell_bonjour"]: - options["build_shell"] = True - if options["build_cxx_rsa_integration"]: options["build_cxx_remote_service_admin"] = True options["build_pushstreams"] = True @@ -225,8 +217,7 @@ def configure(self): options["build_http_admin"] = True options["build_pubsub"] = True - if options["build_pubsub_psa_zmq"] or options["build_pubsub_psa_tcp"] \ - or options["build_pubsub_psa_udp_mc"]: + if options["build_pubsub_psa_zmq"] or options["build_pubsub_psa_tcp"]: options["build_pubsub"] = True if options["build_pubsub_wire_protocol_v1"]: @@ -351,8 +342,8 @@ def configure(self): self.options['gtest'].shared = True if self.options.enable_address_sanitizer: self.options["cpputest"].with_leak_detection = False - if (self.options.build_rsa_discovery_common or self.options.build_shell_bonjour or - (self.options.build_rsa_remote_service_admin_dfi and self.options.enable_testing)): + if (self.options.build_rsa_discovery_common + or (self.options.build_rsa_remote_service_admin_dfi and self.options.enable_testing)): self.options['libxml2'].shared = True if self.options.build_pubsub_psa_zmq: self.options['zeromq'].shared = True @@ -376,8 +367,8 @@ def requirements(self): or self.options.build_rsa_discovery_common or self.options.build_rsa_remote_service_admin_dfi or self.options.build_launcher): self.requires("libcurl/[>=7.64.1 <8.0.0]") - if (self.options.build_rsa_discovery_common or self.options.build_shell_bonjour or - (self.options.build_rsa_remote_service_admin_dfi and self.options.enable_testing)): + if (self.options.build_rsa_discovery_common + or (self.options.build_rsa_remote_service_admin_dfi and self.options.enable_testing)): self.requires("libxml2/[>=2.9.9 <3.0.0]") if self.options.build_cxx_remote_service_admin: self.requires("rapidjson/[>=1.1.0 <2.0.0]") @@ -391,7 +382,7 @@ def requirements(self): self.requires("libffi/[>=3.2.1 <4.0.0]") if self.options.build_celix_dfi or self.options.build_celix_etcdlib: self.requires("jansson/[>=2.12 <3.0.0]") - if self.options.build_rsa_discovery_zeroconf or self.options.build_shell_bonjour: + if self.options.build_rsa_discovery_zeroconf: # TODO: To be replaced with mdnsresponder/1790.80.10, resolve some problems of mdnsresponder # https://github.com/conan-io/conan-center-index/pull/16254 self.requires("mdnsresponder/1310.140.1") diff --git a/examples/conan_test_package/CMakeLists.txt b/examples/conan_test_package/CMakeLists.txt index 868568275..13132c31b 100644 --- a/examples/conan_test_package/CMakeLists.txt +++ b/examples/conan_test_package/CMakeLists.txt @@ -112,19 +112,6 @@ if (TEST_PSA_TCP) ) endif () -option(TEST_PSA_UDP_MC "Test UDP MC PubSub Admin" OFF) -if (TEST_PSA_UDP_MC) - add_celix_container(use_psa_udp_mc - BUNDLES - Celix::celix_pubsub_topology_manager - Celix::celix_pubsub_admin_udp_multicast - hello - PROPERTIES - PSA_UDPMC_VERBOSE=true - PUBSUB_TOPOLOGY_MANAGER_VERBOSE=true - ) -endif () - option(TEST_PSA_WS "Test WebSocket PubSub Admin" OFF) if (TEST_PSA_WS) add_celix_container(use_psa_ws @@ -390,11 +377,6 @@ if (TEST_SHELL_API) target_link_libraries(use_shell_api PRIVATE Celix::shell_api) endif () -option(TEST_SHELL_BONJOUR "Test shell bonjour" OFF) -if (TEST_SHELL_BONJOUR) - add_celix_container("use_shell_bonjour" INSTALL_BUNDLES Celix::bonjour_shell BUNDLES hello) -endif () - option(TEST_CELIX_DFI "Test Celix DFI" OFF) if (TEST_CELIX_DFI) add_executable(use_celix_dfi test_celix_dfi.c) diff --git a/examples/conan_test_package/conanfile.py b/examples/conan_test_package/conanfile.py index 8c41e12c3..d802dc199 100644 --- a/examples/conan_test_package/conanfile.py +++ b/examples/conan_test_package/conanfile.py @@ -33,7 +33,6 @@ def build(self): cmake.definitions["TEST_PUBSUB"] = self.options["celix"].build_pubsub cmake.definitions["TEST_PSA_ZMQ"] = self.options["celix"].build_pubsub_psa_zmq cmake.definitions["TEST_PSA_TCP"] = self.options["celix"].build_pubsub_psa_tcp - cmake.definitions["TEST_PSA_UDP_MC"] = self.options["celix"].build_pubsub_psa_udp_mc cmake.definitions["TEST_PSA_WS"] = self.options["celix"].build_pubsub_psa_ws cmake.definitions["TEST_PSA_DISCOVERY_ETCD"] = self.options["celix"].build_pubsub_discovery_etcd cmake.definitions["TEST_RSA"] = self.options["celix"].build_remote_service_admin @@ -61,7 +60,6 @@ def build(self): cmake.definitions["TEST_PUBSUB_AVROBIN_SERIALIZER"] = self.options["celix"].build_pubsub_avrobin_serializer cmake.definitions["TEST_CXX_REMOTE_SERVICE_ADMIN"] = self.options["celix"].build_cxx_remote_service_admin cmake.definitions["TEST_SHELL_API"] = self.options["celix"].build_shell_api - cmake.definitions["TEST_SHELL_BONJOUR"] = self.options["celix"].build_shell_bonjour cmake.definitions["TEST_CELIX_DFI"] = self.options["celix"].build_celix_dfi cmake.definitions["TEST_UTILS"] = self.options["celix"].build_utils cmake.definitions["TEST_COMPONENTS_READY_CHECK"] = self.options["celix"].build_components_ready_check @@ -90,8 +88,6 @@ def test(self): self.run("./use_psa_zmq", cwd=os.path.join("deploy", "use_psa_zmq"), run_environment=True) if self.options["celix"].build_pubsub_psa_tcp: self.run("./use_psa_tcp", cwd=os.path.join("deploy", "use_psa_tcp"), run_environment=True) - if self.options["celix"].build_pubsub_psa_udp_mc: - self.run("./use_psa_udp_mc", cwd=os.path.join("deploy", "use_psa_udp_mc"), run_environment=True) if self.options["celix"].build_pubsub_psa_ws: self.run("./use_psa_ws", cwd=os.path.join("deploy", "use_psa_ws"), run_environment=True) if self.options["celix"].build_pubsub_discovery_etcd and self.options["celix"].build_launcher: @@ -153,9 +149,6 @@ def test(self): self.run("./use_rsa_spi", run_environment=True) if self.options["celix"].build_shell_api: self.run("./use_shell_api", run_environment=True) - if self.options["celix"].build_shell_bonjour: - self.run("./use_shell_bonjour", - cwd=os.path.join("deploy", "use_shell_bonjour"), run_environment=True) if self.options["celix"].build_celix_dfi: self.run("./use_celix_dfi", run_environment=True) if self.options["celix"].build_utils: diff --git a/examples/conan_test_package/my_psa_activator.c b/examples/conan_test_package/my_psa_activator.c index 6c32125d6..abc44ec43 100644 --- a/examples/conan_test_package/my_psa_activator.c +++ b/examples/conan_test_package/my_psa_activator.c @@ -22,32 +22,14 @@ #include #include #include -#include #include typedef struct my_psa_activator { celix_log_helper_t *logHelper; - long serializersTrackerId; pubsub_admin_service_t adminService; long adminSvcId; } my_psa_activator_t; -static void myPsa_addSerializerSvc(void *handle, void *svc, const celix_properties_t *props) { - my_psa_activator_t *act = handle; - const char *serType = celix_properties_get(props, PUBSUB_SERIALIZER_TYPE_KEY, NULL); - long svcId = celix_properties_getAsLong(props, OSGI_FRAMEWORK_SERVICE_ID, -1L); - celix_logHelper_info(act->logHelper, "Serializer Added: %s=%s %s=%ld\n", - PUBSUB_SERIALIZER_TYPE_KEY, serType, OSGI_FRAMEWORK_SERVICE_ID, svcId); - -} - -static void myPsa_removeSerializerSvc(void *handle, void *svc, const celix_properties_t *props) { - my_psa_activator_t *act = handle; - const char *serType = celix_properties_get(props, PUBSUB_SERIALIZER_TYPE_KEY, NULL); - long svcId = celix_properties_getAsLong(props, OSGI_FRAMEWORK_SERVICE_ID, -1L); - celix_logHelper_info(act->logHelper, "Serializer Removed: %s=%s %s=%ld\n", - PUBSUB_SERIALIZER_TYPE_KEY, serType, OSGI_FRAMEWORK_SERVICE_ID, svcId); -} static celix_status_t matchPublisher(void *handle, long svcRequesterBndId, const celix_filter_t *svcFilter, celix_properties_t **outTopicProperties, @@ -137,21 +119,9 @@ static celix_status_t removeDiscoveredEndpoint(void *handle, const celix_propert int psa_udpmc_start(my_psa_activator_t *act, celix_bundle_context_t *ctx) { act->adminSvcId = -1L; - act->serializersTrackerId = -1L; act->logHelper = celix_logHelper_create(ctx, "my_psa_admin"); celix_status_t status = CELIX_SUCCESS; - //track serializers - if (status == CELIX_SUCCESS) { - celix_service_tracking_options_t opts = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS; - opts.filter.serviceName = PUBSUB_SERIALIZER_SERVICE_NAME; - opts.filter.ignoreServiceLanguage = true; - opts.callbackHandle = act; - opts.addWithProperties = myPsa_addSerializerSvc; - opts.removeWithProperties = myPsa_removeSerializerSvc; - act->serializersTrackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts); - } - //register pubsub admin service if (status == CELIX_SUCCESS) { pubsub_admin_service_t *psaSvc = &act->adminService; @@ -177,7 +147,6 @@ int psa_udpmc_start(my_psa_activator_t *act, celix_bundle_context_t *ctx) { int psa_udpmc_stop(my_psa_activator_t *act, celix_bundle_context_t *ctx) { celix_bundleContext_unregisterService(ctx, act->adminSvcId); - celix_bundleContext_stopTracker(ctx, act->serializersTrackerId); celix_logHelper_destroy(act->logHelper); return CELIX_SUCCESS; } diff --git a/examples/conan_test_package_v2/conanfile.py b/examples/conan_test_package_v2/conanfile.py index 12b352003..06feadccd 100644 --- a/examples/conan_test_package_v2/conanfile.py +++ b/examples/conan_test_package_v2/conanfile.py @@ -43,7 +43,6 @@ def generate(self): tc.cache_variables["TEST_PUBSUB"] = celix_options.build_pubsub tc.cache_variables["TEST_PSA_ZMQ"] = celix_options.build_pubsub_psa_zmq tc.cache_variables["TEST_PSA_TCP"] = celix_options.build_pubsub_psa_tcp - tc.cache_variables["TEST_PSA_UDP_MC"] = celix_options.build_pubsub_psa_udp_mc tc.cache_variables["TEST_PSA_WS"] = celix_options.build_pubsub_psa_ws tc.cache_variables["TEST_PSA_DISCOVERY_ETCD"] = celix_options.build_pubsub_discovery_etcd tc.cache_variables["TEST_RSA"] = celix_options.build_remote_service_admin @@ -71,7 +70,6 @@ def generate(self): tc.cache_variables["TEST_PUBSUB_AVROBIN_SERIALIZER"] = celix_options.build_pubsub_avrobin_serializer tc.cache_variables["TEST_CXX_REMOTE_SERVICE_ADMIN"] = celix_options.build_cxx_remote_service_admin tc.cache_variables["TEST_SHELL_API"] = celix_options.build_shell_api - tc.cache_variables["TEST_SHELL_BONJOUR"] = celix_options.build_shell_bonjour tc.cache_variables["TEST_CELIX_DFI"] = celix_options.build_celix_dfi tc.cache_variables["TEST_UTILS"] = celix_options.build_utils tc.cache_variables["TEST_COMPONENTS_READY_CHECK"] = celix_options.build_components_ready_check @@ -106,8 +104,6 @@ def test(self): self.run("./use_psa_zmq", cwd=os.path.join("deploy", "use_psa_zmq"), env="conanrun") if celix_options.build_pubsub_psa_tcp: self.run("./use_psa_tcp", cwd=os.path.join("deploy", "use_psa_tcp"), env="conanrun") - if celix_options.build_pubsub_psa_udp_mc: - self.run("./use_psa_udp_mc", cwd=os.path.join("deploy", "use_psa_udp_mc"), env="conanrun") if celix_options.build_pubsub_psa_ws: self.run("./use_psa_ws", cwd=os.path.join("deploy", "use_psa_ws"), env="conanrun") if celix_options.build_pubsub_discovery_etcd and celix_options.build_launcher: @@ -169,9 +165,6 @@ def test(self): self.run("./conan_test_package/use_rsa_spi", env="conanrun") if celix_options.build_shell_api: self.run("./conan_test_package/use_shell_api", env="conanrun") - if celix_options.build_shell_bonjour: - self.run("./use_shell_bonjour", - cwd=os.path.join("deploy", "use_shell_bonjour"), env="conanrun") if celix_options.build_celix_dfi: self.run("./conan_test_package/use_celix_dfi", env="conanrun") if celix_options.build_utils: diff --git a/libs/framework/CMakeLists.txt b/libs/framework/CMakeLists.txt index 64d7d2f6b..8c32ed534 100644 --- a/libs/framework/CMakeLists.txt +++ b/libs/framework/CMakeLists.txt @@ -75,11 +75,11 @@ if (FRAMEWORK) install(TARGETS framework EXPORT celix LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT framework INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/framework) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/framework COMPONENT framework) - if (CELIX_INSTALL_DEPRECATED_API) - install(DIRECTORY include_deprecated/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/framework COMPONENT framework) - endif () install(DIRECTORY ${CMAKE_BINARY_DIR}/celix/gen/includes/framework/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/framework COMPONENT framework) + #TODO #509, remove installation of deprecated headers + install(DIRECTORY include_deprecated/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/framework COMPONENT framework) + #Alias setup to match external usage add_library(Celix::framework ALIAS framework) diff --git a/libs/utils/CMakeLists.txt b/libs/utils/CMakeLists.txt index aec9403a9..5c3f6fce3 100644 --- a/libs/utils/CMakeLists.txt +++ b/libs/utils/CMakeLists.txt @@ -105,9 +105,8 @@ if (UTILS) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/utils/ COMPONENT framework) - if (CELIX_INSTALL_DEPRECATED_API) - install(DIRECTORY include_deprecated/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/utils COMPONENT framework) - endif () + #TODO #509, remove installation of deprecated headers + install(DIRECTORY include_deprecated/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/utils COMPONENT framework) #Alias setup to match external usage add_library(Celix::utils ALIAS utils)