Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » UppHub » Added FSMon - FileSystem Monitor class
Added FSMon - FileSystem Monitor class [message #36206] Sat, 12 May 2012 09:32 Go to next message
mdelfede is currently offline  mdelfede
Messages: 1285
Registered: September 2007
Senior 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 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1285
Registered: September 2007
Senior 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 ? Smile

Ciao

Max

Re: Added FSMon - FileSystem Monitor class [message #36235 is a reply to message #36212] Tue, 15 May 2012 19:18 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3268
Registered: August 2008
Senior Veteran
Very interesting Massimo. Thank you Smile.

Best regards
IƱaki
Re: Added FSMon - FileSystem Monitor class [message #40077 is a reply to message #36235] Wed, 05 June 2013 14:55 Go to previous message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Thank you for this package!
A little addition: in FSMonTest/main.cpp at line 15, you should add directory in system charset (not in UTF-8).

fsmMon.Add(ToSystemCharset(path));


And so it works for files and directories with localized names.
Previous Topic: StaticImage enhancement
Next Topic: Added Scgi class to replace Web/ScgiServer
Goto Forum:
  


Current Time: Thu Oct 28 11:16:21 CEST 2021

Total time taken to generate the page: 0.01286 seconds