Author: mlandres
Date: Mon May 7 10:10:10 2007
New Revision: 5506
URL: http://svn.opensuse.org/viewcvs/zypp?rev=5506&view=rev
Log:
restore original versions
Modified:
trunk/libzypp/zypp/ProgressData.cc
trunk/libzypp/zypp/ProgressData.h
trunk/libzypp/zypp/data/ResolvableData.cc
trunk/libzypp/zypp/data/ResolvableData.h
trunk/libzypp/zypp/parser/TagParser.cc
trunk/libzypp/zypp/parser/TagParser.h
Modified: trunk/libzypp/zypp/ProgressData.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ProgressData.cc?rev=5506&r1=5505&r2=5506&view=diff
==============================================================================
--- trunk/libzypp/zypp/ProgressData.cc (original)
+++ trunk/libzypp/zypp/ProgressData.cc Mon May 7 10:10:10 2007
@@ -27,39 +27,67 @@
// 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;
newVal /= ( _d->_max - _d->_min );
- if ( newVal - _d->_last_val > 5 || Date::now() - _d->_last_send > 1 || _d->_state == END )
+ if ( newVal - _d->_last_val > 20 || 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=5506&r1=5505&r2=5506&view=diff
==============================================================================
--- trunk/libzypp/zypp/ProgressData.h (original)
+++ trunk/libzypp/zypp/ProgressData.h Mon May 7 10:10:10 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"
@@ -41,15 +42,108 @@
* Each ProgressData object provides a unique numeric id and you may assign
* it a name.
*
- * \todo complete the progess sending.
+ * \code
+ * bool exampleReceiver( ProgressData::value_type v )
+ * {
+ * DBG << "got ->" << v << endl;
+ * return( v <= 100 ); // Abort if ( v > 100 )
+ * }
+ *
+ * class Example
+ * {
+ * public:
+ *
+ * Example( const ProgressData::ReceiverFnc & fnc_r = ProgressData::ReceiverFnc() )
+ * : _fnc( fnc_r )
+ * {}
+ *
+ * void SendTo( const ProgressData::ReceiverFnc & fnc_r )
+ * { _fnc = fnc_r; }
+ *
+ * public:
+ *
+ * void action()
+ * {
+ * ProgressData tics( 10 ); // Expect range 0 -> 10
+ * tics.name( "test ticks" ); // Some arbitrary name
+ * tics.sendTo( _fnc ); // Send reports to _fnc
+ * tics.toMin(); // start sending min (0)
+ *
+ * for ( int i = 0; i < 10; ++i )
+ * {
+ * if ( ! tics.set( i ) )
+ * return; // user requested abort
+ * }
+ *
+ * tics.toMax(); // take care 100% are reported on success
+ * }
+ *
+ * void action2()
+ * {
+ * ProgressData tics; // Just send 'still alive' messages
+ * tics.name( "test ticks" ); // Some arbitrary name
+ * tics.sendTo( _fnc ); // Send reports to _fnc
+ * tics.toMin(); // start sending min (0)
+ *
+ * for ( int i = 0; i < 10; ++i )
+ * {
+ * if ( ! tics.set( i ) )
+ * return; // user requested abort
+ * }
+ *
+ * tics.toMax(); //
+ * }
+ *
+ * private:
+ * ProgressData::ReceiverFnc _fnc;
+ * };
+ * \endcode
+ * \code
+ * Example t( exampleReceiver );
+ * DBG << "Reporting %:" << endl;
+ * t.action();
+ * DBG << "Reporting 'still alive':" << endl;
+ * t.action2();
+ * \endcode
+ * \code
+ * Reporting %:
+ * got ->0
+ * got ->10
+ * got ->20
+ * got ->30
+ * got ->40
+ * got ->50
+ * got ->60
+ * got ->70
+ * got ->80
+ * got ->90
+ * got ->100
+ * got ->100
+ * Reporting 'still alive':
+ * got ->0
+ * got ->9
+ * \endcode
+ *
+ * The different ammount of triggers is due to different rules for sending
+ * percent or 'still alive' messages.
+ *
+ * \todo Complete the progess sending.
+ * \todo Tell recipient whether percentage or keepalive is sent,
+ * the id and name might be helpfull, and maybe tell whether task
+ * is abortable or not; i.e extend the ReceiverFnc signature.
*/
class ProgressData : public base::ProvideNumericId
{
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.
+ */
+ typedef function ReceiverFnc;
private:
+ enum State { INIT, RUN, END };
+
class Data
{
public:
@@ -59,14 +153,15 @@
{}
public:
- State _state;
+ State _state;
std::string _name;
- value_type _min;
- value_type _max;
- value_type _val;
-
- value_type _last_val;
- Date _last_send;
+ value_type _min;
+ value_type _max;
+ value_type _val;
+
+ ReceiverFnc _receiver;
+ value_type _last_val;
+ Date _last_send;
private:
/** clone for RWCOW_pointer */
@@ -105,27 +200,6 @@
}
public:
- /** @return Current \c min value. */
- value_type min() const
- { return _d->_min; }
-
- /** @return Current \c max value. */
- value_type max() const
- { return _d->_max; }
-
- /** @return Current counter \c value. */
- value_type val() const
- { return _d->_val; }
-
- /** @return Wheter <tt>[min,max]</tt> defines a nonempty range. */
- bool hasRange() const
- { return min() != max(); }
-
- /** @return The counters name. */
- const std::string & name() const
- { return _d->_name; }
-
- public:
/** Set new \c min value. */
void min( value_type min_r )
{ _d->_min = min_r; }
@@ -147,41 +221,87 @@
{ min( min_r ); max( max_r ); }
public:
+ /** Set counter name. */
+ void name( const std::string & name_r )
+ { _d->_name = name_r; }
+
+ /** Set ReceiverFnc. */
+ void sendTo( const ReceiverFnc & fnc_r )
+ { _d->_receiver = fnc_r; }
+
+ /** Set no ReceiverFnc. */
+ void noSend()
+ { _d->_receiver = ReceiverFnc(); }
+
+ public:
+ /** \name Progress reporting.
+ *
+ * These methods may actually cause a progress report to be sent.
+ *
+ * All methods return \c bool, because a progress receiver may
+ * return \c false to indicate the desire to abort the pending
+ * action. The incident is logged, but it's finaly up to the caller
+ * to honor this.
+ */
+ //@{
+
/** Set new counter \c value. */
- void set( value_type val_r )
+ bool set( value_type val_r )
{
_d->_val = val_r;
- report();
+ return report();
}
/** Increment counter \c value (default by 1). */
- void incr( value_type val_r = 1 )
- { set( val() + val_r ); }
+ bool incr( value_type val_r = 1 )
+ { return set( val() + val_r ); }
/** Decrement counter \c value (default by 1). */
- void decr( value_type val_r = 1 )
- { set( val() - val_r ); }
+ bool decr( value_type val_r = 1 )
+ { return set( val() - val_r ); }
/** Set counter value to current \c min value. */
- void toMin()
- { set( min() ); }
+ bool toMin()
+ { return set( min() ); }
/** Set counter value to current \c max value (unless no range). */
- void toMax()
- { if ( hasRange() ) set( max() ); }
+ bool toMax()
+ { return set( hasRange() ? max() : val() ); }
/** Leave counter value unchanged (still alive). */
- void tick()
- { set( val() ); }
+ bool tick()
+ { return set( val() ); }
+
+ //@}
public:
- /** Set counter name. */
- void name( const std::string & name_r )
- { _d->_name = name_r; }
+ /** @return Current \c min value. */
+ value_type min() const
+ { return _d->_min; }
+
+ /** @return Current \c max value. */
+ value_type max() const
+ { return _d->_max; }
+
+ /** @return Current counter \c value. */
+ value_type val() const
+ { return _d->_val; }
+
+ /** @return Wheter <tt>[min,max]</tt> defines a nonempty range. */
+ bool hasRange() const
+ { return min() != max(); }
+
+ /** @return The counters name. */
+ const std::string & name() const
+ { return _d->_name; }
+
+ /** @return The ReceiverFnc. */
+ const ReceiverFnc & receiver() const
+ { return _d->_receiver; }
private:
/** Send report if necessary. */
- void report();
+ bool report();
/** Pointer to data. */
RWCOW_pointer<Data> _d;
Modified: trunk/libzypp/zypp/data/ResolvableData.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/data/ResolvableData.cc?rev=5506&r1=5505&r2=5506&view=diff
==============================================================================
--- trunk/libzypp/zypp/data/ResolvableData.cc (original)
+++ trunk/libzypp/zypp/data/ResolvableData.cc Mon May 7 10:10:10 2007
@@ -25,12 +25,14 @@
IMPL_PTR_TYPE(Patch);
IMPL_PTR_TYPE(Pattern);
IMPL_PTR_TYPE(Product);
+IMPL_PTR_TYPE(Packagebase);
IMPL_PTR_TYPE(Package);
+IMPL_PTR_TYPE(Sourcepackage);
std::ostream & ResObject::dumpOn( std::ostream & str ) const
{
- str << "[ " << name << " " << edition << " ]" << endl;
+ str << "[ " << name << " " << edition << " ]";
return str;
// << " provides: " << provides << endl
// << " conflicts: " << conflicts << endl
Modified: trunk/libzypp/zypp/data/ResolvableData.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/data/ResolvableData.h?rev=5506&r1=5505&r2=5506&view=diff
==============================================================================
--- trunk/libzypp/zypp/data/ResolvableData.h (original)
+++ trunk/libzypp/zypp/data/ResolvableData.h Mon May 7 10:10:10 2007
@@ -75,7 +75,6 @@
std::string vendor;
/** Installed size. \see zypp::ResObject::size() */
- /** Installed size. \see zypp::ResObject::size() */
ByteCount size;
/** RPM package size. \see zypp::ResObject::archive_size() */
ByteCount archive_size;
@@ -94,6 +93,10 @@
virtual std::ostream & dumpOn( std::ostream & str ) const;
};
+ ///////////////////////////////////////////////////////////////////
+
+ DEFINE_PTR_TYPE(AtomBase);
+
class AtomBase : public ResObject
{
public:
@@ -226,17 +229,19 @@
///////////////////////////////////////////////////////////////////
- DEFINE_PTR_TYPE(Package);
+ DEFINE_PTR_TYPE(Packagebase);
- /*
- * Data Object for Package
- * resolvable
+ /**
+ * Common Data Object for Package and Sourcepackage.
+ *
+ * We treat them as differend kind of Resolvable, but they have
+ * almost identical data.
*/
- class Package : public ResObject
+ class Packagebase : public ResObject
{
public:
- Package() {};
- ~Package() {};
+ Packagebase() {};
+ ~Packagebase() {};
std::string type;
CheckSum checksum;
@@ -266,7 +271,19 @@
Pathname location;
};
+ DEFINE_PTR_TYPE(Package);
+ /**
+ * Data Object for Package resolvable
+ */
+ struct Package : public Packagebase
+ {};
+ DEFINE_PTR_TYPE(Sourcepackage);
+ /**
+ * Data Object for Sourcepackage resolvable
+ */
+ struct Sourcepackage : public Packagebase
+ {};
///////////////////////////////////////////////////////////////////
template<class _Res> class SpecificData;
Modified: trunk/libzypp/zypp/parser/TagParser.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/TagParser.cc?rev=5506&r1=5505&r2=5506&view=diff
==============================================================================
--- trunk/libzypp/zypp/parser/TagParser.cc (original)
+++ trunk/libzypp/zypp/parser/TagParser.cc Mon May 7 10:10:10 2007
@@ -15,6 +15,8 @@
#include "zypp/base/Logger.h"
#include "zypp/base/String.h"
#include "zypp/base/IOStream.h"
+#include "zypp/base/UserRequestException.h"
+#include "zypp/parser/tagfile/ParseException.h"
#include "zypp/parser/TagParser.h"
#include "zypp/ProgressData.h"
@@ -93,6 +95,9 @@
void TagParser::endParse()
{}
+ void TagParser::userRequestedAbort( unsigned lineNo_r )
+ { ZYPP_THROW( AbortRequestException( errPrefix( lineNo_r ) ) ); }
+
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : TagParser::errPrefix
@@ -101,30 +106,31 @@
std::string TagParser::errPrefix( unsigned lineNo_r,
const std::string & msg_r ) const
{
- return str::form( "%s:%u:%s: %s",
+ return str::form( "%s:%u:- | %s",
_inputname.c_str(),
lineNo_r,
- "-",
msg_r.c_str() );
}
std::string TagParser::errPrefix( const SingleTagPtr & tag_r,
const std::string & msg_r ) const
{
- return str::form( "%s:%u:=%s %s",
+ return str::form( "%s:%u:=%s %s | %s",
_inputname.c_str(),
tag_r->lineNo,
tag_r->asString().c_str(),
+ tag_r->value.c_str(),
msg_r.c_str() );
}
std::string TagParser::errPrefix( const MultiTagPtr & tag_r,
const std::string & msg_r ) const
{
- return str::form( "%s:%u:+%s %s",
+ return str::form( "%s:%u:+%s (@%ld) | %s",
_inputname.c_str(),
tag_r->lineNo,
tag_r->asString().c_str(),
+ tag_r->value.size(),
msg_r.c_str() );
}
@@ -190,14 +196,16 @@
// METHOD NAME : TagParser::parse
// METHOD TYPE : void
//
- void TagParser::parse( const InputStream & input_r )
+ void TagParser::parse( const InputStream & input_r, const ProgressData::ReceiverFnc & fnc_r )
{
MIL << "Start parsing " << input_r << endl;
_inputname = input_r.name();
beginParse();
ProgressData ticks( makeProgressData( input_r ) );
- ticks.toMin();
+ ticks.sendTo( fnc_r );
+ if ( ! ticks.toMin() )
+ userRequestedAbort( 0 );
iostr::EachLine line( input_r );
for( ; line; line.next() )
@@ -317,10 +325,13 @@
break;
}
- ticks.set( input_r.stream().tellg() );
+
+ if ( ! ticks.set( input_r.stream().tellg() ) )
+ userRequestedAbort( line.lineNo() );
}
- ticks.toMax();
+ if ( ! ticks.toMax() )
+ userRequestedAbort( line.lineNo() );
endParse();
_inputname.clear();
Modified: trunk/libzypp/zypp/parser/TagParser.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/TagParser.h?rev=5506&r1=5505&r2=5506&view=diff
==============================================================================
--- trunk/libzypp/zypp/parser/TagParser.h (original)
+++ trunk/libzypp/zypp/parser/TagParser.h Mon May 7 10:10:10 2007
@@ -20,7 +20,7 @@
#include "zypp/base/NonCopyable.h"
#include "zypp/base/InputStream.h"
-#include "zypp/parser/tagfile/ParseException.h"
+#include "zypp/ProgressData.h"
///////////////////////////////////////////////////////////////////
namespace zypp
@@ -29,8 +29,6 @@
namespace parser
{ /////////////////////////////////////////////////////////////////
- using tagfile::ParseException;
-
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : TagParser
@@ -84,13 +82,15 @@
/** Dtor */
virtual ~TagParser();
/** Parse the stream.
- * \throw ParseExcetion on errors. Invoke \ref consume
- * for each tag. \ref consume might throw other exceptions
- * as well.
+ * \throw ParseExcetion on errors.
+ * \throws AbortRequestException on user request.
+ * Invokes \ref consume for each tag. \ref consume might throw
+ * other exceptions as well.
*/
- void parse( const InputStream & imput_r );
+ virtual void parse( const InputStream & imput_r,
+ const ProgressData::ReceiverFnc & fnc_r = ProgressData::ReceiverFnc() );
- public:
+ protected:
/** Called when start parsing. */
virtual void beginParse();
/** Called when a single-tag is found. */
@@ -100,7 +100,13 @@
/** Called when the parse is done. */
virtual void endParse();
- public:
+ protected:
+ /** Called when user(callback) request to abort.
+ * \throws AbortRequestException unless overloaded.
+ */
+ virtual void userRequestedAbort( unsigned lineNo_r );
+
+ protected:
/** Prefix exception message with line and tag information. */
std::string errPrefix( unsigned lineNo_r,
const std::string & msg_r = std::string() ) const;
@@ -116,7 +122,6 @@
private:
std::string _inputname;
- //ProgressData _ticks;
};
///////////////////////////////////////////////////////////////////
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org