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