wxFileSystemWatcher Class Reference
[File Handling]

#include <wx/fswatcher.h>

Inheritance diagram for wxFileSystemWatcher:
Inheritance graph
[legend]

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.

There are three different ways to use this class:

For example:

    class MyWatcher : public wxFileSystemWatcher
    {
    protected:
        void OnChange(int changeType, const wxFileName& path, const wxFileName& newPath)
        {
            // do whatever you like with the event
        }
    };

    class MyApp : public wxApp
    {
    public:
        ...
        void OnEventLoopEnter(wxEventLoopBase* WXUNUSED(loop))
        {
            // you have to construct the watcher here, because it needs an active loop
            m_watcher = new MyWatcher();

            // please notify me when a new log file is created
            m_watcher->Add(wxFileName::DirName("/var/log", wxFSW_EVENT_CREATE);
        }

    private:
        MyWatcher* m_watcher;
    };

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)=0
 This is the same as Add(), but 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)
 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 GetWatchedPathCount () const
 Returns the number of 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.

Protected Member Functions

virtual void OnChange (int changeType, const wxFileName &path, const wxFileName &newPath)
 You may either connect your event handler to intercept file system watcher events or override this member and handle them here.
virtual void OnWarning (const wxString &errorMessage)
 You may either connect your event handler to intercept file system watcher events or override this member and handle them here.
virtual void OnError (const wxString &errorMessage)
 You may either connect your event handler to intercept file system watcher events or override this member and handle them here.

List of all members.


Constructor & Destructor Documentation

wxFileSystemWatcher::wxFileSystemWatcher (  ) 

Default constructor.

If you create file system watcher using it you have to either call SetOwner() and connect an event handler or override OnChange(), OnWarning() and OnError().

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.

Optionally a filter can be specified to receive only events of particular type.

Any events concerning this particular path will be sent either to connected handler or passed to OnChange(), OnWarning() or OnError().

Note:
When adding a directory, immediate children will be watched as well.
virtual bool wxFileSystemWatcher::AddTree ( const wxFileName path,
int  events = wxFSW_EVENT_ALL,
const wxString filter = wxEmptyString 
) [pure virtual]

This is the same as Add(), but 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.

int wxFileSystemWatcher::GetWatchedPathCount (  )  const

Returns the number of watched paths.

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.

virtual void wxFileSystemWatcher::OnChange ( int  changeType,
const wxFileName path,
const wxFileName newPath 
) [protected, virtual]

You may either connect your event handler to intercept file system watcher events or override this member and handle them here.

Perform whatever action which is to be taken on file system change.

virtual void wxFileSystemWatcher::OnError ( const wxString errorMessage  )  [protected, virtual]

You may either connect your event handler to intercept file system watcher events or override this member and handle them here.

Perform whatever action which is to be taken when an error condition arises.

virtual void wxFileSystemWatcher::OnWarning ( const wxString errorMessage  )  [protected, virtual]

You may either connect your event handler to intercept file system watcher events or override this member and handle them here.

Perform whatever action which is to be taken when a warning condition arises.

virtual bool wxFileSystemWatcher::Remove ( const wxFileName path  )  [virtual]

Removes path from the list of watched paths.

virtual bool wxFileSystemWatcher::RemoveAll (  )  [virtual]

Clears the list of currently watched paths.

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

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

void wxFileSystemWatcher::SetOwner ( wxEvtHandler handler  ) 

Associates the file system watcher with the given handler object.

Basically this means that all events will be passed to this handler object unless you have change the default behaviour by overriding OnChange(), OnWarning() or OnError().

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines



wxWidgets logo

[ top ]