[vlc-commits] Revert "EventManager: Do not copy construct event handlers."
Hugo Beauzée-Luyssen
git at videolan.org
Mon May 25 10:04:44 CEST 2015
libvlcpp | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Wed May 20 10:33:03 2015 +0200| [3ee657c1569efb330c642399d0d0cb92a2582680] | committer: Hugo Beauzée-Luyssen
Revert "EventManager: Do not copy construct event handlers."
This reverts commit 8e8c1672ae2619854d381485e280e15f88a81ead.
This feels too much like a bad idea.
> http://git.videolan.org/gitweb.cgi/libvlcpp.git/?a=commit;h=3ee657c1569efb330c642399d0d0cb92a2582680
---
test/main.cpp | 15 +++------------
vlcpp/EventManager.hpp | 12 ++++++------
2 files changed, 9 insertions(+), 18 deletions(-)
diff --git a/test/main.cpp b/test/main.cpp
index e005485..56c0db3 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -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;
diff --git a/vlcpp/EventManager.hpp b/vlcpp/EventManager.hpp
index 2141dec..c92d370 100644
--- a/vlcpp/EventManager.hpp
+++ b/vlcpp/EventManager.hpp
@@ -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;
More information about the vlc-commits
mailing list