[zypp-devel] Callbacks and reports proposal
I have been trying different approaches for progress reporting Here is one of my proposals: New report ProgressReport struct ProgressReport : public callback::ReportBase { virtual void start( const ProgressData &/*task*/ ) virtual bool progress( const ProgressData &/*task*/ ) virtual void finish( const ProgressData &/*task*/ ) }; Most of the methods of ZYpp time consuming tasks accept a ProgressData function, so if you reuse a ZYpp parser in a small program, you can setup your own progress callback. The idea is that RepoManager functions use an ProgressReportAdaptor internally that appart of sending the progress to the user callback, it also sends it to the global ProgressReport. The reports get the complete progress object, and from it they can get a unique runtime id for the task, text, and progress value. I just implemented the receiver for ZYpper like this: struct ProgressReportReceiver : public zypp::callback::ReceiveReportzypp::ProgressReport { virtual void start( const zypp::ProgressData &data ) { display_progress ( data.name() , data.min() ); } virtual bool progress( const zypp::ProgressData &data ) { display_progress ( data.name() , data.val() ); return true; } virtual void finish( const zypp::ProgressData &data ) { display_progress ( data.name() , data.max() ); } }; The nice thing is, with this we could remove all Source*Reports. Only internal reports like media change and download needs to be kept. Internally, ZYpp uses ProgressData and CombinedProgress data to produce quite nice estimates for progress. If you like the idea, I would add later (next week?) an Error class (or use Exception), a Message class, and provide in the same report perhaps some generic user interaction like continue-cancel, press-ok, etc. -- Duncan Mac-Vicar Prett Novell :: SUSE R&D, Maxfeldstr. 5, 90409 Nürnberg GF: Markus Rex, HRB 16746 (AG Nürnberg) -- To unsubscribe, e-mail: zypp-devel+unsubscribe@opensuse.org For additional commands, e-mail: zypp-devel+help@opensuse.org
On Tue, Jul 10, Duncan Mac-Vicar Prett wrote:
The idea is that RepoManager functions use an ProgressReportAdaptor internally that appart of sending the progress to the user callback, it also sends it to the global ProgressReport. The reports get the complete progress object, and from it they can get a unique runtime id for the task, text, and progress value.
As the ProgressData::ReceiverFnc now takes the ProgressData object as argument, I added these methods to query the progess: + bool reportPercent() const + + bool reportAlive() const + + value_type reportValue() const reportPercent() and reportAlive() are mutual exclusive and tell whether reportValue() will return a percent value, or just -1. -1 is returned if the task did not set a range [min,max]. This ususally indicates that the size of the task is unknown, and only 'still alive' messages are sent. val() returns the 'real' value the task assigned to the ProgressData. -- cu, Michael Andres +------------------------------------------------------------------+ Key fingerprint = 2DFA 5D73 18B1 E7EF A862 27AC 3FB8 9E3A 27C6 B0E4 +------------------------------------------------------------------+ Michael Andres YaST Development ma@novell.com SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nuernberg) Maxfeldstrasse 5, D-90409 Nuernberg, Germany, ++49 (0)911 - 740 53-0 +------------------------------------------------------------------+ -- To unsubscribe, e-mail: zypp-devel+unsubscribe@opensuse.org For additional commands, e-mail: zypp-devel+help@opensuse.org
participants (2)
-
Duncan Mac-Vicar Prett
-
Michael Andres