CFileMan
operation
observersTo be notified of events resulting from CFileMan
operations, implement a file notification observer interface
MFileManObserver
.
Notification functions are called before or after each entry has been processed, or during a file copy or move. This notification can be used to provide information about the state of the operation, such as error messages, the names of the target and destination files, and the number of bytes transferred during a copy operation.
The interface can also be used to allow the user to cancel, retry or
continue processing an entry, or to abort the whole operation.
TControl
encapsulates these options.
The following example defines a class that implements
MFileManObserver
to monitor a file copy operation.
/**
Monitors file copy events, and prints out the progress.
*/
class TFileCopyProgressMonitor : public MFileManObserver
{
public:
/**
Constructor.
@param aFileMan Used to obtain the number of bytes currently copied
*/
TFileCopyProgressMonitor(CFileMan& aFileMan);
private:
// Virtuals defined by MFileManObserver
TControl NotifyFileManStarted();
TControl NotifyFileManOperation();
TControl NotifyFileManEnded();
private:
CFileMan& iFileMan;
};
TFileCopyProgressMonitor::TFileCopyProgressMonitor(CFileMan& aFileMan)
:iFileMan(aFileMan)
{
}
// Called when copy operation started
MFileManObserver::TControl TFileCopyProgressMonitor::NotifyFileManStarted()
{
console->Printf(KStarted);
return EContinue;
}
// Called when copy operation is in progress
MFileManObserver::TControl TFileCopyProgressMonitor::NotifyFileManOperation()
{
console->Printf(KProgress,iFileMan.BytesTransferredByCopyStep());
return EContinue;
}
// Called when copy operation is complete
MFileManObserver::TControl TFileCopyProgressMonitor::NotifyFileManEnded()
{
console->Printf(KComplete);
return EContinue;
}