Foobar as a UPnP renderer (player
Reply #29 – 2009-01-02 22:59:48
Depends on where you want to use it. If it's from an existing class, you can simply derive from main_thread_callback and provide its service interface. I assume you want to plug it into existing C code instead, so I'd use a helper class for delegation like this (not guaranteed to be 100% correct, I'm writing it out of my head only):class PlayAction : public main_thread_callback { protected: playback_control::t_track_command m_command; bool m_paused; public: PlayAction(playback_control::t_track_command p_command = playback_control::track_command_play, bool p_paused = false) : m_command(p_command), m_paused(p_paused) { } virtual void callback_run() { static_api_ptr_t<playback_control> pc; pc->start(m_command, m_paused); } }; // ... void on_command_play() { static_api_ptr_t<main_thread_callback_manager> mtcm; mtcm->add_callback(new service_impl_t<PlayAction>(playback_control::track_command_play)); } Note I didn't know what "play command" you really had had in mind, but I used playback_control::start() as to show how to pass any arguments. Anyway, this is a generic example. If you are going to support several commands, creating such class for each of them might be unnecessarily complex. In that case, it might be better to have just one class, encompassing interface for more commands at once, which will then invoke different methods in its callback_run() depending on what has been set. Or have most of the logic in the class itself and pass only the original events into it. There are many solutions as always, use the one which suits you best.