-
Notifications
You must be signed in to change notification settings - Fork 159
Added support for clients and services #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
e744ca1
Added support for clients and services
esteve 46d76ca
Use tokio runtime for examples. Use futures::Future as future impleme…
esteve 6decac7
Removed RclFuture and supporting functions
esteve 283b185
Removed future module
esteve 6b248f1
Fix rebase compilation issues
esteve ac25018
Fix formatting
esteve a9ef8a0
Fix name of handle variable
esteve a7ae869
Cleanups
esteve b103a97
Fix format
esteve 654f26b
Added documentation for clients and services variables
esteve 5bdf790
Use a FnOnce for client callbacks
esteve 9b13d6e
Return service callback response, made callback immutable
esteve 5dbb220
Only generate request and response messages
esteve 2a396f9
Cleanup
esteve 303b04a
Removed RmwService trait. Added documentation for Service trait
esteve 521c6cc
Added documentantion. Update field names
esteve 77c61f5
Added missing docstrings
esteve d6c8ba4
Fix formatting
esteve 5f6772e
Rearrange imports
esteve 3d79238
Fix doc reference
esteve 7578511
Ignore client-service examples for rustdoc
esteve ec36503
Split rmw and idiomatic messages into separate templates
esteve 81edcee
Added rmw module in srv.rs.em
esteve 92c8a19
Remove std:: from vec macro
esteve c9a46fe
Apply suggestions from code review
esteve 1504f11
Simplify access to futures hashmap
esteve d2c72e3
Remove all unwraps
esteve 20a09d6
Removed self.sequence_number from the client
esteve 997838b
Update rclrs/src/node/client.rs
esteve 40cd43c
Pass the owned request to the callback instead of a reference
esteve b335735
Fix format
esteve 0a15a46
Removed ret variable for unsafe blocks
esteve 8abddd1
Require static for the Service trait
esteve a49d6ca
Reduce scope of node mutex
esteve 64f0ce0
Update comments
esteve 2786288
Type alias request ids
esteve 9d3ee71
Avoid calling unwrap for type support strings
esteve dafe86c
Use tokio::task::spawn_blocking for spawning rclrs::spin
esteve 1542158
Call unwrap()
esteve 5c261fe
Added safety comment
esteve 85d6ed7
Added safety comment
esteve 7c82bb0
Added safety comment
esteve 3adcf60
Added safety comment
esteve d336380
Added ok()?
esteve 9766c33
Added safety comments
esteve 93421fe
Use request id alias
esteve 643c555
Added safety comments
esteve 25b378a
Fix formatting
esteve d1eed67
Added safety comments
esteve ce9c935
Added safety comments
esteve 3e3d2d9
Apply suggestions from code review
esteve 284cecd
Pass owned responses to client calls
esteve 6f2aa36
Call ok() right after the unsafe call
esteve 70f41be
Added comment to service struct
esteve e99d1ec
Do not panic if future is dropped
esteve 1656653
Fix formatting
esteve 34bdc08
Added comment about why calling unwrap is safe
esteve 679b028
Removed map_err
esteve 4191195
Use double slashes for comments for take_* functions
esteve e149424
Fix docstrings
esteve e1b02d2
Simplify unwrap_or call
esteve 1c5064b
Apply suggestions from code review
esteve d085a24
Removed dependency
esteve a87318e
Removed dependency
esteve 051b828
Removed dependency
esteve bf61831
Ignore result
esteve b59bb9a
Added clients and services to the list of supported features
esteve 51141b4
Added comment to service struct
esteve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "examples_rclrs_minimal_client_service" | ||
version = "0.2.0" | ||
authors = ["Esteve Fernandez <esteve@apache.org>"] | ||
edition = "2021" | ||
|
||
[[bin]] | ||
name = "minimal_client" | ||
path = "src/minimal_client.rs" | ||
|
||
[[bin]] | ||
name = "minimal_client_async" | ||
path = "src/minimal_client_async.rs" | ||
|
||
[[bin]] | ||
name = "minimal_service" | ||
path = "src/minimal_service.rs" | ||
|
||
[dependencies] | ||
anyhow = {version = "1", features = ["backtrace"]} | ||
tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread", "time"] } | ||
|
||
[dependencies.rclrs] | ||
version = "*" | ||
|
||
[dependencies.rosidl_runtime_rs] | ||
version = "*" | ||
|
||
[dependencies.example_interfaces] | ||
version = "*" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model | ||
href="http://download.ros.org/schema/package_format3.xsd" | ||
schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>examples_rclrs_minimal_client_service</name> | ||
<version>0.2.0</version> | ||
<description>Package containing an example of the client-service mechanism in rclrs.</description> | ||
<maintainer email="esteve@apache.org">Esteve Fernandez</maintainer> | ||
<license>Apache License 2.0</license> | ||
|
||
<build_depend>example_interfaces</build_depend> | ||
<build_depend>rclrs</build_depend> | ||
<build_depend>rosidl_runtime_rs</build_depend> | ||
|
||
<exec_depend>example_interfaces</exec_depend> | ||
<exec_depend>rclrs</exec_depend> | ||
<exec_depend>rosidl_runtime_rs</exec_depend> | ||
|
||
<export> | ||
<build_type>ament_cargo</build_type> | ||
</export> | ||
</package> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use anyhow::{Error, Result}; | ||
use std::env; | ||
|
||
fn main() -> Result<(), Error> { | ||
let context = rclrs::Context::new(env::args())?; | ||
|
||
let mut node = context.create_node("minimal_client")?; | ||
|
||
let client = node.create_client::<example_interfaces::srv::AddTwoInts>("add_two_ints")?; | ||
|
||
let request = example_interfaces::srv::AddTwoInts_Request { a: 41, b: 1 }; | ||
|
||
println!("Starting client"); | ||
|
||
std::thread::sleep(std::time::Duration::from_millis(500)); | ||
|
||
client.async_send_request_with_callback( | ||
&request, | ||
move |response: example_interfaces::srv::AddTwoInts_Response| { | ||
println!( | ||
"Result of {} + {} is: {}", | ||
request.a, request.b, response.sum | ||
); | ||
}, | ||
)?; | ||
|
||
std::thread::sleep(std::time::Duration::from_millis(500)); | ||
|
||
println!("Waiting for response"); | ||
rclrs::spin(&node).map_err(|err| err.into()) | ||
} |
32 changes: 32 additions & 0 deletions
32
examples/minimal_client_service/src/minimal_client_async.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use anyhow::{Error, Result}; | ||
use std::env; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Error> { | ||
let context = rclrs::Context::new(env::args())?; | ||
|
||
let mut node = context.create_node("minimal_client")?; | ||
|
||
let client = node.create_client::<example_interfaces::srv::AddTwoInts>("add_two_ints")?; | ||
|
||
println!("Starting client"); | ||
|
||
std::thread::sleep(std::time::Duration::from_millis(500)); | ||
|
||
let request = example_interfaces::srv::AddTwoInts_Request { a: 41, b: 1 }; | ||
|
||
let future = client.call_async(&request); | ||
|
||
println!("Waiting for response"); | ||
|
||
let rclrs_spin = tokio::task::spawn_blocking(move || rclrs::spin(&node)); | ||
|
||
let response = future.await?; | ||
println!( | ||
"Result of {} + {} is: {}", | ||
request.a, request.b, response.sum | ||
); | ||
|
||
rclrs_spin.await.ok(); | ||
Ok(()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use anyhow::{Error, Result}; | ||
use std::env; | ||
|
||
fn handle_service( | ||
_request_header: &rclrs::rmw_request_id_t, | ||
request: example_interfaces::srv::AddTwoInts_Request, | ||
) -> example_interfaces::srv::AddTwoInts_Response { | ||
println!("request: {} + {}", request.a, request.b); | ||
example_interfaces::srv::AddTwoInts_Response { | ||
sum: request.a + request.b, | ||
} | ||
} | ||
|
||
fn main() -> Result<(), Error> { | ||
let context = rclrs::Context::new(env::args())?; | ||
|
||
let mut node = context.create_node("minimal_service")?; | ||
|
||
let _server = node | ||
.create_service::<example_interfaces::srv::AddTwoInts, _>("add_two_ints", handle_service)?; | ||
|
||
println!("Starting server"); | ||
rclrs::spin(&node).map_err(|err| err.into()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.