Skip to content

Commit

Permalink
Renaming: activate -> announce_route
Browse files Browse the repository at this point in the history
  • Loading branch information
JEnoch committed Jan 20, 2024
1 parent 42b02b8 commit 6faf70c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 26 deletions.
13 changes: 8 additions & 5 deletions zenoh-plugin-ros2dds/src/route_action_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ impl RouteActionCli<'_> {
})
}

async fn activate(&mut self) -> Result<(), String> {
// Announce the route over Zenoh via a LivelinessToken
async fn announce_route(&mut self) -> Result<(), String> {
self.is_active = true;

// create associated LivelinessToken
Expand All @@ -163,6 +164,7 @@ impl RouteActionCli<'_> {
&self.zenoh_key_expr_prefix,
&self.ros2_type,
)?;
log::debug!("{self} announce via token {liveliness_ke}");
let ros2_name = self.ros2_name.clone();
self.liveliness_token = Some(self.context.zsession
.liveliness()
Expand All @@ -178,8 +180,9 @@ impl RouteActionCli<'_> {
Ok(())
}

fn deactivate(&mut self) {
log::debug!("{self} deactivate");
// Retire the route over Zenoh removing the LivelinessToken
fn retire_route(&mut self) {
log::debug!("{self} retire");
// Drop Zenoh Publisher and Liveliness token
// The DDS Writer remains to be discovered by local ROS nodes
self.is_active = false;
Expand Down Expand Up @@ -256,7 +259,7 @@ impl RouteActionCli<'_> {
log::debug!("{self} now serving local nodes {:?}", self.local_nodes);
// if 1st local node added, activate the route
if self.local_nodes.len() == 1 {
if let Err(e) = self.activate().await {
if let Err(e) = self.announce_route().await {
log::error!("{self} activation failed: {e}");
}
}
Expand All @@ -274,7 +277,7 @@ impl RouteActionCli<'_> {
log::debug!("{self} now serving local nodes {:?}", self.local_nodes);
// if last local node removed, deactivate the route
if self.local_nodes.is_empty() {
self.deactivate();
self.retire_route();
}
}

Expand Down
13 changes: 8 additions & 5 deletions zenoh-plugin-ros2dds/src/route_action_srv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ impl RouteActionSrv<'_> {
})
}

async fn activate(&mut self) -> Result<(), String> {
// Announce the route over Zenoh via a LivelinessToken
async fn announce_route(&mut self) -> Result<(), String> {
self.is_active = true;

// create associated LivelinessToken
Expand All @@ -149,6 +150,7 @@ impl RouteActionSrv<'_> {
&self.zenoh_key_expr_prefix,
&self.ros2_type,
)?;
log::debug!("{self} announce via token {liveliness_ke}");
let ros2_name = self.ros2_name.clone();
self.liveliness_token = Some(self.context.zsession
.liveliness()
Expand All @@ -164,8 +166,9 @@ impl RouteActionSrv<'_> {
Ok(())
}

fn deactivate(&mut self) {
log::debug!("{self} deactivate");
// Retire the route over Zenoh removing the LivelinessToken
fn retire_route(&mut self) {
log::debug!("{self} retire");
// Drop Zenoh Publisher and Liveliness token
// The DDS Writer remains to be discovered by local ROS nodes
self.is_active = false;
Expand Down Expand Up @@ -242,7 +245,7 @@ impl RouteActionSrv<'_> {
log::debug!("{self} now serving local nodes {:?}", self.local_nodes);
// if 1st local node added, activate the route
if self.local_nodes.len() == 1 {
if let Err(e) = self.activate().await {
if let Err(e) = self.announce_route().await {
log::error!("{self} activation failed: {e}");
}
}
Expand All @@ -260,7 +263,7 @@ impl RouteActionSrv<'_> {
log::debug!("{self} now serving local nodes {:?}", self.local_nodes);
// if last local node removed, deactivate the route
if self.local_nodes.is_empty() {
self.deactivate();
self.retire_route();
}
}

Expand Down
2 changes: 0 additions & 2 deletions zenoh-plugin-ros2dds/src/route_publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ impl RoutePublisher<'_> {
.map_err(|e| format!("Failed to lisetn of matchibng status changes: {e}",))?
};

// Ok(route)

Ok(RoutePublisher {
ros2_name,
ros2_type,
Expand Down
13 changes: 8 additions & 5 deletions zenoh-plugin-ros2dds/src/route_service_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ impl RouteServiceCli<'_> {
})
}

async fn activate(&mut self) -> Result<(), String> {
// Announce the route over Zenoh via a LivelinessToken
async fn announce_route(&mut self) -> Result<(), String> {
self.is_active = true;

// if not for an Action (since actions declare their own liveliness)
Expand All @@ -201,6 +202,7 @@ impl RouteServiceCli<'_> {
&self.zenoh_key_expr,
&self.ros2_type,
)?;
log::debug!("{self} announce via token {liveliness_ke}");
let ros2_name = self.ros2_name.clone();
self.liveliness_token = Some(self.context.zsession
.liveliness()
Expand All @@ -217,8 +219,9 @@ impl RouteServiceCli<'_> {
Ok(())
}

fn deactivate(&mut self) {
log::debug!("{self} deactivate");
// Retire the route over Zenoh removing the LivelinessToken
fn retire_route(&mut self) {
log::debug!("{self} retire");
// Drop Zenoh Publisher and Liveliness token
// The DDS Writer remains to be discovered by local ROS nodes
self.is_active = false;
Expand Down Expand Up @@ -250,7 +253,7 @@ impl RouteServiceCli<'_> {
log::debug!("{self} now serving local nodes {:?}", self.local_nodes);
// if 1st local node added, activate the route
if self.local_nodes.len() == 1 {
if let Err(e) = self.activate().await {
if let Err(e) = self.announce_route().await {
log::error!("{self} activation failed: {e}");
}
}
Expand All @@ -262,7 +265,7 @@ impl RouteServiceCli<'_> {
log::debug!("{self} now serving local nodes {:?}", self.local_nodes);
// if last local node removed, deactivate the route
if self.local_nodes.is_empty() {
self.deactivate();
self.retire_route();
}
}

Expand Down
13 changes: 8 additions & 5 deletions zenoh-plugin-ros2dds/src/route_service_srv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ impl RouteServiceSrv<'_> {
})
}

async fn activate(&mut self) -> Result<(), String> {
// Announce the route over Zenoh via a LivelinessToken
async fn announce_route(&mut self) -> Result<(), String> {
// For lifetime issue, redeclare the zenoh key expression that can't be stored in Self
let declared_ke = self
.context
Expand Down Expand Up @@ -262,6 +263,7 @@ impl RouteServiceSrv<'_> {
&self.zenoh_key_expr,
&self.ros2_type,
)?;
log::debug!("{self} announce via token {liveliness_ke}");
let ros2_name = self.ros2_name.clone();
self.liveliness_token = Some(self.context.zsession
.liveliness()
Expand All @@ -278,8 +280,9 @@ impl RouteServiceSrv<'_> {
Ok(())
}

fn deactivate(&mut self) {
log::debug!("{self} deactivate");
// Retire the route over Zenoh removing the LivelinessToken
fn retire_route(&mut self) {
log::debug!("{self} retire");
// Drop Zenoh Publisher and Liveliness token
// The DDS Writer remains to be discovered by local ROS nodes
self.zenoh_queryable = None;
Expand Down Expand Up @@ -311,7 +314,7 @@ impl RouteServiceSrv<'_> {
log::debug!("{self} now serving local nodes {:?}", self.local_nodes);
// if 1st local node added, activate the route
if self.local_nodes.len() == 1 {
if let Err(e) = self.activate().await {
if let Err(e) = self.announce_route().await {
log::error!("{self} activation failed: {e}");
}
}
Expand All @@ -323,7 +326,7 @@ impl RouteServiceSrv<'_> {
log::debug!("{self} now serving local nodes {:?}", self.local_nodes);
// if last local node removed, deactivate the route
if self.local_nodes.is_empty() {
self.deactivate();
self.retire_route();
}
}

Expand Down
10 changes: 6 additions & 4 deletions zenoh-plugin-ros2dds/src/route_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ impl RouteSubscriber<'_> {
})
}

async fn activate(&mut self, discovered_reader_qos: &Qos) -> Result<(), String> {
// Announce the route over Zenoh via a LivelinessToken
async fn announce_route(&mut self, discovered_reader_qos: &Qos) -> Result<(), String> {
log::debug!("{self} activate");
// Callback routing message received by Zenoh subscriber to DDS Writer (if set)
let ros2_name = self.ros2_name.clone();
Expand Down Expand Up @@ -232,7 +233,8 @@ impl RouteSubscriber<'_> {
Ok(())
}

fn deactivate(&mut self) {
// Retire the route over Zenoh removing the LivelinessToken
fn retire_route(&mut self) {
log::debug!("{self} deactivate");
// Drop Zenoh Subscriber and Liveliness token
// The DDS Writer remains to be discovered by local ROS nodes
Expand Down Expand Up @@ -306,7 +308,7 @@ impl RouteSubscriber<'_> {
log::debug!("{self} now serving local nodes {:?}", self.local_nodes);
// if 1st local node added, activate the route
if self.local_nodes.len() == 1 {
if let Err(e) = self.activate(discovered_reader_qos).await {
if let Err(e) = self.announce_route(discovered_reader_qos).await {
log::error!("{self} activation failed: {e}");
}
}
Expand All @@ -318,7 +320,7 @@ impl RouteSubscriber<'_> {
log::debug!("{self} now serving local nodes {:?}", self.local_nodes);
// if last local node removed, deactivate the route
if self.local_nodes.is_empty() {
self.deactivate();
self.retire_route();
}
}

Expand Down

0 comments on commit 6faf70c

Please sign in to comment.