/ src / core / hw.h
hw.h
  1  #ifndef _HW_H_
  2  #define _HW_H_
  3  
  4  #include <string>
  5  #include <vector>
  6  
  7  using namespace std;
  8  
  9  namespace hw
 10  {
 11  
 12    typedef enum
 13    {
 14      system,
 15      bridge,
 16      memory,
 17      processor,
 18      address,
 19      storage,
 20      disk,
 21      tape,
 22      bus,
 23      network,
 24      display,
 25      input,
 26      printer,
 27      multimedia,
 28      communication,
 29      power,
 30      volume,
 31      generic,
 32      accelerator
 33    } hwClass;
 34  
 35    typedef enum { none, iomem, ioport, mem, irq, dma }
 36    hwResourceType;
 37    typedef enum { nil, boolean, integer, text }
 38    hwValueType;
 39  
 40    string strip(const string &);
 41    string asString(long);
 42  
 43    string reportSize(unsigned long long);
 44  
 45    class resource
 46    {
 47      public:
 48  
 49        resource();
 50        ~resource();
 51        resource(const resource &);
 52        resource & operator =(const resource &);
 53  
 54        static resource iomem(unsigned long long, unsigned long long);
 55        static resource ioport(unsigned long, unsigned long);
 56        static resource mem(unsigned long long, unsigned long long, bool prefetchable = false);
 57        static resource irq(unsigned int);
 58        static resource dma(unsigned int);
 59  
 60        bool operator ==(const resource &) const;
 61  
 62        string asString(const string & separator = ":") const;
 63  
 64      private:
 65        struct resource_i * This;
 66  
 67    };
 68  
 69    class value
 70    {
 71      public:
 72  
 73        value();
 74        ~value();
 75        value(const value &);
 76        value(long long);
 77        value(const string &);
 78        value & operator =(const value &);
 79  
 80        bool operator ==(const value &) const;
 81  
 82        string asString() const;
 83        long long asInteger() const;
 84        bool defined() const;
 85  
 86      private:
 87        struct value_i * This;
 88  
 89    };
 90  
 91  }                                                 // namespace hw
 92  
 93  
 94  class hwNode
 95  {
 96    public:
 97      hwNode(const string & id,
 98        hw::hwClass c = hw::generic,
 99        const string & vendor = "",
100        const string & product = "",
101        const string & version = "");
102      hwNode(const hwNode & o);
103      ~hwNode();
104      hwNode & operator =(const hwNode & o);
105  
106      string getId() const;
107  
108      void setHandle(const string & handle);
109      string getHandle() const;
110  
111      bool enabled() const;
112      bool disabled() const;
113      void enable();
114      void disable();
115      bool claimed() const;
116      void claim(bool claimchildren=false);
117      void unclaim();
118  
119      hw::hwClass getClass() const;
120      const char * getClassName() const;
121      void setClass(hw::hwClass c);
122  
123      string getDescription() const;
124      void setDescription(const string & description);
125  
126      string getVendor() const;
127      void setVendor(const string & vendor);
128  
129      string getSubVendor() const;
130      void setSubVendor(const string & subvendor);
131  
132      string getProduct() const;
133      void setProduct(const string & product);
134  
135      string getSubProduct() const;
136      void setSubProduct(const string & subproduct);
137  
138      string getVersion() const;
139      void setVersion(const string & version);
140  
141      string getDate() const;
142      void setDate(const string &);
143  
144      string getSerial() const;
145      void setSerial(const string & serial);
146  
147      unsigned long long getStart() const;
148      void setStart(unsigned long long start);
149  
150      unsigned long long getSize() const;
151      void setSize(unsigned long long size);
152  
153      unsigned long long getCapacity() const;
154      void setCapacity(unsigned long long capacity);
155  
156      unsigned long long getClock() const;
157      void setClock(unsigned long long clock);
158  
159      unsigned int getWidth() const;
160      void setWidth(unsigned int width);
161  
162      string getSlot() const;
163      void setSlot(const string & slot);
164  
165      string getModalias() const;
166      void setModalias(const string & modalias);
167  
168      unsigned int countChildren(hw::hwClass c = hw::generic) const;
169      hwNode * getChild(unsigned int);
170      hwNode * getChildByPhysId(long);
171      hwNode * getChildByPhysId(const string &);
172      hwNode * getChild(const string & id);
173      hwNode * findChildByHandle(const string & handle);
174      hwNode * findChildByLogicalName(const string & handle);
175      hwNode * findChildByBusInfo(const string & businfo);
176      hwNode * findChildByResource(const hw::resource &);
177      hwNode * findChild(bool(*matchfunction)(const hwNode &));
178      hwNode * addChild(const hwNode & node);
179      bool isBus() const
180      {
181        return countChildren()>0;
182      }
183  
184      bool isCapable(const string & feature) const;
185      void addCapability(const string & feature, const string & description = "");
186      void describeCapability(const string & feature, const string & description);
187      string getCapabilities() const;
188      vector<string> getCapabilitiesList() const;
189      string getCapabilityDescription(const string & feature) const;
190  
191      void attractHandle(const string & handle);
192  
193      void setConfig(const string & key, const string & value);
194      void setConfig(const string & key, unsigned long long value);
195      string getConfig(const string & key) const;
196      vector<string> getConfigKeys() const;
197      vector<string> getConfigValues(const string & separator = "") const;
198  
199      vector<string> getLogicalNames() const;
200      string getLogicalName() const;
201      void setLogicalName(const string &);
202  
203      string getDev() const;
204      void setDev(const string &);
205  
206      string getBusInfo() const;
207      void setBusInfo(const string &);
208  
209      string getPhysId() const;
210      void setPhysId(long);
211      void setPhysId(unsigned, unsigned);
212      void setPhysId(unsigned, unsigned, unsigned);
213      void setPhysId(const string &);
214      void assignPhysIds();
215  
216      void addResource(const hw::resource &);
217      bool usesResource(const hw::resource &) const;
218      vector<string> getResources(const string & separator = "") const;
219  
220      void addHint(const string &, const hw::value &);
221      hw::value getHint(const string &) const;
222      vector<string> getHints() const;
223  
224      void merge(const hwNode & node);
225  
226      void fixInconsistencies();
227  
228      string asXML(unsigned level = 0);
229      string asJSON(unsigned level = 0);
230      string asString();
231  
232      bool dump(const string & filename, bool recurse = true);
233    private:
234  
235      void setId(const string & id);
236  
237      bool attractsHandle(const string & handle) const;
238      bool attractsNode(const hwNode & node) const;
239  
240      struct hwNode_i * This;
241  };
242  #endif