Version: 3.1.0
wxFileSystemWatcher Class Reference

#include <wx/fswatcher.h>

+ Inheritance diagram for wxFileSystemWatcher:

Detailed Description

The wxFileSystemWatcher class allows to receive notifications of file system changes.

Note
Implementation limitations: this class is currently implemented for MSW, OS X and GTK ports but doesn't detect all changes correctly everywhere: under MSW accessing the file is not detected (only modifying it is) and under OS X neither accessing nor modifying is detected (only creating and deleting files is). Moreover, OS X version doesn't currently collapse pairs of create/delete events in a rename event, unlike the other ones.

For the full list of change types that are reported see wxFSWFlags.

This class notifies the application about the file system changes by sending events of wxFileSystemWatcherEvent class. By default these events are sent to the wxFileSystemWatcher object itself so you can derive from it and use the event table EVT_FSWATCHER macro to handle these events in a derived class method. Alternatively, you can use wxFileSystemWatcher::SetOwner() to send the events to another object. Or you could use wxEvtHandler::Connect() with wxEVT_FSWATCHER to handle these events in any other object. See the fswatcher sample for an example of the latter approach.

Library:  wxBase
Category:  File Handling
Since
2.9.1

Public Member Functions

 wxFileSystemWatcher ()
 Default constructor.
 
virtual ~wxFileSystemWatcher ()
 Destructor.
 
virtual bool Add (const wxFileName &path, int events=wxFSW_EVENT_ALL)
 Adds path to currently watched files.
 
virtual bool AddTree (const wxFileName &path, int events=wxFSW_EVENT_ALL, const wxString &filter=wxEmptyString)
 This is the same as Add(), but also recursively adds every file/directory in the tree rooted at path.
 
virtual bool Remove (const wxFileName &path)
 Removes path from the list of watched paths.
 
virtual bool RemoveTree (const wxFileName &path)
 This is the same as Remove(), but also removes every file/directory belonging to the tree rooted at path.
 
virtual bool RemoveAll ()
 Clears the list of currently watched paths.
 
int GetWatchedPathsCount () const
 Returns the number of currently watched paths.
 
int GetWatchedPaths (wxArrayString *paths) const
 Retrieves all watched paths and places them in paths.
 
void SetOwner (wxEvtHandler *handler)
 Associates the file system watcher with the given handler object.
 
- Public Member Functions inherited from wxEvtHandler
 wxEvtHandler ()
 Constructor.
 
virtual ~wxEvtHandler ()
 Destructor.
 
virtual void QueueEvent (wxEvent *event)
 Queue event for a later processing.
 
virtual void AddPendingEvent (const wxEvent &event)
 Post an event to be processed later.
 
template<typename T , typename T1 , ... >
void CallAfter (void(T::*method)(T1,...), T1 x1,...)
 Asynchronously call the given method.
 
template<typename T >
void CallAfter (const T &functor)
 Asynchronously call the given functor.
 
virtual bool ProcessEvent (wxEvent &event)
 Processes an event, searching event tables and calling zero or more suitable event handler function(s).
 
bool ProcessEventLocally (wxEvent &event)
 Try to process the event in this handler and all those chained to it.
 
bool SafelyProcessEvent (wxEvent &event)
 Processes an event by calling ProcessEvent() and handles any exceptions that occur in the process.
 
void ProcessPendingEvents ()
 Processes the pending events previously queued using QueueEvent() or AddPendingEvent(); you must call this function only if you are sure there are pending events for this handler, otherwise a wxCHECK will fail.
 
void DeletePendingEvents ()
 Deletes all events queued on this event handler using QueueEvent() or AddPendingEvent().
 
virtual bool SearchEventTable (wxEventTable &table, wxEvent &event)
 Searches the event table, executing an event handler function if an appropriate one is found.
 
void Connect (int id, int lastId, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 Connects the given function dynamically with the event handler, id and event type.
 
void Connect (int id, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info.
 
void Connect (wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info.
 
bool Disconnect (wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 Disconnects the given function dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed.
 
bool Disconnect (int id=wxID_ANY, wxEventType eventType=wxEVT_NULL, wxObjectEventFunction function=NULL, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info.
 
bool Disconnect (int id, int lastId, wxEventType eventType, wxObjectEventFunction function=NULL, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info.
 
template<typename EventTag , typename Functor >
void Bind (const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
 Binds the given function, functor or method dynamically with the event.
 
template<typename EventTag , typename Class , typename EventArg , typename EventHandler >
void Bind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
 See the Bind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info.
 
template<typename EventTag , typename Functor >
bool Unbind (const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
 Unbinds the given function, functor or method dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed.
 
template<typename EventTag , typename Class , typename EventArg , typename EventHandler >
bool Unbind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
 See the Unbind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info.
 
void * GetClientData () const
 Returns user-supplied client data.
 
wxClientDataGetClientObject () const
 Returns a pointer to the user-supplied client data object.
 
void SetClientData (void *data)
 Sets user-supplied client data.
 
void SetClientObject (wxClientData *data)
 Set the client data object.
 
bool GetEvtHandlerEnabled () const
 Returns true if the event handler is enabled, false otherwise.
 
wxEvtHandlerGetNextHandler () const
 Returns the pointer to the next handler in the chain.
 
wxEvtHandlerGetPreviousHandler () const
 Returns the pointer to the previous handler in the chain.
 
void SetEvtHandlerEnabled (bool enabled)
 Enables or disables the event handler.
 
virtual void SetNextHandler (wxEvtHandler *handler)
 Sets the pointer to the next handler.
 
virtual void SetPreviousHandler (wxEvtHandler *handler)
 Sets the pointer to the previous handler.
 
void Unlink ()
 Unlinks this event handler from the chain it's part of (if any); then links the "previous" event handler to the "next" one (so that the chain won't be interrupted).
 
bool IsUnlinked () const
 Returns true if the next and the previous handler pointers of this event handler instance are NULL.
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to NULL the internal reference data.
 
 wxObject (const wxObject &other)
 Copy ctor.
 
virtual ~wxObject ()
 Destructor.
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar).
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object.
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class.
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj.
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone.
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer.
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data.
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public.
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined.
 
void * operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined.
 

Additional Inherited Members

- Static Public Member Functions inherited from wxEvtHandler
static void AddFilter (wxEventFilter *filter)
 Add an event filter whose FilterEvent() method will be called for each and every event processed by wxWidgets.
 
static void RemoveFilter (wxEventFilter *filter)
 Remove a filter previously installed with AddFilter().
 
- Protected Member Functions inherited from wxEvtHandler
virtual bool TryBefore (wxEvent &event)
 Method called by ProcessEvent() before examining this object event tables.
 
virtual bool TryAfter (wxEvent &event)
 Method called by ProcessEvent() as last resort.
 
- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data.
 

Constructor & Destructor Documentation

wxFileSystemWatcher::wxFileSystemWatcher ( )

Default constructor.

virtual wxFileSystemWatcher::~wxFileSystemWatcher ( )
virtual

Destructor.

Stops all paths from being watched and frees any system resources used by this file system watcher object.

Member Function Documentation

virtual bool wxFileSystemWatcher::Add ( const wxFileName path,
int  events = wxFSW_EVENT_ALL 
)
virtual

Adds path to currently watched files.

The path argument can currently only be a directory and any changes to this directory itself or its immediate children will generate the events. Use AddTree() to monitor the directory recursively.

Note that on platforms that use symbolic links, you should consider the possibility that path is a symlink. To watch the symlink itself and not its target you may call wxFileName::DontFollowLink() on path.

Parameters
pathThe name of the path to watch.
eventsAn optional filter to receive only events of particular types. This is currently implemented only for GTK.
virtual bool wxFileSystemWatcher::AddTree ( const wxFileName path,
int  events = wxFSW_EVENT_ALL,
const wxString filter = wxEmptyString 
)
virtual

This is the same as Add(), but also recursively adds every file/directory in the tree rooted at path.

Additionally a file mask can be specified to include only files matching that particular mask.

This method is implemented efficiently on MSW, but should be used with care on other platforms for directories with lots of children (e.g. the root directory) as it calls Add() for each subdirectory, potentially creating a lot of watches and taking a long time to execute.

Note that on platforms that use symbolic links, you will probably want to have called wxFileName::DontFollowLink on path. This is especially important if the symlink targets may themselves be watched.

int wxFileSystemWatcher::GetWatchedPaths ( wxArrayString paths) const

Retrieves all watched paths and places them in paths.

Returns the number of watched paths, which is also the number of entries added to paths.

int wxFileSystemWatcher::GetWatchedPathsCount ( ) const

Returns the number of currently watched paths.

See Also
GetWatchedPaths()
virtual bool wxFileSystemWatcher::Remove ( const wxFileName path)
virtual

Removes path from the list of watched paths.

See the comment in Add() about symbolic links. path should treat symbolic links in the same way as in the original Add() call.

virtual bool wxFileSystemWatcher::RemoveAll ( )
virtual

Clears the list of currently watched paths.

virtual bool wxFileSystemWatcher::RemoveTree ( const wxFileName path)
virtual

This is the same as Remove(), but also removes every file/directory belonging to the tree rooted at path.

See the comment in AddTree() about symbolic links. path should treat symbolic links in the same way as in the original AddTree() call.

void wxFileSystemWatcher::SetOwner ( wxEvtHandler handler)

Associates the file system watcher with the given handler object.

All the events generated by this object will be passed to the specified owner.