Back to index

lshw  02.16
Public Member Functions | Private Member Functions | Private Attributes
hwNode Class Reference

#include <hw.h>

Collaboration diagram for hwNode:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 hwNode (const string &id, hw::hwClass c=hw::generic, const string &vendor="", const string &product="", const string &version="")
 hwNode (const hwNode &o)
 ~hwNode ()
hwNodeoperator= (const hwNode &o)
string getId () const
void setHandle (const string &handle)
string getHandle () const
bool enabled () const
bool disabled () const
void enable ()
void disable ()
bool claimed () const
void claim (bool claimchildren=false)
void unclaim ()
hw::hwClass getClass () const
const char * getClassName () const
void setClass (hw::hwClass c)
string getDescription () const
void setDescription (const string &description)
string getVendor () const
void setVendor (const string &vendor)
string getProduct () const
void setProduct (const string &product)
string getVersion () const
void setVersion (const string &version)
string getDate () const
void setDate (const string &)
string getSerial () const
void setSerial (const string &serial)
unsigned long long getStart () const
void setStart (unsigned long long start)
unsigned long long getSize () const
void setSize (unsigned long long size)
unsigned long long getCapacity () const
void setCapacity (unsigned long long capacity)
unsigned long long getClock () const
void setClock (unsigned long long clock)
unsigned int getWidth () const
void setWidth (unsigned int width)
string getSlot () const
void setSlot (const string &slot)
unsigned int countChildren (hw::hwClass c=hw::generic) const
hwNodegetChild (unsigned int)
hwNodegetChildByPhysId (long)
hwNodegetChildByPhysId (const string &)
hwNodegetChild (const string &id)
hwNodefindChildByHandle (const string &handle)
hwNodefindChildByLogicalName (const string &handle)
hwNodefindChildByBusInfo (const string &businfo)
hwNodefindChildByResource (const hw::resource &)
hwNodefindChild (bool(*matchfunction)(const hwNode &))
hwNodeaddChild (const hwNode &node)
bool isBus () const
bool isCapable (const string &feature) const
void addCapability (const string &feature, const string &description="")
void describeCapability (const string &feature, const string &description)
string getCapabilities () const
vector< string > getCapabilitiesList () const
string getCapabilityDescription (const string &feature) const
void attractHandle (const string &handle)
void setConfig (const string &key, const string &value)
void setConfig (const string &key, unsigned long long value)
string getConfig (const string &key) const
vector< string > getConfigKeys () const
vector< string > getConfigValues (const string &separator="") const
vector< string > getLogicalNames () const
string getLogicalName () const
void setLogicalName (const string &)
string getDev () const
void setDev (const string &)
string getBusInfo () const
void setBusInfo (const string &)
string getPhysId () const
void setPhysId (long)
void setPhysId (unsigned, unsigned)
void setPhysId (unsigned, unsigned, unsigned)
void setPhysId (const string &)
void assignPhysIds ()
void addResource (const hw::resource &)
bool usesResource (const hw::resource &) const
vector< string > getResources (const string &separator="") const
void addHint (const string &, const hw::value &)
hw::value getHint (const string &) const
vector< string > getHints () const
void merge (const hwNode &node)
void fixInconsistencies ()
string asXML (unsigned level=0)
string asJSON (unsigned level=0)
string asString ()
bool dump (const string &filename, bool recurse=true)

Private Member Functions

void setId (const string &id)
bool attractsHandle (const string &handle) const
bool attractsNode (const hwNode &node) const

Private Attributes

struct hwNode_iThis

Detailed Description

Definition at line 92 of file hw.h.


Constructor & Destructor Documentation

hwNode::hwNode ( const string &  id,
hw::hwClass  c = hw::generic,
const string &  vendor = "",
const string &  product = "",
const string &  version = "" 
)

Definition at line 97 of file hw.cc.

{
  This = NULL;
  This = new hwNode_i;

  if (!This)
    return;

  This->deviceclass = c;
  This->id = cleanupId(id);
  This->vendor = strip(vendor);
  This->product = strip(product);
  This->version = strip(version);
  This->start = 0;
  This->size = 0;
  This->capacity = 0;
  This->clock = 0;
  This->width = 0;
  This->enabled = true;
  This->claimed = false;
  This->handle = string("");
  This->description = string("");
  This->businfo = string("");
  This->physid = string("");
  This->dev = string("");
}

Here is the call graph for this function:

hwNode::hwNode ( const hwNode o)

Definition at line 128 of file hw.cc.

{
  This = NULL;
  This = new hwNode_i;

  if (!This)
    return;

  if (o.This)
    (*This) = (*o.This);
}

Definition at line 141 of file hw.cc.

{
  if (This)
    delete This;
}

Member Function Documentation

void hwNode::addCapability ( const string &  feature,
const string &  description = "" 
)

Definition at line 852 of file hw.cc.

{
  string features = feature;

  if (!This)
    return;

  if (description != "")
    This->features_descriptions[cleanupId(feature)] = strip(description);

  while (features.length() > 0)
  {
    size_t pos = features.find('\0');

    if (pos == string::npos)
    {
      if (!isCapable(cleanupId(features)))
        This->features.push_back(cleanupId(features));
      features = "";
    }
    else
    {
      string featureid = cleanupId(features.substr(0, pos));
      if (!isCapable(featureid))
        This->features.push_back(featureid);
      features = features.substr(pos + 1);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

hwNode * hwNode::addChild ( const hwNode node)

Definition at line 753 of file hw.cc.

{
  hwNode *existing = NULL;
  hwNode *samephysid = NULL;
  string id = node.getId();
  int count = 0;

  if (!This)
    return NULL;

// first see if the new node is attracted by one of our children
  for (unsigned int i = 0; i < This->children.size(); i++)
    if (This->children[i].attractsNode(node))
      return This->children[i].addChild(node);

// find if another child already has the same physical id
// in that case, we remove BOTH physical ids and let auto-allocation proceed
  if (node.getPhysId() != "")
    samephysid = getChildByPhysId(node.getPhysId());
  if (samephysid)
  {
    samephysid->setPhysId("");
  }

  existing = getChild(id);
  if (existing)                                   // first rename existing instance
  {
    while (getChild(generateId(id, count)))       // find a usable name
      count++;

    existing->setId(generateId(id, count));       // rename
  }

  while (getChild(generateId(id, count)))
    count++;

  This->children.push_back(node);
  if (existing || getChild(generateId(id, 0)))
    This->children.back().setId(generateId(id, count));

  if (samephysid)
    This->children.back().setPhysId("");

  return &(This->children.back());
//return getChild(This->children.back().getId());
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hwNode::addHint ( const string &  id,
const hw::value v 
)

Definition at line 1315 of file hw.cc.

{
  if(This)
    This->hints[id] = v;
}

Here is the caller graph for this function:

void hwNode::addResource ( const hw::resource r)

Definition at line 1262 of file hw.cc.

{
  if (!This)
    return;

  This->resources.push_back(r);
}

Here is the caller graph for this function:

string hwNode::asJSON ( unsigned  level = 0)

Definition at line 1344 of file hw.cc.

{
  vector < string > config;
  vector < string > resources;
  ostringstream out;

  if(!This) return "";

  config = getConfigKeys();
  resources = getResources("\" value=\"");

  if(visible(getClassName()))
  {
    out << "{" << endl;
    out << spaces(2*level+2) << "\"id\" : \"" << getId() << "\"," << endl;
    out << spaces(2*level+2) << "\"class\" : \"" << getClassName() << "\"";

    if (disabled())
      out << "," << endl << spaces(2*level+2) << "\"disabled\" : true";
    if (claimed())
      out << "," << endl << spaces(2*level+2) << "\"claimed\" : true";

    if(getHandle() != "")
      out << "," << endl << spaces(2*level+2) << "\"handle\" : \"" << getHandle() << "\"";

    if (getDescription() != "")
    {
      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"description\" : \"";
      out << escapeJSON(getDescription());
      out << "\"";
    }

    if (getProduct() != "")
    {
      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"product\" : \"";
      out << escapeJSON(getProduct());
      out << "\"";
    }

    if (getVendor() != "")
    {
      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"vendor\" : \"";
      out << escapeJSON(getVendor());
      out << "\"";
    }

    if (getPhysId() != "")
    {
      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"physid\" : \"";
      out << getPhysId();
      out << "\"";
    }

    if (getBusInfo() != "")
    {
      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"businfo\" : \"";
      out << escapeJSON(getBusInfo());
      out << "\"";
    }

    if (getLogicalName() != "")
    {
      vector<string> logicalnames = getLogicalNames();

      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"logicalname\" : ";
      if(logicalnames.size() > 1)
      {
        out << "[";
        for(unsigned int i = 0; i<logicalnames.size(); i++)
        {
          if(i) out << ", ";
          out << "\"" << logicalnames[i] << "\"";
        }
        out << "]";
      }
      else
        out << "\"" << escapeJSON(getLogicalName()) << "\"";
    }

    if (getDev() != "")
    {
      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"dev\" : \"";
      out << escapeJSON(getDev());
      out << "\"";
    }

    if (getVersion() != "")
    {
      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"version\" : \"";
      out << escapeJSON(getVersion());
      out << "\"";
    }

    if (getDate() != "")
    {
      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"date\" : \"";
      out << escapeJSON(getDate());
      out << "\"";
    }

    if (getSerial() != "")
    {
      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"serial\" : \"";
      out << (::enabled("output:sanitize")?REMOVED:escapeJSON(getSerial()));
      out << "\"";
    }

    if (getSlot() != "")
    {
      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"slot\" : \"";
      out << escapeJSON(getSlot());
      out << "\"";
    }

    if ((getSize() > 0) || (getCapacity() > 0))
      switch (getClass())
      {
        case hw::memory:
        case hw::address:
        case hw::storage:
        case hw::disk:
        case hw::display:
          out << "," << endl << spaces(2*level+2) << "\"units\" : \"bytes\"";
          break;

        case hw::processor:
        case hw::bus:
        case hw::system:
          out << "," << endl << spaces(2*level+2) << "\"units\" : \"Hz\"";
          break;

        case hw::power:
          out << "," << endl << spaces(2*level+2) << "\"units\" : \"mWh\"";
          break;

        case hw::network:
          out << "," << endl << spaces(2*level+2) << "\"units\" : \"bit/s\"";
          break;

        default:
          break;
      }

    if (getSize() > 0)
    {
      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"size\" : ";
      out << getSize();
    }

    if (getCapacity() > 0)
    {
      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"capacity\" : ";
      out << getCapacity();
    }

    if (getWidth() > 0)
    {
      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"width\" : ";
      out << getWidth();
    }

    if (getClock() > 0)
    {
      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"clock\" : ";
      out << getClock();
    }

    if (config.size() > 0)
    {
      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"configuration\" : {" << endl;
      for (unsigned int j = 0; j < config.size(); j++)
      {
        if(j) out << "," << endl;
        out << spaces(2*level+4);
        out << "\"" << escapeJSON(config[j]) << "\" : \"" << escapeJSON(getConfig(config[j])) << "\"";
      }
      out << endl << spaces(2*level+2);
      out << "}";
    }
    config.clear();

    splitlines(getCapabilities(), config, ' ');
    if (config.size() > 0)
    {
      out << "," << endl;
      out << spaces(2*level+2);
      out << "\"capabilities\" : {" << endl;
      for (unsigned int j = 0; j < config.size(); j++)
      {
        if(j) out << "," << endl;
        out << spaces(2*level+4);
        out << "\"" << escapeJSON(config[j]) << "\" : ";
        if (getCapabilityDescription(config[j]) == "")
        {
          out << "true";
        }
        else
        {
          out << "\"";
          out << escapeJSON(getCapabilityDescription(config[j]));
          out << "\"";
        }
      }
      out << endl << spaces(2*level+2);
      out << "}";
    }
    config.clear();

    if (0 && resources.size() > 0)
    {
      out << spaces(2*level+1);
      out << "<resources>" << endl;
      for (unsigned int j = 0; j < resources.size(); j++)
      {
        out << spaces(2*level+2);
        out << "<resource type=\"" << escapeJSON(resources[j]) << "\" />";
        out << endl;
      }
      out << spaces(2*level+1);
      out << "</resources>" << endl;
    }
    resources.clear();
  }

  
  if(countChildren()>0)
  {
    if(visible(getClassName()))
      out << "," << endl << spaces(2*level+2) << "\"children\" : [" << endl;

    for (unsigned int i = 0; i < countChildren(); i++)
    {
      out << spaces(2*level+4) << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
      if(visible(getChild(i)->getClassName()) && (i < countChildren()-1)) out << "," << endl;
    }

    if(visible(getClassName()))
      out << endl << spaces(2*level+2) << "]";
  }

  if(visible(getClassName()))
  {
    out << endl << spaces(2*level);
    out << "}";
  }

  return out.str();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1158 of file hw.cc.

{
  if (!This)
    return;

  for (unsigned int i = 0; i < This->children.size(); i++)
  {
    long curid = 0;

    if (This->children[i].getClass() == hw::bridge)
      curid = 0x100;

    if (This->children[i].getPhysId() == "")
    {
      while (getChildByPhysId(curid))
        curid++;

      This->children[i].setPhysId(curid);
    }

    This->children[i].assignPhysIds();
  }
}

Here is the caller graph for this function:

string hwNode::asString ( )

Definition at line 1943 of file hw.cc.

{
  string summary = "";
  if(!This)
    return "";

  if(getClass() != hw::memory)
    summary = getProduct();        // memory devices tend to have obscure product names
  if (summary == "")
    summary = getDescription();

  if((getClass() == hw::memory) || (getClass() == hw::disk) || (getClass() == hw::storage) || (getClass() == hw::volume))
  {
    unsigned long long size = 0;
    if(getClass() != hw::memory)
    {
      if(getCapacity())
        size = getCapacity();
      else
      {
        if(getSize())
          size = getSize();
      }
    }
    else
    {
      if(getSize())
        size = getSize();
    }
    if(size)
      summary = (getClass()==hw::disk?(decimalkilos(size)+"B"):kilobytes(size)) +" "+ summary;
  }

  return summary;
}

Here is the call graph for this function:

Here is the caller graph for this function:

string hwNode::asXML ( unsigned  level = 0)

Definition at line 1625 of file hw.cc.

{
  vector < string > config;
  vector < string > resources;
  ostringstream out;

  if(!This) return "";

  config = getConfigKeys();
  resources = getResources("\" value=\"");

  if (level == 0)
  {
    struct utsname un;

    out << "<?xml version=\"1.0\" standalone=\"yes\" ?>" << endl;
    out << _("<!-- generated by lshw-") << getpackageversion() << " -->" <<
  #if defined(__GNUC__) && defined(__VERSION__)
      endl << "<!-- GCC " << escapecomment(__VERSION__) << " -->" <<
  #endif
      endl;

    if(uname(&un) == 0)
      out << "<!-- " << escapecomment(un.sysname) << " " << escapecomment(un.release) << " " << escapecomment(un.version) << " " << escapecomment(un.machine) << " -->" << endl;
  #if defined(__GLIBC__) && defined(_CS_GNU_LIBC_VERSION)
    char version[PATH_MAX];

      if(confstr(_CS_GNU_LIBC_VERSION, version, sizeof(version))>0)
        out << "<!-- GNU libc " << __GLIBC__ << " (" << escapecomment(version) << ") -->" << endl;
  #endif
    if (geteuid() != 0)
      out << _("<!-- WARNING: not running as root -->") << endl;

    if(::enabled("output:list"))
      out << "<list>" << endl;

  }

  if(visible(getClassName()))
  {
    out << spaces(2*level);
    out << "<node id=\"" << getId() << "\"";
    if (disabled())
      out << " disabled=\"true\"";
    if (claimed())
      out << " claimed=\"true\"";

    out << " class=\"" << getClassName() << "\"";
    out << " handle=\"" << getHandle() << "\"";
    out << ">" << endl;

    if (getDescription() != "")
    {
      out << spaces(2*level+1);
      out << "<description>";
      out << escape(getDescription());
      out << "</description>";
      out << endl;
    }

    if (getProduct() != "")
    {
      out << spaces(2*level+1);
      out << "<product>";
      out << escape(getProduct());
      out << "</product>";
      out << endl;
    }

    if (getVendor() != "")
    {
      out << spaces(2*level+1);
      out << "<vendor>";
      out << escape(getVendor());
      out << "</vendor>";
      out << endl;
    }

    if (getPhysId() != "")
    {
      out << spaces(2*level+1);
      out << "<physid>";
      out << getPhysId();
      out << "</physid>";
      out << endl;
    }

    if (getBusInfo() != "")
    {
      out << spaces(2*level+1);
      out << "<businfo>";
      out << escape(getBusInfo());
      out << "</businfo>";
      out << endl;
    }

    if (getLogicalName() != "")
    {
      vector<string> logicalnames = getLogicalNames();

      for(unsigned int i = 0; i<logicalnames.size(); i++)
      {
        out << spaces(2*level+1);
        out << "<logicalname>";
        out << logicalnames[i];
        out << "</logicalname>";
        out << endl;
      }
    }

    if (getDev() != "")
    {
      out << spaces(2*level+1);
      out << "<dev>";
      out << escape(getDev());
      out << "</dev>";
      out << endl;
    }

    if (getVersion() != "")
    {
      out << spaces(2*level+1);
      out << "<version>";
      out << escape(getVersion());
      out << "</version>";
      out << endl;
    }

    if (getDate() != "")
    {
      out << spaces(2*level+1);
      out << "<date>";
      out << escape(getDate());
      out << "</date>";
      out << endl;
    }

    if (getSerial() != "")
    {
      out << spaces(2*level+1);
      out << "<serial>";
      out << (::enabled("output:sanitize")?REMOVED:escape(getSerial()));
      out << "</serial>";
      out << endl;
    }

    if (getSlot() != "")
    {
      out << spaces(2*level+1);
      out << "<slot>";
      out << escape(getSlot());
      out << "</slot>";
      out << endl;
    }

    if (getSize() > 0)
    {
      out << spaces(2*level+1);
      out << "<size";
      switch (getClass())
      {
        case hw::memory:
        case hw::address:
        case hw::storage:
        case hw::disk:
        case hw::volume:
        case hw::display:
          out << " units=\"bytes\"";
          break;

        case hw::processor:
        case hw::bus:
        case hw::system:
          out << " units=\"Hz\"";
          break;

        case hw::network:
          out << " units=\"bit/s\"";
          break;

        case hw::power:
          out << " units=\"mWh\"";
          break;

        default:
          out << "";
      }
      out << ">";
      out << getSize();
      out << "</size>";
      out << endl;
    }

    if (getCapacity() > 0)
    {
      out << spaces(2*level+1);
      out << "<capacity";
      switch (getClass())
      {
        case hw::memory:
        case hw::address:
        case hw::storage:
        case hw::disk:
          out << " units=\"bytes\"";
          break;

        case hw::processor:
        case hw::bus:
        case hw::system:
          out << " units=\"Hz\"";
          break;

        case hw::power:
          out << " units=\"mWh\"";
          break;

        default:
          out << "";
      }
      out << ">";
      out << getCapacity();
      out << "</capacity>";
      out << endl;
    }

    if (getWidth() > 0)
    {
      out << spaces(2*level+1);
      out << "<width units=\"bits\">";
      out << getWidth();
      out << "</width>";
      out << endl;
    }

    if (getClock() > 0)
    {
      out << spaces(2*level+1);
      out << "<clock units=\"Hz\">";
      out << getClock();
      out << "</clock>";
      out << endl;
    }

    if (config.size() > 0)
    {
      out << spaces(2*level+1);
      out << "<configuration>" << endl;
      for (unsigned int j = 0; j < config.size(); j++)
      {
        out << spaces(2*level+2);
        out << "<setting id=\"" << escape(config[j]) << "\" value=\"" << escape(getConfig(config[j])) << "\" />";
        out << endl;
      }
      out << spaces(2*level+1);
      out << "</configuration>" << endl;
    }
    config.clear();

    splitlines(getCapabilities(), config, ' ');
    if (config.size() > 0)
    {
      out << spaces(2*level+1);
      out << "<capabilities>" << endl;
      for (unsigned int j = 0; j < config.size(); j++)
      {
        out << spaces(2*level+2);
        out << "<capability id=\"" << escape(config[j]);
        if (getCapabilityDescription(config[j]) == "")
        {
          out << "\" />";
        }
        else
        {
          out << "\" >";
          out << escape(getCapabilityDescription(config[j]));
          out << "</capability>";
        }
        out << endl;
      }
      out << spaces(2*level+1);
      out << "</capabilities>" << endl;
    }
    config.clear();

    if (resources.size() > 0)
    {
      out << spaces(2*level+1);
      out << "<resources>" << endl;
      for (unsigned int j = 0; j < resources.size(); j++)
      {
        out << spaces(2*level+2);
        out << "<resource type=\"" << resources[j] << "\" />";
        out << endl;
      }
      out << spaces(2*level+1);
      out << "</resources>" << endl;
    }
    resources.clear();
  }

  for (unsigned int i = 0; i < countChildren(); i++)
  {
    out << getChild(i)->asXML(visible(getClassName()) ? level + 1 : 1);
  }

  if(visible(getClassName()))
  {
    out << spaces(2*level);
    out << "</node>" << endl;
  }

  if((level==0) && ::enabled("output:list"))
    out << "</list>" << endl;


  return out.str();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hwNode::attractHandle ( const string &  handle)

Definition at line 801 of file hw.cc.

{
  if (!This)
    return;

  This->attracted.push_back(handle);
}

Here is the caller graph for this function:

bool hwNode::attractsHandle ( const string &  handle) const [private]

Definition at line 810 of file hw.cc.

{
  unsigned int i = 0;
  if (handle == "" || !This)
    return false;

  for (i = 0; i < This->attracted.size(); i++)
    if (This->attracted[i] == handle)
      return true;

  for (i = 0; i < This->children.size(); i++)
    if (This->children[i].attractsHandle(handle))
      return true;

  return false;
}
bool hwNode::attractsNode ( const hwNode node) const [private]

Definition at line 828 of file hw.cc.

{
  if (!This || !node.This)
    return false;

  return attractsHandle(node.This->handle);
}
void hwNode::claim ( bool  claimchildren = false)

Definition at line 307 of file hw.cc.

{
  if (!This)
    return;

  This->claimed = true;

  if (!claimchildren)
    return;

  for (unsigned int i = 0; i < This->children.size(); i++)
    This->children[i].claim(claimchildren);
}

Here is the caller graph for this function:

bool hwNode::claimed ( ) const

Definition at line 288 of file hw.cc.

{
  if (!This)
    return false;

  if (This->claimed)
    return true;

  for (unsigned int i = 0; i < This->children.size(); i++)
    if (This->children[i].claimed())
  {
    This->claimed = true;
    return true;
  }

  return false;
}

Here is the caller graph for this function:

unsigned int hwNode::countChildren ( hw::hwClass  c = hw::generic) const

Definition at line 545 of file hw.cc.

{
  unsigned int count = 0;

  if (!This)
    return 0;

  if (c == hw::generic)
    return This->children.size();

  for (unsigned int i = 0; i < This->children.size(); i++)
    if (This->children[i].getClass() == c)
      count++;

  return count;
}

Here is the caller graph for this function:

void hwNode::describeCapability ( const string &  feature,
const string &  description 
)

Definition at line 884 of file hw.cc.

{
  if (!This)
    return;

  if (!isCapable(feature))
    return;

  This->features_descriptions[cleanupId(feature)] = strip(description);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hwNode::disable ( )

Definition at line 279 of file hw.cc.

{
  if (!This)
    return;

  This->enabled = false;
}

Here is the caller graph for this function:

bool hwNode::disabled ( ) const

Definition at line 261 of file hw.cc.

{
  if (!This)
    return true;

  return !(This->enabled);
}

Here is the caller graph for this function:

bool hwNode::dump ( const string &  filename,
bool  recurse = true 
)

Definition at line 2359 of file hw.cc.

{
#ifdef SQLITE
  try {
    sqlite::database db(filename);

    db.execute("BEGIN TRANSACTION");
    ::dump(*this, db, "", recurse);
    db.execute("COMMIT");
  }
  catch(exception & e)
  {
    return false;
  }
#else
  return false;
#endif

  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hwNode::enable ( )

Definition at line 270 of file hw.cc.

{
  if (!This)
    return;

  This->enabled = true;
}

Here is the caller graph for this function:

bool hwNode::enabled ( ) const

Definition at line 252 of file hw.cc.

{
  if (!This)
    return false;

  return (This->enabled);
}

Here is the caller graph for this function:

hwNode * hwNode::findChild ( bool(*)(const hwNode &)  matchfunction)

Definition at line 636 of file hw.cc.

{
  if (!This)
    return NULL;

  if (matchfunction(*this))
    return this;

  for (unsigned int i = 0; i < This->children.size(); i++)
  {
    hwNode *result = This->children[i].findChild(matchfunction);

    if (result)
      return result;
  }

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

hwNode * hwNode::findChildByBusInfo ( const string &  businfo)

Definition at line 699 of file hw.cc.

{
  if (!This)
    return NULL;

  if (strip(businfo) == "")
    return NULL;

  if (lowercase(strip(This->businfo)) == lowercase(strip(businfo)))
    return this;

  for (unsigned int i = 0; i < This->children.size(); i++)
  {
    hwNode *result = This->children[i].findChildByBusInfo(businfo);

    if (result)
      return result;
  }

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

hwNode * hwNode::findChildByHandle ( const string &  handle)

Definition at line 656 of file hw.cc.

{
  if (!This)
    return NULL;

  if (This->handle == handle)
    return this;

  for (unsigned int i = 0; i < This->children.size(); i++)
  {
    hwNode *result = This->children[i].findChildByHandle(handle);

    if (result)
      return result;
  }

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

hwNode * hwNode::findChildByLogicalName ( const string &  handle)

Definition at line 676 of file hw.cc.

{
  unsigned int i = 0;

  if (!This)
    return NULL;

  for (i = 0; i < This->logicalnames.size(); i++)
    if (This->logicalnames[i] == name)
      return this;

  for (i = 0; i < This->children.size(); i++)
  {
    hwNode *result = This->children[i].findChildByLogicalName(name);

    if (result)
      return result;
  }

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 722 of file hw.cc.

{
  if (!This)
    return NULL;

  if (this->usesResource(r))
    return this;

  for (unsigned int i = 0; i < This->children.size(); i++)
  {
    hwNode *result = This->children[i].findChildByResource(r);

    if (result)
      return result;
  }

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1183 of file hw.cc.

{
  if (!This)
    return;

  if (getCapacity() < getSize())
    setCapacity(0);

  guessProduct(*this);
  guessVendor(*this);

  if(getLogicalName() != "")
    claim();

  for (unsigned int i = 0; i < This->children.size(); i++)
    This->children[i].fixInconsistencies();
}

Here is the call graph for this function:

Here is the caller graph for this function:

string hwNode::getBusInfo ( ) const

Definition at line 1074 of file hw.cc.

{
  if (This)
    return This->businfo;
  else
    return "";
}

Here is the caller graph for this function:

string hwNode::getCapabilities ( ) const

Definition at line 897 of file hw.cc.

{
  string result = "";

  if (!This)
    return "";

  for (unsigned int i = 0; i < This->features.size(); i++)
    result += This->features[i] + " ";

  return strip(result);
}

Here is the call graph for this function:

Here is the caller graph for this function:

vector< string > hwNode::getCapabilitiesList ( ) const

Definition at line 911 of file hw.cc.

{
  vector < string > result;

  if (!This)
    return result;

  for (unsigned int i = 0; i < This->features.size(); i++)
    result.push_back(This->features[i]);

  return result;
}

Here is the caller graph for this function:

string hwNode::getCapabilityDescription ( const string &  feature) const

Definition at line 925 of file hw.cc.

{
  string featureid = cleanupId(feature);

  if (!isCapable(feature))
    return "";

  if (!This)
    return "";

  if (This->features_descriptions.find(featureid) ==
    This->features_descriptions.end())
    return "";

  return This->features_descriptions[featureid];
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned long long hwNode::getCapacity ( ) const

Definition at line 513 of file hw.cc.

{
  if (This)
    return This->capacity;
  else
    return 0;
}

Here is the caller graph for this function:

hwNode * hwNode::getChild ( unsigned int  i)

Definition at line 563 of file hw.cc.

{
  if (!This)
    return NULL;

  if (i >= This->children.size())
    return NULL;
  else
    return &(This->children[i]);
}

Here is the caller graph for this function:

hwNode * hwNode::getChild ( const string &  id)

Definition at line 608 of file hw.cc.

{
  string baseid = id, path = "";
  size_t pos = 0;

  if (!This)
    return NULL;

  pos = id.find('/');
  if (pos != string::npos)
  {
    baseid = id.substr(0, pos);
    if (pos < id.length() - 1)
      path = id.substr(pos + 1);
  }

  for (unsigned int i = 0; i < This->children.size(); i++)
    if (This->children[i].getId() == baseid)
  {
    if (path == "")
      return &(This->children[i]);
    else
      return This->children[i].getChild(path);
  }
  return NULL;
}
hwNode * hwNode::getChildByPhysId ( long  physid)

Definition at line 590 of file hw.cc.

{
  char buffer[20];
  if (!This)
    return NULL;

  snprintf(buffer, sizeof(buffer), "%lx", physid);

  for (unsigned int i = 0; i < This->children.size(); i++)
  {
    if (This->children[i].getPhysId() == string(buffer))
      return &(This->children[i]);
  }

  return NULL;
}
hwNode * hwNode::getChildByPhysId ( const string &  physid)

Definition at line 575 of file hw.cc.

{
  if (physid == "" || !This)
    return NULL;

  for (unsigned int i = 0; i < This->children.size(); i++)
  {
    if (This->children[i].getPhysId() == physid)
      return &(This->children[i]);
  }

  return NULL;
}

Definition at line 168 of file hw.cc.

{
  if (This)
    return This->deviceclass;
  else
    return hw::generic;
}

Here is the caller graph for this function:

const char * hwNode::getClassName ( ) const

Definition at line 177 of file hw.cc.

{
  if (This)
  {
    switch (This->deviceclass)
    {
      case processor:
        return "processor";

      case memory:
        return "memory";

      case address:
        return "address";

      case storage:
        return "storage";

      case disk:
        return "disk";

      case tape:
        return "tape";

      case hw::system:
        return "system";

      case bridge:
        return "bridge";

      case bus:
        return "bus";

      case network:
        return "network";

      case display:
        return "display";

      case input:
        return "input";

      case printer:
        return "printer";

      case multimedia:
        return "multimedia";

      case communication:
        return "communication";

      case power:
        return "power";

      case volume:
        return "volume";

      default:
        return "generic";
    }
  }
  else
    return "generic";
}

Here is the caller graph for this function:

unsigned long long hwNode::getClock ( ) const

Definition at line 529 of file hw.cc.

{
  if (This)
    return This->clock;
  else
    return 0;
}

Here is the caller graph for this function:

string hwNode::getConfig ( const string &  key) const

Definition at line 965 of file hw.cc.

{
  if (!This)
    return "";

  if (This->config.find(key) == This->config.end())
    return "";

  return This->config[key];
}

Here is the caller graph for this function:

vector< string > hwNode::getConfigKeys ( ) const

Definition at line 977 of file hw.cc.

{
  vector < string > result;

  if (!This)
    return result;

  for (map < string, string >::iterator i = This->config.begin();
    i != This->config.end(); i++)
  result.push_back(i->first);

  return result;
}
vector< string > hwNode::getConfigValues ( const string &  separator = "") const

Definition at line 991 of file hw.cc.

{
  vector < string > result;

  if (!This)
    return result;

  for (map < string, string >::iterator i = This->config.begin();
    i != This->config.end(); i++)
  result.push_back(i->first + separator + i->second);

  return result;
}

Here is the caller graph for this function:

string hwNode::getDate ( ) const

Definition at line 430 of file hw.cc.

{
  if (This)
    return This->date;
  else
    return "";
}

Here is the caller graph for this function:

string hwNode::getDescription ( ) const

Definition at line 367 of file hw.cc.

{
  if (This)
    return This->description;
  else
    return "";
}

Here is the caller graph for this function:

string hwNode::getDev ( ) const

Definition at line 1046 of file hw.cc.

{
  if (This)
    return This->dev;
  else
    return "";
}

Here is the caller graph for this function:

string hwNode::getHandle ( ) const

Definition at line 358 of file hw.cc.

{
  if (This)
    return This->handle;
  else
    return "";
}

Here is the caller graph for this function:

value hwNode::getHint ( const string &  id) const

Definition at line 1322 of file hw.cc.

{
  if(!This)
    return value();

  return This->hints[id];
}

Here is the caller graph for this function:

vector< string > hwNode::getHints ( ) const

Definition at line 1330 of file hw.cc.

{
  vector < string > result;

  if (!This)
    return result;

  for (map < string, value >::iterator i = This->hints.begin();
    i != This->hints.end(); i++)
  result.push_back(i->first);

  return result;
}
string hwNode::getId ( ) const

Definition at line 331 of file hw.cc.

{
  if (This)
    return This->id;
  else
    return "";
}

Here is the caller graph for this function:

string hwNode::getLogicalName ( ) const

Definition at line 1006 of file hw.cc.

{
  if (This && (This->logicalnames.size()>0))
    return This->logicalnames[0];
  else
    return "";
}

Here is the caller graph for this function:

vector< string > hwNode::getLogicalNames ( ) const

Definition at line 1015 of file hw.cc.

{
  if (This)
    return This->logicalnames;
  else
    return vector<string>();
}

Here is the caller graph for this function:

string hwNode::getPhysId ( ) const

Definition at line 1095 of file hw.cc.

{
  if (This)
    return This->physid;
  else
    return "";
}

Here is the caller graph for this function:

string hwNode::getProduct ( ) const

Definition at line 399 of file hw.cc.

{
  if (This)
    return This->product;
  else
    return "";
}

Here is the caller graph for this function:

vector< string > hwNode::getResources ( const string &  separator = "") const

Definition at line 1284 of file hw.cc.

{
  vector < string > result;

  if (!This)
    return result;

  for (vector < resource >::iterator i = This->resources.begin();
    i != This->resources.end(); i++)
  result.push_back(i->asString(separator));

  return result;
}

Here is the caller graph for this function:

string hwNode::getSerial ( ) const

Definition at line 446 of file hw.cc.

{
  if (This)
    return This->serial;
  else
    return "";
}

Here is the caller graph for this function:

unsigned long long hwNode::getSize ( ) const

Definition at line 497 of file hw.cc.

{
  if (This)
    return This->size;
  else
    return 0;
}

Here is the caller graph for this function:

string hwNode::getSlot ( ) const

Definition at line 465 of file hw.cc.

{
  if (This)
    return This->slot;
  else
    return "";
}

Here is the caller graph for this function:

unsigned long long hwNode::getStart ( ) const

Definition at line 481 of file hw.cc.

{
  if (This)
    return This->start;
  else
    return 0;
}

Here is the caller graph for this function:

string hwNode::getVendor ( ) const

Definition at line 383 of file hw.cc.

{
  if (This)
    return This->vendor;
  else
    return "";
}

Here is the caller graph for this function:

string hwNode::getVersion ( ) const

Definition at line 415 of file hw.cc.

{
  if (This)
    return This->version;
  else
    return "";
}

Here is the caller graph for this function:

unsigned int hwNode::getWidth ( ) const

Definition at line 1306 of file hw.cc.

{
  if(This)
    return This->width;
  else
    return 0;
}

Here is the caller graph for this function:

bool hwNode::isBus ( ) const [inline]

Definition at line 168 of file hw.h.

    {
      return countChildren()>0;
    }
bool hwNode::isCapable ( const string &  feature) const

Definition at line 837 of file hw.cc.

{
  string featureid = cleanupId(feature);

  if (!This)
    return false;

  for (unsigned int i = 0; i < This->features.size(); i++)
    if (This->features[i] == featureid)
      return true;

  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hwNode::merge ( const hwNode node)

Definition at line 1202 of file hw.cc.

{
  if (!This)
    return;
  if (!node.This)
    return;

  if (This->deviceclass == hw::generic)
    This->deviceclass = node.getClass();
  if (This->vendor == "")
    This->vendor = node.getVendor();
  if (This->product == "")
    This->product = node.getProduct();
  if (This->version == "")
    This->version = node.getVersion();
  if (This->serial == "")
    This->serial = node.getSerial();
  if (This->start == 0)
    This->start = node.getStart();
  if (This->size == 0)
    This->size = node.getSize();
  if (This->capacity == 0)
    This->capacity = node.getCapacity();
  if (This->clock == 0)
    This->clock = node.getClock();
  if (This->width == 0)
    This->width = node.getWidth();
  if (node.enabled())
    enable();
  else
    disable();
  if (node.claimed())
    claim();
  if (This->handle == "")
    This->handle = node.getHandle();
  if (This->description == "")
    This->description = node.getDescription();
  if (This->logicalnames.size() == 0)
    This->logicalnames = node.getLogicalNames();
  if (This->businfo == "")
    This->businfo = node.getBusInfo();
  if (This->physid == "")
    This->physid = node.getPhysId();

  for (unsigned int i = 0; i < node.This->features.size(); i++)
    addCapability(node.This->features[i]);
  for (map < string, string >::iterator i = node.This->features_descriptions.begin();
    i != node.This->features_descriptions.end(); i++)
  describeCapability(i->first, i->second);

  for (map < string, string >::iterator i = node.This->config.begin();
    i != node.This->config.end(); i++)
  setConfig(i->first, i->second);

  for (map < string, value >::iterator i = node.This->hints.begin();
    i != node.This->hints.end(); i++)
  addHint(i->first, i->second);
}

Here is the call graph for this function:

Here is the caller graph for this function:

hwNode & hwNode::operator= ( const hwNode o)

Definition at line 148 of file hw.cc.

{
  if (this == &o)
    return *this;                                 // self-affectation

  if (This)
    delete This;
  This = NULL;
  This = new hwNode_i;

  if (!This)
    return *this;

  if (o.This)
    (*This) = (*o.This);

  return *this;
}
void hwNode::setBusInfo ( const string &  businfo)

Definition at line 1083 of file hw.cc.

{
  if (This)
  {
    if (businfo.find('@') != string::npos)
      This->businfo = strip(businfo);
    else
      This->businfo = guessBusInfo(strip(businfo));
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hwNode::setCapacity ( unsigned long long  capacity)

Definition at line 522 of file hw.cc.

{
  if (This)
    This->capacity = capacity;
}

Here is the caller graph for this function:

Definition at line 243 of file hw.cc.

{
  if (!This)
    return;

  This->deviceclass = c;
}

Here is the caller graph for this function:

void hwNode::setClock ( unsigned long long  clock)

Definition at line 538 of file hw.cc.

{
  if (This)
    This->clock = clock;
}

Here is the caller graph for this function:

void hwNode::setConfig ( const string &  key,
const string &  value 
)

Definition at line 943 of file hw.cc.

{
  if (!This)
    return;

  This->config[key] = strip(value);
  if (strip(value) == "")
    This->config.erase(This->config.find(key));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hwNode::setConfig ( const string &  key,
unsigned long long  value 
)

Definition at line 955 of file hw.cc.

{
  if (!This)
    return;

  This->config[key] = tostring(value);
}

Here is the call graph for this function:

void hwNode::setDate ( const string &  s)

Definition at line 439 of file hw.cc.

{
  if (This)
    This->date = strip(s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hwNode::setDescription ( const string &  description)

Definition at line 376 of file hw.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

void hwNode::setDev ( const string &  s)

Definition at line 1055 of file hw.cc.

{
  if (This)
  {
    string devid = strip(s);
    unsigned int i = 0;

    while((i<devid.length()) && isdigit(devid[i])) i++;
    if(i>=devid.length()) return;
    if(devid[i] != ':') return;
    i++;
    while((i<devid.length()) && isdigit(devid[i])) i++;
    if(i!=devid.length()) return;

    This->dev = devid;
  }
}

Here is the call graph for this function:

void hwNode::setHandle ( const string &  handle)

Definition at line 349 of file hw.cc.

{
  if (!This)
    return;

  This->handle = handle;
}

Here is the caller graph for this function:

void hwNode::setId ( const string &  id) [private]

Definition at line 340 of file hw.cc.

{
  if (!This)
    return;

  This->id = cleanupId(id);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hwNode::setLogicalName ( const string &  name)

Definition at line 1024 of file hw.cc.

{
  string n = strip(name);

  if (This)
  {
    for (unsigned i = 0; i < This->logicalnames.size(); i++)
      if (This->logicalnames[i] == n || This->logicalnames[i] == "/dev/" + n)
        return;                                   // nothing to add, this logical name already exists
    if ((name[0] != '/') && exists("/dev/" + n))
    {
      This->logicalnames.push_back("/dev/" + n);
    }
    else
      This->logicalnames.push_back(n);

    if(This->dev == "")
      This->dev = get_devid(n);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hwNode::setPhysId ( long  physid)

Definition at line 1104 of file hw.cc.

{
  if (This)
  {
    char buffer[20];

    snprintf(buffer, sizeof(buffer), "%lx", physid);
    This->physid = string(buffer);
  }
}

Here is the caller graph for this function:

void hwNode::setPhysId ( unsigned  physid1,
unsigned  physid2 
)

Definition at line 1116 of file hw.cc.

{
  if (This)
  {
    char buffer[40];

    if (physid2 != 0)
      snprintf(buffer, sizeof(buffer), "%x.%x", physid1, physid2);
    else
      snprintf(buffer, sizeof(buffer), "%x", physid1);
    This->physid = string(buffer);
  }
}
void hwNode::setPhysId ( unsigned  physid1,
unsigned  physid2,
unsigned  physid3 
)

Definition at line 1132 of file hw.cc.

{
  if (This)
  {
    char buffer[40];

    snprintf(buffer, sizeof(buffer), "%x.%x.%x", physid1, physid2, physid3);
    This->physid = string(buffer);
  }
}
void hwNode::setPhysId ( const string &  physid)

Definition at line 1146 of file hw.cc.

{
  if (This)
  {
    This->physid = strip(physid);

    while ((This->physid.length() > 1) && (This->physid[0] == '0'))
      This->physid.erase(0, 1);
  }
}

Here is the call graph for this function:

void hwNode::setProduct ( const string &  product)

Definition at line 408 of file hw.cc.

{
  if (This)
    This->product = strip(product);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hwNode::setSerial ( const string &  serial)

Definition at line 455 of file hw.cc.

{
  if(serial == "00000000-0000-0000-0000-000000000000")
    return;

  if (This)
    This->serial = strip(serial);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hwNode::setSize ( unsigned long long  size)

Definition at line 506 of file hw.cc.

{
  if (This)
    This->size = size;
}

Here is the caller graph for this function:

void hwNode::setSlot ( const string &  slot)

Definition at line 474 of file hw.cc.

{
  if (This)
    This->slot = strip(slot);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hwNode::setStart ( unsigned long long  start)

Definition at line 490 of file hw.cc.

{
  if (This)
    This->start = start;
}

Here is the caller graph for this function:

void hwNode::setVendor ( const string &  vendor)

Definition at line 392 of file hw.cc.

{
  if (This)
    This->vendor = strip(vendor);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hwNode::setVersion ( const string &  version)

Definition at line 424 of file hw.cc.

{
  if (This)
    This->version = strip(version);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hwNode::setWidth ( unsigned int  width)

Definition at line 1299 of file hw.cc.

{
  if(This)
    This->width = width;
}

Here is the caller graph for this function:

void hwNode::unclaim ( )

Definition at line 322 of file hw.cc.

{
  if (!This)
    return;

  This->claimed = false;
}
bool hwNode::usesResource ( const hw::resource r) const

Definition at line 1271 of file hw.cc.

{
  if (!This)
    return false;

  for (size_t i = 0; i < This->resources.size(); i++)
    if (r == This->resources[i])
      return true;

  return false;
}

Member Data Documentation

struct hwNode_i* hwNode::This [private]

Definition at line 229 of file hw.h.


The documentation for this class was generated from the following files: