diff --git a/include/eepp/ui/models/filesystemmodel.hpp b/include/eepp/ui/models/filesystemmodel.hpp index ff3432402..aa96aef38 100644 --- a/include/eepp/ui/models/filesystemmodel.hpp +++ b/include/eepp/ui/models/filesystemmodel.hpp @@ -232,7 +232,7 @@ class EE_API FileSystemModel : public Model { */ bool handleFileEvent( const FileEvent& event, const FileInfo& file ); - virtual bool isValid( const ModelIndex& index ) const override; + virtual bool isValid( const ModelIndex& index ) const; virtual bool classModelRoleEnabled() { return true; } diff --git a/src/tests/unit_tests/filesystemlistener_tests.cpp b/src/tests/unit_tests/filesystemlistener_tests.cpp index 45fa7921c..809052e53 100644 --- a/src/tests/unit_tests/filesystemlistener_tests.cpp +++ b/src/tests/unit_tests/filesystemlistener_tests.cpp @@ -1,4 +1,5 @@ -#include "../../tools/ecode/filesystemlistener.hpp" +#include "../../tools/ecode/filesystemlistenercallbackstate.hpp" +#include "../../tools/ecode/filesystemlisteneroptions.hpp" #include "utest.h" #include #include @@ -8,10 +9,10 @@ using namespace ecode; UTEST( FileSystemListenerOptions, filtersByEventTypeAndPathPrefix ) { - FileSystemListener::ListenerOptions options; + FileSystemListenerOptions options; FileSystemListenerFilter filter; - filter.eventTypes = FileSystemListener::eventTypeMask( FileSystemEventType::Add ) | - FileSystemListener::eventTypeMask( FileSystemEventType::Modified ); + filter.eventTypes = fileEventTypeMask( FileSystemEventType::Add ) | + fileEventTypeMask( FileSystemEventType::Modified ); filter.path = "/tmp/ecode-ipc/"; options.filters.emplace_back( std::move( filter ) ); @@ -22,9 +23,9 @@ UTEST( FileSystemListenerOptions, filtersByEventTypeAndPathPrefix ) { } UTEST( FileSystemListenerOptions, matchesAnyFilterWithoutDuplicateSemantics ) { - FileSystemListener::ListenerOptions options; + FileSystemListenerOptions options; FileSystemListenerFilter config; - config.eventTypes = FileSystemListener::eventTypeMask( FileSystemEventType::Modified ); + config.eventTypes = fileEventTypeMask( FileSystemEventType::Modified ); config.path = "/tmp/plugin.json"; config.pathMatch = FileEventPathMatch::Exact; options.filters.emplace_back( std::move( config ) ); @@ -43,8 +44,8 @@ UTEST( FileSystemListenerOptions, matchesAnyFilterWithoutDuplicateSemantics ) { } UTEST( FileSystemListenerOptions, defaultsToAllEventsAndPathsOnMainThread ) { - FileSystemListener::ListenerOptions options; - EXPECT_EQ( options.affinity, FileSystemListener::ThreadAffinity::Main ); + FileSystemListenerOptions options; + EXPECT_EQ( options.affinity, FileEventThreadAffinity::Main ); EXPECT_TRUE( options.matches( FileSystemEventType::Add, "/any/path" ) ); EXPECT_TRUE( options.matches( FileSystemEventType::Delete, "/another/path" ) ); EXPECT_TRUE( options.matches( FileSystemEventType::Modified, "relative/path" ) ); diff --git a/src/tools/ecode/filesystemlistener.hpp b/src/tools/ecode/filesystemlistener.hpp index aada6295f..4584ad88d 100644 --- a/src/tools/ecode/filesystemlistener.hpp +++ b/src/tools/ecode/filesystemlistener.hpp @@ -2,10 +2,10 @@ #define ECODE_FILESYSTEMLISTENER_HPP #include "boundedeventqueue.hpp" +#include "filesystemlistenercallbackstate.hpp" #include "filesystemlisteneroptions.hpp" #include "projectdirectorytree.hpp" #include -#include #include #include #include @@ -20,36 +20,6 @@ using namespace EE::UI::Tools; namespace ecode { -class FileSystemListenerCallbackState { - public: - bool beginCallback() { - std::lock_guard lock( mMutex ); - if ( mRemoved ) - return false; - ++mActiveCallbacks; - return true; - } - - void endCallback() { - std::lock_guard lock( mMutex ); - if ( --mActiveCallbacks == 0 ) - mCondition.notify_all(); - } - - void removeAndWait( bool calledFromThisListener ) { - std::unique_lock lock( mMutex ); - mRemoved = true; - if ( !calledFromThisListener ) - mCondition.wait( lock, [this] { return mActiveCallbacks == 0; } ); - } - - private: - std::mutex mMutex; - std::condition_variable mCondition; - std::size_t mActiveCallbacks{ 0 }; - bool mRemoved{ false }; -}; - class FileSystemListener : public efsw::FileWatchListener { public: typedef std::function FileEventFn; diff --git a/src/tools/ecode/filesystemlistenercallbackstate.hpp b/src/tools/ecode/filesystemlistenercallbackstate.hpp new file mode 100644 index 000000000..0834ef29f --- /dev/null +++ b/src/tools/ecode/filesystemlistenercallbackstate.hpp @@ -0,0 +1,42 @@ +#ifndef ECODE_FILESYSTEMLISTENERCALLBACKSTATE_HPP +#define ECODE_FILESYSTEMLISTENERCALLBACKSTATE_HPP + +#include +#include +#include + +namespace ecode { + +class FileSystemListenerCallbackState { + public: + bool beginCallback() { + std::lock_guard lock( mMutex ); + if ( mRemoved ) + return false; + ++mActiveCallbacks; + return true; + } + + void endCallback() { + std::lock_guard lock( mMutex ); + if ( --mActiveCallbacks == 0 ) + mCondition.notify_all(); + } + + void removeAndWait( bool calledFromThisListener ) { + std::unique_lock lock( mMutex ); + mRemoved = true; + if ( !calledFromThisListener ) + mCondition.wait( lock, [this] { return mActiveCallbacks == 0; } ); + } + + private: + std::mutex mMutex; + std::condition_variable mCondition; + std::size_t mActiveCallbacks{ 0 }; + bool mRemoved{ false }; +}; + +} // namespace ecode + +#endif // ECODE_FILESYSTEMLISTENERCALLBACKSTATE_HPP