diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-04-27 12:55:30 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-04-27 12:55:30 +1000 |
| commit | 5d7cbec34cd5e473d5768b39054d99bc72ddad62 (patch) | |
| tree | f83040e527dc025345b3786a298f11e914b5eb37 /src/main/app_console.cpp | |
| parent | fbe047a35fff100cb5f42d10984bccde137f586e (diff) | |
| download | tangara-fw-5d7cbec34cd5e473d5768b39054d99bc72ddad62.tar.gz | |
Move DB interactions to a background thread
Diffstat (limited to 'src/main/app_console.cpp')
| -rw-r--r-- | src/main/app_console.cpp | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/src/main/app_console.cpp b/src/main/app_console.cpp index 859700f4..fc2a4fe5 100644 --- a/src/main/app_console.cpp +++ b/src/main/app_console.cpp @@ -154,48 +154,49 @@ int CmdDbInit(int argc, char** argv) { return 1; } - sInstance->database_->Initialise(); + sInstance->database_->Populate().get(); return 0; } void RegisterDbInit() { - esp_console_cmd_t cmd{.command = "db_init", - .help = "scans for playable files and adds them to the database", - .hint = NULL, - .func = &CmdDbInit, - .argtable = NULL}; + esp_console_cmd_t cmd{ + .command = "db_init", + .help = "scans for playable files and adds them to the database", + .hint = NULL, + .func = &CmdDbInit, + .argtable = NULL}; esp_console_cmd_register(&cmd); } -int CmdDbTitles(int argc, char** argv) { - static const std::string usage = "usage: db_titles"; +int CmdDbSongs(int argc, char** argv) { + static const std::string usage = "usage: db_songs"; if (argc != 1) { std::cout << usage << std::endl; return 1; } - database::Iterator it = sInstance->database_->ByTitle(); - while (true) { - std::optional<std::string> title = it.Next(); - if (!title) { - break; - } - std::cout << *title << std::endl; + database::DbResult<database::Song> res = + sInstance->database_->GetSongs(10).get(); + for (database::Song s : res.values()) { + std::cout << s.title << std::endl; } + return 0; } -void RegisterDbTitles() { - esp_console_cmd_t cmd{.command = "db_titles", +void RegisterDbSongs() { + esp_console_cmd_t cmd{.command = "db_songs", .help = "lists titles of ALL songs in the database", .hint = NULL, - .func = &CmdDbTitles, + .func = &CmdDbSongs, .argtable = NULL}; esp_console_cmd_register(&cmd); } -AppConsole::AppConsole(audio::AudioPlayback* playback, database::Database *database) : playback_(playback), database_(database) { +AppConsole::AppConsole(audio::AudioPlayback* playback, + database::Database* database) + : playback_(playback), database_(database) { sInstance = this; } AppConsole::~AppConsole() { @@ -209,7 +210,7 @@ auto AppConsole::RegisterExtraComponents() -> void { RegisterVolume(); RegisterAudioStatus(); RegisterDbInit(); - RegisterDbTitles(); + RegisterDbSongs(); } } // namespace console |
