Skip to content

Commit

Permalink
Restructure crates
Browse files Browse the repository at this point in the history
  • Loading branch information
Ax9DTW committed May 21, 2024
1 parent 454432f commit 4d0cde1
Show file tree
Hide file tree
Showing 35 changed files with 154 additions and 6 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ edition = "2021"
[workspace]
resolver = "2"

members = ["smip_core", "smip_proc_macros", "someip_types", "vsomeip_compat"]
members = ["crates/smip_core", "crates/smip_proc_macros", "crates/someip_types", "crates/vsomeip_compat"]


[dependencies]
smip_core = {path = "smip_core" }
smip_core = {path = "crates/smip_core" }
# smip_al = { path = "smip_al" }
smip_proc_macros = {path = "smip_proc_macros"}
someip_types = {path = "someip_types"}
vsomeip_compat = {path = "vsomeip_compat"}
smip_proc_macros = {path = "crates/smip_proc_macros"}
someip_types = {path = "crates/someip_types"}
vsomeip_compat = {path = "crates/vsomeip_compat"}

[dev-dependencies]
rand = "0.8"
Expand Down
10 changes: 10 additions & 0 deletions crates/smip_al/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "smip_al"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
vsomeip-rs = {git = "ssh://[email protected]/tw-sdv/vsomeip-rs"}
someip_types = { path = "../someip_types" }
2 changes: 2 additions & 0 deletions crates/smip_al/src/implementations/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod noop;
mod vsomeip;
Empty file.
76 changes: 76 additions & 0 deletions crates/smip_al/src/implementations/vsomeip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use std::collections::HashMap;

use crate::*;
pub struct VSomeIPService {
config: ServiceConfig,
methods: HashMap<MethodId, Box<dyn FnMut(vsomeip_rs::Message) + 'static>>
}

impl Service for VSomeIPService {
type B = vsomeip_rs::Application;

fn with_method<F>(&mut self, method_id: MethodId, handler: F) where F: FnMut(<Self::B as Backend>::M) + 'static {
self.methods.insert(method_id, Box::new(handler));
}
}

impl Backend for vsomeip_rs::Application {
type S = VSomeIPService;
type M = vsomeip_rs::Message;
type P = vsomeip_rs::Payload;

fn init(name: impl AsRef<str>) -> Self {
vsomeip_rs::Runtime::get().create_application_with_name(name)
}
fn create_service(config: &ServiceConfig) -> Self::S {
VSomeIPService {
config: config.clone(),
methods: HashMap::new()
}
}
fn offer_service(&self, service: &Self::S) {
self.offer_service(service.config.id, service.config.instance_id, service.config.major_version, service.config.minor_version);

for (method_id, handler) in service.methods {
self.register_message_handler(service_id, instance_id, method_id, f)
}
}
fn create_payload(data: &[u8]) -> Self::P {
vsomeip_rs::Payload::with_data(data)
}
fn create_message(header: &SOMEIpHeader, reliable: bool, payload: Self::P) -> Self::M {
let mut message = vsomeip_rs::Message::new(reliable);

message.set_payload(&payload);
message.set_service(header.service_id);
message.set_method(header.method_id);
message.set_return_code(header.return_code.into());
// message.set_message_type();
// message.set_client();
// message
}
}


impl Payload for vsomeip_rs::Payload {
type B = vsomeip_rs::Application;

fn data(&self) -> &[u8] {
self.get_data()
}

fn with_data(data: &[u8]) -> Self where Self: Sized {
vsomeip_rs::Payload::with_data(data)
}
}

impl Message for vsomeip_rs::Message {
type B = vsomeip_rs::Application;

fn header(&self) -> &S {
// self.header()
}
fn payload(&self) -> &vsomeip_rs::Payload {
self.get_payload()
}
}
60 changes: 60 additions & 0 deletions crates/smip_al/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// mod implementations;

use std::net::IpAddr;
use someip_types::*;

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum ConnectionType {
#[default]
Tcp,
Udp
}

#[derive(Debug, Clone)]
pub struct ServiceConfig {
pub name: String,
pub id: ServiceId,
pub instance_id: InstanceId,
pub address: IpAddr,
pub major_version: MajorVersion,
pub minor_version: MinorVersion,
pub port: u16,
pub connection_type: ConnectionType
}

pub trait Service {
type B: Backend;
fn with_method<F>(&mut self, method_id: MethodId, handler: F) where F: FnMut(<Self::B as Backend>::M) + 'static;
}

pub trait Message {
type B: Backend;
fn header(&self) -> &SOMEIpHeader;
fn payload(&self) -> &<Self::B as Backend>::P;
}

pub trait Payload {
type B: Backend;
fn with_data(data: &[u8]) -> Self where Self: Sized;
fn data(&self) -> &[u8];
}

pub trait Backend {
type S: Service;
type M: Message;
type P: Payload;
fn init(name: impl AsRef<str>) -> Self;
fn create_service(config: &ServiceConfig) -> Self::S;
fn offer_service(&self, service: &Self::S);
fn create_payload(data: &[u8]) -> Self::P;
fn create_message(header: &SOMEIpHeader, reliable: bool, payload: Self::P) -> Self::M;
}


// vsomeip-rs
// application.init()


// let service1 = Service::new(config).method(method_id, |message| {...});
// backend.offer_service(service1);
// backend.start();
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ someip_types = {path = "../someip_types"}

[dev-dependencies]
trybuild = "1.0"
smip = { path = "../" }
smip = { path = "../../" }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4d0cde1

Please sign in to comment.