libgpiod  1.6.2
Public Types | Public Member Functions
gpiod::chip Class Reference

Represents a GPIO chip. More...

#include <gpiod.hpp>

Public Types

enum  : int {
  OPEN_LOOKUP = 1, OPEN_BY_PATH, OPEN_BY_NAME, OPEN_BY_LABEL,
  OPEN_BY_NUMBER
}
 Affect the way in which chip::chip and chip::open will try to open a GPIO chip character device. More...
 

Public Member Functions

GPIOD_API chip (void)=default
 Default constructor. More...
 
GPIOD_API chip (const ::std::string &device, int how=OPEN_LOOKUP)
 Constructor. More...
 
GPIOD_API chip (const chip &other)=default
 Copy constructor. More...
 
GPIOD_API chip (chip &&other)=default
 Move constructor. More...
 
GPIOD_API chipoperator= (const chip &other)=default
 Assignment operator. More...
 
GPIOD_API chipoperator= (chip &&other)=default
 Move assignment operator. More...
 
GPIOD_API ~chip (void)=default
 Destructor. More...
 
GPIOD_API void open (const ::std::string &device, int how=OPEN_LOOKUP)
 Open a GPIO chip. More...
 
GPIOD_API void reset (void) noexcept
 Reset the internal smart pointer owned by this object.
 
GPIOD_API ::std::string name (void) const
 Return the name of the chip held by this object. More...
 
GPIOD_API ::std::string label (void) const
 Return the label of the chip held by this object. More...
 
GPIOD_API unsigned int num_lines (void) const
 Return the number of lines exposed by this chip. More...
 
GPIOD_API line get_line (unsigned int offset) const
 Get the line exposed by this chip at given offset. More...
 
GPIOD_API line find_line (const ::std::string &name) const
 Get the line exposed by this chip by name. More...
 
GPIOD_API line_bulk get_lines (const ::std::vector< unsigned int > &offsets) const
 Get a set of lines exposed by this chip at given offsets. More...
 
GPIOD_API line_bulk get_all_lines (void) const
 Get all lines exposed by this chip. More...
 
GPIOD_API line_bulk find_lines (const ::std::vector<::std::string > &names) const
 Get a set of lines exposed by this chip by their names. More...
 
GPIOD_API bool operator== (const chip &rhs) const noexcept
 Equality operator. More...
 
GPIOD_API bool operator!= (const chip &rhs) const noexcept
 Inequality operator. More...
 
GPIOD_API operator bool (void) const noexcept
 Check if this object holds a reference to a GPIO chip. More...
 
GPIOD_API bool operator! (void) const noexcept
 Check if this object doesn't hold a reference to a GPIO chip. More...
 

Detailed Description

Represents a GPIO chip.

Internally this class holds a smart pointer to an open GPIO chip descriptor. Multiple objects of this class can reference the same chip. The chip is closed and all resources freed when the last reference is dropped.

Definition at line 42 of file gpiod.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum : int

Affect the way in which chip::chip and chip::open will try to open a GPIO chip character device.

Enumerator
OPEN_LOOKUP 

Open based on the best guess what the supplied string is.

OPEN_BY_PATH 

Assume the string is a path to the GPIO chardev.

OPEN_BY_NAME 

Assume the string is the name of the chip.

OPEN_BY_LABEL 

Assume the string is the label of the GPIO chip.

OPEN_BY_NUMBER 

Assume the string is the number of the GPIO chip.

Definition at line 186 of file gpiod.hpp.

Constructor & Destructor Documentation

◆ chip() [1/4]

GPIOD_API gpiod::chip::chip ( void  )
default

Default constructor.

Creates an empty GPIO chip object.

◆ chip() [2/4]

GPIOD_API gpiod::chip::chip ( const ::std::string &  device,
int  how = OPEN_LOOKUP 
)

Constructor.

Opens the chip using chip::open.

Parameters
deviceString describing the GPIO chip.
howIndicates how the chip should be opened.

◆ chip() [3/4]

GPIOD_API gpiod::chip::chip ( const chip other)
default

Copy constructor.

References the object held by other.

Parameters
otherOther chip object.

◆ chip() [4/4]

GPIOD_API gpiod::chip::chip ( chip &&  other)
default

Move constructor.

References the object held by other.

Parameters
otherOther chip object.

◆ ~chip()

GPIOD_API gpiod::chip::~chip ( void  )
default

Destructor.

Unreferences the internal chip object.

Member Function Documentation

◆ find_line()

GPIOD_API line gpiod::chip::find_line ( const ::std::string &  name) const

Get the line exposed by this chip by name.

Parameters
nameLine name.
Returns
Line object.

◆ find_lines()

GPIOD_API line_bulk gpiod::chip::find_lines ( const ::std::vector<::std::string > &  names) const

Get a set of lines exposed by this chip by their names.

Parameters
namesVector of line names.
Returns
Set of lines held by a line_bulk object.

◆ get_all_lines()

GPIOD_API line_bulk gpiod::chip::get_all_lines ( void  ) const

Get all lines exposed by this chip.

Returns
All lines exposed by this chip held by a line_bulk object.

◆ get_line()

GPIOD_API line gpiod::chip::get_line ( unsigned int  offset) const

Get the line exposed by this chip at given offset.

Parameters
offsetOffset of the line.
Returns
Line object.

◆ get_lines()

GPIOD_API line_bulk gpiod::chip::get_lines ( const ::std::vector< unsigned int > &  offsets) const

Get a set of lines exposed by this chip at given offsets.

Parameters
offsetsVector of line offsets.
Returns
Set of lines held by a line_bulk object.

◆ label()

GPIOD_API ::std::string gpiod::chip::label ( void  ) const

Return the label of the chip held by this object.

Returns
Label of the GPIO chip.

◆ name()

GPIOD_API ::std::string gpiod::chip::name ( void  ) const

Return the name of the chip held by this object.

Returns
Name of the GPIO chip.

◆ num_lines()

GPIOD_API unsigned int gpiod::chip::num_lines ( void  ) const

Return the number of lines exposed by this chip.

Returns
Number of lines.

◆ open()

GPIOD_API void gpiod::chip::open ( const ::std::string &  device,
int  how = OPEN_LOOKUP 
)

Open a GPIO chip.

Parameters
deviceString describing the GPIO chip.
howIndicates how the chip should be opened.

If the object already holds a reference to an open chip, it will be closed and the reference reset.

◆ operator bool()

GPIOD_API gpiod::chip::operator bool ( void  ) const
explicitnoexcept

Check if this object holds a reference to a GPIO chip.

Returns
True if this object references a GPIO chip, false otherwise.

◆ operator!()

GPIOD_API bool gpiod::chip::operator! ( void  ) const
noexcept

Check if this object doesn't hold a reference to a GPIO chip.

Returns
False if this object references a GPIO chip, true otherwise.

References OPEN_BY_LABEL, OPEN_BY_NAME, OPEN_BY_NUMBER, OPEN_BY_PATH, and OPEN_LOOKUP.

◆ operator!=()

GPIOD_API bool gpiod::chip::operator!= ( const chip rhs) const
noexcept

Inequality operator.

Parameters
rhsRight-hand side of the equation.
Returns
False if rhs references the same chip. True otherwise.

◆ operator=() [1/2]

GPIOD_API chip& gpiod::chip::operator= ( chip &&  other)
default

Move assignment operator.

References the object held by other.

Parameters
otherOther chip object.
Returns
Reference to this object.

◆ operator=() [2/2]

GPIOD_API chip& gpiod::chip::operator= ( const chip other)
default

Assignment operator.

References the object held by other.

Parameters
otherOther chip object.
Returns
Reference to this object.

◆ operator==()

GPIOD_API bool gpiod::chip::operator== ( const chip rhs) const
noexcept

Equality operator.

Parameters
rhsRight-hand side of the equation.
Returns
True if rhs references the same chip. False otherwise.

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