View | Details | Raw Unified | Return to bug 168935
Collapse All | Expand All

(-)ZYppCallbacks.h (-1 / +2 lines)
Lines 224-230 Link Here
224
      
224
      
225
        virtual void start( Url file, Pathname localfile ) {}
225
        virtual void start( Url file, Pathname localfile ) {}
226
226
227
        virtual bool progress(int value, Url file) 
227
        virtual bool progress(int value, Url file, double dbps_avg = 0,
228
                                                   double dbps_now = 0)
228
        { return true; }
229
        { return true; }
229
230
230
        virtual Action problem(
231
        virtual Action problem(
(-)media/MediaCurl.cc (-9 / +43 lines)
Lines 91-96 Link Here
91
	, reached(false)
91
	, reached(false)
92
	, report(_report)
92
	, report(_report)
93
	, ltime( time(NULL))
93
	, ltime( time(NULL))
94
	, secs(  0)
94
	, dload( 0)
95
	, dload( 0)
95
	, uload( 0)
96
	, uload( 0)
96
	, url(_url)
97
	, url(_url)
Lines 99-104 Link Here
99
      bool                                          reached;
100
      bool                                          reached;
100
      callback::SendReport<DownloadProgressReport> *report;
101
      callback::SendReport<DownloadProgressReport> *report;
101
      time_t                                        ltime;
102
      time_t                                        ltime;
103
      long                                          secs;
102
      double                                        dload;
104
      double                                        dload;
103
      double                                        uload;
105
      double                                        uload;
104
      zypp::Url                                     url;
106
      zypp::Url                                     url;
Lines 1035-1050 Link Here
1035
//
1037
//
1036
//	DESCRIPTION : Progress callback triggered from MediaCurl::getFile
1038
//	DESCRIPTION : Progress callback triggered from MediaCurl::getFile
1037
//
1039
//
1038
int MediaCurl::progressCallback( void *clientp, double dltotal, double dlnow,
1040
int MediaCurl::progressCallback( void *clientp,
1039
                                 double ultotal, double ulnow )
1041
                                 double dltotal, double dlnow,
1042
                                 double ultotal, double ulnow)
1040
{
1043
{
1041
  ProgressData *pdata = reinterpret_cast<ProgressData *>(clientp);
1044
  ProgressData *pdata = reinterpret_cast<ProgressData *>(clientp);
1042
  if( pdata)
1045
  if( pdata)
1043
  {
1046
  {
1047
    double drate_avg = 0;
1048
    double drate_now = 0;
1049
    time_t now   = time(NULL);
1050
    if( now > 0)
1051
    {
1052
    	// reset time of last change in case initial time()
1053
	// failed or the time was adjusted (goes backward)
1054
	if( pdata->ltime <= 0 || pdata->ltime > now)
1055
	{
1056
	  pdata->ltime = now;
1057
	}
1058
1059
	//
1060
	// dif: this callback is called every seconds, but
1061
	// there is also some run time of the callback code
1062
	// and it can happen that we "step over" a second.
1063
	//
1064
	// start time counting as soon as first data arrives
1065
	// (skip the connection / redirection time at begin)
1066
	//
1067
	time_t dif = 1;
1068
	if( pdata->secs > 0 || dlnow > 0 || ulnow > 0)
1069
	{
1070
    	  dif = (now - pdata->ltime);
1071
	  dif = dif > 1 ? dif : 1;
1072
1073
	  pdata->secs += dif;
1074
	}
1075
1076
	if( pdata->secs > 0)
1077
	  drate_avg = (dlnow / pdata->secs);
1078
1079
	if( dlnow > pdata->dload)
1080
	  drate_now = ((dlnow - pdata->dload) / dif);
1081
    }
1082
1044
    // send progress report first, abort transfer if requested
1083
    // send progress report first, abort transfer if requested
1045
    if( pdata->report)
1084
    if( pdata->report)
1046
    {
1085
    {
1047
      if (! (*(pdata->report))->progress(int( dlnow * 100 / dltotal ), pdata->url))
1086
      if (! (*(pdata->report))->progress(int( dlnow * 100 / dltotal ),
1087
	                                 pdata->url, drate_avg, drate_now))
1048
      {
1088
      {
1049
	return 1; // abort transfer
1089
	return 1; // abort transfer
1050
      }
1090
      }
Lines 1053-1068 Link Here
1053
    // check if we there is a timeout set
1093
    // check if we there is a timeout set
1054
    if( pdata->timeout > 0)
1094
    if( pdata->timeout > 0)
1055
    {
1095
    {
1056
      time_t now = time(NULL);
1057
      if( now > 0)
1096
      if( now > 0)
1058
      {
1097
      {
1059
	bool progress = false;
1098
	bool progress = false;
1060
1099
1061
	// reset time of last change in case initial time()
1062
	// failed or the time was adjusted (goes backward)
1063
	if( pdata->ltime <= 0 || pdata->ltime > now)
1064
	  pdata->ltime = now;
1065
1066
	// update download data if changed, mark progress
1100
	// update download data if changed, mark progress
1067
	if( dlnow != pdata->dload)
1101
	if( dlnow != pdata->dload)
1068
	{
1102
	{

Return to bug 168935