00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef ZYPP_SOLVER_DETAIL_PENDING_H
00023 #define ZYPP_SOLVER_DETAIL_PENDING_H
00024
00025 #include <iosfwd>
00026 #include <list>
00027 #include <string>
00028
00029 #include "zypp/base/ReferenceCounted.h"
00030 #include "zypp/base/NonCopyable.h"
00031 #include "zypp/base/PtrTypes.h"
00032
00034 namespace zypp
00035 {
00036
00037 namespace solver
00038 {
00039
00040 namespace detail
00041 {
00042
00043 DEFINE_PTR_TYPE(Pending);
00044
00045 typedef std::list <Pending_Ptr> PendingList;
00046 typedef PendingList * PendingList_Ptr;
00047
00049
00050
00051
00052 class Pending : public base::ReferenceCounted, private base::NonCopyable {
00053
00054
00055 typedef enum {
00056 PENDING_STATUS_INVALID = 0,
00057 PENDING_STATUS_PRE_BEGIN,
00058 PENDING_STATUS_RUNNING,
00059 PENDING_STATUS_BLOCKING,
00060 PENDING_STATUS_ABORTED,
00061 PENDING_STATUS_FAILED,
00062 PENDING_STATUS_FINISHED
00063 } PendingStatus;
00064
00065 const char *pendingStatusToString (PendingStatus status);
00066
00067 #define INVALID_PENDING_ID 0
00068
00069
00070 private:
00071
00072 char *_description;
00073 int _id;
00074
00075 PendingStatus _status;
00076
00077 double _percent_complete;
00078
00079 size_t _completed_size;
00080 size_t _total_size;
00081
00082 time_t _start_time;
00083 time_t _last_time;
00084 time_t _poll_time;
00085
00086 int _retval;
00087 char *_error_msg;
00088
00089 std::list<const char *> _messages;
00090
00091 void (*_update) (Pending_Ptr);
00092 void (*_complete) (Pending_Ptr);
00093 void (*_message) (Pending_Ptr);
00094
00095 public:
00096
00097 Pending (const char *description);
00098 virtual ~Pending();
00099
00100
00101
00102 static std::string toString (const Pending & section);
00103
00104 virtual std::ostream & dumpOn(std::ostream & str ) const;
00105
00106 friend std::ostream& operator<<(std::ostream&, const Pending & section);
00107
00108 std::string asString (void) const;
00109
00110
00111
00112 const char *description (void) const { return _description; }
00113 void setDescription (const char *description) { _description = strdup (description); }
00114 int id (void) const { return _id; }
00115 PendingStatus status (void) const { return _status; }
00116 double percentComplete (void) const { return _percent_complete; }
00117 size_t completedSize (void) const { return _completed_size; }
00118 size_t totalSize (void) const { return _total_size; }
00119 time_t startTime (void) const { return _start_time; }
00120 time_t lastTime (void) const { return _last_time; }
00121 time_t pollTime (void) const { return _poll_time; }
00122
00123 int elapsedSecs (void) const { return 0; }
00124 int expectedSecs (void) const { return 0; }
00125 int remainingSecs (void) const { return 0; }
00126
00127 std::list<const char *> messages (void) const { return _messages; }
00128 const char *latestMessage (void) const { return _error_msg; }
00129
00130
00131
00132 Pending_Ptr lookupById (int id);
00133 std::list<Pending_Ptr> getAllActiveIds (void);
00134
00135 void begin (void);
00136 void update (double percent_complete);
00137 void updateBySize (size_t size, size_t total_size);
00138
00139 void finished (int retval);
00140 void abort (int retval);
00141 void fail (int retval, const char *error_msg);
00142
00143 bool isActive (void);
00144
00145 const char *errorMsg (void);
00146
00147 void addMessage (const char *message);
00148
00149 };
00150
00152 };
00155 };
00158 };
00160
00161 #endif // ZYPP_SOLVER_DETAIL_PENDING_H