FileMonitor Manual

Table of Contents

About

The maxon::FileMonitor class can be used to watch a certain folder. If a file in that folder is changed, a delegate is called.

Warning
The events observed and messages sent depend on the OS.

FileMonitor

maxon::FileMonitor::WatchDirectory() is used to watch the given folder.

// This example shows how to use maxon::FileMonitor to watch a given folder.
// global instance of FileMonitorItemRef
maxon::FileMonitorItemRef g_directoryWatch;
// ------------------------------------------------------------
// This function watches the given folder.
// ------------------------------------------------------------
static maxon::Result<void> WatchFolder(const maxon::Url& url)
{
// check argument
if (url.IoDetect() != maxon::IODETECT::DIRECTORY)
return maxon::IllegalArgumentError(MAXON_SOURCE_LOCATION);
// lambda function called when a file is was changed
auto folderActivity = [](const maxon::Url& watched, const maxon::Url& updated, maxon::FileMonitor::STATE state)
{
DiagnosticOutput("Some change in folder @.", watched);
};
// watch folder and store FileMonitorItemRef
g_directoryWatch = nullptr;
g_directoryWatch = maxon::FileMonitor::WatchDirectory(url, folderActivity) iferr_return;
return maxon::OK;
}
static void ClearWatcher()
{
// clear global instance at the end
g_directoryWatch = nullptr;
}
MAXON_INITIALIZATION(nullptr, ClearWatcher);

Further Reading

maxon::FileMonitor::STATE
STATE
Types of CaptureDevices.
Definition: filemonitor.h:32
maxon::IODETECT::DIRECTORY
@ DIRECTORY
Url is a directory, you can use GetBrowseIterator to iterate through the children.
maxon::OK
return OK
Definition: apibase.h:2546
iferr_return
#define iferr_return
Definition: resultbase.h:1465
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:167
maxon::Url
Definition: url.h:855
MAXON_INITIALIZATION
#define MAXON_INITIALIZATION(...)
Definition: module.h:746
maxon::Result< void >
iferr_scope
#define iferr_scope
Definition: resultbase.h:1374
maxon::FileMonitor::WatchDirectory
static MAXON_METHOD Result< FileMonitorItemRef > WatchDirectory(const Url &url, Observer &&observer)