-
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.
initial version of plugin based storage api
- Loading branch information
1 parent
779eaae
commit b2e20ac
Showing
13 changed files
with
582 additions
and
10 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
63 changes: 63 additions & 0 deletions
63
rosbag2_storage/cmake/rosbag2_storage_register_storage_plugin.cmake
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,63 @@ | ||
# Copyright 2018 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. | ||
|
||
find_package(ament_cmake_core REQUIRED) | ||
|
||
macro(rosbag2_storage_register_storage_plugin target) | ||
if(NOT TARGET ${target}) | ||
message( | ||
FATAL_ERROR | ||
"rosbag2_storage_register_storage_plugin() first argument " | ||
"'${target}' is not a target") | ||
endif() | ||
|
||
cmake_parse_arguments(_ARG "SKIP_INSTALL" "" "" ${ARGN}) | ||
|
||
get_target_property(_target_type ${target} TYPE) | ||
if(NOT _target_type STREQUAL "SHARED_LIBRARY") | ||
message( | ||
FATAL_ERROR | ||
"rosbag2_storage_register_storage_plugin() first argument " | ||
"'${target}' is not a shared library target") | ||
endif() | ||
set(_unique_names) | ||
foreach(_arg ${_ARG_UNPARSED_ARGUMENTS}) | ||
if(_arg IN_LIST _unique_names) | ||
message( | ||
FATAL_ERROR | ||
"rosbag2_storage_register_storage_plugin() the plugin names " | ||
"must be unique (multiple '${_arg}')") | ||
endif() | ||
list(APPEND _unique_names "${_arg}") | ||
|
||
if(_ARG_SKIP_INSTALL) | ||
set(_library_path $<TARGET_FILE:${target}>) | ||
else() | ||
if(WIN32) | ||
set(_path "bin") | ||
else() | ||
set(_path "lib") | ||
endif() | ||
set(_library_path ${_path}/$<TARGET_FILE_NAME:${target}>) | ||
endif() | ||
set(_STORAGE_PLUGINS | ||
"${_STORAGE_PLUGINS}${_arg};${_library_path}\n") | ||
endforeach() | ||
|
||
if(_ARG_SKIP_INSTALL) | ||
ament_index_register_resource("rosbag2_storage_plugins" CONTENT ${_STORAGE_PLUGINS} AMENT_INDEX_BINARY_DIR "${CMAKE_BINARY_DIR}/ament_cmake_index_$<CONFIG>" SKIP_INSTALL) | ||
else() | ||
ament_index_register_resource("rosbag2_storage_plugins" CONTENT ${_STORAGE_PLUGINS}) | ||
endif() | ||
endmacro() |
52 changes: 52 additions & 0 deletions
52
rosbag2_storage/include/rosbag2_storage/storage_factory.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,52 @@ | ||
// Copyright 2018 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 ROSBAG2_STORAGE__STORAGE_FACTORY_HPP_ | ||
#define ROSBAG2_STORAGE__STORAGE_FACTORY_HPP_ | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "rosbag2_storage/storage_interface.hpp" | ||
#include "rosbag2_storage/visibility_control.h" | ||
|
||
namespace rosbag2_storage | ||
{ | ||
|
||
class StorageFactoryImpl; | ||
|
||
/// Factory to create instances for various storage interfaces | ||
class StorageFactory | ||
{ | ||
public: | ||
explicit StorageFactory(const std::string & storage_identifier); | ||
|
||
virtual ~StorageFactory(); | ||
|
||
/// Static function to create \sa StorageInterface given the storage_identifier | ||
/** | ||
* The function returns the StorageInterface base class for a specific identifier. | ||
* \param storage_identifier unique string indicating which storage format to use. | ||
*/ | ||
ROSBAG2_STORAGE_PUBLIC | ||
std::shared_ptr<StorageInterface> | ||
get_storage_interface(); | ||
|
||
private: | ||
std::unique_ptr<StorageFactoryImpl> impl_; | ||
}; | ||
|
||
} // namespace rosbag2_storage | ||
|
||
#endif // ROSBAG2_STORAGE__STORAGE_FACTORY_HPP_ |
33 changes: 33 additions & 0 deletions
33
rosbag2_storage/include/rosbag2_storage/storage_handle.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,33 @@ | ||
// Copyright 2018 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 ROSBAG2_STORAGE__STORAGE_HANDLE_HPP_ | ||
#define ROSBAG2_STORAGE__STORAGE_HANDLE_HPP_ | ||
|
||
#include <string> | ||
|
||
#include "rosbag2_storage/visibility_control.h" | ||
|
||
namespace rosbag2_storage | ||
{ | ||
|
||
typedef struct ROSBAG2_STORAGE_PUBLIC_TYPE StorageHandle | ||
{ | ||
std::string storage_identifier; | ||
std::string file_path; | ||
} StorageHandle; | ||
|
||
} // rosbag2_storage | ||
|
||
#endif // ROSBAG2_STORAGE__STORAGE_HANDLE_HPP_ |
78 changes: 78 additions & 0 deletions
78
rosbag2_storage/include/rosbag2_storage/storage_interface.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,78 @@ | ||
// Copyright 2018 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 ROSBAG2_STORAGE__STORAGE_INTERFACE_HPP_ | ||
#define ROSBAG2_STORAGE__STORAGE_INTERFACE_HPP_ | ||
|
||
#include <string> | ||
|
||
#include "rosbag2_storage/storage_handle.hpp" | ||
#include "rosbag2_storage/visibility_control.h" | ||
|
||
namespace rosbag2_storage | ||
{ | ||
|
||
/// Abstract base class for the storage API | ||
/** | ||
* Every storage plugin shall implement this interface | ||
* in order to be able to get correctly loaded by the storage API. | ||
*/ | ||
class StorageInterface | ||
{ | ||
public: | ||
ROSBAG2_STORAGE_PUBLIC | ||
StorageInterface() = default; | ||
|
||
ROSBAG2_STORAGE_PUBLIC | ||
virtual ~StorageInterface() = default; | ||
|
||
/// Open the bag file given the specified path | ||
/** | ||
* The function opens the bag file and returns a handle to it. | ||
* \param file_path the fqdn path to the bag to be loaded | ||
*/ | ||
ROSBAG2_STORAGE_PUBLIC | ||
virtual | ||
StorageHandle | ||
open(const std::string & file_path) = 0; | ||
|
||
/// Close the bag | ||
/** | ||
* The function closes the bag file which was previously opened by \sa open. | ||
* \param storage_handle is the returned handle after opening the bag. | ||
*/ | ||
ROSBAG2_STORAGE_PUBLIC | ||
virtual | ||
bool | ||
close(StorageHandle & storage_handle) = 0; | ||
|
||
ROSBAG2_STORAGE_PUBLIC | ||
virtual | ||
void | ||
set_storage_identifier(const std::string & storage_identifier) = 0; | ||
|
||
/// Get the identifier for this storage handle | ||
/** | ||
* The function returns the unique identifier for this storage format | ||
* \return string identifying the storage format | ||
*/ | ||
ROSBAG2_STORAGE_PUBLIC | ||
virtual | ||
std::string | ||
get_storage_identifier() = 0; | ||
}; | ||
|
||
} // namespace rosbag2_storage | ||
|
||
#endif // ROSBAG2_STORAGE__STORAGE_INTERFACE_HPP_ |
56 changes: 56 additions & 0 deletions
56
rosbag2_storage/include/rosbag2_storage/visibility_control.h
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,56 @@ | ||
// Copyright 2018 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. | ||
|
||
/* This header must be included by all rclcpp headers which declare symbols | ||
* which are defined in the rclcpp library. When not building the rclcpp | ||
* library, i.e. when using the headers in other package's code, the contents | ||
* of this header change the visibility of certain symbols which the rclcpp | ||
* library cannot have, but the consuming code must have inorder to link. | ||
*/ | ||
|
||
#ifndef ROSBAG2_STORAGE__VISIBILITY_CONTROL_H_ | ||
#define ROSBAG2_STORAGE__VISIBILITY_CONTROL_H_ | ||
|
||
// This logic was borrowed (then namespaced) from the examples on the gcc wiki: | ||
// https://gcc.gnu.org/wiki/Visibility | ||
|
||
#if defined _WIN32 || defined __CYGWIN__ | ||
#ifdef __GNUC__ | ||
#define ROSBAG2_STORAGE_EXPORT __attribute__ ((dllexport)) | ||
#define ROSBAG2_STORAGE_IMPORT __attribute__ ((dllimport)) | ||
#else | ||
#define ROSBAG2_STORAGE_EXPORT __declspec(dllexport) | ||
#define ROSBAG2_STORAGE_IMPORT __declspec(dllimport) | ||
#endif | ||
#ifdef ROSBAG2_STORAGE_BUILDING_DLL | ||
#define ROSBAG2_STORAGE_PUBLIC ROSBAG2_STORAGE_EXPORT | ||
#else | ||
#define ROSBAG2_STORAGE_PUBLIC ROSBAG2_STORAGE_IMPORT | ||
#endif | ||
#define ROSBAG2_STORAGE_PUBLIC_TYPE ROSBAG2_STORAGE_PUBLIC | ||
#define ROSBAG2_STORAGE_LOCAL | ||
#else | ||
#define ROSBAG2_STORAGE_EXPORT __attribute__ ((visibility("default"))) | ||
#define ROSBAG2_STORAGE_IMPORT | ||
#if __GNUC__ >= 4 | ||
#define ROSBAG2_STORAGE_PUBLIC __attribute__ ((visibility("default"))) | ||
#define ROSBAG2_STORAGE_LOCAL __attribute__ ((visibility("hidden"))) | ||
#else | ||
#define ROSBAG2_STORAGE_PUBLIC | ||
#define ROSBAG2_STORAGE_LOCAL | ||
#endif | ||
#define ROSBAG2_STORAGE_PUBLIC_TYPE | ||
#endif | ||
|
||
#endif // ROSBAG2_STORAGE__VISIBILITY_CONTROL_H_ |
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
Oops, something went wrong.