You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2023/12/03 21:49:33 UTC
(celix) 01/02: Remove pubsub and refactor cxx rsa example/integration
This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a commit to branch feature/509-remove-pubsub
in repository https://gitbox.apache.org/repos/asf/celix.git
commit 05b7f5f66b768e2b9d555995f0c5b1384afaf7f7
Author: Pepijn Noltes <pn...@apache.org>
AuthorDate: Sun Dec 3 22:42:23 2023 +0100
Remove pubsub and refactor cxx rsa example/integration
---
bundles/CMakeLists.txt | 1 -
.../cxx_remote_services/integration/CMakeLists.txt | 50 +-
.../resources/Calculator$add$Invoke.descriptor | 9 -
.../resources/Calculator$add$Return.descriptor | 9 -
.../resources/Calculator$result$Event.descriptor | 9 -
.../integration/src/CalculatorConsumer.cc | 12 +
.../integration/src/CalculatorProvider.cc | 2 +-
.../src/TestExportImportRemoteServiceFactory.cc | 470 ++++---
bundles/pubsub/CMakeLists.txt | 36 -
bundles/pubsub/README.md | 116 --
bundles/pubsub/doc/pubsub_serialization.adoc | 263 ----
bundles/pubsub/examples/CMakeLists.txt | 361 -----
bundles/pubsub/examples/keys/README.md | 39 -
.../examples/keys/publisher/private/.gitkeep | 14 -
.../pubsub/examples/keys/publisher/public/.gitkeep | 16 -
.../examples/keys/subscriber/private/.gitkeep | 16 -
.../examples/keys/subscriber/public/.gitkeep | 16 -
bundles/pubsub/examples/pubsub/CMakeLists.txt | 28 -
.../pubsub/examples/pubsub/common/include/poi.h | 55 -
.../pubsub/examples/pubsub/common/include/poiCmd.h | 39 -
.../examples/pubsub/interceptors/CMakeLists.txt | 28 -
.../include/first_interceptor_private.h | 43 -
.../include/second_interceptor_private.h | 36 -
.../pubsub/interceptors/src/first_interceptor.c | 73 -
.../interceptors/src/ps_interceptor_activator.c | 95 --
.../pubsub/interceptors/src/second_interceptor.c | 58 -
.../pubsub/msg_descriptors/msg_poi1.descriptor | 10 -
.../pubsub/msg_descriptors/msg_poi2.descriptor | 11 -
.../pubsub/msg_descriptors/msg_poiCmd.descriptor | 8 -
.../pubsub/msg_descriptors/poi1.properties | 38 -
.../pubsub/msg_descriptors/poi2.properties | 38 -
.../pubsub/msg_descriptors/poiCmd.properties | 35 -
.../examples/pubsub/publisher/CMakeLists.txt | 51 -
.../private/include/pubsub_publisher_private.h | 55 -
.../publisher/private/src/ps_pub_activator.c | 96 --
.../publisher/private/src/pubsub_publisher.c | 168 ---
.../examples/pubsub/publisher2/CMakeLists.txt | 50 -
.../pubsub/pubsub_websocket/CMakeLists.txt | 62 -
.../private/include/pubsub_websocket_private.h | 97 --
.../private/src/ps_websocket_activator.c | 163 ---
.../private/src/pubsub_websocket_example.c | 207 ---
.../pubsub/pubsub_websocket/resources/index.html | 60 -
.../pubsub/pubsub_websocket/resources/script.js | 54 -
.../examples/pubsub/subscriber/CMakeLists.txt | 52 -
.../private/include/pubsub_subscriber_private.h | 50 -
.../subscriber/private/src/ps_sub_activator.c | 113 --
.../subscriber/private/src/pubsub_subscriber.c | 71 -
bundles/pubsub/integration/CMakeLists.txt | 505 -------
.../gtest/PubSubEndpointIntegrationTestSuite.cc | 70 -
.../gtest/PubSubIntegrationTestSuite.cc | 119 --
.../gtest/PubSubInterceptorTestSuite.cc | 235 ----
.../PubSubTopicAndScopeIntegrationTestSuite.cc | 69 -
.../integration/gtest/PubSubWebsocketTestMain.cc | 28 -
.../pubsub/integration/gtest/loopback_activator.c | 99 --
bundles/pubsub/integration/gtest/msg.h | 31 -
.../integration/gtest/receive_count_service.h | 30 -
.../integration/gtest/serializer_activator.cc | 87 --
bundles/pubsub/integration/gtest/sut_activator.c | 118 --
.../integration/gtest/sut_endpoint_activator.c | 120 --
bundles/pubsub/integration/gtest/tst_activator.c | 138 --
.../integration/gtest/tst_endpoint_activator.c | 103 --
.../meta_data/deadlock.scope.properties | 28 -
.../meta_data/deadlock.scope2.properties | 28 -
.../pubsub/integration/meta_data/msg.descriptor | 9 -
.../pubsub/integration/meta_data/ping.properties | 29 -
.../pubsub/integration/meta_data/ping2.properties | 23 -
.../pubsub/integration/meta_data/ping3.properties | 22 -
.../pubsub/integration/meta_data/pong2.properties | 23 -
.../pubsub/integration/meta_data/pong3.properties | 22 -
.../integration/pstm_deadlock_test/test_runner.cc | 161 ---
bundles/pubsub/keygen/CMakeLists.txt | 30 -
bundles/pubsub/keygen/ed_file.c | 309 -----
bundles/pubsub/keygen/makecert.c | 54 -
bundles/pubsub/pubsub_admin_tcp/CMakeLists.txt | 45 -
.../pubsub/pubsub_admin_tcp/src/psa_activator.c | 128 --
.../src/pubsub_psa_tcp_constants.h | 140 --
.../pubsub/pubsub_admin_tcp/src/pubsub_tcp_admin.c | 710 ----------
.../pubsub/pubsub_admin_tcp/src/pubsub_tcp_admin.h | 87 --
.../pubsub_admin_tcp/src/pubsub_tcp_common.c | 39 -
.../pubsub_admin_tcp/src/pubsub_tcp_common.h | 33 -
.../pubsub_admin_tcp/src/pubsub_tcp_handler.c | 1451 --------------------
.../pubsub_admin_tcp/src/pubsub_tcp_handler.h | 92 --
.../src/pubsub_tcp_topic_receiver.c | 674 ---------
.../src/pubsub_tcp_topic_receiver.h | 56 -
.../pubsub_admin_tcp/src/pubsub_tcp_topic_sender.c | 435 ------
.../pubsub_admin_tcp/src/pubsub_tcp_topic_sender.h | 52 -
.../pubsub/pubsub_admin_websocket/CMakeLists.txt | 44 -
.../pubsub_admin_websocket/src/psa_activator.c | 100 --
.../src/pubsub_psa_websocket_constants.h | 61 -
.../src/pubsub_websocket_admin.c | 533 -------
.../src/pubsub_websocket_admin.h | 64 -
.../src/pubsub_websocket_common.c | 68 -
.../src/pubsub_websocket_common.h | 43 -
.../src/pubsub_websocket_topic_receiver.c | 733 ----------
.../src/pubsub_websocket_topic_receiver.h | 48 -
.../src/pubsub_websocket_topic_sender.c | 330 -----
.../src/pubsub_websocket_topic_sender.h | 43 -
bundles/pubsub/pubsub_admin_zmq/CMakeLists.txt | 58 -
.../pubsub/pubsub_admin_zmq/src/psa_activator.c | 115 --
.../src/pubsub_psa_zmq_constants.h | 108 --
.../pubsub/pubsub_admin_zmq/src/pubsub_zmq_admin.c | 799 -----------
.../pubsub/pubsub_admin_zmq/src/pubsub_zmq_admin.h | 52 -
.../src/pubsub_zmq_topic_receiver.c | 710 ----------
.../src/pubsub_zmq_topic_receiver.h | 53 -
.../pubsub_admin_zmq/src/pubsub_zmq_topic_sender.c | 559 --------
.../pubsub_admin_zmq/src/pubsub_zmq_topic_sender.h | 55 -
bundles/pubsub/pubsub_admin_zmq/src/zmq_crypto.c | 278 ----
bundles/pubsub/pubsub_admin_zmq/src/zmq_crypto.h | 41 -
bundles/pubsub/pubsub_api/CMakeLists.txt | 33 -
bundles/pubsub/pubsub_api/include/pubsub/api.h | 28 -
.../pubsub/pubsub_api/include/pubsub/publisher.h | 78 --
.../pubsub/pubsub_api/include/pubsub/subscriber.h | 80 --
bundles/pubsub/pubsub_discovery/CMakeLists.txt | 43 -
.../pubsub/pubsub_discovery/src/psd_activator.c | 105 --
.../pubsub_discovery/src/pubsub_discovery_impl.c | 639 ---------
.../pubsub_discovery/src/pubsub_discovery_impl.h | 100 --
bundles/pubsub/pubsub_protocol/CMakeLists.txt | 21 -
.../pubsub_protocol_lib/CMakeLists.txt | 26 -
.../pubsub_protocol_lib/gtest/CMakeLists.txt | 32 -
.../gtest/src/PS_WP_common_ei_tests.cc | 233 ----
.../gtest/src/PS_WP_common_tests.cc | 311 -----
.../include/pubsub_wire_protocol_common.h | 86 --
.../src/pubsub_wire_protocol_common.c | 313 -----
.../pubsub_protocol_wire_v1/CMakeLists.txt | 48 -
.../pubsub_protocol_wire_v1/gtest/CMakeLists.txt | 28 -
.../gtest/src/PS_WP_tests.cc | 323 -----
.../pubsub_protocol_wire_v1/gtest/src/main.cc | 26 -
.../src/ps_wire_protocol_activator.c | 72 -
.../src/pubsub_wire_protocol_impl.c | 177 ---
.../src/pubsub_wire_protocol_impl.h | 57 -
.../pubsub_protocol_wire_v2/CMakeLists.txt | 45 -
.../pubsub_protocol_wire_v2/gtest/CMakeLists.txt | 28 -
.../gtest/src/PS_WP_v2_tests.cc | 309 -----
.../pubsub_protocol_wire_v2/gtest/src/main.cc | 26 -
.../src/ps_wire_v2_protocol_activator.c | 73 -
.../src/pubsub_wire_v2_protocol_impl.c | 210 ---
.../src/pubsub_wire_v2_protocol_impl.h | 58 -
.../pubsub_serializer_avrobin/CMakeLists.txt | 46 -
.../pubsub_serializer_avrobin/gtest/CMakeLists.txt | 36 -
.../gtest/msg_descriptors/msg_poi1.descriptor | 10 -
.../PubSubAvrobinSerializationProviderTestSuite.cc | 110 --
.../src/ps_avrobin_serializer_activator.c | 40 -
.../src/pubsub_avrobin_serialization_provider.c | 120 --
.../src/pubsub_avrobin_serialization_provider.h | 40 -
.../pubsub/pubsub_serializer_json/CMakeLists.txt | 47 -
.../pubsub_serializer_json/gtest/CMakeLists.txt | 36 -
.../gtest/msg_descriptors/msg_poi1.descriptor | 10 -
.../PubSubJsonSerializationProviderTestSuite.cc | 117 --
.../src/ps_json_serializer_activator.c | 41 -
.../src/pubsub_json_serialization_provider.c | 117 --
.../src/pubsub_json_serialization_provider.h | 43 -
bundles/pubsub/pubsub_spi/CMakeLists.txt | 45 -
bundles/pubsub/pubsub_spi/gtest/CMakeLists.txt | 24 -
.../gtest/src/PubSubEndpointUtilsTestSuite.cc | 47 -
bundles/pubsub/pubsub_spi/include/pubsub_admin.h | 67 -
.../pubsub_spi/include/pubsub_admin_metrics.h | 113 --
.../pubsub/pubsub_spi/include/pubsub_constants.h | 47 -
.../pubsub/pubsub_spi/include/pubsub_endpoint.h | 90 --
.../pubsub/pubsub_spi/include/pubsub_interceptor.h | 116 --
.../include/pubsub_interceptors_handler.h | 81 --
.../pubsub/pubsub_spi/include/pubsub_listeners.h | 57 -
.../include/pubsub_message_serialization_marker.h | 67 -
.../include/pubsub_message_serialization_service.h | 102 --
.../pubsub/pubsub_spi/include/pubsub_protocol.h | 270 ----
.../pubsub/pubsub_spi/src/pubsub_admin_metrics.c | 51 -
bundles/pubsub/pubsub_spi/src/pubsub_endpoint.c | 230 ----
.../pubsub/pubsub_spi/src/pubsub_endpoint_match.c | 35 -
.../pubsub_spi/src/pubsub_interceptors_handler.c | 216 ---
.../pubsub/pubsub_topology_manager/CMakeLists.txt | 37 -
.../pubsub_topology_manager/src/pstm_activator.c | 162 ---
.../src/pubsub_topology_manager.c | 1406 -------------------
.../src/pubsub_topology_manager.h | 136 --
bundles/pubsub/pubsub_utils/CMakeLists.txt | 44 -
bundles/pubsub/pubsub_utils/gtest/CMakeLists.txt | 60 -
.../gtest/msg_descriptors/fiets.properties | 39 -
.../gtest/msg_descriptors/garbage.descriptor | 1 -
.../gtest/msg_descriptors/int_calc.descriptor | 13 -
.../gtest/msg_descriptors/msg_poi1.descriptor | 10 -
.../msg_descriptors/msg_poi2_variant1.descriptor | 11 -
.../msg_descriptors/msg_poi2_variant2.descriptor | 11 -
.../msg_descriptors/msg_poi3_variant1.descriptor | 11 -
.../msg_descriptors/msg_poi3_variant2.descriptor | 12 -
.../msg_descriptors/msg_poi4_variant1.descriptor | 12 -
.../msg_descriptors/msg_poi4_variant2.descriptor | 12 -
.../gtest/msg_descriptors/msg_poiCmd.descriptor | 8 -
.../gtest/src/PubSubMatchingTestSuite.cpp | 183 ---
.../src/PubSubSerializationHandlerTestSuite.cc | 339 -----
.../src/PubSubSerializationProviderTestSuite.cc | 71 -
.../pubsub/pubsub_utils/include/pubsub_matching.h | 140 --
.../include/pubsub_serialization_provider.h | 127 --
.../include/pubsub_serializer_handler.h | 206 ---
bundles/pubsub/pubsub_utils/include/pubsub_utils.h | 99 --
.../pubsub/pubsub_utils/include/pubsub_utils_url.h | 55 -
bundles/pubsub/pubsub_utils/src/pubsub_matching.c | 302 ----
.../src/pubsub_serialization_provider.c | 729 ----------
.../pubsub_utils/src/pubsub_serializer_handler.c | 482 -------
bundles/pubsub/pubsub_utils/src/pubsub_utils.c | 198 ---
bundles/pubsub/pubsub_utils/src/pubsub_utils_url.c | 344 -----
examples/conan_test_package/CMakeLists.txt | 82 --
examples/conan_test_package/my_psa_activator.c | 154 ---
libs/pushstreams/api/celix/PushStream.h | 2 +-
201 files changed, 271 insertions(+), 26016 deletions(-)
diff --git a/bundles/CMakeLists.txt b/bundles/CMakeLists.txt
index e2d92333..deb285cf 100644
--- a/bundles/CMakeLists.txt
+++ b/bundles/CMakeLists.txt
@@ -20,6 +20,5 @@ add_subdirectory(http_admin)
add_subdirectory(logging)
add_subdirectory(shell)
add_subdirectory(remote_services)
-add_subdirectory(pubsub)
add_subdirectory(cxx_remote_services)
add_subdirectory(components_ready_check)
diff --git a/bundles/cxx_remote_services/integration/CMakeLists.txt b/bundles/cxx_remote_services/integration/CMakeLists.txt
index 65ce3330..b19715fc 100644
--- a/bundles/cxx_remote_services/integration/CMakeLists.txt
+++ b/bundles/cxx_remote_services/integration/CMakeLists.txt
@@ -20,14 +20,8 @@ if (CXX_RSA_INTEGRATION)
add_celix_bundle(TestExportImportRemoteServiceFactory
SOURCES src/TestExportImportRemoteServiceFactory.cc
)
- target_link_libraries(TestExportImportRemoteServiceFactory PRIVATE Celix::rsa_spi Celix::pubsub_api Celix::Promises Celix::PushStreams Celix::log_helper)
+ target_link_libraries(TestExportImportRemoteServiceFactory PRIVATE Celix::rsa_spi Celix::Promises Celix::PushStreams Celix::log_helper)
target_include_directories(TestExportImportRemoteServiceFactory PRIVATE include)
- celix_bundle_files(TestExportImportRemoteServiceFactory
- resources/Calculator$add$Invoke.descriptor
- resources/Calculator$result$Event.descriptor
- resources/Calculator$add$Return.descriptor
- DESTINATION "META-INF/descriptors"
- )
add_celix_bundle(CalculatorProvider
SOURCES src/CalculatorProvider.cc
@@ -42,30 +36,22 @@ if (CXX_RSA_INTEGRATION)
target_link_libraries(CalculatorConsumer PRIVATE Celix::Promises Celix::PushStreams Celix::shell_api Celix::RsaConfiguredDiscovery_api)
target_include_directories(CalculatorConsumer PRIVATE include)
- if (ENABLE_TESTING)
- add_subdirectory(gtest)
- endif()
+# if (ENABLE_TESTING)
+# add_subdirectory(gtest)
+# endif()
################# Integration examples ##################################
if (BUILD_LAUNCHER)
add_celix_container(RemoteCalculatorProvider
- LAUNCHER Celix::launcher
- GROUP rsa
- USE_CONFIG
- PROPERTIES
- CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL=trace
- BUNDLES
+ CXX
+ GROUP rsa
+ PROPERTIES
+ CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL=debug
+ BUNDLES
Celix::ShellCxx
Celix::shell_tui
- #Pubsub needed for remote services on pubsub
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_zmq
- Celix::celix_pubsub_protocol_wire_v2
- Celix::celix_pubsub_discovery_etcd
-
#Remote Services
Celix::RemoteServiceAdmin
TestExportImportRemoteServiceFactory #needed to be able to create a ExportedService for ICalculator
@@ -74,22 +60,14 @@ if (CXX_RSA_INTEGRATION)
)
add_celix_container(RemoteCalculatorConsumer
- LAUNCHER Celix::launcher
- GROUP rsa
- USE_CONFIG
- PROPERTIES
- CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL=trace
- BUNDLES
+ CXX
+ GROUP rsa
+ PROPERTIES
+ CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL=debug
+ BUNDLES
Celix::ShellCxx
Celix::shell_tui
- #Pubsub needed for remote services on pubsub
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_discovery_etcd
- Celix::celix_pubsub_admin_zmq
- Celix::celix_pubsub_protocol_wire_v2
-
#Remote Services
Celix::RsaConfiguredDiscovery
Celix::RemoteServiceAdmin
diff --git a/bundles/cxx_remote_services/integration/resources/Calculator$add$Invoke.descriptor b/bundles/cxx_remote_services/integration/resources/Calculator$add$Invoke.descriptor
deleted file mode 100644
index 74777de4..00000000
--- a/bundles/cxx_remote_services/integration/resources/Calculator$add$Invoke.descriptor
+++ /dev/null
@@ -1,9 +0,0 @@
-:header
-type=message
-name=Calculator$add$Invoke
-version=1.0.0
-:annotations
-classname=Calculator$add$Invoke
-:types
-:message
-{DD arg1 arg2}
diff --git a/bundles/cxx_remote_services/integration/resources/Calculator$add$Return.descriptor b/bundles/cxx_remote_services/integration/resources/Calculator$add$Return.descriptor
deleted file mode 100644
index 50e82281..00000000
--- a/bundles/cxx_remote_services/integration/resources/Calculator$add$Return.descriptor
+++ /dev/null
@@ -1,9 +0,0 @@
-:header
-type=message
-name=Calculator$add$Return
-version=1.0.0
-:annotations
-classname=Calculator$add$Return
-:types
-:message
-{[Dt optionalReturnValue optionalError}
diff --git a/bundles/cxx_remote_services/integration/resources/Calculator$result$Event.descriptor b/bundles/cxx_remote_services/integration/resources/Calculator$result$Event.descriptor
deleted file mode 100644
index fb1e018a..00000000
--- a/bundles/cxx_remote_services/integration/resources/Calculator$result$Event.descriptor
+++ /dev/null
@@ -1,9 +0,0 @@
-:header
-type=message
-name=Calculator$result$Event
-version=1.0.0
-:annotations
-classname=Calculator$result$Event
-:types
-:message
-{[Dt optionalReturnValue optionalError}
diff --git a/bundles/cxx_remote_services/integration/src/CalculatorConsumer.cc b/bundles/cxx_remote_services/integration/src/CalculatorConsumer.cc
index 3e64082e..35ceac04 100644
--- a/bundles/cxx_remote_services/integration/src/CalculatorConsumer.cc
+++ b/bundles/cxx_remote_services/integration/src/CalculatorConsumer.cc
@@ -47,8 +47,19 @@ public:
counter++;
}
+ void start() {
+ stream = calculator->result();
+ stream->forEach([](double val) {
+ fprintf(stdout, "calc result stream: %f\n", val);
+ });
+ }
+
+ void stop() {
+ stream.reset();
+ }
private:
std::shared_ptr<ICalculator> calculator{};
+ std::shared_ptr<celix::PushStream<double>> stream{};
};
class CalculatorConsumerActivator {
@@ -60,6 +71,7 @@ public:
.setCallbacks(&CalculatorConsumer::setCalculator);
cmp.createProvidedService<celix::IShellCommand>()
.addProperty(celix::IShellCommand::COMMAND_NAME, "calc");
+ cmp.setCallbacks(nullptr, &CalculatorConsumer::start, &CalculatorConsumer::stop, nullptr);
cmp.build();
//bootstrap own configured import discovery to the configured discovery manager
diff --git a/bundles/cxx_remote_services/integration/src/CalculatorProvider.cc b/bundles/cxx_remote_services/integration/src/CalculatorProvider.cc
index da92530a..57e86b00 100644
--- a/bundles/cxx_remote_services/integration/src/CalculatorProvider.cc
+++ b/bundles/cxx_remote_services/integration/src/CalculatorProvider.cc
@@ -60,7 +60,7 @@ public:
while(!stopThread) {
ses->publish((double)counter);
counter++;
- std::this_thread::sleep_for(std::chrono::milliseconds{100});
+ std::this_thread::sleep_for(std::chrono::milliseconds{5000});
}
});
return CELIX_SUCCESS;
diff --git a/bundles/cxx_remote_services/integration/src/TestExportImportRemoteServiceFactory.cc b/bundles/cxx_remote_services/integration/src/TestExportImportRemoteServiceFactory.cc
index 75ec9487..428e8d65 100644
--- a/bundles/cxx_remote_services/integration/src/TestExportImportRemoteServiceFactory.cc
+++ b/bundles/cxx_remote_services/integration/src/TestExportImportRemoteServiceFactory.cc
@@ -18,6 +18,8 @@
*/
#include <unordered_map>
+#include <optional>
+#include <sys/msg.h>
#include "celix/PromiseFactory.h"
#include "celix/PushStream.h"
@@ -28,40 +30,86 @@
#include "celix/LogHelper.h"
#include "ICalculator.h"
-#include "pubsub/publisher.h"
-#include "pubsub/subscriber.h"
constexpr auto INVOKE_TIMEOUT = std::chrono::milliseconds {500};
struct Calculator$add$Invoke {
- double arg1{};
- double arg2{};
+ long invokeId;
+ double arg1;
+ double arg2;
};
struct Calculator$add$Return {
- struct {
- uint32_t cap{};
- uint32_t len{};
- double* buf{};
- } optionalReturnValue{};
- char* optionalError{};
+ long invokeId;
+ double result;
+ bool hasError;
+ char errorMsg[512];
};
struct Calculator$result$Event {
- struct {
- uint32_t cap{};
- uint32_t len{};
- double* buf{};
- } optionalReturnValue{};
- char* optionalError{};
+ double eventData;
+ bool hasError;
+ char errorMsg[512];
};
+struct Calculator$add$InvokeIpcMsg {
+ long mtype; //1
+ Calculator$add$Invoke mtext;
+};
+
+struct Calculator$add$ReturnIpcMsg {
+ long mtype; //2
+ Calculator$add$Return mtext;
+};
+
+struct Calculator$result$EventIpcMsg {
+ long mtype; //3
+ Calculator$result$Event mtext;
+};
+
+class IpcException : public std::runtime_error {
+ public:
+ using std::runtime_error::runtime_error;
+};
+
+template<typename T>
+static std::optional<T> receiveMsgFromIpc(const celix::LogHelper& logHelper, int qidReceiver, long mtype) {
+ T msg{};
+ msg.mtype = mtype;
+ int rc = msgrcv(qidReceiver, &msg, sizeof(msg.mtext), mtype, MSG_NOERROR | IPC_NOWAIT);
+ if (rc == -1) {
+ if (errno != ENOMSG) {
+ throw IpcException{std::string{"Error receiving message from queue: "} + strerror(errno)};
+ } else {
+ logHelper.trace("No message available for msgrcv()");
+ }
+ return {};
+ } else if (rc != sizeof(msg.mtext)) {
+ throw IpcException{
+ "Error receiving message from queue: Received message size does not match expected size. Got " +
+ std::to_string(rc) + " expected " + std::to_string(sizeof(msg.mtext))};
+ }
+ return msg;
+}
+
+template<typename T>
+static void sendMsgWithIpc(const celix::LogHelper& logHelper, int qidSender, const T& msg) {
+ int rc = msgsnd(qidSender, &msg, sizeof(msg.mtext), IPC_NOWAIT);
+ if (rc == EAGAIN) {
+ logHelper.warning("Cannot send message to queue. Queue is full.");
+ } else if (rc == -1) {
+ logHelper.error("Error sending message to queue: %s", strerror(errno));
+ }
+}
+
/**
* A importedCalculater which acts as a pubsub proxy to a imported remote service.
*/
class ImportedCalculator final : public ICalculator {
public:
- explicit ImportedCalculator(celix::LogHelper _logHelper) : logHelper{std::move(_logHelper)} {}
+ explicit ImportedCalculator(celix::LogHelper _logHelper) : logHelper{std::move(_logHelper)} {
+ setupMsgIpc();
+ }
~ImportedCalculator() noexcept override {
//failing al leftover deferreds
@@ -72,93 +120,27 @@ public:
}
}
};
-public:
std::shared_ptr<celix::PushStream<double>> result() override {
return stream;
}
celix::Promise<double> add(double a, double b) override {
- //setup msg id
- thread_local unsigned int invokeMsgId = 0;
- if (invokeMsgId == 0) {
- publisher->localMsgTypeIdForMsgType(publisher->handle, "Calculator$add$Invoke", &invokeMsgId);
- }
+ //sending Calculator$add$Invoke (mtype=1) to qidSender
+ Calculator$add$InvokeIpcMsg msg{};
+ msg.mtype = 1;
+ msg.mtext.invokeId = nextInvokeId++;
+ msg.mtext.arg1 = a;
+ msg.mtext.arg2 = b;
+
+ sendMsgWithIpc(logHelper, qidSender, msg);
- long invokeId = nextInvokeId++;
std::lock_guard lck{mutex};
auto deferred = factory->deferred<double>();
- deferreds.emplace(invokeId, deferred);
- if (invokeMsgId > 0) {
- Calculator$add$Invoke invoke;
- invoke.arg1 = a;
- invoke.arg2 = b;
- auto* meta = celix_properties_create();
- celix_properties_setLong(meta, "invoke.id", invokeId);
- int rc = publisher->send(publisher->handle, invokeMsgId, &invoke, meta);
- if (rc != 0) {
- constexpr auto msg = "error sending invoke msg";
- logHelper.error(msg);
- deferred.fail(celix::rsa::RemoteServicesException{msg});
- }
- } else {
- constexpr auto msg = "error getting msg id for invoke msg";
- logHelper.error(msg);
- deferred.fail(celix::rsa::RemoteServicesException{msg});
- }
+ deferreds.emplace(msg.mtext.invokeId, deferred);
return deferred.getPromise().setTimeout(INVOKE_TIMEOUT);
}
- void receive(const char *msgType, unsigned int msgTypeId, void *msg, const celix_properties_t* meta) {
- //setup message ids
- thread_local unsigned int returnAddMsgId = 0;
- thread_local unsigned int streamResultMsgId = 0;
-
- if (returnAddMsgId == 0 && celix_utils_stringEquals(msgType, "Calculator$add$Return")) {
- returnAddMsgId = msgTypeId;
- }
- if (streamResultMsgId == 0 && celix_utils_stringEquals(msgType, "Calculator$result$Event")) {
- streamResultMsgId = msgTypeId;
- }
-
- //handle incoming messages
- if (streamResultMsgId != 0 && streamResultMsgId == msgTypeId) {
- long invokeId = celix_properties_getAsLong(meta, "invoke.id", -1);
- if (invokeId == -1) {
- logHelper.error("Cannot find invoke id on metadata");
- return;
- }
- auto* result = static_cast<Calculator$result$Event*>(msg);
- if (result->optionalReturnValue.len == 1) {
- ses->publish(result->optionalReturnValue.buf[0]);
- } else {
- ses->close();
- }
- } else if (returnAddMsgId != 0 && returnAddMsgId == msgTypeId) {
- long invokeId = celix_properties_getAsLong(meta, "invoke.id", -1);
- if (invokeId == -1) {
- logHelper.error("Cannot find invoke id on metadata");
- return;
- }
- auto* result = static_cast<Calculator$add$Return*>(msg);
- std::unique_lock lock{mutex};
- auto it = deferreds.find(invokeId);
- if (it == end(deferreds)) {
- logHelper.error("Cannot find deferred for invoke id %li", invokeId);
- return;
- }
- auto deferred = it->second;
- deferreds.erase(it);
- lock.unlock();
- if (result->optionalReturnValue.len == 1) {
- deferred.resolve(result->optionalReturnValue.buf[0]);
- } else {
- deferred.fail(celix::rsa::RemoteServicesException{"Failed resolving remote promise"});
- }
- } else {
- logHelper.warning("Unexpected message type %s", msgType);
- }
- }
int init() {
return CELIX_SUCCESS;
}
@@ -166,10 +148,22 @@ public:
int start() {
ses = psp->createSynchronousEventSource<double>(factory);
stream = psp->createStream<double>(ses, factory);
+ running.store(true, std::memory_order::memory_order_release);
+ receiveThread = std::thread{[this]{
+ while (running.load(std::memory_order::memory_order_consume)) {
+ receiveMessages();
+ cleanupResolvedDeferreds();
+ //note for example purposes, sleep instead of blocking with cond is used.
+ std::this_thread::sleep_for(std::chrono::milliseconds{10});
+ }
+ }};
return CELIX_SUCCESS;
}
int stop() {
+ running.store(false, std::memory_order::memory_order_release);
+ receiveThread.join();
+ receiveThread = {};
ses->close();
ses.reset();
stream.reset();
@@ -180,11 +174,6 @@ public:
return CELIX_SUCCESS;
}
- void setPublisher(const std::shared_ptr<pubsub_publisher>& pub) {
- std::lock_guard lock{mutex};
- publisher = pub;
- }
-
void setPromiseFactory(const std::shared_ptr<celix::PromiseFactory>& fac) {
std::lock_guard lock{mutex};
factory = fac;
@@ -196,15 +185,97 @@ public:
}
private:
+ void setupMsgIpc() {
+ int keySender = 1234; // TODO make configurable
+ int keyReceiver = 1235; // TODO make configurable
+ qidSender = msgget(keySender, 0666 | IPC_CREAT);
+ qidReceiver = msgget(keyReceiver, 0666 | IPC_CREAT);
+
+ if (qidSender == -1 || qidReceiver == -1) {
+ throw std::logic_error{"RsaShmClient: Error creating msg queue."};
+ }
+ }
+
+ void receiveMessages() {
+ receiveCalculator$add$Return();
+ receiveCalculator$result$Event();
+ }
+
+ void receiveCalculator$add$Return() {
+ //receiving Calculator$add$Return (mtype=2) from qidReceiver
+ try {
+ auto msg = receiveMsgFromIpc<Calculator$add$ReturnIpcMsg>(logHelper, qidReceiver, 2);
+ if (!msg) {
+ return; // no message available (yet)
+ }
+ auto& ret = msg.value().mtext;
+
+ std::unique_lock lock{mutex};
+ auto it = deferreds.find(ret.invokeId);
+ if (it == end(deferreds)) {
+ logHelper.error("Cannot find deferred for invoke id %li", ret.invokeId);
+ return;
+ }
+ auto deferred = it->second;
+ deferreds.erase(it);
+ lock.unlock();
+
+ if (ret.hasError) {
+ deferred.fail(celix::rsa::RemoteServicesException{ret.errorMsg});
+ } else {
+ deferred.resolve(ret.result);
+ }
+ } catch (const IpcException& e) {
+ logHelper.error("IpcException: %s", e.what());
+ }
+ }
+
+ void receiveCalculator$result$Event() {
+ try {
+ auto msg = receiveMsgFromIpc<Calculator$result$EventIpcMsg>(logHelper, qidReceiver, 3);
+ if (!msg) {
+ return; // no message available (yet)
+ }
+ auto event = msg.value().mtext;
+
+ if (event.hasError) {
+ logHelper.error("Received error event %s", event.errorMsg);
+ ses->close();
+ } else {
+ ses->publish(event.eventData);
+ }
+ } catch (const IpcException& e) {
+ logHelper.error("IpcException: %s", e.what());
+ }
+ }
+
+ /**
+ * @brief Clean up deferreds which are resolved (because of a timeout).
+ */
+ void cleanupResolvedDeferreds() {
+ std::lock_guard lock{mutex};
+ for (auto it = begin(deferreds); it != end(deferreds);) {
+ if (it->second.getPromise().isDone()) {
+ it = deferreds.erase(it);
+ } else {
+ ++it;
+ }
+ }
+ }
+
celix::LogHelper logHelper;
std::atomic<long> nextInvokeId{0};
+ std::atomic<bool> running{false};
+ std::thread receiveThread{};
std::mutex mutex{}; //protects below
std::shared_ptr<celix::PromiseFactory> factory{};
- std::shared_ptr<pubsub_publisher> publisher{};
std::unordered_map<long, celix::Deferred<double>> deferreds{};
std::shared_ptr<celix::PushStreamProvider> psp {};
std::shared_ptr<celix::SynchronousPushEventSource<double>> ses{};
std::shared_ptr<celix::PushStream<double>> stream{};
+
+ int qidSender{-1};
+ int qidReceiver{-1};
};
/**
@@ -261,11 +332,6 @@ private:
auto scope = endpoint.getProperties().get("endpoint.scope");
auto& cmp = ctx->getDependencyManager()->createComponent(std::make_unique<ImportedCalculator>(logHelper));
- cmp.createServiceDependency<pubsub_publisher>(PUBSUB_PUBLISHER_SERVICE_NAME)
- .setRequired(true)
- .setStrategy(DependencyUpdateStrategy::suspend)
- .setFilter(std::string{"(&(topic="}.append(invokeTopic).append(")(scope=").append(scope).append("))"))
- .setCallbacks(&ImportedCalculator::setPublisher);
cmp.createServiceDependency<celix::PromiseFactory>()
.setRequired(true)
.setStrategy(DependencyUpdateStrategy::suspend)
@@ -277,22 +343,6 @@ private:
cmp.setCallbacks(&ImportedCalculator::init, &ImportedCalculator::start, &ImportedCalculator::stop, &ImportedCalculator::deinit);
- auto subscriber = std::make_shared<pubsub_subscriber_t>();
- subscriber->handle = &cmp.getInstance();
- subscriber->receive = [](void *handle, const char *msgType, unsigned int msgTypeId, void *msg, const celix_properties_t *metadata, bool */*release*/) -> int {
- auto* inst = static_cast<ImportedCalculator*>(handle);
- try {
- inst->receive(msgType, msgTypeId, msg, metadata);
- } catch (...) {
- return -1;
- }
- return 0;
- };
- cmp.addContext(subscriber);
- cmp.createProvidedCService<pubsub_subscriber_t>(subscriber.get(), PUBSUB_SUBSCRIBER_SERVICE_NAME)
- .addProperty("topic", returnTopic)
- .addProperty("scope", scope);
-
//Adding the imported service as provide
celix::Properties svcProps{};
for (const auto& entry : endpoint.getProperties()) {
@@ -323,71 +373,7 @@ private:
class ExportedCalculator final {
public:
explicit ExportedCalculator(celix::LogHelper _logHelper) : logHelper{std::move(_logHelper)} {
-
- }
-
- void receive(const char *msgType, unsigned int msgTypeId, void *msg, const celix_properties_t* meta) {
- //setup message ids
- thread_local unsigned int invokeAddMsgId = 0;
- if (invokeAddMsgId == 0 && celix_utils_stringEquals(msgType, "Calculator$add$Invoke")) {
- invokeAddMsgId = msgTypeId;
- }
- thread_local unsigned int returnMsgId = 0;
- if (returnMsgId == 0) {
- publisher->localMsgTypeIdForMsgType(publisher->handle, "Calculator$add$Return", &returnMsgId);
- }
-
- //handle incoming messages
- if (invokeAddMsgId != 0 && invokeAddMsgId == msgTypeId) {
- auto* invoke = static_cast<Calculator$add$Invoke*>(msg);
- long invokeId = celix_properties_getAsLong(meta, "invoke.id", -1);
- if (invokeId == -1) {
- logHelper.error("Cannot find invoke id on metadata");
- return;
- }
-
- auto* metaProps = celix_properties_create();
- celix_properties_set(metaProps, "invoke.id", std::to_string(invokeId).c_str());
- std::lock_guard lock{mutex};
- auto promise = calculator->add(invoke->arg1, invoke->arg2);
- promise
- .onFailure([logHelper = logHelper, weakPub = std::weak_ptr<pubsub_publisher>{publisher}, msgId = returnMsgId, metaProps](const auto& exp) {
- auto pub = weakPub.lock();
- if (pub) {
- Calculator$add$Return ret;
- ret.optionalReturnValue.buf = nullptr;
- ret.optionalReturnValue.len = 0;
- ret.optionalReturnValue.cap = 0;
- ret.optionalError = celix_utils_strdup(exp.what());
- pub->send(pub->handle, msgId, &ret, metaProps);
- } else {
- logHelper.error("publisher is gone");
- }
- })
- .onSuccess([logHelper = logHelper, weakSvc = std::weak_ptr<ICalculator>{calculator}, weakPub = std::weak_ptr<pubsub_publisher>{publisher}, msgId = returnMsgId, metaProps](auto val) {
- auto pub = weakPub.lock();
- auto svc = weakSvc.lock();
- if (pub && svc) {
- Calculator$add$Return ret;
- ret.optionalReturnValue.buf = (double *) malloc(sizeof(*ret.optionalReturnValue.buf));
- ret.optionalReturnValue.len = 1;
- ret.optionalReturnValue.cap = 1;
- ret.optionalReturnValue.buf[0] = val;
- ret.optionalError = nullptr;
- pub->send(pub->handle, msgId, &ret, metaProps);
- free(ret.optionalReturnValue.buf);
- } else {
- logHelper.error("publisher is gone");
- }
- });
- } else {
- logHelper.warning("Unexpected message type %s", msgType);
- }
- }
-
- void setPublisher(const std::shared_ptr<pubsub_publisher>& pub) {
- std::lock_guard lock{mutex};
- publisher = pub;
+ setupMsgIpc();
}
void setPromiseFactory(const std::shared_ptr<celix::PromiseFactory>& fac) {
@@ -401,33 +387,33 @@ public:
int start() {
resultStream = calculator->result();
- auto streamEnded = resultStream->forEach([logHelper = logHelper, weakSvc = std::weak_ptr<ICalculator>{calculator}, weakPub = std::weak_ptr<pubsub_publisher>{publisher}](const double& event){
- auto pub = weakPub.lock();
+ auto streamEnded = resultStream->forEach([lh = logHelper, weakSvc = std::weak_ptr<ICalculator>{calculator}, qidSnd = qidSender](const double& event) {
auto svc = weakSvc.lock();
- if (pub && svc) {
- thread_local unsigned int eventMsgId = 0;
- if (eventMsgId == 0) {
- pub->localMsgTypeIdForMsgType(pub->handle, "Calculator$result$Event", &eventMsgId);
- }
-
- auto* metaProps = celix_properties_create();
- celix_properties_set(metaProps, "invoke.id", std::to_string(0).c_str());
- Calculator$result$Event wireEvent;
- wireEvent.optionalReturnValue.buf = (double *) malloc(sizeof(*wireEvent.optionalReturnValue.buf));
- wireEvent.optionalReturnValue.len = 1;
- wireEvent.optionalReturnValue.cap = 1;
- wireEvent.optionalReturnValue.buf[0] = event;
- wireEvent.optionalError = nullptr;
- pub->send(pub->handle, eventMsgId, &wireEvent, metaProps);
- free(wireEvent.optionalReturnValue.buf);
+ if (qidSnd != -1 && svc) {
+ Calculator$result$EventIpcMsg msg{};
+ msg.mtype = 3;
+ msg.mtext.eventData = event;
+ msg.mtext.hasError = false;
+ sendMsgWithIpc(lh, qidSnd, msg);
} else {
- logHelper.error("publisher is gone");
+ lh.error("Cannot send event, qidSender is -1 or service is gone");
}
});
+ running.store(true, std::memory_order::memory_order_release);
+ receiveThread = std::thread{[this]{
+ while (running.load(std::memory_order::memory_order_consume)) {
+ receiveMessages();
+ //note for example purposes, sleep instead of blocking with cond is used.
+ std::this_thread::sleep_for(std::chrono::milliseconds{10});
+ }
+ }};
return CELIX_SUCCESS;
}
int stop() {
+ running.store(false, std::memory_order::memory_order_release);
+ receiveThread.join();
+ receiveThread = {};
resultStream->close();
resultStream.reset();
return CELIX_SUCCESS;
@@ -442,14 +428,66 @@ public:
calculator = calc;
}
private:
+ void setupMsgIpc() {
+ //note reverse order of sender and receiver compared to ImportedCalculator
+ int keySender = 1235; // TODO make configurable
+ int keyReceiver = 1234; // TODO make configurable
+ qidSender = msgget(keySender, 0666 | IPC_CREAT);
+ qidReceiver = msgget(keyReceiver, 0666 | IPC_CREAT);
+
+ if (qidSender == -1 || qidReceiver == -1) {
+ throw std::logic_error{"RsaShmClient: Error creating msg queue."};
+ }
+ }
+
+ void receiveMessages() {
+ receiveCalculator$add$Invoke();
+ }
+
+ void receiveCalculator$add$Invoke() {
+ try {
+ auto msg = receiveMsgFromIpc<Calculator$add$InvokeIpcMsg>(logHelper, qidReceiver, 1);
+ if (!msg) {
+ return; // no message available (yet)
+ }
+ auto& invoke = msg->mtext;
+
+ auto promise = calculator->add(invoke.arg1, invoke.arg2);
+ promise.onFailure([lh = logHelper, id = invoke.invokeId, qidSnd = qidSender](const auto& exp) {
+ //sending Calculator$add$Return (mtype=2) to qidSender
+ Calculator$add$ReturnIpcMsg msg{};
+ msg.mtype = 2;
+ msg.mtext.invokeId = id;
+ msg.mtext.result = 0.0;
+ msg.mtext.hasError = true;
+ snprintf(msg.mtext.errorMsg, sizeof(msg.mtext.errorMsg), "%s", exp.what());
+ sendMsgWithIpc(lh, qidSnd, msg);
+ });
+ promise.onSuccess([lh = logHelper, id = invoke.invokeId, qidSnd = qidSender](const auto& val) {
+ //sending Calculator$add$Return (mtype=2) to qidSender
+ Calculator$add$ReturnIpcMsg msg{};
+ msg.mtype = 2;
+ msg.mtext.invokeId = id;
+ msg.mtext.result = val;
+ msg.mtext.hasError = false;
+ sendMsgWithIpc(lh, qidSnd, msg);
+ });
+ } catch (const IpcException& e) {
+ logHelper.error("IpcException: %s", e.what());
+ }
+ }
+
celix::LogHelper logHelper;
- std::atomic<long> nextInvokeId{0};
+ std::atomic<bool> running{false};
+ std::thread receiveThread{};
std::mutex mutex{}; //protects below
std::shared_ptr<ICalculator> calculator{};
std::shared_ptr<celix::PromiseFactory> factory{};
- std::shared_ptr<pubsub_publisher> publisher{};
std::unordered_map<long, celix::Deferred<double>> deferreds{};
std::shared_ptr<celix::PushStream<double>> resultStream{};
+
+ int qidSender{-1};
+ int qidReceiver{-1};
};
/**
@@ -513,11 +551,6 @@ private:
auto svcId = serviceProperties.get(celix::SERVICE_ID);
auto& cmp = ctx->getDependencyManager()->createComponent(std::make_unique<ExportedCalculator>(logHelper));
- cmp.createServiceDependency<pubsub_publisher>(PUBSUB_PUBLISHER_SERVICE_NAME)
- .setRequired(true)
- .setStrategy(DependencyUpdateStrategy::suspend)
- .setFilter(std::string{"(&(topic="}.append(returnTopic).append(")(scope=").append(scope).append("))"))
- .setCallbacks(&ExportedCalculator::setPublisher);
cmp.createServiceDependency<celix::PromiseFactory>()
.setRequired(true)
@@ -532,23 +565,6 @@ private:
cmp.setCallbacks(&ExportedCalculator::init, &ExportedCalculator::start, &ExportedCalculator::stop, &ExportedCalculator::deinit);
-
- auto subscriber = std::make_shared<pubsub_subscriber_t>();
- subscriber->handle = &cmp.getInstance();
- subscriber->receive = [](void *handle, const char *msgType, unsigned int msgTypeId, void *msg, const celix_properties_t *metadata, bool */*release*/) -> int {
- auto* inst = static_cast<ExportedCalculator*>(handle);
- try {
- inst->receive(msgType, msgTypeId, msg, metadata);
- } catch (...) {
- return -1;
- }
- return 0;
- };
- cmp.addContext(subscriber);
- cmp.createProvidedCService<pubsub_subscriber_t>(subscriber.get(), PUBSUB_SUBSCRIBER_SERVICE_NAME)
- .addProperty("topic", invokeTopic)
- .addProperty("scope", scope);
-
cmp.buildAsync();
return cmp.getUUID();
diff --git a/bundles/pubsub/CMakeLists.txt b/bundles/pubsub/CMakeLists.txt
deleted file mode 100644
index 11513943..00000000
--- a/bundles/pubsub/CMakeLists.txt
+++ /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.
-
-celix_subproject(PUBSUB "Option to build the pubsub bundles" ON)
-if (PUBSUB)
- add_subdirectory(pubsub_api)
- add_subdirectory(pubsub_utils)
- add_subdirectory(pubsub_spi)
- add_subdirectory(pubsub_topology_manager)
- add_subdirectory(pubsub_admin_zmq)
- add_subdirectory(pubsub_admin_tcp)
- add_subdirectory(pubsub_admin_websocket)
- add_subdirectory(pubsub_discovery)
- add_subdirectory(pubsub_serializer_json)
- add_subdirectory(pubsub_serializer_avrobin)
- add_subdirectory(pubsub_protocol)
- add_subdirectory(keygen)
- add_subdirectory(examples)
- if (ENABLE_TESTING)
- add_subdirectory(integration)
- endif()
-endif(PUBSUB)
diff --git a/bundles/pubsub/README.md b/bundles/pubsub/README.md
deleted file mode 100644
index 744cfd9a..00000000
--- a/bundles/pubsub/README.md
+++ /dev/null
@@ -1,116 +0,0 @@
----
-title: Publisher / subscriber implementation
----
-
-<!--
-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.
--->
-
-# Publisher / subscriber implementation
-
-This subdirectory contains an implementation for a publish-subscribe remote services system, that use dfi library for message serialization.
-For low-level communication, TCP, UDP and ZMQ is used.
-
-# Description
-
-This publisher / subscriber implementation is based on the concepts of the remote service admin (i.e. rsa / topology / discovery pattern).
-
-Publishers are senders of data, subscribers can receive data. Publishers can publish/send data to certain channels (called 'topics' further on), subscribers can subscribe to these topics. For every topic a publisher service is created by the pubsub admin. This publisher is announced through etcd. So etcd is used for discovery of the publishers. Subscribers are also registered as a service by the pubsub admin and will watch etcd for changes and when a new publisher is announced, the subsc [...]
-
-The dfi library is used for message serialization. The publisher / subscriber implementation will arrange that every message which will be send gets an unique id.
-
-For communication between publishers and subscribers TCP, UDP and ZeroMQ can be used. When using ZeroMQ it's also possible to setup a secure connection to encrypt the traffic being send between publishers and subscribers. This connection can be secured with ZeroMQ by using a curve25519 key pair per topic.
-
-The publisher/subscriber implementation supports sending of a single message and sending of multipart messages.
-
-## Getting started
-
-The publisher/subscriber implementation contains 3 different PubSubAdmins for managing connections:
- * PubsubAdminUDP: This pubsub admin is using udp (multicast) linux sockets to setup a connection.
- * PubsubAdminTCP: This pubsub admin is using tcp linux sockets to setup a connection.
- * PubsubAdminZMQ (LGPL License): This pubsub admin is using ZeroMQ and is disabled as default. This is a because the pubsub admin is using ZeroMQ which is licensed as LGPL ([View ZeroMQ License](https://github.com/zeromq/libzmq#license)).
-
- The ZeroMQ pubsub admin can be enabled by specifying the build flag `BUILD_PUBSUB_PSA_ZMQ=ON`. To get the ZeroMQ pubsub admin running, [ZeroMQ](https://github.com/zeromq/libzmq) and [CZMQ](https://github.com/zeromq/czmq) need to be installed. Also, to make use of encrypted traffic, [OpenSSL](https://github.com/openssl/openssl) is required.
-
-## Running instructions
-
-### Running PSA UDP-Multicast
-
-1. Open a terminal
-1. Run `etcd`
-1. Open second terminal on project build location
-1. Run `cd deploy/pubsub/pubsub_publisher_udp_mc`
-1. Run `sh run.sh`
-1. Open third terminal on project build location
-1. Run `cd deploy/pubsub/pubsub_subscriber_udp_mc`
-1. Run `sh run.sh`
-
-Design information can be found at pubsub\_admin\_udp\_mc/README.md
-
-
-### Running PSA TCP
-
-1. Open a terminal
-1. Run `cd runtimes/pubsub/tcp`
-1. Run `sh start.sh`
-
-### Properties PSA TCP
-
-Some properties can be set to configure the PSA-TCP. If not configured defaults will be used. These
-properties can be set in the config.properties file (<PROPERTY>=<VALUE> format)
-
-
- PSA_IP The url address to be used by the TCP admin to publish its data. Default the first IP not on localhost
- This can be hostname / IP address / IP address with postfix, e.g. 192.168.1.0/24
-
-
-### Running PSA ZMQ
-
-For ZeroMQ without encryption, skip the steps 1-12 below
-
-1. Run `touch ~/pubsub.keys`
-1. Run `echo "aes_key:{AES_KEY here}" >> ~/pubsub.keys`. Note that AES_KEY is just a sequence of random bytes. To generate such a key, you can use the command `cat /dev/urandom | hexdump -v -e '/1 "%02X"' | head -c 32` (this will take out of /dev/urandom 16 bytes, thus a 128bit key)
-1. Run `echo "aes_iv:{AES_IV here}" >> ~/pubsub.keys`. Note that AES_IV is just a sequence of random bytes. To generate such an initial vector , you can use the command `cat /dev/urandom | hexdump -v -e '/1 "%02X"' | head -c 16` (this will take out of /dev/urandom 8 bytes, thus a 64bit initial vector)
-1. Run `touch ~/pubsub.conf`
-1. Run `echo "keys.file.path=$HOME" >> ~/pubsub.conf`
-1. Run `echo "keys.file.name=pubsub.keys" >> ~/pubsub.conf`
-1. Generate ZMQ keypairs by running `pubsub/keygen/makecert pub_<topic_name>.pub pub_<topic_name>.key`
-1. Encrypt the private key file using `pubsub/keygen/ed_file ~/pubsub.keys pub_<topic_name>.key pub_<topic>.key.enc`
-1. Store the keys in the pubsub/examples/keys/ directory, as described in the pubsub/examples/keys/README.
-1. Build project to include these keys (check the CMakeLists.txt files to be sure that the keys are included in the bundles)
-1. Add to the config.properties the property SECURE_TOPICS=<list_of_secure_topics>
-
-For ZeroMQ without encryption, start here
-
-1. Run `etcd`
-1. Open second terminal on pubsub root
-1. Run `cd deploy/pubsub/pubsub_publisher_zmq`
-1. Run `cat ~/pubsub.conf >> config.properties` (only for ZeroMQ with encryption)
-1. Run `sh run.sh`
-1. Open third terminal on pubsub root
-1. Run `cd deploy/pubsub/pubsub_subscriber_zmq`
-1. Run `cat ~/pubsub.conf >> config.properties` (only for ZeroMQ with encryption)
-1. Run `sh run.sh`
-
-### Properties PSA ZMQ
-
-Some properties can be set to configure the PSA-ZMQ. If not configured defaults will be used. These
-properties can be set in the config.properties file (<PROPERTY>=<VALUE> format)
-
-
- PSA_IP The local IP address to be used by the ZMQ admin to publish its data. Default the first IP not on localhost
- PSA_INTERFACE The local ethernet interface to be used by the ZMQ admin to publish its data (ie eth0). Default the first non localhost interface
- PSA_ZMQ_RECEIVE_TIMEOUT_MICROSEC Set the polling interval of the ZMQ receive thread. Default 1ms
\ No newline at end of file
diff --git a/bundles/pubsub/doc/pubsub_serialization.adoc b/bundles/pubsub/doc/pubsub_serialization.adoc
deleted file mode 100644
index c4d7c1bc..00000000
--- a/bundles/pubsub/doc/pubsub_serialization.adoc
+++ /dev/null
@@ -1,263 +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.
-////
-= PubSub Serialization
-
-WARNING: The PubSub Serialization Services are still work in progress. The current PubSubAdmins still work differently.
-
-PubSub serialization is realized by providing multiple message serialization services
-(`pubsub_message_serialization_service_t`), a message serialization service per msg type.
-
-The message serialization services must provide a mandatory `serialization.type`.
-This is used to identify the serialization "type" they belong to, for example "json" or "avrobin".
-
-The serialization services are used by the PubSubAdmins to find a matching serializer.
-This is done by checking if a publisher requester or subscriber provider has configured a serialization type and
-if this is not the case select the highest ranking available serialization service.
-
-The serialization services are also used by the PubSub Admins to send (serialize) and receive (deserialize) messages.
-The PubSub Admins realizes the transport for messages and the serialization services serializes the serializations.
-
-Currently the Celix PubSub facilities delivers two serialiation types: "json" and "avrobin".
-<<PubSub Serialization Provider>> can be used to create additional serialization types.
-
-pubsub_message_serialization_service_t
-[source,c]
-----
-#define PUBSUB_MESSAGE_SERIALIZATION_SERVICE_NAME "pubsub_message_serialization_service"
-#define PUBSUB_MESSAGE_SERIALIZATION_SERVICE_VERSION "1.0.0"
-#define PUBSUB_MESSAGE_SERIALIZATION_SERVICE_RANGE "[1,2)"
-
-#define PUBSUB_MESSAGE_SERIALIZATION_SERVICE_SERIALIZATION_TYPE_PROPERTY "serialization.type"
-#define PUBSUB_MESSAGE_SERIALIZATION_SERVICE_MSG_FQN_PROPERTY "msg.fqn"
-#define PUBSUB_MESSAGE_SERIALIZATION_SERVICE_MSG_VERSION_PROPERTY "msg.version"
-#define PUBSUB_MESSAGE_SERIALIZATION_SERVICE_MSG_ID_PROPERTY "msg.id"
-
-/**
- * A message serialization service for a serialization type (e.g. json) and
- * for a specific msg type (based on the fully qualified name) and version.
- *
- * The properties serialization.type, msg,fqn, msg.version and msg.id are mandatory
- */
-typedef struct pubsub_message_serialization_service {
- void* handle;
-
- celix_status_t (*serialize)(void* handle, const void* input, struct iovec** output, size_t* outputIovLen);
- void (*freeSerializedMsg)(void* handle, 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 (*freeDeserializedMsg)(void* handle, void* msg);
-
-} pubsub_message_serialization_service_t;
-----
-
-== PubSub Serialization Matching
-
-TODO: Explain matching and usage service ranking on serialization service.
-
-
-=== Match Serializer for Subscriber
-[plantuml]
-----
-@startuml
-actor PubSubUser
-
-PubSubUser -> BundleContext: Register Subscriber Service
-BundleContext -> Framework: Register Subscriber Service
-Framework -> PubSubTopologyManager : Service Added (service tracker)
-PubSubTopologyManager --> Framework
-Framework --> BundleContext
-BundleContext --> PubSubUser
-
-== PubSubAdmin Setup ==
-
-loop psa handling thread
-PubSubTopologyManager -> PubSubTopologyManager: pstm_setupTopicReceivers
-activate PubSubTopologyManager
-PubSubTopologyManager -> PubSubAdmin: matchSubscriber
-PubSubAdmin -> PubSubUtils: matchSerializer
-PubSubUtils --> PubSubAdmin
-PubSubAdmin --> PubSubTopologyManager
-PubSubTopologyManager -> PubSubAdmin: setupTopicReceiver
-PubSubAdmin -> PubSubAdmin: create topic receiver
-PubSubAdmin --> PubSubTopologyManager
-deactivate PubSubTopologyManager
-end
-
-@enduml
-----
-
-=== Match Serializer for Publisher
-[plantuml]
-----
-@startuml
-actor PubSubUser
-
-PubSubUser -> BundleContext: Request Publisher Service
-BundleContext -> Framework: Register Service Listener hook
-Framework -> PubSubTopologyManager : Listener Added
-PubSubTopologyManager --> Framework
-Framework --> BundleContext
-BundleContext --> PubSubUser
-
-== PubSubAdmin Setup ==
-
-loop psa handling thread
-PubSubTopologyManager -> PubSubTopologyManager: pstm_setupTopicSenders
-activate PubSubTopologyManager
-PubSubTopologyManager -> PubSubAdmin: matchPublisher
-PubSubAdmin -> PubSubUtils: matchSerializer
-PubSubUtils --> PubSubAdmin
-PubSubAdmin --> PubSubTopologyManager
-PubSubTopologyManager -> PubSubAdmin: setupTopicSender
-PubSubAdmin -> PubSubAdmin: create topic sender
-PubSubAdmin -> BundleContext: Register Publisher Service
-BundleContext -> PubSubUser: Publisher Added
-PubSubUser --> BundleContext
-BundleContext --> PubSubAdmin
-PubSubAdmin --> PubSubTopologyManager
-deactivate PubSubTopologyManager
-end
-
-@enduml
-----
-
-== PubSub Serialization Provider
-The PubSub Serialization Provider (`pubsub_serialization_provider_t`) is a helper object which can be used to more easily
-create serialization services based on descriptors (libdfi). It arranges tracking bundles, reading descriptor files,
-generating errors for invalid descriptors and provides a shell command to interactively query the available descriptors.
-
-The PubSub Serialization Provider needs to be constructor with the serializations service functions
-(`serialize`, `freeSerializedMsg`, `deserialize` and `freeDeserializedMsg`)
-
-The PubSub Serialization Provider is part of the `Celix::pubsub_utils` static library.
-
-[ditaa]
-----
- +----------------+
- | PubSub User |
- | (bundle) | +----------------+
- | | contains | |
- | +------------->+ +-------------+--+
- | | | | |
- +-------+--------+ | | +--------------+--+
- ^ | | | examples.Type |
- | +-------------->+ | | (descriptor) |
- tracks | | reads +----+ |
- bundles | | | | |
- | | +-+ |
- | | | |
- | | | {d} |
- | | +-----------------+
- | |
- | |
- | |
- +---------+-------+-+
- | JSON |
- | Serialization | +----------------+
- | Provider +------------>+ |
- | (bundle) | provides | +----------------+
- | | | | | |
- | | | | +-----------+--+--+
- | | | | | | Properties:
- | | | | | PubSub | o serialization.type = json
- +--+--------------+-+ +----+ Message | o msg.fqn = examples.Type
- | | | | Serialization | o msg.version = ...
- | | +-+ Service | o msg.id = ...
- | | | (service) |
- specialize| | | |
- | | +-----------------+
- | |
- | |
- v | +------------------+
-+-------------+-----+ | | | Properties:
-| | | | PubSub | o serialization.type = json
-| PubSub | | | Message |
-| Serialization | +-------------->+ Serialization |
-| Provider | provides | Marker |
-| (library) | | (service) |
-| | | |
-| | +------------------+
-+-------------------+
-----
-
-== PubSub Serialization Handler
-The PubSub Serialization Handler (`pubsub_serialization_handler_t`) is a helper object which can be used to more easily
-serialize/deserialize message.
-The handler will track message serialization services for the provided serialization type (constructor argument) and
-provides a more easy to use set of function for serialization.
-
-It will also check if the provided message serialization services do not clash on the msg id and msg fqn combination.
-When multiple message serialization services are registered it will use the highest ranking services.
-
-serialization services based on descriptors (libdfi). It arranges tracking bundles, reading descriptor files,
-generating errors for invalid descriptors and provides a shell command to interactively query the available descriptors.
-
-The PubSub Serialization Handler is part of the `Celix::pubsub_utils` static library.
-
-=== Serialization function for PubSub Serialization Handler
-[source, c]
-----
-/**
- * Serialize a message into iovec structs (set of structures with buffer pointer and length)
- *
- * The correct message serialization services will be selected based on the provided msgId.
- *
- * @param handler The pubsub serialization handler.
- * @param msgId The msg id for the message to be serialized.
- * @param input A pointer to the message object
- * @param output An output pointer to a array of iovec structs.
- * @param outputIovLen The number of iovec struct created
- * @return CELIX_SUCCESS on success, CELIX_ILLEGAL_ARGUMENT if the msg id is not known or serialization failed.
- */
-celix_status_t pubsub_serializerHandler_serialize(pubsub_serializer_handler_t* handler, uint32_t msgId, const void* input, struct iovec** output, size_t* outputIovLen);
-
-/**
- * Free the memory of for the serialized msg.
- */
-celix_status_t pubsub_serializerHandler_freeSerializedMsg(pubsub_serializer_handler_t* handler, uint32_t msgId, struct iovec* input, size_t inputIovLen);
-
-/**
- * Deserialize a message using the provided iovec buffers.
- *
- * The deserialize function will also check if the target major/minor version of the message is valid with the version
- * of the serialized data.
- *
- * For some serialization types (e.g. JSON) newer versions of the serialized data can be deserialized.
- * E.g. JSON serialized data with version 1.2.0 can be deserialized to a target message with version 1.0.0
- * But JSON serialized data with a version 2.0.0 will not be deserialized to a target message with version 1.0.0
- * This assume correct use of semantic versioning.
- *
- * @param handler The pubsub serialization handler.
- * @param msgId The msg id for the message to be deserialized.
- * @param serializedMajorVersion The major version of the serialized data
- * @param serializedMinorVersion The minor version of the serialized data.
- * @param input Pointer to the first element in a array of iovecs.
- * @param inputIovLen Then number of iovecs.
- * @param out The newly allocated and deserialized message object
- * @return CELIX_SUCCESS on success. CELIX_ILLEGAL_ARGUMENT if the msg id is not known,
- * or if the version do no match or deserialization failed.
- */
-celix_status_t pubsub_serializerHandler_deserialize(pubsub_serializer_handler_t* handler, uint32_t msgId, int serializedMajorVersion, int serializedMinorVersion, const struct iovec* input, size_t inputIovLen, void** out);
-
-/**
- * Free the memory for the deserialized message.
- */
-celix_status_t pubsub_serializerHandler_freeDeserializedMsg(pubsub_serializer_handler_t* handler, uint32_t msgId, void* msg);
-----
\ No newline at end of file
diff --git a/bundles/pubsub/examples/CMakeLists.txt b/bundles/pubsub/examples/CMakeLists.txt
deleted file mode 100644
index 5afeb5a6..00000000
--- a/bundles/pubsub/examples/CMakeLists.txt
+++ /dev/null
@@ -1,361 +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_EXAMPLES "Option to build the pubsub examples" ON)
-if (PUBSUB_EXAMPLES)
- add_subdirectory(pubsub)
-
- find_program(ETCD_CMD NAMES etcd)
- find_program(XTERM_CMD NAMES xterm)
-
- if (BUILD_PUBSUB_PSA_TCP AND BUILD_LAUNCHER)
- # TCP
- add_celix_container(pubsub_publisher_tcp
- 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_tcp
- Celix::celix_pubsub_protocol_wire_v2
- celix_pubsub_poi_publisher
- celix_pubsub_poi_publisher2
- USE_CONFIG
- PROPERTIES
- PSA_TCP_VERBOSE=true
- PUBSUB_ETCD_DISCOVERY_VERBOSE=true
- PUBSUB_TOPOLOGY_MANAGER_VERBOSE=true
- )
-
- add_celix_container(pubsub_subscriber_tcp
- 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_tcp
- Celix::celix_pubsub_protocol_wire_v2
- celix_pubsub_poi_subscriber
- USE_CONFIG
- PROPERTIES
- PSA_TCP_VERBOSE=true
- PUBSUB_ETCD_DISCOVERY_VERBOSE=true
- PUBSUB_TOPOLOGY_MANAGER_VERBOSE=true
- )
-
- add_celix_container(pubsub_subscriber2_tcp
- 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_tcp
- Celix::celix_pubsub_protocol_wire_v2
- celix_pubsub_poi_subscriber
- USE_CONFIG
- PROPERTIES
- PSA_TCP_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 tcp
- add_celix_runtime(pubsub_rt_tcp
- NAME tcp
- GROUP pubsub
- CONTAINERS
- pubsub_publisher_tcp
- pubsub_subscriber_tcp
- pubsub_subscriber2_tcp
- COMMANDS
- etcd
- USE_TERM
- )
- endif ()
- endif()
-
- if (BUILD_PUBSUB_PSA_ZMQ AND BUILD_LAUNCHER)
-
- if (BUILD_PUBSUB_PSA_TCP)
- # Dynamic ZMQ / UDP / TCP admin
- add_celix_container(pubsub_publisher
- LAUNCHER Celix::launcher
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_discovery_etcd
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_zmq
- Celix::celix_pubsub_admin_tcp
- Celix::celix_pubsub_protocol_wire_v1
- celix_pubsub_poi_publisher
- celix_pubsub_poi_publisher2
- USE_CONFIG
- )
-
- add_celix_container(pubsub_subscriber
- LAUNCHER Celix::launcher
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_discovery_etcd
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_zmq
- Celix::celix_pubsub_admin_tcp
- Celix::celix_pubsub_protocol_wire_v1
- celix_pubsub_poi_subscriber
- USE_CONFIG
- )
- endif()
-
- # ZMQ
- add_celix_container(pubsub_zmq
- LAUNCHER Celix::launcher
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_discovery_etcd
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_zmq
- celix_pubsub_poi_publisher
- celix_pubsub_poi_subscriber
- USE_CONFIG
- PROPERTIES
- PSA_ZMQ_ZEROCOPY_ENABLED=true
- )
-
- add_celix_container(pubsub_publisher_zmq
- LAUNCHER Celix::launcher
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_protocol_wire_v1
- Celix::celix_pubsub_discovery_etcd
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_zmq
- celix_pubsub_poi_publisher
- celix_pubsub_poi_publisher2
- celix_pubsub_interceptors_example
- USE_CONFIG
- PROPERTIES
- PSA_ZMQ_VERBOSE=true
- PUBSUB_ETCD_DISCOVERY_VERBOSE=true
- PUBSUB_TOPOLOGY_MANAGER_VERBOSE=true
- PSA_ZMQ_ZEROCOPY_ENABLED=false
- )
-
- add_celix_container(pubsub_subscriber_zmq
- LAUNCHER Celix::launcher
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_protocol_wire_v1
- Celix::celix_pubsub_discovery_etcd
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_zmq
- celix_pubsub_poi_subscriber
- celix_pubsub_interceptors_example
- USE_CONFIG
- PROPERTIES
- PSA_ZMQ_VERBOSE=true
- PUBSUB_ETCD_DISCOVERY_VERBOSE=true
- PUBSUB_TOPOLOGY_MANAGER_VERBOSE=true
- )
-
- add_celix_container(pubsub_subscriber2_zmq
- LAUNCHER Celix::launcher
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_discovery_etcd
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_zmq
- celix_pubsub_poi_subscriber
- USE_CONFIG
- PROPERTIES
- PSA_ZMQ_VERBOSE=true
- PUBSUB_ETCD_DISCOVERY_VERBOSE=true
- PUBSUB_TOPOLOGY_MANAGER_VERBOSE=true
- )
-
- if (ETCD_CMD AND XTERM_CMD)
- # Runtime starting two bundles using both zmq and upd mc pubsub
- add_celix_runtime(pubsub_rt_zmq_udpmc_combi
- NAME combi
- GROUP pubsub
- CONTAINERS
- pubsub_publisher_zmq
- pubsub_subscriber_zmq
- pubsub_subscriber_zmq
- COMMANDS
- etcd
- USE_TERM
- )
-
- # Runtime starting a publish and 2 subscribers for zmq
- add_celix_runtime(pubsub_rt_zmq
- NAME zmq
- GROUP pubsub
- CONTAINERS
- pubsub_publisher_zmq
- pubsub_subscriber_zmq
- pubsub_subscriber2_zmq
- COMMANDS
- etcd
- USE_TERM
- )
- endif ()
- endif()
-
- if (BUILD_PUBSUB_PSA_NANOMSG AND BUILD_LAUNCHER)
-
- add_celix_container(pubsub_publisher1_nanomsg
- LAUNCHER Celix::launcher
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_discovery_etcd
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_nanomsg
- celix_pubsub_poi_publisher
- USE_CONFIG
- PROPERTIES
- PSA_NANOMSG_VERBOSE=true
- PUBSUB_ETCD_DISCOVERY_VERBOSE=true
- PUBSUB_TOPOLOGY_MANAGER_VERBOSE=true
- )
-
- add_celix_container(pubsub_publisher2_nanomsg
- LAUNCHER Celix::launcher
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_discovery_etcd
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_nanomsg
- celix_pubsub_poi_publisher
- USE_CONFIG
- PROPERTIES
- PSA_NANOMSG_VERBOSE=true
- PUBSUB_ETCD_DISCOVERY_VERBOSE=true
- PUBSUB_TOPOLOGY_MANAGER_VERBOSE=true
- )
-
- add_celix_container(pubsub_subscriber1_nanomsg
- LAUNCHER Celix::launcher
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_discovery_etcd
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_nanomsg
- celix_pubsub_poi_subscriber
- USE_CONFIG
- PROPERTIES
- PSA_NANOMSG_VERBOSE=true
- PUBSUB_ETCD_DISCOVERY_VERBOSE=true
- PUBSUB_TOPOLOGY_MANAGER_VERBOSE=true
- )
-
- add_celix_container(pubsub_subscriber2_nanomsg
- LAUNCHER Celix::launcher
- GROUP "pubsub"
- BUNDLES
- Celix::shell
- Celix::shell_tui
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_discovery_etcd
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_nanomsg
- celix_pubsub_poi_subscriber
- USE_CONFIG
- PROPERTIES
- PSA_NANOMSG_VERBOSE=true
- PUBSUB_ETCD_DISCOVERY_VERBOSE=true
- PUBSUB_TOPOLOGY_MANAGER_VERBOSE=true
- )
-
- if (ETCD_CMD AND XTERM_CMD)
- # Runtime starting a publisher and 2 subscribers for nanomsg
- add_celix_runtime(pubsub_rt_nanomsg
- NAME nanomsg
- GROUP pubsub
- CONTAINERS
- pubsub_publisher1_nanomsg
- pubsub_publisher2_nanomsg
- pubsub_subscriber1_nanomsg
- pubsub_subscriber2_nanomsg
- COMMANDS
- etcd
- USE_TERM
- )
- endif ()
-
- endif()
-
- if (BUILD_PUBSUB_PSA_WS)
- add_celix_container(pubsub_websocket_example
- GROUP pubsub
- BUNDLES
- Celix::log_admin
- Celix::shell
- Celix::shell_tui
- Celix::http_admin
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_websocket
- celix_pubsub_websocket_example
- PROPERTIES
- PSA_TCP_VERBOSE=true
- PUBSUB_ETCD_DISCOVERY_VERBOSE=true
- PUBSUB_TOPOLOGY_MANAGER_VERBOSE=true
- CELIX_HTTP_ADMIN_LISTENING_PORTS=7660
- CELIX_HTTP_ADMIN_NUM_THREADS=5
- )
- endif()
-endif ()
diff --git a/bundles/pubsub/examples/keys/README.md b/bundles/pubsub/examples/keys/README.md
deleted file mode 100644
index b46438b3..00000000
--- a/bundles/pubsub/examples/keys/README.md
+++ /dev/null
@@ -1,39 +0,0 @@
----
-title: Pubsub Keys
----
-
-<!--
-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.
--->
-
-Store the AES key for encrypting and decrypting the encoded secret keys safe in a file!
-Default file is `/etc/pubsub.keys` with the following format:
-```
-aes_key:{32 character AES key here}
-aes_iv:{16 character AES iv here}
-```
-
-Use the $PROJECT_BUILD/pubsub/keygen/makecert for generating keypairs
-Use the $PROJECT_BUILD/pubsub/keygen/ed_file for encrypting and decrypting private keys
-
-Public keys need to be stored in the 'public' folder having the following format:
-- pub_{topic}.pub
-- sub_{topic}.pub
-
-Secret keys need to be stored in the 'private' folder having the following format:
-- pub_{topic}.key.enc
-- sub_{topic}.key.enc
-These files need to be encrypted using the 'ed_file' executable.
diff --git a/bundles/pubsub/examples/keys/publisher/private/.gitkeep b/bundles/pubsub/examples/keys/publisher/private/.gitkeep
deleted file mode 100644
index 4ea9b315..00000000
--- a/bundles/pubsub/examples/keys/publisher/private/.gitkeep
+++ /dev/null
@@ -1,14 +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.
diff --git a/bundles/pubsub/examples/keys/publisher/public/.gitkeep b/bundles/pubsub/examples/keys/publisher/public/.gitkeep
deleted file mode 100644
index 978b68af..00000000
--- a/bundles/pubsub/examples/keys/publisher/public/.gitkeep
+++ /dev/null
@@ -1,16 +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.
diff --git a/bundles/pubsub/examples/keys/subscriber/private/.gitkeep b/bundles/pubsub/examples/keys/subscriber/private/.gitkeep
deleted file mode 100644
index 978b68af..00000000
--- a/bundles/pubsub/examples/keys/subscriber/private/.gitkeep
+++ /dev/null
@@ -1,16 +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.
diff --git a/bundles/pubsub/examples/keys/subscriber/public/.gitkeep b/bundles/pubsub/examples/keys/subscriber/public/.gitkeep
deleted file mode 100644
index 978b68af..00000000
--- a/bundles/pubsub/examples/keys/subscriber/public/.gitkeep
+++ /dev/null
@@ -1,16 +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.
diff --git a/bundles/pubsub/examples/pubsub/CMakeLists.txt b/bundles/pubsub/examples/pubsub/CMakeLists.txt
deleted file mode 100644
index 427dbd1e..00000000
--- a/bundles/pubsub/examples/pubsub/CMakeLists.txt
+++ /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.
-
-include_directories("common/include")
-
-add_subdirectory(interceptors)
-add_subdirectory(publisher)
-add_subdirectory(publisher2)
-if (BUILD_PUBSUB_PSA_WS)
- add_subdirectory(pubsub_websocket)
-endif()
-add_subdirectory(subscriber)
-
-
diff --git a/bundles/pubsub/examples/pubsub/common/include/poi.h b/bundles/pubsub/examples/pubsub/common/include/poi.h
deleted file mode 100644
index 8f592220..00000000
--- a/bundles/pubsub/examples/pubsub/common/include/poi.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/**
- * poi.h
- *
- * \date Nov 12, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef POI_H_
-#define POI_H_
-
-#define MIN_LAT -90.0F
-#define MAX_LAT 90.0F
-#define MIN_LON -180.0F
-#define MAX_LON 180.0F
-
-#define MSG_POI_NAME "poi" //Has to match the message name in the msg descriptor!
-
-struct poi{
- double lat;
- double lon;
-};
-
-typedef struct poi1 poi1_t;
-
-struct location{
- struct poi position;
- char* name;
- char* description;
- char* extra;
- char* data;
-};
-
-typedef struct location* location_t;
-
-
-#endif /* POI_H_ */
diff --git a/bundles/pubsub/examples/pubsub/common/include/poiCmd.h b/bundles/pubsub/examples/pubsub/common/include/poiCmd.h
deleted file mode 100644
index 1c9c0a3b..00000000
--- a/bundles/pubsub/examples/pubsub/common/include/poiCmd.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.
- */
-/**
- * poiCmd.h
- *
- * \date Jan 16, 2020
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef POICMD_H_
-#define POICMD_H_
-
-#define MSG_POI_CMD_NAME "poiCmd" //Has to match the message name in the msg descriptor!
-
-struct poi_cmd{
- char* command;
-};
-
-typedef struct poi_cmd poi_cmd_t;
-
-
-#endif /* POICMD_H_ */
diff --git a/bundles/pubsub/examples/pubsub/interceptors/CMakeLists.txt b/bundles/pubsub/examples/pubsub/interceptors/CMakeLists.txt
deleted file mode 100644
index 0be810a3..00000000
--- a/bundles/pubsub/examples/pubsub/interceptors/CMakeLists.txt
+++ /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.
-
-add_celix_bundle(celix_pubsub_interceptors_example
- SYMBOLIC_NAME "celix_pubsub_interceptors_example"
- VERSION "1.0.0"
- SOURCES
- src/ps_interceptor_activator.c
- src/first_interceptor.c
- src/second_interceptor.c
-)
-
-target_link_libraries(celix_pubsub_interceptors_example PRIVATE Celix::pubsub_spi)
-target_include_directories(celix_pubsub_interceptors_example PRIVATE include)
\ No newline at end of file
diff --git a/bundles/pubsub/examples/pubsub/interceptors/include/first_interceptor_private.h b/bundles/pubsub/examples/pubsub/interceptors/include/first_interceptor_private.h
deleted file mode 100644
index ddc5dbd9..00000000
--- a/bundles/pubsub/examples/pubsub/interceptors/include/first_interceptor_private.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 CELIX_FIRST_INTERCEPTOR_PRIVATE_H
-#define CELIX_FIRST_INTERCEPTOR_PRIVATE_H
-
-#include <celix_threads.h>
-#include "pubsub_interceptor.h"
-
-typedef struct first_interceptor {
-
- celix_thread_mutex_t mutex;
-
- uint64_t sequenceNumber;
-
-} first_interceptor_t;
-
-static const char *const SEQUENCE_NUMBER = "sequence.number";
-
-celix_status_t firstInterceptor_create(first_interceptor_t **interceptor);
-celix_status_t firstInterceptor_destroy(first_interceptor_t *interceptor);
-
-bool firstInterceptor_preSend(void *handle, const pubsub_interceptor_properties_t *properties, const char *messageType, uint32_t msgTypeId, const void *message, celix_properties_t *metadata);
-void firstInterceptor_postSend(void *handle, const pubsub_interceptor_properties_t *properties, const char *messageType, uint32_t msgTypeId, const void *message, celix_properties_t *metadata);
-bool firstInterceptor_preReceive(void *handle, const pubsub_interceptor_properties_t *properties, const char *messageType, uint32_t msgTypeId, const void *message, celix_properties_t *metadata);
-void firstInterceptor_postReceive(void *handle, const pubsub_interceptor_properties_t *properties, const char *messageType, uint32_t msgTypeId, const void *message, celix_properties_t *metadata);
-
-#endif //CELIX_FIRST_INTERCEPTOR_PRIVATE_H
diff --git a/bundles/pubsub/examples/pubsub/interceptors/include/second_interceptor_private.h b/bundles/pubsub/examples/pubsub/interceptors/include/second_interceptor_private.h
deleted file mode 100644
index 4819277a..00000000
--- a/bundles/pubsub/examples/pubsub/interceptors/include/second_interceptor_private.h
+++ /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.
- */
-#ifndef CELIX_SECOND_INTERCEPTOR_PRIVATE_H
-#define CELIX_SECOND_INTERCEPTOR_PRIVATE_H
-
-#include "pubsub_interceptor.h"
-
-typedef struct second_interceptor {
-
-} second_interceptor_t;
-
-celix_status_t secondInterceptor_create(second_interceptor_t **interceptor);
-celix_status_t secondInterceptor_destroy(second_interceptor_t *interceptor);
-
-bool secondInterceptor_preSend(void *handle, const pubsub_interceptor_properties_t *properties, const char *messageType, uint32_t msgTypeId, const void *message, celix_properties_t *metadata);
-void secondInterceptor_postSend(void *handle, const pubsub_interceptor_properties_t *properties, const char *messageType, uint32_t msgTypeId, const void *message, celix_properties_t *metadata);
-bool secondInterceptor_preReceive(void *handle, const pubsub_interceptor_properties_t *properties, const char *messageType, uint32_t msgTypeId, const void *message, celix_properties_t *metadata);
-void secondInterceptor_postReceive(void *handle, const pubsub_interceptor_properties_t *properties, const char *messageType, uint32_t msgTypeId, const void *message, celix_properties_t *metadata);
-
-#endif //CELIX_SECOND_INTERCEPTOR_PRIVATE_H
diff --git a/bundles/pubsub/examples/pubsub/interceptors/src/first_interceptor.c b/bundles/pubsub/examples/pubsub/interceptors/src/first_interceptor.c
deleted file mode 100644
index 62ce21d7..00000000
--- a/bundles/pubsub/examples/pubsub/interceptors/src/first_interceptor.c
+++ /dev/null
@@ -1,73 +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 "first_interceptor_private.h"
-
-#include <inttypes.h>
-
-celix_status_t firstInterceptor_create(first_interceptor_t **interceptor) {
- celix_status_t status = CELIX_SUCCESS;
-
- *interceptor = calloc(1, sizeof(**interceptor));
- if (!*interceptor) {
- status = CELIX_ENOMEM;
- } else {
- (*interceptor)->sequenceNumber = 0;
-
- status = celixThreadMutex_create(&(*interceptor)->mutex, NULL);
- }
-
- return status;
-}
-
-celix_status_t firstInterceptor_destroy(first_interceptor_t *interceptor) {
- free(interceptor);
- return CELIX_SUCCESS;
-}
-
-
-bool firstInterceptor_preSend(void *handle, const pubsub_interceptor_properties_t *properties, const char *messageType, const uint32_t msgTypeId, const void *message, celix_properties_t *metadata) {
- first_interceptor_t *interceptor = handle;
- celixThreadMutex_lock(&interceptor->mutex);
-
- printf("Invoked preSend on first interceptor\n");
-
- celix_properties_setLong((celix_properties_t *) metadata, SEQUENCE_NUMBER, interceptor->sequenceNumber++);
-
- celixThreadMutex_unlock(&interceptor->mutex);
-
- return true;
-}
-
-void firstInterceptor_postSend(void *handle, const pubsub_interceptor_properties_t *properties, const char *messageType, uint32_t msgTypeId, const void *message, celix_properties_t *metadata) {
- uint64_t sequence = celix_properties_getAsLong(metadata, SEQUENCE_NUMBER, 0);
- printf("Invoked postSend on first interceptor, for message with sequenceNumber [%"PRIu64"]\n", sequence);
-}
-
-bool firstInterceptor_preReceive(void *handle, const pubsub_interceptor_properties_t *properties, const char *messageType, uint32_t msgTypeId, const void *message, celix_properties_t *metadata) {
- uint64_t sequence = celix_properties_getAsLong(metadata, SEQUENCE_NUMBER, 0);
- printf("Invoked preReceive on first interceptor, for message with sequenceNumber [%"PRIu64"]\n", sequence);
-
- return true;
-}
-
-void firstInterceptor_postReceive(void *handle, const pubsub_interceptor_properties_t *properties, const char *messageType, uint32_t msgTypeId, const void *message, celix_properties_t *metadata) {
- uint64_t sequence = celix_properties_getAsLong(metadata, SEQUENCE_NUMBER, 0);
- printf("Invoked postReceive on first interceptor, for message with sequenceNumber [%"PRIu64"]\n", sequence);
-}
-
diff --git a/bundles/pubsub/examples/pubsub/interceptors/src/ps_interceptor_activator.c b/bundles/pubsub/examples/pubsub/interceptors/src/ps_interceptor_activator.c
deleted file mode 100644
index 9bafd755..00000000
--- a/bundles/pubsub/examples/pubsub/interceptors/src/ps_interceptor_activator.c
+++ /dev/null
@@ -1,95 +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_constants.h"
-
-#include "first_interceptor_private.h"
-#include "second_interceptor_private.h"
-
-#include <string.h>
-
-struct interceptorActivator {
- first_interceptor_t *interceptor;
- uint64_t interceptorSvcId;
- pubsub_interceptor_t interceptorSvc;
-
- second_interceptor_t *secondInterceptor;
- uint64_t secondInterceptorSvcId;
- pubsub_interceptor_t secondInterceptorSvc;
-};
-
-static int interceptor_start(struct interceptorActivator *act, celix_bundle_context_t *ctx) {
- first_interceptor_t *interceptor = NULL;
- firstInterceptor_create(&interceptor);
-
- act->interceptorSvc.handle = interceptor;
- act->interceptorSvc.preSend = firstInterceptor_preSend;
- act->interceptorSvc.postSend = firstInterceptor_postSend;
- act->interceptorSvc.preReceive = firstInterceptor_preReceive;
- act->interceptorSvc.postReceive = firstInterceptor_postReceive;
-
- act->interceptor = interceptor;
-
- celix_properties_t *props = celix_properties_create();
- celix_properties_setLong(props, CELIX_FRAMEWORK_SERVICE_RANKING, 10);
-
- celix_service_registration_options_t opts = CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS;
- opts.svc = &act->interceptorSvc;
- opts.serviceName = PUBSUB_INTERCEPTOR_SERVICE_NAME;
- opts.serviceVersion = PUBSUB_INTERCEPTOR_SERVICE_VERSION;
- opts.properties = props;
-
- act->interceptorSvcId = celix_bundleContext_registerServiceWithOptions(ctx, &opts);
-
- second_interceptor_t *secondInterceptor = NULL;
- secondInterceptor_create(&secondInterceptor);
-
- act->secondInterceptorSvc.handle = secondInterceptor;
- act->secondInterceptorSvc.preSend = secondInterceptor_preSend;
- act->secondInterceptorSvc.postSend = secondInterceptor_postSend;
- act->secondInterceptorSvc.preReceive = secondInterceptor_preReceive;
- act->secondInterceptorSvc.postReceive = secondInterceptor_postReceive;
-
- act->secondInterceptor = secondInterceptor;
-
- celix_properties_t *secondProps = celix_properties_create();
- celix_properties_setLong(secondProps, CELIX_FRAMEWORK_SERVICE_RANKING, 20);
-
- celix_service_registration_options_t secondOpts = CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS;
- secondOpts.svc = &act->secondInterceptorSvc;
- secondOpts.serviceName = PUBSUB_INTERCEPTOR_SERVICE_NAME;
- secondOpts.serviceVersion = PUBSUB_INTERCEPTOR_SERVICE_VERSION;
- secondOpts.properties = secondProps;
-
- act->secondInterceptorSvcId = celix_bundleContext_registerServiceWithOptions(ctx, &secondOpts);
-
- return 0;
-}
-
-static int interceptor_stop(struct interceptorActivator *act, celix_bundle_context_t *ctx) {
- celix_bundleContext_unregisterService(ctx, act->interceptorSvcId);
- firstInterceptor_destroy(act->interceptor);
-
- celix_bundleContext_unregisterService(ctx, act->secondInterceptorSvcId);
- secondInterceptor_destroy(act->secondInterceptor);
-
- return 0;
-}
-
-CELIX_GEN_BUNDLE_ACTIVATOR(struct interceptorActivator, interceptor_start, interceptor_stop)
\ No newline at end of file
diff --git a/bundles/pubsub/examples/pubsub/interceptors/src/second_interceptor.c b/bundles/pubsub/examples/pubsub/interceptors/src/second_interceptor.c
deleted file mode 100644
index be4d04e1..00000000
--- a/bundles/pubsub/examples/pubsub/interceptors/src/second_interceptor.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-#include "second_interceptor_private.h"
-
-celix_status_t secondInterceptor_create(second_interceptor_t **interceptor) {
- celix_status_t status = CELIX_SUCCESS;
-
- *interceptor = calloc(1, sizeof(**interceptor));
- if (!*interceptor) {
- status = CELIX_ENOMEM;
- } else {
- }
-
- return status;
-}
-
-celix_status_t secondInterceptor_destroy(second_interceptor_t *interceptor) {
- free(interceptor);
- return CELIX_SUCCESS;
-}
-
-
-bool secondInterceptor_preSend(void *handle, const pubsub_interceptor_properties_t *properties, const char *messageType, uint32_t msgTypeId, const void *message, celix_properties_t *metadata) {
- printf("Invoked preSend on second interceptor\n");
-
- return true;
-}
-
-void secondInterceptor_postSend(void *handle, const pubsub_interceptor_properties_t *properties, const char *messageType, uint32_t msgTypeId, const void *message, celix_properties_t *metadata) {
- printf("Invoked postSend on second interceptor\n");
-}
-
-bool secondInterceptor_preReceive(void *handle, const pubsub_interceptor_properties_t *properties, const char *messageType, uint32_t msgTypeId, const void *message, celix_properties_t *metadata) {
- printf("Invoked preReceive on second interceptor\n");
-
- return true;
-}
-
-void secondInterceptor_postReceive(void *handle, const pubsub_interceptor_properties_t *properties, const char *messageType, uint32_t msgTypeId, const void *message, celix_properties_t *metadata) {
- printf("Invoked postReceive on second interceptor\n");
-}
-
diff --git a/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poi1.descriptor b/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poi1.descriptor
deleted file mode 100644
index 367bf348..00000000
--- a/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poi1.descriptor
+++ /dev/null
@@ -1,10 +0,0 @@
-:header
-type=message
-name=poi1
-version=1.0.0
-:annotations
-classname=org.example.PointOfInterest
-:types
-location={DD lat lon}
-:message
-{llocation;tttt location name description extra data}
diff --git a/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poi2.descriptor b/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poi2.descriptor
deleted file mode 100644
index 32870e85..00000000
--- a/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poi2.descriptor
+++ /dev/null
@@ -1,11 +0,0 @@
-:header
-type=message
-name=poi2
-version=1.0.0
-:annotations
-classname=org.example.PointOfInterest
-msgId=5555
-:types
-location={DD lat lon}
-:message
-{llocation;tttt location name description extra data}
diff --git a/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poiCmd.descriptor b/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poiCmd.descriptor
deleted file mode 100644
index f4f263c2..00000000
--- a/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poiCmd.descriptor
+++ /dev/null
@@ -1,8 +0,0 @@
-:header
-type=message
-name=poiCmd
-version=1.0.0
-:annotations
-classname=org.example.PointOfInterestCommand
-:message
-{t command}
diff --git a/bundles/pubsub/examples/pubsub/msg_descriptors/poi1.properties b/bundles/pubsub/examples/pubsub/msg_descriptors/poi1.properties
deleted file mode 100644
index 1a07f354..00000000
--- a/bundles/pubsub/examples/pubsub/msg_descriptors/poi1.properties
+++ /dev/null
@@ -1,38 +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.
-
-#
-# included in the bundle at location META-INF/topics/[pub|sub]/poi1.properties
-#
-
-#topic info
-topic.name=poi1
-topic.id=poi1
-
-#Interface info
-interface.name=org.example.unknown
-interface.version=1.0.0
-interface.messages=poi1 poi2
-
-# Version info
-interface.message.consumer.range@poi1=[0.0.0,1.0.0)
-interface.message.provider.version@poi1=0.0.0
-interface.message.consumer.range@poi2=[0.0.0,1.0.0)
-interface.message.provider.version@poi2=0.0.0
-
-
-qos=sample
diff --git a/bundles/pubsub/examples/pubsub/msg_descriptors/poi2.properties b/bundles/pubsub/examples/pubsub/msg_descriptors/poi2.properties
deleted file mode 100644
index c0c6e28a..00000000
--- a/bundles/pubsub/examples/pubsub/msg_descriptors/poi2.properties
+++ /dev/null
@@ -1,38 +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.
-
-#
-# included in the bundle at location META-INF/topics/[pub|sub]/poi2.properties
-#
-
-#topic info
-topic.name=poi2
-topic.id=poi2
-
-#Interface info
-interface.name=org.example.unknown
-interface.version=1.0.0
-interface.messages=poi1 poi2
-
-# Version info
-interface.message.consumer.range@poi1=[0.0.0,1.0.0)
-interface.message.provider.version@poi1=0.0.0
-interface.message.consumer.range@poi2=[0.0.0,1.0.0)
-interface.message.provider.version@poi2=0.0.0
-
-
-qos=control
diff --git a/bundles/pubsub/examples/pubsub/msg_descriptors/poiCmd.properties b/bundles/pubsub/examples/pubsub/msg_descriptors/poiCmd.properties
deleted file mode 100644
index ffecb9d3..00000000
--- a/bundles/pubsub/examples/pubsub/msg_descriptors/poiCmd.properties
+++ /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.
-
-#
-# included in the bundle at location META-INF/topics/[pub|sub]/poi2.properties
-#
-
-#topic info
-topic.name=poiCmd
-topic.id=poiCmd
-
-#Interface info
-interface.name=org.example.unknown
-interface.version=1.0.0
-interface.messages=poiCmd
-
-# Version info
-interface.message.consumer.range@poiCmd=[0.0.0,1.0.0)
-interface.message.provider.version@poiCmd=0.0.0
-
-qos=control
diff --git a/bundles/pubsub/examples/pubsub/publisher/CMakeLists.txt b/bundles/pubsub/examples/pubsub/publisher/CMakeLists.txt
deleted file mode 100644
index b55d9077..00000000
--- a/bundles/pubsub/examples/pubsub/publisher/CMakeLists.txt
+++ /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.
-
-add_celix_bundle(celix_pubsub_poi_publisher
- SYMBOLIC_NAME "apache_celix_pubsub_poi_publisher"
- VERSION "1.0.0"
- SOURCES
- private/src/ps_pub_activator.c
- private/src/pubsub_publisher.c
-)
-
-target_link_libraries(celix_pubsub_poi_publisher PRIVATE Celix::pubsub_api)
-target_include_directories(celix_pubsub_poi_publisher PRIVATE private/include)
-celix_deprecated_utils_headers(celix_pubsub_poi_publisher)
-celix_deprecated_framework_headers(celix_pubsub_poi_publisher)
-
-celix_bundle_files(celix_pubsub_poi_publisher
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poi1.descriptor
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poi2.descriptor
- DESTINATION "META-INF/descriptors"
-)
-
-celix_bundle_files(celix_pubsub_poi_publisher
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/poi1.properties
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/poi2.properties
- DESTINATION "META-INF/topics/pub"
-)
-
-celix_bundle_files(celix_pubsub_poi_publisher
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/keys/publisher
- DESTINATION "META-INF/keys"
-)
-
-celix_bundle_files(celix_pubsub_poi_publisher
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/keys/subscriber/public
- DESTINATION "META-INF/keys/subscriber"
-)
diff --git a/bundles/pubsub/examples/pubsub/publisher/private/include/pubsub_publisher_private.h b/bundles/pubsub/examples/pubsub/publisher/private/include/pubsub_publisher_private.h
deleted file mode 100644
index 12d42272..00000000
--- a/bundles/pubsub/examples/pubsub/publisher/private/include/pubsub_publisher_private.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef PUBSUB_PUBLISHER_PRIVATE_H_
-#define PUBSUB_PUBLISHER_PRIVATE_H_
-
-#include "celix_array_list.h"
-#include "hash_map.h"
-#include <pthread.h>
-#include "pubsub/publisher.h"
-
-struct pubsub_sender {
- celix_array_list_t* trackers;
- const char *ident;
- hash_map_pt tid_map; //service -> tid
- long bundleId;
- bool stop;
-};
-typedef struct pubsub_sender pubsub_sender_t;
-
-struct send_thread_struct {
- pubsub_publisher_t *service;
- pubsub_sender_t *publisher;
- const char *topic;
-};
-typedef struct send_thread_struct send_thread_struct_t;
-
-pubsub_sender_t* publisher_create(celix_array_list_t* trackers, const char* ident,long bundleId);
-
-void publisher_start(pubsub_sender_t *client);
-void publisher_stop(pubsub_sender_t *client);
-
-void publisher_destroy(pubsub_sender_t *client);
-
-void publisher_publishSvcAdded(void * handle, void *svc, const celix_properties_t *props);
-void publisher_publishSvcRemoved(void * handle, void *svc, const celix_properties_t *props);
-
-
-#endif /* PUBSUB_PUBLISHER_PRIVATE_H_ */
diff --git a/bundles/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c b/bundles/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c
deleted file mode 100644
index 7efc3ac1..00000000
--- a/bundles/pubsub/examples/pubsub/publisher/private/src/ps_pub_activator.c
+++ /dev/null
@@ -1,96 +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 <sys/cdefs.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "celix_bundle_activator.h"
-
-#include "pubsub/publisher.h"
-#include "pubsub_publisher_private.h"
-
-static const char * PUB_TOPICS[] = {
- "poi1",
- "poi2",
- NULL
-};
-
-struct publisherActivator {
- pubsub_sender_t *client;
- celix_array_list_t* trackerList;//List<service_tracker_pt>
-};
-
-static int pub_start(struct publisherActivator *act, celix_bundle_context_t *ctx) {
- const char *fwUUID = celix_bundleContext_getProperty(ctx,CELIX_FRAMEWORK_UUID, NULL);
- if (fwUUID == NULL) {
- printf("PUBLISHER: Cannot retrieve fwUUID.\n");
- return CELIX_INVALID_BUNDLE_CONTEXT;
- }
-
-
- celix_bundle_t *bnd = celix_bundleContext_getBundle(ctx);
- long bundleId = celix_bundle_getId(bnd);
-
- act->trackerList = celix_arrayList_create();
- act->client = publisher_create(act->trackerList, fwUUID, bundleId);
-
- int i;
- char filter[128];
- for (i = 0; PUB_TOPICS[i] != NULL; i++) {
- const char* topic = PUB_TOPICS[i];
- memset(filter,0,128);
-#ifdef USE_SCOPE
- char *scope;
- asprintf(&scope, "my_scope_%d", i);
- snprintf(filter, 128, "(%s=%s)(%s=%s)", PUBSUB_PUBLISHER_TOPIC, topic, PUBSUB_PUBLISHER_SCOPE, scope);
- free(scope);
-#else
- snprintf(filter, 128, "(&(%s=%s)(!(%s=*)))", (char*) PUBSUB_PUBLISHER_TOPIC, topic, PUBSUB_PUBLISHER_SCOPE);
-#endif
- celix_service_tracking_options_t opts = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS;
- opts.callbackHandle = act->client;
- opts.addWithProperties = publisher_publishSvcAdded;
- opts.removeWithProperties = publisher_publishSvcRemoved;
- opts.filter.serviceName = PUBSUB_PUBLISHER_SERVICE_NAME;
- opts.filter.filter = filter;
- long trackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts);
-
- celix_arrayList_addLong(act->trackerList,trackerId);
- }
-
- publisher_start(act->client);
-
- return 0;
-}
-
-static int pub_stop(struct publisherActivator *act, celix_bundle_context_t *ctx) {
- for (int i = 0; i < celix_arrayList_size(act->trackerList); i++) {
- long trkId = celix_arrayList_getLong(act->trackerList, i);
- celix_bundleContext_stopTracker(ctx, trkId);
- }
- publisher_stop(act->client);
-
- publisher_destroy(act->client);
- celix_arrayList_destroy(act->trackerList);
-
- return 0;
-}
-
-CELIX_GEN_BUNDLE_ACTIVATOR(struct publisherActivator, pub_start, pub_stop)
\ No newline at end of file
diff --git a/bundles/pubsub/examples/pubsub/publisher/private/src/pubsub_publisher.c b/bundles/pubsub/examples/pubsub/publisher/private/src/pubsub_publisher.c
deleted file mode 100644
index c65146f6..00000000
--- a/bundles/pubsub/examples/pubsub/publisher/private/src/pubsub_publisher.c
+++ /dev/null
@@ -1,168 +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.
- */
-/**
- * pubsub_publisher.c
- *
- * \date Sep 21, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <pthread.h>
-#include <unistd.h>
-
-#include "celix_threads.h"
-
-#include "poi.h"
-
-#include "pubsub_publisher_private.h"
-
-static double randCoordinate(double min, double max) {
- double ret = min + (((double)random()) / (((double)RAND_MAX)/(max-min)));
- return ret;
-}
-
-static void* send_thread(void* arg) {
- send_thread_struct_t *st_struct = (send_thread_struct_t *) arg;
-
- pubsub_publisher_t *publish_svc = st_struct->service;
- pubsub_sender_t *publisher = st_struct->publisher;
-
- char fwUUID[9];
- memset(fwUUID, 0, 9);
- memcpy(fwUUID, publisher->ident, 8);
-
- //poi_t point = calloc(1,sizeof(*point));
- location_t place = calloc(1, sizeof(*place));
-
- char *desc = calloc(64, sizeof(char));
- snprintf(desc, 64, "fw-%s [TID=%lu]", fwUUID, (unsigned long)pthread_self());
-
- char *name = calloc(64, sizeof(char));
- snprintf(name, 64, "Bundle#%ld", publisher->bundleId);
-
- place->name = name;
- place->description = desc;
- place->extra = "extra value";
- printf("TOPIC : %s\n", st_struct->topic);
-
- unsigned int msgId = 0;
-
- while (publisher->stop == false) {
- if (msgId == 0) {
- if (publish_svc->localMsgTypeIdForMsgType(publish_svc->handle, st_struct->topic, &msgId) != 0) {
- printf("PUBLISHER: Cannot retrieve msgId for message '%s'\n", MSG_POI_NAME);
- }
- }
-
- if (msgId > 0) {
- place->position.lat = randCoordinate(MIN_LAT, MAX_LAT);
- place->position.lon = randCoordinate(MIN_LON, MAX_LON);
- int nr_char = (int) randCoordinate(5, 100000);
- place->data = calloc(nr_char, 1);
- for (int i = 0; i < (nr_char - 1); i++) {
- place->data[i] = i % 10 + '0';
- }
- place->data[nr_char - 1] = '\0';
- if (publish_svc->send) {
- celix_properties_t *metadata = celix_properties_create();
- celix_properties_set(metadata, "Key", "Value");
- if (publish_svc->send(publish_svc->handle, msgId, place, metadata) == 0) {
- printf("Sent %s [%f, %f] (%s, %s) data len = %d\n", st_struct->topic,
- place->position.lat, place->position.lon, place->name, place->description, nr_char);
- }
- } else {
- printf("No send for %s\n", st_struct->topic);
- }
-
- free(place->data);
- }
- sleep(2);
- }
-
- free(place->description);
- free(place->name);
- free(place);
-
- free(st_struct);
-
- return NULL;
-}
-
-pubsub_sender_t* publisher_create(celix_array_list_t* trackers,const char* ident,long bundleId) {
- pubsub_sender_t *publisher = malloc(sizeof(*publisher));
-
- publisher->trackers = trackers;
- publisher->ident = ident;
- publisher->bundleId = bundleId;
- publisher->tid_map = hashMap_create(NULL, NULL, NULL, NULL);
- publisher->stop = false;
-
- return publisher;
-}
-
-void publisher_start(pubsub_sender_t *client) {
- printf("PUBLISHER: starting up...\n");
-}
-
-void publisher_stop(pubsub_sender_t *client) {
- printf("PUBLISHER: stopping...\n");
-}
-
-void publisher_destroy(pubsub_sender_t *client) {
- hashMap_destroy(client->tid_map, false, false);
- client->trackers = NULL;
- client->ident = NULL;
- free(client);
-}
-
-void publisher_publishSvcAdded(void * handle, void *svc, const celix_properties_t *props) {
- pubsub_publisher_t *publish_svc = (pubsub_publisher_t *) svc;
- pubsub_sender_t *manager = (pubsub_sender_t *) handle;
- manager->stop = false;
-
- printf("PUBLISHER: new publish service exported (%s).\n", manager->ident);
-
- send_thread_struct_t *data = calloc(1, sizeof(*data));
- data->service = publish_svc;
- data->publisher = manager;
- data->topic = celix_properties_get(props, PUBSUB_PUBLISHER_TOPIC, "!ERROR!");
- celix_thread_t *tid = malloc(sizeof(*tid));
- celixThread_create(tid, NULL, send_thread, (void*)data);
- hashMap_put(manager->tid_map, publish_svc, tid);
-}
-
-void publisher_publishSvcRemoved(void * handle, void *svc, const celix_properties_t *props) {
- pubsub_sender_t *manager = (pubsub_sender_t *) handle;
- celix_thread_t *tid = hashMap_get(manager->tid_map, svc);
- manager->stop = true;
-
-#if defined(__APPLE__) && defined(__MACH__)
- uint64_t threadid;
- pthread_threadid_np(tid->thread, &threadid);
- printf("PUBLISHER: publish service unexporting (%s) %llu!\n",manager->ident, threadid);
-#else
- printf("PUBLISHER: publish service unexporting (%s) %li!\n", manager->ident, tid->thread);
-#endif
-
- celixThread_join(*tid,NULL);
- free(tid);
-}
diff --git a/bundles/pubsub/examples/pubsub/publisher2/CMakeLists.txt b/bundles/pubsub/examples/pubsub/publisher2/CMakeLists.txt
deleted file mode 100644
index 60392538..00000000
--- a/bundles/pubsub/examples/pubsub/publisher2/CMakeLists.txt
+++ /dev/null
@@ -1,50 +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(celix_pubsub_poi_publisher2
- SYMBOLIC_NAME "apache_celix_pubsub_poi_publisher2"
- VERSION "1.0.0"
- SOURCES
- ../publisher/private/src/ps_pub_activator.c
- ../publisher/private/src/pubsub_publisher.c
-)
-target_link_libraries(celix_pubsub_poi_publisher2 PRIVATE Celix::pubsub_api)
-target_include_directories(celix_pubsub_poi_publisher2 PRIVATE ../publisher/private/include)
-celix_deprecated_utils_headers(celix_pubsub_poi_publisher2)
-
-celix_bundle_files(celix_pubsub_poi_publisher2
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poi1.descriptor
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poi2.descriptor
- DESTINATION "META-INF/descriptors"
-)
-
-celix_bundle_files(celix_pubsub_poi_publisher2
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/poi1.properties
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/poi2.properties
- DESTINATION "META-INF/topics/pub"
-)
-
-celix_bundle_files(celix_pubsub_poi_publisher2
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/keys/publisher
- DESTINATION "META-INF/keys"
-)
-
-celix_bundle_files(celix_pubsub_poi_publisher2
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/keys/subscriber/public
- DESTINATION "META-INF/keys/subscriber"
-)
-
diff --git a/bundles/pubsub/examples/pubsub/pubsub_websocket/CMakeLists.txt b/bundles/pubsub/examples/pubsub/pubsub_websocket/CMakeLists.txt
deleted file mode 100644
index b51ce136..00000000
--- a/bundles/pubsub/examples/pubsub/pubsub_websocket/CMakeLists.txt
+++ /dev/null
@@ -1,62 +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(celix_pubsub_websocket_example
- SYMBOLIC_NAME "apache_celix_pubsub_websocket_example"
- VERSION "1.0.0"
- SOURCES
- private/src/ps_websocket_activator.c
- private/src/pubsub_websocket_example.c
-)
-target_link_libraries(celix_pubsub_websocket_example PRIVATE Celix::pubsub_api)
-target_include_directories(celix_pubsub_websocket_example PRIVATE private/include)
-celix_deprecated_utils_headers(celix_pubsub_websocket_example)
-celix_deprecated_framework_headers(celix_pubsub_websocket_example)
-
-celix_bundle_files(celix_pubsub_websocket_example
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poi1.descriptor
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poi2.descriptor
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poiCmd.descriptor
- DESTINATION "META-INF/descriptors"
-)
-
-celix_bundle_files(celix_pubsub_websocket_example
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/poi1.properties
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/poi2.properties
- DESTINATION "META-INF/topics/pub"
-)
-celix_bundle_files(celix_pubsub_websocket_example
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/poiCmd.properties
- DESTINATION "META-INF/topics/sub"
-)
-
-celix_bundle_files(celix_pubsub_websocket_example
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/keys/publisher
- DESTINATION "META-INF/keys"
-)
-
-celix_bundle_files(celix_pubsub_websocket_example
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/keys/subscriber/public
- DESTINATION "META-INF/keys/subscriber"
-)
-
-celix_bundle_add_dir(celix_pubsub_websocket_example resources DESTINATION ".")
-
-celix_bundle_headers(celix_pubsub_websocket_example
- "X-Web-Resource: /example$<SEMICOLON>/resources"
-)
diff --git a/bundles/pubsub/examples/pubsub/pubsub_websocket/private/include/pubsub_websocket_private.h b/bundles/pubsub/examples/pubsub/pubsub_websocket/private/include/pubsub_websocket_private.h
deleted file mode 100644
index 5a26a684..00000000
--- a/bundles/pubsub/examples/pubsub/pubsub_websocket/private/include/pubsub_websocket_private.h
+++ /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.
- */
-/**
- * pubsub_websocket_private.h
- *
- * \date Jan 16, 2020
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PUBSUB_WEBSOCKET_PRIVATE_H_
-#define PUBSUB_WEBSOCKET_PRIVATE_H_
-
-
-#include <string.h>
-
-#include "celix_api.h"
-
-#include "pubsub/subscriber.h"
-#include "pubsub/publisher.h"
-
-struct pubsub_sender{
- array_list_t *trackers;
- const char *ident;
- hash_map_t *tid_map; //service -> tid
- long bundleId;
- bool stop;
-};
-typedef struct pubsub_sender pubsub_sender_t;
-
-struct pubsub_receiver {
- char *name;
-};
-
-typedef struct pubsub_receiver pubsub_receiver_t;
-
-
-/**
- * Shared Publisher and Subscriber types
- *
- */
-struct pubsub_info {
- pubsub_sender_t *sender;
- bool sending;
- pubsub_receiver_t *receiver;
-};
-
-typedef struct pubsub_info pubsub_info_t;
-
-/**
- * Publisher
- */
-struct send_thread_struct {
- pubsub_publisher_t *service;
- pubsub_info_t *pubsub;
- const char *topic;
-};
-typedef struct send_thread_struct send_thread_struct_t;
-
-pubsub_sender_t* publisher_create(array_list_pt trackers, const char* ident,long bundleId);
-
-void publisher_start(pubsub_sender_t *client);
-void publisher_stop(pubsub_sender_t *client);
-
-void publisher_destroy(pubsub_sender_t *client);
-
-void publisher_publishSvcAdded(void * handle, void *svc, const celix_properties_t *props);
-void publisher_publishSvcRemoved(void * handle, void *svc, const celix_properties_t *props);
-
-/**
- * Subscriber
- */
-pubsub_receiver_t* subscriber_create(char* topics);
-void subscriber_start(pubsub_receiver_t* client);
-void subscriber_stop(pubsub_receiver_t* client);
-void subscriber_destroy(pubsub_receiver_t* client);
-
-int pubsub_subscriber_recv(void* handle, const char* msgType, unsigned int msgTypeId, void* msg, const celix_properties_t *metadata, bool* release);
-
-
-#endif /* PUBSUB_WEBSOCKET_PRIVATE_H_ */
diff --git a/bundles/pubsub/examples/pubsub/pubsub_websocket/private/src/ps_websocket_activator.c b/bundles/pubsub/examples/pubsub/pubsub_websocket/private/src/ps_websocket_activator.c
deleted file mode 100644
index 5cd72d3e..00000000
--- a/bundles/pubsub/examples/pubsub/pubsub_websocket/private/src/ps_websocket_activator.c
+++ /dev/null
@@ -1,163 +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.
- */
-/**
- * ps_websocket_activator.c
- *
- * \date Jan 16, 2020
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-#include <pubsub/subscriber.h>
-#include <pubsub/publisher.h>
-
-#include "celix_api.h"
-
-#include "pubsub_websocket_private.h"
-
-
-static const char * PUB_TOPICS[] = {
- "poi1",
- "poi2",
- NULL
-};
-
-
-#define SUB_NAME "poiCmd"
-static const char * SUB_TOPICS[] = {
- "poiCmd",
- NULL
-};
-
-struct ps_websocketActivator {
- pubsub_info_t *pubsub;
- //Publisher vars
- array_list_t *trackerList;//List<service_tracker_pt>
- //Subscriber vars
- array_list_t *registrationList; //List<service_registration_pt>
- pubsub_subscriber_t *subsvc;
-};
-
-static int pubsub_start(struct ps_websocketActivator *act, celix_bundle_context_t *ctx) {
- const char *fwUUID = celix_bundleContext_getProperty(ctx,CELIX_FRAMEWORK_UUID, NULL);
- if (fwUUID == NULL) {
- printf("PUBLISHER: Cannot retrieve fwUUID.\n");
- return CELIX_INVALID_BUNDLE_CONTEXT;
- }
-
- celix_bundle_t *bnd = celix_bundleContext_getBundle(ctx);
- long bundleId = celix_bundle_getId(bnd);
-
- act->pubsub = calloc(1, sizeof(*act->pubsub));
-
- //Publisher
- act->trackerList = celix_arrayList_create();
- act->pubsub->sender = publisher_create(act->trackerList, fwUUID, bundleId);
-
- int i;
- char filter[128];
- for (i = 0; PUB_TOPICS[i] != NULL; i++) {
- const char* topic = PUB_TOPICS[i];
- memset(filter,0,128);
-#ifdef USE_SCOPE
- char *scope;
- asprintf(&scope, "my_scope_%d", i);
- snprintf(filter, 128, "(%s=%s)(%s=%s)", PUBSUB_PUBLISHER_TOPIC, topic, PUBSUB_PUBLISHER_SCOPE, scope);
- free(scope);
-#else
- snprintf(filter, 128, "(%s=%s)", (char*) PUBSUB_PUBLISHER_TOPIC, topic);
-#endif
- celix_service_tracking_options_t opts = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS;
- opts.callbackHandle = act->pubsub;
- opts.addWithProperties = publisher_publishSvcAdded;
- opts.removeWithProperties = publisher_publishSvcRemoved;
- opts.filter.serviceName = PUBSUB_PUBLISHER_SERVICE_NAME;
- opts.filter.filter = filter;
- long trackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts);
-
- celix_arrayList_addLong(act->trackerList,trackerId);
- }
-
- publisher_start(act->pubsub->sender);
-
- //Subscriber
- act->registrationList = celix_arrayList_create();
-
- pubsub_subscriber_t *subsvc = calloc(1,sizeof(*subsvc));
- act->pubsub->receiver = subscriber_create(SUB_NAME);
- subsvc->handle = act->pubsub;
- subsvc->receive = pubsub_subscriber_recv;
-
- act->subsvc = subsvc;
-
- for (i = 0; SUB_TOPICS[i] != NULL; i++) {
- const char* topic = SUB_TOPICS[i];
- celix_properties_t *props = celix_properties_create();
- celix_properties_set(props, PUBSUB_SUBSCRIBER_TOPIC, topic);
-#ifdef USE_SCOPE
- char *scope;
- asprintf(&scope, "my_scope_%d", i);
- celix_properties_set(props, PUBSUB_SUBSCRIBER_SCOPE, scope);
- free(scope);
-#endif
- service_registration_pt reg = NULL;
- bundleContext_registerService(ctx, PUBSUB_SUBSCRIBER_SERVICE_NAME, subsvc, props, ®);
- arrayList_add(act->registrationList,reg);
- }
-
- subscriber_start((pubsub_receiver_t *) act->subsvc->handle);
-
- return 0;
-}
-
-static int pubsub_stop(struct ps_websocketActivator *act, celix_bundle_context_t *ctx) {
- int i;
-
- //Publishers
- for (i = 0; i < celix_arrayList_size(act->trackerList); i++) {
- long trkId = celix_arrayList_getLong(act->trackerList, i);
- celix_bundleContext_stopTracker(ctx, trkId);
- }
- publisher_stop(act->pubsub->sender);
-
- publisher_destroy(act->pubsub->sender);
- celix_arrayList_destroy(act->trackerList);
-
- //Subscriber
- for (i = 0; i < celix_arrayList_size(act->registrationList); i++) {
- service_registration_pt reg = celix_arrayList_get(act->registrationList, i);
- serviceRegistration_unregister(reg);
- }
-
- subscriber_stop((pubsub_receiver_t *) act->pubsub->receiver);
-
- act->subsvc->receive = NULL;
- subscriber_destroy((pubsub_receiver_t *) act->pubsub->receiver);
- act->subsvc->handle = NULL;
- free(act->subsvc);
- act->subsvc = NULL;
-
- celix_arrayList_destroy(act->registrationList);
- free(act->pubsub);
-
- return CELIX_SUCCESS;
-}
-
-CELIX_GEN_BUNDLE_ACTIVATOR(struct ps_websocketActivator, pubsub_start, pubsub_stop)
\ No newline at end of file
diff --git a/bundles/pubsub/examples/pubsub/pubsub_websocket/private/src/pubsub_websocket_example.c b/bundles/pubsub/examples/pubsub/pubsub_websocket/private/src/pubsub_websocket_example.c
deleted file mode 100644
index 528b0d33..00000000
--- a/bundles/pubsub/examples/pubsub/pubsub_websocket/private/src/pubsub_websocket_example.c
+++ /dev/null
@@ -1,207 +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.
- */
-/**
- * pubsub_subscriber.c
- *
- * \date Sep 21, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <pthread.h>
-#include <unistd.h>
-
-#include "poi.h"
-#include "poiCmd.h"
-#include "pubsub_websocket_private.h"
-
-#include "service_tracker.h"
-#include "celix_threads.h"
-
-
-static double randCoordinate(double min, double max) {
- double ret = min + (((double)random()) / (((double)RAND_MAX)/(max-min)));
- return ret;
-}
-
-static void* send_thread(void* arg) {
- send_thread_struct_t *st_struct = (send_thread_struct_t *) arg;
-
- pubsub_publisher_t *publish_svc = st_struct->service;
- pubsub_info_t *pubsubInfo = st_struct->pubsub;
- pubsub_sender_t *publisher = st_struct->pubsub->sender;
-
- char fwUUID[9];
- memset(fwUUID, 0, 9);
- memcpy(fwUUID, publisher->ident, 8);
-
- location_t place = calloc(1, sizeof(*place));
-
- char *desc = calloc(64, sizeof(char));
- snprintf(desc, 64, "fw-%s [TID=%lu]", fwUUID, (unsigned long)pthread_self());
-
- char *name = calloc(64, sizeof(char));
- snprintf(name, 64, "Bundle#%ld", publisher->bundleId);
-
- place->name = name;
- place->description = desc;
- place->extra = "extra value";
- printf("TOPIC : %s\n", st_struct->topic);
-
- unsigned int msgId = 0;
-
- while (publisher->stop == false) {
- if(pubsubInfo->sending) {
- if (msgId == 0) {
- if (publish_svc->localMsgTypeIdForMsgType(publish_svc->handle, st_struct->topic, &msgId) != 0) {
- printf("PUBLISHER: Cannot retrieve msgId for message '%s'\n", MSG_POI_NAME);
- }
- }
-
- if (msgId > 0) {
- place->position.lat = randCoordinate(MIN_LAT, MAX_LAT);
- place->position.lon = randCoordinate(MIN_LON, MAX_LON);
- int nr_char = (int) randCoordinate(5, 100000);
- place->data = calloc(nr_char, 1);
- for (int i = 0; i < (nr_char - 1); i++) {
- place->data[i] = i % 10 + '0';
- }
- place->data[nr_char - 1] = '\0';
- if (publish_svc->send) {
- if (publish_svc->send(publish_svc->handle, msgId, place, NULL) == 0) {
- printf("Sent %s [%f, %f] (%s, %s) data len = %d\n", st_struct->topic,
- place->position.lat, place->position.lon, place->name, place->description, nr_char);
- }
- } else {
- printf("No send for %s\n", st_struct->topic);
- }
-
- free(place->data);
- }
- }
- sleep(2);
- }
-
- free(place->description);
- free(place->name);
- free(place);
-
- free(st_struct);
-
- return NULL;
-}
-
-pubsub_sender_t* publisher_create(array_list_pt trackers,const char* ident,long bundleId) {
- pubsub_sender_t *publisher = malloc(sizeof(*publisher));
-
- publisher->trackers = trackers;
- publisher->ident = ident;
- publisher->bundleId = bundleId;
- publisher->tid_map = hashMap_create(NULL, NULL, NULL, NULL);
- publisher->stop = false;
-
- return publisher;
-}
-
-void publisher_start(pubsub_sender_t *client) {
- printf("PUBLISHER: starting up...\n");
-}
-
-void publisher_stop(pubsub_sender_t *client) {
- printf("PUBLISHER: stopping...\n");
-}
-
-void publisher_destroy(pubsub_sender_t *client) {
- hashMap_destroy(client->tid_map, false, false);
- client->trackers = NULL;
- client->ident = NULL;
- free(client);
-}
-
-void publisher_publishSvcAdded(void * handle, void *svc, const celix_properties_t *props) {
- pubsub_publisher_t *publish_svc = (pubsub_publisher_t *) svc;
- pubsub_info_t *manager = (pubsub_info_t *) handle;
- manager->sender->stop = false;
-
- printf("PUBLISHER: new publish service exported (%s).\n", manager->sender->ident);
-
- send_thread_struct_t *data = calloc(1, sizeof(*data));
- data->service = publish_svc;
- data->pubsub = manager;
- data->topic = celix_properties_get(props, PUBSUB_PUBLISHER_TOPIC, "!ERROR!");
- celix_thread_t *tid = malloc(sizeof(*tid));
- celixThread_create(tid, NULL, send_thread, (void*)data);
- hashMap_put(manager->sender->tid_map, publish_svc, tid);
-}
-
-void publisher_publishSvcRemoved(void * handle, void *svc, const celix_properties_t *props) {
- pubsub_info_t *manager = (pubsub_info_t *) handle;
- celix_thread_t *tid = hashMap_get(manager->sender->tid_map, svc);
- manager->sender->stop = true;
-
-#if defined(__APPLE__) && defined(__MACH__)
- uint64_t threadid;
- pthread_threadid_np(tid->thread, &threadid);
- printf("PUBLISHER: publish service unexporting (%s) %llu!\n",manager->sender->ident, threadid);
-#else
- printf("PUBLISHER: publish service unexporting (%s) %li!\n", manager->sender->ident, tid->thread);
-#endif
-
- celixThread_join(*tid,NULL);
- free(tid);
-}
-
-pubsub_receiver_t* subscriber_create(char* topics) {
- pubsub_receiver_t *sub = calloc(1,sizeof(*sub));
- sub->name = strdup(topics);
- return sub;
-}
-
-
-void subscriber_start(pubsub_receiver_t *subscriber) {
- printf("Subscriber started...\n");
-}
-
-void subscriber_stop(pubsub_receiver_t *subscriber) {
- printf("Subscriber stopped...\n");
-}
-
-void subscriber_destroy(pubsub_receiver_t *subscriber) {
- if (subscriber->name != NULL) {
- free(subscriber->name);
- }
- subscriber->name=NULL;
- free(subscriber);
-}
-
-int pubsub_subscriber_recv(void* handle, const char* msgType, unsigned int msgTypeId, void* msg, const celix_properties_t *metadata, bool* release) {
- poi_cmd_t *cmd = (poi_cmd_t *) msg;
- pubsub_info_t *pubsub = (pubsub_info_t *) handle;
- printf("Received command %s\n", cmd->command);
-
- if(strcmp(cmd->command, "start") == 0) {
- pubsub->sending = true;
- } else {
- pubsub->sending = false;
- }
- return 0;
-}
diff --git a/bundles/pubsub/examples/pubsub/pubsub_websocket/resources/index.html b/bundles/pubsub/examples/pubsub/pubsub_websocket/resources/index.html
deleted file mode 100644
index 37c0daf4..00000000
--- a/bundles/pubsub/examples/pubsub/pubsub_websocket/resources/index.html
+++ /dev/null
@@ -1,60 +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.
--->
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <meta charset="utf-8"/>
- <title>Apache Celix Websocket publisher example</title>
- <script src="script.js"></script>
-</head>
-<body>
- <div>
- <h1>Poi1 message:</h1>
- <br/>
- <p id="receivePoi1"></p>
- </div>
- <br/>
- <div>
- <h1>Poi2 message:</h1>
- <br/>
- <p id="receivePoi2"></p>
- </div>
- <div>
- <h1>Send start/stop message:</h1>
- <br/>
- <form onsubmit="return submitForm()">
- <table>
- <tr>
- <td>
- <p>Choose command: </p>
- </td>
- <td>
- <select name="command" id="command">
- <option value="start" selected="selected">Start</option>
- <option value="stop">Stop</option>
- </select>
- </td>
- </tr>
- </table>
- <input type="submit" name="submit" class="button" id="button" value="Send!">
- </form>
- </div>
- <script>docReady();</script>
-</body>
-</html>
diff --git a/bundles/pubsub/examples/pubsub/pubsub_websocket/resources/script.js b/bundles/pubsub/examples/pubsub/pubsub_websocket/resources/script.js
deleted file mode 100644
index 503db7a7..00000000
--- a/bundles/pubsub/examples/pubsub/pubsub_websocket/resources/script.js
+++ /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.
- */
-
-var seqnr = 0;
-var sendSocketP1;
-
-function docReady() {
- var host = window.location.host;
- var rcvSocketP1 = new WebSocket("ws://" + host + "/pubsub/default/poi1");
- var rcvSocketP2 = new WebSocket("ws://" + host + "/pubsub/default/poi2");
- sendSocketP1 = new WebSocket("ws://" + host + "/pubsub/default/poiCmd");
-
- rcvSocketP1.onmessage = function (event) {
- console.log(event);
- var obj = JSON.parse(event.data);
- document.getElementById("receivePoi1").innerHTML = "Received " + obj.id + " message with sequence nr: "
- + obj.seqNr + "<br/>latitude = " + JSON.stringify(obj.data.location.lat) + "<br/>longitude = " + JSON.stringify(obj.data.location.lon);
- };
-
- rcvSocketP2.onmessage = function (event) {
- console.log(event);
- var obj = JSON.parse(event.data);
- document.getElementById("receivePoi2").innerHTML = "Received " + obj.id + " message with sequence nr: "
- + obj.seqNr + "<br/>latitude = " + JSON.stringify(obj.data.location.lat) + "<br/>longitude = " + JSON.stringify(obj.data.location.lon);
- };
-}
-
-function submitForm() {
- var element = document.getElementById("command");
- var value = element.options[element.selectedIndex].value;
- let msg = "{\"id\":\"poiCmd\", \"major\": 1, \"minor\": 0, \"seqNr\": " + seqnr++ + ", \"data\": {" +
- "\"command\": \"" + value + "\" }}";
-
- console.log("Sending message: " + msg);
- sendSocketP1.send(msg);
- alert("sending message: " + msg);
- return false;
-}
\ No newline at end of file
diff --git a/bundles/pubsub/examples/pubsub/subscriber/CMakeLists.txt b/bundles/pubsub/examples/pubsub/subscriber/CMakeLists.txt
deleted file mode 100644
index 363833f2..00000000
--- a/bundles/pubsub/examples/pubsub/subscriber/CMakeLists.txt
+++ /dev/null
@@ -1,52 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-add_celix_bundle(celix_pubsub_poi_subscriber
- SYMBOLIC_NAME "apache_celix_pubsub_poi_subscriber"
- VERSION "1.0.0"
- SOURCES
- private/src/ps_sub_activator.c
- private/src/pubsub_subscriber.c
-)
-
-target_link_libraries(celix_pubsub_poi_subscriber PRIVATE Celix::pubsub_api)
-target_include_directories(celix_pubsub_poi_subscriber PRIVATE private/include)
-celix_deprecated_utils_headers(celix_pubsub_poi_subscriber)
-celix_deprecated_framework_headers(celix_pubsub_poi_subscriber)
-
-
-celix_bundle_files(celix_pubsub_poi_subscriber
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poi1.descriptor
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/msg_poi2.descriptor
- DESTINATION "META-INF/descriptors"
-)
-
-celix_bundle_files(celix_pubsub_poi_subscriber
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/poi1.properties
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/pubsub/msg_descriptors/poi2.properties
- DESTINATION "META-INF/topics/sub"
-)
-
-celix_bundle_files(celix_pubsub_poi_subscriber
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/keys/subscriber
- DESTINATION "META-INF/keys"
-)
-
-celix_bundle_files(celix_pubsub_poi_subscriber
- ${PROJECT_SOURCE_DIR}/bundles/pubsub/examples/keys/publisher/public
- DESTINATION "META-INF/keys/publisher"
-)
diff --git a/bundles/pubsub/examples/pubsub/subscriber/private/include/pubsub_subscriber_private.h b/bundles/pubsub/examples/pubsub/subscriber/private/include/pubsub_subscriber_private.h
deleted file mode 100644
index 8021517c..00000000
--- a/bundles/pubsub/examples/pubsub/subscriber/private/include/pubsub_subscriber_private.h
+++ /dev/null
@@ -1,50 +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.
- */
-/**
- * pubsub_subscriber_private.h
- *
- * \date Sep 21, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef PUBSUB_SUBSCRIBER_PRIVATE_H_
-#define PUBSUB_SUBSCRIBER_PRIVATE_H_
-
-
-#include <string.h>
-#include <stdbool.h>
-
-#include "pubsub/subscriber.h"
-
-struct pubsub_receiver {
- char *name;
-};
-
-typedef struct pubsub_receiver pubsub_receiver_t;
-
-pubsub_receiver_t* subscriber_create(char* topics);
-void subscriber_start(pubsub_receiver_t* client);
-void subscriber_stop(pubsub_receiver_t* client);
-void subscriber_destroy(pubsub_receiver_t* client);
-
-int pubsub_subscriber_recv(void* handle, const char* msgType, unsigned int msgTypeId, void* msg, const celix_properties_t *metadata, bool* release);
-
-
-#endif /* PUBSUB_SUBSCRIBER_PRIVATE_H_ */
diff --git a/bundles/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c b/bundles/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c
deleted file mode 100644
index 1e6385e1..00000000
--- a/bundles/pubsub/examples/pubsub/subscriber/private/src/ps_sub_activator.c
+++ /dev/null
@@ -1,113 +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.
- */
-/**
- * ps_sub_activator.c
- *
- * \date Sep 21, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-#include <pubsub/subscriber.h>
-
-#include "celix_bundle_activator.h"
-#include "bundle_context.h"
-
-#include "pubsub_subscriber_private.h"
-
-#define SUB_NAME "poi1;poi2"
-static const char * SUB_TOPICS[] = {
- "poi1",
- "poi2",
- NULL
-};
-
-struct subscriberActivator {
- celix_array_list_t* registrationList; //List<service_registration_pt>
- pubsub_subscriber_t *subsvc;
-};
-
-celix_status_t bundleActivator_create(celix_bundle_context_t *context, void **userData) {
- struct subscriberActivator * act = calloc(1,sizeof(struct subscriberActivator));
- *userData = act;
- act->registrationList = celix_arrayList_create();
- return CELIX_SUCCESS;
-}
-
-celix_status_t bundleActivator_start(void * userData, celix_bundle_context_t *context) {
- struct subscriberActivator * act = (struct subscriberActivator *) userData;
-
- pubsub_subscriber_t *subsvc = calloc(1,sizeof(*subsvc));
- pubsub_receiver_t *sub = subscriber_create(SUB_NAME);
- subsvc->handle = sub;
- subsvc->receive = pubsub_subscriber_recv;
-
- act->subsvc = subsvc;
-
- int i;
- for (i = 0; SUB_TOPICS[i] != NULL; i++) {
- const char* topic = SUB_TOPICS[i];
- celix_properties_t *props = celix_properties_create();
- celix_properties_set(props, PUBSUB_SUBSCRIBER_TOPIC, topic);
-#ifdef USE_SCOPE
- char *scope;
- asprintf(&scope, "my_scope_%d", i);
- celix_properties_set(props, PUBSUB_SUBSCRIBER_SCOPE, scope);
- free(scope);
-#endif
- service_registration_pt reg = NULL;
- bundleContext_registerService(context, PUBSUB_SUBSCRIBER_SERVICE_NAME, subsvc, props, ®);
- celix_arrayList_add(act->registrationList,reg);
- }
-
- subscriber_start((pubsub_receiver_t *) act->subsvc->handle);
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t bundleActivator_stop(void * userData, celix_bundle_context_t *context) {
- struct subscriberActivator * act = (struct subscriberActivator *) userData;
-
- int i;
- for (i = 0; i < celix_arrayList_size(act->registrationList); i++) {
- service_registration_pt reg = celix_arrayList_get(act->registrationList, i);
- serviceRegistration_unregister(reg);
-
- }
-
- subscriber_stop((pubsub_receiver_t *) act->subsvc->handle);
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, celix_bundle_context_t *context) {
-
- struct subscriberActivator * act = (struct subscriberActivator *) userData;
-
- act->subsvc->receive = NULL;
- subscriber_destroy((pubsub_receiver_t *) act->subsvc->handle);
- act->subsvc->handle = NULL;
- free(act->subsvc);
- act->subsvc = NULL;
- celix_arrayList_destroy(act->registrationList);
- free(act);
-
- return CELIX_SUCCESS;
-}
diff --git a/bundles/pubsub/examples/pubsub/subscriber/private/src/pubsub_subscriber.c b/bundles/pubsub/examples/pubsub/subscriber/private/src/pubsub_subscriber.c
deleted file mode 100644
index c05df1ee..00000000
--- a/bundles/pubsub/examples/pubsub/subscriber/private/src/pubsub_subscriber.c
+++ /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.
- */
-/**
- * pubsub_subscriber.c
- *
- * \date Sep 21, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <hash_map.h>
-#include <celix_properties.h>
-
-#include "poi.h"
-#include "pubsub_subscriber_private.h"
-
-pubsub_receiver_t* subscriber_create(char* topics) {
- pubsub_receiver_t *sub = calloc(1,sizeof(*sub));
- sub->name = strdup(topics);
- return sub;
-}
-
-
-void subscriber_start(pubsub_receiver_t *subscriber) {
- printf("Subscriber started...\n");
-}
-
-void subscriber_stop(pubsub_receiver_t *subscriber) {
- printf("Subscriber stopped...\n");
-}
-
-void subscriber_destroy(pubsub_receiver_t *subscriber) {
- if (subscriber->name != NULL) {
- free(subscriber->name);
- }
- subscriber->name=NULL;
- free(subscriber);
-}
-
-int pubsub_subscriber_recv(void* handle, const char* msgType, unsigned int msgTypeId, void* msg, const celix_properties_t *metadata, bool* release) {
- location_t place = (location_t)msg;
- printf("Recv (%s): [%f, %f] (%s, %s, %s, len data %li)\n", msgType, place->position.lat, place->position.lon, place->name, place->description, place->extra, (long)(strlen(place->data) + 1));
-
- if (metadata == NULL || celix_properties_size(metadata) == 0) {
- printf("No metadata\n");
- } else {
- CELIX_PROPERTIES_ITERATE(metadata, iter) {
- printf("%s=%s\n", iter.key, iter.entry.value);
- }
- }
-
- return 0;
-}
diff --git a/bundles/pubsub/integration/CMakeLists.txt b/bundles/pubsub/integration/CMakeLists.txt
deleted file mode 100644
index 64ce4414..00000000
--- a/bundles/pubsub/integration/CMakeLists.txt
+++ /dev/null
@@ -1,505 +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_INTEGRATION "Option to build the pubsub integration" ON)
-if (PUBSUB_INTEGRATION)
- add_celix_bundle(pubsub_endpoint_sut
- #"Vanilla" bundle which is under test
- SOURCES
- gtest/sut_endpoint_activator.c
- VERSION 1.0.0
- )
- target_include_directories(pubsub_endpoint_sut PRIVATE gtest)
- target_link_libraries(pubsub_endpoint_sut PRIVATE Celix::pubsub_api)
- celix_deprecated_utils_headers(pubsub_endpoint_sut)
- celix_bundle_files(pubsub_endpoint_sut
- meta_data/msg.descriptor
- DESTINATION "META-INF/descriptors"
- )
- celix_bundle_files(pubsub_endpoint_sut
- meta_data/ping2.properties
- DESTINATION "META-INF/topics/pub"
- )
-
- add_celix_bundle(pubsub_endpoint_tst
- #Test bundle containing cpputests and uses celix_test_runner launcher instead of the celix launcher
- SOURCES
- gtest/tst_endpoint_activator.c
- VERSION 1.0.0
- )
- target_link_libraries(pubsub_endpoint_tst PRIVATE Celix::pubsub_api)
- celix_deprecated_utils_headers(pubsub_endpoint_tst)
- celix_bundle_files(pubsub_endpoint_tst
- meta_data/msg.descriptor
- DESTINATION "META-INF/descriptors"
- )
- celix_bundle_files(pubsub_endpoint_tst
- meta_data/pong3.properties
- DESTINATION "META-INF/topics/sub"
- )
-
-
- add_celix_bundle(pubsub_loopback
- #"Vanilla" bundle which is under test
- SOURCES
- gtest/loopback_activator.c
- VERSION 1.0.0
- )
- celix_deprecated_utils_headers(pubsub_loopback)
- target_include_directories(pubsub_loopback PRIVATE gtest)
- target_link_libraries(pubsub_loopback PRIVATE Celix::pubsub_api)
- celix_bundle_files(pubsub_loopback
- meta_data/msg.descriptor
- DESTINATION "META-INF/descriptors"
- )
- celix_bundle_files(pubsub_loopback
- meta_data/ping3.properties
- DESTINATION "META-INF/topics/pub"
- )
- celix_bundle_files(pubsub_loopback
- meta_data/pong2.properties
- DESTINATION "META-INF/topics/sub"
- )
-
- add_celix_bundle(pubsub_sut
- #"Vanilla" bundle which is under test
- SOURCES
- gtest/sut_activator.c
- VERSION 1.0.0
- )
- celix_deprecated_utils_headers(pubsub_sut)
- target_include_directories(pubsub_sut PRIVATE gtest)
- target_link_libraries(pubsub_sut PRIVATE Celix::pubsub_api)
- celix_bundle_files(pubsub_sut
- meta_data/msg.descriptor
- DESTINATION "META-INF/descriptors"
- )
- celix_bundle_files(pubsub_sut
- meta_data/ping.properties
- DESTINATION "META-INF/topics/pub"
- )
-
- add_celix_bundle(pubsub_tst
- #Test bundle containing cpputests and uses celix_test_runner launcher instead of the celix launcher
- SOURCES
- gtest/tst_activator.c
- VERSION 1.0.0
- )
- celix_deprecated_utils_headers(pubsub_tst)
- target_link_libraries(pubsub_tst PRIVATE Celix::pubsub_api)
- celix_bundle_files(pubsub_tst
- meta_data/msg.descriptor
- DESTINATION "META-INF/descriptors"
- )
- celix_bundle_files(pubsub_tst
- meta_data/ping.properties
- DESTINATION "META-INF/topics/sub"
- )
-
- add_celix_bundle(pubsub_deadlock_sut
- #"Vanilla" bundle which is used to trigger a publisher added call
- SOURCES
- gtest/sut_activator.c
- VERSION 1.0.0
- )
- celix_deprecated_utils_headers(pubsub_deadlock_sut)
- celix_bundle_files(pubsub_deadlock_sut
- meta_data/msg.descriptor
- DESTINATION "META-INF/descriptors"
- )
- celix_bundle_files(pubsub_deadlock_sut
- meta_data/deadlock.scope.properties
- DESTINATION "META-INF/topics/pub"
- )
- celix_bundle_files(pubsub_deadlock_sut
- meta_data/deadlock.scope2.properties
- DESTINATION "META-INF/topics/pub"
- )
- target_link_libraries(pubsub_deadlock_sut PRIVATE Celix::pubsub_api)
-
- celix_get_bundle_file(pubsub_deadlock_sut DEADLOCK_SUT_BUNDLE_FILE)
-
- add_celix_bundle(pubsub_serializer
- #serializer bundle
- SOURCES
- gtest/serializer_activator.cc
- VERSION 1.0.0
- )
- celix_deprecated_utils_headers(pubsub_serializer)
- target_include_directories(pubsub_serializer PRIVATE gtest)
- target_link_libraries(pubsub_serializer PRIVATE Celix::pubsub_api Celix::pubsub_spi)
-
- if (BUILD_PUBSUB_PSA_TCP)
- # TCP v2 tests
-
- add_celix_container(pubsub_tcp_v2_wire_v1_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::shell
- Celix::shell_tui
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_protocol_wire_v1
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_tcp
- pubsub_sut
- pubsub_tst
- pubsub_serializer
- )
- target_link_libraries(pubsub_tcp_v2_wire_v1_tests PRIVATE Celix::pubsub_api GTest::gtest GTest::gtest_main)
- target_include_directories(pubsub_tcp_v2_wire_v1_tests SYSTEM PRIVATE gtest)
- add_test(NAME pubsub_tcp_v2_wire_v1_tests COMMAND pubsub_tcp_v2_wire_v1_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_tcp_v2_wire_v1_tests,CONTAINER_LOC>)
- setup_target_for_coverage(pubsub_tcp_v2_wire_v1_tests SCAN_DIR ..)
-
- add_celix_container(pubsub_tcp_v2_wire_v2_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::shell
- Celix::shell_tui
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_protocol_wire_v2
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_tcp
- pubsub_sut
- pubsub_tst
- pubsub_serializer
- )
- target_link_libraries(pubsub_tcp_v2_wire_v2_tests PRIVATE Celix::pubsub_api GTest::gtest GTest::gtest_main)
- target_include_directories(pubsub_tcp_v2_wire_v2_tests SYSTEM PRIVATE gtest)
- add_test(NAME pubsub_tcp_v2_wire_v2_tests COMMAND pubsub_tcp_v2_wire_v2_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_tcp_v2_wire_v2_tests,CONTAINER_LOC>)
- setup_target_for_coverage(pubsub_tcp_v2_wire_v2_tests SCAN_DIR ..)
-
- add_celix_container(pubsub_tcp_v2_wire_v2_with_no_scope_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
- CELIX_PUBSUB_TEST_USE_NEGATIVE_SCOPE_FILTER=false
- BUNDLES
- Celix::shell
- Celix::shell_tui
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_protocol_wire_v2
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_tcp
- pubsub_sut
- pubsub_tst
- pubsub_serializer
- )
- target_link_libraries(pubsub_tcp_v2_wire_v2_with_no_scope_tests PRIVATE Celix::pubsub_api GTest::gtest GTest::gtest_main)
- target_include_directories(pubsub_tcp_v2_wire_v2_with_no_scope_tests SYSTEM PRIVATE gtest)
- add_test(NAME pubsub_tcp_v2_wire_v2_with_no_scope_tests COMMAND pubsub_tcp_v2_wire_v2_with_no_scope_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_tcp_v2_wire_v2_with_no_scope_tests,CONTAINER_LOC>)
- setup_target_for_coverage(pubsub_tcp_v2_wire_v2_with_no_scope_tests SCAN_DIR ..)
-
- add_celix_container(pubsub_tcp_v2_endpoint_tests
- USE_CONFIG #ensures that a config.properties will be created with the launch bundles.
- LAUNCHER_SRC ${CMAKE_CURRENT_LIST_DIR}/gtest/PubSubEndpointIntegrationTestSuite.cc
- DIR ${CMAKE_CURRENT_BINARY_DIR}
- PROPERTIES
- LOGHELPER_STDOUT_FALLBACK_INCLUDE_DEBUG=true
- CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL=trace
- BUNDLES
- Celix::shell
- Celix::shell_tui
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_protocol_wire_v2
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_tcp
- pubsub_endpoint_tst
- pubsub_endpoint_sut
- pubsub_loopback
- pubsub_serializer
- )
- target_link_libraries(pubsub_tcp_v2_endpoint_tests PRIVATE Celix::pubsub_api GTest::gtest GTest::gtest_main)
- target_include_directories(pubsub_tcp_v2_endpoint_tests SYSTEM PRIVATE gtest)
-
- add_celix_container(pstm_deadlock_tcp_v2_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_tcp
- Celix::shell
- Celix::shell_tui
- pubsub_serializer
- )
- target_compile_definitions(pstm_deadlock_tcp_v2_test PRIVATE -DDEADLOCK_SUT_BUNDLE_FILE=\"${DEADLOCK_SUT_BUNDLE_FILE}\")
- target_link_libraries(pstm_deadlock_tcp_v2_test PRIVATE Celix::pubsub_api GTest::gtest GTest::gtest_main)
- target_include_directories(pstm_deadlock_tcp_v2_test SYSTEM PRIVATE pstm_deadlock_tcp_v2_test)
-
- #Note we do not link to bundles, as result (to ensure a bundle zip file is created) an dependency on the bundle is needed.
- add_celix_bundle_dependencies(pstm_deadlock_tcp_v2_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_tcp_gtest/META-INF/descriptors/msg.descriptor COPYONLY)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/meta_data/deadlock.scope.properties ${CMAKE_CURRENT_BINARY_DIR}/pstm_deadlock_tcp_gtest/META-INF/topics/pub/deadlock.properties COPYONLY)
-
- add_test(NAME pstm_deadlock_tcp_v2_test COMMAND pstm_deadlock_tcp_v2_test WORKING_DIRECTORY $<TARGET_PROPERTY:pstm_deadlock_tcp_v2_test,CONTAINER_LOC>)
- setup_target_for_coverage(pstm_deadlock_tcp_v2_test SCAN_DIR ..)
-
- #TCP Endpoint test is disabled because the test is not stable when running on Travis
- if (ENABLE_PUBSUB_PSA_TCP_ENDPOINT_TEST)
- add_test(NAME pubsub_tcp_v2_endpoint_tests COMMAND pubsub_tcp_v2_endpoint_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_tcp_v2_endpoint_tests,CONTAINER_LOC>)
- setup_target_for_coverage(pubsub_tcp_v2_endpoint_tests SCAN_DIR ..)
- endif()
- endif()
-
- if (BUILD_PUBSUB_PSA_WS)
- find_package(civetweb REQUIRED)
- add_celix_container(pubsub_websocket_v2_tests
- USE_CONFIG
- LAUNCHER_SRC ${CMAKE_CURRENT_LIST_DIR}/gtest/PubSubWebsocketTestMain.cc
- DIR ${CMAKE_CURRENT_BINARY_DIR}
- PROPERTIES
- LOGHELPER_STDOUT_FALLBACK_INCLUDE_DEBUG=true
- CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL=trace
- CELIX_HTTP_ADMIN_LISTENING_PORTS=58080
- BUNDLES
- Celix::celix_pubsub_serializer_json
- Celix::http_admin
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_websocket
- pubsub_sut
- pubsub_tst
- pubsub_serializer
- )
- target_link_libraries(pubsub_websocket_v2_tests PRIVATE Celix::pubsub_api GTest::gtest civetweb::civetweb)
- target_include_directories(pubsub_websocket_v2_tests SYSTEM PRIVATE gtest)
- add_test(NAME pubsub_websocket_v2_tests COMMAND pubsub_websocket_v2_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_websocket_v2_tests,CONTAINER_LOC>)
- setup_target_for_coverage(pubsub_websocket_v2_tests SCAN_DIR ..)
-
- add_celix_container(pstm_deadlock_websocket_v2_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
- CELIX_HTTP_ADMIN_LISTENING_PORTS=58080
- BUNDLES
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_websocket
- Celix::shell
- Celix::shell_tui
- pubsub_serializer
- )
- target_compile_definitions(pstm_deadlock_websocket_v2_test PRIVATE -DDEADLOCK_SUT_BUNDLE_FILE=\"${DEADLOCK_SUT_BUNDLE_FILE}\")
- target_link_libraries(pstm_deadlock_websocket_v2_test PRIVATE Celix::pubsub_api GTest::gtest GTest::gtest_main)
- target_include_directories(pstm_deadlock_websocket_v2_test SYSTEM PRIVATE pstm_deadlock_websocket_v2_test)
-
- #Note we do not link to bundles, as result (to ensure a bundle zip file is created) an dependency on the bundle is needed.
- add_celix_bundle_dependencies(pstm_deadlock_websocket_v2_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_websocket_v2_test/META-INF/descriptors/msg.descriptor COPYONLY)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/meta_data/deadlock.scope.properties ${CMAKE_CURRENT_BINARY_DIR}/pstm_deadlock_websocket_v2_test/META-INF/topics/pub/deadlock.properties COPYONLY)
-
- add_test(NAME pstm_deadlock_websocket_v2_test COMMAND pstm_deadlock_websocket_v2_test WORKING_DIRECTORY $<TARGET_PROPERTY:pstm_deadlock_websocket_v2_test,CONTAINER_LOC>)
- setup_target_for_coverage(pstm_deadlock_websocket_v2_test SCAN_DIR ..)
- endif()
-
- if (BUILD_PUBSUB_PSA_ZMQ)
- add_celix_container(pubsub_zmq_v2_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_zmq
- Celix::celix_pubsub_protocol_wire_v2
- pubsub_sut
- pubsub_tst
- pubsub_serializer
- )
-
- target_link_libraries(pubsub_zmq_v2_tests PRIVATE Celix::pubsub_api GTest::gtest GTest::gtest_main)
- target_include_directories(pubsub_zmq_v2_tests SYSTEM PRIVATE gtest)
- add_test(NAME pubsub_zmq_v2_tests COMMAND pubsub_zmq_v2_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_zmq_v2_tests,CONTAINER_LOC>)
- setup_target_for_coverage(pubsub_zmq_v2_tests SCAN_DIR ..)
-
- add_celix_container(pubsub_zmq_v2_zerocopy_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
- PSA_ZMQ_ZEROCOPY_ENABLED=true
- CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL=trace
- BUNDLES
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_topology_manager
- Celix::celix_pubsub_admin_zmq
- Celix::celix_pubsub_protocol_wire_v2
- Celix::shell
- Celix::shell_tui
- pubsub_sut
- pubsub_tst
- pubsub_serializer
- )
-
- target_link_libraries(pubsub_zmq_v2_zerocopy_tests PRIVATE Celix::pubsub_api GTest::gtest GTest::gtest_main)
- target_include_directories(pubsub_zmq_v2_zerocopy_tests SYSTEM PRIVATE gtest)
-
- add_test(NAME pubsub_zmq_v2_zerocopy_tests COMMAND pubsub_zmq_v2_zerocopy_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_zmq_v2_zerocopy_tests,CONTAINER_LOC>)
- setup_target_for_coverage(pubsub_zmq_v2_zerocopy_tests SCAN_DIR ..)
-
- add_celix_container(pstm_deadlock_zmq_v2_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_topology_manager
- Celix::celix_pubsub_admin_zmq
- Celix::celix_pubsub_protocol_wire_v2
- )
-
- target_compile_definitions(pstm_deadlock_zmq_v2_test PRIVATE -DDEADLOCK_SUT_BUNDLE_FILE=\"${DEADLOCK_SUT_BUNDLE_FILE}\")
- target_link_libraries(pstm_deadlock_zmq_v2_test PRIVATE Celix::pubsub_api GTest::gtest GTest::gtest_main)
- target_include_directories(pstm_deadlock_zmq_v2_test SYSTEM PRIVATE pstm_deadlock_zmq_v2_test)
-
- #Note we do not link to bundles, as result (to ensure a bundle zip file is created) an dependency on the bundle is needed.
- add_celix_bundle_dependencies(pstm_deadlock_zmq_v2_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_zmq_v2_test/META-INF/descriptors/msg.descriptor COPYONLY)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/meta_data/deadlock.scope.properties ${CMAKE_CURRENT_BINARY_DIR}/pstm_deadlock_zmq_v2_test/META-INF/topics/pub/deadlock.properties COPYONLY)
-
- add_test(NAME pstm_deadlock_zmq_v2_test COMMAND pstm_deadlock_zmq_v2_test WORKING_DIRECTORY $<TARGET_PROPERTY:pstm_deadlock_zmq_v2_test,CONTAINER_LOC>)
- setup_target_for_coverage(pstm_deadlock_zmq_v2_test SCAN_DIR ..)
- endif ()
-
- if (BUILD_PUBSUB_PSA_ZMQ)
- #Test suite to test if component with same topic and different scope combinations work
- add_executable(test_pubsub_topic_and_scope_integration
- gtest/PubSubTopicAndScopeIntegrationTestSuite.cc
- )
- target_link_libraries(test_pubsub_topic_and_scope_integration PRIVATE Celix::framework Celix::pubsub_api GTest::gtest GTest::gtest_main)
- add_test(NAME test_pubsub_topic_and_scope_integration COMMAND test_pubsub_topic_and_scope_integration)
- setup_target_for_coverage(test_pubsub_topic_and_scope_integration SCAN_DIR ..)
-
- #configure topology manager and pubsub zmq, json serializer and wire protocol v2 bundles
- celix_get_bundle_file(Celix::celix_pubsub_serializer_json PUBSUB_JSON_BUNDLE_FILE)
- celix_get_bundle_file(Celix::celix_pubsub_topology_manager PUBSUB_TOPMAN_BUNDLE_FILE)
- celix_get_bundle_file(Celix::celix_pubsub_admin_zmq PUBSUB_ZMQ_BUNDLE_FILE)
- celix_get_bundle_file(Celix::celix_pubsub_protocol_wire_v2 PUBSUB_WIRE_BUNDLE_FILE)
- add_celix_bundle_dependencies(test_pubsub_topic_and_scope_integration
- celix_pubsub_serializer_json
- celix_pubsub_topology_manager
- celix_pubsub_admin_zmq
- celix_pubsub_protocol_wire_v2
- )
- target_compile_definitions(test_pubsub_topic_and_scope_integration PRIVATE
- PUBSUB_JSON_BUNDLE_FILE="${PUBSUB_JSON_BUNDLE_FILE}"
- PUBSUB_TOPMAN_BUNDLE_FILE="${PUBSUB_TOPMAN_BUNDLE_FILE}"
- PUBSUB_ZMQ_BUNDLE_FILE="${PUBSUB_ZMQ_BUNDLE_FILE}"
- PUBSUB_WIRE_BUNDLE_FILE="${PUBSUB_WIRE_BUNDLE_FILE}"
- )
- endif ()
-
- #[[
- Add a integration test with use interceptors for a configurable PSA and wire protocol
-
- ARGV0 is test target name
- ARGV1 is PSA target name
- ARGV2 is wire protocol target name
- ARGV3 is option boolean whether http admin bundle should be used
-
- ]]
- function(add_celix_interceptors_test_for_psa_and_wire)
- set(TEST_TARGET_NAME ${ARGV0})
- set(PSA ${ARGV1})
- set(WIRE ${ARGV2})
- set(USE_HTTP_ADMIN ${ARGV3})
-
- #Test suite to test if pusbub interceptors
- add_executable(${TEST_TARGET_NAME}
- gtest/PubSubInterceptorTestSuite.cc
- )
- target_link_libraries(${TEST_TARGET_NAME} PRIVATE Celix::framework Celix::pubsub_api GTest::gtest GTest::gtest_main Celix::pubsub_spi)
- target_include_directories(${TEST_TARGET_NAME} PRIVATE gtest)
- add_test(NAME ${TEST_TARGET_NAME} COMMAND ${TEST_TARGET_NAME})
- setup_target_for_coverage(${TEST_TARGET_NAME} SCAN_DIR ..)
-
- #configure topology manager and pubsub admin, json serializer and wire protocol bundles
- celix_get_bundle_file(Celix::celix_pubsub_serializer_json PUBSUB_JSON_BUNDLE_FILE)
- celix_get_bundle_file(Celix::celix_pubsub_topology_manager PUBSUB_TOPMAN_BUNDLE_FILE)
- celix_get_bundle_file(${PSA} PUBSUB_PSA_BUNDLE_FILE)
- celix_get_bundle_file(${WIRE} PUBSUB_WIRE_BUNDLE_FILE)
-
- celix_get_bundle_file(pubsub_sut PUBSUB_PUBLISHER_BUNDLE_FILE)
- celix_get_bundle_file(pubsub_tst PUBSUB_SUBSCRIBER_BUNDLE_FILE)
- add_celix_bundle_dependencies(${TEST_TARGET_NAME} Celix::celix_pubsub_serializer_json Celix::celix_pubsub_topology_manager ${PSA} ${WIRE} pubsub_sut pubsub_tst)
- target_compile_definitions(${TEST_TARGET_NAME} PRIVATE
- PUBSUB_JSON_BUNDLE_FILE="${PUBSUB_JSON_BUNDLE_FILE}"
- PUBSUB_TOPMAN_BUNDLE_FILE="${PUBSUB_TOPMAN_BUNDLE_FILE}"
- PUBSUB_PSA_BUNDLE_FILE="${PUBSUB_PSA_BUNDLE_FILE}"
- PUBSUB_WIRE_BUNDLE_FILE="${PUBSUB_WIRE_BUNDLE_FILE}"
- PUBSUB_PUBLISHER_BUNDLE_FILE="${PUBSUB_PUBLISHER_BUNDLE_FILE}"
- PUBSUB_SUBSCRIBER_BUNDLE_FILE="${PUBSUB_SUBSCRIBER_BUNDLE_FILE}"
- )
-
- #if PSA websocket is enabled add http_admin bundle
- if (USE_HTTP_ADMIN)
- target_link_libraries(${TEST_TARGET_NAME} PRIVATE Celix::http_admin_api)
- celix_get_bundle_file(Celix::http_admin HTTP_ADMIN_BUNDLE_FILE)
- add_celix_bundle_dependencies(${TEST_TARGET_NAME} Celix::http_admin)
- target_compile_definitions(${TEST_TARGET_NAME} PRIVATE HTTP_ADMIN_BUNDLE_FILE="${HTTP_ADMIN_BUNDLE_FILE}")
- endif ()
- endfunction()
-
-
- if (BUILD_PUBSUB_PSA_WS)
- add_celix_interceptors_test_for_psa_and_wire(test_pubsub_interceptors_ws_and_wire_v1_integration Celix::celix_pubsub_admin_websocket Celix::celix_pubsub_protocol_wire_v1 true)
- add_celix_interceptors_test_for_psa_and_wire(test_pubsub_interceptors_ws_and_wire_v2_integration Celix::celix_pubsub_admin_websocket Celix::celix_pubsub_protocol_wire_v2 true)
- endif ()
-
- if (BUILD_PUBSUB_PSA_TCP)
- add_celix_interceptors_test_for_psa_and_wire(test_pubsub_interceptors_tcp_and_wire_v1_integration Celix::celix_pubsub_admin_tcp Celix::celix_pubsub_protocol_wire_v1)
- add_celix_interceptors_test_for_psa_and_wire(test_pubsub_interceptors_tcp_and_wire_v2_integration Celix::celix_pubsub_admin_tcp Celix::celix_pubsub_protocol_wire_v2)
- endif ()
-
- if (BUILD_PUBSUB_PSA_ZMQ)
- add_celix_interceptors_test_for_psa_and_wire(test_pubsub_interceptors_zmq_and_wire_v1_integration Celix::celix_pubsub_admin_zmq Celix::celix_pubsub_protocol_wire_v1)
- add_celix_interceptors_test_for_psa_and_wire(test_pubsub_interceptors_zmq_and_wire_v2_integration Celix::celix_pubsub_admin_zmq Celix::celix_pubsub_protocol_wire_v2)
- endif ()
-endif ()
diff --git a/bundles/pubsub/integration/gtest/PubSubEndpointIntegrationTestSuite.cc b/bundles/pubsub/integration/gtest/PubSubEndpointIntegrationTestSuite.cc
deleted file mode 100644
index af05e27a..00000000
--- a/bundles/pubsub/integration/gtest/PubSubEndpointIntegrationTestSuite.cc
+++ /dev/null
@@ -1,70 +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 <gtest/gtest.h>
-
-#include "celix_launcher.h"
-#include "celix_bundle_context.h"
-#include <unistd.h>
-#include "receive_count_service.h"
-
-class PubSubIntegrationTestSuite : public ::testing::Test {
-public:
- PubSubIntegrationTestSuite() {
- celixLauncher_launch("config.properties", &fw);
- ctx = celix_framework_getFrameworkContext(fw);
- }
-
- ~PubSubIntegrationTestSuite() override {
- celixLauncher_stop(fw);
- celixLauncher_waitForShutdown(fw);
- celixLauncher_destroy(fw);
- }
-
- PubSubIntegrationTestSuite(const PubSubIntegrationTestSuite&) = delete;
- PubSubIntegrationTestSuite(PubSubIntegrationTestSuite&&) = delete;
- PubSubIntegrationTestSuite& operator=(const PubSubIntegrationTestSuite&) = delete;
- PubSubIntegrationTestSuite& operator=(PubSubIntegrationTestSuite&&) = delete;
-
- celix_framework_t* fw = nullptr;
- celix_bundle_context_t* ctx = nullptr;
-};
-
-TEST_F(PubSubIntegrationTestSuite, recvTest) {
- constexpr int TRIES = 50;
- constexpr int TIMEOUT = 250000;
- constexpr int MSG_COUNT = 100;
-
- int count = 0;
-
- for (int i = 0; i < TRIES; ++i) {
- count = 0;
- celix_bundleContext_useService(ctx, CELIX_RECEIVE_COUNT_SERVICE_NAME, &count, [](void *handle, void *svc) {
- auto* count_ptr = static_cast<int*>(handle);
- auto* count = static_cast<celix_receive_count_service_t*>(svc);
- *count_ptr = count->receiveCount(count->handle);
- });
- printf("Current msg count is %i, waiting for at least %i\n", count, MSG_COUNT);
- if (count >= MSG_COUNT) {
- break;
- }
- usleep(TIMEOUT);
- }
- EXPECT_GE(count, MSG_COUNT);
-}
diff --git a/bundles/pubsub/integration/gtest/PubSubIntegrationTestSuite.cc b/bundles/pubsub/integration/gtest/PubSubIntegrationTestSuite.cc
deleted file mode 100644
index 8f420dbf..00000000
--- a/bundles/pubsub/integration/gtest/PubSubIntegrationTestSuite.cc
+++ /dev/null
@@ -1,119 +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 <gtest/gtest.h>
-
-#include "celix_launcher.h"
-#include "celix_bundle_context.h"
-#include <unistd.h>
-#include "receive_count_service.h"
-
-class PubSubIntegrationTestSuite : public ::testing::Test {
-public:
- PubSubIntegrationTestSuite() {
- celixLauncher_launch("config.properties", &fw);
- ctx = celix_framework_getFrameworkContext(fw);
- }
-
- ~PubSubIntegrationTestSuite() override {
- celixLauncher_stop(fw);
- celixLauncher_waitForShutdown(fw);
- celixLauncher_destroy(fw);
- }
-
- PubSubIntegrationTestSuite(const PubSubIntegrationTestSuite&) = delete;
- PubSubIntegrationTestSuite(PubSubIntegrationTestSuite&&) = delete;
- PubSubIntegrationTestSuite& operator=(const PubSubIntegrationTestSuite&) = delete;
- PubSubIntegrationTestSuite& operator=(PubSubIntegrationTestSuite&&) = delete;
-
- celix_framework_t* fw = nullptr;
- celix_bundle_context_t* ctx = nullptr;
-};
-
-class PubSubIntegrationWithEnvironmentTestSuite : public ::testing::Test {
-public:
- PubSubIntegrationWithEnvironmentTestSuite() {
- setenv("PSA_TCP_STATIC_BIND_URL_FOR_ping", "tcp://localhost:9001", 1);
- setenv("PSA_TCP_STATIC_CONNECT_URL_FOR_ping", "tcp://localhost:9001", 1);
- setenv("PSA_UDPMC_STATIC_BIND_PORT_FOR_ping", "9001", 1);
- setenv("PSA_UDPMC_STATIC_CONNECT_URLS_FOR_ping", "224.100.0.1:9001", 1);
- setenv("PUBSUB_WEBSOCKET_STATIC_CONNECT_SOCKET_ADDRESSES_FOR_ping", "127.0.0.1:9001", 1);
- setenv("CELIX_HTTP_ADMIN_LISTENING_PORTS", "9001", 1);
- setenv("PSA_ZMQ_STATIC_BIND_URL_FOR_ping", "ipc:///tmp/pubsub-envtest", 1);
- setenv("PSA_ZMQ_STATIC_CONNECT_URL_FOR_ping", "ipc:///tmp/pubsub-envtest", 1);
-
- celixLauncher_launch("config.properties", &fw);
- ctx = celix_framework_getFrameworkContext(fw);
- }
-
- ~PubSubIntegrationWithEnvironmentTestSuite() override {
- celixLauncher_stop(fw);
- celixLauncher_waitForShutdown(fw);
- celixLauncher_destroy(fw);
-
- unsetenv("PSA_TCP_STATIC_BIND_URL_FOR_ping");
- unsetenv("PSA_TCP_STATIC_CONNECT_URL_FOR_ping");
- unsetenv("PSA_UDPMC_STATIC_BIND_PORT_FOR_ping");
- unsetenv("PSA_UDPMC_STATIC_CONNECT_URLS_FOR_ping");
- unsetenv("PUBSUB_WEBSOCKET_STATIC_CONNECT_SOCKET_ADDRESSES_FOR_ping");
- unsetenv("CELIX_HTTP_ADMIN_LISTENING_PORTS");
- unsetenv("PSA_ZMQ_STATIC_BIND_URL_FOR_ping");
- unsetenv("PSA_ZMQ_STATIC_CONNECT_URL_FOR_ping");
- }
-
- PubSubIntegrationWithEnvironmentTestSuite(const PubSubIntegrationWithEnvironmentTestSuite&) = delete;
- PubSubIntegrationWithEnvironmentTestSuite(PubSubIntegrationWithEnvironmentTestSuite&&) = delete;
- PubSubIntegrationWithEnvironmentTestSuite& operator=(const PubSubIntegrationWithEnvironmentTestSuite&) = delete;
- PubSubIntegrationWithEnvironmentTestSuite& operator=(PubSubIntegrationWithEnvironmentTestSuite&&) = delete;
-
- celix_framework_t* fw = nullptr;
- celix_bundle_context_t* ctx = nullptr;
-};
-
-void receiveTest(celix_bundle_context_t *ctx) {
- constexpr int TRIES = 50;
- constexpr int TIMEOUT = 250000;
- constexpr int MSG_COUNT = 100;
-
- int count = 0;
-
- for (int i = 0; i < TRIES; ++i) {
- count = 0;
- celix_bundleContext_useService(ctx, CELIX_RECEIVE_COUNT_SERVICE_NAME, &count, [](void *handle, void *svc) {
- auto *count_ptr = static_cast<int *>(handle);
- auto *count = static_cast<celix_receive_count_service_t *>(svc);
- *count_ptr = count->receiveCount(count->handle);
- });
- printf("Current msg count is %i, waiting for at least %i\n", count, MSG_COUNT);
- if (count >= MSG_COUNT) {
- break;
- }
- usleep(TIMEOUT);
- }
- EXPECT_GE(count, MSG_COUNT);
-}
-
-TEST_F(PubSubIntegrationTestSuite, recvTest) {
- receiveTest(ctx);
-}
-
-
-TEST_F(PubSubIntegrationWithEnvironmentTestSuite, recvTest) {
- receiveTest(ctx);
-}
diff --git a/bundles/pubsub/integration/gtest/PubSubInterceptorTestSuite.cc b/bundles/pubsub/integration/gtest/PubSubInterceptorTestSuite.cc
deleted file mode 100644
index 0c4c7c0b..00000000
--- a/bundles/pubsub/integration/gtest/PubSubInterceptorTestSuite.cc
+++ /dev/null
@@ -1,235 +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 <gtest/gtest.h>
-
-#include <memory>
-#include <mutex>
-#include <condition_variable>
-#include <memory>
-
-#include "pubsub_serializer_handler.h"
-#include "celix/FrameworkFactory.h"
-#include "msg.h"
-#include "pubsub_interceptor.h"
-
-struct TestData {
- TestData(const std::shared_ptr<celix::BundleContext>& ctx) {
- serHandler = std::shared_ptr<pubsub_serializer_handler>{pubsub_serializerHandler_create(ctx->getCBundleContext(), "json", true), [](pubsub_serializer_handler_t* h) {
- pubsub_serializerHandler_destroy(h);
- }};
- }
-
- std::shared_ptr<pubsub_serializer_handler_t> serHandler{};
-
- std::mutex mutex{}; //protects below
- int preSendCount{0};
- int postSendCount{0};
- int preReceiveCount{0};
- int postReceiveCount{0};
- std::condition_variable cond{};
-};
-
-static void serializeAndPrint(TestData* testData, uint32_t msgId, const void *msg) {
- struct iovec* vec = nullptr;
- size_t vecLen = 0;
- pubsub_serializerHandler_serialize(testData->serHandler.get(), msgId, msg, &vec, &vecLen);
- if (vecLen > 0) {
- for (size_t i = 0; i < vecLen; ++i) {
- fwrite(vec[i].iov_base, sizeof(char), vec[i].iov_len, stdout);
- }
- }
- fputc('\n', stdout);
- pubsub_serializerHandler_freeSerializedMsg(testData->serHandler.get(), msgId, vec, vecLen);
-}
-
-class PubSubInterceptorTestSuite : public ::testing::Test {
-public:
- PubSubInterceptorTestSuite() {
- fw = celix::createFramework({
- {"CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL", "info"},
- {"CELIX_HTTP_ADMIN_LISTENING_PORTS", "58080"},
- {"CELIX_PUBSUB_TEST_ADD_METADATA", "true"}
- });
- ctx = fw->getFrameworkBundleContext();
- testData = std::make_shared<TestData>(ctx);
-
- EXPECT_GE(ctx->installBundle(PUBSUB_JSON_BUNDLE_FILE), 0);
- EXPECT_GE(ctx->installBundle(PUBSUB_TOPMAN_BUNDLE_FILE), 0);
- EXPECT_GE(ctx->installBundle(PUBSUB_PSA_BUNDLE_FILE), 0);
- EXPECT_GE(ctx->installBundle(PUBSUB_WIRE_BUNDLE_FILE), 0);
-#ifdef HTTP_ADMIN_BUNDLE_FILE
- EXPECT_GE(ctx->installBundle(HTTP_ADMIN_BUNDLE_FILE), 0);
-#endif
- }
-
- std::shared_ptr<celix::ServiceRegistration> createInterceptor(bool cancelSend, bool cancelReceive) {
- auto interceptor = std::make_shared<pubsub_interceptor>(pubsub_interceptor{});
- interceptor->handle = (void*)testData.get();
- interceptor->preSend = [](void* handle, const pubsub_interceptor_properties_t *, const char *, const uint32_t,
- const void *, celix_properties_t* metadata) {
- auto* td = (TestData*)handle;
- celix_properties_set(metadata, "test", "preSend");
-
- std::lock_guard<std::mutex> lck{td->mutex};
- td->preSendCount += 1;
- td->cond.notify_all();
- return true;
- };
- if (cancelSend) {
- interceptor->preSend = [](void* handle, const pubsub_interceptor_properties_t *, const char *, const uint32_t,
- const void *, celix_properties_t*) {
- auto* td = (TestData*)handle;
- std::lock_guard<std::mutex> lck{td->mutex};
- td->preSendCount += 1;
- td->cond.notify_all();
- return false;
- };
- }
- interceptor->postSend = [](void *handle, const pubsub_interceptor_properties_t* intProps, const char *msgType, uint32_t msgId, const void *rawMsg,
- celix_properties_t* metadata) {
- auto* td = (TestData*)handle;
- serializeAndPrint(td, msgId, rawMsg);
- EXPECT_STREQ(msgType, "msg");
- const auto *msg = static_cast<const msg_t*>(rawMsg);
- EXPECT_GE(msg->seqNr, 0);
- EXPECT_STREQ(celix_properties_get(metadata, "test", nullptr), "preSend");
- CELIX_PROPERTIES_ITERATE(metadata, iter) {
- printf("got property %s=%s\n", iter.key, iter.entry.value);
- }
- fprintf(stdout, "Got message in postSend interceptor %s/%s for type %s and ser %s with seq nr %i\n", intProps->scope, intProps->topic, intProps->psaType, intProps->serializationType, msg->seqNr);
-
- std::lock_guard<std::mutex> lck{td->mutex};
- td->postSendCount += 1;
- td->cond.notify_all();
- };
- interceptor->preReceive = [](void* handle, const pubsub_interceptor_properties_t *, const char *, uint32_t,
- const void *, celix_properties_t* metadata) {
- auto* td = (TestData*)handle;
- celix_properties_set(metadata, "test", "preReceive");
-
- std::lock_guard<std::mutex> lck{td->mutex};
- td->preReceiveCount += 1;
- td->cond.notify_all();
- return true;
- };
- if (cancelReceive) {
- interceptor->preReceive = [](void* handle, const pubsub_interceptor_properties_t *, const char *, uint32_t,
- const void *, celix_properties_t*) {
- auto* td = (TestData*)handle;
- std::lock_guard<std::mutex> lck{td->mutex};
- td->preReceiveCount += 1;
- td->cond.notify_all();
- return false;
- };
- }
- interceptor->postReceive = [](void *handle, const pubsub_interceptor_properties_t* intProps, const char *msgType, uint32_t msgId, const void *rawMsg,
- celix_properties_t* metadata) {
- auto* td = (TestData*)handle;
- serializeAndPrint(td, msgId, rawMsg);
- EXPECT_STREQ(msgType, "msg");
- const auto *msg = static_cast<const msg_t*>(rawMsg);
- EXPECT_GE(msg->seqNr, 0);
- EXPECT_STREQ(celix_properties_get(metadata, "test", nullptr), "preReceive");
- fprintf(stdout, "Got message in postReceive interceptor %s/%s for type %s and ser %s with seq nr %i\n", intProps->scope, intProps->topic, intProps->psaType, intProps-> serializationType, msg->seqNr);
-
- std::lock_guard<std::mutex> lck{td->mutex};
- td->postReceiveCount += 1;
- td->cond.notify_all();
- };
- //note registering identical services to validate multiple interceptors
- return ctx->registerService<pubsub_interceptor>(std::move(interceptor), PUBSUB_INTERCEPTOR_SERVICE_NAME)
- .setUnregisterAsync(false) //note to ensure test data is still valid when service is registered
- .build();
- }
-
- std::shared_ptr<celix::Framework> fw{};
- std::shared_ptr<celix::BundleContext> ctx{};
- std::shared_ptr<TestData> testData{};
-};
-
-TEST_F(PubSubInterceptorTestSuite, InterceptorWithSinglePublishersAndMultipleReceivers) {
- //Given a publisher (PUBSUB_PUBLISHER_BUNDLE_FILE) and 2 receivers (PUBSUB_SUBSCRIBER_BUNDLE_FILE)
- //And several registered interceptors
- //Then the interceptor receives a correct msg type.
-
- auto reg1 = createInterceptor(false, false);
- auto reg2 = createInterceptor(false, false);
- auto reg3 = createInterceptor(false, false);
- ctx->waitForEvents();
-
- EXPECT_GE(ctx->installBundle(PUBSUB_PUBLISHER_BUNDLE_FILE), 0);
- EXPECT_GE(ctx->installBundle(PUBSUB_SUBSCRIBER_BUNDLE_FILE), 0);
-
- std::unique_lock<std::mutex> lck{testData->mutex};
- auto isTestDone = testData->cond.wait_for(lck, std::chrono::seconds{5}, [this]{
- return testData->preSendCount > 10 &&
- testData->postSendCount > 10 &&
- testData->preReceiveCount > 10 &&
- testData->postReceiveCount > 10;
- });
-
- EXPECT_TRUE(isTestDone);
-}
-
-TEST_F(PubSubInterceptorTestSuite, InterceptorWithPreSendCancelWillPreventSends) {
- //Given a publisher (PUBSUB_PUBLISHER_BUNDLE_FILE) and 2 receivers (PUBSUB_SUBSCRIBER_BUNDLE_FILE)
- //And a interceptor which cancel a send
- //Then only the preSend count will be increased, but the rest of the count will be 0
-
- auto reg1 = createInterceptor(true, false);
- ctx->waitForEvents();
-
- EXPECT_GE(ctx->installBundle(PUBSUB_PUBLISHER_BUNDLE_FILE), 0);
- EXPECT_GE(ctx->installBundle(PUBSUB_SUBSCRIBER_BUNDLE_FILE), 0);
-
- std::unique_lock<std::mutex> lck{testData->mutex};
- auto isTestDone = testData->cond.wait_for(lck, std::chrono::seconds{5}, [this]{
- return testData->preSendCount > 10 ;
- });
-
- EXPECT_EQ(testData->postSendCount, 0);
- EXPECT_EQ(testData->preReceiveCount, 0);
- EXPECT_EQ(testData->postReceiveCount, 0);
-
- EXPECT_TRUE(isTestDone);
-}
-
-TEST_F(PubSubInterceptorTestSuite, InterceptorWithPreRedeiveCancelWillPreventPostReceive) {
- //Given a publisher (PUBSUB_PUBLISHER_BUNDLE_FILE) and 2 receivers (PUBSUB_SUBSCRIBER_BUNDLE_FILE)
- //And a interceptor which cancel a receive
- //Then the preSend, postSend and preReceive count will be increased, but the postReceive count will be 0
-
- auto reg1 = createInterceptor(false, true);
- ctx->waitForEvents();
-
- EXPECT_GE(ctx->installBundle(PUBSUB_PUBLISHER_BUNDLE_FILE), 0);
- EXPECT_GE(ctx->installBundle(PUBSUB_SUBSCRIBER_BUNDLE_FILE), 0);
-
- std::unique_lock<std::mutex> lck{testData->mutex};
- auto isTestDone = testData->cond.wait_for(lck, std::chrono::seconds{5}, [this]{
- return testData->preSendCount > 10 &&
- testData->postSendCount > 10 &&
- testData->preReceiveCount > 10;
- });
-
- EXPECT_EQ(testData->postReceiveCount, 0);
-
- EXPECT_TRUE(isTestDone);
-}
\ No newline at end of file
diff --git a/bundles/pubsub/integration/gtest/PubSubTopicAndScopeIntegrationTestSuite.cc b/bundles/pubsub/integration/gtest/PubSubTopicAndScopeIntegrationTestSuite.cc
deleted file mode 100644
index f900b4a4..00000000
--- a/bundles/pubsub/integration/gtest/PubSubTopicAndScopeIntegrationTestSuite.cc
+++ /dev/null
@@ -1,69 +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 <gtest/gtest.h>
-#include <thread>
-
-#include "celix/FrameworkFactory.h"
-#include "pubsub/publisher.h"
-
-class PubSubTopicAndScopeIntegrationTestSuite : public ::testing::Test {
-public:
-
- PubSubTopicAndScopeIntegrationTestSuite() {
- celix::Properties config {{"CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL", "trace"}};
- fw = celix::createFramework(config);
- ctx = fw->getFrameworkBundleContext();
-
- EXPECT_GE(ctx->installBundle(PUBSUB_JSON_BUNDLE_FILE), 0);
- EXPECT_GE(ctx->installBundle(PUBSUB_TOPMAN_BUNDLE_FILE), 0);
- EXPECT_GE(ctx->installBundle(PUBSUB_ZMQ_BUNDLE_FILE), 0);
- EXPECT_GE(ctx->installBundle(PUBSUB_WIRE_BUNDLE_FILE), 0);
- }
-
-
- std::shared_ptr<celix::Framework> fw{};
- std::shared_ptr<celix::BundleContext> ctx{};
-};
-
-class TestComponent{};
-
-TEST_F(PubSubTopicAndScopeIntegrationTestSuite, ComponentsWithSameTopicAndDifferentScope) {
- //When I create publisher with the same topic, but different scope
- //I expect the pubsub topology manager and a PSA can handle this and the
- //publisher components will become active.
-
- auto& cmp1 = ctx->getDependencyManager()->createComponent<TestComponent>();
- cmp1.createServiceDependency<pubsub_publisher>(PUBSUB_PUBLISHER_SERVICE_NAME)
- .setFilter("(topic=foo)");
- cmp1.build();
- EXPECT_EQ(cmp1.getState(), celix::dm::ComponentState::TRACKING_OPTIONAL);
-
- auto& cmp2 = ctx->getDependencyManager()->createComponent<TestComponent>();
- cmp2.createServiceDependency<pubsub_publisher>(PUBSUB_PUBLISHER_SERVICE_NAME)
- .setFilter("(&(topic=foo)(scope=bar))");
- cmp2.build();
- EXPECT_EQ(cmp2.getState(), celix::dm::ComponentState::TRACKING_OPTIONAL);
-
- auto& cmp3 = ctx->getDependencyManager()->createComponent<TestComponent>();
- cmp3.createServiceDependency<pubsub_publisher>(PUBSUB_PUBLISHER_SERVICE_NAME)
- .setFilter("(&(topic=foo)(scope=default))");
- cmp3.build();
- EXPECT_EQ(cmp3.getState(), celix::dm::ComponentState::TRACKING_OPTIONAL);
-}
\ No newline at end of file
diff --git a/bundles/pubsub/integration/gtest/PubSubWebsocketTestMain.cc b/bundles/pubsub/integration/gtest/PubSubWebsocketTestMain.cc
deleted file mode 100644
index ee3774e0..00000000
--- a/bundles/pubsub/integration/gtest/PubSubWebsocketTestMain.cc
+++ /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.
- */
-#include <civetweb.h>
-#include "PubSubIntegrationTestSuite.cc"
-
-int main(int argc, char **argv) {
- mg_init_library(MG_FEATURES_ALL);
- ::testing::InitGoogleTest(&argc, argv);
- int rc = RUN_ALL_TESTS();
- mg_exit_library();
- return rc;
-}
diff --git a/bundles/pubsub/integration/gtest/loopback_activator.c b/bundles/pubsub/integration/gtest/loopback_activator.c
deleted file mode 100644
index c718c4a7..00000000
--- a/bundles/pubsub/integration/gtest/loopback_activator.c
+++ /dev/null
@@ -1,99 +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 <stdio.h>
-#include <stdlib.h>
-#include "celix_constants.h"
-#include <unistd.h>
-
-#include "celix_bundle_activator.h"
-#include "pubsub/api.h"
-#include "msg.h"
-
-static int tst_receive(void *handle, const char *msgType, unsigned int msgTypeId, void *msg, const celix_properties_t *metadata, bool *release);
-static void sut_pubSet(void *handle, void *service);
-
-struct activator {
- long pubTrkId;
- long subSvcId;
- pubsub_publisher_t* pubSvc;
- pubsub_subscriber_t subSvc;
- pthread_mutex_t mutex;
- unsigned int count;
- unsigned int msgId;
-};
-
-celix_status_t bnd_start(struct activator *act, celix_bundle_context_t *ctx) {
-
- char filter[512];
- snprintf(filter, 512, "(%s=%s)", PUBSUB_PUBLISHER_TOPIC, "ping3");
- celix_service_tracking_options_t opts = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS;
- opts.set = sut_pubSet;
- opts.callbackHandle = act;
- opts.filter.serviceName = PUBSUB_PUBLISHER_SERVICE_NAME;
- opts.filter.filter = filter;
- act->pubTrkId = celix_bundleContext_trackServicesWithOptions(ctx, &opts);
- act->count = 0;
- act->msgId = 0;
-
- pthread_mutex_init(&act->mutex, NULL);
-
- celix_properties_t *props = celix_properties_create();
- celix_properties_set(props, PUBSUB_SUBSCRIBER_TOPIC, "pong2");
- act->subSvc.handle = act;
- act->subSvc.receive = tst_receive;
- act->subSvcId = celix_bundleContext_registerService(ctx, &act->subSvc, PUBSUB_SUBSCRIBER_SERVICE_NAME, props);
-
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t bnd_stop(struct activator *act, celix_bundle_context_t *ctx) {
- celix_bundleContext_stopTracker(ctx, act->pubTrkId);
- celix_bundleContext_unregisterService(ctx, act->subSvcId);
- pthread_mutex_destroy(&act->mutex);
- return CELIX_SUCCESS;
-}
-
-CELIX_GEN_BUNDLE_ACTIVATOR(struct activator, bnd_start, bnd_stop);
-
-static void sut_pubSet(void *handle, void *service) {
- struct activator* act = handle;
- pthread_mutex_lock(&act->mutex);
- act->pubSvc = service;
- pthread_mutex_unlock(&act->mutex);
-}
-
-
-static int tst_receive(void *handle, const char *msgType, unsigned int msgTypeId, void * voidMsg, const celix_properties_t *metadata, bool *release) {
- struct activator *act =handle;
- msg_t *msg = voidMsg;
- msg_t send_msg = *msg;
- pthread_mutex_lock(&act->mutex);
-
- if (act->pubSvc != NULL) {
- if (act->count == 0) {
- act->pubSvc->localMsgTypeIdForMsgType(act->pubSvc->handle, MSG_NAME, &act->msgId);
- }
- act->pubSvc->send(act->pubSvc->handle, act->msgId, &send_msg, (celix_properties_t *) metadata);
- act->count += 1;
- }
- pthread_mutex_unlock(&act->mutex);
- return CELIX_SUCCESS;
-}
diff --git a/bundles/pubsub/integration/gtest/msg.h b/bundles/pubsub/integration/gtest/msg.h
deleted file mode 100644
index 81cf4b81..00000000
--- a/bundles/pubsub/integration/gtest/msg.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 MSG_H
-#define MSG_H
-
-#include <stdint.h>
-
-#define MSG_NAME "msg"
-
-typedef struct msg {
- uint32_t seqNr;
-} msg_t;
-
-#endif //MSG_H
diff --git a/bundles/pubsub/integration/gtest/receive_count_service.h b/bundles/pubsub/integration/gtest/receive_count_service.h
deleted file mode 100644
index d1eca004..00000000
--- a/bundles/pubsub/integration/gtest/receive_count_service.h
+++ /dev/null
@@ -1,30 +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_RECEIVE_COUNT_SERVICE_H
-#define CELIX_RECEIVE_COUNT_SERVICE_H
-
-#define CELIX_RECEIVE_COUNT_SERVICE_NAME "celix_receive_count_service"
-
-typedef struct celix_receive_count_service {
- void *handle;
- size_t (*receiveCount)(void *handle);
-} celix_receive_count_service_t;
-
-#endif //CELIX_RECEIVE_COUNT_SERVICE_H
diff --git a/bundles/pubsub/integration/gtest/serializer_activator.cc b/bundles/pubsub/integration/gtest/serializer_activator.cc
deleted file mode 100644
index cecf90fb..00000000
--- a/bundles/pubsub/integration/gtest/serializer_activator.cc
+++ /dev/null
@@ -1,87 +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_constants.h"
-#include <unistd.h>
-#include <pubsub_message_serialization_service.h>
-#include <pubsub_constants.h>
-
-#include "celix_bundle_activator.h"
-#include "msg.h"
-
-struct activator {
- long serId;
- pubsub_message_serialization_service_t svc;
-};
-
-celix_status_t bnd_start(struct activator *act, celix_bundle_context_t *ctx) {
-
-#pragma GCC diagnostic ignored "-Wunused-parameter"
- act->svc.serialize = [](void* handle, const void* input, struct iovec** output, size_t* outputIovLen) {
- if (*output == nullptr) {
- *output = static_cast<iovec *>(calloc(1, sizeof(struct iovec)));
- *outputIovLen = 1;
- auto *val = new uint32_t;
- *val = ((msg_t *) input)->seqNr;
- (*output)->iov_base = val;
- (*output)->iov_len = sizeof(uint32_t);
- }
-
- return CELIX_SUCCESS;
- };
-
- act->svc.deserialize = [](void* handle, const struct iovec* input, size_t inputIovLen, void** out) {
- auto *msg = new msg_t;
- msg->seqNr = *(uint32_t*)(uintptr_t)input->iov_base;
- *out = msg;
- return CELIX_SUCCESS;
- };
-
- act->svc.freeSerializedMsg = [](void* handle, struct iovec* input, size_t inputIovLen) {
- delete (uint32_t*)input->iov_base;
- free(input);
- };
-
- act->svc.freeDeserializedMsg = [](void* handle, void* msg) {
- delete (msg_t*)msg;
- };
-
- auto* p = celix_properties_create();
- celix_properties_set(p, PUBSUB_SERIALIZER_TYPE_KEY, "json");
- celix_properties_set(p, PUBSUB_MESSAGE_SERIALIZATION_SERVICE_SERIALIZATION_TYPE_PROPERTY, "msg_serializer");
- celix_properties_set(p, PUBSUB_MESSAGE_SERIALIZATION_SERVICE_MSG_ID_PROPERTY, "20");
- celix_properties_set(p, PUBSUB_MESSAGE_SERIALIZATION_SERVICE_MSG_FQN_PROPERTY, MSG_NAME);
- celix_properties_set(p, PUBSUB_MESSAGE_SERIALIZATION_SERVICE_MSG_VERSION_PROPERTY, "1.0.0");
- celix_properties_setLong(p, CELIX_FRAMEWORK_SERVICE_RANKING, 20);
- celix_service_registration_options_t opts;
- opts.svc = &act->svc;
- opts.properties = p;
- opts.serviceName = PUBSUB_MESSAGE_SERIALIZATION_SERVICE_NAME;
- opts.serviceVersion = PUBSUB_MESSAGE_SERIALIZATION_SERVICE_VERSION;
- act->serId = celix_bundleContext_registerServiceWithOptions(ctx, &opts);
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t bnd_stop(struct activator *act, celix_bundle_context_t *ctx) {
- celix_bundleContext_unregisterService(ctx, act->serId);
- return CELIX_SUCCESS;
-}
-
-CELIX_GEN_BUNDLE_ACTIVATOR(activator, bnd_start, bnd_stop)
diff --git a/bundles/pubsub/integration/gtest/sut_activator.c b/bundles/pubsub/integration/gtest/sut_activator.c
deleted file mode 100644
index 27ad18a6..00000000
--- a/bundles/pubsub/integration/gtest/sut_activator.c
+++ /dev/null
@@ -1,118 +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 <stdio.h>
-#include <stdlib.h>
-#include "celix_constants.h"
-#include <unistd.h>
-
-#include "celix_bundle_activator.h"
-#include "pubsub/api.h"
-#include "msg.h"
-
-static void sut_pubSet(void *handle, void *service);
-static void* sut_sendThread(void *data);
-
-struct activator {
- bool addMetadata;
-
- long pubTrkId;
-
- pthread_t sendThread;
-
- pthread_mutex_t mutex;
- bool running;
- pubsub_publisher_t* pubSvc;
-};
-
-celix_status_t bnd_start(struct activator *act, celix_bundle_context_t *ctx) {
-
- act->addMetadata = celix_bundleContext_getPropertyAsBool(ctx, "CELIX_PUBSUB_TEST_ADD_METADATA", false);
-
- char filter[512];
- bool useNegativeScopeFilter = celix_bundleContext_getPropertyAsBool(ctx, "CELIX_PUBSUB_TEST_USE_NEGATIVE_SCOPE_FILTER", true);
- if (useNegativeScopeFilter) {
- snprintf(filter, 512, "(%s=%s)(!(scope=*))", PUBSUB_PUBLISHER_TOPIC, "ping");
- } else {
- snprintf(filter, 512, "(%s=%s)", PUBSUB_PUBLISHER_TOPIC, "ping");
- }
- celix_service_tracking_options_t opts = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS;
- opts.set = sut_pubSet;
- opts.callbackHandle = act;
- opts.filter.serviceName = PUBSUB_PUBLISHER_SERVICE_NAME;
- opts.filter.filter = filter;
- act->pubTrkId = celix_bundleContext_trackServicesWithOptions(ctx, &opts);
-
- __atomic_store_n(&act->running, true, __ATOMIC_RELEASE);
- pthread_create(&act->sendThread, NULL, sut_sendThread, act);
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t bnd_stop(struct activator *act, celix_bundle_context_t *ctx) {
- __atomic_store_n(&act->running, false, __ATOMIC_RELEASE);
- pthread_join(act->sendThread, NULL);
- celix_bundleContext_stopTracker(ctx, act->pubTrkId);
- pthread_mutex_destroy(&act->mutex);
- return CELIX_SUCCESS;
-}
-
-CELIX_GEN_BUNDLE_ACTIVATOR(struct activator, bnd_start, bnd_stop)
-
-static void sut_pubSet(void *handle, void *service) {
- struct activator* act = handle;
- pthread_mutex_lock(&act->mutex);
- act->pubSvc = service;
- pthread_mutex_unlock(&act->mutex);
-}
-
-static void* sut_sendThread(void *data) {
- struct activator *act = data;
-
- unsigned int msgId = 0;
- msg_t msg;
- msg.seqNr = 1;
-
- while (__atomic_load_n(&act->running, __ATOMIC_ACQUIRE)) {
- pthread_mutex_lock(&act->mutex);
- if (act->pubSvc != NULL) {
- if (msgId == 0) {
- act->pubSvc->localMsgTypeIdForMsgType(act->pubSvc->handle, MSG_NAME, &msgId);
- }
- celix_properties_t* metadata = NULL;
- if (act->addMetadata) {
- metadata = celix_properties_create();
- celix_properties_setLong(metadata, "seqNr", (long)msgId);
- }
- act->pubSvc->send(act->pubSvc->handle, msgId, &msg, metadata);
- if (msg.seqNr % 1000 == 0) {
- printf("Send %i messages\n", msg.seqNr);
- }
-
- msg.seqNr += 1;
-
- }
- pthread_mutex_unlock(&act->mutex);
-
- usleep(10000);
- }
- printf("Send %i messages\n", msg.seqNr);
-
- return NULL;
-}
diff --git a/bundles/pubsub/integration/gtest/sut_endpoint_activator.c b/bundles/pubsub/integration/gtest/sut_endpoint_activator.c
deleted file mode 100644
index 3b97ab73..00000000
--- a/bundles/pubsub/integration/gtest/sut_endpoint_activator.c
+++ /dev/null
@@ -1,120 +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 <stdio.h>
-#include <stdlib.h>
-#include "celix_constants.h"
-#include <unistd.h>
-
-#include "celix_bundle_activator.h"
-#include "pubsub/api.h"
-#include "msg.h"
-
-static void sut_pubSet(void *handle, void *service);
-static void* sut_sendThread(void *data);
-
-struct activator {
- long pubTrkId;
-
- pthread_t sendThread;
-
- pthread_mutex_t mutex;
- bool running;
- pubsub_publisher_t* pubSvc;
-};
-
-celix_status_t bnd_start(struct activator *act, celix_bundle_context_t *ctx) {
-
- char filter[512];
- bool useNegativeScopeFilter = celix_bundleContext_getPropertyAsBool(ctx, "CELIX_PUBSUB_TEST_USE_NEGATIVE_SCOPE_FILTER", true);
- if (useNegativeScopeFilter) {
- snprintf(filter, 512, "(%s=%s)(!(scope=*))", PUBSUB_PUBLISHER_TOPIC, "ping");
- } else {
- snprintf(filter, 512, "(%s=%s)", PUBSUB_PUBLISHER_TOPIC, "ping");
- }
- celix_service_tracking_options_t opts = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS;
- opts.set = sut_pubSet;
- opts.callbackHandle = act;
- opts.filter.serviceName = PUBSUB_PUBLISHER_SERVICE_NAME;
- opts.filter.filter = filter;
- act->pubTrkId = celix_bundleContext_trackServicesWithOptions(ctx, &opts);
-
- act->running = true;
- pthread_create(&act->sendThread, NULL, sut_sendThread, act);
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t bnd_stop(struct activator *act, celix_bundle_context_t *ctx) {
- pthread_mutex_lock(&act->mutex);
- act->running = false;
- pthread_mutex_unlock(&act->mutex);
- pthread_join(act->sendThread, NULL);
- pthread_mutex_destroy(&act->mutex);
-
- celix_bundleContext_stopTracker(ctx, act->pubTrkId);
- return CELIX_SUCCESS;
-}
-
-CELIX_GEN_BUNDLE_ACTIVATOR(struct activator, bnd_start, bnd_stop);
-
-static void sut_pubSet(void *handle, void *service) {
- struct activator* act = handle;
- pthread_mutex_lock(&act->mutex);
- act->pubSvc = service;
- pthread_mutex_unlock(&act->mutex);
-}
-
-static void* sut_sendThread(void *data) {
- struct activator *act = data;
-
- pthread_mutex_lock(&act->mutex);
- bool running = act->running;
- pthread_mutex_unlock(&act->mutex);
-
- unsigned int msgId = 0;
- msg_t msg;
- msg.seqNr = 1;
-
- while (running) {
- pthread_mutex_lock(&act->mutex);
- if (act->pubSvc != NULL) {
- if (msgId == 0) {
- act->pubSvc->localMsgTypeIdForMsgType(act->pubSvc->handle, MSG_NAME, &msgId);
- }
- act->pubSvc->send(act->pubSvc->handle, msgId, &msg, NULL);
- if (msg.seqNr % 1000 == 0) {
- printf("Send %i messages\n", msg.seqNr);
- }
-
- msg.seqNr += 1;
-
- }
- pthread_mutex_unlock(&act->mutex);
-
- usleep(10000);
-
- pthread_mutex_lock(&act->mutex);
- running = act->running;
- pthread_mutex_unlock(&act->mutex);
- }
- printf("Send %i messages\n", msg.seqNr);
-
- return NULL;
-}
diff --git a/bundles/pubsub/integration/gtest/tst_activator.c b/bundles/pubsub/integration/gtest/tst_activator.c
deleted file mode 100644
index 811c8d4d..00000000
--- a/bundles/pubsub/integration/gtest/tst_activator.c
+++ /dev/null
@@ -1,138 +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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "celix_bundle_activator.h"
-#include "celix_compiler.h"
-#include "pubsub/api.h"
-
-#include "msg.h"
-#include "receive_count_service.h"
-
-static int tst_receive(void *handle, const char *msgType, unsigned int msgTypeId, void *msg, const celix_properties_t *metadata, bool *release);
-static int tst_receive2(void *handle, const char *msgType, unsigned int msgTypeId, void *msg, const celix_properties_t *metadata, bool *release);
-static size_t tst_count(void *handle);
-
-struct activator {
- pubsub_subscriber_t subSvc1;
- long subSvcId1;
-
- pubsub_subscriber_t subSvc2;
- long subSvcId2;
-
- celix_receive_count_service_t countSvc;
- long countSvcId;
-
- pthread_mutex_t mutex;
- unsigned int count1;
- unsigned int count2;
-};
-
-celix_status_t bnd_start(struct activator *act, celix_bundle_context_t *ctx) {
- pthread_mutex_init(&act->mutex, NULL);
-
- {
- celix_properties_t *props = celix_properties_create();
- celix_properties_set(props, PUBSUB_SUBSCRIBER_TOPIC, "ping");
- act->subSvc1.handle = act;
- act->subSvc1.receive = tst_receive;
- act->subSvcId1 = celix_bundleContext_registerService(ctx, &act->subSvc1, PUBSUB_SUBSCRIBER_SERVICE_NAME, props);
- }
-
- {
- celix_properties_t *props = celix_properties_create();
- celix_properties_set(props, PUBSUB_SUBSCRIBER_TOPIC, "ping");
- act->subSvc2.handle = act;
- act->subSvc2.receive = tst_receive2;
- act->subSvcId2 = celix_bundleContext_registerService(ctx, &act->subSvc2, PUBSUB_SUBSCRIBER_SERVICE_NAME, props);
- }
-
- {
- act->countSvc.handle = act;
- act->countSvc.receiveCount = tst_count;
- act->countSvcId = celix_bundleContext_registerService(ctx, &act->countSvc, CELIX_RECEIVE_COUNT_SERVICE_NAME, NULL);
- }
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t bnd_stop(struct activator *act, celix_bundle_context_t *ctx) {
- celix_bundleContext_unregisterService(ctx, act->subSvcId1);
- celix_bundleContext_unregisterService(ctx, act->subSvcId2);
- celix_bundleContext_unregisterService(ctx, act->countSvcId);
- pthread_mutex_destroy(&act->mutex);
- return CELIX_SUCCESS;
-}
-
-CELIX_GEN_BUNDLE_ACTIVATOR(struct activator, bnd_start, bnd_stop) ;
-
-
-static int tst_receive(void *handle, const char * msgType CELIX_UNUSED, unsigned int msgTypeId CELIX_UNUSED, void * voidMsg, const celix_properties_t *metadata CELIX_UNUSED, bool *release) {
- struct activator *act = handle;
-
- msg_t *msg = voidMsg;
- static uint32_t prevSeqNr = 0;
- long delta = msg->seqNr - prevSeqNr;
- if (delta != 1 && msg->seqNr > 1 && prevSeqNr < msg->seqNr) {
- fprintf(stderr, "Warning: missing messages. seq jumped from %i to %i\n", prevSeqNr, msg->seqNr);
- }
- prevSeqNr = msg->seqNr;
-
- pthread_mutex_lock(&act->mutex);
- act->count1 += 1;
- pthread_mutex_unlock(&act->mutex);
-
- *release = false;
- free(voidMsg);
-
- return CELIX_SUCCESS;
-}
-
-static int tst_receive2(void *handle, const char * msgType CELIX_UNUSED, unsigned int msgTypeId CELIX_UNUSED, void * voidMsg, const celix_properties_t *metadata CELIX_UNUSED, bool *release CELIX_UNUSED) {
- struct activator *act = handle;
-
- msg_t *msg = voidMsg;
- static int prevSeqNr = 0;
- int delta = msg->seqNr - prevSeqNr;
- if (delta != 1) {
- fprintf(stderr, "Warning: missing messages. seq jumped from %i to %i\n", prevSeqNr, msg->seqNr);
- }
- prevSeqNr = msg->seqNr;
-
- pthread_mutex_lock(&act->mutex);
- act->count2 += 1;
- pthread_mutex_unlock(&act->mutex);
- return CELIX_SUCCESS;
-}
-
-static size_t tst_count(void *handle) {
- struct activator *act = handle;
- size_t count1;
- size_t count2;
- pthread_mutex_lock(&act->mutex);
- count1 = act->count1;
- count2 = act->count2;
- pthread_mutex_unlock(&act->mutex);
- printf("msg count1 is %lu and msg count 2 is %lu\n", (long unsigned int) count1, (long unsigned int) count2);
- return count1 >= count2 ? count1 : count2;
-}
diff --git a/bundles/pubsub/integration/gtest/tst_endpoint_activator.c b/bundles/pubsub/integration/gtest/tst_endpoint_activator.c
deleted file mode 100644
index b9198650..00000000
--- a/bundles/pubsub/integration/gtest/tst_endpoint_activator.c
+++ /dev/null
@@ -1,103 +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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "celix_bundle_activator.h"
-#include "celix_compiler.h"
-#include "pubsub/api.h"
-
-#include "msg.h"
-#include "receive_count_service.h"
-
-
-static int tst_receive(void *handle, const char *msgType, unsigned int msgTypeId, void *msg, const celix_properties_t *metadata, bool *release);
-static size_t tst_count(void *handle);
-
-struct activator {
- pubsub_subscriber_t subSvc;
- long subSvcId;
-
- celix_receive_count_service_t countSvc;
- long countSvcId;
-
- pthread_mutex_t mutex;
- unsigned int count;
-};
-
-celix_status_t bnd_start(struct activator *act, celix_bundle_context_t *ctx) {
- pthread_mutex_init(&act->mutex, NULL);
-
- {
- celix_properties_t *props = celix_properties_create();
- celix_properties_set(props, PUBSUB_SUBSCRIBER_TOPIC, "pong3");
- act->subSvc.handle = act;
- act->subSvc.receive = tst_receive;
- act->subSvcId = celix_bundleContext_registerService(ctx, &act->subSvc, PUBSUB_SUBSCRIBER_SERVICE_NAME, props);
- }
-
-
- {
- act->countSvc.handle = act;
- act->countSvc.receiveCount = tst_count;
- act->countSvcId = celix_bundleContext_registerService(ctx, &act->countSvc, CELIX_RECEIVE_COUNT_SERVICE_NAME, NULL);
- }
-
-
- return CELIX_SUCCESS;
-}
-
-celix_status_t bnd_stop(struct activator *act, celix_bundle_context_t *ctx) {
- celix_bundleContext_unregisterService(ctx, act->subSvcId);
- celix_bundleContext_unregisterService(ctx, act->countSvcId);
- pthread_mutex_destroy(&act->mutex);
- return CELIX_SUCCESS;
-}
-
-CELIX_GEN_BUNDLE_ACTIVATOR(struct activator, bnd_start, bnd_stop) ;
-
-
-static int tst_receive(void *handle, const char * msgType CELIX_UNUSED, unsigned int msgTypeId CELIX_UNUSED, void * voidMsg, const celix_properties_t *metadata CELIX_UNUSED, bool *release CELIX_UNUSED) {
- struct activator *act = handle;
-
- msg_t *msg = voidMsg;
- static uint32_t prevSeqNr = 0;
- long delta = msg->seqNr - prevSeqNr;
- if (delta != 1 && msg->seqNr > 1 && prevSeqNr < msg->seqNr) {
- fprintf(stderr, "Warning: missing messages. seq jumped from %i to %i\n", prevSeqNr, msg->seqNr);
- }
- prevSeqNr = msg->seqNr;
-
- pthread_mutex_lock(&act->mutex);
- act->count += 1;
- pthread_mutex_unlock(&act->mutex);
- return CELIX_SUCCESS;
-}
-
-static size_t tst_count(void *handle) {
- struct activator *act = handle;
- size_t count;
- pthread_mutex_lock(&act->mutex);
- count = act->count;
- pthread_mutex_unlock(&act->mutex);
- return count;
-}
diff --git a/bundles/pubsub/integration/meta_data/deadlock.scope.properties b/bundles/pubsub/integration/meta_data/deadlock.scope.properties
deleted file mode 100644
index 29985104..00000000
--- a/bundles/pubsub/integration/meta_data/deadlock.scope.properties
+++ /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.
-zmq.static.bind.url=ipc:///tmp/pubsub-deadlock
-zmq.static.connect.urls=ipc:///tmp/pubsub-deadlock
-tcp.static.bind.url=tcp://localhost:9000
-tcp.static.connect.urls=tcp://localhost:9000
-udpmc.static.bind.port=50678
-udpmc.static.connect.socket_addresses=224.100.0.1:50678
-websocket.static.connect.socket_addresses=127.0.0.1:58080
-
-#note only effective if run as root
-thread.realtime.sched=SCHED_FIFO
-thread.realtime.prio=50
-
diff --git a/bundles/pubsub/integration/meta_data/deadlock.scope2.properties b/bundles/pubsub/integration/meta_data/deadlock.scope2.properties
deleted file mode 100644
index 29985104..00000000
--- a/bundles/pubsub/integration/meta_data/deadlock.scope2.properties
+++ /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.
-zmq.static.bind.url=ipc:///tmp/pubsub-deadlock
-zmq.static.connect.urls=ipc:///tmp/pubsub-deadlock
-tcp.static.bind.url=tcp://localhost:9000
-tcp.static.connect.urls=tcp://localhost:9000
-udpmc.static.bind.port=50678
-udpmc.static.connect.socket_addresses=224.100.0.1:50678
-websocket.static.connect.socket_addresses=127.0.0.1:58080
-
-#note only effective if run as root
-thread.realtime.sched=SCHED_FIFO
-thread.realtime.prio=50
-
diff --git a/bundles/pubsub/integration/meta_data/msg.descriptor b/bundles/pubsub/integration/meta_data/msg.descriptor
deleted file mode 100644
index da774ae0..00000000
--- a/bundles/pubsub/integration/meta_data/msg.descriptor
+++ /dev/null
@@ -1,9 +0,0 @@
-:header
-type=message
-name=msg
-version=1.0.0
-:annotations
-classname=org.example.Msg
-:types
-:message
-{i seqNr}
diff --git a/bundles/pubsub/integration/meta_data/ping.properties b/bundles/pubsub/integration/meta_data/ping.properties
deleted file mode 100644
index 81144137..00000000
--- a/bundles/pubsub/integration/meta_data/ping.properties
+++ /dev/null
@@ -1,29 +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.
-zmq.static.bind.url=ipc:///tmp/pubsub-pingtest
-zmq.static.connect.urls=ipc:///tmp/pubsub-pingtest
-tcp.static.bind.url=tcp://localhost:9000
-tcp.static.connect.urls=tcp://localhost:9000
-udpmc.static.bind.port=50678
-udpmc.static.connect.socket_addresses=224.100.0.1:50678
-websocket.static.connect.socket_addresses=127.0.0.1:58080
-
-#note only effective if run as root
-thread.realtime.sched=SCHED_FIFO
-thread.realtime.prio=50
-
-pubsub.serializer=json
\ No newline at end of file
diff --git a/bundles/pubsub/integration/meta_data/ping2.properties b/bundles/pubsub/integration/meta_data/ping2.properties
deleted file mode 100644
index ff0dbed3..00000000
--- a/bundles/pubsub/integration/meta_data/ping2.properties
+++ /dev/null
@@ -1,23 +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.
-tcp.static.bind.url=tcp://localhost:9500
-tcp.passive.key=tcp://localhost:9500
-
-#note only effective if run as root
-thread.realtime.sched=SCHED_FIFO
-thread.realtime.prio=50
-
diff --git a/bundles/pubsub/integration/meta_data/ping3.properties b/bundles/pubsub/integration/meta_data/ping3.properties
deleted file mode 100644
index 55717054..00000000
--- a/bundles/pubsub/integration/meta_data/ping3.properties
+++ /dev/null
@@ -1,22 +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.
-tcp.passive.key=tcp://localhost
-tcp.passive.configured=true
-#note only effective if run as root
-thread.realtime.sched=SCHED_FIFO
-thread.realtime.prio=50
-
diff --git a/bundles/pubsub/integration/meta_data/pong2.properties b/bundles/pubsub/integration/meta_data/pong2.properties
deleted file mode 100644
index b95f3bc5..00000000
--- a/bundles/pubsub/integration/meta_data/pong2.properties
+++ /dev/null
@@ -1,23 +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.
-tcp.static.connect.urls=tcp://localhost:9500
-tcp.passive.key=tcp://localhost
-
-#note only effective if run as root
-thread.realtime.sched=SCHED_FIFO
-thread.realtime.prio=50
-
diff --git a/bundles/pubsub/integration/meta_data/pong3.properties b/bundles/pubsub/integration/meta_data/pong3.properties
deleted file mode 100644
index cb64543d..00000000
--- a/bundles/pubsub/integration/meta_data/pong3.properties
+++ /dev/null
@@ -1,22 +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.
-tcp.passive.key=tcp://localhost:9500
-tcp.passive.configured=true
-#note only effective if run as root
-thread.realtime.sched=SCHED_FIFO
-thread.realtime.prio=50
-
diff --git a/bundles/pubsub/integration/pstm_deadlock_test/test_runner.cc b/bundles/pubsub/integration/pstm_deadlock_test/test_runner.cc
deleted file mode 100644
index b4e10e7c..00000000
--- a/bundles/pubsub/integration/pstm_deadlock_test/test_runner.cc
+++ /dev/null
@@ -1,161 +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_launcher.h"
-#include <celix/dm/Component.h>
-#include <celix/dm/DependencyManager.h>
-#include "pubsub/api.h"
-#include <unistd.h>
-#include <memory>
-#include <mutex>
-#include "celix_bundle_context.h"
-#include "celix_constants.h"
-
-#include <gtest/gtest.h>
-#include <future>
-
-constexpr const char *deadlockSutBundleFile = DEADLOCK_SUT_BUNDLE_FILE;
-
-struct DeadlockTestSuite : public ::testing::Test {
- celix_framework_t *fw = NULL;
- celix_bundle_context_t *ctx = NULL;
- std::shared_ptr<DependencyManager> mng = NULL;
- long sutBundleId = 0;
-
- DeadlockTestSuite() {
- celixLauncher_launch("config.properties", &fw);
- ctx = celix_framework_getFrameworkContext(fw);
- mng = std::shared_ptr<DependencyManager>(new DependencyManager(ctx));
- sutBundleId = celix_bundleContext_installBundle(ctx, deadlockSutBundleFile, false);
- }
-
- ~DeadlockTestSuite() override {
- celix_bundleContext_uninstallBundle(ctx, sutBundleId);
- mng = nullptr;
- celixLauncher_stop(fw);
- celixLauncher_waitForShutdown(fw);
- celixLauncher_destroy(fw);
- ctx = NULL;
- fw = NULL;
- }
-
- DeadlockTestSuite(const DeadlockTestSuite&) = delete;
- DeadlockTestSuite& operator=(const DeadlockTestSuite&) = delete;
-};
-
-class DependencyCmp;
-
-struct activator {
- std::string cmpUUID{};
- celix_bundle_context_t *ctx{};
- std::promise<void> promise{};
- std::shared_ptr<celix::dm::DependencyManager> mng{};
-};
-
-class IDependency {
-protected:
- IDependency() = default;
- ~IDependency() = default;
-public:
- virtual double getData() = 0;
-};
-
-class DependencyCmp : public IDependency {
-public:
- DependencyCmp() {
- std::cout << "Creating DependencyCmp\n";
- }
- virtual ~DependencyCmp() { std::cout << "Destroying DependencyCmp\n"; };
-
- DependencyCmp(DependencyCmp&& other) noexcept = default;
- DependencyCmp& operator=(DependencyCmp&&) = default;
-
- DependencyCmp(const DependencyCmp& other) = delete;
- DependencyCmp operator=(const DependencyCmp&) = delete;
-
- double getData() override {
- return 1.0;
- }
-
- void setPublisher(const pubsub_publisher_t *pub) {
- if (pub == nullptr) {
- return; //nothing on "unsetting" svc
- }
- auto cmp = act->mng->findComponent<DependencyCmp>(act->cmpUUID);
- EXPECT_TRUE(cmp);
- if (cmp) {
- cmp->createCServiceDependency<pubsub_publisher_t>(PUBSUB_PUBLISHER_SERVICE_NAME)
- .setVersionRange("[3.0.0,4)")
- .setFilter("(topic=deadlock)(scope=scope2)")
- .setStrategy(celix::dm::DependencyUpdateStrategy::suspend)
- .setCallbacks([](const pubsub_publisher_t *, Properties&&) { std::cout << "success\n"; })
- .setRequired(true)
- .build();
- }
- act->promise.set_value();
- }
-
- int init() {
- return CELIX_SUCCESS;
- }
-
- int start() {
- return CELIX_SUCCESS;
- }
-
- int stop() {
- return CELIX_SUCCESS;
- }
-
- int deinit() {
- return CELIX_SUCCESS;
- }
-
- activator *act{nullptr};
-};
-
-TEST_F(DeadlockTestSuite, test) {
-
- Component<DependencyCmp>& cmp = mng->createComponent<DependencyCmp>()
- .addInterface<IDependency>("1.0.0", {});
-
- cmp.setCallbacks(&DependencyCmp::init, &DependencyCmp::start, &DependencyCmp::stop, &DependencyCmp::deinit);
-
- activator act{};
- act.ctx = ctx;
- act.mng = mng;
- act.cmpUUID = cmp.getUUID();
- cmp.getInstance().act = &act;
-
- cmp.createCServiceDependency<pubsub_publisher_t>(PUBSUB_PUBLISHER_SERVICE_NAME)
- .setVersionRange("[3.0.0,4)")
- .setFilter("(topic=deadlock)(scope=scope)")
- .setStrategy(celix::dm::DependencyUpdateStrategy::suspend)
- .setCallbacks([&cmp](const pubsub_publisher_t *pub, Properties&&) { cmp.getInstance().setPublisher(pub); })
- .setRequired(true);
-
- ASSERT_TRUE(cmp.isValid());
- mng->start();
-
- celix_bundleContext_startBundle(ctx, sutBundleId);
-
- //wait till setPublisher has added an service dependency. If not the findComponent can return NULL
- act.promise.get_future().wait();
- mng->stop();
-}
diff --git a/bundles/pubsub/keygen/CMakeLists.txt b/bundles/pubsub/keygen/CMakeLists.txt
deleted file mode 100644
index 0f8ecc89..00000000
--- a/bundles/pubsub/keygen/CMakeLists.txt
+++ /dev/null
@@ -1,30 +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.
-
-if (BUILD_ZMQ_SECURITY)
-
- find_package(ZeroMQ REQUIRED)
- find_package(czmq REQUIRED)
- find_package(OpenSSL 1.1.0 REQUIRED)
-
- add_executable(makecert makecert.c)
- target_link_libraries(makecert czmq::czmq)
-
- add_executable(ed_file ed_file.c)
- target_link_libraries(ed_file PUBLIC ZeroMQ::ZeroMQ czmq::czmq OpenSSL::SSL)
-
-endif()
diff --git a/bundles/pubsub/keygen/ed_file.c b/bundles/pubsub/keygen/ed_file.c
deleted file mode 100644
index aabb8f1a..00000000
--- a/bundles/pubsub/keygen/ed_file.c
+++ /dev/null
@@ -1,309 +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.
- */
-/**
- * ed_file.c
- *
- * \date Dec 2, 2016
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <czmq.h>
-#include <openssl/evp.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <strings.h>
-
-#define MAX_KEY_FILE_LENGTH 256
-#define MAX_LINE_LENGTH 64
-#define AES_KEY_LENGTH 32
-#define AES_IV_LENGTH 16
-
-#define KEY_TO_GET "aes_key"
-#define IV_TO_GET "aes_iv"
-
-int generate_sha256_hash(char* text, unsigned char* digest);
-int encrypt_aes(unsigned char *plaintext, int plaintext_len, unsigned char *key, unsigned char *iv, unsigned char *ciphertext);
-int decrypt_aes(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, unsigned char *iv, unsigned char *plaintext);
-
-static char* read_keys_file_content(const char *filePath);
-static void parse_key_lines(char *keysBuffer, char **key, char **iv);
-static void parse_key_line(char *line, char **key, char **iv);
-
-int main(int argc, const char* argv[])
-{
- if (argc < 4) {
- printf("Usage: %s <key_file> <input_file> <output_file> [options]\n", argv[0]);
- printf("Default behavior: encrypting a file\n");
- printf("Options:\n");
- printf("\t-d\tSpecify to decrypt a file\n");
- printf("\n");
- return EXIT_FAILURE;
- }
-
- int rc = 0;
-
- const char* keys_file_path = argv[1];
- const char* input_file_path = argv[2];
- const char* output_file_path = argv[3];
-
- bool decryptParam = false;
- if (argc > 4 && strcmp(argv[4], "-d") == 0) {
- decryptParam = true;
- }
-
- if (!zsys_file_exists(keys_file_path)) {
- printf("Keys file '%s' doesn't exist!\n", keys_file_path);
- return EXIT_FAILURE;
- }
-
- if (!zsys_file_exists(input_file_path)) {
- printf("Input file does not exist!\n");
- return EXIT_FAILURE;
- }
-
- char* keys_data = read_keys_file_content(keys_file_path);
- if (keys_data == NULL) {
- return EXIT_FAILURE;
- }
-
- char* key = NULL;
- char* iv = NULL;
- parse_key_lines(keys_data, &key, &iv);
- free(keys_data);
-
- if (key == NULL || iv == NULL) {
- printf("Loading AES key and/or AES iv failed!\n");
- free(key);
- free(iv);
- return EXIT_FAILURE;
- }
-
- printf("Using AES Key \t\t'%s'\n", key);
- printf("Using AES IV \t\t'%s'\n", iv);
- printf("Input file path \t'%s'\n", input_file_path);
- printf("Output file path \t'%s'\n", output_file_path);
- printf("Decrypting \t\t'%s'\n\n", (decryptParam) ? "true" : "false");
-
- unsigned char key_digest[EVP_MAX_MD_SIZE];
- unsigned char iv_digest[EVP_MAX_MD_SIZE];
- generate_sha256_hash((char*) key, key_digest);
- generate_sha256_hash((char*) iv, iv_digest);
-
- zchunk_t* input_chunk = zchunk_slurp (input_file_path, 0);
- if (input_chunk == NULL) {
- printf("Input file not correct!\n");
- free(key);
- free(iv);
- return EXIT_FAILURE;
- }
-
- //Load input data from file
- int input_file_size = (int) zchunk_size (input_chunk);
- char* input_file_data = zchunk_strdup(input_chunk);
- zchunk_destroy (&input_chunk);
-
- int output_len;
- unsigned char output[input_file_size];
- if (decryptParam) {
- output_len = decrypt_aes((unsigned char*) input_file_data, input_file_size, key_digest, iv_digest, output);
- output[output_len] = '\0';
- }else{
- output_len = encrypt_aes((unsigned char*) input_file_data, input_file_size, key_digest, iv_digest, output);
- }
-
- //Write output data to file
- zfile_t* output_file = zfile_new (".", output_file_path);
- zchunk_t* output_chunk = zchunk_new(output, output_len);
- rc = zfile_output (output_file);
- if (rc != 0) {
- printf("Problem with opening file for writing!\n");
- zchunk_destroy (&output_chunk);
- zfile_close (output_file);
- zfile_destroy (&output_file);
- free(input_file_data);
- free(key);
- free(iv);
-
- return EXIT_FAILURE;
- }
-
- rc = zfile_write (output_file, output_chunk, 0);
- if (rc != 0) {
- printf("Problem with writing output to file!\n");
- }
- printf("Output written to file:\n");
- if (decryptParam) {
- printf("%s\n", output);
- }else{
- BIO_dump_fp (stdout, (const char *) output, output_len);
- }
-
- zchunk_destroy (&output_chunk);
- zfile_close (output_file);
- zfile_destroy (&output_file);
- free(input_file_data);
- free(key);
- free(iv);
-
- return EXIT_SUCCESS;
-}
-
-int generate_sha256_hash(char* text, unsigned char* digest)
-{
- unsigned int digest_len;
-
- EVP_MD_CTX * mdctx = EVP_MD_CTX_new();
- EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL);
- EVP_DigestUpdate(mdctx, text, strlen(text));
- EVP_DigestFinal_ex(mdctx, digest, &digest_len);
- EVP_MD_CTX_free(mdctx);
-
- return digest_len;
-}
-
-int encrypt_aes(unsigned char *plaintext, int plaintext_len, unsigned char *key, unsigned char *iv, unsigned char *ciphertext)
-{
- int len;
- int ciphertext_len;
-
- EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
-
- EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv);
- EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len);
- ciphertext_len = len;
- EVP_EncryptFinal_ex(ctx, ciphertext + len, &len);
- ciphertext_len += len;
-
- EVP_CIPHER_CTX_free(ctx);
-
- return ciphertext_len;
-}
-
-int decrypt_aes(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, unsigned char *iv, unsigned char *plaintext)
-{
- int len;
- int plaintext_len;
-
- EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
-
- EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv);
- EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len);
- plaintext_len = len;
- EVP_DecryptFinal_ex(ctx, plaintext + len, &len);
- plaintext_len += len;
-
- EVP_CIPHER_CTX_free(ctx);
-
- return plaintext_len;
-}
-
-static char* read_keys_file_content(const char *keys_file_path) {
- char* keys_file_full_path = strndup(keys_file_path, MAX_KEY_FILE_LENGTH);
- char* keys_file_name = NULL;
-
- char* sep_kf_at = strrchr(keys_file_path, '/');
- if (sep_kf_at != NULL) {
- *sep_kf_at = '\0';
- keys_file_name = sep_kf_at + 1;
- }else{
- keys_file_name = (char*) keys_file_path;
- keys_file_path = (const char*) ".";
- }
-
- printf("Keys file path: %s\n", keys_file_full_path);
-
- int rc = 0;
-
- zfile_t* keys_file = zfile_new (keys_file_path, keys_file_name);
- rc = zfile_input (keys_file);
- if (rc != 0) {
- printf("Keys file '%s' not readable!\n", keys_file_full_path);
- zfile_destroy(&keys_file);
- free(keys_file_full_path);
- return NULL;
- }
-
- ssize_t keys_file_size = zsys_file_size (keys_file_full_path);
- zchunk_t* keys_chunk = zfile_read (keys_file, keys_file_size, 0);
- if (keys_chunk == NULL) {
- printf("Can't read file '%s'!\n", keys_file_full_path);
- zfile_close(keys_file);
- zfile_destroy(&keys_file);
- free(keys_file_full_path);
- return NULL;
- }
-
- char* keys_data = zchunk_strdup(keys_chunk);
- zchunk_destroy(&keys_chunk);
- zfile_close(keys_file);
- zfile_destroy (&keys_file);
-
- return keys_data;
-}
-
-static void parse_key_lines(char *keysBuffer, char **key, char **iv) {
- char *line = NULL, *saveLinePointer = NULL;
-
- bool firstTime = true;
- do {
- if (firstTime) {
- line = strtok_r(keysBuffer, "\n", &saveLinePointer);
- firstTime = false;
- }else {
- line = strtok_r(NULL, "\n", &saveLinePointer);
- }
-
- if (line == NULL) {
- break;
- }
-
- parse_key_line(line, key, iv);
-
- } while ((*key == NULL || *iv == NULL) && line != NULL);
-
-}
-
-static void parse_key_line(char *line, char **key, char **iv) {
- char *detectedKey = NULL, *detectedValue= NULL;
-
- char* sep_at = strchr(line, ':');
- if (sep_at == NULL) {
- return;
- }
-
- *sep_at = '\0'; // overwrite first separator, creating two strings.
- detectedKey = line;
- detectedValue = sep_at + 1;
-
- if (detectedKey == NULL || detectedValue == NULL) {
- return;
- }
- if (detectedKey[0] == '\0' || detectedValue[0] == '\0') {
- return;
- }
-
- if (*key == NULL && strcmp(detectedKey, KEY_TO_GET) == 0) {
- *key = strndup(detectedValue, AES_KEY_LENGTH);
- } else if (*iv == NULL && strcmp(detectedKey, IV_TO_GET) == 0) {
- *iv = strndup(detectedValue, AES_IV_LENGTH);
- }
-}
-
diff --git a/bundles/pubsub/keygen/makecert.c b/bundles/pubsub/keygen/makecert.c
deleted file mode 100644
index 4999397a..00000000
--- a/bundles/pubsub/keygen/makecert.c
+++ /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.
- */
-/**
- * makecert.c
- *
- * \date Dec 2, 2016
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <string.h>
-
-#include "czmq.h"
-
-int main (int argc, const char * argv[]) {
-
- const char * cert_name_public = "certificate.pub";
- const char * cert_name_secret = "certificate.key";
- if (argc == 3 && strcmp(argv[1], argv[2]) != 0) {
- cert_name_public = argv[1];
- cert_name_secret = argv[2];
- }
-
- zcert_t * cert = zcert_new();
-
- char *timestr = zclock_timestr ();
- zcert_set_meta (cert, "date-created", timestr);
- free (timestr);
-
- zcert_save_public(cert, cert_name_public);
- zcert_save_secret(cert, cert_name_secret);
- zcert_print (cert);
- printf("\n");
- printf("I: CURVE certificate created in %s and %s\n", cert_name_public, cert_name_secret);
- zcert_destroy (&cert);
-
- return 0;
-}
diff --git a/bundles/pubsub/pubsub_admin_tcp/CMakeLists.txt b/bundles/pubsub/pubsub_admin_tcp/CMakeLists.txt
deleted file mode 100644
index 421f4afa..00000000
--- a/bundles/pubsub/pubsub_admin_tcp/CMakeLists.txt
+++ /dev/null
@@ -1,45 +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_TCP "Build TCP PubSub Admin" ON)
-if (PUBSUB_PSA_TCP)
- find_package(libuuid REQUIRED)
-
- add_celix_bundle(celix_pubsub_admin_tcp
- BUNDLE_SYMBOLICNAME "apache_celix_pubsub_admin_tcp"
- VERSION "2.1.0"
- GROUP "Celix/PubSub"
- SOURCES
- src/psa_activator.c
- src/pubsub_tcp_admin.c
- src/pubsub_tcp_topic_sender.c
- src/pubsub_tcp_topic_receiver.c
- src/pubsub_tcp_handler.c
- src/pubsub_tcp_common.c
- )
-
- target_link_libraries(celix_pubsub_admin_tcp PRIVATE Celix::pubsub_spi Celix::pubsub_utils)
- target_link_libraries(celix_pubsub_admin_tcp PRIVATE Celix::log_helper)
- target_link_libraries(celix_pubsub_admin_tcp PRIVATE Celix::shell_api)
- target_include_directories(celix_pubsub_admin_tcp PRIVATE src)
- target_link_libraries(celix_pubsub_admin_tcp PRIVATE libuuid::libuuid)
- celix_deprecated_utils_headers(celix_pubsub_admin_tcp)
- celix_deprecated_framework_headers(celix_pubsub_admin_tcp)
-
- install_celix_bundle(celix_pubsub_admin_tcp EXPORT celix COMPONENT pubsub)
- add_library(Celix::celix_pubsub_admin_tcp ALIAS celix_pubsub_admin_tcp)
-endif (PUBSUB_PSA_TCP)
diff --git a/bundles/pubsub/pubsub_admin_tcp/src/psa_activator.c b/bundles/pubsub/pubsub_admin_tcp/src/psa_activator.c
deleted file mode 100644
index d8b5f13a..00000000
--- a/bundles/pubsub/pubsub_admin_tcp/src/psa_activator.c
+++ /dev/null
@@ -1,128 +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 <stdlib.h>
-
-#include "celix_bundle_activator.h"
-#include "pubsub_protocol.h"
-#include "celix_log_helper.h"
-
-#include "pubsub_admin.h"
-#include "pubsub_admin_metrics.h"
-#include "pubsub_tcp_admin.h"
-#include "celix_shell_command.h"
-
-typedef struct psa_tcp_activator {
- celix_log_helper_t *logHelper;
-
- pubsub_tcp_admin_t *admin;
-
- long protocolsTrackerId;
-
- pubsub_admin_service_t adminService;
- long adminSvcId;
-
- pubsub_admin_metrics_service_t adminMetricsService;
- long adminMetricsSvcId;
-
- celix_shell_command_t cmdSvc;
- long cmdSvcId;
-} psa_tcp_activator_t;
-
-int psa_tcp_start(psa_tcp_activator_t *act, celix_bundle_context_t *ctx) {
- act->adminSvcId = -1L;
- act->cmdSvcId = -1L;
- act->protocolsTrackerId = -1L;
-
- act->logHelper = celix_logHelper_create(ctx, "celix_psa_admin_tcp_v2");
-
- act->admin = pubsub_tcpAdmin_create(ctx, act->logHelper);
- celix_status_t status = act->admin != NULL ? CELIX_SUCCESS : CELIX_BUNDLE_EXCEPTION;
-
- //track protocols
- if (status == CELIX_SUCCESS) {
- celix_service_tracking_options_t opts = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS;
- opts.filter.serviceName = PUBSUB_PROTOCOL_SERVICE_NAME;
- opts.callbackHandle = act->admin;
- opts.addWithProperties = pubsub_tcpAdmin_addProtocolSvc;
- opts.removeWithProperties = pubsub_tcpAdmin_removeProtocolSvc;
- act->protocolsTrackerId = 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_tcpAdmin_matchPublisher;
- psaSvc->matchSubscriber = pubsub_tcpAdmin_matchSubscriber;
- psaSvc->matchDiscoveredEndpoint = pubsub_tcpAdmin_matchDiscoveredEndpoint;
- psaSvc->setupTopicSender = pubsub_tcpAdmin_setupTopicSender;
- psaSvc->teardownTopicSender = pubsub_tcpAdmin_teardownTopicSender;
- psaSvc->setupTopicReceiver = pubsub_tcpAdmin_setupTopicReceiver;
- psaSvc->teardownTopicReceiver = pubsub_tcpAdmin_teardownTopicReceiver;
- psaSvc->addDiscoveredEndpoint = pubsub_tcpAdmin_addDiscoveredEndpoint;
- psaSvc->removeDiscoveredEndpoint = pubsub_tcpAdmin_removeDiscoveredEndpoint;
-
- celix_properties_t *props = celix_properties_create();
- celix_properties_set(props, PUBSUB_ADMIN_SERVICE_TYPE, PUBSUB_TCP_ADMIN_TYPE);
-
- act->adminSvcId = celix_bundleContext_registerService(ctx, psaSvc, PUBSUB_ADMIN_SERVICE_NAME, props);
- }
-
- if (status == CELIX_SUCCESS) {
- act->adminMetricsService.handle = act->admin;
- act->adminMetricsService.metrics = pubsub_tcpAdmin_metrics;
-
- celix_properties_t *props = celix_properties_create();
- celix_properties_set(props, PUBSUB_ADMIN_SERVICE_TYPE, PUBSUB_TCP_ADMIN_TYPE);
-
- act->adminMetricsSvcId =
- celix_bundleContext_registerService(ctx,
- &act->adminMetricsService,
- PUBSUB_ADMIN_METRICS_SERVICE_NAME,
- props);
- }
-
- //register shell command service
- {
- act->cmdSvc.handle = act->admin;
- act->cmdSvc.executeCommand = pubsub_tcpAdmin_executeCommand;
- celix_properties_t *props = celix_properties_create();
- celix_properties_set(props, CELIX_SHELL_COMMAND_NAME, "celix::psa_tcp");
- celix_properties_set(props, CELIX_SHELL_COMMAND_USAGE, "psa_tcp");
- celix_properties_set(props, CELIX_SHELL_COMMAND_DESCRIPTION, "Print the information about the TopicSender and TopicReceivers for the TCP PSA");
- act->cmdSvcId = celix_bundleContext_registerService(ctx, &act->cmdSvc, CELIX_SHELL_COMMAND_SERVICE_NAME, props);
- }
-
- return status;
-}
-
-int psa_tcp_stop(psa_tcp_activator_t *act, celix_bundle_context_t *ctx) {
- celix_bundleContext_unregisterService(ctx, act->adminSvcId);
- celix_bundleContext_unregisterService(ctx, act->cmdSvcId);
- celix_bundleContext_unregisterService(ctx, act->adminMetricsSvcId);
- celix_bundleContext_stopTracker(ctx, act->protocolsTrackerId);
- pubsub_tcpAdmin_destroy(act->admin);
-
- celix_logHelper_destroy(act->logHelper);
-
- return CELIX_SUCCESS;
-}
-
-CELIX_GEN_BUNDLE_ACTIVATOR(psa_tcp_activator_t, psa_tcp_start, psa_tcp_stop);
diff --git a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_psa_tcp_constants.h b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_psa_tcp_constants.h
deleted file mode 100644
index d493eaac..00000000
--- a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_psa_tcp_constants.h
+++ /dev/null
@@ -1,140 +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_TCP_CONSTANTS_H_
-#define PUBSUB_PSA_TCP_CONSTANTS_H_
-
-#define PSA_TCP_BASE_PORT "PSA_TCP_BASE_PORT"
-#define PSA_TCP_MAX_PORT "PSA_TCP_MAX_PORT"
-
-#define PSA_TCP_MAX_MESSAGE_SIZE "PSA_TCP_MAX_MESSAGE_SIZE"
-#define PSA_TCP_RECV_BUFFER_SIZE "PSA_TCP_RECV_BUFFER_SIZE"
-#define PSA_TCP_TIMEOUT "PSA_TCP_TIMEOUT"
-#define PSA_TCP_SUBSCRIBER_CONNECTION_TIMEOUT "PSA_TCP_SUBSCRIBER_CONNECTION_TIMEOUT"
-
-#define PSA_TCP_DEFAULT_BASE_PORT 5501
-#define PSA_TCP_DEFAULT_MAX_PORT 6000
-
-#define PSA_TCP_DEFAULT_MAX_MESSAGE_SIZE UINT32_MAX
-#define PSA_TCP_DEFAULT_RECV_BUFFER_SIZE 65 * 1024
-#define PSA_TCP_DEFAULT_TIMEOUT 2000 // 2 seconds
-#define PSA_TCP_SUBSCRIBER_CONNECTION_DEFAULT_TIMEOUT 250 // 250 ms
-
-#define PSA_TCP_DEFAULT_QOS_SAMPLE_SCORE 30
-#define PSA_TCP_DEFAULT_QOS_CONTROL_SCORE 70
-#define PSA_TCP_DEFAULT_SCORE 30
-
-#define PSA_TCP_QOS_SAMPLE_SCORE_KEY "PSA_TCP_QOS_SAMPLE_SCORE"
-#define PSA_TCP_QOS_CONTROL_SCORE_KEY "PSA_TCP_QOS_CONTROL_SCORE"
-#define PSA_TCP_DEFAULT_SCORE_KEY "PSA_TCP_DEFAULT_SCORE"
-
-#define PSA_TCP_METRICS_ENABLED "PSA_TCP_METRICS_ENABLED"
-#define PSA_TCP_DEFAULT_METRICS_ENABLED false
-
-#define PUBSUB_TCP_VERBOSE_KEY "PSA_TCP_VERBOSE"
-#define PUBSUB_TCP_VERBOSE_DEFAULT false
-
-#define PUBSUB_TCP_PUBLISHER_RETRY_CNT_KEY "PUBSUB_TCP_PUBLISHER_RETRY_COUNT"
-#define PUBSUB_TCP_PUBLISHER_RETRY_CNT_DEFAULT 5
-
-#define PUBSUB_TCP_SUBSCRIBER_RETRY_CNT_KEY "PUBSUB_TCP_SUBSCRIBER_RETRY_COUNT"
-#define PUBSUB_TCP_SUBSCRIBER_RETRY_CNT_DEFAULT 5
-
-
-//Time-out settings are only for BLOCKING connections
-#define PUBSUB_TCP_PUBLISHER_SNDTIMEO_KEY "PUBSUB_TCP_PUBLISHER_SEND_TIMEOUT"
-#define PUBSUB_TCP_PUBLISHER_SNDTIMEO_DEFAULT 5.0
-#define PUBSUB_TCP_PUBLISHER_SNDTIMEO_ENDPOINT_DEFAULT 0.0
-
-#define PUBSUB_TCP_SUBSCRIBER_RCVTIMEO_KEY "PUBSUB_TCP_SUBSCRIBER_RCV_TIMEOUT"
-#define PUBSUB_TCP_SUBSCRIBER_RCVTIMEO_DEFAULT 5.0
-
-#define PUBSUB_TCP_PSA_IP_KEY "PSA_IP"
-#define PUBSUB_TCP_ADMIN_TYPE "tcp"
-
-/**
- * The TCP url key for the topic sender endpoints
- */
-#define PUBSUB_TCP_URL_KEY "tcp.url"
-
-/**
- * Can be set in the topic properties to fix a static bind url
- */
-#define PUBSUB_TCP_STATIC_BIND_URL "tcp.static.bind.url"
-
-/**
- * Name of environment variable with ip/url to bind to
- * e.g. PSA_TCP_STATIC_BIND_FOR_topic_scope="tcp://0.0.0.0:4444"
- */
-#define PUBSUB_TCP_STATIC_BIND_URL_FOR "PSA_TCP_STATIC_BIND_URL_FOR_"
-
-/**
- * Can be set in the topic properties to fix a static url used for discovery
- */
-#define PUBSUB_TCP_STATIC_DISCOVER_URL "tcp.static.bind.url"
-
-/**
- * If set true on the endpoint, the tcp TopicSender bind and/or discovery url is statically configured.
- */
-#define PUBSUB_TCP_STATIC_CONFIGURED "tcp.static.configured"
-
-/**
- * The static url which a subscriber should try to connect to.
- * The urls are space separated.
- * Can be set in the topic properties.
- */
-#define PUBSUB_TCP_STATIC_CONNECT_URLS "tcp.static.connect.urls"
-
-
-/**
- * Defines if the publisher / subscriber is a passive endpoint and shares
- * the connection with publisher / subscriber endpoint with the matching (passive) key
- * e.g. tcp.passive.configured="true" means that a publisher / subscriber is passive,
- * when a publisher / subscriber is found with a matching key (for example tcp.passive.key="localhost").
- * This creates full-duplex connection using a single socket.
- */
-#define PUBSUB_TCP_PASSIVE_CONFIGURED "tcp.passive.configured"
-#define PUBSUB_TCP_PASSIVE_KEY "tcp.passive.key"
-
-/**
- * Name of environment variable to indicate that passive endpoint is configured
- * e.g. PSA_TCP_PASSIVE_CONFIGURED_topic_scope="true"
- */
-#define PUBSUB_TCP_PASSIVE_ENABLED "PSA_TCP_PASSIVE_CONFIGURED_"
-/**
- * Name of environment variable to configure the passive key (see PUBSUB_TCP_PASSIVE_KEY )
- * e.g. PSA_TCP_PASSIVE_KEY__topic_scope="tcp://localhost:4444"
- */
-#define PUBSUB_TCP_PASSIVE_SELECTION_KEY "PSA_TCP_PASSIVE_KEY_"
-
-/**
- * Name of environment variable with space-separated list of ips/urls to connect to
- * e.g. PSA_TCP_STATIC_CONNECT_FOR_topic_scope="tcp://127.0.0.1:4444 tcp://127.0.0.2:4444"
- */
-#define PUBSUB_TCP_STATIC_CONNECT_URLS_FOR "PSA_TCP_STATIC_CONNECT_URL_FOR_"
-
-/**
- * Realtime thread prio and scheduling information. This is used to setup the thread prio/sched of the
- * internal TCP threads.
- * Can be set in the topic properties.
- */
-#define PUBSUB_TCP_THREAD_REALTIME_PRIO "thread.realtime.prio"
-#define PUBSUB_TCP_THREAD_REALTIME_SCHED "thread.realtime.sched"
-
-#endif /* PUBSUB_PSA_TCP_CONSTANTS_H_ */
diff --git a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_admin.c b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_admin.c
deleted file mode 100644
index bdca02cb..00000000
--- a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_admin.c
+++ /dev/null
@@ -1,710 +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 <memory.h>
-#include <pubsub_endpoint.h>
-#include <ip_utils.h>
-
-#include <pubsub_matching.h>
-#include "pubsub_utils.h"
-#include "pubsub_tcp_admin.h"
-#include "pubsub_tcp_handler.h"
-#include "pubsub_psa_tcp_constants.h"
-#include "pubsub_tcp_topic_sender.h"
-#include "pubsub_tcp_topic_receiver.h"
-#include "celix_compiler.h"
-#include "celix_constants.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_tcp_admin {
- celix_bundle_context_t *ctx;
- celix_log_helper_t *log;
- const char *fwUUID;
-
- char *ipAddress;
-
- unsigned int basePort;
-
- double qosSampleScore;
- double qosControlScore;
- double defaultScore;
-
- bool verbose;
-
- struct {
- celix_thread_mutex_t mutex;
- hash_map_t *map; //key = svcId, value = psa_tcp_protocol_entry_t*
- } protocols;
-
- struct {
- celix_thread_mutex_t mutex;
- hash_map_t *map; //key = scope:topic key, value = pubsub_tcp_topic_sender_t*
- } topicSenders;
-
- struct {
- celix_thread_mutex_t mutex;
- hash_map_t *map; //key = scope:topic key, value = pubsub_tcp_topic_sender_t*
- } topicReceivers;
-
- struct {
- celix_thread_mutex_t mutex;
- hash_map_t *map; //key = endpoint uuid, value = celix_properties_t* (endpoint)
- } discoveredEndpoints;
-
- struct {
- celix_thread_mutex_t mutex;
- hash_map_t *map; //key = pubsub message serialization marker svc id (long), pubsub_serialization_handler_t*.
- } serializationHandlers;
-
- pubsub_tcp_endPointStore_t endpointStore;
-};
-
-typedef struct psa_tcp_protocol_entry {
- const char *protType;
- long svcId;
- pubsub_protocol_service_t *svc;
-} psa_tcp_protocol_entry_t;
-
-static celix_status_t
-pubsub_tcpAdmin_connectEndpointToReceiver(pubsub_tcp_admin_t *psa, pubsub_tcp_topic_receiver_t *receiver,
- const celix_properties_t *endpoint);
-
-static celix_status_t
-pubsub_tcpAdmin_disconnectEndpointFromReceiver(pubsub_tcp_admin_t *psa, pubsub_tcp_topic_receiver_t *receiver,
- const celix_properties_t *endpoint);
-
-static bool pubsub_tcpAdmin_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_tcp_admin_t *pubsub_tcpAdmin_create(celix_bundle_context_t *ctx, celix_log_helper_t *logHelper) {
- pubsub_tcp_admin_t *psa = calloc(1, sizeof(*psa));
- psa->ctx = ctx;
- psa->log = logHelper;
- psa->verbose = celix_bundleContext_getPropertyAsBool(ctx, PUBSUB_TCP_VERBOSE_KEY, PUBSUB_TCP_VERBOSE_DEFAULT);
- psa->fwUUID = celix_bundleContext_getProperty(ctx, CELIX_FRAMEWORK_UUID, NULL);
- long basePort = celix_bundleContext_getPropertyAsLong(ctx, PSA_TCP_BASE_PORT, PSA_TCP_DEFAULT_BASE_PORT);
- psa->basePort = (unsigned int) basePort;
- psa->defaultScore = celix_bundleContext_getPropertyAsDouble(ctx, PSA_TCP_DEFAULT_SCORE_KEY, PSA_TCP_DEFAULT_SCORE);
- psa->qosSampleScore = celix_bundleContext_getPropertyAsDouble(ctx, PSA_TCP_QOS_SAMPLE_SCORE_KEY,
- PSA_TCP_DEFAULT_QOS_SAMPLE_SCORE);
- psa->qosControlScore = celix_bundleContext_getPropertyAsDouble(ctx, PSA_TCP_QOS_CONTROL_SCORE_KEY,
- PSA_TCP_DEFAULT_QOS_CONTROL_SCORE);
-
- celixThreadMutex_create(&psa->protocols.mutex, NULL);
- psa->protocols.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);
-
- celixThreadMutex_create(&psa->endpointStore.mutex, NULL);
- psa->endpointStore.map = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
-
- celixThreadMutex_create(&psa->serializationHandlers.mutex, NULL);
- psa->serializationHandlers.map = hashMap_create(NULL, NULL, NULL, NULL);
-
- return psa;
-}
-
-void pubsub_tcpAdmin_destroy(pubsub_tcp_admin_t *psa) {
- if (psa == NULL) {
- return;
- }
-
- celixThreadMutex_lock(&psa->endpointStore.mutex);
- hash_map_iterator_t iter = hashMapIterator_construct(psa->endpointStore.map);
- while (hashMapIterator_hasNext(&iter)) {
- pubsub_tcpHandler_t *tcpHandler = hashMapIterator_nextValue(&iter);
- pubsub_tcpHandler_destroy(tcpHandler);
- }
- celixThreadMutex_unlock(&psa->endpointStore.mutex);
-
- celixThreadMutex_lock(&psa->topicSenders.mutex);
- iter = hashMapIterator_construct(psa->topicSenders.map);
- while (hashMapIterator_hasNext(&iter)) {
- pubsub_tcp_topic_sender_t *sender = hashMapIterator_nextValue(&iter);
- pubsub_tcpTopicSender_destroy(sender);
- }
- celixThreadMutex_unlock(&psa->topicSenders.mutex);
-
- celixThreadMutex_lock(&psa->topicReceivers.mutex);
- iter = hashMapIterator_construct(psa->topicReceivers.map);
- while (hashMapIterator_hasNext(&iter)) {
- pubsub_tcp_topic_receiver_t *recv = hashMapIterator_nextValue(&iter);
- pubsub_tcpTopicReceiver_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->serializationHandlers.mutex);
- iter = hashMapIterator_construct(psa->serializationHandlers.map);
- while (hashMapIterator_hasNext(&iter)) {
- pubsub_serializer_handler_t* entry = hashMapIterator_nextValue(&iter);
- pubsub_serializerHandler_destroy(entry);
- }
- celixThreadMutex_unlock(&psa->serializationHandlers.mutex);
-
- celixThreadMutex_lock(&psa->protocols.mutex);
- iter = hashMapIterator_construct(psa->protocols.map);
- while (hashMapIterator_hasNext(&iter)) {
- psa_tcp_protocol_entry_t *entry = hashMapIterator_nextValue(&iter);
- free(entry);
- }
- celixThreadMutex_unlock(&psa->protocols.mutex);
- //note assuming al psa register services and service tracker are removed.
- celixThreadMutex_destroy(&psa->endpointStore.mutex);
- hashMap_destroy(psa->endpointStore.map, false, false);
-
- 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->serializationHandlers.mutex);
- hashMap_destroy(psa->serializationHandlers.map, false, false);
-
- celixThreadMutex_destroy(&psa->protocols.mutex);
- hashMap_destroy(psa->protocols.map, false, false);
-
- free(psa->ipAddress);
-
- free(psa);
-}
-
-void pubsub_tcpAdmin_addProtocolSvc(void *handle, void *svc, const celix_properties_t *props) {
- pubsub_tcp_admin_t *psa = handle;
-
- const char *protType = celix_properties_get(props, PUBSUB_PROTOCOL_TYPE_KEY, NULL);
- long svcId = celix_properties_getAsLong(props, CELIX_FRAMEWORK_SERVICE_ID, -1L);
-
- if (protType == NULL) {
- L_INFO("[PSA_tcp] Ignoring protocol service without %s property", PUBSUB_PROTOCOL_TYPE_KEY);
- return;
- }
-
- celixThreadMutex_lock(&psa->protocols.mutex);
- psa_tcp_protocol_entry_t *entry = hashMap_get(psa->protocols.map, (void *) svcId);
- if (entry == NULL) {
- entry = calloc(1, sizeof(*entry));
- entry->protType = protType;
- entry->svcId = svcId;
- entry->svc = svc;
- hashMap_put(psa->protocols.map, (void *) svcId, entry);
- }
- celixThreadMutex_unlock(&psa->protocols.mutex);
-}
-
-void pubsub_tcpAdmin_removeProtocolSvc(void *handle, void *svc, const celix_properties_t *props) {
- pubsub_tcp_admin_t *psa = handle;
- long svcId = celix_properties_getAsLong(props, CELIX_FRAMEWORK_SERVICE_ID, -1L);
-
- //remove protocol
- // 1) First find entry and
- // 2) loop and destroy all topic sender using the protocol and
- // 3) loop and destroy all topic receivers using the protocol
- // Note that it is the responsibility of the topology manager to create new topic senders/receivers
-
- celixThreadMutex_lock(&psa->protocols.mutex);
- psa_tcp_protocol_entry_t *entry = hashMap_remove(psa->protocols.map, (void *) svcId);
- celixThreadMutex_unlock(&psa->protocols.mutex);
-
- 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_tcp_topic_sender_t *sender = hashMapEntry_getValue(senderEntry);
- if (sender != NULL && entry->svcId == pubsub_tcpTopicSender_protocolSvcId(sender)) {
- char *key = hashMapEntry_getKey(senderEntry);
- hashMapIterator_remove(&iter);
- pubsub_tcpTopicSender_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_tcp_topic_receiver_t *receiver = hashMapEntry_getValue(senderEntry);
- if (receiver != NULL && entry->svcId == pubsub_tcpTopicReceiver_protocolSvcId(receiver)) {
- char *key = hashMapEntry_getKey(senderEntry);
- hashMapIterator_remove(&iter);
- pubsub_tcpTopicReceiver_destroy(receiver);
- free(key);
- }
- }
- celixThreadMutex_unlock(&psa->topicReceivers.mutex);
-
- free(entry);
- }
-}
-
-celix_status_t pubsub_tcpAdmin_matchPublisher(void *handle, long svcRequesterBndId, const celix_filter_t *svcFilter,
- celix_properties_t **topicProperties, double *outScore,
- long *outSerializerSvcId, long *outProtocolSvcId) {
- pubsub_tcp_admin_t *psa = handle;
- L_DEBUG("[PSA_TCP_V2] pubsub_tcpAdmin_matchPublisher");
- celix_status_t status = CELIX_SUCCESS;
- double score = pubsub_utils_matchPublisher(psa->ctx, svcRequesterBndId, svcFilter->filterStr, PUBSUB_TCP_ADMIN_TYPE,
- psa->qosSampleScore, psa->qosControlScore, psa->defaultScore, true, topicProperties, outSerializerSvcId, outProtocolSvcId);
- *outScore = score;
-
-
- return status;
-}
-
-celix_status_t
-pubsub_tcpAdmin_matchSubscriber(void *handle, long svcProviderBndId, const celix_properties_t *svcProperties,
- celix_properties_t **topicProperties, double *outScore, long *outSerializerSvcId,
- long *outProtocolSvcId) {
- pubsub_tcp_admin_t *psa = handle;
- L_DEBUG("[PSA_TCP_V2] pubsub_tcpAdmin_matchSubscriber");
- celix_status_t status = CELIX_SUCCESS;
- double score = pubsub_utils_matchSubscriber(psa->ctx, svcProviderBndId, svcProperties, PUBSUB_TCP_ADMIN_TYPE,
- psa->qosSampleScore, psa->qosControlScore, psa->defaultScore, true, topicProperties, outSerializerSvcId, outProtocolSvcId);
- if (outScore != NULL) {
- *outScore = score;
- }
- return status;
-}
-
-celix_status_t
-pubsub_tcpAdmin_matchDiscoveredEndpoint(void *handle, const celix_properties_t *endpoint, bool *outMatch) {
- pubsub_tcp_admin_t *psa = handle;
- L_DEBUG("[PSA_TCP_V2] pubsub_tcpAdmin_matchEndpoint");
- celix_status_t status = CELIX_SUCCESS;
- bool match = pubsub_utils_matchEndpoint(psa->ctx, psa->log, endpoint, PUBSUB_TCP_ADMIN_TYPE, true, NULL, NULL);
- if (outMatch != NULL) {
- *outMatch = match;
- }
- return status;
-}
-
-static pubsub_serializer_handler_t* pubsub_tcpAdmin_getSerializationHandler(pubsub_tcp_admin_t* psa, long msgSerializationMarkerSvcId) {
- pubsub_serializer_handler_t* handler = NULL;
- celixThreadMutex_lock(&psa->serializationHandlers.mutex);
- handler = hashMap_get(psa->serializationHandlers.map, (void*)msgSerializationMarkerSvcId);
- if (handler == NULL) {
- handler = pubsub_serializerHandler_createForMarkerService(psa->ctx, msgSerializationMarkerSvcId, psa->log);
- if (handler != NULL) {
- hashMap_put(psa->serializationHandlers.map, (void*)msgSerializationMarkerSvcId, handler);
- }
- }
- celixThreadMutex_unlock(&psa->serializationHandlers.mutex);
- return handler;
-}
-
-celix_status_t pubsub_tcpAdmin_setupTopicSender(void *handle, const char *scope, const char *topic,
- const celix_properties_t *topicProperties, long serializerSvcId,
- long protocolSvcId, celix_properties_t **outPublisherEndpoint) {
- pubsub_tcp_admin_t *psa = handle;
- celix_status_t status = CELIX_SUCCESS;
-
- //1) Get serialization handler
- //2) Create TopicSender
- //3) Store TopicSender
- //4) Connect existing endpoints
- //5) set outPublisherEndpoint
-
- pubsub_serializer_handler_t* handler = pubsub_tcpAdmin_getSerializationHandler(psa, serializerSvcId);
- if (handler == NULL) {
- L_ERROR("Cannot create topic sender without serialization handler");
- return CELIX_ILLEGAL_STATE;
- }
-
- celix_properties_t *newEndpoint = NULL;
- char *key = pubsubEndpoint_createScopeTopicKey(scope, topic);
-
- celixThreadMutex_lock(&psa->protocols.mutex);
- celixThreadMutex_lock(&psa->topicSenders.mutex);
- pubsub_tcp_topic_sender_t *sender = hashMap_get(psa->topicSenders.map, key);
- celixThreadMutex_unlock(&psa->topicSenders.mutex);
- if (sender == NULL) {
- psa_tcp_protocol_entry_t *protEntry = hashMap_get(psa->protocols.map, (void *) protocolSvcId);
- if (protEntry != NULL) {
- sender = pubsub_tcpTopicSender_create(psa->ctx, psa->log, scope, topic, handler, handle, topicProperties,
- &psa->endpointStore, protocolSvcId,
- protEntry->svc);
- }
- if (sender != NULL) {
- const char *psaType = PUBSUB_TCP_ADMIN_TYPE;
- const char *protType = protEntry->protType;
- newEndpoint = pubsubEndpoint_create(psa->fwUUID, scope, topic, PUBSUB_PUBLISHER_ENDPOINT_TYPE, psaType,
- pubsub_serializerHandler_getSerializationType(handler), protType, NULL);
- celix_properties_set(newEndpoint, PUBSUB_TCP_URL_KEY, pubsub_tcpTopicSender_url(sender));
-
- celix_properties_setBool(newEndpoint, PUBSUB_TCP_STATIC_CONFIGURED, pubsub_tcpTopicSender_isStatic(sender));
- if (pubsub_tcpTopicSender_isPassive(sender)) {
- celix_properties_set(newEndpoint, PUBSUB_ENDPOINT_VISIBILITY, PUBSUB_ENDPOINT_LOCAL_VISIBILITY);
- } else {
- celix_properties_set(newEndpoint, PUBSUB_ENDPOINT_VISIBILITY, PUBSUB_ENDPOINT_SYSTEM_VISIBILITY);
- }
- //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);
- celixThreadMutex_lock(&psa->topicSenders.mutex);
- hashMap_put(psa->topicSenders.map, key, sender);
- celixThreadMutex_unlock(&psa->topicSenders.mutex);
- } else {
- L_ERROR("[PSA_TCP_V2] Error creating a TopicSender");
- free(key);
- }
- } else {
- free(key);
- L_ERROR("[PSA_TCP_V2] Cannot setup already existing TopicSender for scope/topic %s/%s!", scope, topic);
- }
- celixThreadMutex_unlock(&psa->protocols.mutex);
-
- if (newEndpoint != NULL && outPublisherEndpoint != NULL) {
- *outPublisherEndpoint = newEndpoint;
- }
-
- return status;
-}
-
-celix_status_t pubsub_tcpAdmin_teardownTopicSender(void *handle, const char *scope, const char *topic) {
- pubsub_tcp_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_tcp_topic_sender_t *sender = hashMap_remove(psa->topicSenders.map, key);
- celixThreadMutex_unlock(&psa->topicSenders.mutex);
- free(mapKey);
- pubsub_tcpTopicSender_destroy(sender);
- } else {
- celixThreadMutex_unlock(&psa->topicSenders.mutex);
- L_ERROR("[PSA_TCP_V2] Cannot teardown TopicSender with scope/topic %s/%s. Does not exists",
- scope == NULL ? "(null)" : scope,
- topic);
- }
- free(key);
-
- return status;
-}
-
-celix_status_t pubsub_tcpAdmin_setupTopicReceiver(void *handle, const char *scope, const char *topic,
- const celix_properties_t *topicProperties, long serializerSvcId,
- long protocolSvcId, celix_properties_t **outSubscriberEndpoint) {
- pubsub_tcp_admin_t *psa = handle;
-
- pubsub_serializer_handler_t* handler = pubsub_tcpAdmin_getSerializationHandler(psa, serializerSvcId);
- if (handler == NULL) {
- L_ERROR("Cannot create topic receiver without serialization handler");
- return CELIX_ILLEGAL_STATE;
- }
-
- celix_properties_t *newEndpoint = NULL;
- char *key = pubsubEndpoint_createScopeTopicKey(scope, topic);
-
- celixThreadMutex_lock(&psa->protocols.mutex);
- celixThreadMutex_lock(&psa->topicReceivers.mutex);
- pubsub_tcp_topic_receiver_t *receiver = hashMap_get(psa->topicReceivers.map, key);
- celixThreadMutex_unlock(&psa->topicReceivers.mutex);
- if (receiver == NULL) {
- psa_tcp_protocol_entry_t *protEntry = hashMap_get(psa->protocols.map, (void *) protocolSvcId);
- if (protEntry != NULL) {
- receiver = pubsub_tcpTopicReceiver_create(psa->ctx, psa->log, scope, topic,
- handler, handle, topicProperties,
- &psa->endpointStore, protocolSvcId, protEntry->svc);
- } else {
- L_ERROR("[PSA_TCP_V2] Cannot find serializer or protocol for TopicSender %s/%s", scope == NULL ? "(null)" : scope, topic);
- }
- if (receiver != NULL) {
- const char *psaType = PUBSUB_TCP_ADMIN_TYPE;
- const char *protType = protEntry->protType;
- newEndpoint = pubsubEndpoint_create(psa->fwUUID, scope, topic,
- PUBSUB_SUBSCRIBER_ENDPOINT_TYPE, psaType, pubsub_serializerHandler_getSerializationType(handler), protType, 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);
- }
- celixThreadMutex_lock(&psa->topicReceivers.mutex);
- hashMap_put(psa->topicReceivers.map, key, receiver);
- celixThreadMutex_unlock(&psa->topicReceivers.mutex);
- } else {
- L_ERROR("[PSA_TCP_V2] Error creating a TopicReceiver.");
- free(key);
- }
- } else {
- free(key);
- L_ERROR("[PSA_TCP_V2] Cannot setup already existing TopicReceiver for scope/topic %s/%s!",
- scope == NULL ? "(null)" : scope,
- topic);
- }
- celixThreadMutex_unlock(&psa->protocols.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_tcpAdmin_endpointIsPublisher(endpoint) && pubsubEndpoint_matchWithTopicAndScope(endpoint, topic, scope)) {
- pubsub_tcpAdmin_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_tcpAdmin_teardownTopicReceiver(void *handle, const char *scope, const char *topic) {
- pubsub_tcp_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_tcp_topic_receiver_t *receiver = hashMapEntry_getValue(entry);
- hashMap_remove(psa->topicReceivers.map, receiverKey);
- celixThreadMutex_unlock(&psa->topicReceivers.mutex);
-
- free(receiverKey);
- pubsub_tcpTopicReceiver_destroy(receiver);
- } else {
- celixThreadMutex_unlock(&psa->topicReceivers.mutex);
- }
-
- celix_status_t status = CELIX_SUCCESS;
- return status;
-}
-
-static celix_status_t
-pubsub_tcpAdmin_connectEndpointToReceiver(pubsub_tcp_admin_t *psa, pubsub_tcp_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 *url = celix_properties_get(endpoint, PUBSUB_TCP_URL_KEY, NULL);
-
- if (url == NULL) {
- const char *admin = celix_properties_get(endpoint, PUBSUB_ENDPOINT_ADMIN_TYPE, NULL);
- const char *type = celix_properties_get(endpoint, PUBSUB_ENDPOINT_TYPE, NULL);
- L_WARN("[PSA_TCP_V2] Error got endpoint without a tcp url (admin: %s, type: %s)", admin, type);
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- pubsub_tcpTopicReceiver_connectTo(receiver, url);
- }
-
- return status;
-}
-
-celix_status_t pubsub_tcpAdmin_addDiscoveredEndpoint(void *handle, const celix_properties_t *endpoint) {
- pubsub_tcp_admin_t *psa = handle;
-
- if (pubsub_tcpAdmin_endpointIsPublisher(endpoint)) {
- celixThreadMutex_lock(&psa->topicReceivers.mutex);
- hash_map_iterator_t iter = hashMapIterator_construct(psa->topicReceivers.map);
- while (hashMapIterator_hasNext(&iter)) {
- pubsub_tcp_topic_receiver_t *receiver = hashMapIterator_nextValue(&iter);
- if (pubsubEndpoint_matchWithTopicAndScope(endpoint, pubsub_tcpTopicReceiver_topic(receiver), pubsub_tcpTopicReceiver_scope(receiver))) {
- pubsub_tcpAdmin_connectEndpointToReceiver(psa, receiver, endpoint);
- }
- }
- celixThreadMutex_unlock(&psa->topicReceivers.mutex);
- }
-
- celix_properties_t *cpy = celix_properties_copy(endpoint);
- const char *uuid = celix_properties_get(cpy, PUBSUB_ENDPOINT_UUID, NULL);
-
- celixThreadMutex_lock(&psa->discoveredEndpoints.mutex);
- 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_tcpAdmin_disconnectEndpointFromReceiver(pubsub_tcp_admin_t *psa, pubsub_tcp_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 *url = celix_properties_get(endpoint, PUBSUB_TCP_URL_KEY, NULL);
-
- if (url == NULL) {
- L_WARN("[PSA_TCP_V2] Error got endpoint without tcp url");
- status = CELIX_BUNDLE_EXCEPTION;
- } else {
- pubsub_tcpTopicReceiver_disconnectFrom(receiver, url);
- }
-
- return status;
-}
-
-celix_status_t pubsub_tcpAdmin_removeDiscoveredEndpoint(void *handle, const celix_properties_t *endpoint) {
- pubsub_tcp_admin_t *psa = handle;
-
- if (pubsub_tcpAdmin_endpointIsPublisher(endpoint)) {
- celixThreadMutex_lock(&psa->topicReceivers.mutex);
- hash_map_iterator_t iter = hashMapIterator_construct(psa->topicReceivers.map);
- while (hashMapIterator_hasNext(&iter)) {
- pubsub_tcp_topic_receiver_t *receiver = hashMapIterator_nextValue(&iter);
- pubsub_tcpAdmin_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_tcpAdmin_executeCommand(void *handle, const char *commandLine CELIX_UNUSED, FILE *out,
- FILE *errStream CELIX_UNUSED) {
- pubsub_tcp_admin_t *psa = handle;
- celix_status_t status = CELIX_SUCCESS;
- char *line = celix_utils_strdup(commandLine);
- char *token = line;
- strtok_r(line, " ", &token); //first token is command name
- strtok_r(NULL, " ", &token); //second token is sub command
-
- if (celix_utils_stringEquals(token, "nr_of_receivers")) {
- celixThreadMutex_lock(&psa->topicReceivers.mutex);
- fprintf(out,"%i\n", hashMap_size(psa->topicReceivers.map));
- celixThreadMutex_unlock(&psa->topicReceivers.mutex);
- }
- if (celix_utils_stringEquals(token, "nr_of_senders")) {
- celixThreadMutex_lock(&psa->topicSenders.mutex);
- fprintf(out, "%i\n", hashMap_size(psa->topicSenders.map));
- celixThreadMutex_unlock(&psa->topicSenders.mutex);
- }
-
- fprintf(out, "\n");
- fprintf(out, "Topic Senders:\n");
- celixThreadMutex_lock(&psa->protocols.mutex);
- celixThreadMutex_lock(&psa->topicSenders.mutex);
- hash_map_iterator_t iter = hashMapIterator_construct(psa->topicSenders.map);
- while (hashMapIterator_hasNext(&iter)) {
- pubsub_tcp_topic_sender_t *sender = hashMapIterator_nextValue(&iter);
- long protSvcId = pubsub_tcpTopicSender_protocolSvcId(sender);
- psa_tcp_protocol_entry_t *protEntry = hashMap_get(psa->protocols.map, (void *) protSvcId);
- const char *serType = pubsub_tcpTopicSender_serializerType(sender);
- const char *protType = protEntry == NULL ? "!Error!" : protEntry->protType;
- const char *scope = pubsub_tcpTopicSender_scope(sender);
- const char *topic = pubsub_tcpTopicSender_topic(sender);
- const char *url = pubsub_tcpTopicSender_url(sender);
- const char *isPassive = pubsub_tcpTopicSender_isPassive(sender) ? " (passive)" : "";
- const char *postUrl = pubsub_tcpTopicSender_isStatic(sender) ? " (static)" : "";
- fprintf(out, "|- Topic Sender %s/%s\n", scope == NULL ? "(null)" : scope, topic);
- fprintf(out, " |- serializer type = %s\n", serType);
- fprintf(out, " |- protocol type = %s\n", protType);
- fprintf(out, " |- url = %s%s%s\n", url, postUrl, isPassive);
- }
- celixThreadMutex_unlock(&psa->topicSenders.mutex);
- celixThreadMutex_unlock(&psa->protocols.mutex);
-
- fprintf(out, "\n");
- fprintf(out, "\nTopic Receivers:\n");
- celixThreadMutex_lock(&psa->protocols.mutex);
- celixThreadMutex_lock(&psa->topicReceivers.mutex);
- iter = hashMapIterator_construct(psa->topicReceivers.map);
- while (hashMapIterator_hasNext(&iter)) {
- pubsub_tcp_topic_receiver_t *receiver = hashMapIterator_nextValue(&iter);
- long protSvcId = pubsub_tcpTopicReceiver_protocolSvcId(receiver);
- psa_tcp_protocol_entry_t *protEntry = hashMap_get(psa->protocols.map, (void *) protSvcId);
- const char *serType = pubsub_tcpTopicReceiver_serializerType(receiver);
- const char *protType = protEntry == NULL ? "!Error!" : protEntry->protType;
- const char *scope = pubsub_tcpTopicReceiver_scope(receiver);
- const char *topic = pubsub_tcpTopicReceiver_topic(receiver);
-
- celix_array_list_t *connected = celix_arrayList_create();
- celix_array_list_t *unconnected = celix_arrayList_create();
- pubsub_tcpTopicReceiver_listConnections(receiver, connected, unconnected);
-
- fprintf(out, "|- Topic Receiver %s/%s\n", scope == NULL ? "(null)" : scope, topic);
- fprintf(out, " |- serializer type = %s\n", serType);
- fprintf(out, " |- protocol type = %s\n", protType);
- for (int i = 0; i < celix_arrayList_size(connected); ++i) {
- char *url = celix_arrayList_get(connected, i);
- fprintf(out, " |- connected url = %s\n", url);
- free(url);
- }
- for (int i = 0; i < celix_arrayList_size(unconnected); ++i) {
- char *url = celix_arrayList_get(unconnected, i);
- fprintf(out, " |- unconnected url = %s\n", url);
- free(url);
- }
- celix_arrayList_destroy(connected);
- celix_arrayList_destroy(unconnected);
- }
- celixThreadMutex_unlock(&psa->topicReceivers.mutex);
- celixThreadMutex_unlock(&psa->protocols.mutex);
- fprintf(out, "\n");
-
- free(line);
- return status;
-}
-
-pubsub_admin_metrics_t *pubsub_tcpAdmin_metrics(void *handle) {
- return NULL;
-}
diff --git a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_admin.h b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_admin.h
deleted file mode 100644
index fe8d97a5..00000000
--- a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_admin.h
+++ /dev/null
@@ -1,87 +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_TCP_ADMIN_H
-#define CELIX_PUBSUB_TCP_ADMIN_H
-
-#include <pubsub_admin_metrics.h>
-#include <pubsub_message_serialization_service.h>
-#include <stdint.h>
-#include "celix_log_helper.h"
-#include "pubsub_psa_tcp_constants.h"
-
-typedef struct pubsub_tcp_admin pubsub_tcp_admin_t;
-
-typedef struct psa_tcp_serializer_entry {
- const char *fqn;
- const char *version;
- pubsub_message_serialization_service_t *svc;
-} psa_tcp_serializer_entry_t;
-
-pubsub_tcp_admin_t *pubsub_tcpAdmin_create(celix_bundle_context_t *ctx, celix_log_helper_t *logHelper);
-void pubsub_tcpAdmin_destroy(pubsub_tcp_admin_t *psa);
-
-celix_status_t pubsub_tcpAdmin_matchPublisher(void *handle,
- long svcRequesterBndId,
- const celix_filter_t *svcFilter,
- celix_properties_t **topicProperties,
- double *score,
- long *serializerSvcId,
- long *protocolSvcId);
-celix_status_t pubsub_tcpAdmin_matchSubscriber(void *handle,
- long svcProviderBndId,
- const celix_properties_t *svcProperties,
- celix_properties_t **topicProperties,
- double *score,
- long *serializerSvcId,
- long *protocolSvcId);
-celix_status_t pubsub_tcpAdmin_matchDiscoveredEndpoint(void *handle, const celix_properties_t *endpoint, bool *match);
-
-celix_status_t pubsub_tcpAdmin_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_tcpAdmin_teardownTopicSender(void *handle, const char *scope, const char *topic);
-
-celix_status_t pubsub_tcpAdmin_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_tcpAdmin_teardownTopicReceiver(void *handle, const char *scope, const char *topic);
-
-celix_status_t pubsub_tcpAdmin_addDiscoveredEndpoint(void *handle, const celix_properties_t *endpoint);
-celix_status_t pubsub_tcpAdmin_removeDiscoveredEndpoint(void *handle, const celix_properties_t *endpoint);
-
-void pubsub_tcpAdmin_addSerializerSvc(void *handle, void *svc, const celix_properties_t *props);
-void pubsub_tcpAdmin_removeSerializerSvc(void *handle, void *svc, const celix_properties_t *props);
-
-void pubsub_tcpAdmin_addProtocolSvc(void *handle, void *svc, const celix_properties_t *props);
-void pubsub_tcpAdmin_removeProtocolSvc(void *handle, void *svc, const celix_properties_t *props);
-bool pubsub_tcpAdmin_executeCommand(void *handle, const char *commandLine, FILE *outStream, FILE *errStream);
-
-pubsub_admin_metrics_t *pubsub_tcpAdmin_metrics(void *handle);
-
-#endif //CELIX_PUBSUB_TCP_ADMIN_H
-
diff --git a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_common.c b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_common.c
deleted file mode 100644
index b46e39c6..00000000
--- a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_common.c
+++ /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.
- */
-#include <stdio.h>
-#include <string.h>
-#include "pubsub_tcp_common.h"
-#include "celix_utils.h"
-
-
-bool psa_tcp_isPassive(const char* buffer) {
- bool isPassive = false;
- // Parse Properties
- if (buffer != NULL) {
- char buf[32];
- snprintf(buf, 32, "%s", buffer);
- char *trimmed = celix_utils_trimInPlace(buf);
- if (strncasecmp("true", trimmed, strlen("true")) == 0) {
- isPassive = true;
- } else if (strncasecmp("false", trimmed, strlen("false")) == 0) {
- isPassive = false;
- }
- }
- return isPassive;
-}
diff --git a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_common.h b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_common.h
deleted file mode 100644
index 9ea31dba..00000000
--- a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_common.h
+++ /dev/null
@@ -1,33 +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_TCP_COMMON_H
-#define CELIX_PUBSUB_TCP_COMMON_H
-
-#include <utils.h>
-#include <hash_map.h>
-
-typedef struct pubsub_tcp_endPointStore {
- celix_thread_mutex_t mutex;
- hash_map_t *map;
-} pubsub_tcp_endPointStore_t;
-
-bool psa_tcp_isPassive(const char* buffer);
-
-#endif //CELIX_PUBSUB_TCP_COMMON_H
diff --git a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_handler.c b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_handler.c
deleted file mode 100644
index 464e6019..00000000
--- a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_handler.c
+++ /dev/null
@@ -1,1451 +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.
- */
-/*
- * pubsub_tcp_handler.c
- *
- * \date July 18, 2019
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <array_list.h>
-#include <pthread.h>
-#if defined(__APPLE__)
-#include <sys/types.h>
-#include <sys/event.h>
-#include <sys/time.h>
-#else
-#include <sys/epoll.h>
-#endif
-#include <limits.h>
-#include <fcntl.h>
-#include <arpa/inet.h>
-#include <netinet/tcp.h>
-#include "hash_map.h"
-#include "utils.h"
-#include "pubsub_tcp_handler.h"
-#include "celix_compiler.h"
-
-#define MAX_EVENTS 64
-#define MAX_DEFAULT_BUFFER_SIZE 4u
-
-#if defined(__APPLE__)
-#ifndef MSG_NOSIGNAL
-#define MSG_NOSIGNAL (0)
-#endif
-#endif
-
-#define L_DEBUG(...) \
- celix_logHelper_log(handle->logHelper, CELIX_LOG_LEVEL_DEBUG, __VA_ARGS__)
-#define L_INFO(...) \
- celix_logHelper_log(handle->logHelper, CELIX_LOG_LEVEL_INFO, __VA_ARGS__)
-#define L_WARN(...) \
- celix_logHelper_log(handle->logHelper, CELIX_LOG_LEVEL_WARNING, __VA_ARGS__)
-#define L_ERROR(...) \
- celix_logHelper_log(handle->logHelper, CELIX_LOG_LEVEL_ERROR, __VA_ARGS__)
-
-//
-// Entry administration
-//
-typedef struct psa_tcp_connection_entry {
- char *interface_url;
- char *url;
- int fd;
- struct sockaddr_in addr;
- socklen_t len;
- bool connected;
- bool headerError;
- pubsub_protocol_message_t header;
- size_t maxMsgSize;
- size_t readHeaderSize;
- size_t readHeaderBufferSize; // Size of headerBuffer
- void *readHeaderBuffer;
- size_t writeHeaderBufferSize; // Size of headerBuffer
- void *writeHeaderBuffer;
- size_t readFooterSize;
- size_t readFooterBufferSize;
- void *readFooterBuffer;
- size_t writeFooterBufferSize;
- void *writeFooterBuffer;
- size_t bufferSize;
- void *buffer;
- size_t readMetaBufferSize;
- void *readMetaBuffer;
- size_t writeMetaBufferSize;
- void *writeMetaBuffer;
- unsigned int retryCount;
- celix_thread_mutex_t writeMutex;
- struct msghdr readMsg;
-} psa_tcp_connection_entry_t;
-
-//
-// Handle administration
-//
-struct pubsub_tcpHandler {
- celix_thread_rwlock_t dbLock;
- unsigned int timeout;
- hash_map_t *connection_url_map;
- hash_map_t *connection_fd_map;
- hash_map_t *interface_url_map;
- hash_map_t *interface_fd_map;
- int efd;
- pubsub_tcpHandler_receiverConnectMessage_callback_t receiverConnectMessageCallback;
- pubsub_tcpHandler_receiverConnectMessage_callback_t receiverDisconnectMessageCallback;
- void *receiverConnectPayload;
- pubsub_tcpHandler_acceptConnectMessage_callback_t acceptConnectMessageCallback;
- pubsub_tcpHandler_acceptConnectMessage_callback_t acceptDisconnectMessageCallback;
- void *acceptConnectPayload;
- pubsub_tcpHandler_processMessage_callback_t processMessageCallback;
- void *processMessagePayload;
- celix_log_helper_t *logHelper;
- pubsub_protocol_service_t *protocol;
- unsigned int bufferSize;
- unsigned int maxMsgSize;
- unsigned int maxSendRetryCount;
- unsigned int maxRcvRetryCount;
- double sendTimeout;
- double rcvTimeout;
- celix_thread_t thread;
- bool running;
- bool enableReceiveEvent;
-};
-
-static inline int pubsub_tcpHandler_closeConnectionEntry(pubsub_tcpHandler_t *handle, psa_tcp_connection_entry_t *entry, bool lock);
-static inline int pubsub_tcpHandler_closeInterfaceEntry(pubsub_tcpHandler_t *handle, psa_tcp_connection_entry_t *entry);
-static inline int pubsub_tcpHandler_makeNonBlocking(pubsub_tcpHandler_t *handle, int fd);
-static inline psa_tcp_connection_entry_t* pubsub_tcpHandler_createEntry(pubsub_tcpHandler_t *handle, int fd, char *url, char *interface_url, struct sockaddr_in *addr);
-static inline void pubsub_tcpHandler_freeEntry(psa_tcp_connection_entry_t *entry);
-static inline void pubsub_tcpHandler_releaseEntryBuffer(pubsub_tcpHandler_t *handle, int fd, unsigned int index);
-static inline long int pubsub_tcpHandler_getMsgSize(psa_tcp_connection_entry_t *entry);
-static inline void pubsub_tcpHandler_ensureReadBufferCapacity(pubsub_tcpHandler_t *handle, psa_tcp_connection_entry_t *entry);
-static inline bool pubsub_tcpHandler_readHeader(pubsub_tcpHandler_t *handle, int fd, psa_tcp_connection_entry_t *entry, long int* msgSize);
-static inline void pubsub_tcpHandler_decodePayload(pubsub_tcpHandler_t *handle, psa_tcp_connection_entry_t *entry);
-static inline long int pubsub_tcpHandler_readPayload(pubsub_tcpHandler_t *handle, int fd, psa_tcp_connection_entry_t *entry);
-static inline void pubsub_tcpHandler_connectionHandler(pubsub_tcpHandler_t *handle, int fd);
-static inline void pubsub_tcpHandler_handler(pubsub_tcpHandler_t *handle);
-static void *pubsub_tcpHandler_thread(void *data);
-
-
-
-//
-// Create a handle
-//
-pubsub_tcpHandler_t *pubsub_tcpHandler_create(pubsub_protocol_service_t *protocol, celix_log_helper_t *logHelper) {
- pubsub_tcpHandler_t *handle = calloc(sizeof(*handle), 1);
- if (handle != NULL) {
-#if defined(__APPLE__)
- handle->efd = kqueue();
-#else
- handle->efd = epoll_create1(0);
-#endif
- handle->connection_url_map = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- handle->connection_fd_map = hashMap_create(NULL, NULL, NULL, NULL);
- handle->interface_url_map = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- handle->interface_fd_map = hashMap_create(NULL, NULL, NULL, NULL);
- handle->timeout = 2000; // default 2 sec
- handle->logHelper = logHelper;
- handle->protocol = protocol;
- handle->bufferSize = MAX_DEFAULT_BUFFER_SIZE;
- celixThreadRwlock_create(&handle->dbLock, 0);
- handle->running = true;
- celixThread_create(&handle->thread, NULL, pubsub_tcpHandler_thread, handle);
- // signal(SIGPIPE, SIG_IGN);
- }
- return handle;
-}
-
-//
-// Destroys the handle
-//
-void pubsub_tcpHandler_destroy(pubsub_tcpHandler_t *handle) {
- if (handle != NULL) {
- celixThreadRwlock_readLock(&handle->dbLock);
- bool running = handle->running;
- celixThreadRwlock_unlock(&handle->dbLock);
- if (running) {
- celixThreadRwlock_writeLock(&handle->dbLock);
- handle->running = false;
- celixThreadRwlock_unlock(&handle->dbLock);
- celixThread_join(handle->thread, NULL);
- }
- celixThreadRwlock_writeLock(&handle->dbLock);
- hash_map_iterator_t interface_iter = hashMapIterator_construct(handle->interface_url_map);
- while (hashMapIterator_hasNext(&interface_iter)) {
- psa_tcp_connection_entry_t *entry = hashMapIterator_nextValue(&interface_iter);
- if (entry != NULL) {
- pubsub_tcpHandler_closeInterfaceEntry(handle, entry);
- }
- }
-
- hash_map_iterator_t connection_iter = hashMapIterator_construct(handle->connection_url_map);
- while (hashMapIterator_hasNext(&connection_iter)) {
- psa_tcp_connection_entry_t *entry = hashMapIterator_nextValue(&connection_iter);
- if (entry != NULL) {
- pubsub_tcpHandler_closeConnectionEntry(handle, entry, true);
- }
- }
- if (handle->efd >= 0) close(handle->efd);
- hashMap_destroy(handle->connection_url_map, false, false);
- hashMap_destroy(handle->connection_fd_map, false, false);
- hashMap_destroy(handle->interface_url_map, false, false);
- hashMap_destroy(handle->interface_fd_map, false, false);
- celixThreadRwlock_unlock(&handle->dbLock);
- celixThreadRwlock_destroy(&handle->dbLock);
- free(handle);
- }
-}
-
-//
-// Open the socket using an url
-//
-int pubsub_tcpHandler_open(pubsub_tcpHandler_t *handle, char *url) {
- int rc = 0;
- celixThreadRwlock_readLock(&handle->dbLock);
- pubsub_utils_url_t *url_info = pubsub_utils_url_parse(url);
- int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- if (rc >= 0) {
- int setting = 1;
- if (rc == 0) {
- rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &setting, sizeof(setting));
- if (rc != 0) {
- close(fd);
- L_ERROR("[TCP Socket] Error setsockopt(SO_REUSEADDR): %s\n", strerror(errno));
- }
- }
- if (rc == 0) {
- rc = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &setting, sizeof(setting));
- if (rc != 0) {
- close(fd);
- L_ERROR("[TCP Socket] Error setsockopt(TCP_NODELAY): %s\n", strerror(errno));
- }
- } else {
- L_ERROR("[TCP Socket] Error creating socket: %s\n", strerror(errno));
- }
- if (rc == 0 && handle->sendTimeout != 0.0) {
- struct timeval tv;
- tv.tv_sec = (long int) handle->sendTimeout;
- tv.tv_usec = (long int) ((handle->sendTimeout - tv.tv_sec) * 1000000.0);
- rc = setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
- if (rc != 0) {
- L_ERROR("[TCP Socket] Error setsockopt (SO_SNDTIMEO) to set send timeout: %s", strerror(errno));
- }
- }
- if (rc == 0 && handle->rcvTimeout != 0.0) {
- struct timeval tv;
- tv.tv_sec = (long int) handle->rcvTimeout;
- tv.tv_usec = (long int) ((handle->rcvTimeout - tv.tv_sec) * 1000000.0);
- rc = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
- if (rc != 0) {
- L_ERROR("[TCP Socket] Error setsockopt (SO_RCVTIMEO) to set send timeout: %s", strerror(errno));
- }
- }
- struct sockaddr_in *addr = pubsub_utils_url_getInAddr(url_info->hostname, url_info->port_nr);
- if (addr) {
- rc = bind(fd, (struct sockaddr *) addr, sizeof(struct sockaddr));
- if (rc != 0) {
- close(fd);
- L_ERROR("[TCP Socket] Error bind: %s\n", strerror(errno));
- }
- free(addr);
- }
- }
- pubsub_utils_url_free(url_info);
- celixThreadRwlock_unlock(&handle->dbLock);
- return (!rc) ? fd : rc;
-}
-
-//
-// Closes the discriptor with it's connection/interfaces (receiver/sender)
-//
-int pubsub_tcpHandler_close(pubsub_tcpHandler_t *handle, int fd) {
- int rc = 0;
- if (handle != NULL) {
- psa_tcp_connection_entry_t *entry = NULL;
- celixThreadRwlock_writeLock(&handle->dbLock);
- entry = hashMap_get(handle->interface_fd_map, (void *) (intptr_t) fd);
- if (entry) {
- entry = hashMap_remove(handle->interface_url_map, (void *) (intptr_t) entry->url);
- rc = pubsub_tcpHandler_closeInterfaceEntry(handle, entry);
- entry = NULL;
- }
- entry = hashMap_get(handle->connection_fd_map, (void *) (intptr_t) fd);
- if (entry) {
- entry = hashMap_remove(handle->connection_url_map, (void *) (intptr_t) entry->url);
- rc = pubsub_tcpHandler_closeConnectionEntry(handle, entry, false);
- entry = NULL;
- }
- celixThreadRwlock_unlock(&handle->dbLock);
- }
- return rc;
-}
-
-//
-// Create connection/interface entry
-//
-static inline psa_tcp_connection_entry_t *
-pubsub_tcpHandler_createEntry(pubsub_tcpHandler_t *handle, int fd, char *url, char *interface_url,
- struct sockaddr_in *addr) {
- psa_tcp_connection_entry_t *entry = NULL;
- if (fd >= 0) {
- entry = calloc(sizeof(psa_tcp_connection_entry_t), 1);
- entry->fd = fd;
- celixThreadMutex_create(&entry->writeMutex, NULL);
- if (url) {
- entry->url = strndup(url, 1024 * 1024);
- }
- if (interface_url) {
- entry->interface_url = strndup(interface_url, 1024 * 1024);
- } else {
- if (url) {
- entry->interface_url = strndup(url, 1024 * 1024);
- }
- }
- if (addr) {
- entry->addr = *addr;
- }
- entry->len = sizeof(struct sockaddr_in);
- size_t headerSize = 0;
- size_t footerSize = 0;
- handle->protocol->getHeaderSize(handle->protocol->handle, &headerSize);
- handle->protocol->getFooterSize(handle->protocol->handle, &footerSize);
- entry->readHeaderBufferSize = headerSize;
- entry->writeHeaderBufferSize = headerSize;
-
- entry->readFooterBufferSize = footerSize;
- entry->writeFooterBufferSize = footerSize;
- entry->bufferSize = MAX(handle->bufferSize, headerSize);
- entry->connected = false;
- unsigned minimalMsgSize = entry->writeHeaderBufferSize + entry->writeFooterBufferSize;
- if ((minimalMsgSize > handle->maxMsgSize) && (handle->maxMsgSize)) {
- L_ERROR("[TCP Socket] maxMsgSize (%d) < headerSize + FooterSize (%d)\n", handle->maxMsgSize, minimalMsgSize);
- } else {
- entry->maxMsgSize = (handle->maxMsgSize) ? handle->maxMsgSize : LONG_MAX;
- }
- entry->readHeaderBuffer = calloc(sizeof(char), headerSize);
- entry->writeHeaderBuffer = calloc(sizeof(char), headerSize);
- if (entry->readFooterBufferSize ) entry->readFooterBuffer = calloc(sizeof(char), entry->readFooterBufferSize );
- if (entry->writeFooterBufferSize) entry->writeFooterBuffer = calloc(sizeof(char), entry->writeFooterBufferSize);
- if (entry->bufferSize) entry->buffer = calloc(sizeof(char), entry->bufferSize);
- memset(&entry->readMsg, 0x00, sizeof(struct msghdr));
- entry->readMsg.msg_iov = calloc(sizeof(struct iovec), IOV_MAX);
- }
- return entry;
-}
-
-//
-// Free connection/interface entry
-//
-static inline void
-pubsub_tcpHandler_freeEntry(psa_tcp_connection_entry_t *entry) {
- if (entry) {
- free(entry->url);
- free(entry->interface_url);
- if (entry->fd >= 0) close(entry->fd);
- free(entry->buffer);
- free(entry->readHeaderBuffer);
- free(entry->writeHeaderBuffer);
- free(entry->readFooterBuffer);
- free(entry->writeFooterBuffer);
- free(entry->readMetaBuffer);
- free(entry->writeMetaBuffer);
- free(entry->readMsg.msg_iov);
- celixThreadMutex_destroy(&entry->writeMutex);
- free(entry);
- }
-}
-
-//
-// Releases the Buffer
-//
-static inline void
-pubsub_tcpHandler_releaseEntryBuffer(pubsub_tcpHandler_t *handle, int fd, unsigned int index CELIX_UNUSED) {
- psa_tcp_connection_entry_t *entry = hashMap_get(handle->connection_fd_map, (void *) (intptr_t) fd);
- if (entry != NULL) {
- entry->buffer = NULL;
- entry->bufferSize = 0;
- }
-}
-
-//
-// Connect to url (receiver)
-//
-int pubsub_tcpHandler_connect(pubsub_tcpHandler_t *handle, char *url) {
- int rc = 0;
- psa_tcp_connection_entry_t *entry = hashMap_get(handle->connection_url_map, (void *) (intptr_t) url);
- if (entry == NULL) {
- pubsub_utils_url_t *url_info = pubsub_utils_url_parse(url);
- int fd = pubsub_tcpHandler_open(handle, url_info->interface_url);
- rc = fd;
- // Connect to sender
- struct sockaddr_in sin;
- socklen_t len = sizeof(sin);
- getsockname(fd, (struct sockaddr *) &sin, &len);
- char *interface_url = pubsub_utils_url_get_url(&sin, NULL);
- struct sockaddr_in *addr = pubsub_utils_url_getInAddr(url_info->hostname, url_info->port_nr);
- if ((rc >= 0) && addr) {
- rc = connect(fd, (struct sockaddr *) addr, sizeof(struct sockaddr));
- if (rc < 0 && errno != EINPROGRESS) {
- L_ERROR("[TCP Socket] Cannot connect to %s:%d: using %s err(%d): %s\n", url_info->hostname, url_info->port_nr, interface_url, errno, strerror(errno));
- close(fd);
- } else {
- entry = pubsub_tcpHandler_createEntry(handle, fd, url, interface_url, &sin);
- }
- free(addr);
- }
- free(interface_url);
- // Subscribe File Descriptor to epoll
- if ((rc >= 0) && (entry)) {
-#if defined(__APPLE__)
- struct kevent ev;
- EV_SET (&ev, entry->fd, EVFILT_READ | EVFILT_WRITE, EV_ADD | EV_ENABLE, 0, 0, 0);
- rc = kevent (handle->efd, &ev, 1, NULL, 0, NULL);
-#else
- struct epoll_event event;
- bzero(&event, sizeof(struct epoll_event)); // zero the struct
- event.events = EPOLLIN | EPOLLRDHUP | EPOLLERR;
- event.data.fd = entry->fd;
- rc = epoll_ctl(handle->efd, EPOLL_CTL_ADD, entry->fd, &event);
-#endif
- if (rc < 0) {
- pubsub_tcpHandler_freeEntry(entry);
- L_ERROR("[TCP Socket] Cannot create poll event %s\n", strerror(errno));
- entry = NULL;
- }
- }
- if ((rc >= 0) && (entry)) {
- celixThreadRwlock_writeLock(&handle->dbLock);
- hashMap_put(handle->connection_url_map, entry->url, entry);
- hashMap_put(handle->connection_fd_map, (void *) (intptr_t) entry->fd, entry);
- celixThreadRwlock_unlock(&handle->dbLock);
- pubsub_tcpHandler_connectionHandler(handle, fd);
- L_INFO("[TCP Socket] Connect to %s using: %s\n", entry->url, entry->interface_url);
- }
- pubsub_utils_url_free(url_info);
- }
- return rc;
-}
-
-//
-// Disconnect from url
-//
-int pubsub_tcpHandler_disconnect(pubsub_tcpHandler_t *handle, char *url) {
- int rc = 0;
- if (handle != NULL) {
- celixThreadRwlock_writeLock(&handle->dbLock);
- psa_tcp_connection_entry_t *entry = NULL;
- entry = hashMap_remove(handle->connection_url_map, url);
- if (entry) {
- pubsub_tcpHandler_closeConnectionEntry(handle, entry, false);
- }
- celixThreadRwlock_unlock(&handle->dbLock);
- }
- return rc;
-}
-
-// loses the connection entry (of receiver)
-//
-static inline int pubsub_tcpHandler_closeConnectionEntry(
- pubsub_tcpHandler_t *handle, psa_tcp_connection_entry_t *entry, bool lock) {
- int rc = 0;
- if (handle != NULL && entry != NULL) {
- fprintf(stdout, "[TCP Socket] Close connection to url: %s: \n", entry->url);
- hashMap_remove(handle->connection_fd_map, (void *) (intptr_t) entry->fd);
- if ((handle->efd >= 0)) {
-#if defined(__APPLE__)
- struct kevent ev;
- EV_SET (&ev, entry->fd, EVFILT_READ, EV_DELETE , 0, 0, 0);
- rc = kevent (handle->efd, &ev, 1, NULL, 0, NULL);
-#else
- struct epoll_event event;
- bzero(&event, sizeof(struct epoll_event)); // zero the struct
- rc = epoll_ctl(handle->efd, EPOLL_CTL_DEL, entry->fd, &event);
-#endif
- if (rc < 0) {
- L_ERROR("[PSA TCP] Error disconnecting %s\n", strerror(errno));
- }
- }
- if (entry->fd >= 0) {
- if (handle->receiverDisconnectMessageCallback)
- handle->receiverDisconnectMessageCallback(handle->receiverConnectPayload, entry->url, lock);
- if (handle->acceptConnectMessageCallback)
- handle->acceptConnectMessageCallback(handle->acceptConnectPayload, entry->url);
- pubsub_tcpHandler_freeEntry(entry);
- entry = NULL;
- }
- }
- return rc;
-}
-
-//
-// Closes the interface entry (of sender)
-//
-static inline int
-pubsub_tcpHandler_closeInterfaceEntry(pubsub_tcpHandler_t *handle,
- psa_tcp_connection_entry_t *entry) {
- int rc = 0;
- if (handle != NULL && entry != NULL) {
- L_INFO("[TCP Socket] Close interface url: %s: \n", entry->url);
- hashMap_remove(handle->interface_fd_map, (void *) (intptr_t) entry->fd);
- if ((handle->efd >= 0)) {
-#if defined(__APPLE__)
- struct kevent ev;
- EV_SET (&ev, entry->fd, EVFILT_READ, EV_DELETE , 0, 0, 0);
- rc = kevent (handle->efd, &ev, 1, NULL, 0, NULL);
-#else
- struct epoll_event event;
- bzero(&event, sizeof(struct epoll_event)); // zero the struct
- rc = epoll_ctl(handle->efd, EPOLL_CTL_DEL, entry->fd, &event);
-#endif
- if (rc < 0) {
- L_ERROR("[PSA TCP] Error disconnecting %s\n", strerror(errno));
- }
- }
- if (entry->fd >= 0) {
- pubsub_tcpHandler_freeEntry(entry);
- }
- }
- return rc;
-}
-
-//
-// Make accept file descriptor non blocking
-//
-static inline int pubsub_tcpHandler_makeNonBlocking(pubsub_tcpHandler_t *handle, int fd) {
- int rc = 0;
- int flags = fcntl(fd, F_GETFL, 0);
- if (flags == -1)
- rc = flags;
- else {
- rc = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
- if (rc < 0) {
- L_ERROR("[TCP Socket] Cannot set to NON_BLOCKING: %s\n", strerror(errno));
- }
- }
- return rc;
-}
-
-//
-// setup listening to interface (sender) using an url
-//
-int pubsub_tcpHandler_listen(pubsub_tcpHandler_t *handle, char *url) {
- int rc = 0;
- celixThreadRwlock_readLock(&handle->dbLock);
- psa_tcp_connection_entry_t *entry =
- hashMap_get(handle->connection_url_map, (void *) (intptr_t) url);
- celixThreadRwlock_unlock(&handle->dbLock);
- if (entry != NULL) {
- // already exist
- return rc;
- }
- char protocol[] = "tcp";
- int fd = pubsub_tcpHandler_open(handle, url);
- rc = fd;
- if (rc < 0) {
- return rc;
- }
- struct sockaddr_in *sin = pubsub_utils_url_from_fd(fd);
- // Make handler fd entry
- char *pUrl = pubsub_utils_url_get_url(sin, protocol);
- if (sin != NULL && pUrl != NULL) {
- entry = pubsub_tcpHandler_createEntry(handle, fd, pUrl, NULL, sin);
- }
- free(pUrl);
- free(sin);
- if (entry != NULL) {
- __atomic_store_n(&entry->connected, true, __ATOMIC_RELEASE);
- if (rc >= 0) {
- rc = listen(fd, SOMAXCONN);
- if (rc != 0) {
- L_ERROR("[TCP Socket] Error listen: %s\n", strerror(errno));
- }
- }
- if (rc >= 0) {
- rc = pubsub_tcpHandler_makeNonBlocking(handle, fd);
- }
- if ((rc >= 0) && (handle->efd >= 0)) {
-#if defined(__APPLE__)
- struct kevent ev;
- EV_SET (&ev, fd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, 0);
- rc = kevent(handle->efd, &ev, 1, NULL, 0, NULL);
-#else
- struct epoll_event event;
- bzero(&event, sizeof(event)); // zero the struct
- event.events = EPOLLIN | EPOLLRDHUP | EPOLLERR;
- event.data.fd = fd;
- rc = epoll_ctl(handle->efd, EPOLL_CTL_ADD, fd, &event);
-#endif
- if (rc == 0) {
- L_INFO("[TCP Socket] Using %s for service annunciation", entry->url);
- celixThreadRwlock_writeLock(&handle->dbLock);
- hashMap_put(handle->interface_fd_map, (void *) (intptr_t) entry->fd, entry);
- hashMap_put(handle->interface_url_map, entry->url, entry);
- celixThreadRwlock_unlock(&handle->dbLock);
- entry = NULL;
- } else {
- L_ERROR("[TCP Socket] Cannot create poll: %s\n", strerror(errno));
- }
- }
- if (entry) {
- pubsub_tcpHandler_freeEntry(entry);
- entry = NULL;
- }
- } else {
- L_ERROR("[TCP Socket] Error listen socket cannot bind to %s: %s\n", url ? url : "", strerror(errno));
- close(fd);
- }
- return rc;
-}
-
-//
-// Setup default receive buffer size.
-// This size is used to allocated the initial read buffer, to avoid receive buffer reallocting.
-// The default receive buffer is allocated in the createEntry when the connection is establised
-//
-int pubsub_tcpHandler_setReceiveBufferSize(pubsub_tcpHandler_t *handle, unsigned int size) {
- if (handle != NULL) {
- celixThreadRwlock_writeLock(&handle->dbLock);
- handle->bufferSize = size;
- celixThreadRwlock_unlock(&handle->dbLock);
- }
- return 0;
-}
-
-//
-// Set Maximum message size
-//
-int pubsub_tcpHandler_setMaxMsgSize(pubsub_tcpHandler_t *handle, unsigned int size) {
- if (handle != NULL) {
- celixThreadRwlock_writeLock(&handle->dbLock);
- handle->maxMsgSize = size;
- celixThreadRwlock_unlock(&handle->dbLock);
- }
- return 0;
-}
-
-//
-// Setup thread timeout
-//
-void pubsub_tcpHandler_setTimeout(pubsub_tcpHandler_t *handle,
- unsigned int timeout) {
- if (handle != NULL) {
- celixThreadRwlock_writeLock(&handle->dbLock);
- handle->timeout = timeout;
- celixThreadRwlock_unlock(&handle->dbLock);
- }
-}
-
-//
-// Setup thread name
-//
-void pubsub_tcpHandler_setThreadName(pubsub_tcpHandler_t *handle,
- const char *topic, const char *scope) {
- if ((handle != NULL) && (topic)) {
- char *thread_name = NULL;
- if ((scope) && (topic))
- asprintf(&thread_name, "TCP TS %s/%s", scope, topic);
- else
- asprintf(&thread_name, "TCP TS %s", topic);
- celixThreadRwlock_writeLock(&handle->dbLock);
- celixThread_setName(&handle->thread, thread_name);
- celixThreadRwlock_unlock(&handle->dbLock);
- free(thread_name);
- }
-}
-
-//
-// Setup thread priorities
-//
-void pubsub_tcpHandler_setThreadPriority(pubsub_tcpHandler_t *handle, long prio,
- const char *sched) {
- if (handle == NULL)
- return;
- // NOTE. Function will abort when performing a sched_setscheduler without
- // permission. As result permission has to be checked first.
- // TODO update this to use cap_get_pid and cap-get_flag instead of check user
- // is root (note adds dep to -lcap)
- bool gotPermission = false;
- if (getuid() == 0) {
- gotPermission = true;
- }
- if (sched != NULL) {
- int policy = SCHED_OTHER;
- if (strncmp("SCHED_OTHER", sched, 16) == 0) {
- policy = SCHED_OTHER;
-#if !defined(__APPLE__)
- } else if (strncmp("SCHED_BATCH", sched, 16) == 0) {
- policy = SCHED_BATCH;
- } else if (strncmp("SCHED_IDLE", sched, 16) == 0) {
- policy = SCHED_IDLE;
-#endif
- } else if (strncmp("SCHED_FIFO", sched, 16) == 0) {
- policy = SCHED_FIFO;
- } else if (strncmp("SCHED_RR", sched, 16) == 0) {
- policy = SCHED_RR;
- }
- if (gotPermission) {
- celixThreadRwlock_writeLock(&handle->dbLock);
- if (prio > 0 && prio < 100) {
- struct sched_param sch;
- bzero(&sch, sizeof(struct sched_param));
- sch.sched_priority = (int)prio;
- pthread_setschedparam(handle->thread.thread, policy, &sch);
- } else {
- L_INFO("Skipping configuration of thread prio to %i and thread "
- "scheduling to %s. No permission\n",
- (int) prio, sched);
- }
- celixThreadRwlock_unlock(&handle->dbLock);
- }
- }
-}
-
-void pubsub_tcpHandler_setSendRetryCnt(pubsub_tcpHandler_t *handle, unsigned int count) {
- if (handle != NULL) {
- celixThreadRwlock_writeLock(&handle->dbLock);
- handle->maxSendRetryCount = count;
- celixThreadRwlock_unlock(&handle->dbLock);
- }
-}
-
-void pubsub_tcpHandler_setReceiveRetryCnt(pubsub_tcpHandler_t *handle, unsigned int count) {
- if (handle != NULL) {
- celixThreadRwlock_writeLock(&handle->dbLock);
- handle->maxRcvRetryCount = count;
- celixThreadRwlock_unlock(&handle->dbLock);
- }
-}
-
-void pubsub_tcpHandler_setSendTimeOut(pubsub_tcpHandler_t *handle, double timeout) {
- if (handle != NULL) {
- celixThreadRwlock_writeLock(&handle->dbLock);
- handle->sendTimeout = timeout;
- celixThreadRwlock_unlock(&handle->dbLock);
- }
-}
-
-void pubsub_tcpHandler_setReceiveTimeOut(pubsub_tcpHandler_t *handle, double timeout) {
- if (handle != NULL) {
- celixThreadRwlock_writeLock(&handle->dbLock);
- handle->rcvTimeout = timeout;
- celixThreadRwlock_unlock(&handle->dbLock);
- }
-}
-
-void pubsub_tcpHandler_enableReceiveEvent(pubsub_tcpHandler_t *handle,bool enable) {
- if (handle != NULL) {
- celixThreadRwlock_writeLock(&handle->dbLock);
- handle->enableReceiveEvent = enable;
- celixThreadRwlock_unlock(&handle->dbLock);
- }
-}
-
-static inline long int pubsub_tcpHandler_getMsgSize(psa_tcp_connection_entry_t *entry) {
- // Note header message is already read
- return (long int)entry->header.header.payloadPartSize + (long int)entry->header.header.metadataSize + (long int)entry->readFooterSize;
-}
-
-static inline
-bool pubsub_tcpHandler_readHeader(pubsub_tcpHandler_t *handle, int fd, psa_tcp_connection_entry_t *entry, long int* msgSize) {
- bool result = false;
- size_t syncSize = 0;
- size_t protocolHeaderBufferSize = 0;
- // Get Sync Size
- handle->protocol->getSyncHeaderSize(handle->protocol->handle, &syncSize);
- // Get HeaderSize of the Protocol Header
- handle->protocol->getHeaderSize(handle->protocol->handle, &entry->readHeaderSize);
- // Get HeaderBufferSize of the Protocol Header, when headerBufferSize == 0, the protocol header is included in the payload (needed for endpoints)
- handle->protocol->getHeaderBufferSize(handle->protocol->handle, &protocolHeaderBufferSize);
-
- // Ensure capacity in header buffer
- pubsub_tcpHandler_ensureReadBufferCapacity(handle, entry);
-
- entry->readMsg.msg_iovlen = 0;
- entry->readMsg.msg_iov[entry->readMsg.msg_iovlen].iov_base = entry->readHeaderBuffer;
- entry->readMsg.msg_iov[entry->readMsg.msg_iovlen].iov_len = entry->readHeaderBufferSize;
- entry->readMsg.msg_iovlen++;
-
- // Read the message
- long int nbytes = 0;
- // Use peek flag to find sync word or when header is part of the payload
- unsigned int flag = (entry->headerError || (!protocolHeaderBufferSize)) ? MSG_PEEK : 0;
- if (entry->readHeaderSize) nbytes = recvmsg(fd, &(entry->readMsg), MSG_NOSIGNAL | MSG_WAITALL | flag);
- if (nbytes >= entry->readHeaderSize) {
- if (handle->protocol->decodeHeader(handle->protocol->handle,
- entry->readMsg.msg_iov[0].iov_base,
- entry->readMsg.msg_iov[0].iov_len,
- &entry->header) == CELIX_SUCCESS) {
- // read header from queue, when recovered from headerError and when header is not part of the payload. (Because of MSG_PEEK)
- if (entry->headerError && protocolHeaderBufferSize && entry->readHeaderSize) nbytes = recvmsg(fd, &(entry->readMsg), MSG_NOSIGNAL | MSG_WAITALL);
- entry->headerError = false;
- result = true;
- } else {
- // Did not receive correct header
- // skip sync word and try to read next header
- if (!entry->headerError) {
- L_WARN("[TCP Socket] Failed to decode message header (fd: %d) (url: %s)", entry->fd, entry->url);
- }
- entry->headerError = true;
- entry->readMsg.msg_iovlen = 0;
- entry->readMsg.msg_iov[entry->readMsg.msg_iovlen].iov_len = syncSize;
- entry->readMsg.msg_iovlen++;
- // remove sync item from the queue
- if (syncSize) nbytes = recvmsg(fd, &(entry->readMsg), MSG_NOSIGNAL | MSG_WAITALL);
- }
- }
- if (msgSize) *msgSize = nbytes;
- return result;
-}
-
-
-static inline void pubsub_tcpHandler_ensureReadBufferCapacity(pubsub_tcpHandler_t *handle, psa_tcp_connection_entry_t *entry) {
- if (entry->readHeaderSize > entry->readHeaderBufferSize) {
- free(entry->readHeaderBuffer);
- entry->readHeaderBuffer = malloc((size_t) entry->readHeaderSize);
- entry->readHeaderBufferSize = entry->readHeaderSize;
- }
-
- if (entry->header.header.payloadSize > entry->bufferSize) {
- free(entry->buffer);
- entry->buffer = malloc((size_t)entry->header.header.payloadSize);
- entry->bufferSize = entry->header.header.payloadSize;
- }
-
- if (entry->header.header.metadataSize > entry->readMetaBufferSize) {
- free(entry->readMetaBuffer);
- entry->readMetaBuffer = malloc((size_t) entry->header.header.metadataSize);
- entry->readMetaBufferSize = entry->header.header.metadataSize;
- }
-
- if (entry->readFooterSize > entry->readFooterBufferSize) {
- free(entry->readFooterBuffer);
- entry->readFooterBuffer = malloc( (size_t) entry->readFooterSize);
- entry->readFooterBufferSize = entry->readFooterSize;
- }
-}
-
-static inline
-void pubsub_tcpHandler_decodePayload(pubsub_tcpHandler_t *handle, psa_tcp_connection_entry_t *entry) {
-
- if (entry->header.header.payloadSize > 0) {
- handle->protocol->decodePayload(handle->protocol->handle, entry->buffer, entry->header.header.payloadSize, &entry->header);
- }
- if (entry->header.header.metadataSize > 0) {
- handle->protocol->decodeMetadata(handle->protocol->handle, entry->readMetaBuffer,
- entry->header.header.metadataSize, &entry->header);
- }
- if (handle->processMessageCallback && entry->header.payload.payload != NULL && entry->header.payload.length) {
- struct timespec receiveTime;
- clock_gettime(CLOCK_REALTIME, &receiveTime);
- bool releaseEntryBuffer = false;
- handle->processMessageCallback(handle->processMessagePayload, &entry->header, &releaseEntryBuffer, &receiveTime);
- if (releaseEntryBuffer) {
- pubsub_tcpHandler_releaseEntryBuffer(handle, entry->fd, 0);
- }
- }
- celix_properties_destroy(entry->header.metadata.metadata);
- entry->header.metadata.metadata = NULL;
-}
-
-static inline
-long int pubsub_tcpHandler_readPayload(pubsub_tcpHandler_t *handle, int fd, psa_tcp_connection_entry_t *entry) {
- entry->readMsg.msg_iovlen = 0;
- handle->protocol->getFooterSize(handle->protocol->handle, &entry->readFooterSize);
-
- // from the header can be determined how large buffers should be. Even before receiving all data these buffers can be allocated
- pubsub_tcpHandler_ensureReadBufferCapacity(handle, entry);
-
- if (entry->header.header.payloadPartSize) {
- char* buffer = entry->buffer;
- entry->readMsg.msg_iov[entry->readMsg.msg_iovlen].iov_base = &buffer[entry->header.header.payloadOffset];
- entry->readMsg.msg_iov[entry->readMsg.msg_iovlen].iov_len = entry->header.header.payloadPartSize;
- entry->readMsg.msg_iovlen++;
- }
- if (entry->header.header.metadataSize) {
- entry->readMsg.msg_iov[entry->readMsg.msg_iovlen].iov_base = entry->readMetaBuffer;
- entry->readMsg.msg_iov[entry->readMsg.msg_iovlen].iov_len = entry->header.header.metadataSize;
- entry->readMsg.msg_iovlen++;
- }
-
- if (entry->readFooterSize) {
- entry->readMsg.msg_iov[entry->readMsg.msg_iovlen].iov_base = entry->readFooterBuffer;
- entry->readMsg.msg_iov[entry->readMsg.msg_iovlen].iov_len = entry->readFooterSize;
- entry->readMsg.msg_iovlen++;
- }
-
- long int nbytes = recvmsg(fd, &(entry->readMsg), MSG_NOSIGNAL | MSG_WAITALL);
- if (nbytes >= pubsub_tcpHandler_getMsgSize(entry)) {
- bool valid = true;
- if (entry->readFooterSize) {
- if (handle->protocol->decodeFooter(handle->protocol->handle, entry->readFooterBuffer, entry->readFooterBufferSize, &entry->header) != CELIX_SUCCESS) {
- // Did not receive correct footer
- L_ERROR("[TCP Socket] Failed to decode message footer seq %d (received corrupt message, transmit buffer full?) (fd: %d) (url: %s)", entry->header.header.seqNr, entry->fd, entry->url);
- valid = false;
- }
- }
- if (!entry->header.header.isLastSegment) {
- // Not last Segment of message
- valid = false;
- }
-
- if (valid) {
- // Complete message is received
- pubsub_tcpHandler_decodePayload(handle, entry);
- }
- }
- return nbytes;
-}
-
-//
-// 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
-//
-int pubsub_tcpHandler_read(pubsub_tcpHandler_t *handle, int fd) {
- celixThreadRwlock_readLock(&handle->dbLock);
- psa_tcp_connection_entry_t *entry = hashMap_get(handle->interface_fd_map, (void *) (intptr_t) fd);
- if (entry == NULL) {
- entry = hashMap_get(handle->connection_fd_map, (void *) (intptr_t) fd);
- }
- // Find FD entry
- if (entry == NULL) {
- celixThreadRwlock_unlock(&handle->dbLock);
- return -1;
- }
- // If it's not connected return from function
- if (!__atomic_load_n(&entry->connected, __ATOMIC_ACQUIRE)) {
- celixThreadRwlock_unlock(&handle->dbLock);
- return -1;
- }
- long int nbytes = 0;
- // if not yet enough bytes are received the header can not be read
- if (pubsub_tcpHandler_readHeader(handle, fd, entry, &nbytes)) {
- nbytes = pubsub_tcpHandler_readPayload(handle, fd, entry);
- }
- if (nbytes > 0) {
- entry->retryCount = 0;
- } else if (nbytes < 0) {
- if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
- // Non blocking interrupt
- entry->retryCount = 0;
- } else if (entry->retryCount < handle->maxRcvRetryCount) {
- entry->retryCount++;
- L_WARN(
- "[TCP Socket] Failed to receive message (fd: %d), try again. error(%d): %s, Retry count %u of %u.",
- entry->fd, errno, strerror(errno), entry->retryCount, handle->maxSendRetryCount);
- } else {
- L_ERROR("[TCP Socket] Failed to receive message (fd: %d) after %u retries! Closing connection... Error: %s",
- entry->fd, handle->maxRcvRetryCount, strerror(errno));
- nbytes = 0; //Return 0 as indicator to close the connection
- }
- }
- celixThreadRwlock_unlock(&handle->dbLock);
- return (int)nbytes;
-}
-
-int pubsub_tcpHandler_addMessageHandler(pubsub_tcpHandler_t *handle, void *payload,
- pubsub_tcpHandler_processMessage_callback_t processMessageCallback) {
- int result = 0;
- celixThreadRwlock_writeLock(&handle->dbLock);
- handle->processMessageCallback = processMessageCallback;
- handle->processMessagePayload = payload;
- celixThreadRwlock_unlock(&handle->dbLock);
- return result;
-}
-
-int pubsub_tcpHandler_addReceiverConnectionCallback(pubsub_tcpHandler_t *handle, void *payload,
- pubsub_tcpHandler_receiverConnectMessage_callback_t connectMessageCallback,
- pubsub_tcpHandler_receiverConnectMessage_callback_t disconnectMessageCallback) {
- int result = 0;
- celixThreadRwlock_writeLock(&handle->dbLock);
- handle->receiverConnectMessageCallback = connectMessageCallback;
- handle->receiverDisconnectMessageCallback = disconnectMessageCallback;
- handle->receiverConnectPayload = payload;
- celixThreadRwlock_unlock(&handle->dbLock);
- return result;
-}
-
-//
-// Write large data to TCP. .
-//
-int pubsub_tcpHandler_write(pubsub_tcpHandler_t *handle, pubsub_protocol_message_t *message, struct iovec *msgIoVec,
- size_t msg_iov_len, int flags) {
- int result = 0;
- if (handle == NULL) {
- return -1;
- }
- int connFdCloseQueue[hashMap_size(handle->connection_fd_map)+1]; // +1 to ensure a size of 0 never occurs.
- int nofConnToClose = 0;
- if (handle) {
- celixThreadRwlock_readLock(&handle->dbLock);
- hash_map_iterator_t iter = hashMapIterator_construct(handle->connection_fd_map);
- size_t max_msg_iov_len = IOV_MAX - 2; // header , footer, padding
- while (hashMapIterator_hasNext(&iter)) {
- psa_tcp_connection_entry_t *entry = hashMapIterator_nextValue(&iter);
- if (!__atomic_load_n(&entry->connected, __ATOMIC_ACQUIRE)) {
- continue;
- }
- // When maxMsgSize is zero then payloadSize is disabled
- if (entry->maxMsgSize == 0) {
- // if max msg size is set to zero nothing will be send
- continue;
- }
- celixThreadMutex_lock(&entry->writeMutex);
- void *payloadData = NULL;
- size_t payloadSize = 0;
- if (msg_iov_len == 1) {
- handle->protocol->encodePayload(handle->protocol->handle, message, &payloadData, &payloadSize);
- } else {
- for (size_t i = 0; i < msg_iov_len; i++) {
- payloadSize += msgIoVec[i].iov_len;
- }
- }
-
- // check if message is not too large
- bool isMessageSegmentationSupported = false;
- handle->protocol->isMessageSegmentationSupported(handle->protocol->handle, &isMessageSegmentationSupported);
- if (!isMessageSegmentationSupported && (msg_iov_len > max_msg_iov_len || payloadSize > entry->maxMsgSize)) {
- L_WARN("[TCP Socket] Failed to send message (fd: %d), Message segmentation is not supported\n", entry->fd);
- celixThreadMutex_unlock(&entry->writeMutex);
- continue;
- }
-
- message->header.convertEndianess = 0;
- message->header.payloadSize = payloadSize;
- message->header.payloadPartSize = payloadSize;
- message->header.payloadOffset = 0;
- message->header.isLastSegment = 1;
-
- size_t metadataSize = 0;
- if (message->metadata.metadata) {
- handle->protocol->encodeMetadata(handle->protocol->handle, message, &entry->writeMetaBuffer, &entry->writeMetaBufferSize, &metadataSize);
- // When maxMsgSize is smaller then meta data is disabled
- if (metadataSize > entry->maxMsgSize) {
- metadataSize = 0;
- }
- }
-
- message->header.metadataSize = metadataSize;
- size_t totalMsgSize = payloadSize + metadataSize;
-
- size_t sendMsgSize = 0;
- size_t msgPayloadOffset = 0;
- size_t msgIovOffset = 0;
- bool allPayloadAdded = (payloadSize == 0);
- long int nbytes = LONG_MAX;
- while (sendMsgSize < totalMsgSize && nbytes > 0) {
- struct msghdr msg;
- struct iovec msg_iov[IOV_MAX];
- memset(&msg, 0x00, sizeof(struct msghdr));
- msg.msg_name = &entry->addr;
- msg.msg_namelen = entry->len;
- msg.msg_flags = flags;
- msg.msg_iov = msg_iov;
-
- size_t msgPartSize = 0;
- message->header.payloadPartSize = 0;
- message->header.payloadOffset = 0;
- message->header.metadataSize = 0;
- message->header.isLastSegment = 0;
-
- size_t protocolHeaderBufferSize = 0;
- // Get HeaderBufferSize of the Protocol Header, when headerBufferSize == 0, the protocol header is included in the payload (needed for endpoints)
- handle->protocol->getHeaderBufferSize(handle->protocol->handle, &protocolHeaderBufferSize);
- size_t footerSize = 0;
- // Get size of the Protocol Footer
- handle->protocol->getFooterSize(handle->protocol->handle, &footerSize);
- size_t maxMsgSize = entry->maxMsgSize - protocolHeaderBufferSize - footerSize;
-
- // reserve space for the header if required, header is added later when size of message is known (message can split in parts)
- if (protocolHeaderBufferSize) {
- msg.msg_iovlen++;
- }
- // Write generic seralized payload in vector buffer
- if (!allPayloadAdded) {
- if (payloadSize && payloadData && maxMsgSize) {
- char *buffer = payloadData;
- msg.msg_iov[msg.msg_iovlen].iov_base = &buffer[msgPayloadOffset];
- msg.msg_iov[msg.msg_iovlen].iov_len = MIN((payloadSize - msgPayloadOffset), maxMsgSize);
- msgPartSize += msg.msg_iov[msg.msg_iovlen].iov_len;
- msg.msg_iovlen++;
-
- } else {
- // copy serialized vector into vector buffer
- size_t i;
- for (i = msgIovOffset; i < MIN(msg_iov_len, msgIovOffset + max_msg_iov_len); i++) {
- if ((msgPartSize + msgIoVec[i].iov_len) > maxMsgSize) {
- break;
- }
- msg.msg_iov[msg.msg_iovlen].iov_base = msgIoVec[i].iov_base;
- msg.msg_iov[msg.msg_iovlen].iov_len = msgIoVec[i].iov_len;
- msgPartSize += msg.msg_iov[msg.msg_iovlen].iov_len;
- msg.msg_iovlen++;
- }
- // if no entry could be added
- if (i == msgIovOffset) {
- // TODO element can be split in parts?
- L_ERROR("[TCP Socket] vector io element is larger than max msg size");
- break;
- }
- msgIovOffset = i;
- }
- message->header.payloadPartSize = msgPartSize;
- message->header.payloadOffset = msgPayloadOffset;
- msgPayloadOffset += message->header.payloadPartSize;
- sendMsgSize = msgPayloadOffset;
- allPayloadAdded= msgPayloadOffset >= payloadSize;
- }
-
- // Write optional metadata in vector buffer
- if (allPayloadAdded &&
- (metadataSize != 0 && entry->writeMetaBuffer) &&
- (msgPartSize < maxMsgSize) &&
- (msg.msg_iovlen-1 < max_msg_iov_len)) { // header is already included
- msg.msg_iov[msg.msg_iovlen].iov_base = entry->writeMetaBuffer;
- msg.msg_iov[msg.msg_iovlen].iov_len = metadataSize;
- msg.msg_iovlen++;
- msgPartSize += metadataSize;
- message->header.metadataSize = metadataSize;
- sendMsgSize += metadataSize;
- }
- if (sendMsgSize >= totalMsgSize) {
- message->header.isLastSegment = 0x1;
- }
-
- void *headerData = NULL;
- size_t headerSize = 0;
- // Get HeaderSize of the Protocol Header
- handle->protocol->getHeaderSize(handle->protocol->handle, &headerSize);
-
- // check if header is not part of the payload (=> headerBufferSize = 0)
- if (protocolHeaderBufferSize) {
- headerData = entry->writeHeaderBuffer;
- // Encode the header, with payload size and metadata size
- handle->protocol->encodeHeader(handle->protocol->handle, message, &headerData, &headerSize);
- entry->writeHeaderBufferSize = MAX(headerSize, entry->writeHeaderBufferSize);
- if (headerData && entry->writeHeaderBuffer != headerData) {
- entry->writeHeaderBuffer = headerData;
- }
- if (headerSize && headerData) {
- // Write header in 1st vector buffer item
- msg.msg_iov[0].iov_base = headerData;
- msg.msg_iov[0].iov_len = headerSize;
- msgPartSize += msg.msg_iov[0].iov_len;
- } else {
- L_ERROR("[TCP Socket] No header buffer is generated");
- break;
- }
- }
-
- void *footerData = NULL;
- // Write optional footerData in vector buffer
- if (footerSize) {
- footerData = entry->writeFooterBuffer;
- handle->protocol->encodeFooter(handle->protocol->handle, message, &footerData, &footerSize);
- if (footerData && entry->writeFooterBuffer != footerData) {
- entry->writeFooterBuffer = footerData;
- entry->writeFooterBufferSize = footerSize;
- }
- if (footerData) {
- msg.msg_iov[msg.msg_iovlen].iov_base = footerData;
- msg.msg_iov[msg.msg_iovlen].iov_len = footerSize;
- msg.msg_iovlen++;
- msgPartSize += footerSize;
- }
- }
- nbytes = sendmsg(entry->fd, &msg, flags | MSG_NOSIGNAL);
-
- // When a specific socket keeps reporting errors can indicate a subscriber
- // which is not active anymore, the connection will remain until the retry
- // counter exceeds the maximum retry count.
- // Btw, also, SIGSTOP issued by a debugging tool can result in EINTR error.
- if (nbytes == -1) {
- if (entry->retryCount < handle->maxSendRetryCount) {
- entry->retryCount++;
- L_ERROR(
- "[TCP Socket] Failed to send message (fd: %d), try again. Retry count %u of %u, error(%d): %s.",
- entry->fd, entry->retryCount, handle->maxSendRetryCount, errno, strerror(errno));
- } else {
- L_ERROR(
- "[TCP Socket] Failed to send message (fd: %d) after %u retries! Closing connection... Error: %s", entry->fd, handle->maxSendRetryCount, strerror(errno));
- connFdCloseQueue[nofConnToClose++] = entry->fd;
- }
- result = -1; //At least one connection failed sending
- } else if (msgPartSize) {
- entry->retryCount = 0;
- if (nbytes != msgPartSize) {
- L_ERROR("[TCP Socket] seq: %d MsgSize not correct: %zu != %ld (%s)\n", message->header.seqNr, msgPartSize, nbytes, strerror(errno));
- }
- }
- // Note: serialized Payload is deleted by serializer
- if (payloadData && (payloadData != message->payload.payload)) {
- free(payloadData);
- }
- }
- celixThreadMutex_unlock(&entry->writeMutex);
- }
- celixThreadRwlock_unlock(&handle->dbLock);
- }
- //Force close all connections that are queued in a list, done outside of locking handle->dbLock to prevent deadlock
- for (int i = 0; i < nofConnToClose; i++) {
- pubsub_tcpHandler_close(handle, connFdCloseQueue[i]);
- }
- return result;
-}
-
-//
-// get interface URL
-//
-char *pubsub_tcpHandler_get_interface_url(pubsub_tcpHandler_t *handle) {
- hash_map_iterator_t iter =
- hashMapIterator_construct(handle->interface_url_map);
- char *url = NULL;
- while (hashMapIterator_hasNext(&iter)) {
- psa_tcp_connection_entry_t *entry =
- hashMapIterator_nextValue(&iter);
- if (entry && entry->url) {
- if (!url) {
- url = celix_utils_strdup(entry->url);
- } else {
- char *tmp = url;
- asprintf(&url, "%s %s", tmp, entry->url);
- free(tmp);
- }
- }
- }
- return url;
-}
-//
-// get interface URL
-//
-char *pubsub_tcpHandler_get_connection_url(pubsub_tcpHandler_t *handle) {
- celixThreadRwlock_writeLock(&handle->dbLock);
- hash_map_iterator_t iter =
- hashMapIterator_construct(handle->connection_url_map);
- char *url = NULL;
- while (hashMapIterator_hasNext(&iter)) {
- psa_tcp_connection_entry_t *entry =
- hashMapIterator_nextValue(&iter);
- if (entry && entry->url) {
- if (!url) {
- pubsub_utils_url_t *url_info = pubsub_utils_url_parse(entry->url);
- url = celix_utils_strdup(url_info->interface_url ? url_info->interface_url : entry->url);
- pubsub_utils_url_free(url_info);
- } else {
- char *tmp = url;
- pubsub_utils_url_t *url_info = pubsub_utils_url_parse(entry->url);
- asprintf(&url, "%s %s", tmp, url_info->interface_url ? url_info->interface_url : entry->url);
- pubsub_utils_url_free(url_info);
- free(tmp);
- }
- }
- }
- celixThreadRwlock_unlock(&handle->dbLock);
- return url;
-}
-
-//
-// Handle non-blocking accept (sender)
-//
-static inline
-int pubsub_tcpHandler_acceptHandler(pubsub_tcpHandler_t *handle, psa_tcp_connection_entry_t *pendingConnectionEntry) {
- celixThreadRwlock_writeLock(&handle->dbLock);
- // new connection available
- struct sockaddr_in their_addr;
- socklen_t len = sizeof(struct sockaddr_in);
- int fd = accept(pendingConnectionEntry->fd, (struct sockaddr*)&their_addr, &len);
- int rc = fd;
- if (rc == -1) {
- L_ERROR("[TCP Socket] accept failed: %s\n", strerror(errno));
- }
- if (rc >= 0) {
- // handle new connection:
- struct sockaddr_in sin;
- getsockname(pendingConnectionEntry->fd, (struct sockaddr *) &sin, &len);
- char *interface_url = pubsub_utils_url_get_url(&sin, NULL);
- char *url = pubsub_utils_url_get_url(&their_addr, NULL);
- psa_tcp_connection_entry_t *entry = pubsub_tcpHandler_createEntry(handle, fd, url, interface_url, &their_addr);
-#if defined(__APPLE__)
- struct kevent ev;
- EV_SET (&ev, entry->fd, EVFILT_READ, EV_ADD | EV_ENABLE , 0, 0, 0);
- rc = kevent (handle->efd, &ev, 1, NULL, 0, NULL);
-#else
- struct epoll_event event;
- bzero(&event, sizeof(event)); // zero the struct
- event.events = EPOLLRDHUP | EPOLLERR;
- if (handle->enableReceiveEvent) event.events |= EPOLLIN;
- event.data.fd = entry->fd;
- // Register Read to epoll
- rc = epoll_ctl(handle->efd, EPOLL_CTL_ADD, entry->fd, &event);
-#endif
- if (rc < 0) {
- pubsub_tcpHandler_freeEntry(entry);
- L_ERROR("[TCP Socket] Cannot create epoll\n");
- } else {
- // Call Accept Connection callback
- if (handle->acceptConnectMessageCallback)
- handle->acceptConnectMessageCallback(handle->acceptConnectPayload, url);
- hashMap_put(handle->connection_fd_map, (void *) (intptr_t) entry->fd, entry);
- hashMap_put(handle->connection_url_map, entry->url, entry);
- L_INFO("[TCP Socket] New connection to url: %s: \n", url);
- }
- free(url);
- free(interface_url);
- }
- celixThreadRwlock_unlock(&handle->dbLock);
- return fd;
-}
-
-//
-// Handle sockets connection (sender)
-//
-static inline
-void pubsub_tcpHandler_connectionHandler(pubsub_tcpHandler_t *handle, int fd) {
- celixThreadRwlock_readLock(&handle->dbLock);
- psa_tcp_connection_entry_t *entry = hashMap_get(handle->connection_fd_map, (void *) (intptr_t) fd);
- if (entry)
- if (!__atomic_exchange_n(&entry->connected, true, __ATOMIC_ACQ_REL)) {
- // tell sender that an receiver is connected
- if (handle->receiverConnectMessageCallback)
- handle->receiverConnectMessageCallback(handle->receiverConnectPayload, entry->url, false);
- }
- celixThreadRwlock_unlock(&handle->dbLock);
-}
-
-#if defined(__APPLE__)
-//
-// The main socket event loop
-//
-static inline
-void pubsub_tcpHandler_handler(pubsub_tcpHandler_t *handle) {
- int rc = 0;
- if (handle->efd >= 0) {
- int nof_events = 0;
- // Wait for events.
- struct kevent events[MAX_EVENTS];
- struct timespec ts = {handle->timeout / 1000, (handle->timeout % 1000) * 1000000};
- nof_events = kevent (handle->efd, NULL, 0, &events[0], MAX_EVENTS, handle->timeout ? &ts : NULL);
- if (nof_events < 0) {
- if ((errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)) {
- } else
- L_ERROR("[TCP Socket] Cannot create poll wait (%d) %s\n", nof_events, strerror(errno));
- }
- for (int i = 0; i < nof_events; i++) {
- hash_map_iterator_t iter = hashMapIterator_construct(handle->interface_fd_map);
- psa_tcp_connection_entry_t *pendingConnectionEntry = NULL;
- while (hashMapIterator_hasNext(&iter)) {
- psa_tcp_connection_entry_t *entry = hashMapIterator_nextValue(&iter);
- if (events[i].ident == entry->fd)
- pendingConnectionEntry = entry;
- }
- if (pendingConnectionEntry) {
- int fd = pubsub_tcpHandler_acceptHandler(handle, pendingConnectionEntry);
- pubsub_tcpHandler_connectionHandler(handle, fd);
- } else if (events[i].filter & EVFILT_READ) {
- int rc = pubsub_tcpHandler_read(handle, events[i].ident);
- if (rc == 0) pubsub_tcpHandler_close(handle, events[i].ident);
- } else if (events[i].flags & EV_EOF) {
- int err = 0;
- socklen_t len = sizeof(int);
- rc = getsockopt(events[i].ident, SOL_SOCKET, SO_ERROR, &err, &len);
- if (rc != 0) {
- L_ERROR("[TCP Socket]:EPOLLRDHUP ERROR read from socket %s\n", strerror(errno));
- continue;
- }
- pubsub_tcpHandler_close(handle, events[i].ident);
- } else if (events[i].flags & EV_ERROR) {
- L_ERROR("[TCP Socket]:EPOLLERR ERROR read from socket %s\n", strerror(errno));
- pubsub_tcpHandler_close(handle, events[i].ident);
- continue;
- }
- }
- }
- return;
-}
-
-#else
-
-//
-// The main socket event loop
-//
-static inline
-void pubsub_tcpHandler_handler(pubsub_tcpHandler_t *handle) {
- int rc = 0;
- if (handle->efd >= 0) {
- int nof_events = 0;
- struct epoll_event events[MAX_EVENTS];
- nof_events = epoll_wait(handle->efd, events, MAX_EVENTS, (int)handle->timeout);
- if (nof_events < 0) {
- if ((errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)) {
- } else
- L_ERROR("[TCP Socket] Cannot create epoll wait (%d) %s\n", nof_events, strerror(errno));
- }
- for (int i = 0; i < nof_events; i++) {
- hash_map_iterator_t iter = hashMapIterator_construct(handle->interface_fd_map);
- psa_tcp_connection_entry_t *pendingConnectionEntry = NULL;
- while (hashMapIterator_hasNext(&iter)) {
- psa_tcp_connection_entry_t *entry = hashMapIterator_nextValue(&iter);
- if (events[i].data.fd == entry->fd)
- pendingConnectionEntry = entry;
- }
- if (pendingConnectionEntry) {
- int fd = pubsub_tcpHandler_acceptHandler(handle, pendingConnectionEntry);
- pubsub_tcpHandler_connectionHandler(handle, fd);
- } else if (events[i].events & EPOLLIN) {
- rc = pubsub_tcpHandler_read(handle, events[i].data.fd);
- if (rc == 0) pubsub_tcpHandler_close(handle, events[i].data.fd);
- } else if (events[i].events & EPOLLRDHUP) {
- int err = 0;
- socklen_t len = sizeof(int);
- rc = getsockopt(events[i].data.fd, SOL_SOCKET, SO_ERROR, &err, &len);
- if (rc != 0) {
- L_ERROR("[TCP Socket]:EPOLLRDHUP ERROR read from socket %s\n", strerror(errno));
- continue;
- }
- pubsub_tcpHandler_close(handle, events[i].data.fd);
- } else if (events[i].events & EPOLLERR) {
- L_ERROR("[TCP Socket]:EPOLLERR ERROR read from socket %s\n", strerror(errno));
- pubsub_tcpHandler_close(handle, events[i].data.fd);
- continue;
- }
- }
- }
-}
-#endif
-
-//
-// The socket thread
-//
-static void *pubsub_tcpHandler_thread(void *data) {
- pubsub_tcpHandler_t *handle = data;
- celixThreadRwlock_readLock(&handle->dbLock);
- bool running = handle->running;
- celixThreadRwlock_unlock(&handle->dbLock);
-
- while (running) {
- pubsub_tcpHandler_handler(handle);
- celixThreadRwlock_readLock(&handle->dbLock);
- running = handle->running;
- celixThreadRwlock_unlock(&handle->dbLock);
- } // while
- return NULL;
-}
diff --git a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_handler.h b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_handler.h
deleted file mode 100644
index 2d97634e..00000000
--- a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_handler.h
+++ /dev/null
@@ -1,92 +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.
- */
-/*
- * pubsub_tcp_handler.h
- *
- * \date July 18, 2016
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#ifndef _PUBSUB_TCP_BUFFER_HANDLER_H_
-#define _PUBSUB_TCP_BUFFER_HANDLER_H_
-
-#include <stdbool.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <celix_log_helper.h>
-#include "celix_threads.h"
-#include "pubsub_utils_url.h"
-#include <pubsub_protocol.h>
-
-#ifndef MIN
-#define MIN(a, b) ((a<b) ? (a) : (b))
-#endif
-
-#ifndef MAX
-#define MAX(a, b) ((a>b) ? (a) : (b))
-#endif
-
-typedef struct pubsub_tcpHandler pubsub_tcpHandler_t;
-typedef void(*pubsub_tcpHandler_processMessage_callback_t)
- (void *payload, const pubsub_protocol_message_t *header, bool *release, struct timespec *receiveTime);
-typedef void (*pubsub_tcpHandler_receiverConnectMessage_callback_t)(void *payload, const char *url, bool lock);
-typedef void (*pubsub_tcpHandler_acceptConnectMessage_callback_t)(void *payload, const char *url);
-
-pubsub_tcpHandler_t *pubsub_tcpHandler_create(pubsub_protocol_service_t *protocol, celix_log_helper_t *logHelper);
-void pubsub_tcpHandler_destroy(pubsub_tcpHandler_t *handle);
-int pubsub_tcpHandler_open(pubsub_tcpHandler_t *handle, char *url);
-int pubsub_tcpHandler_close(pubsub_tcpHandler_t *handle, int fd);
-int pubsub_tcpHandler_connect(pubsub_tcpHandler_t *handle, char *url);
-int pubsub_tcpHandler_disconnect(pubsub_tcpHandler_t *handle, char *url);
-int pubsub_tcpHandler_listen(pubsub_tcpHandler_t *handle, char *url);
-int pubsub_tcpHandler_setReceiveBufferSize(pubsub_tcpHandler_t *handle, unsigned int size);
-int pubsub_tcpHandler_setMaxMsgSize(pubsub_tcpHandler_t *handle, unsigned int size);
-void pubsub_tcpHandler_setTimeout(pubsub_tcpHandler_t *handle, unsigned int timeout);
-void pubsub_tcpHandler_setSendRetryCnt(pubsub_tcpHandler_t *handle, unsigned int count);
-void pubsub_tcpHandler_setReceiveRetryCnt(pubsub_tcpHandler_t *handle, unsigned int count);
-void pubsub_tcpHandler_setSendTimeOut(pubsub_tcpHandler_t *handle, double timeout);
-void pubsub_tcpHandler_setReceiveTimeOut(pubsub_tcpHandler_t *handle, double timeout);
-void pubsub_tcpHandler_enableReceiveEvent(pubsub_tcpHandler_t *handle, bool enable);
-
-int pubsub_tcpHandler_read(pubsub_tcpHandler_t *handle, int fd);
-int pubsub_tcpHandler_write(pubsub_tcpHandler_t *handle,
- pubsub_protocol_message_t *message,
- struct iovec *msg_iovec,
- size_t msg_iov_len,
- int flags);
-int pubsub_tcpHandler_addMessageHandler(pubsub_tcpHandler_t *handle,
- void *payload,
- pubsub_tcpHandler_processMessage_callback_t processMessageCallback);
-int pubsub_tcpHandler_addReceiverConnectionCallback(pubsub_tcpHandler_t *handle,
- void *payload,
- pubsub_tcpHandler_receiverConnectMessage_callback_t connectMessageCallback,
- pubsub_tcpHandler_receiverConnectMessage_callback_t disconnectMessageCallback);
-int pubsub_tcpHandler_addAcceptConnectionCallback(pubsub_tcpHandler_t *handle,
- void *payload,
- pubsub_tcpHandler_acceptConnectMessage_callback_t connectMessageCallback,
- pubsub_tcpHandler_acceptConnectMessage_callback_t disconnectMessageCallback);
-char *pubsub_tcpHandler_get_interface_url(pubsub_tcpHandler_t *handle);
-char *pubsub_tcpHandler_get_connection_url(pubsub_tcpHandler_t *handle);
-void pubsub_tcpHandler_setThreadPriority(pubsub_tcpHandler_t *handle, long prio, const char *sched);
-void pubsub_tcpHandler_setThreadName(pubsub_tcpHandler_t *handle, const char *topic, const char *scope);
-
-#endif /* _PUBSUB_TCP_BUFFER_HANDLER_H_ */
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
deleted file mode 100644
index b533b8ae..00000000
--- a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_topic_receiver.c
+++ /dev/null
@@ -1,674 +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 <stdlib.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <pubsub/subscriber.h>
-#include <memory.h>
-#include <arpa/inet.h>
-#include <celix_log_helper.h>
-#include "pubsub_tcp_handler.h"
-#include "pubsub_tcp_topic_receiver.h"
-#include "pubsub_psa_tcp_constants.h"
-#include "pubsub_tcp_common.h"
-#include "pubsub_tcp_admin.h"
-
-#include <uuid/uuid.h>
-#include <pubsub_utils.h>
-#include "pubsub_interceptors_handler.h"
-#include <celix_api.h>
-#include "celix_compiler.h"
-#include "celix_string_hash_map.h"
-#include "celix_long_hash_map.h"
-
-#ifndef UUID_STR_LEN
-#define UUID_STR_LEN 37
-#endif
-
-#define L_TRACE(...) \
- celix_logHelper_log(receiver->logHelper, CELIX_LOG_LEVEL_TRACE, __VA_ARGS__)
-#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_tcp_topic_receiver {
- celix_bundle_context_t *ctx;
- celix_log_helper_t *logHelper;
- long protocolSvcId;
- pubsub_protocol_service_t *protocol;
- char *scope;
- char *topic;
- pubsub_serializer_handler_t* serializerHandler;
- void *admin;
- size_t timeout;
- bool isPassive;
- pubsub_tcpHandler_t *socketHandler;
- pubsub_tcpHandler_t *sharedSocketHandler;
- pubsub_interceptors_handler_t *interceptorsHandler;
-
- struct {
- celix_thread_t thread;
- celix_thread_mutex_t mutex;
- bool running;
- } thread;
-
- struct {
- celix_thread_mutex_t mutex;
- celix_string_hash_map_t *map; //key = tcp url, value = psa_tcp_requested_connection_entry_t*
- bool allConnected; //true if all requestedConnection are connected
- } requestedConnections;
-
- long subscriberTrackerId;
- struct {
- celix_thread_mutex_t mutex;
- celix_long_hash_map_t *map; //key = long svc id, value = psa_tcp_subscriber_entry_t
- bool allInitialized;
- } subscribers;
-};
-
-typedef struct psa_tcp_requested_connection_entry {
- pubsub_tcp_topic_receiver_t *parent;
- char *url;
- bool connected;
- bool statically; //true if the connection is statically configured through the topic properties.
-} psa_tcp_requested_connection_entry_t;
-
-typedef struct psa_tcp_subscriber_entry {
- pubsub_subscriber_t* subscriberSvc;
- bool initialized; //true if the init function is called through the receive thread
-} psa_tcp_subscriber_entry_t;
-
-static void pubsub_tcpTopicReceiver_addSubscriber(void *handle, void *svc, const celix_properties_t *props);
-static void pubsub_tcpTopicReceiver_removeSubscriber(void *handle, void *svc, const celix_properties_t *props);
-static void *psa_tcp_recvThread(void *data);
-static void psa_tcp_connectToAllRequestedConnections(pubsub_tcp_topic_receiver_t *receiver);
-static void psa_tcp_initializeAllSubscribers(pubsub_tcp_topic_receiver_t *receiver);
-static void processMsg(void *handle, const pubsub_protocol_message_t *message, bool *release, struct timespec *receiveTime);
-static void psa_tcp_connectHandler(void *handle, const char *url, bool lock);
-static void psa_tcp_disConnectHandler(void *handle, const char *url, bool lock);
-
-pubsub_tcp_topic_receiver_t *pubsub_tcpTopicReceiver_create(celix_bundle_context_t *ctx,
- celix_log_helper_t *logHelper,
- const char *scope,
- const char *topic,
- pubsub_serializer_handler_t* serializerHandler,
- void *admin,
- const celix_properties_t *topicProperties,
- pubsub_tcp_endPointStore_t *handlerStore,
- long protocolSvcId,
- pubsub_protocol_service_t *protocol) {
- pubsub_tcp_topic_receiver_t *receiver = calloc(1, sizeof(*receiver));
- receiver->ctx = ctx;
- receiver->logHelper = logHelper;
- receiver->serializerHandler = serializerHandler;
- receiver->admin = admin;
- receiver->protocolSvcId = protocolSvcId;
- receiver->protocol = protocol;
- receiver->scope = celix_utils_strdup(scope);
- receiver->topic = celix_utils_strdup(topic);
- receiver->interceptorsHandler = pubsubInterceptorsHandler_create(ctx, scope, topic, PUBSUB_TCP_ADMIN_TYPE,
- pubsub_serializerHandler_getSerializationType(serializerHandler));
- const char *staticConnectUrls = pubsub_getEnvironmentVariableWithScopeTopic(ctx, PUBSUB_TCP_STATIC_CONNECT_URLS_FOR, topic, scope);
- const char *isPassive = pubsub_getEnvironmentVariableWithScopeTopic(ctx, PUBSUB_TCP_PASSIVE_ENABLED, topic, scope);
- const char *passiveKey = pubsub_getEnvironmentVariableWithScopeTopic(ctx, PUBSUB_TCP_PASSIVE_SELECTION_KEY, topic, scope);
-
- if (isPassive) {
- receiver->isPassive = psa_tcp_isPassive(isPassive);
- }
- if (topicProperties != NULL) {
- if(staticConnectUrls == NULL) {
- staticConnectUrls = celix_properties_get(topicProperties, PUBSUB_TCP_STATIC_CONNECT_URLS, NULL);
- }
- if (isPassive == NULL) {
- receiver->isPassive = celix_properties_getAsBool(topicProperties, PUBSUB_TCP_PASSIVE_CONFIGURED, false);
- }
- if (passiveKey == NULL) {
- passiveKey = celix_properties_get(topicProperties, PUBSUB_TCP_PASSIVE_KEY, NULL);
- }
- }
-
- // Set receiver connection thread timeout.
- // property is in ms, timeout value in us. (convert ms to us).
- receiver->timeout = celix_bundleContext_getPropertyAsLong(ctx, PSA_TCP_SUBSCRIBER_CONNECTION_TIMEOUT,
- PSA_TCP_SUBSCRIBER_CONNECTION_DEFAULT_TIMEOUT) * 1000;
-
- celixThreadMutex_create(&receiver->thread.mutex, NULL);
-
- //receiver->socketHandler depend on belows, we should initialize them first.
- celixThreadMutex_create(&receiver->requestedConnections.mutex, NULL);
- celixThreadMutex_create(&receiver->subscribers.mutex, NULL);
- celix_string_hash_map_create_options_t reqConsMapOpts = CELIX_EMPTY_STRING_HASH_MAP_CREATE_OPTIONS;
- reqConsMapOpts.storeKeysWeakly = true;
- receiver->requestedConnections.map = celix_stringHashMap_createWithOptions(&reqConsMapOpts);
- receiver->subscribers.map = celix_longHashMap_create();
-
- /* When it's an endpoint share the socket with the sender */
- if (passiveKey != NULL) {
- celixThreadMutex_lock(&handlerStore->mutex);
- pubsub_tcpHandler_t *entry = hashMap_get(handlerStore->map, passiveKey);
- if (entry == NULL) {
- if (receiver->socketHandler == NULL)
- receiver->socketHandler = pubsub_tcpHandler_create(receiver->protocol, receiver->logHelper);
- entry = receiver->socketHandler;
- receiver->sharedSocketHandler = receiver->socketHandler;
- hashMap_put(handlerStore->map, (void *) passiveKey, entry);
- } else {
- receiver->socketHandler = entry;
- receiver->sharedSocketHandler = entry;
- }
- celixThreadMutex_unlock(&handlerStore->mutex);
- } else {
- receiver->socketHandler = pubsub_tcpHandler_create(receiver->protocol, receiver->logHelper);
- }
-
- if (receiver->socketHandler != NULL) {
- long prio = celix_properties_getAsLong(topicProperties, PUBSUB_TCP_THREAD_REALTIME_PRIO, -1L);
- const char *sched = celix_properties_get(topicProperties, PUBSUB_TCP_THREAD_REALTIME_SCHED, NULL);
- long retryCnt = celix_properties_getAsLong(topicProperties, PUBSUB_TCP_SUBSCRIBER_RETRY_CNT_KEY,
- PUBSUB_TCP_SUBSCRIBER_RETRY_CNT_DEFAULT);
- double rcvTimeout = celix_properties_getAsDouble(topicProperties, PUBSUB_TCP_SUBSCRIBER_RCVTIMEO_KEY, PUBSUB_TCP_SUBSCRIBER_RCVTIMEO_DEFAULT);
- long bufferSize = celix_bundleContext_getPropertyAsLong(ctx, PSA_TCP_RECV_BUFFER_SIZE,
- PSA_TCP_DEFAULT_RECV_BUFFER_SIZE);
- long timeout = celix_bundleContext_getPropertyAsLong(ctx, PSA_TCP_TIMEOUT, PSA_TCP_DEFAULT_TIMEOUT);
-
- pubsub_tcpHandler_setThreadName(receiver->socketHandler, topic, scope);
- pubsub_tcpHandler_setReceiveBufferSize(receiver->socketHandler, (unsigned int) bufferSize);
- pubsub_tcpHandler_setTimeout(receiver->socketHandler, (unsigned int) timeout);
- pubsub_tcpHandler_addMessageHandler(receiver->socketHandler, receiver, processMsg);
- pubsub_tcpHandler_addReceiverConnectionCallback(receiver->socketHandler, receiver, psa_tcp_connectHandler,
- psa_tcp_disConnectHandler);
- pubsub_tcpHandler_setThreadPriority(receiver->socketHandler, prio, sched);
- pubsub_tcpHandler_setReceiveRetryCnt(receiver->socketHandler, (unsigned int) retryCnt);
- pubsub_tcpHandler_setReceiveTimeOut(receiver->socketHandler, rcvTimeout);
- }
-
- if ((staticConnectUrls != NULL) && (receiver->socketHandler != NULL) && (!receiver->isPassive)) {
- char *urlsCopy = celix_utils_strdup(staticConnectUrls);
- char *url;
- char *save = urlsCopy;
- while ((url = strtok_r(save, " ", &save))) {
- psa_tcp_requested_connection_entry_t *entry = calloc(1, sizeof(*entry));
- entry->statically = true;
- entry->connected = false;
- entry->url = celix_utils_strdup(url);
- entry->parent = receiver;
- celix_stringHashMap_put(receiver->requestedConnections.map, entry->url, entry);
- receiver->requestedConnections.allConnected = false;
- }
- free(urlsCopy);
- }
-
- if (receiver->socketHandler != NULL && (!receiver->isPassive)) {
- // Configure Receiver thread
- receiver->thread.running = true;
- celixThread_create(&receiver->thread.thread, NULL, psa_tcp_recvThread, receiver);
- char name[64];
- snprintf(name, 64, "TCP TR %s/%s", scope == NULL ? "(null)" : scope, topic);
- celixThread_setName(&receiver->thread.thread, name);
- }
-
- //track subscribers
- if (receiver->socketHandler != NULL) {
- 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.serviceName = PUBSUB_SUBSCRIBER_SERVICE_NAME;
- opts.filter.filter = buf;
- opts.callbackHandle = receiver;
- opts.addWithProperties = pubsub_tcpTopicReceiver_addSubscriber;
- opts.removeWithProperties = pubsub_tcpTopicReceiver_removeSubscriber;
- receiver->subscriberTrackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts);
- }
-
- if (receiver->socketHandler == NULL) {
- celix_longHashMap_destroy(receiver->subscribers.map);
- celix_stringHashMap_destroy(receiver->requestedConnections.map);
- celixThreadMutex_destroy(&receiver->subscribers.mutex);
- celixThreadMutex_destroy(&receiver->requestedConnections.mutex);
- celixThreadMutex_destroy(&receiver->thread.mutex);
- pubsubInterceptorsHandler_destroy(receiver->interceptorsHandler);
- if (receiver->scope != NULL) {
- free(receiver->scope);
- }
- free(receiver->topic);
- free(receiver);
- receiver = NULL;
- L_ERROR("[PSA_TCP] Cannot create TopicReceiver for %s/%s", scope == NULL ? "(null)" : scope, topic);
- }
- return receiver;
-}
-
-void pubsub_tcpTopicReceiver_destroy(pubsub_tcp_topic_receiver_t *receiver) {
- if (receiver != NULL) {
-
- celix_bundleContext_stopTracker(receiver->ctx, receiver->subscriberTrackerId);
-
- celixThreadMutex_lock(&receiver->thread.mutex);
- if (receiver->thread.running) {
- receiver->thread.running = false;
- celixThreadMutex_unlock(&receiver->thread.mutex);
- celixThread_join(receiver->thread.thread, NULL);
- }
-
- pubsub_tcpHandler_addMessageHandler(receiver->socketHandler, NULL, NULL);
- pubsub_tcpHandler_addReceiverConnectionCallback(receiver->socketHandler, NULL, NULL, NULL);
- if ((receiver->socketHandler) && (receiver->sharedSocketHandler == NULL)) {
- pubsub_tcpHandler_destroy(receiver->socketHandler);
- receiver->socketHandler = NULL;
- }
-
- celixThreadMutex_lock(&receiver->subscribers.mutex);
- CELIX_LONG_HASH_MAP_ITERATE(receiver->subscribers.map, iter) {
- free(iter.value.ptrValue);
- }
- celix_longHashMap_destroy(receiver->subscribers.map);
- celixThreadMutex_unlock(&receiver->subscribers.mutex);
-
- celixThreadMutex_lock(&receiver->requestedConnections.mutex);
-
- CELIX_STRING_HASH_MAP_ITERATE(receiver->requestedConnections.map, iter) {
- psa_tcp_requested_connection_entry_t *entry = iter.value.ptrValue;
- if (entry != NULL) {
- free(entry->url);
- free(entry);
- }
- }
- celix_stringHashMap_destroy(receiver->requestedConnections.map);
- celixThreadMutex_unlock(&receiver->requestedConnections.mutex);
-
- celixThreadMutex_destroy(&receiver->subscribers.mutex);
- celixThreadMutex_destroy(&receiver->requestedConnections.mutex);
- celixThreadMutex_destroy(&receiver->thread.mutex);
-
- pubsubInterceptorsHandler_destroy(receiver->interceptorsHandler);
- if (receiver->scope != NULL) {
- free(receiver->scope);
- }
- free(receiver->topic);
- }
- free(receiver);
-}
-
-const char *pubsub_tcpTopicReceiver_scope(pubsub_tcp_topic_receiver_t *receiver) {
- return receiver->scope;
-}
-
-const char *pubsub_tcpTopicReceiver_topic(pubsub_tcp_topic_receiver_t *receiver) {
- return receiver->topic;
-}
-
-const char *pubsub_tcpTopicReceiver_serializerType(pubsub_tcp_topic_receiver_t *receiver) {
- return pubsub_serializerHandler_getSerializationType(receiver->serializerHandler);
-}
-
-long pubsub_tcpTopicReceiver_protocolSvcId(pubsub_tcp_topic_receiver_t *receiver) {
- return receiver->protocolSvcId;
-}
-
-void pubsub_tcpTopicReceiver_listConnections(pubsub_tcp_topic_receiver_t *receiver, celix_array_list_t *connectedUrls,
- celix_array_list_t *unconnectedUrls) {
- celixThreadMutex_lock(&receiver->requestedConnections.mutex);
- if (receiver->isPassive) {
- char* interface_url = pubsub_tcpHandler_get_interface_url(receiver->socketHandler);
- char *url = NULL;
- asprintf(&url, "%s (passive)", interface_url ? interface_url : "");
- if (interface_url) {
- celix_arrayList_add(connectedUrls, url);
- } else {
- celix_arrayList_add(unconnectedUrls, url);
- }
- free(interface_url);
- } else {
- CELIX_STRING_HASH_MAP_ITERATE(receiver->requestedConnections.map, iter) {
- psa_tcp_requested_connection_entry_t *entry = iter.value.ptrValue;
- char *url = NULL;
- asprintf(&url, "%s%s", entry->url, entry->statically ? " (static)" : "");
- if (entry->connected) {
- celix_arrayList_add(connectedUrls, url);
- } else {
- celix_arrayList_add(unconnectedUrls, url);
- }
- }
- }
- celixThreadMutex_unlock(&receiver->requestedConnections.mutex);
-}
-
-bool pubsub_tcpTopicReceiver_isPassive(pubsub_tcp_topic_receiver_t *receiver) {
- return receiver->isPassive;
-}
-
-void pubsub_tcpTopicReceiver_connectTo(
- pubsub_tcp_topic_receiver_t *receiver,
- const char *url) {
- L_DEBUG("[PSA_TCP] TopicReceiver %s/%s connecting to tcp url %s",
- receiver->scope == NULL ? "(null)" : receiver->scope,
- receiver->topic,
- url);
-
- celixThreadMutex_lock(&receiver->requestedConnections.mutex);
- psa_tcp_requested_connection_entry_t *entry = celix_stringHashMap_get(receiver->requestedConnections.map, url);
- if (entry == NULL) {
- entry = calloc(1, sizeof(*entry));
- entry->url = celix_utils_strdup(url);
- entry->connected = false;
- entry->statically = false;
- entry->parent = receiver;
- celix_stringHashMap_put(receiver->requestedConnections.map, (void *) entry->url, entry);
- receiver->requestedConnections.allConnected = false;
- }
- celixThreadMutex_unlock(&receiver->requestedConnections.mutex);
-
- psa_tcp_connectToAllRequestedConnections(receiver);
-}
-
-void pubsub_tcpTopicReceiver_disconnectFrom(pubsub_tcp_topic_receiver_t *receiver, const char *url) {
- L_DEBUG("[PSA TCP] TopicReceiver %s/%s disconnect from tcp url %s",
- receiver->scope == NULL ? "(null)" : receiver->scope,
- receiver->topic,
- url);
-
- celixThreadMutex_lock(&receiver->requestedConnections.mutex);
- psa_tcp_requested_connection_entry_t *entry = celix_stringHashMap_get(receiver->requestedConnections.map, url);
- if (entry != NULL) {
- int rc = pubsub_tcpHandler_disconnect(receiver->socketHandler, entry->url);
- if (rc < 0)
- L_WARN("[PSA_TCP] Error disconnecting from tcp url %s. (%s)", url, strerror(errno));
- }
- if (entry != NULL) {
- celix_stringHashMap_remove(receiver->requestedConnections.map, url);
- free(entry->url);
- free(entry);
- }
- celixThreadMutex_unlock(&receiver->requestedConnections.mutex);
-}
-
-static void pubsub_tcpTopicReceiver_addSubscriber(void *handle, void *svc, const celix_properties_t *props) {
- pubsub_tcp_topic_receiver_t *receiver = handle;
-
- long svcId = celix_properties_getAsLong(props, CELIX_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;
- }
-
- psa_tcp_subscriber_entry_t *entry = calloc(1, sizeof(*entry));
- entry->subscriberSvc = svc;
- entry->initialized = false;
-
- celixThreadMutex_lock(&receiver->subscribers.mutex);
- celix_longHashMap_put(receiver->subscribers.map, svcId, entry);
- receiver->subscribers.allInitialized = false;
- celixThreadMutex_unlock(&receiver->subscribers.mutex);
-}
-
-static void pubsub_tcpTopicReceiver_removeSubscriber(void *handle, void *svc CELIX_UNUSED, const celix_properties_t *props) {
- pubsub_tcp_topic_receiver_t *receiver = handle;
-
- long svcId = celix_properties_getAsLong(props, CELIX_FRAMEWORK_SERVICE_ID, -1);
-
- celixThreadMutex_lock(&receiver->subscribers.mutex);
- psa_tcp_subscriber_entry_t *entry = celix_longHashMap_get(receiver->subscribers.map, svcId);
- celix_longHashMap_remove(receiver->subscribers.map, svcId);
- free(entry);
- celixThreadMutex_unlock(&receiver->subscribers.mutex);
-}
-
-static void callReceivers(pubsub_tcp_topic_receiver_t *receiver, const char* msgFqn, const pubsub_protocol_message_t *message, void** msg, bool* release, const celix_properties_t* metadata) {
- *release = true;
- celixThreadMutex_lock(&receiver->subscribers.mutex);
- celix_long_hash_map_iterator_t iter = celix_longHashMap_begin(receiver->subscribers.map);
- while(!celix_longHashMapIterator_isEnd(&iter)) {
- psa_tcp_subscriber_entry_t* entry = iter.value.ptrValue;
- celix_longHashMapIterator_next(&iter);
- if (entry != NULL && entry->subscriberSvc->receive != NULL) {
- entry->subscriberSvc->receive(entry->subscriberSvc->handle, msgFqn, message->header.msgId, *msg, metadata, release);
- if (!(*release) && !celix_longHashMapIterator_isEnd(&iter)) { //receive function has taken ownership, deserialize again for new message
- struct iovec deSerializeBuffer;
- deSerializeBuffer.iov_base = message->payload.payload;
- deSerializeBuffer.iov_len = message->payload.length;
- celix_status_t status = pubsub_serializerHandler_deserialize(receiver->serializerHandler,
- message->header.msgId,
- message->header.msgMajorVersion,
- message->header.msgMinorVersion,
- &deSerializeBuffer, 0, msg);
- if (status != CELIX_SUCCESS) {
- L_WARN("[PSA_TCP_TR] Cannot deserialize msg type %s for scope/topic %s/%s", msgFqn,
- receiver->scope == NULL ? "(null)" : receiver->scope, receiver->topic);
- break;
- }
- } else if (!(*release)) { //receive function has taken ownership, but no receive left anymore. set msg to null
- *msg = NULL;
- }
- *release = true;
- }
- }
- celixThreadMutex_unlock(&receiver->subscribers.mutex);
-}
-
-static inline void processMsg(void* handle, const pubsub_protocol_message_t *message, bool* releaseMsg, struct timespec *receiveTime) {
- pubsub_tcp_topic_receiver_t *receiver = handle;
-
- const char *msgFqn = pubsub_serializerHandler_getMsgFqn(receiver->serializerHandler, message->header.msgId);
- if (msgFqn == NULL) {
- L_WARN("Cannot find msg fqn for msg id %u", message->header.msgId);
- return;
... 17960 lines suppressed ...