message_collection_helper.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 
3 /*
4  * Copyright (c) 2020, Bjarne von Horn
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  * * Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  * * Neither the name of the copyright holder nor the names of its contributors
15  * may be used to endorse or promote products derived from this software
16  * without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL BJARNE VON HORN BE LIABLE FOR ANY DIRECT,
22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 #pragma once
30 
33 #include <warehouse_ros_sqlite/warehouse_ros_sqlite_export.h>
34 
35 namespace warehouse_ros_sqlite
36 {
37 class WAREHOUSE_ROS_SQLITE_EXPORT MessageCollectionHelper : public warehouse_ros::MessageCollectionHelper
38 {
40  std::string collection_name_;
41  std::string db_name_;
42  std::string mangled_tablename_;
44 
45 public:
46  MessageCollectionHelper() = default;
47  MessageCollectionHelper(sqlite3_ptr db, const std::string& db_name, const std::string& name)
48  : db_(std::move(db))
49  , collection_name_(name)
50  , db_name_(db_name)
51  , mangled_tablename_(schema::mangle_database_and_collection_name(db_name, name))
52  , escaped_mangled_name_(schema::escape_and_mangle_database_and_collection_name(db_name, name))
53  {
54  }
55  bool initialize(const std::string& datatype, const std::string& md5) override;
56  void insert(char* msg, size_t msg_size, warehouse_ros::Metadata::ConstPtr metadata) override;
57  warehouse_ros::ResultIteratorHelper::Ptr query(warehouse_ros::Query::ConstPtr query, const std::string& sort_by = "",
58  bool ascending = true) const override;
59  unsigned removeMessages(warehouse_ros::Query::ConstPtr query) override;
60  void modifyMetadata(warehouse_ros::Query::ConstPtr q, warehouse_ros::Metadata::ConstPtr m) override;
61  unsigned count() override;
62  warehouse_ros::Query::Ptr createQuery() const override;
63  warehouse_ros::Metadata::Ptr createMetadata() const override;
64  std::string collectionName() const override
65  {
66  return collection_name_;
67  }
68 
69 private:
70  enum class Md5CompareResult
71  {
72  EMPTY,
73  MATCH,
74  MISMATCH
75  };
76  Md5CompareResult findAndMatchMd5Sum(const std::array<unsigned char, 16>& md5_bytes);
77 };
78 
79 } // namespace warehouse_ros_sqlite
warehouse_ros_sqlite
Definition: database_connection.h:36
warehouse_ros_sqlite::MessageCollectionHelper::mangled_tablename_
std::string mangled_tablename_
Definition: message_collection_helper.h:42
warehouse_ros_sqlite::schema::escape_and_mangle_database_and_collection_name
escaped_tablename escape_and_mangle_database_and_collection_name(const std::string &db_name, const std::string &collection_name)
Definition: utils.h:114
warehouse_ros_sqlite::schema::escaped_tablename
std::string escaped_tablename
Definition: utils.h:97
boost::shared_ptr< const Metadata >
warehouse_ros_sqlite::MessageCollectionHelper::MessageCollectionHelper
MessageCollectionHelper(sqlite3_ptr db, const std::string &db_name, const std::string &name)
Definition: message_collection_helper.h:47
warehouse_ros_sqlite::schema::mangle_database_and_collection_name
std::string mangle_database_and_collection_name(const std::string &db_name, const std::string &collection_name)
Definition: utils.h:110
warehouse_ros_sqlite::MessageCollectionHelper
Definition: message_collection_helper.h:37
utils.h
warehouse_ros::MessageCollectionHelper
warehouse_ros_sqlite::sqlite3_ptr
std::shared_ptr< sqlite3 > sqlite3_ptr
Definition: utils.h:51
warehouse_ros_sqlite::MessageCollectionHelper::Md5CompareResult
Md5CompareResult
Definition: message_collection_helper.h:70
warehouse_ros_sqlite::MessageCollectionHelper::db_
sqlite3_ptr db_
Definition: message_collection_helper.h:39
warehouse_ros_sqlite::MessageCollectionHelper::escaped_mangled_name_
schema::escaped_tablename escaped_mangled_name_
Definition: message_collection_helper.h:43
std
warehouse_ros_sqlite::MessageCollectionHelper::collectionName
std::string collectionName() const override
Definition: message_collection_helper.h:64
initialize
ROSCONSOLE_DECL void initialize()
warehouse_ros_sqlite::MessageCollectionHelper::collection_name_
std::string collection_name_
Definition: message_collection_helper.h:40
warehouse_ros_sqlite::MessageCollectionHelper::db_name_
std::string db_name_
Definition: message_collection_helper.h:41
message_collection.h


warehouse_ros_sqlite
Author(s): Bjarne von Horn
autogenerated on Mon Oct 14 2024 02:16:58