wxFileSystemWatcher and general design ideas solicited

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

wxFileSystemWatcher and general design ideas solicited

Post by iwbnwif »

I am looking at using wxWidgets to rewrite an old client application that performs the following:
  1. Shows a (smallish)list of (smallish)files that are stored on a server
  2. Allows a user to double click on a file, which downloads it to a temporary directory and opens it for editing
  3. Each time the user saves the file a copy is uploaded back to the server as a temporary backup
  4. When the user closes the application the following happens:
    1. The local temporary file is uploaded to the server as a new 'version'
    2. The temporary backups (intermediate saves) on the server are deleted
    3. The local temporary file is deleted
My idea is to create two separate applications to do this:
  1. The 'main' application that manages the initial download, deletes the temporary files (local and remote) after closure
  2. A small application that watches the local temporary directory and sends updated files to the server after each save
The reason for two applications is because wxFileSystemWatcher needs to be created inside an event loop. As some of the 'main' application, including the part that would have to perform the watching function, would be in a DLL this might be problematic?

By having a second small 'watcher / uploader' application the wxFileSystemWatcher can be in the event loop of the main class.

A potentially better way might be to spawn the 'watcher / uploader' in a thread, but again I don't know if there are problems with using wxFileSystemWatcher in a thread.

Any hints or tips about this are very welcome!
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2408
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: wxFileSystemWatcher and general design ideas solicited

Post by evstevemd »

Actually am designing similar kind of app. I have not yet coded but in summary the best way is to do in same app. As for your requirement:
1. Download file
2. Monitor changes
3. Lock file to receive no more changes (or wait until wxClose event)
4. Spawn threads to upload files
5. When all threads are done, release locks (o let app close and rest in peace)
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: wxFileSystemWatcher and general design ideas solicited

Post by iwbnwif »

Thank you for your answer, sorry I didn't notice that there was a reply.

I do prefer your suggestion to spawn a separate thread to upload the file, and will look into this in more detail. Amazingly despite having been using wxWidgets for a couple of years now, I have only really just started to understand the threading framework :oops:.
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
Post Reply