Go to the documentation of this file.
12 const auto extension = filepath.filename().extension();
13 if(extension !=
".db3" && extension !=
".btdb")
15 throw RuntimeError(
"SqliteLogger: the file extension must be [.db3] or [.btdb]");
20 db_ = std::make_unique<sqlite::Connection>(filepath.string());
23 "timestamp INTEGER PRIMARY KEY NOT NULL, "
24 "session_id INTEGER NOT NULL, "
25 "node_uid INTEGER NOT NULL, "
27 "state INTEGER NOT NULL,"
28 "extra_data VARCHAR );");
31 "session_id INTEGER NOT NULL, "
33 "node_uid INTEGER NOT NULL );");
36 "session_id INTEGER PRIMARY KEY AUTOINCREMENT, "
38 "xml_tree TEXT NOT NULL);");
49 "INSERT into Definitions (date, xml_tree) "
50 "VALUES (datetime('now','localtime'),?);",
54 "FROM Definitions LIMIT 1;");
61 for(
const auto& subtree : tree.
subtrees)
63 for(
const auto& node : subtree->nodes)
66 node->fullPath(), node->UID());
90 using namespace std::chrono;
91 int64_t tm_usec = int64_t(duration_cast<microseconds>(timestamp).
count());
94 long elapsed_time = 0;
107 elapsed_time -= it->second;
141 std::deque<Transition> transitions;
152 while(!transitions.empty())
154 auto const trans = transitions.front();
155 transitions.pop_front();
158 trans.timestamp,
session_id_, trans.node_uid, trans.duration,
159 static_cast<int>(trans.status), trans.extra_data);
166 sqlite3_db_cacheflush(
db_->GetPtr());
virtual void flush() override
SqliteLogger(const Tree &tree, std::filesystem::path const &file, bool append=false)
To correctly read this log with Groot2, you must use the suffix ".db3". Constructor will throw otherw...
void setAdditionalCallback(ExtraCallback func)
std::thread writer_thread_
ExtraCallback extra_func_
void execSqlStatement(std::string statement)
void enableTransitionToIdle(bool enable)
Abstract base class for Behavior Tree Nodes.
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
std::chrono::high_resolution_clock::duration Duration
std::unordered_map< const BT::TreeNode *, int64_t > starting_time_
std::string WriteTreeToXML(const Tree &tree, bool add_metadata, bool add_builtin_models)
WriteTreeToXML create a string that contains the XML that corresponds to a given tree....
std::deque< Transition > transitions_queue_
virtual void callback(Duration timestamp, const TreeNode &node, NodeStatus prev_status, NodeStatus status) override
void Statement(sqlite::Connection &connection, const std::string &command, const First &first, const Args... args)
constexpr auto count
Sink that counts all arguments.
int64_t monotonic_timestamp_
virtual ~SqliteLogger() override
std::condition_variable queue_cv_
std::vector< Subtree::Ptr > subtrees
std::function< std::string(Duration, const TreeNode &, NodeStatus, NodeStatus)> ExtraCallback
std::unique_ptr< sqlite::Connection > db_
CPP_SQLITE_NODISCARD Result Query(sqlite::Connection &connection, const std::string &command, const First &first, const Args... args)
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression, cppcoreguidelines-noexcept-swap, performance-noexcept-swap) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects