Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions score/mw/com/test/common_test_resources/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ cc_library(
],
)

cc_library(
name = "send_incrementing_sequence_of_samples",
hdrs = ["send_incrementing_sequence_of_samples.h"],
features = COMPILER_WARNING_FEATURES,
visibility = ["//score/mw/com/test:__subpackages__"],
deps = [
":fail_test",
],
)

cc_library(
name = "fail_test",
srcs = [
Expand Down
10 changes: 10 additions & 0 deletions score/mw/com/test/common_test_resources/proxy_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <memory>
#include <mutex>
#include <string>
#include <utility>

namespace score::mw::com::test
{
Expand All @@ -39,6 +40,15 @@ class ProxyContainer
return *proxy_;
}

Proxy Extract()
{
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(proxy_ != nullptr,
"Proxy was not successfully created! Cannot extract it!");
auto proxy = std::move(*proxy_);
proxy_.reset();
return proxy;
}

private:
std::unique_ptr<typename Proxy::HandleType> handle_{nullptr};
std::mutex proxy_creation_mutex_{};
Expand Down
19 changes: 15 additions & 4 deletions score/mw/com/test/common_test_resources/proxy_event_receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <score/stop_token.hpp>

#include <cstdint>
#include <functional>
#include <iostream>
#include <optional>

Expand All @@ -39,12 +40,22 @@ class ProxyEventReceiver
std::cout << "ProxyEventReceiver: Received event notification" << std::endl;
received_sample_notification.notify();
};
proxy_event_.SetReceiveHandler(receive_handler);
proxy_event_.get().SetReceiveHandler(receive_handler);
}

~ProxyEventReceiver()
{
proxy_event_.UnsetReceiveHandler();
proxy_event_.get().UnsetReceiveHandler();
}

/// \brief Rebind this receiver to a different event after a proxy move.
///
/// Does NOT re-register the receive handler — the handler was already transferred to the new event by the
/// proxy move. Only updates the internal reference so that subsequent GetNewSamples calls target the
/// correct event.
void Reattach(ProxyEventType& new_event) noexcept
{
proxy_event_ = std::ref(new_event);
}

ProxyEventReceiver(const ProxyEventReceiver&) = delete;
Expand All @@ -62,7 +73,7 @@ class ProxyEventReceiver
std::size_t received_count{0U};
while (!stop_token.stop_requested())
{
auto get_samples_result = proxy_event_.GetNewSamples(
auto get_samples_result = proxy_event_.get().GetNewSamples(
[this](SamplePtr<std::uint32_t> sample) {
std::invoke(get_new_samples_callback_, std::move(sample));
},
Expand Down Expand Up @@ -106,7 +117,7 @@ class ProxyEventReceiver
private:
score::concurrency::Notification received_sample_notification_{};
std::optional<std::uint32_t> latest_value_{};
ProxyEventType& proxy_event_;
std::reference_wrapper<ProxyEventType> proxy_event_;
GetNewSamplesCallback get_new_samples_callback_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <score/stop_token.hpp>

#include <cstdint>
#include <functional>
#include <iostream>
#include <mutex>
#include <optional>
Expand All @@ -43,7 +44,7 @@ class ProxyEventStateChangeNotifier
condition_variable_.notify_all();
return true;
};
const auto registration_result = proxy_event_.SetSubscriptionStateChangeHandler(state_change_handler);
const auto registration_result = proxy_event_.get().SetSubscriptionStateChangeHandler(state_change_handler);
if (!registration_result.has_value())
{
FailTest("ProxyEventStateChangeNotifier: Failed to register state change handler: ",
Expand All @@ -53,7 +54,17 @@ class ProxyEventStateChangeNotifier

~ProxyEventStateChangeNotifier()
{
proxy_event_.UnsetSubscriptionStateChangeHandler();
proxy_event_.get().UnsetSubscriptionStateChangeHandler();
}

/// \brief Rebind this notifier to a different event after a proxy move.
///
/// Does NOT re-register the subscription state change handler — the handler was already transferred to the
/// new event by the proxy move. Only updates the internal reference so that subsequent GetSubscriptionState
/// calls target the correct event.
void Reattach(ProxyEventType& new_event) noexcept
{
proxy_event_ = std::ref(new_event);
}

ProxyEventStateChangeNotifier(const ProxyEventStateChangeNotifier&) = delete;
Expand All @@ -69,7 +80,7 @@ class ProxyEventStateChangeNotifier
[[nodiscard]] bool WaitForStateChange(const score::cpp::stop_token& stop_token, SubscriptionState desired_state)
{
std::unique_lock lock(mutex_);
const auto current_state = proxy_event_.GetSubscriptionState();
const auto current_state = proxy_event_.get().GetSubscriptionState();
if (current_state == desired_state)
{
return true;
Expand All @@ -90,7 +101,7 @@ class ProxyEventStateChangeNotifier
std::mutex mutex_{};
concurrency::InterruptibleConditionalVariable condition_variable_{};
std::optional<SubscriptionState> last_seen_state_{};
ProxyEventType& proxy_event_;
std::reference_wrapper<ProxyEventType> proxy_event_;
};

} // namespace score::mw::com::test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*******************************************************************************
* Copyright (c) 2026 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
#include "score/mw/com/test/common_test_resources/send_incrementing_sequence_of_samples.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/********************************************************************************
* Copyright (c) 2026 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#ifndef SCORE_MW_COM_TEST_COMMON_TEST_RESOURCES_SEND_INCREMENTING_SEQUENCE_OF_SAMPLES_H
#define SCORE_MW_COM_TEST_COMMON_TEST_RESOURCES_SEND_INCREMENTING_SEQUENCE_OF_SAMPLES_H

#include "score/mw/com/test/common_test_resources/fail_test.h"

#include <chrono>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <thread>

namespace score::mw::com::test
{

/// Sends an incrementing sequence of \p number_of_samples_to_send_per_offer samples via
/// \p skeleton.moved_event_, starting at \p initial_value.
template <typename SkeletonT>
void SendIncrementingSequenceOfSamples(SkeletonT& skeleton,
const std::size_t number_of_samples_to_send_per_offer,
const std::uint32_t initial_value)
{
std::cout << "\nProvider: Sending " << number_of_samples_to_send_per_offer << " samples" << std::endl;
for (std::uint32_t i = 0; i < number_of_samples_to_send_per_offer; ++i)
{
auto send_result = skeleton.moved_event_.Send(i + initial_value);
if (!send_result.has_value())
{
FailTest("Provider: Send failed: ", send_result.error());
}
std::this_thread::sleep_for(std::chrono::milliseconds(20));
}
}

} // namespace score::mw::com::test

#endif // SCORE_MW_COM_TEST_COMMON_TEST_RESOURCES_SEND_INCREMENTING_SEQUENCE_OF_SAMPLES_H
171 changes: 171 additions & 0 deletions score/mw/com/test/move_semantics/proxy_event/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("@score_baselibs//score/language/safecpp:toolchain_features.bzl", "COMPILER_WARNING_FEATURES")
load("//bazel/tools:json_schema_validator.bzl", "validate_json_schema_test")
load("//score/mw/com/test:pkg_application.bzl", "pkg_application")

validate_json_schema_test(
name = "validate_config_schema",
json = "config/mw_com_config.json",
schema = "//score/mw/com:config_schema",
tags = ["lint"],
)

cc_library(
name = "test_event_datatype",
srcs = ["test_event_datatype.cpp"],
hdrs = ["test_event_datatype.h"],
features = COMPILER_WARNING_FEATURES,
deps = [
"//score/mw/com",
],
)

cc_library(
name = "test_parameters",
srcs = ["test_parameters.cpp"],
hdrs = ["test_parameters.h"],
features = COMPILER_WARNING_FEATURES,
deps = [
"//score/mw/com",
"//score/mw/com/test/common_test_resources:command_line_parser",
"//score/mw/com/test/common_test_resources:fail_test",
],
)

cc_library(
name = "provider",
srcs = ["provider.cpp"],
hdrs = ["provider.h"],
features = COMPILER_WARNING_FEATURES,
deps = [
":test_event_datatype",
":test_parameters",
"//score/mw/com",
"//score/mw/com/test/common_test_resources:fail_test",
"//score/mw/com/test/common_test_resources:process_synchronizer",
"//score/mw/com/test/common_test_resources:send_incrementing_sequence_of_samples",
"//score/mw/com/test/common_test_resources:skeleton_container",
],
)

cc_library(
name = "consumer",
srcs = ["consumer.cpp"],
hdrs = ["consumer.h"],
features = COMPILER_WARNING_FEATURES,
deps = [
":test_event_datatype",
":test_parameters",
"//score/mw/com",
"//score/mw/com/test/common_test_resources:fail_test",
"//score/mw/com/test/common_test_resources:process_synchronizer",
"//score/mw/com/test/common_test_resources:proxy_container",
"//score/mw/com/test/common_test_resources:proxy_event_receiver",
"//score/mw/com/test/common_test_resources:proxy_event_state_change_notifier",
],
)

cc_binary(
name = "main_provider",
srcs = ["main_provider.cpp"],
data = ["config/mw_com_config.json"],
features = COMPILER_WARNING_FEATURES + [
"aborts_upon_exception",
],
deps = [
":provider",
":test_parameters",
"//score/mw/com",
"//score/mw/com/test/common_test_resources:assert_handler",
"//score/mw/com/test/common_test_resources:fail_test",
"//score/mw/com/test/common_test_resources:stop_token_sig_term_handler",
],
)

cc_binary(
name = "main_consumer",
srcs = ["main_consumer.cpp"],
data = ["config/mw_com_config.json"],
features = COMPILER_WARNING_FEATURES + [
"aborts_upon_exception",
],
deps = [
":consumer",
":test_parameters",
"//score/mw/com",
"//score/mw/com/test/common_test_resources:assert_handler",
"//score/mw/com/test/common_test_resources:fail_test",
"//score/mw/com/test/common_test_resources:stop_token_sig_term_handler",
],
)

cc_binary(
name = "main_consumer_and_provider",
srcs = ["main_consumer_and_provider.cpp"],
data = ["config/mw_com_config.json"],
features = COMPILER_WARNING_FEATURES + [
"aborts_upon_exception",
],
deps = [
":consumer",
":provider",
":test_parameters",
"//score/mw/com",
"//score/mw/com/test/common_test_resources:assert_handler",
"//score/mw/com/test/common_test_resources:fail_test",
"//score/mw/com/test/common_test_resources:process_synchronizer",
"//score/mw/com/test/common_test_resources:stop_token_sig_term_handler",
],
)

pkg_application(
name = "main_provider-pkg",
app_name = "MainProviderApp",
bin = [":main_provider"],
etc = [
"config/mw_com_config.json",
"config/logging.json",
],
visibility = [
"//score/mw/com/test/move_semantics/proxy_event:__subpackages__",
],
)

pkg_application(
name = "main_consumer-pkg",
app_name = "MainConsumerApp",
bin = [":main_consumer"],
etc = [
"config/mw_com_config.json",
"config/logging.json",
],
visibility = [
"//score/mw/com/test/move_semantics/proxy_event:__subpackages__",
],
)

pkg_application(
name = "main_consumer_and_provider-pkg",
app_name = "MainConsumerAndProviderApp",
bin = [":main_consumer_and_provider"],
etc = [
"config/mw_com_config.json",
"config/logging.json",
],
visibility = [
"//score/mw/com/test/move_semantics/proxy_event:__subpackages__",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"appId": "PRMS",
"appDesc": "proxy_event_move_semantics",
"logLevel": "kDebug",
"logLevelThresholdConsole": "kDebug",
"logMode": "kRemote|kConsole"
}
Loading
Loading