mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-28 18:32:38 +00:00
Added the ability to run queries directly, without going through the
library.
This commit is contained in:
parent
43c23c3f34
commit
4f536c3d6e
@ -40,6 +40,7 @@
|
||||
#include <core/runtime/MessageQueue.h>
|
||||
#include <core/runtime/Message.h>
|
||||
#include <core/library/LibraryFactory.h>
|
||||
#include <core/library/LocalLibrary.h>
|
||||
#include <core/audio/PlaybackService.h>
|
||||
#include <core/plugin/Plugins.h>
|
||||
#include <core/library/LocalMetadataProxy.h>
|
||||
@ -53,6 +54,7 @@
|
||||
|
||||
using namespace musik;
|
||||
using namespace musik::core;
|
||||
using namespace musik::core::library;;
|
||||
using namespace musik::core::db::local;
|
||||
using namespace musik::core::audio;
|
||||
using namespace musik::core::sdk;
|
||||
@ -165,6 +167,11 @@ mcsdk_export void mcsdk_context_init(mcsdk_context** context) {
|
||||
c->playback.opaque = internal->playback;
|
||||
c->library.opaque = internal->library.get();
|
||||
|
||||
auto localLibrary = dynamic_cast<LocalLibrary*>(internal->library.get());
|
||||
if (localLibrary) {
|
||||
c->db.opaque = localLibrary;
|
||||
}
|
||||
|
||||
auto indexer = internal->library->Indexer();
|
||||
auto indexer_internal = new mcsdk_svc_indexer_context_internal();
|
||||
indexer_internal->indexer = indexer;
|
||||
|
@ -1252,16 +1252,18 @@ class mcsdk_db_wrapped_query: public LocalQueryBase {
|
||||
mcsdk_db_wrapped_query(
|
||||
mcsdk_svc_library library,
|
||||
const std::string& name,
|
||||
void* user_context,
|
||||
mcsdk_svc_library_run_query_callback cb)
|
||||
{
|
||||
this->library = library;
|
||||
this->name = name;
|
||||
this->user_context = user_context;
|
||||
this->cb = cb;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool OnRun(musik::core::db::Connection& db) {
|
||||
return cb(this->library, { &db });
|
||||
return cb(this->library, { &db }, this->user_context);
|
||||
}
|
||||
|
||||
virtual std::string Name() {
|
||||
@ -1271,11 +1273,12 @@ class mcsdk_db_wrapped_query: public LocalQueryBase {
|
||||
private:
|
||||
mcsdk_svc_library library;
|
||||
std::string name;
|
||||
void* user_context;
|
||||
mcsdk_svc_library_run_query_callback cb;
|
||||
};
|
||||
|
||||
mcsdk_export void mcsdk_svc_library_run_query(mcsdk_svc_library l, const char* name, mcsdk_svc_library_run_query_callback cb, mcsdk_svc_library_query_flag flags) {
|
||||
LIBRARY(l)->Enqueue(std::make_shared<mcsdk_db_wrapped_query>(l, name, cb));
|
||||
mcsdk_export void mcsdk_svc_library_run_query(mcsdk_svc_library l, const char* name, void* user_context, mcsdk_svc_library_run_query_callback cb, mcsdk_svc_library_query_flag flags) {
|
||||
LIBRARY(l)->Enqueue(std::make_shared<mcsdk_db_wrapped_query>(l, name, user_context, cb));
|
||||
}
|
||||
|
||||
mcsdk_export int mcsdk_svc_library_get_id(mcsdk_svc_library l) {
|
||||
|
@ -82,6 +82,7 @@ namespace musik { namespace core { namespace library {
|
||||
virtual void ProcessMessage(musik::core::runtime::IMessage &message) override;
|
||||
|
||||
/* implementation specific */
|
||||
db::Connection& GetConnection() { return this->db; }
|
||||
std::string GetLibraryDirectory();
|
||||
std::string GetDatabaseFilename();
|
||||
static void CreateDatabase(db::Connection &db);
|
||||
|
@ -281,7 +281,7 @@ typedef struct mcsdk_audio_player_gain {
|
||||
float peakValid;
|
||||
} mcsdk_audio_player_gain;
|
||||
|
||||
typedef bool (*mcsdk_svc_library_run_query_callback)(mcsdk_svc_library l, mcsdk_db_connection db);
|
||||
typedef bool (*mcsdk_svc_library_run_query_callback)(mcsdk_svc_library l, mcsdk_db_connection db, void* user_context);
|
||||
|
||||
/*
|
||||
* instance context
|
||||
@ -292,6 +292,7 @@ typedef struct mcsdk_context {
|
||||
mcsdk_svc_playback playback;
|
||||
mcsdk_svc_indexer indexer;
|
||||
mcsdk_svc_library library;
|
||||
mcsdk_db_connection db;
|
||||
mcsdk_prefs preferences;
|
||||
mcsdk_internal internal;
|
||||
} mcsdk_context;
|
||||
@ -654,7 +655,7 @@ mcsdk_export void mcsdk_svc_indexer_remove_callbacks(mcsdk_svc_indexer in, mcsdk
|
||||
* ILibrary
|
||||
*/
|
||||
|
||||
mcsdk_export void mcsdk_svc_library_run_query(mcsdk_svc_library l, const char* name, mcsdk_svc_library_run_query_callback cb, mcsdk_svc_library_query_flag flags);
|
||||
mcsdk_export void mcsdk_svc_library_run_query(mcsdk_svc_library l, const char* name, void* user_context, mcsdk_svc_library_run_query_callback cb, mcsdk_svc_library_query_flag flags);
|
||||
mcsdk_export int mcsdk_svc_library_get_id(mcsdk_svc_library l);
|
||||
mcsdk_export int mcsdk_svc_library_get_name(mcsdk_svc_library l, char* dst, int len);
|
||||
|
||||
|
@ -52,16 +52,16 @@ static void indexer_finished_callback(mcsdk_svc_indexer in, int total_updated_co
|
||||
printf("[indexer_finished_callback] %d\n", total_updated_count);
|
||||
}
|
||||
|
||||
static bool run_test_query_callback(mcsdk_svc_library library, mcsdk_db_connection connection) {
|
||||
static bool run_test_query_callback(mcsdk_svc_library library, mcsdk_db_connection connection, void* user_context) {
|
||||
bool result = false;
|
||||
mcsdk_db_statement stmt = mcsdk_db_statement_create(connection, "SELECT COUNT(*) FROM tracks");
|
||||
if (mcsdk_db_statement_step(stmt) == mcsdk_db_result_row) {
|
||||
int total_tracks = mcsdk_db_statement_column_int64(stmt, 0);
|
||||
printf("[run_test_query_callback] success! %d total tracks", total_tracks);
|
||||
printf("[run_test_query_callback] success! %d total tracks\n", total_tracks);
|
||||
result = true;
|
||||
}
|
||||
else {
|
||||
printf("[run_test_query_callback] failed");
|
||||
printf("[run_test_query_callback] failed\n");
|
||||
}
|
||||
mcsdk_db_statement_release(stmt);
|
||||
return result;
|
||||
@ -181,6 +181,7 @@ static void test_library(mcsdk_context* context) {
|
||||
mcsdk_svc_library_run_query(
|
||||
context->library,
|
||||
"test query",
|
||||
NULL,
|
||||
run_test_query_callback,
|
||||
mcsdk_svc_library_query_flag_synchronous);
|
||||
}
|
||||
@ -203,9 +204,9 @@ int main(int argc, char** argv) {
|
||||
mcsdk_context_init(&context);
|
||||
if (context) {
|
||||
printf("[main] context initialized\n");
|
||||
test_library(context);
|
||||
test_indexer(context);
|
||||
test_metadata(context);
|
||||
test_library(context);
|
||||
test_low_level_playback();
|
||||
test_high_level_playback(context);
|
||||
test_decode_encode();
|
||||
|
Loading…
x
Reference in New Issue
Block a user