Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ rust_library(
crate_name = "bigdata_com_api_gen",
features = ["link_std_cpp_lib"],
visibility = [
"//score/mw/com/test/com_api:__subpackages__",
"//score/mw/com/test/basic_rust_api:__subpackages__",
],
deps = [
":bigdata_com_api_gen_cpp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/

#include "score/mw/com/test/com_api/bigdata_com_api_gen.h"
#include "score/mw/com/test/basic_rust_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.
Expand All @@ -25,3 +25,20 @@ 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)

// Test for primitive and complex data types, used in the com-api integration tests.
BEGIN_EXPORT_MW_COM_INTERFACE(MixedPrimitivesInterface,
::score::mw::com::test::MixedPrimitivesProxy,
::score::mw::com::test::MixedPrimitivesSkeleton)
EXPORT_MW_COM_EVENT(::score::mw::com::test::MixedPrimitivesPayload, mixed_event)
END_EXPORT_MW_COM_INTERFACE()

BEGIN_EXPORT_MW_COM_INTERFACE(ComplexStructInterface,
::score::mw::com::test::ComplexStructProxy,
::score::mw::com::test::ComplexStructSkeleton)
EXPORT_MW_COM_EVENT(::score::mw::com::test::ComplexStruct, complex_event)
END_EXPORT_MW_COM_INTERFACE()

// Export all types
EXPORT_MW_COM_TYPE(MixedPrimitivesPayload, ::score::mw::com::test::MixedPrimitivesPayload)
EXPORT_MW_COM_TYPE(ComplexStruct, ::score::mw::com::test::ComplexStruct)
121 changes: 121 additions & 0 deletions score/mw/com/test/basic_rust_api/bigdata_com_api_gen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*******************************************************************************
* 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_BASIC_RUST_API_COM_API_GEN_H
#define SCORE_MW_COM_TEST_BASIC_RUST_API_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"

namespace score::mw::com::test
{
/// Combined payload carrying every primitive type in a single struct.
/// Field order follows descending alignment to eliminate padding bytes.
struct MixedPrimitivesPayload
{
uint64_t u64_val;
int64_t i64_val;
uint32_t u32_val;
int32_t i32_val;
float f32_val;
uint16_t u16_val;
int16_t i16_val;
uint8_t u8_val;
int8_t i8_val;
bool flag;
};

struct SimpleStruct
{
uint32_t id;
};

struct NestedStruct
{
uint32_t id;
SimpleStruct simple;
float value;
};

struct Point
{
float x;
float y;
};

struct Point3D
{
float x;
float y;
float z;
};

struct SensorData
{
uint16_t sensor_id;
float temperature;
float humidity;
float pressure;
};

struct VehicleState
{
float speed;
uint16_t rpm;
float fuel_level;
bool is_running;
uint32_t mileage;
};

struct ArrayStruct
{
uint32_t values[5];
};

struct ComplexStruct
{
uint32_t count;
SimpleStruct simple;
NestedStruct nested;
Point point;
Point3D point3d;
SensorData sensor;
VehicleState vehicle;
ArrayStruct array;
};

template <typename Trait>
class MixedPrimitivesInterface : public Trait::Base
{
public:
using Trait::Base::Base;
typename Trait::template Event<MixedPrimitivesPayload> mixed_event{*this, "mixed_event"};
};

template <typename Trait>
class ComplexStructInterface : public Trait::Base
{
public:
using Trait::Base::Base;
typename Trait::template Event<ComplexStruct> complex_event{*this, "complex_event"};
};

// Type aliases for proxy and skeleton
using MixedPrimitivesProxy = ::score::mw::com::AsProxy<MixedPrimitivesInterface>;
using MixedPrimitivesSkeleton = ::score::mw::com::AsSkeleton<MixedPrimitivesInterface>;
using ComplexStructProxy = ::score::mw::com::AsProxy<ComplexStructInterface>;
using ComplexStructSkeleton = ::score::mw::com::AsSkeleton<ComplexStructInterface>;
} // namespace score::mw::com::test

#endif // SCORE_MW_COM_TEST_BASIC_RUST_API_COM_API_GEN_H
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ pub const MAX_LANES: usize = 16;

/// Large data type sent over the `map_api_lanes_stamped` event.
#[repr(C)]
#[derive(Default, Reloc)]
#[derive(Default, Reloc, CommData)]
#[comm_data(id = "MapApiLanesStamped")]
pub struct MapApiLanesStamped {
pub time_stamp: StdTimestamp,
pub frame_id: [u8; 10],
Expand All @@ -70,10 +71,6 @@ pub struct MapApiLanesStamped {
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)
Expand All @@ -82,17 +79,14 @@ impl Debug for MapApiLanesStamped {

/// Secondary event data type.
#[repr(C)]
#[derive(Default, Reloc)]
#[derive(Default, Reloc, CommData)]
#[comm_data(id = "DummyDataStamped")]
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)
Expand All @@ -106,3 +100,111 @@ interface!(
dummy_data_stamped_: Event<DummyDataStamped>,
}
);

// Test for primitive and complex data types, used in the com-api integration tests.

// Macro to generate struct (types) with CommData impl.
// Supports custom trait derivation via standard #[derive(...)] syntax.
macro_rules! define_com_type {
(#[derive($($trait:path),+)] struct $name:ident $body:tt) => {
define_com_type_impl!($name $body [$($trait),+]);
};
(struct $name:ident $body:tt) => {
define_com_type_impl!($name $body []);
};
}

macro_rules! define_com_type_impl {
($name:ident { $($field:ident: $field_type:ty),+ $(,)? } [$($trait:path),*]) => {
#[derive(Debug, Clone, Copy, PartialEq $(, $trait)*, Reloc)]
#[repr(C)]
pub struct $name {
$(pub $field: $field_type,)*
}
impl CommData for $name {
const ID: &'static str = stringify!($name);
}
};
}

// Combined primitive payload – all primitive types packed into one struct.
define_com_type!(
struct MixedPrimitivesPayload {
u64_val: u64,
i64_val: i64,
u32_val: u32,
i32_val: i32,
f32_val: f32,
u16_val: u16,
i16_val: i16,
u8_val: u8,
i8_val: i8,
flag: bool,
}
);

// Complex struct types
define_com_type!(
#[derive(Eq)]
struct SimpleStruct {
id: u32,
}
);
define_com_type!(
struct NestedStruct {
id: u32,
simple: SimpleStruct,
value: f32,
}
);
define_com_type!(
struct Point {
x: f32,
y: f32,
}
);
define_com_type!(
struct Point3D {
x: f32,
y: f32,
z: f32,
}
);
define_com_type!(
struct SensorData {
sensor_id: u16,
temperature: f32,
humidity: f32,
pressure: f32,
}
);
define_com_type!(
struct VehicleState {
speed: f32,
rpm: u16,
fuel_level: f32,
is_running: bool,
mileage: u32,
}
);
define_com_type!(
#[derive(Eq)]
struct ArrayStruct {
values: [u32; 5],
}
);
define_com_type!(
struct ComplexStruct {
count: u32,
simple: SimpleStruct,
nested: NestedStruct,
point: Point,
point3d: Point3D,
sensor: SensorData,
vehicle: VehicleState,
array: ArrayStruct,
}
);

interface!(interface MixedPrimitives, { Id = "MixedPrimitivesInterface", mixed_event: Event<MixedPrimitivesPayload> });
interface!(interface ComplexStruct, { Id = "ComplexStructInterface", complex_event: Event<ComplexStruct> });
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ rust_binary(
"-Clink-arg=-lstdc++",
],
visibility = [
"//score/mw/com/test/com_api:__subpackages__",
"//score/mw/com/test/basic_rust_api:__subpackages__",
],
deps = [
"//score/mw/com/impl/rust/com-api/com-api",
"//score/mw/com/test/com_api:bigdata_com_api_gen_rs",
"//score/mw/com/test/basic_rust_api:bigdata_com_api_gen_rs",
"@score_communication_crate_index//:clap",
"@score_communication_crate_index//:futures",
],
Expand All @@ -42,13 +42,13 @@ pkg_application(
app_name = "bigdata-com-api-async",
bin = [
":bigdata-consumer-async",
"//score/mw/com/test/com_api/producer_app:bigdata-producer",
"//score/mw/com/test/basic_rust_api/producer_app:bigdata-producer",
],
etc = [
"//score/mw/com/test/com_api/etc:config",
"//score/mw/com/test/basic_rust_api/etc:config",
"//score/mw/com/test/bigdata:logging.json",
],
visibility = [
"//score/mw/com/test/com_api:__subpackages__",
"//score/mw/com/test/basic_rust_api:__subpackages__",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ load("//quality/integration_testing:integration_testing.bzl", "integration_test"
pkg_tar(
name = "filesystem",
deps = [
"//score/mw/com/test/com_api/consumer_async_apis:bigdata-com-api-async-pkg",
"//score/mw/com/test/basic_rust_api/consumer_async_apis:bigdata-com-api-async-pkg",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: what basic_rust_api means?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is a folder name where we kept rust com api related integration tests, keeping name com-api is so generic.

],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ rust_binary(
"-Clink-arg=-lstdc++",
],
visibility = [
"//score/mw/com/test/com_api:__subpackages__",
"//score/mw/com/test/basic_rust_api:__subpackages__",
],
deps = [
"//score/mw/com/impl/rust/com-api/com-api",
"//score/mw/com/test/com_api:bigdata_com_api_gen_rs",
"//score/mw/com/test/basic_rust_api:bigdata_com_api_gen_rs",
"@score_communication_crate_index//:clap",
],
)
Expand All @@ -41,13 +41,13 @@ pkg_application(
app_name = "bigdata-com-api-sync",
bin = [
":bigdata-consumer",
"//score/mw/com/test/com_api/producer_app:bigdata-producer",
"//score/mw/com/test/basic_rust_api/producer_app:bigdata-producer",
],
etc = [
"//score/mw/com/test/com_api/etc:config",
"//score/mw/com/test/basic_rust_api/etc:config",
"//score/mw/com/test/bigdata:logging.json",
],
visibility = [
"//score/mw/com/test/com_api:__subpackages__",
"//score/mw/com/test/basic_rust_api:__subpackages__",
],
)
Loading
Loading