Fix builds and warnings in builds.

This commit is contained in:
Martín Lucas Golini
2026-08-21 10:51:20 -03:00
parent 864b2a9b3f
commit 2895d771ab
4 changed files with 53 additions and 40 deletions
+1 -1
View File
@@ -232,7 +232,7 @@ class EE_API FileSystemModel : public Model {
*/ */
bool handleFileEvent( const FileEvent& event, const FileInfo& file ); 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; } virtual bool classModelRoleEnabled() { return true; }
@@ -1,4 +1,5 @@
#include "../../tools/ecode/filesystemlistener.hpp" #include "../../tools/ecode/filesystemlistenercallbackstate.hpp"
#include "../../tools/ecode/filesystemlisteneroptions.hpp"
#include "utest.h" #include "utest.h"
#include <condition_variable> #include <condition_variable>
#include <future> #include <future>
@@ -8,10 +9,10 @@
using namespace ecode; using namespace ecode;
UTEST( FileSystemListenerOptions, filtersByEventTypeAndPathPrefix ) { UTEST( FileSystemListenerOptions, filtersByEventTypeAndPathPrefix ) {
FileSystemListener::ListenerOptions options; FileSystemListenerOptions options;
FileSystemListenerFilter filter; FileSystemListenerFilter filter;
filter.eventTypes = FileSystemListener::eventTypeMask( FileSystemEventType::Add ) | filter.eventTypes = fileEventTypeMask( FileSystemEventType::Add ) |
FileSystemListener::eventTypeMask( FileSystemEventType::Modified ); fileEventTypeMask( FileSystemEventType::Modified );
filter.path = "/tmp/ecode-ipc/"; filter.path = "/tmp/ecode-ipc/";
options.filters.emplace_back( std::move( filter ) ); options.filters.emplace_back( std::move( filter ) );
@@ -22,9 +23,9 @@ UTEST( FileSystemListenerOptions, filtersByEventTypeAndPathPrefix ) {
} }
UTEST( FileSystemListenerOptions, matchesAnyFilterWithoutDuplicateSemantics ) { UTEST( FileSystemListenerOptions, matchesAnyFilterWithoutDuplicateSemantics ) {
FileSystemListener::ListenerOptions options; FileSystemListenerOptions options;
FileSystemListenerFilter config; FileSystemListenerFilter config;
config.eventTypes = FileSystemListener::eventTypeMask( FileSystemEventType::Modified ); config.eventTypes = fileEventTypeMask( FileSystemEventType::Modified );
config.path = "/tmp/plugin.json"; config.path = "/tmp/plugin.json";
config.pathMatch = FileEventPathMatch::Exact; config.pathMatch = FileEventPathMatch::Exact;
options.filters.emplace_back( std::move( config ) ); options.filters.emplace_back( std::move( config ) );
@@ -43,8 +44,8 @@ UTEST( FileSystemListenerOptions, matchesAnyFilterWithoutDuplicateSemantics ) {
} }
UTEST( FileSystemListenerOptions, defaultsToAllEventsAndPathsOnMainThread ) { UTEST( FileSystemListenerOptions, defaultsToAllEventsAndPathsOnMainThread ) {
FileSystemListener::ListenerOptions options; FileSystemListenerOptions options;
EXPECT_EQ( options.affinity, FileSystemListener::ThreadAffinity::Main ); EXPECT_EQ( options.affinity, FileEventThreadAffinity::Main );
EXPECT_TRUE( options.matches( FileSystemEventType::Add, "/any/path" ) ); EXPECT_TRUE( options.matches( FileSystemEventType::Add, "/any/path" ) );
EXPECT_TRUE( options.matches( FileSystemEventType::Delete, "/another/path" ) ); EXPECT_TRUE( options.matches( FileSystemEventType::Delete, "/another/path" ) );
EXPECT_TRUE( options.matches( FileSystemEventType::Modified, "relative/path" ) ); EXPECT_TRUE( options.matches( FileSystemEventType::Modified, "relative/path" ) );
+1 -31
View File
@@ -2,10 +2,10 @@
#define ECODE_FILESYSTEMLISTENER_HPP #define ECODE_FILESYSTEMLISTENER_HPP
#include "boundedeventqueue.hpp" #include "boundedeventqueue.hpp"
#include "filesystemlistenercallbackstate.hpp"
#include "filesystemlisteneroptions.hpp" #include "filesystemlisteneroptions.hpp"
#include "projectdirectorytree.hpp" #include "projectdirectorytree.hpp"
#include <atomic> #include <atomic>
#include <condition_variable>
#include <eepp/system/fileinfo.hpp> #include <eepp/system/fileinfo.hpp>
#include <eepp/ui/models/filesystemmodel.hpp> #include <eepp/ui/models/filesystemmodel.hpp>
#include <eepp/ui/tools/uicodeeditorsplitter.hpp> #include <eepp/ui/tools/uicodeeditorsplitter.hpp>
@@ -20,36 +20,6 @@ using namespace EE::UI::Tools;
namespace ecode { namespace ecode {
class FileSystemListenerCallbackState {
public:
bool beginCallback() {
std::lock_guard<std::mutex> lock( mMutex );
if ( mRemoved )
return false;
++mActiveCallbacks;
return true;
}
void endCallback() {
std::lock_guard<std::mutex> lock( mMutex );
if ( --mActiveCallbacks == 0 )
mCondition.notify_all();
}
void removeAndWait( bool calledFromThisListener ) {
std::unique_lock<std::mutex> 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 { class FileSystemListener : public efsw::FileWatchListener {
public: public:
typedef std::function<void( const FileEvent&, const FileInfo& )> FileEventFn; typedef std::function<void( const FileEvent&, const FileInfo& )> FileEventFn;
@@ -0,0 +1,42 @@
#ifndef ECODE_FILESYSTEMLISTENERCALLBACKSTATE_HPP
#define ECODE_FILESYSTEMLISTENERCALLBACKSTATE_HPP
#include <condition_variable>
#include <cstddef>
#include <mutex>
namespace ecode {
class FileSystemListenerCallbackState {
public:
bool beginCallback() {
std::lock_guard<std::mutex> lock( mMutex );
if ( mRemoved )
return false;
++mActiveCallbacks;
return true;
}
void endCallback() {
std::lock_guard<std::mutex> lock( mMutex );
if ( --mActiveCallbacks == 0 )
mCondition.notify_all();
}
void removeAndWait( bool calledFromThisListener ) {
std::unique_lock<std::mutex> 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