HydrogenAudio

Hosted Forums => foobar2000 => Development - (fb2k) => Topic started by: Ambit on 2012-01-02 04:09:01

Title: meta_db_io Callback Registration
Post by: Ambit on 2012-01-02 04:09:01
I'm wondering what exactly I have to do to register for callbacks when meta_db entries are modified.

Right now I am doing my testing by modifying the foo_tutorial1 plugin. Based off of how the menu entry is registered and how I saw things being done in foo_httpcontrol, in foo_tutorial1.cpp I added

Code: [Select]
class metadb_io_callback_tutorial1 : public metadb_io_callback_dynamic_impl_base
{
    virtual void on_change_sorted(const pfc::list_base_const_t<metadb_handle_ptr>& p_items_sorted, bool p_fromhook)
    {
        SharedVars::num_callbacks++;
    }
};

static metadb_io_callback_tutorial1 mdb_callback;
static service_ptr_t<metadb_io_v3> mdb_io;


and in on_init() I added:
Code: [Select]
mdb_io->register_callback(&mdb_callback);


This code all compiles just fine, but when I try to run Foobar with the plugin I get this error:
Failed to load DLL: foo_tutorial1.dll
Reason: Invalid access to memory location.

And, even though it says it didn't load the DLL, Foobar crashes when I close it. (http://pastebin.com/iU9b75GU)
Title: meta_db_io Callback Registration
Post by: kode54 on 2012-01-02 05:27:12
You probably want to use static_api_ptr_t<metadb_io_v3> to access that service. Oh, and I don't know if you can get away with using a static instance of the callback, that may or may not work.
Title: meta_db_io Callback Registration
Post by: Ambit on 2012-01-02 15:56:40
You probably want to use static_api_ptr_t<metadb_io_v3> to access that service. Oh, and I don't know if you can get away with using a static instance of the callback, that may or may not work.


I made those changes and moved the static_api_ptr_t line inside the oninit function and it is no longer crashing. However, I am not getting callbacks for the events I expected. Since the metadb_handle has a format title function, I thought I would be getting notified whenever a tag updates. Is there a way to get a callback for that or will I have to make a thread that continuously calls format_title on every item in the library until the result changes?