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
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ use rustecal::{Ecal, EcalComponents, TypedPublisher};
use rustecal_types_string::StringMessage;

fn main() {
// eCAL init
// Initialize eCAL
Ecal::initialize(Some("hello publisher"), EcalComponents::DEFAULT).unwrap();

// create a string publisher on "hello"
let publisher = TypedPublisher::<StringMessage>::new("hello").unwrap();

// prepare the message to send
let message = StringMessage(Arc::from("Hello from Rust!"));
let message = StringMessage { data: Arc::from("Hello from Rust") };

// publish until eCAL shuts down
while Ecal::ok() {
Expand All @@ -52,19 +52,17 @@ fn main() {
```rust
use rustecal::{Ecal, EcalComponents, TypedSubscriber};
use rustecal_types_string::StringMessage;
use rustecal::pubsub::typed_subscriber::Received;

fn main() {
// eCAL init
// Initialize eCAL
Ecal::initialize(Some("hello subscriber"), EcalComponents::DEFAULT).unwrap();

// create a string subscriber on “hello”
let mut subscriber = TypedSubscriber::<StringMessage>::new("hello").unwrap();

// print each incoming message
subscriber.set_callback(|msg: Received<StringMessage>| {
let StringMessage(text) = msg.msg;
println!("Received: {}", text);
subscriber.set_callback(|message| {
println!("Received: {}", message.payload.data)
});

// keep the thread alive so callbacks can run
Expand All @@ -88,7 +86,7 @@ use rustecal::service::server::ServiceServer;
use rustecal::service::types::MethodInfo;

fn main() {
// eCAL init
// Initialize eCAL
Ecal::initialize(Some("mirror server"), EcalComponents::DEFAULT).unwrap();

// create a service server for "mirror"
Expand Down Expand Up @@ -127,7 +125,7 @@ use rustecal::service::client::ServiceClient;
use rustecal::service::types::ServiceRequest;

fn main() {
// eCAL init
// Initialize eCAL
Ecal::initialize(Some("mirror client"), EcalComponents::DEFAULT).unwrap();

// create a service client for "mirror"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api/ecal.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The `Ecal` struct manages initialization and finalization of the eCAL system.
## Example

```rust
use rustecal::Ecal;
use rustecal::{Ecal, EcalComponents};

fn main() -> Result<(), Box<dyn std::error::Error>> {
Ecal::initialize(Some("my ecal app"), EcalComponents::DEFAULT)?;
Expand Down
8 changes: 5 additions & 3 deletions docs/src/api/message_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ Used for binary `Vec<u8>` payloads.
Supports publishing/receiving of Protobuf types that implement `Message` and `Default`.

```rust
use rustecal_types_protobuf::ProtobufMessage;
use my_proto::MyProto;
use rustecal_types_protobuf::{ProtobufMessage, IsProtobufType};

let publisher = Publisher::<ProtobufMessage<MyProto>>::builder("proto_topic").create()?;
use people::Person;
impl IsProtobufType for Person {}

let publisher = TypedPublisher::<ProtobufMessage<Person>>::new("person").unwrap();
```
11 changes: 7 additions & 4 deletions docs/src/api/publisher.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ The `Publisher<T>` allows you to publish messages of type `T` on a topic.
## Example

```rust
use rustecal::pubsub::Publisher;
use rustecal_types::StringMessage;
use std::sync::Arc;
use rustecal::{Ecal, EcalComponents, TypedPublisher};
use rustecal_types_string::StringMessage;

let publisher = Publisher::<StringMessage>::builder("my_topic").create()?;
publisher.send("Rust rocks!")?;
let publisher = TypedPublisher::<StringMessage>::new("hello").unwrap();

let message = StringMessage { data: Arc::from("Hello from Rust") };
publisher.send(&message);
```
10 changes: 7 additions & 3 deletions docs/src/api/service_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ use rustecal::service::types::ServiceRequest;
let request = ServiceRequest {
payload: b"stressed".to_vec(),
};
```

To broadcast call all connected instances:

let response = client.call("echo", request, Some(1000));
```rust
let responses = client.call("echo", request, Some(1000));
```

To call all connected instances:
To call (and filter) all connected instances separately:

```rust
for instance in client.get_client_instances() {
Expand All @@ -48,4 +52,4 @@ match response {

## Runtime Compatibility

This API is fully compatible with the C++ `mirror_client.cpp` and C `mirror_client_c.c` examples.
This API is fully compatible with the C++ `mirror_client.cpp`, the C `mirror_client_c.c` and the C# `mirror_client_csharp.cs` example.
2 changes: 1 addition & 1 deletion docs/src/api/service_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ Response : desserts

## Runtime Compatibility

This API is fully compatible with the C++ `mirror_server.cpp` and C `mirror_server_c.c` examples.
This API is fully compatible with the C++ `mirror_server.cpp`, the C `mirror_server_c.c` and the C# `mirror_client_csharp.cs` example.
11 changes: 5 additions & 6 deletions docs/src/api/subscriber.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ The `Subscriber<T>` enables you to subscribe to messages of type `T` on a topic.
## Example

```rust
use rustecal::pubsub::Subscriber;
use rustecal_types::StringMessage;
use rustecal::{Ecal, EcalComponents, TypedSubscriber};
use rustecal_types_string::StringMessage;

let subscriber = Subscriber::<StringMessage>::builder("my_topic").create()?;
subscriber.set_callback(|msg| {
println!("Received: {}", msg.data());
});
let mut subscriber = TypedSubscriber::<StringMessage>::new("hello")?;
subscriber.set_callback(|message| {
println!("Received: {}", message.payload.data)
```
8 changes: 5 additions & 3 deletions docs/src/examples/binary.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
while Ecal::ok() {
let buf = vec![counter; 1024];
counter = counter.wrapping_add(1);
publisher.send(&BytesMessage(Arc::from(buf)));

let message = BytesMessage { data: Arc::from(buf) };
publisher.send(&message);

std::thread::sleep(std::time::Duration::from_millis(500));
}
Expand All @@ -36,8 +38,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Ecal::initialize(Some("blob subscriber"), EcalComponents::DEFAULT)?;

let mut subscriber = TypedSubscriber::<BytesMessage>::new("blob")?;
subscriber.set_callback(|msg| {
println!("Received blob of {} bytes", msg.payload.data.len());
subscriber.set_callback(|message| {
println!("Received blob of {} bytes", message.payload.data.len());
});

while Ecal::ok() {
Expand Down
1 change: 0 additions & 1 deletion docs/src/examples/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::{thread, time::Duration};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize only the logging subsystem
Ecal::initialize(Some("logging_receive_sample"), EcalComponents::LOGGING)?;
println!("eCAL initialized. Entering logging loop…");

while Ecal::ok() {
let entries = Log::get_logging()?;
Expand Down
1 change: 0 additions & 1 deletion docs/src/examples/monitoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::{thread, time::Duration};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize only the monitoring subsystem
Ecal::initialize(Some("monitoring_receive_sample"), EcalComponents::MONITORING)?;
println!("eCAL initialized. Entering monitoring loop…");

while Ecal::ok() {
let snap = Monitoring::get_snapshot()?;
Expand Down
8 changes: 5 additions & 3 deletions docs/src/examples/protobuf.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

while Ecal::ok() {
let person = Person { id: 1, name: "Alice".into(), ..Default::default() };
publisher.send(&ProtobufMessage(Arc::from(person)));

let message = ProtobufMessage { data : Arc::from(person) };
publisher.send(&message);

std::thread::sleep(std::time::Duration::from_millis(500));
}
Expand All @@ -48,8 +50,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Ecal::initialize(Some("protobuf subscriber"), EcalComponents::DEFAULT)?;

let mut subscriber = TypedSubscriber::<ProtobufMessage<Person>>::new("person")?;
subscriber.set_callback(|msg| {
println!("Received person: {}", msg.payload.data.name)
subscriber.set_callback(|message| {
println!("Received person: {}", message.payload.data.name)
});

while Ecal::ok() {
Expand Down
9 changes: 5 additions & 4 deletions docs/src/examples/string.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Publisher

```rust
use std::sync::Arc;
use rustecal::{Ecal, EcalComponents, TypedPublisher};
use rustecal_types_string::StringMessage;

Expand All @@ -12,8 +13,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let publisher = TypedPublisher::<StringMessage>::new("hello")?;

while Ecal::ok() {
let msg = StringMessage(Arc::from("Hello from Rust"));
publisher.send(&msg);
let message = StringMessage { data: Arc::from("Hello from Rust") };
publisher.send(&message);

std::thread::sleep(std::time::Duration::from_millis(500));
}
Expand All @@ -33,8 +34,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Ecal::initialize(Some("string subscriber"), EcalComponents::DEFAULT)?;

let mut subscriber = TypedSubscriber::<StringMessage>::new("hello")?;
subscriber.set_callback(|msg| {
println!("Received: {}", msg.payload.data)
subscriber.set_callback(|message| {
println!("Received: {}", message.payload.data)
});

while Ecal::ok() {
Expand Down
4 changes: 2 additions & 2 deletions rustecal-samples/monitoring/logging_receive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustecal_core::log::Log;
use std::{thread, time::Duration};

fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize only the logging component
// Initialize eCAL (only the logging component)
Ecal::initialize(Some("logging receive sample"), EcalComponents::LOGGING)?;
println!("eCAL initialized. Entering logging loop…");

Expand All @@ -18,7 +18,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
thread::sleep(Duration::from_secs(1));
}

// Clean shutdown
// clean up and finalize eCAL
Ecal::finalize();
Ok(())
}
4 changes: 2 additions & 2 deletions rustecal-samples/monitoring/monitoring_receive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustecal_core::monitoring::Monitoring;
use std::{thread, time::Duration};

fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize only the monitoring component
// Initialize eCAL (only the monitoring component)
Ecal::initialize(Some("monitoring receive sample"), EcalComponents::MONITORING)?;
println!("eCAL initialized. Entering monitoring loop…");

Expand All @@ -22,7 +22,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
thread::sleep(Duration::from_secs(1));
}

// Clean shutdown
// clean up and finalize eCAL
Ecal::finalize();
Ok(())
}
11 changes: 7 additions & 4 deletions rustecal-samples/pubsub/blob_receive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use rustecal::{Ecal, EcalComponents, TypedSubscriber};
use rustecal::pubsub::typed_subscriber::Received;
use rustecal_types_bytes::BytesMessage;

fn main() {
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize eCAL
Ecal::initialize(Some("blob receive rust"), EcalComponents::DEFAULT)
.expect("eCAL initialization failed");

let mut subscriber = TypedSubscriber::<BytesMessage>::new("blob")
.expect("Failed to create subscriber");
let mut subscriber = TypedSubscriber::<BytesMessage>::new("blob")?;

subscriber.set_callback(|msg: Received<BytesMessage>| {
let buffer = &msg.payload.data;
Expand All @@ -33,11 +33,14 @@ fn main() {
println!("------------------------------------------\n");
});

println!("Waiting for binary blobs on topic 'blob'...");
println!("Waiting for messages on topic 'blob'...");

// keep the thread alive so callbacks can run
while Ecal::ok() {
std::thread::sleep(std::time::Duration::from_millis(100));
}

// clean up and finalize eCAL
Ecal::finalize();
Ok(())
}
9 changes: 5 additions & 4 deletions rustecal-samples/pubsub/blob_send/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ use std::sync::Arc;
use rustecal::{Ecal, EcalComponents, TypedPublisher};
use rustecal_types_bytes::BytesMessage;

fn main() {
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize eCAL
Ecal::initialize(Some("blob send rust"), EcalComponents::DEFAULT)
.expect("eCAL initialization failed");

let publisher = TypedPublisher::<BytesMessage>::new("blob")
.expect("Failed to create publisher");
let publisher = TypedPublisher::<BytesMessage>::new("blob")?;

let mut counter: u8 = 0;

while Ecal::ok() {
// Fill 1024-byte buffer with the current counter value
let buffer = vec![counter; 1024];
Expand All @@ -24,5 +23,7 @@ fn main() {
std::thread::sleep(std::time::Duration::from_millis(500));
}

// clean up and finalize eCAL
Ecal::finalize();
Ok(())
}
9 changes: 6 additions & 3 deletions rustecal-samples/pubsub/hello_receive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use rustecal::{Ecal, EcalComponents, TypedSubscriber};
use rustecal::pubsub::typed_subscriber::Received;
use rustecal_types_string::StringMessage;

fn main() {
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize eCAL
Ecal::initialize(Some("hello receive rust"), EcalComponents::DEFAULT)
.expect("eCAL initialization failed");

let mut subscriber = TypedSubscriber::<StringMessage>::new("hello")
.expect("Failed to create subscriber");
let mut subscriber = TypedSubscriber::<StringMessage>::new("hello")?;

subscriber.set_callback(|msg: Received<StringMessage>| {
println!("------------------------------------------");
Expand All @@ -27,9 +27,12 @@ fn main() {

println!("Waiting for messages on topic 'hello'...");

// keep the thread alive so callbacks can run
while Ecal::ok() {
std::thread::sleep(std::time::Duration::from_millis(100));
}

// clean up and finalize eCAL
Ecal::finalize();
Ok(())
}
10 changes: 6 additions & 4 deletions rustecal-samples/pubsub/hello_send/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use std::sync::Arc;
use rustecal::{Ecal, EcalComponents, TypedPublisher};
use rustecal_types_string::StringMessage;

fn main() {
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize eCAL
Ecal::initialize(Some("hello send rust"), EcalComponents::DEFAULT)
.expect("eCAL initialization failed");

let publisher: TypedPublisher<StringMessage> = TypedPublisher::<StringMessage>::new("hello")
.expect("Failed to create publisher");
let publisher: TypedPublisher<StringMessage> = TypedPublisher::<StringMessage>::new("hello")?;

let mut cnt = 0;
while Ecal::ok() {
Expand All @@ -22,5 +22,7 @@ fn main() {
std::thread::sleep(std::time::Duration::from_millis(500));
}

// clean up and finalize eCAL
Ecal::finalize();
}
Ok(())
}
Loading