-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds keyboard controls for ros2 bag play
Signed-off-by: Sonia Jin <[email protected]>
- Loading branch information
Showing
9 changed files
with
358 additions
and
6 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
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
73 changes: 73 additions & 0 deletions
73
rosbag2_transport/test/rosbag2_transport/mock_keyboard_handler.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,73 @@ | ||
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// 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 ROSBAG2_TRANSPORT__MOCK_KEYBOARD_HANDLER_HPP_ | ||
#define ROSBAG2_TRANSPORT__MOCK_KEYBOARD_HANDLER_HPP_ | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
#include "keyboard_handler/keyboard_handler.hpp" | ||
|
||
// press one specific key code one second at a time | ||
class MockKeyboardHandlerImpl : public KeyboardHandler | ||
{ | ||
public: | ||
MockKeyboardHandlerImpl( | ||
KeyboardHandler::KeyCode pause_resume_toggle_key, | ||
KeyboardHandler::KeyCode play_next_key) | ||
: pause_resume_toggle_key_(pause_resume_toggle_key), | ||
play_next_key_(play_next_key) | ||
{ | ||
is_init_succeed_ = true; | ||
} | ||
|
||
KEYBOARD_HANDLER_PUBLIC void pause_resume() | ||
{ | ||
press_key(pause_resume_toggle_key_); | ||
} | ||
|
||
KEYBOARD_HANDLER_PUBLIC void play_next() | ||
{ | ||
press_key(play_next_key_); | ||
} | ||
|
||
/// \brief destructor | ||
KEYBOARD_HANDLER_PUBLIC | ||
virtual ~MockKeyboardHandlerImpl() | ||
{ | ||
exit_ = true; | ||
} | ||
|
||
private: | ||
KeyboardHandler::KeyCode pause_resume_toggle_key_; | ||
KeyboardHandler::KeyCode play_next_key_; | ||
std::thread key_handler_thread_; | ||
std::atomic_bool exit_; | ||
std::exception_ptr thread_exception_ptr{nullptr}; | ||
|
||
void press_key(KeyboardHandler::KeyCode key_code) | ||
{ | ||
std::lock_guard<std::mutex> lk(callbacks_mutex_); | ||
KeyboardHandler::KeyModifiers key_modifiers = KeyboardHandler::KeyModifiers::NONE; | ||
auto range = callbacks_.equal_range(KeyAndModifiers{key_code, key_modifiers}); | ||
for (auto it = range.first; it != range.second; ++it) { | ||
it->second.callback(key_code, key_modifiers); | ||
} | ||
} | ||
}; | ||
|
||
#endif // ROSBAG2_TRANSPORT__MOCK_KEYBOARD_HANDLER_HPP_ |
Oops, something went wrong.