-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add plugin development documentation
- Loading branch information
1 parent
2865679
commit af77c5b
Showing
1 changed file
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Writing storage plugins | ||
|
||
There are different interfaces for storage plugins depending on your need: The general `ReadWriteStorage` and the more specific `ReadableStorage`. | ||
|
||
## Writing a general plugin | ||
|
||
Assume you write a plugin `MyStorage` which can both save messages and read messages. | ||
Its header file could be `my_storage.hpp` and it would derive from `rosbag2_storage::ReadWriteStorage`. | ||
While implementing the interface provided by `rosbag2_storage::ReadWriteStorage`, make sure that all resources such as file handles or database connections are closed or destroyed in the destructor, no additional `close` call should be necessary. | ||
|
||
In order to find the plugin at runtime, it needs to be exported to the pluginlib. | ||
Add the following lines to `my_storage.cpp`: | ||
|
||
``` | ||
#include "pluginlib/class_list_macros.hpp" | ||
PLUGINLIB_EXPORT_CLASS(MyStorage, rosbag2_storage::ReadWriteStorage) | ||
``` | ||
|
||
Furthermore, we need some meta-information in the form of a `plugin_description.xml` file. | ||
Here, it contains | ||
|
||
``` | ||
<library path="my_storage_lib"> | ||
<class name="my_storage" type="MyStorage" base_class_type="rosbag2_storage::ReadWriteStorage"> | ||
</class> | ||
</library> | ||
``` | ||
Here, `my_storage_lib` is the name of the library while `my_storage` is an identifier used by the pluginlib to load it. | ||
|
||
In addition, in the `CMakeLists.txt` plugins and `plugin_description` file need to be added to the index to be found at runtime: | ||
|
||
`pluginlib_export_plugin_description_file(rosbag2_storage plugin_description.xml)` | ||
|
||
The first argument `rosbag2_storage` denotes the library we add our plugin to, while the second argument is the path to the plugin description file. | ||
|
||
## Writing a plugin for reading only | ||
|
||
When writing plugins to only provide functionality for reading, derive from `rosbag2_storage::ReadableStorage`. | ||
|
||
If the read-only plugin is called `my_readonly_storage` in a library `my_storage_lib`, it will be registered using | ||
|
||
``` | ||
#include "pluginlib/class_list_macros.hpp" | ||
PLUGINLIB_EXPORT_CLASS(MyReadonlyStorage, rosbag2_storage::ReadableStorage) | ||
``` | ||
with the plugin description | ||
``` | ||
<library path="my_storage_lib"> | ||
<class name="my_readonly_storage" type="MyReadonlyStorage" base_class_type="rosbag2_storage::ReadableStorage"> | ||
</class> | ||
</library> | ||
``` | ||
and the usual pluginlib export in the CMakeLists: | ||
|
||
`pluginlib_export_plugin_description_file(rosbag2_storage plugin_description.xml)` |