Author: mlandres
Date: Wed May 2 19:18:55 2007
New Revision: 5467
URL: http://svn.opensuse.org/viewcvs/zypp?rev=5467&view=rev
Log:
improve ProgressData
Modified:
trunk/libzypp/zypp/ProgressData.cc
trunk/libzypp/zypp/ProgressData.h
Modified: trunk/libzypp/zypp/ProgressData.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ProgressData.cc?rev=5467&r1=5466&r2=5467&view=diff
==============================================================================
--- trunk/libzypp/zypp/ProgressData.cc (original)
+++ trunk/libzypp/zypp/ProgressData.cc Wed May 2 19:18:55 2007
@@ -27,8 +27,16 @@
// METHOD NAME : ProgressData::report
// METHOD TYPE : void
//
- void ProgressData::report()
+ bool ProgressData::report()
{
+ // DISABLED to get DBG output from 'if ( doReport )'
+ //if ( ! _d->_receiver )
+ // return true;
+
+ bool goOn = true; // continue per default
+ bool doReport = false;
+
+ // compute value and check whether to report it
if ( hasRange() )
{
value_type newVal = _d->_val * 100;
@@ -36,30 +44,50 @@
if ( newVal - _d->_last_val > 5 || Date::now() - _d->_last_send > 1 || _d->_state == END )
{
- DBG << str::form( "{%u|%s}(%d%%)",
- numericId(), name().c_str(), newVal ) << endl;
_d->_last_val = newVal;
_d->_last_send = Date::now();
- if ( _d->_state == INIT )
- {
- _d->_state = RUN;
- }
+ doReport = true;
}
}
else
{
if ( Date::now() - _d->_last_send > 1 || _d->_state == END )
{
- DBG << str::form( "{%u|%s}(%d!)",
- numericId(), name().c_str(), _d->_val ) << endl;
_d->_last_val = _d->_val;
_d->_last_send = Date::now();
- if ( _d->_state == INIT )
- {
- _d->_state = RUN;
- }
+ doReport = true;
+ }
+ }
+
+ // report if necessary
+ if ( doReport )
+ {
+ if ( _d->_state == INIT )
+ {
+ _d->_state = RUN;
}
+
+ if ( _d->_receiver )
+ {
+ goOn = _d->_receiver( _d->_last_val );
+ }
+ else
+ {
+ DBG << str::form( "{#%u|%s}(%lld%s)",
+ numericId(), name().c_str(),
+ _d->_last_val, ( hasRange() ? "%" : "!" ) ) << endl;
+ }
+ }
+
+ // log abort request and return
+ if ( ! goOn && _d->_state != END )
+ {
+ WAR << "User request to ABORT pending action. "
+ << str::form( "{#%u|%s}(%lld%s)",
+ numericId(), name().c_str(),
+ _d->_last_val, ( hasRange() ? "%" : "!" ) ) << endl;
}
+ return goOn;
}
/******************************************************************
Modified: trunk/libzypp/zypp/ProgressData.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ProgressData.h?rev=5467&r1=5466&r2=5467&view=diff
==============================================================================
--- trunk/libzypp/zypp/ProgressData.h (original)
+++ trunk/libzypp/zypp/ProgressData.h Wed May 2 19:18:55 2007
@@ -16,6 +16,7 @@
#include <string>
#include "zypp/base/PtrTypes.h"
+#include "zypp/base/Function.h"
#include "zypp/base/ProvideNumericId.h"
#include "zypp/Date.h"
@@ -47,9 +48,17 @@
{
public:
typedef long long value_type;
- enum State { INIT, RUN, END };
+ /** Most simple version of progress reporting - a single value.
+ * The percentage in most cases. Sometimes just keepalive.
+ *
+ * \todo tell recipient whether percentage or keepalive is sent
+ * and maybe tell whether task is abortable or not.
+ */
+ typedef function