From b58c08150853b8055093dc116d407ffd543f8ec8 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 30 Oct 2023 15:47:38 +1100 Subject: add locale-aware colation to db indexes --- src/system_fsm/CMakeLists.txt | 2 +- src/system_fsm/booting.cpp | 2 ++ src/system_fsm/include/service_locator.hpp | 11 +++++++++++ src/system_fsm/running.cpp | 4 ++-- 4 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src/system_fsm') diff --git a/src/system_fsm/CMakeLists.txt b/src/system_fsm/CMakeLists.txt index 449e14cc..8535a0e7 100644 --- a/src/system_fsm/CMakeLists.txt +++ b/src/system_fsm/CMakeLists.txt @@ -5,5 +5,5 @@ idf_component_register( SRCS "system_fsm.cpp" "running.cpp" "booting.cpp" "idle.cpp" "service_locator.cpp" INCLUDE_DIRS "include" - REQUIRES "tinyfsm" "drivers" "database" "ui" "result" "events" "audio" "app_console" "battery") + REQUIRES "tinyfsm" "drivers" "database" "ui" "result" "events" "audio" "app_console" "battery" "locale") target_compile_options(${COMPONENT_LIB} PRIVATE ${EXTRA_WARNINGS}) diff --git a/src/system_fsm/booting.cpp b/src/system_fsm/booting.cpp index 82d83836..893a4560 100644 --- a/src/system_fsm/booting.cpp +++ b/src/system_fsm/booting.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: GPL-3.0-only */ +#include "collation.hpp" #include "system_fsm.hpp" #include @@ -76,6 +77,7 @@ auto Booting::entry() -> void { sServices->track_queue(std::make_unique()); sServices->tag_parser(std::make_unique()); + sServices->collator(locale::CreateCollator()); ESP_LOGI(kTag, "init bluetooth"); sServices->bluetooth(std::make_unique(sServices->nvs())); diff --git a/src/system_fsm/include/service_locator.hpp b/src/system_fsm/include/service_locator.hpp index 1dcf0f5e..24dc1eb9 100644 --- a/src/system_fsm/include/service_locator.hpp +++ b/src/system_fsm/include/service_locator.hpp @@ -10,6 +10,7 @@ #include "battery.hpp" #include "bluetooth.hpp" +#include "collation.hpp" #include "database.hpp" #include "gpios.hpp" #include "nvs.hpp" @@ -101,6 +102,15 @@ class ServiceLocator { queue_ = std::move(i); } + auto collator() -> locale::ICollator& { + assert(collator_ != nullptr); + return *collator_; + } + + auto collator(std::unique_ptr i) { + collator_ = std::move(i); + } + // Not copyable or movable. ServiceLocator(const ServiceLocator&) = delete; ServiceLocator& operator=(const ServiceLocator&) = delete; @@ -117,6 +127,7 @@ class ServiceLocator { std::shared_ptr database_; std::unique_ptr tag_parser_; + std::unique_ptr collator_; drivers::SdState sd_; }; diff --git a/src/system_fsm/running.cpp b/src/system_fsm/running.cpp index 567553a9..91cd46af 100644 --- a/src/system_fsm/running.cpp +++ b/src/system_fsm/running.cpp @@ -55,8 +55,8 @@ void Running::entry() { ESP_LOGI(kTag, "opening database"); sFileGatherer = new database::FileGathererImpl(); - auto database_res = - database::Database::Open(*sFileGatherer, sServices->tag_parser()); + auto database_res = database::Database::Open( + *sFileGatherer, sServices->tag_parser(), sServices->collator()); if (database_res.has_error()) { ESP_LOGW(kTag, "failed to open!"); events::System().Dispatch(StorageError{}); -- cgit v1.2.3