Home » Developing U++ » UppHub » Added FSMon - FileSystem Monitor class
Added FSMon - FileSystem Monitor class [message #36206] |
Sat, 12 May 2012 09:32 |
mdelfede
Messages: 1307 Registered: September 2007
|
Ultimate Contributor |
|
|
Hi,
I dropped a small class, FSMon, along with its demo FSMonTest, which allows monitoring a folder and its sub-folders for file changes.
Usage is quite simple :
FSMon fsMon;
// this will add a monitored path
fsMon.Add(APathToMonitor);
// this will remove it
fsMon.Remove(AMonitoredPath);
Catch of events can be done by polling
while(true)
{
if(fsMon.HasChanges())
{
Vector<FSMon::Info> info = fsMon.GetChanged();
for(int i = 0; i < info.GetCount(); i++)
DoSomething(info[i].path, info[i].newPath, info[i].flags);
}
else
Sleep(100);
}
or event driven with a callback :
void eventHandler(void)
{
Vector<FSMon::Info> info = fsMon.GetChanged();
......
}
fsMon.EventHandler = THISBACK(eventHandler);
Beware, for the event-driven the behaviour is different if runnini inside a GUI app or a NON-GUI app :
for GUI apps, the call is done through a PostCallback, so runs in main thread
for NON GUI apps, the call is direct, so runs in FSMon monitoring thread, which is not good for lengty operations.
So, for NON-GUI apps it's better to use a separate thread and polling.
FSMon can catch file/folders creation, deletion and renaming, along with attribute changes. See flags in FSMon.h and the sample FSMonDemo for details.
Ciao
Max
|
|
|
Re: Added FSMon - FileSystem Monitor class [message #36212 is a reply to message #36206] |
Sat, 12 May 2012 14:33 |
mdelfede
Messages: 1307 Registered: September 2007
|
Ultimate Contributor |
|
|
Added another fancy, more useful example : FSMonSync package.
It realizes a trivial path syncronization mechanics; the demo creates a couple of folders in user home folder, which are
/home/user/FSMonTest_A
/home/user/FSMonTest_B
on Linux, and
c:\windows\profiles\users\user\FSMonTest_A
c:\windows\profiles\users\user\FSMonTest_B
or
c:\documents and settings\user\FSMonTest_A
c:\documents and settings\user\FSMonTest_A
on Windows (well, I guess, it depends on win version... anyways the log windows will show you both).
Wathever you do on first folder (FSMonTest_A) gets duplicated on second one (FSMonTest_B), even in subfolders, in real-time.
The app is quite trivial, don't do any security checks nor optimizations, but works and allows, for example, to have a real-time backup of your data on an external disk.
The very base for an "UCloud" app ?
Ciao
Max
|
|
|
|
|
Goto Forum:
Current Time: Fri Mar 29 01:23:52 CET 2024
Total time taken to generate the page: 0.01909 seconds
|