Commit 3ee657c1 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Revert "EventManager: Do not copy construct event handlers."

This reverts commit 8e8c1672.
This feels too much like a bad idea.
parent 27bbfad9
......@@ -36,18 +36,9 @@ int main(int ac, char** av)
const char* vlcArgs = "-vv";
auto instance = VLC::Instance(1, &vlcArgs);
{
auto exitHandler = [] {
std::cout << "Libvlc is exiting" << std::endl;
};
// Uncommenting this line would cause undefined behavior, as libvlcpp
// would store a reference, which would become dangling as soon as
// we leave this scope.
//instance.setExitHandler( exitHandler );
// This is fine, since we are moving the exitHandler. No dangling ref.
instance.setExitHandler( std::move( exitHandler ) );
}
instance.setExitHandler([] {
std::cout << "Libvlc is exiting" << std::endl;
});
instance.logSet([](int lvl, const libvlc_log_t*, std::string message ) {
std::cout << "Hooked VLC log: " << lvl << ' ' << message << std::endl;
......
......@@ -41,11 +41,9 @@ namespace VLC
/**
* @brief This class serves as a base for all event managers.
*
* Event handlers can be anything which implement the Callable concept
* (http://en.cppreference.com/w/cpp/concept/Callable)
* libvlcpp can take ownership (ie. move it to an internal storage) of your handler.
* If you provide a rvalue, libvlcpp will store a reference to the handler.
* If you provide a lvalue, libvlcpp will move the handler internaly.
* All events can be handled by providing a std::function.
* libvlcpp will take ownership (ie. the function will be moved inside an internal list)
* If the provided std::function is a lambda, it may capture anything you desire
*/
class EventManager : public Internal<libvlc_event_manager_t>
{
......@@ -106,7 +104,9 @@ private:
private:
// Deduced type is Func& in case of lvalue; Func in case of rvalue.
Func m_userCallback;
// We decay the type to ensure we either copy or take ownership.
// Taking a reference would quite likely lead to unexpected behavior
typename std::decay<Func>::type m_userCallback;
// EventManager always outlive EventHandler, no need for smart pointer
EventManager* m_eventManager;
Wrapper m_wrapper;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment