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
5 changes: 5 additions & 0 deletions score/mw/com/test/bigdata/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library")
load("@score_baselibs//score/language/safecpp:toolchain_features.bzl", "COMPILER_WARNING_FEATURES")
load("//score/mw/com/test:pkg_application.bzl", "pkg_application")

exports_files(
["logging.json"],
visibility = ["//score/mw/com/test:__subpackages__"],
)

cc_binary(
name = "bigdata",
srcs = [
Expand Down
44 changes: 44 additions & 0 deletions score/mw/com/test/com_api/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# *******************************************************************************
# 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_library")
load("@rules_rust//rust:defs.bzl", "rust_library")
load("@score_baselibs//score/language/safecpp:toolchain_features.bzl", "COMPILER_WARNING_FEATURES")

cc_library(
name = "bigdata_com_api_gen_cpp",
srcs = ["bigdata_com_api_gen.cpp"],
hdrs = ["bigdata_com_api_gen.h"],
features = COMPILER_WARNING_FEATURES,
implementation_deps = [
"//score/mw/com/impl/rust/com-api/com-api-ffi-lola:registry_bridge_macro_cpp",
],
deps = [
"//score/mw/com/test/common_test_resources:bigdata_type",
],
alwayslink = True,
)

rust_library(
name = "bigdata_com_api_gen_rs",
srcs = ["bigdata_com_api_gen.rs"],
crate_name = "bigdata_com_api_gen",
features = ["link_std_cpp_lib"],
visibility = [
"//score/mw/com/test/com_api:__subpackages__",
],
deps = [
":bigdata_com_api_gen_cpp",
"//score/mw/com/impl/rust/com-api/com-api",
],
)
27 changes: 27 additions & 0 deletions score/mw/com/test/com_api/bigdata_com_api_gen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* 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/com_api/bigdata_com_api_gen.h"
#include "score/mw/com/impl/rust/com-api/com-api-ffi-lola/registry_bridge_macro.h"

// Register the BigData interface with the com-api FFI bridge.
BEGIN_EXPORT_MW_COM_INTERFACE(BigDataInterface,
::score::mw::com::test::BigDataProxy,
::score::mw::com::test::BigDataSkeleton)
EXPORT_MW_COM_EVENT(::score::mw::com::test::MapApiLanesStamped, map_api_lanes_stamped_)
EXPORT_MW_COM_EVENT(::score::mw::com::test::DummyDataStamped, dummy_data_stamped_)
END_EXPORT_MW_COM_INTERFACE()

// Export data types so that the Rust-side CommData::ID can resolve them.
EXPORT_MW_COM_TYPE(MapApiLanesStamped, ::score::mw::com::test::MapApiLanesStamped)
EXPORT_MW_COM_TYPE(DummyDataStamped, ::score::mw::com::test::DummyDataStamped)
21 changes: 21 additions & 0 deletions score/mw/com/test/com_api/bigdata_com_api_gen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* 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_COM_API_BIGDATA_COM_API_GEN_H
#define SCORE_MW_COM_TEST_COM_API_BIGDATA_COM_API_GEN_H

// Re-export the BigData interface types (BigDataProxy / BigDataSkeleton) that are
// already defined in big_datatype.h
#include "score/mw/com/test/common_test_resources/big_datatype.h"

#endif // SCORE_MW_COM_TEST_COM_API_BIGDATA_COM_API_GEN_H
108 changes: 108 additions & 0 deletions score/mw/com/test/com_api/bigdata_com_api_gen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/********************************************************************************
* 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
********************************************************************************/

//! Generated bindings for the BigData interface using the com-api library.
//!
//! This file is the com-api counterpart of the old-API `bigdata_gen.rs`. It
//! defines the same large data types (`MapApiLanesStamped`, `DummyDataStamped`)
//! and wires them through the com-api `Interface` / `Consumer` / `Producer`
//! abstractions instead of the legacy `mw_com::import_interface!` macro.

use com_api::{interface, CommData, ProviderInfo, Publisher, Reloc, Subscriber};

use core::fmt::Debug;

#[repr(C)]
#[derive(Default, Reloc)]
pub struct StdTimestamp {
pub fractional_seconds: u32,
pub seconds: u32,
pub sync_status: u32,
}

/// Opaque representation of `MapApiLaneBoundaryData` (empty struct in C++).
#[repr(C)]
#[derive(Default, Reloc)]
pub struct MapApiLaneBoundaryData {
_dummy: [u8; 1],
}

/// Opaque representation of `MapApiLaneData`.
/// Using a single-byte placeholder; the C++ type is much larger.
/// This is sufficient because the test only verifies sample-count delivery.
#[repr(C)]
#[derive(Default, Reloc)]
pub struct MapApiLaneData {
_dummy: [u8; 1],
}

/// Opaque representation of `LaneGroupData` (empty struct in C++).
#[repr(C)]
#[derive(Default, Reloc)]
pub struct LaneGroupData {
_dummy: [u8; 1],
}

pub const MAX_LANES: usize = 16;

/// Large data type sent over the `map_api_lanes_stamped` event.
#[repr(C)]
#[derive(Default, Reloc)]
pub struct MapApiLanesStamped {
pub time_stamp: StdTimestamp,
pub frame_id: [u8; 10],
pub projection_id: u32,
pub event_data_qualifier: u32,
pub lane_boundaries: [MapApiLaneBoundaryData; 10],
pub lanes: [MapApiLaneData; MAX_LANES],
pub lane_groups: [LaneGroupData; 10],
pub x: u32,
pub hash_value: usize,
}

impl CommData for MapApiLanesStamped {
const ID: &'static str = "MapApiLanesStamped";
}

impl Debug for MapApiLanesStamped {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "MapApiLanesStamped {{ x: {} }}", self.x)
}
}

/// Secondary event data type.
#[repr(C)]
#[derive(Default, Reloc)]
pub struct DummyDataStamped {
pub time_stamp: StdTimestamp,
pub x: u8,
pub hash_value: usize,
}

impl CommData for DummyDataStamped {
const ID: &'static str = "DummyDataStamped";
}

impl Debug for DummyDataStamped {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "DummyDataStamped {{ x: {} }}", self.x)
}
}

interface!(
interface BigData, {
Id = "BigDataInterface",
map_api_lanes_stamped_: Event<MapApiLanesStamped>,
dummy_data_stamped_: Event<DummyDataStamped>,
}
);
46 changes: 46 additions & 0 deletions score/mw/com/test/com_api/consumer_async_apis/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# *******************************************************************************
# 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_rust//rust:defs.bzl", "rust_binary")
load("//score/mw/com/test:pkg_application.bzl", "pkg_application")

rust_binary(
name = "bigdata-consumer-async",
srcs = ["consumer_app.rs"],
features = ["link_std_cpp_lib"],
visibility = [
"//score/mw/com/test/com_api:__subpackages__",
],
deps = [
"//score/mw/com/impl/rust/com-api/com-api",
"//score/mw/com/test/com_api:bigdata_com_api_gen_rs",
"@score_communication_crate_index//:clap",
"@score_communication_crate_index//:tokio",
],
)

pkg_application(
name = "bigdata-com-api-async-pkg",
app_name = "bigdata-com-api-async",
bin = [
":bigdata-consumer-async",
"//score/mw/com/test/com_api/producer_app:bigdata-producer",
],
etc = [
"//score/mw/com/test/com_api/etc:config",
"//score/mw/com/test/bigdata:logging.json",
],
visibility = [
"//score/mw/com/test/com_api:__subpackages__",
],
)
123 changes: 123 additions & 0 deletions score/mw/com/test/com_api/consumer_async_apis/consumer_app.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/********************************************************************************
* 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
********************************************************************************/

//! Consumer (proxy) binary for the BigData com-api SCT.
//! it use the async APIs for Service Discovery and Receive samples.
//!
//! # Usage
//!
//! ```
//! bigdata-consumer -n <num_cycles>
//! ```
//! * `-n <num_cycles>` — number of samples to receive before exiting.
//! The consumer subscribes to the producer's `map_api_lanes_stamped_` output and
//! prints the `x` field of each received sample until it has received the specified number of samples, at which point it exits.

use bigdata_com_api_gen::BigDataInterface;
use clap::Parser;
use com_api::{
Builder, FindServiceSpecifier, InstanceSpecifier, LolaRuntimeBuilderImpl, Runtime,
RuntimeBuilder, SampleContainer, ServiceDiscovery, Subscriber, Subscription,
};
use std::path::Path;

const CONFIG_PATH: &str = "etc/config.json";
const MAX_SAMPLES_PER_CALL: usize = 5;

#[derive(Parser)]
struct Args {
/// Number of samples to receive before exiting
#[arg(short = 'n', required = true)]
num_cycles: usize,
}

#[tokio::main]
async fn main() {
let args = Args::parse();
let num_cycles = args.num_cycles;

println!(
"[bigdata-consumer] Starting, will receive {} samples",
num_cycles
);

// Initialise the Lola runtime.
let mut runtime_builder = LolaRuntimeBuilderImpl::new();
runtime_builder.load_config(Path::new(CONFIG_PATH));
let runtime = runtime_builder
.build()
.expect("Failed to build Lola runtime");

let instance_specifier = InstanceSpecifier::new("/score/cp60/MapApiLanesStamped")
.expect("Invalid instance specifier");

let discovery = runtime
.find_service::<BigDataInterface>(FindServiceSpecifier::Specific(instance_specifier));

// Await the producer to become available.
let instances = discovery
.get_available_instances_async()
.await
.expect("Failed to get available instances");

let builder = instances
.into_iter()
.next()
.expect("No service instances available");
let consumer = builder.build().expect("Failed to build consumer");

// Subscribe with a slot buffer large enough for MAX_SAMPLES_PER_CALL.
let subscription = consumer
.map_api_lanes_stamped_
.subscribe(MAX_SAMPLES_PER_CALL)
.expect("Failed to subscribe to map_api_lanes_stamped_");

let mut received_total: usize = 0;
let mut sample_buf = SampleContainer::new(MAX_SAMPLES_PER_CALL);
// `receive` awaits until at least `min_samples` (1) are available.
while received_total < num_cycles {
sample_buf = match subscription
.receive(sample_buf, 1, MAX_SAMPLES_PER_CALL)
.await
{
Ok(returned_buf) => {
let count = returned_buf.sample_count();
if count > 0 {
let mut buf = returned_buf;
for _ in 0..count {
if let Some(sample) = buf.pop_front() {
println!("[bigdata-consumer] Received sample x={}", sample.x);
}
}
received_total += count;
println!(
"[bigdata-consumer] Progress: {}/{}",
received_total, num_cycles
);
buf
} else {
returned_buf
}
}
Err(e) => {
eprintln!("[bigdata-consumer] Receive error: {:?}", e);
std::process::exit(1);
}
};
}

println!(
"[bigdata-consumer] Received all {} samples, exiting",
num_cycles
);
}
Loading
Loading