-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically transition lifecycle entities when node transitions (#1863
) * Automatically transition LifecyclePublisher(s) between activated and inactive Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com> * Fix: Add created publishers to the managed entities vector Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com> * enabled_ -> activated_ Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com> * Continue setting should_log_ as before Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com> * Fix visibility attributes so it works on Windows Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
- Loading branch information
Showing
9 changed files
with
168 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
68 changes: 68 additions & 0 deletions
68
rclcpp_lifecycle/include/rclcpp_lifecycle/managed_entity.hpp
This file contains 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,68 @@ | ||
// Copyright 2022 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef RCLCPP_LIFECYCLE__MANAGED_ENTITY_HPP_ | ||
#define RCLCPP_LIFECYCLE__MANAGED_ENTITY_HPP_ | ||
|
||
#include <atomic> | ||
|
||
#include "rclcpp_lifecycle/visibility_control.h" | ||
|
||
namespace rclcpp_lifecycle | ||
{ | ||
|
||
/// Base class for lifecycle entities, like `LifecyclePublisher`. | ||
class ManagedEntityInterface | ||
{ | ||
public: | ||
RCLCPP_LIFECYCLE_PUBLIC | ||
virtual | ||
~ManagedEntityInterface() {} | ||
|
||
RCLCPP_LIFECYCLE_PUBLIC | ||
virtual | ||
void | ||
on_activate() = 0; | ||
|
||
RCLCPP_LIFECYCLE_PUBLIC | ||
virtual | ||
void | ||
on_deactivate() = 0; | ||
}; | ||
|
||
/// A simple implementation of `ManagedEntityInterface`, which toogles a flag. | ||
class SimpleManagedEntity : public ManagedEntityInterface | ||
{ | ||
public: | ||
RCLCPP_LIFECYCLE_PUBLIC | ||
~SimpleManagedEntity() override = default; | ||
|
||
RCLCPP_LIFECYCLE_PUBLIC | ||
void | ||
on_activate() override; | ||
|
||
RCLCPP_LIFECYCLE_PUBLIC | ||
void | ||
on_deactivate() override; | ||
|
||
RCLCPP_LIFECYCLE_PUBLIC | ||
bool | ||
is_activated() const; | ||
|
||
private: | ||
std::atomic<bool> activated_ = false; | ||
}; | ||
|
||
} // namespace rclcpp_lifecycle | ||
#endif // RCLCPP_LIFECYCLE__MANAGED_ENTITY_HPP_ |
This file contains 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 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 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,35 @@ | ||
// Copyright 2022 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "rclcpp_lifecycle/managed_entity.hpp" | ||
|
||
namespace rclcpp_lifecycle | ||
{ | ||
|
||
void SimpleManagedEntity::on_activate() | ||
{ | ||
activated_.store(true); | ||
} | ||
|
||
void SimpleManagedEntity::on_deactivate() | ||
{ | ||
activated_.store(false); | ||
} | ||
|
||
bool SimpleManagedEntity::is_activated() const | ||
{ | ||
return activated_.load(); | ||
} | ||
|
||
} // namespace rclcpp_lifecycle |
This file contains 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