Back to index

lshw  02.16
hw.h
Go to the documentation of this file.
00001 #ifndef _HW_H_
00002 #define _HW_H_
00003 
00004 #include <string>
00005 #include <vector>
00006 
00007 using namespace std;
00008 
00009 namespace hw
00010 {
00011 
00012   typedef enum
00013   {
00014     system,
00015     bridge,
00016     memory,
00017     processor,
00018     address,
00019     storage,
00020     disk,
00021     tape,
00022     bus,
00023     network,
00024     display,
00025     input,
00026     printer,
00027     multimedia,
00028     communication,
00029     power,
00030     volume,
00031     generic
00032   } hwClass;
00033 
00034   typedef enum { none, iomem, ioport, mem, irq, dma }
00035   hwResourceType;
00036   typedef enum { nil, boolean, integer, text }
00037   hwValueType;
00038 
00039   string strip(const string &);
00040   string asString(long);
00041 
00042   string reportSize(unsigned long long);
00043 
00044   class resource
00045   {
00046     public:
00047 
00048       resource();
00049       ~resource();
00050       resource(const resource &);
00051       resource & operator =(const resource &);
00052 
00053       static resource iomem(unsigned long long, unsigned long long);
00054       static resource ioport(unsigned long, unsigned long);
00055       static resource mem(unsigned long long, unsigned long long, bool prefetchable = false);
00056       static resource irq(unsigned int);
00057       static resource dma(unsigned int);
00058 
00059       bool operator ==(const resource &) const;
00060 
00061       string asString(const string & separator = ":") const;
00062 
00063     private:
00064       struct resource_i * This;
00065 
00066   };
00067 
00068   class value
00069   {
00070     public:
00071 
00072       value();
00073       ~value();
00074       value(const value &);
00075       value(long long);
00076       value(const string &);
00077       value & operator =(const value &);
00078 
00079       bool operator ==(const value &) const;
00080 
00081       string asString() const;
00082       bool defined() const;
00083 
00084     private:
00085       struct value_i * This;
00086 
00087   };
00088 
00089 }                                                 // namespace hw
00090 
00091 
00092 class hwNode
00093 {
00094   public:
00095     hwNode(const string & id,
00096       hw::hwClass c = hw::generic,
00097       const string & vendor = "",
00098       const string & product = "",
00099       const string & version = "");
00100     hwNode(const hwNode & o);
00101     ~hwNode();
00102     hwNode & operator =(const hwNode & o);
00103 
00104     string getId() const;
00105 
00106     void setHandle(const string & handle);
00107     string getHandle() const;
00108 
00109     bool enabled() const;
00110     bool disabled() const;
00111     void enable();
00112     void disable();
00113     bool claimed() const;
00114     void claim(bool claimchildren=false);
00115     void unclaim();
00116 
00117     hw::hwClass getClass() const;
00118     const char * getClassName() const;
00119     void setClass(hw::hwClass c);
00120 
00121     string getDescription() const;
00122     void setDescription(const string & description);
00123 
00124     string getVendor() const;
00125     void setVendor(const string & vendor);
00126 
00127     string getProduct() const;
00128     void setProduct(const string & product);
00129 
00130     string getVersion() const;
00131     void setVersion(const string & version);
00132 
00133     string getDate() const;
00134     void setDate(const string &);
00135 
00136     string getSerial() const;
00137     void setSerial(const string & serial);
00138 
00139     unsigned long long getStart() const;
00140     void setStart(unsigned long long start);
00141 
00142     unsigned long long getSize() const;
00143     void setSize(unsigned long long size);
00144 
00145     unsigned long long getCapacity() const;
00146     void setCapacity(unsigned long long capacity);
00147 
00148     unsigned long long getClock() const;
00149     void setClock(unsigned long long clock);
00150 
00151     unsigned int getWidth() const;
00152     void setWidth(unsigned int width);
00153 
00154     string getSlot() const;
00155     void setSlot(const string & slot);
00156 
00157     unsigned int countChildren(hw::hwClass c = hw::generic) const;
00158     hwNode * getChild(unsigned int);
00159     hwNode * getChildByPhysId(long);
00160     hwNode * getChildByPhysId(const string &);
00161     hwNode * getChild(const string & id);
00162     hwNode * findChildByHandle(const string & handle);
00163     hwNode * findChildByLogicalName(const string & handle);
00164     hwNode * findChildByBusInfo(const string & businfo);
00165     hwNode * findChildByResource(const hw::resource &);
00166     hwNode * findChild(bool(*matchfunction)(const hwNode &));
00167     hwNode * addChild(const hwNode & node);
00168     bool isBus() const
00169     {
00170       return countChildren()>0;
00171     }
00172 
00173     bool isCapable(const string & feature) const;
00174     void addCapability(const string & feature, const string & description = "");
00175     void describeCapability(const string & feature, const string & description);
00176     string getCapabilities() const;
00177     vector<string> getCapabilitiesList() const;
00178     string getCapabilityDescription(const string & feature) const;
00179 
00180     void attractHandle(const string & handle);
00181 
00182     void setConfig(const string & key, const string & value);
00183     void setConfig(const string & key, unsigned long long value);
00184     string getConfig(const string & key) const;
00185     vector<string> getConfigKeys() const;
00186     vector<string> getConfigValues(const string & separator = "") const;
00187 
00188     vector<string> getLogicalNames() const;
00189     string getLogicalName() const;
00190     void setLogicalName(const string &);
00191 
00192     string getDev() const;
00193     void setDev(const string &);
00194 
00195     string getBusInfo() const;
00196     void setBusInfo(const string &);
00197 
00198     string getPhysId() const;
00199     void setPhysId(long);
00200     void setPhysId(unsigned, unsigned);
00201     void setPhysId(unsigned, unsigned, unsigned);
00202     void setPhysId(const string &);
00203     void assignPhysIds();
00204 
00205     void addResource(const hw::resource &);
00206     bool usesResource(const hw::resource &) const;
00207     vector<string> getResources(const string & separator = "") const;
00208 
00209     void addHint(const string &, const hw::value &);
00210     hw::value getHint(const string &) const;
00211     vector<string> getHints() const;
00212 
00213     void merge(const hwNode & node);
00214 
00215     void fixInconsistencies();
00216 
00217     string asXML(unsigned level = 0);
00218     string asJSON(unsigned level = 0);
00219     string asString();
00220 
00221     bool dump(const string & filename, bool recurse = true);
00222   private:
00223 
00224     void setId(const string & id);
00225 
00226     bool attractsHandle(const string & handle) const;
00227     bool attractsNode(const hwNode & node) const;
00228 
00229     struct hwNode_i * This;
00230 };
00231 #endif