Back to index

lshw  02.16
Public Member Functions | Static Public Member Functions | Private Attributes
hw::resource Class Reference

#include <hw.h>

Collaboration diagram for hw::resource:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 resource ()
 ~resource ()
 resource (const resource &)
resourceoperator= (const resource &)
bool operator== (const resource &) const
string asString (const string &separator=":") const

Static Public Member Functions

static resource iomem (unsigned long long, unsigned long long)
static resource ioport (unsigned long, unsigned long)
static resource mem (unsigned long long, unsigned long long, bool prefetchable=false)
static resource irq (unsigned int)
static resource dma (unsigned int)

Private Attributes

struct resource_iThis

Detailed Description

Definition at line 44 of file hw.h.


Constructor & Destructor Documentation

Definition at line 1991 of file hw.cc.

{
  This = new struct resource_i;

  if (This)
  {
    memset(This, 0, sizeof(*This));
    This->type = none;
    This->refcount = 1;
  }
}

Definition at line 2004 of file hw.cc.

{
  if (This)
  {
    This->refcount--;

    if (This->refcount <= 0)
    {
      delete This;
      This = NULL;
    }
  }
}
resource::resource ( const resource r)

Definition at line 2019 of file hw.cc.

{
  This = r.This;

  if (This)
    This->refcount++;
}

Member Function Documentation

string resource::asString ( const string &  separator = ":") const

Definition at line 2132 of file hw.cc.

{
  char buffer[80];
  string result = "";

  if (!This)
    return result;

  strncpy(buffer, "", sizeof(buffer));

  switch (This->type)
  {
    case hw::none:
      result = _("(none)");
      break;
    case hw::dma:
      result = _("dma") + separator;
      snprintf(buffer, sizeof(buffer), "%d", This->ui1);
      break;
    case hw::irq:
      result = _("irq") + separator;
      snprintf(buffer, sizeof(buffer), "%d", This->ui1);
      break;
    case hw::iomem:
      result = _("iomemory") + separator;
      snprintf(buffer, sizeof(buffer), "%llx-%llx", This->ull1, This->ull2);
      break;
    case hw::mem:
      result = _("memory") + separator;
      snprintf(buffer, sizeof(buffer), "%llx-%llx", This->ull1, This->ull2);
      if(This->b) strcat(buffer, _("(prefetchable)"));
      break;
    case hw::ioport:
      result = _("ioport") + separator;
      if(This->ul1 == This->ul2)
        snprintf(buffer, sizeof(buffer), "%lx", This->ul1);
      else
        snprintf(buffer, sizeof(buffer), _("%lx(size=%ld)"), This->ul1, This->ul2 - This->ul1 + 1);
      break;
    default:
      result = _("(unknown)");
  }

  return result + string(buffer);
}
resource resource::dma ( unsigned int  value) [static]

Definition at line 2118 of file hw.cc.

{
  resource r;

  if (!r.This)
    return r;

  r.This->type = hw::dma;
  r.This->ui1 = value;

  return r;
}
resource resource::iomem ( unsigned long long  start,
unsigned long long  end 
) [static]

Definition at line 2055 of file hw.cc.

{
  resource r;

  if (!r.This)
    return r;

  r.This->type = hw::iomem;
  r.This->ull1 = start;
  r.This->ull2 = end;

  return r;
}

Here is the caller graph for this function:

resource resource::ioport ( unsigned long  start,
unsigned long  end 
) [static]

Definition at line 2071 of file hw.cc.

{
  resource r;

  if (!r.This)
    return r;

  r.This->type = hw::ioport;
  r.This->ul1 = start;
  r.This->ul2 = end;

  return r;
}

Here is the caller graph for this function:

resource resource::irq ( unsigned int  value) [static]

Definition at line 2104 of file hw.cc.

{
  resource r;

  if (!r.This)
    return r;

  r.This->type = hw::irq;
  r.This->ui1 = value;

  return r;
}

Here is the caller graph for this function:

resource resource::mem ( unsigned long long  start,
unsigned long long  end,
bool  prefetchable = false 
) [static]

Definition at line 2087 of file hw.cc.

{
  resource r;

  if (!r.This)
    return r;

  r.This->type = hw::mem;
  r.This->ull1 = start;
  r.This->ull2 = end;
  r.This->b = prefetchable;

  return r;
}

Here is the caller graph for this function:

resource & resource::operator= ( const resource r)

Definition at line 2028 of file hw.cc.

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

  if (This == r.This)
    return *this;                                 // both objects reference the same data

  if (This)
  {
    This->refcount--;

    if (This->refcount <= 0)
    {
      delete This;
      This = NULL;
    }
  }

  This = r.This;
  if (This)
    This->refcount++;

  return *this;
}
bool resource::operator== ( const resource r) const

Definition at line 2179 of file hw.cc.

{
  if (This == r.This)
    return true;

  if (!This || !r.This)
    return false;

  if (This->type != r.This->type)
    return false;

  switch (This->type)
  {
    case hw::dma:
    case hw::irq:
      return This->ui1 == r.This->ui1;
      break;

    case hw::iomem:
    case hw::mem:
      return ((This->ull1 >= r.This->ull1)
      && (This->ull2 <= r.This->ull2)) || ((r.This->ull1 >= This->ull1)
      && (r.This->ull2 <= This->ull2));
    break;

    case hw::ioport:
      return ((This->ul1 >= r.This->ul1)
      && (This->ul1 <= r.This->ul2)) || ((r.This->ul1 >= This->ul1)
      && (r.This->ul1 <= This->ul2));
    break;

    default:return false;
  }
}

Member Data Documentation

struct resource_i* hw::resource::This [private]

Definition at line 64 of file hw.h.


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