degate  0.1.2
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
degate::ProgressControl Class Reference

#include <ProgressControl.h>

Inheritance diagram for degate::ProgressControl:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 ProgressControl ()
 The constructor.
virtual ~ProgressControl ()
 The destructor for a plugin.
virtual bool is_canceled () const
 Check if the process is canceled.
virtual void cancel ()
 Stop the processing.
virtual double get_progress () const
 Get progress.
virtual time_t get_time_passed () const
 Get (real) time since the progress counter was resetted.
virtual time_t get_time_left () const
 Get estimated time left in seconds.
virtual std::string get_time_left_as_string ()
virtual void set_log_message (std::string const &msg)
virtual std::string get_log_message () const
virtual bool has_log_message () const

Protected Member Functions

virtual void set_progress (double progress)
 Set progress.
virtual void set_progress_step_size (double step_size)
 Set step size.
virtual void progress_step_done ()
 Increase progress.
virtual void reset_progress ()
 Reset progress and cancel state.

Private Member Functions

time_t get_time_left_averaged ()

Private Attributes

double progress
bool canceled
double step_size
time_t time_started
time_t estimated [averaging_buf_size]
int estimated_idx
std::string log_message
bool log_message_set
boost::recursive_mutex mtx

Static Private Attributes

static const int averaging_buf_size = 5

Detailed Description

Definition at line 34 of file ProgressControl.h.


Constructor & Destructor Documentation

The constructor.

Definition at line 116 of file ProgressControl.h.

References reset_progress().

Here is the call graph for this function:

virtual degate::ProgressControl::~ProgressControl ( ) [inline, virtual]

The destructor for a plugin.

Definition at line 124 of file ProgressControl.h.

{}

Member Function Documentation

virtual void degate::ProgressControl::cancel ( ) [inline, virtual]

Stop the processing.

Definition at line 139 of file ProgressControl.h.

References canceled, and mtx.

                          {
      boost::recursive_mutex::scoped_lock(mtx);
      canceled = true;
    }
virtual std::string degate::ProgressControl::get_log_message ( ) const [inline, virtual]

Definition at line 201 of file ProgressControl.h.

References log_message, and mtx.

                                              {
      boost::recursive_mutex::scoped_lock(mtx);
      return log_message;
    }
virtual double degate::ProgressControl::get_progress ( ) const [inline, virtual]

Get progress.

Returns:
Returns a value between 0 and 100 percent.

Definition at line 150 of file ProgressControl.h.

References mtx, and progress.

                                        {
      boost::recursive_mutex::scoped_lock(mtx);
      return progress;
    }
virtual time_t degate::ProgressControl::get_time_left ( ) const [inline, virtual]

Get estimated time left in seconds.

Returns:
Returns the time to go in seconds or -1, if that time cannot be calculated.

Definition at line 168 of file ProgressControl.h.

References get_time_passed(), mtx, and progress.

Referenced by get_time_left_averaged().

                                         {
      boost::recursive_mutex::scoped_lock(mtx);
      if(progress < 1.0)
        return progress > 0 ? (1.0 - progress) * get_time_passed() / progress : -1;
      return 0;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual std::string degate::ProgressControl::get_time_left_as_string ( ) [inline, virtual]

Definition at line 175 of file ProgressControl.h.

References get_time_left_averaged(), and mtx.

                                                {
      boost::recursive_mutex::scoped_lock(mtx);
      time_t time_left = get_time_left_averaged();
      if(time_left == -1) return std::string("-");
      else {
        char buf[100];
        if(time_left < 60)
          snprintf(buf, sizeof(buf), "%d s", (int)time_left);
        else if(time_left < 60*60)
          snprintf(buf, sizeof(buf), "%d:%02d m", (int)time_left / 60, (int)time_left % 60);
        else {
          unsigned int minutes = (int)time_left / 60;
          snprintf(buf, sizeof(buf), "%d:%02d h", minutes / 60, (int)time_left % 60);
        }
        return std::string(buf);
      }

    }

Here is the call graph for this function:

Definition at line 56 of file ProgressControl.h.

References averaging_buf_size, estimated, estimated_idx, and get_time_left().

Referenced by get_time_left_as_string().

                                    {
      estimated[estimated_idx++] = get_time_left();
      estimated_idx %= averaging_buf_size;

      unsigned int sum = 0, valid_values = 0;
      for(int i = 0; i < averaging_buf_size; i++)
        if(estimated[i] != -1) {
          sum += estimated[i];
          valid_values++;
        }

      return valid_values > 0 ? sum / valid_values : get_time_left_averaged();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual time_t degate::ProgressControl::get_time_passed ( ) const [inline, virtual]

Get (real) time since the progress counter was resetted.

Definition at line 158 of file ProgressControl.h.

References time_started.

Referenced by get_time_left().

                                           {
      boost::mutex::scoped_lock(m_mutex);
      return time(NULL) - time_started;
    }

Here is the caller graph for this function:

virtual bool degate::ProgressControl::has_log_message ( ) const [inline, virtual]

Definition at line 206 of file ProgressControl.h.

References log_message_set, and mtx.

                                         {
      boost::recursive_mutex::scoped_lock(mtx);
      return log_message_set;
    }
virtual bool degate::ProgressControl::is_canceled ( ) const [inline, virtual]

Check if the process is canceled.

Definition at line 130 of file ProgressControl.h.

References canceled, and mtx.

Referenced by degate::TemplateMatching::match_single_template(), degate::TemplateMatching::run(), and degate::ViaMatching::scan().

                                     {
      boost::recursive_mutex::scoped_lock(mtx);
      return canceled;
    }

Here is the caller graph for this function:

virtual void degate::ProgressControl::progress_step_done ( ) [inline, protected, virtual]

Increase progress.

Definition at line 91 of file ProgressControl.h.

References mtx, progress, and step_size.

Referenced by degate::TemplateMatching::run(), and degate::ViaMatching::scan().

                                      {
      boost::recursive_mutex::scoped_lock(mtx);
      progress += step_size;
    }

Here is the caller graph for this function:

virtual void degate::ProgressControl::reset_progress ( ) [inline, protected, virtual]

Reset progress and cancel state.

Definition at line 99 of file ProgressControl.h.

References averaging_buf_size, canceled, estimated, estimated_idx, mtx, progress, and time_started.

Referenced by degate::ViaMatching::init(), degate::TemplateMatching::init(), ProgressControl(), degate::TemplateMatching::run(), and degate::ViaMatching::scan().

                                  {
      boost::recursive_mutex::scoped_lock(mtx);
      time_started = time(NULL);
      canceled = false;
      progress = 0;

      for(int i = 0; i < averaging_buf_size; i++) estimated[i] = -1;

      estimated_idx = 0;
    }

Here is the caller graph for this function:

virtual void degate::ProgressControl::set_log_message ( std::string const &  msg) [inline, virtual]

Definition at line 195 of file ProgressControl.h.

References log_message, log_message_set, and mtx.

Referenced by degate::TemplateMatching::run().

                                                       {
      boost::recursive_mutex::scoped_lock(mtx);
      log_message = msg;
      log_message_set = true;
    }

Here is the caller graph for this function:

virtual void degate::ProgressControl::set_progress ( double  progress) [inline, protected, virtual]

Set progress.

Definition at line 75 of file ProgressControl.h.

References mtx, and progress.

                                               {
      boost::recursive_mutex::scoped_lock(mtx);
      this->progress = progress;
    }
virtual void degate::ProgressControl::set_progress_step_size ( double  step_size) [inline, protected, virtual]

Set step size.

Definition at line 83 of file ProgressControl.h.

References mtx, and step_size.

Referenced by degate::ViaMatching::run(), and degate::TemplateMatching::run().

                                                          {
      boost::recursive_mutex::scoped_lock(mtx);
      this->step_size = step_size;
    }

Here is the caller graph for this function:


Member Data Documentation

const int degate::ProgressControl::averaging_buf_size = 5 [static, private]

Definition at line 38 of file ProgressControl.h.

Referenced by get_time_left_averaged(), and reset_progress().

Definition at line 41 of file ProgressControl.h.

Referenced by cancel(), is_canceled(), and reset_progress().

Definition at line 46 of file ProgressControl.h.

Referenced by get_time_left_averaged(), and reset_progress().

Definition at line 47 of file ProgressControl.h.

Referenced by get_time_left_averaged(), and reset_progress().

std::string degate::ProgressControl::log_message [private]

Definition at line 49 of file ProgressControl.h.

Referenced by get_log_message(), and set_log_message().

Definition at line 50 of file ProgressControl.h.

Referenced by has_log_message(), and set_log_message().

boost::recursive_mutex degate::ProgressControl::mtx [private]

Definition at line 43 of file ProgressControl.h.

Referenced by progress_step_done(), and set_progress_step_size().

Definition at line 44 of file ProgressControl.h.

Referenced by get_time_passed(), and reset_progress().


The documentation for this class was generated from the following file: