Help - Search - Members - Calendar
Full Version: main_thread_callback_manager
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Development - (fb2k)
cwbowron
I'm trying to use the main_thread_callback_manager to setup a method to notify components of changes in the variables provided by cwb_hooks. But when I do what I think is the correct way, the callback_run method isnt called until I exit foobar2000. Below is a stripped down version of what I am doing. The messageboxes only popup after I exit foobar2000. If I cheat and just call p_callback->callback_run directly rather than add the callback to the manager, it works, so it appears the var_notify_callback is created correctly.

any help is appreciated.

CODE

class var_notify_callback : public main_thread_callback
{
public:
pfc::string8_fastalloc m_var;

var_notify_callback( const char * var )
{
m_var = var;
}

virtual void callback_run()
{
uMessageBox( NULL, "w00t", "w00t", MB_OK );
}
};


void post_callback_notification( const char * str )
{
service_ptr_t<var_notify_callback> p_callback = new service_impl_t<var_notify_callback>( str );
static_api_ptr_t<main_thread_callback_manager> man;
man->add_callback( p_callback );
}
cwbowron
Thought I had it, but still no. thought it was the lack of calling the base class creator in the derived var_notify_class, but that still doesnt do it.

CODE
class var_notify_callback : public main_thread_callback
{
public:
pfc::string8_fastalloc m_var;

var_notify_callback( const char * var )
: main_thread_callback()
{
m_var = var;
}

virtual void callback_run()
{
/* do something */
}
};
cwbowron
I have now really solved the problem.

post_callback_notification was getting called inside of a on_playlist_activate callback, which was happening before things had been initialized (at least prior to my getting notified in my on_initquit handler). When this happens none of the main thread callbacks were getting called until the program was exiting.

my fix was to set a global variable to false, then inside on_init set it to true to allow the callbacks to be posted.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.