X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d98a58c543948d84d9287e6fa53a5539d662b7a5..e10972f6c1436a6dcd5427b4e3913bb0f398e045:/include/wx/fswatcher.h diff --git a/include/wx/fswatcher.h b/include/wx/fswatcher.h index 959bcf8a8a..30656714ef 100644 --- a/include/wx/fswatcher.h +++ b/include/wx/fswatcher.h @@ -196,12 +196,16 @@ class wxFSWatchInfo { public: wxFSWatchInfo() : - m_events(-1), m_type(wxFSWPath_None) + m_events(-1), m_type(wxFSWPath_None), m_refcount(-1) { } - wxFSWatchInfo(const wxString& path, int events, wxFSWPathType type) : - m_path(path), m_events(events), m_type(type) + wxFSWatchInfo(const wxString& path, + int events, + wxFSWPathType type, + const wxString& filespec = wxString()) : + m_path(path), m_filespec(filespec), m_events(events), m_type(type), + m_refcount(1) { } @@ -210,6 +214,8 @@ public: return m_path; } + const wxString& GetFilespec() const { return m_filespec; } + int GetFlags() const { return m_events; @@ -220,10 +226,27 @@ public: return m_type; } + // Reference counting of watch entries is used to avoid watching the same + // file system path multiple times (this can happen even accidentally, e.g. + // when you have a recursive watch and then decide to watch some file or + // directory under it separately). + int IncRef() + { + return ++m_refcount; + } + + int DecRef() + { + wxASSERT_MSG( m_refcount > 0, wxS("Trying to decrement a zero count") ); + return --m_refcount; + } + protected: wxString m_path; + wxString m_filespec; // For tree watches, holds any filespec to apply int m_events; wxFSWPathType m_type; + int m_refcount; }; WX_DECLARE_STRING_HASH_MAP(wxFSWatchInfo, wxFSWatchInfoMap); @@ -260,7 +283,7 @@ public: * of particular type. */ virtual bool AddTree(const wxFileName& path, int events = wxFSW_EVENT_ALL, - const wxString& filter = wxEmptyString); + const wxString& filespec = wxEmptyString); /** * Removes path from the list of watched paths. @@ -305,6 +328,14 @@ public: m_owner = handler; } + + // This is a semi-private function used by wxWidgets itself only. + // + // Delegates the real work of adding the path to wxFSWatcherImpl::Add() and + // updates m_watches if the new path was successfully added. + bool AddAny(const wxFileName& path, int events, wxFSWPathType type, + const wxString& filespec = wxString()); + protected: static wxString GetCanonicalPath(const wxFileName& path) @@ -320,10 +351,6 @@ protected: return path_copy.GetFullPath(); } - // Delegates the real work of adding the path to wxFSWatcherImpl::Add() and - // updates m_watches if the new path was successfully added. - bool DoAdd(const wxFileName& path, int events, wxFSWPathType type); - wxFSWatchInfoMap m_watches; // path=>wxFSWatchInfo map wxFSWatcherImpl* m_service; // file system events service