Skip to content
Open
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
Empty file modified score/mw/com/design/events_fields/NestedCallbacks.svg
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion score/mw/com/example/ipc_bridge/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Params ParseCommandLineArguments(const int argc, const char** argv)
"Number of cycles that are executed before determining success or failure. 0 indicates no limit.");
options.add_options()("mode,m",
po::value<std::string>(),
"Set to either send/skeleton or recv/proxy to determine the role of the process");
"Set to: send/skeleton (typed skeleton), gen_skeleton (generic skeleton) or recv/proxy to determine the role of the process");
options.add_options()("cycle-time,t", po::value<std::size_t>(), "Cycle time in milliseconds for sending/polling");
options.add_options()(
"service_instance_manifest,s", po::value<std::string>(), "Path to the com configuration file");
Expand Down Expand Up @@ -119,6 +119,10 @@ int main(const int argc, const char** argv)
{
return event_sender_receiver.RunAsSkeleton(instance_specifier, cycle_time, cycles);
}
else if (mode == "gen_skeleton")
{
return event_sender_receiver.RunAsGenericSkeleton(instance_specifier, cycle_time, cycles);
}
else if (mode == "recv" || mode == "proxy")
{
return event_sender_receiver.RunAsProxy(instance_specifier, cycle_time, cycles, false, check_sample_hash);
Expand Down
86 changes: 86 additions & 0 deletions score/mw/com/example/ipc_bridge/sample_sender_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "sample_sender_receiver.h"
#include "score/mw/com/impl/generic_proxy.h"
#include "score/mw/com/impl/generic_proxy_event.h"
#include "score/mw/com/impl/generic_skeleton.h"
#include "score/mw/com/impl/handle_type.h"

#include "score/concurrency/notification.h"
Expand Down Expand Up @@ -268,6 +269,36 @@ Result<SampleAllocateePtr<MapApiLanesStamped>> PrepareMapLaneSample(IpcBridgeSke
return sample;
}

Result<SampleAllocateePtr<void>> PrepareMapLaneSample(impl::GenericSkeletonEvent& event,
const std::size_t cycle)
{
const std::default_random_engine::result_type seed{static_cast<std::default_random_engine::result_type>(
std::chrono::steady_clock::now().time_since_epoch().count())};
std::default_random_engine rng{seed};

auto sample_result = event.Allocate();

if (!sample_result.has_value())
{
return sample_result;
}
auto sample = std::move(sample_result).value();
auto* typed_sample = static_cast<MapApiLanesStamped*>(sample.Get());
typed_sample->hash_value = START_HASH;
typed_sample->x = static_cast<std::uint32_t>(cycle);

std::cout << ToString("Sending sample: ", typed_sample->x, "\n");
for (MapApiLaneData& lane : typed_sample->lanes) {
for (LaneIdType& successor : lane.successor_lanes)
{
successor = std::uniform_int_distribution<std::size_t>()(rng);
}

HashArray(lane.successor_lanes, typed_sample->hash_value);
}
return sample;
}

} // namespace

template <typename ProxyType, typename ProxyEventType>
Expand Down Expand Up @@ -447,6 +478,61 @@ int EventSenderReceiver::RunAsSkeleton(const score::mw::com::InstanceSpecifier&
return EXIT_SUCCESS;
}

int EventSenderReceiver::RunAsGenericSkeleton(const score::mw::com::InstanceSpecifier& instance_specifier,
const std::chrono::milliseconds cycle_time,
const std::size_t num_cycles)
{
auto create_result = impl::GenericSkeleton::Create(instance_specifier);
if (!create_result.has_value())
{
std::cerr << "Unable to construct skeleton: " << create_result.error() << ", bailing!\n";
return EXIT_FAILURE;
}
auto& skeleton = create_result.value();

const auto event_name = "map_api_lanes_stamped";
const SizeInfo size_info{sizeof(MapApiLanesStamped), alignof(MapApiLanesStamped)};
auto event_result = skeleton.AddEvent(event_name, size_info);
if (!event_result.has_value())
{
std::cerr << "Unable to add event to skeleton: " << event_result.error() << ", bailing!\n";
return EXIT_FAILURE;
}
auto& event = *event_result.value();

const auto offer_result = skeleton.OfferService();
if (!offer_result.has_value())
{
std::cerr << "Unable to offer service for skeleton: " << offer_result.error() << ", bailing!\n";
return EXIT_FAILURE;
}
std::cout << "Starting to send data\n";

for (std::size_t cycle = 0U; cycle < num_cycles || num_cycles == 0U; ++cycle)
{
auto sample_result = PrepareMapLaneSample(event, cycle);
if (!sample_result.has_value())
{
std::cerr << "No sample received. Exiting.\n";
return EXIT_FAILURE;
}
auto sample = std::move(sample_result).value();

{
std::lock_guard lock{event_sending_mutex_};
event.Send(std::move(sample));
event_published_ = true;
}
std::this_thread::sleep_for(cycle_time);
}

std::cout << "Stop offering service...";
skeleton.StopOfferService();
std::cout << "and terminating, bye bye\n";

return EXIT_SUCCESS;
}

template int EventSenderReceiver::RunAsProxy<IpcBridgeProxy, impl::ProxyEvent<MapApiLanesStamped>>(
const score::mw::com::InstanceSpecifier&,
const score::cpp::optional<std::chrono::milliseconds>,
Expand Down
4 changes: 4 additions & 0 deletions score/mw/com/example/ipc_bridge/sample_sender_receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class EventSenderReceiver
const std::chrono::milliseconds cycle_time,
const std::size_t num_cycles);

int RunAsGenericSkeleton(const score::mw::com::InstanceSpecifier& instance_specifier,
const std::chrono::milliseconds cycle_time,
const std::size_t num_cycles);

template <typename ProxyType = score::mw::com::IpcBridgeProxy,
typename ProxyEventType = score::mw::com::impl::ProxyEvent<MapApiLanesStamped>>
int RunAsProxy(const score::mw::com::InstanceSpecifier& instance_specifier,
Expand Down
79 changes: 79 additions & 0 deletions score/mw/com/impl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cc_library(
":generic_proxy_event",
":proxy_event",
":proxy_field",
":generic_skeleton",
":skeleton_event",
":skeleton_field",
":traits",
Expand Down Expand Up @@ -110,6 +111,82 @@ cc_library(
],
)

cc_library(
name = "generic_skeleton",
srcs = ["generic_skeleton.cpp"],
hdrs = ["generic_skeleton.h"],
features = COMPILER_WARNING_FEATURES,
implementation_deps = [
":error",
"//score/mw/com/impl/plumbing:generic_skeleton_event_binding_factory",
"//score/mw/com/impl/plumbing",
],
tags = ["FFI"],
visibility = [
"//score/mw/com:__subpackages__",
],
deps = [
":generic_skeleton_event",
":instance_identifier",
":instance_specifier",
":runtime",
":skeleton_base",
":skeleton_binding",
":size_info",
"@score_baselibs//score/result",
],
)

cc_library(
name = "generic_skeleton_event",
srcs = ["generic_skeleton_event.cpp"],
hdrs = ["generic_skeleton_event.h"],
features = COMPILER_WARNING_FEATURES,
tags = ["FFI"],
visibility = [
"//score/mw/com:__subpackages__",
],
deps = [
"//score/mw/com/impl/bindings/lola:generic_skeleton_event",
":generic_skeleton_event_binding",
":skeleton_base",
":skeleton_event_base",
":skeleton_event_binding",
":size_info",
"//score/mw/com/impl/plumbing:sample_allocatee_ptr",
"@score_baselibs//score/result",
],
)

cc_library(
name = "generic_skeleton_event_binding",
hdrs = [
"generic_skeleton_event_binding.h",
],
features = COMPILER_WARNING_FEATURES,
tags = ["FFI"],
visibility = [
"//score/mw/com/impl/bindings/lola:__pkg__",
"//score/mw/com/impl/bindings/mock_binding:__pkg__",
"//score/mw/com/impl/plumbing:__pkg__",
],
deps = [
":skeleton_event_binding",
"@score_baselibs//score/result",
],
)

cc_library(
name = "size_info",
hdrs = ["size_info.h"],
features = COMPILER_WARNING_FEATURES,
tags = ["FFI"],
visibility = [
"//score/mw/com:__pkg__",
"//score/mw/com/impl:__subpackages__",
],
)

cc_library(
name = "skeleton_event",
srcs = ["skeleton_event.cpp"],
Expand Down Expand Up @@ -381,6 +458,8 @@ cc_library(
],
deps = [
":binding_type",
":generic_skeleton_event_binding",
":size_info",
"//score/mw/com/impl/configuration",
"@score_baselibs//score/language/futurecpp",
"@score_baselibs//score/memory/shared:i_shared_memory_resource",
Expand Down
24 changes: 24 additions & 0 deletions score/mw/com/impl/bindings/lola/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,41 @@ cc_library(
],
)

cc_library(
name = "generic_skeleton_event",
srcs = ["generic_skeleton_event.cpp"],
hdrs = ["generic_skeleton_event.h"],
features = COMPILER_WARNING_FEATURES,
tags = ["FFI"],
visibility = [
"//score/mw/com/impl:__subpackages__",
],
deps = [
":event",
":skeleton",
"//score/mw/com/impl:error",
"//score/mw/com/impl:generic_skeleton_event_binding",
"//score/mw/com/impl:size_info",
"//score/mw/com/impl/tracing:skeleton_event_tracing",
":type_erased_sample_ptrs_guard",
],
)

cc_library(
name = "skeleton",
srcs = [
"skeleton.cpp",
"skeleton_event.cpp",
"skeleton_event_properties.cpp",
"skeleton_method.cpp",
"generic_skeleton_event.cpp",
],
hdrs = [
"skeleton.h",
"skeleton_event.h",
"skeleton_event_properties.h",
"skeleton_method.h",
"generic_skeleton_event.h",
],
features = COMPILER_WARNING_FEATURES,
tags = ["FFI"],
Expand Down Expand Up @@ -282,6 +304,8 @@ cc_library(
"//score/mw/com/impl/plumbing:sample_allocatee_ptr",
"//score/mw/com/impl/tracing:skeleton_event_tracing",
"//score/mw/com/impl/util:arithmetic_utils",
"//score/mw/com/impl:generic_skeleton_event_binding",
"//score/mw/com/impl:error",
"@score_baselibs//score/filesystem",
"@score_baselibs//score/language/futurecpp",
"@score_baselibs//score/language/safecpp/safe_math",
Expand Down
Loading
Loading