00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef CONTAINER_H
00024 #define CONTAINER_H
00025
00026 #include <list>
00027
00028 #include "y2storage/Volume.h"
00029 #include "y2storage/StorageTypes.h"
00030 #include "y2storage/StorageTmpl.h"
00031
00032 namespace storage
00033 {
00034
00035 class Container
00036 {
00037 friend class Storage;
00038 protected:
00039 template<typename L1, typename L2> friend class ListListIterator;
00040
00041 typedef std::list<Volume*> VCont;
00042 typedef VCont::iterator VIter;
00043 typedef VCont::const_iterator CVIter;
00044 typedef VCont::reverse_iterator RVIter;
00045 typedef VCont::const_reverse_iterator CRVIter;
00046
00047
00048 public:
00049 bool operator== ( const Container& rhs ) const
00050 { return( typ == rhs.typ && nm == rhs.nm && del == rhs.del ); }
00051 bool operator!= ( const Container& rhs ) const
00052 { return( !(*this==rhs) ); }
00053 bool operator< ( const Container& rhs ) const
00054 {
00055 if( typ != rhs.typ )
00056 return( typ<rhs.typ );
00057 else if( nm != rhs.nm )
00058 return( nm<rhs.nm );
00059 else
00060 return( !del );
00061 }
00062 bool operator<= ( const Container& rhs ) const
00063 { return( *this<rhs || *this==rhs ); }
00064 bool operator>= ( const Container& rhs ) const
00065 { return( !(*this<rhs) ); }
00066 bool operator> ( const Container& rhs ) const
00067 { return( !(*this<=rhs) ); }
00068 virtual bool equalContent( const Container& rhs ) const;
00069 virtual string getDiffString( const Container& c ) const;
00070 virtual void logDifference( const Container& c ) const;
00071
00072 virtual void getCommitActions( std::list<storage::commitAction*>& l ) const;
00073 virtual int getToCommit( storage::CommitStage stage,
00074 std::list<Container*>& col,
00075 std::list<Volume*>& vol );
00076
00077 virtual int commitChanges( storage::CommitStage stage );
00078 virtual int commitChanges( storage::CommitStage stage, Volume* vol );
00079 virtual void changeDeviceName( const string& old, const string& nw ) {}
00080 unsigned numVolumes() const;
00081 bool isEmpty() const;
00082 void getInfo( storage::ContainerInfo& info ) const;
00083 bool findVolume( const string& device, Volume*& vol );
00084
00085
00086 protected:
00087
00088 template< class Pred >
00089 struct ConstVolumePI { typedef ContainerIter<Pred, CVIter> type; };
00090 template< class Pred >
00091 struct VolumePI { typedef ContainerIter<Pred, VIter> type; };
00092 template< class Pred >
00093 struct VolumeI { typedef ContainerDerIter<Pred, typename VolumePI<Pred>::type, Volume> type; };
00094 typedef CheckFnc<const Volume> CheckFncVol;
00095 typedef CheckerIterator< CheckFncVol, ConstVolumePI<CheckFncVol>::type,
00096 CVIter, Volume> ConstVolPIterator;
00097 typedef CheckerIterator< CheckFncVol, VolumePI<CheckFncVol>::type,
00098 VIter, Volume> VolPIterator;
00099 typedef DerefIterator<VolPIterator,Volume> VolIterator;
00100 typedef IterPair<VolIterator> VolPair;
00101
00102 public:
00103
00104 template< class Pred >
00105 struct ConstVolumeI { typedef ContainerDerIter<Pred, typename ConstVolumePI<Pred>::type, const Volume> type; };
00106 template< class Pred >
00107 struct VolCondIPair { typedef MakeCondIterPair<Pred, typename ConstVolumeI<Pred>::type> type;};
00108 typedef DerefIterator<ConstVolPIterator,const Volume> ConstVolIterator;
00109 typedef IterPair<ConstVolIterator> ConstVolPair;
00110
00111
00112 ConstVolPair volPair( bool (* CheckFnc)( const Volume& )=NULL ) const
00113 {
00114 return( ConstVolPair( volBegin( CheckFnc ), volEnd( CheckFnc ) ));
00115 }
00116 ConstVolIterator volBegin( bool (* CheckFnc)( const Volume& )=NULL ) const
00117 {
00118 return( ConstVolIterator( ConstVolPIterator(vols.begin(), vols.end(), CheckFnc )) );
00119 }
00120 ConstVolIterator volEnd( bool (* CheckFnc)( const Volume& )=NULL ) const
00121 {
00122 return( ConstVolIterator( ConstVolPIterator(vols.begin(), vols.end(), CheckFnc, true )) );
00123 }
00124
00125 template< class Pred > typename VolCondIPair<Pred>::type volCondPair( const Pred& p ) const
00126 {
00127 return( VolCondIPair<Pred>::type( volCondBegin( p ), volCondEnd( p ) ) );
00128 }
00129 template< class Pred > typename ConstVolumeI<Pred>::type volCondBegin( const Pred& p ) const
00130 {
00131 return( ConstVolumeI<Pred>::type( vols.begin(), vols.end(), p ) );
00132 }
00133 template< class Pred > typename ConstVolumeI<Pred>::type volCondEnd( const Pred& p ) const
00134 {
00135 return( ConstVolumeI<Pred>::type( vols.begin(), vols.end(), p, true ) );
00136 }
00137
00138 protected:
00139
00140 VolPair volPair( bool (* CheckFnc)( const Volume& )=NULL )
00141 {
00142 return( VolPair( vBegin( CheckFnc ), vEnd( CheckFnc ) ));
00143 }
00144 VolIterator vBegin( bool (* CheckFnc)( const Volume& )=NULL )
00145 {
00146 return( VolIterator( VolPIterator(vols.begin(), vols.end(), CheckFnc )) );
00147 }
00148 VolIterator vEnd( bool (* CheckFnc)( const Volume& )=NULL )
00149 {
00150 return( VolIterator( VolPIterator(vols.begin(), vols.end(), CheckFnc, true )) );
00151 }
00152
00153 public:
00154 Container( Storage * const, const string& Name, storage::CType typ );
00155 Container( const Container& );
00156 Storage * getStorage() const { return sto; }
00157 virtual ~Container();
00158 const string& name() const { return nm; }
00159 const string& device() const { return dev; }
00160 storage::CType type() const { return typ; }
00161 bool deleted() const { return del; }
00162 bool created() const { return create; }
00163 void setDeleted( bool val=true ) { del=val; }
00164 void setCreated( bool val=true ) { create=val; }
00165 void setSilent( bool val=true ) { silent=val; }
00166
00167 void clearUsedBy() { uby.clear(); }
00168 void setUsedBy(storage::UsedByType ub_type, const string& ub_name) { uby.set(ub_type, ub_name); }
00169 const storage::usedBy& getUsedBy() const { return uby; }
00170 storage::UsedByType getUsedByType() const { return uby.type(); }
00171
00172 bool readonly() const { return ronly; }
00173 unsigned long minorNr() const { return mnr; }
00174 unsigned long majorNr() const { return mjr; }
00175 unsigned long long sizeK() const { return size_k; }
00176 virtual string removeText(bool doing=true) const;
00177 virtual string createText(bool doing=true) const;
00178 virtual int resizeVolume( Volume* v, unsigned long long newSize );
00179 virtual int removeVolume( Volume* v );
00180 static storage::CType staticType() { return storage::CUNKNOWN; }
00181 friend std::ostream& operator<< (std::ostream& s, const Container &c );
00182 virtual Container* getCopy() const { return( new Container( *this ) ); }
00183 bool compareContainer( const Container* c, bool verbose ) const;
00184 void setExtError( const string& txt ) const;
00185 void setExtError( const SystemCmd& cmd, bool serr=true ) const;
00186
00187 protected:
00188 typedef CVIter ConstPlainIterator;
00189 ConstPlainIterator begin() const { return vols.begin(); }
00190 ConstPlainIterator end() const { return vols.end(); }
00191
00192 typedef VIter PlainIterator;
00193 PlainIterator begin() { return vols.begin(); }
00194 PlainIterator end() { return vols.end(); }
00195
00196 virtual void print( std::ostream& s ) const { s << *this; }
00197 void addToList( Volume* e )
00198 { pointerIntoSortedList<Volume>( vols, e ); }
00199 bool removeFromList( Volume* e );
00200 virtual int doCreate( Volume * v );
00201 virtual int doRemove( Volume * v );
00202 virtual int doResize( Volume * v );
00203 virtual void logData( const string& Dir ) {}
00204 Container& operator=( const Container& );
00205
00206 static bool stageDecrease(const Volume& v);
00207 static bool stageIncrease(const Volume& v);
00208 static bool stageFormat(const Volume& v);
00209 static bool stageMount(const Volume& v);
00210
00211 static const string type_names[COTYPE_LAST_ENTRY];
00212
00213 Storage * const sto;
00214 storage::CType typ;
00215 string nm;
00216 string dev;
00217 bool del;
00218 bool create;
00219 bool silent;
00220 bool ronly;
00221 storage::usedBy uby;
00222 unsigned long long size_k;
00223 unsigned long mnr;
00224 unsigned long mjr;
00225 VCont vols;
00226 mutable storage::ContainerInfo info;
00227 };
00228
00229 }
00230
00231 #endif