00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef SYSTEM_INFO_H
00024 #define SYSTEM_INFO_H
00025
00026
00027 #include <boost/noncopyable.hpp>
00028
00029 #include "storage/AppUtil.h"
00030 #include "storage/ProcParts.h"
00031 #include "storage/ProcMounts.h"
00032 #include "storage/ProcMdstat.h"
00033 #include "storage/Blkid.h"
00034 #include "storage/Lsscsi.h"
00035 #include "storage/Parted.h"
00036 #include "storage/Dasdview.h"
00037 #include "storage/DmCo.h"
00038 #include "storage/DmraidCo.h"
00039 #include "storage/DmmultipathCo.h"
00040
00041 namespace storage
00042 {
00043 using std::map;
00044 using std::list;
00045
00046 class CmdBtrfsShow
00047 {
00048 public:
00049 CmdBtrfsShow();
00050 struct Entry
00051 {
00052 list<string> devices;
00053 };
00054 bool getEntry(const string& uuid, Entry& entry) const;
00055 list<string> getUuids() const;
00056
00057 private:
00058 typedef map<string, Entry>::const_iterator const_iterator;
00059
00060 map< string, Entry > fs;
00061 };
00062
00063 class SystemInfo : boost::noncopyable
00064 {
00065
00066 public:
00067
00068 SystemInfo();
00069 ~SystemInfo();
00070
00071 const UdevMap& getUdevMap(const string& path) { return udevmaps.get(path); }
00072 const ProcParts& getProcParts() { return *procparts; }
00073 const ProcMounts& getProcMounts() { return *procmounts; }
00074 const ProcMdstat& getProcMdstat() { return *procmdstat; }
00075 const Blkid& getBlkid() { return *blkid; }
00076 const Lsscsi& getLsscsi() { return *lsscsi; }
00077 const Parted& getParted(const string& device) { return parteds.get(device); }
00078 const Dasdview& getDasdview(const string& device) { return dasdviews.get(device); }
00079 const Fdasd& getFdasd(const string& device) { return fdasds.get(device); }
00080 const CmdDmsetup& getCmdDmsetup() { return *cmddmsetup; }
00081 const CmdDmraid& getCmdDmraid() { return *cmddmraid; }
00082 const CmdMultipath& getCmdMultipath() { return *cmdmultipath; }
00083 const CmdBtrfsShow& getCmdBtrfsShow() { return *cmdbtrfsshow; }
00084
00085 private:
00086
00087 template <class Type>
00088 class LazyObject : boost::noncopyable
00089 {
00090 public:
00091
00092 LazyObject() : ptr(NULL) {}
00093 ~LazyObject() { delete ptr; }
00094
00095 const Type& operator*() { if (!ptr) ptr = new Type(); return *ptr; }
00096
00097 private:
00098
00099 Type* ptr;
00100
00101 };
00102
00103 template <class Type>
00104 class LazyObjects : boost::noncopyable
00105 {
00106 public:
00107
00108 const Type& get(const string& s)
00109 {
00110 typename map<string, Type>::iterator pos = data.lower_bound(s);
00111 if (pos == data.end() || typename map<string, Type>::key_compare()(s, pos->first))
00112 {
00113 Type tmp(s);
00114 pos = data.insert(pos, typename map<string, Type>::value_type(s, tmp));
00115 }
00116 return pos->second;
00117 }
00118
00119 private:
00120
00121 map<string, Type> data;
00122
00123 };
00124
00125 LazyObjects<UdevMap> udevmaps;
00126 LazyObject<ProcParts> procparts;
00127 LazyObject<ProcMounts> procmounts;
00128 LazyObject<ProcMdstat> procmdstat;
00129 LazyObject<Blkid> blkid;
00130 LazyObject<Lsscsi> lsscsi;
00131 LazyObjects<Parted> parteds;
00132 LazyObjects<Fdasd> fdasds;
00133 LazyObjects<Dasdview> dasdviews;
00134 LazyObject<CmdDmsetup> cmddmsetup;
00135 LazyObject<CmdDmraid> cmddmraid;
00136 LazyObject<CmdMultipath> cmdmultipath;
00137 LazyObject<CmdBtrfsShow> cmdbtrfsshow;
00138
00139 };
00140
00141 }
00142
00143
00144 #endif