tags:

views:

45

answers:

3

Hi,

I've a daemon (obexpushd) that writes some files in a directory. In my Qt application, I listen to changes in this directory thanks to QFileSystemWatcher. Yet, the directoryChanged signal is emitted when obexpushd creates the file, not when it has finished to write it.

So, I've to wait for obexpush to finish writing the file before processing it. What is the best strategy ?

Check the size remains the same for a fixed amount of time ? Call lsof at fixed interval ? Any better solution ?

+2  A: 

Is obexpushd a program that you can change? If so, the easiest thing to do would probably be have obexpushd write to temporary file, then rename the file when it's done writing. That would be something you could monitor in your Qt program. A more robust and elegant way would be to have obexpushd communicate with your Qt program, maybe via dbus, to explicitly say when it's done.

If obexpushd isn't under your control, then one of the strategies you've listed is probably your best bet.

Colin
Modifying Obexpushd seems a good solution, but unfortunately it is less maintenable (and even less in an embedded environment !).
Tangui
I'll try this solution anyway.
Tangui
A: 

You could watch for file timestamps to change. QFileInfo makes that possible.

HardCoder1986
A: 

There seems to be an open bug on this issue http://bugreports.qt.nokia.com/browse/QTBUG-3576. If you know the filenames of the files you are waiting on, perhaps you can use QFileSystemWatcher::fileChanged().

Arnold Spence
Yes but the file is continuously modified while the obex server is receiving and saving the file. And there's no way to know what event triggered this signal.
Tangui