# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <bartekgola@gmail.com>
lib_LTLIBRARIES = libgpiodcxx.la
-libgpiodcxx_la_SOURCES = chip.cpp iter.cpp line.cpp line_bulk.cpp
+libgpiodcxx_la_SOURCES = chip.cpp internal.h iter.cpp line.cpp line_bulk.cpp
libgpiodcxx_la_CPPFLAGS = -Wall -Wextra -g -std=gnu++11
libgpiodcxx_la_CPPFLAGS += -fvisibility=hidden -I$(top_srcdir)/include/
libgpiodcxx_la_LDFLAGS = -version-info $(subst .,:,$(ABI_CXX_VERSION))
#include <system_error>
#include <utility>
+#include "internal.hpp"
+
namespace gpiod {
namespace {
-void chip_deleter(::gpiod_chip* chip)
+GPIOD_CXX_API void chip_deleter(::gpiod_chip* chip)
{
::gpiod_chip_unref(chip);
}
} /* namespace */
-bool is_gpiochip_device(const ::std::string& path)
+GPIOD_CXX_API bool is_gpiochip_device(const ::std::string& path)
{
return ::gpiod_is_gpiochip_device(path.c_str());
}
-chip::chip(const ::std::string& path)
+GPIOD_CXX_API chip::chip(const ::std::string& path)
: _m_chip()
{
this->open(path);
}
-chip::chip(::gpiod_chip* chip)
+GPIOD_CXX_API chip::chip(::gpiod_chip* chip)
: _m_chip(chip, chip_deleter)
{
}
-chip::chip(const ::std::weak_ptr<::gpiod_chip>& chip_ptr)
+GPIOD_CXX_API chip::chip(const ::std::weak_ptr<::gpiod_chip>& chip_ptr)
: _m_chip(chip_ptr)
{
}
-void chip::open(const ::std::string& path)
+GPIOD_CXX_API void chip::open(const ::std::string& path)
{
::gpiod_chip *chip = ::gpiod_chip_open(path.c_str());
if (!chip)
this->_m_chip.reset(chip, chip_deleter);
}
-void chip::reset(void) noexcept
+GPIOD_CXX_API void chip::reset(void) noexcept
{
this->_m_chip.reset();
}
-::std::string chip::name(void) const
+GPIOD_CXX_API ::std::string chip::name(void) const
{
this->throw_if_noref();
return ::std::string(::gpiod_chip_name(this->_m_chip.get()));
}
-::std::string chip::label(void) const
+GPIOD_CXX_API ::std::string chip::label(void) const
{
this->throw_if_noref();
return ::std::string(::gpiod_chip_label(this->_m_chip.get()));
}
-unsigned int chip::num_lines(void) const
+GPIOD_CXX_API unsigned int chip::num_lines(void) const
{
this->throw_if_noref();
return ::gpiod_chip_num_lines(this->_m_chip.get());
}
-line chip::get_line(unsigned int offset) const
+GPIOD_CXX_API line chip::get_line(unsigned int offset) const
{
this->throw_if_noref();
return line(line_handle, *this);
}
-int chip::find_line(const ::std::string& name) const
+GPIOD_CXX_API int chip::find_line(const ::std::string& name) const
{
this->throw_if_noref();
return -1;
}
-line_bulk chip::get_lines(const ::std::vector<unsigned int>& offsets) const
+GPIOD_CXX_API line_bulk chip::get_lines(const ::std::vector<unsigned int>& offsets) const
{
line_bulk lines;
return lines;
}
-line_bulk chip::get_all_lines(void) const
+GPIOD_CXX_API line_bulk chip::get_all_lines(void) const
{
line_bulk lines;
return lines;
}
-bool chip::operator==(const chip& rhs) const noexcept
+GPIOD_CXX_API bool chip::operator==(const chip& rhs) const noexcept
{
return this->_m_chip.get() == rhs._m_chip.get();
}
-bool chip::operator!=(const chip& rhs) const noexcept
+GPIOD_CXX_API bool chip::operator!=(const chip& rhs) const noexcept
{
return this->_m_chip.get() != rhs._m_chip.get();
}
-chip::operator bool(void) const noexcept
+GPIOD_CXX_API chip::operator bool(void) const noexcept
{
return this->_m_chip.get() != nullptr;
}
-bool chip::operator!(void) const noexcept
+GPIOD_CXX_API bool chip::operator!(void) const noexcept
{
return this->_m_chip.get() == nullptr;
}
-void chip::throw_if_noref(void) const
+GPIOD_CXX_API void chip::throw_if_noref(void) const
{
if (!this->_m_chip.get())
throw ::std::logic_error("object not associated with an open GPIO chip");
* @return True if the file exists and is a GPIO chip character device or a
* symbolic link to it.
*/
-bool is_gpiochip_device(const ::std::string& path) GPIOD_API;
+bool is_gpiochip_device(const ::std::string& path);
/**
* @brief Represents a GPIO chip.
/**
* @brief Default constructor. Creates an empty GPIO chip object.
*/
- GPIOD_API chip(void) = default;
+ chip(void) = default;
/**
* @brief Constructor. Opens the chip using chip::open.
* @param path Path to the GPIO chip device.
*/
- GPIOD_API chip(const ::std::string& path);
+ chip(const ::std::string& path);
/**
* @brief Copy constructor. References the object held by other.
* @param other Other chip object.
*/
- GPIOD_API chip(const chip& other) = default;
+ chip(const chip& other) = default;
/**
* @brief Move constructor. References the object held by other.
* @param other Other chip object.
*/
- GPIOD_API chip(chip&& other) = default;
+ chip(chip&& other) = default;
/**
* @brief Assignment operator. References the object held by other.
* @param other Other chip object.
* @return Reference to this object.
*/
- GPIOD_API chip& operator=(const chip& other) = default;
+ chip& operator=(const chip& other) = default;
/**
* @brief Move assignment operator. References the object held by other.
* @param other Other chip object.
* @return Reference to this object.
*/
- GPIOD_API chip& operator=(chip&& other) = default;
+ chip& operator=(chip&& other) = default;
/**
* @brief Destructor. Unreferences the internal chip object.
*/
- GPIOD_API ~chip(void) = default;
+ ~chip(void) = default;
/**
* @brief Open a GPIO chip.
* If the object already holds a reference to an open chip, it will be
* closed and the reference reset.
*/
- GPIOD_API void open(const ::std::string &path);
+ void open(const ::std::string &path);
/**
* @brief Reset the internal smart pointer owned by this object.
*/
- GPIOD_API void reset(void) noexcept;
+ void reset(void) noexcept;
/**
* @brief Return the name of the chip held by this object.
* @return Name of the GPIO chip.
*/
- GPIOD_API ::std::string name(void) const;
+ ::std::string name(void) const;
/**
* @brief Return the label of the chip held by this object.
* @return Label of the GPIO chip.
*/
- GPIOD_API ::std::string label(void) const;
+ ::std::string label(void) const;
/**
* @brief Return the number of lines exposed by this chip.
* @return Number of lines.
*/
- GPIOD_API unsigned int num_lines(void) const;
+ unsigned int num_lines(void) const;
/**
* @brief Get the line exposed by this chip at given offset.
* @param offset Offset of the line.
* @return Line object.
*/
- GPIOD_API line get_line(unsigned int offset) const;
+ line get_line(unsigned int offset) const;
/**
* @brief Map a GPIO line's name to its offset within the chip.
* @return Offset of the line within the chip or -1 if a line with
* given name is not exposed by the chip.
*/
- GPIOD_API int find_line(const ::std::string& name) const;
+ int find_line(const ::std::string& name) const;
/**
* @brief Get a set of lines exposed by this chip at given offsets.
* @param offsets Vector of line offsets.
* @return Set of lines held by a line_bulk object.
*/
- GPIOD_API line_bulk get_lines(const ::std::vector<unsigned int>& offsets) const;
+ line_bulk get_lines(const ::std::vector<unsigned int>& offsets) const;
/**
* @brief Get all lines exposed by this chip.
* @return All lines exposed by this chip held by a line_bulk object.
*/
- GPIOD_API line_bulk get_all_lines(void) const;
+ line_bulk get_all_lines(void) const;
/**
* @brief Equality operator.
* @param rhs Right-hand side of the equation.
* @return True if rhs references the same chip. False otherwise.
*/
- GPIOD_API bool operator==(const chip& rhs) const noexcept;
+ bool operator==(const chip& rhs) const noexcept;
/**
* @brief Inequality operator.
* @param rhs Right-hand side of the equation.
* @return False if rhs references the same chip. True otherwise.
*/
- GPIOD_API bool operator!=(const chip& rhs) const noexcept;
+ bool operator!=(const chip& rhs) const noexcept;
/**
* @brief Check if this object holds a reference to a GPIO chip.
* @return True if this object references a GPIO chip, false otherwise.
*/
- GPIOD_API explicit operator bool(void) const noexcept;
+ explicit operator bool(void) const noexcept;
/**
* @brief Check if this object doesn't hold a reference to a GPIO chip.
* @return False if this object references a GPIO chip, true otherwise.
*/
- GPIOD_API bool operator!(void) const noexcept;
+ bool operator!(void) const noexcept;
private:
/**< Listen for all types of events. */
};
- GPIOD_API static const ::std::bitset<32> FLAG_ACTIVE_LOW;
+ static const ::std::bitset<32> FLAG_ACTIVE_LOW;
/**< Set the active state to 'low' (high is the default). */
- GPIOD_API static const ::std::bitset<32> FLAG_OPEN_SOURCE;
+ static const ::std::bitset<32> FLAG_OPEN_SOURCE;
/**< The line is an open-source port. */
- GPIOD_API static const ::std::bitset<32> FLAG_OPEN_DRAIN;
+ static const ::std::bitset<32> FLAG_OPEN_DRAIN;
/**< The line is an open-drain port. */
- GPIOD_API static const ::std::bitset<32> FLAG_BIAS_DISABLED;
+ static const ::std::bitset<32> FLAG_BIAS_DISABLED;
/**< The line has neither pull-up nor pull-down resistor enabled. */
- GPIOD_API static const ::std::bitset<32> FLAG_BIAS_PULL_DOWN;
+ static const ::std::bitset<32> FLAG_BIAS_PULL_DOWN;
/**< The line has a configurable pull-down resistor enabled. */
- GPIOD_API static const ::std::bitset<32> FLAG_BIAS_PULL_UP;
+ static const ::std::bitset<32> FLAG_BIAS_PULL_UP;
/**< The line has a configurable pull-up resistor enabled. */
::std::string consumer;
/**
* @brief Default constructor. Creates an empty line object.
*/
- GPIOD_API line(void);
+ line(void);
/**
* @brief Copy constructor.
* @param other Other line object.
*/
- GPIOD_API line(const line& other) = default;
+ line(const line& other) = default;
/**
* @brief Move constructor.
* @param other Other line object.
*/
- GPIOD_API line(line&& other) = default;
+ line(line&& other) = default;
/**
* @brief Assignment operator.
* @param other Other line object.
* @return Reference to this object.
*/
- GPIOD_API line& operator=(const line& other) = default;
+ line& operator=(const line& other) = default;
/**
* @brief Move assignment operator.
* @param other Other line object.
* @return Reference to this object.
*/
- GPIOD_API line& operator=(line&& other) = default;
+ line& operator=(line&& other) = default;
/**
* @brief Destructor.
*/
- GPIOD_API ~line(void) = default;
+ ~line(void) = default;
/**
* @brief Get the offset of this line.
* @return Offet of this line.
*/
- GPIOD_API unsigned int offset(void) const;
+ unsigned int offset(void) const;
/**
* @brief Get the name of this line (if any).
* @return Name of this line or an empty string if it is unnamed.
*/
- GPIOD_API ::std::string name(void) const;
+ ::std::string name(void) const;
/**
* @brief Get the consumer of this line (if any).
* @return Name of the consumer of this line or an empty string if it
* is unused.
*/
- GPIOD_API ::std::string consumer(void) const;
+ ::std::string consumer(void) const;
/**
* @brief Get current direction of this line.
* @return Current direction setting.
*/
- GPIOD_API int direction(void) const;
+ int direction(void) const;
/**
* @brief Check if this line's signal is inverted.
* @return True if this line is "active-low", false otherwise.
*/
- GPIOD_API bool is_active_low(void) const;
+ bool is_active_low(void) const;
/**
* @brief Get current bias of this line.
* @return Current bias setting.
*/
- GPIOD_API int bias(void) const;
+ int bias(void) const;
/**
* @brief Check if this line is used by the kernel or other user space
* process.
* @return True if this line is in use, false otherwise.
*/
- GPIOD_API bool is_used(void) const;
+ bool is_used(void) const;
/**
* @brief Get current drive setting of this line.
* @return Current drive setting.
*/
- GPIOD_API int drive(void) const;
+ int drive(void) const;
/**
* @brief Request this line.
* @param config Request config (see gpiod::line_request).
* @param default_val Default value - only matters for OUTPUT direction.
*/
- GPIOD_API void request(const line_request& config, int default_val = 0) const;
+ void request(const line_request& config, int default_val = 0) const;
/**
* @brief Release the line if it was previously requested.
*/
- GPIOD_API void release(void) const;
+ void release(void) const;
/**
* @brief Read the line value.
* @return Current value (0 or 1).
*/
- GPIOD_API int get_value(void) const;
+ int get_value(void) const;
/**
* @brief Set the value of this line.
* @param val New value (0 or 1).
*/
- GPIOD_API void set_value(int val) const;
+ void set_value(int val) const;
/**
* @brief Set configuration of this line.
* @param flags Replacement flags.
* @param value New value (0 or 1) - only matters for OUTPUT direction.
*/
- GPIOD_API void set_config(int direction, ::std::bitset<32> flags,
- int value = 0) const;
+ void set_config(int direction, ::std::bitset<32> flags, int value = 0) const;
/**
* @brief Set configuration flags of this line.
* @param flags Replacement flags.
*/
- GPIOD_API void set_flags(::std::bitset<32> flags) const;
+ void set_flags(::std::bitset<32> flags) const;
/**
* @brief Change the direction this line to input.
*/
- GPIOD_API void set_direction_input() const;
+ void set_direction_input() const;
/**
* @brief Change the direction this lines to output.
* @param value New value (0 or 1).
*/
- GPIOD_API void set_direction_output(int value = 0) const;
+ void set_direction_output(int value = 0) const;
/**
* @brief Wait for an event on this line.
* @return True if an event occurred and can be read, false if the wait
* timed out.
*/
- GPIOD_API bool event_wait(const ::std::chrono::nanoseconds& timeout) const;
+ bool event_wait(const ::std::chrono::nanoseconds& timeout) const;
/**
* @brief Read a line event.
* @return Line event object.
*/
- GPIOD_API line_event event_read(void) const;
+ line_event event_read(void) const;
/**
* @brief Read multiple line events.
* @return Vector of line event objects.
*/
- GPIOD_API ::std::vector<line_event> event_read_multiple(void) const;
+ ::std::vector<line_event> event_read_multiple(void) const;
/**
* @brief Get the event file descriptor associated with this line.
* @return File descriptor number.
*/
- GPIOD_API int event_get_fd(void) const;
+ int event_get_fd(void) const;
/**
* @brief Get the parent chip.
* @return Parent chip of this line.
*/
- GPIOD_API const chip get_chip(void) const;
+ const chip get_chip(void) const;
/**
* @brief Reset the state of this object.
* but wants to drop the reference to the GPIO chip indirectly held by
* the line being the source of the event.
*/
- GPIOD_API void reset(void);
+ void reset(void);
/**
* @brief Check if two line objects reference the same GPIO line.
* @param rhs Right-hand side of the equation.
* @return True if both objects reference the same line, fale otherwise.
*/
- GPIOD_API bool operator==(const line& rhs) const noexcept;
+ bool operator==(const line& rhs) const noexcept;
/**
* @brief Check if two line objects reference different GPIO lines.
* @param rhs Right-hand side of the equation.
* @return False if both objects reference the same line, true otherwise.
*/
- GPIOD_API bool operator!=(const line& rhs) const noexcept;
+ bool operator!=(const line& rhs) const noexcept;
/**
* @brief Check if this object holds a reference to any GPIO line.
* @return True if this object references a GPIO line, false otherwise.
*/
- GPIOD_API explicit operator bool(void) const noexcept;
+ explicit operator bool(void) const noexcept;
/**
* @brief Check if this object doesn't reference any GPIO line.
* @return True if this object doesn't reference any GPIO line, true
* otherwise.
*/
- GPIOD_API bool operator!(void) const noexcept;
+ bool operator!(void) const noexcept;
/**
* @brief Possible direction settings.
/**
* @brief Default constructor. Creates an empty line_bulk object.
*/
- GPIOD_API line_bulk(void) = default;
+ line_bulk(void) = default;
/**
* @brief Construct a line_bulk from a vector of lines.
* @param lines Vector of gpiod::line objects.
* @note All lines must be owned by the same GPIO chip.
*/
- GPIOD_API line_bulk(const ::std::vector<line>& lines);
+ line_bulk(const ::std::vector<line>& lines);
/**
* @brief Copy constructor.
* @param other Other line_bulk object.
*/
- GPIOD_API line_bulk(const line_bulk& other) = default;
+ line_bulk(const line_bulk& other) = default;
/**
* @brief Move constructor.
* @param other Other line_bulk object.
*/
- GPIOD_API line_bulk(line_bulk&& other) = default;
+ line_bulk(line_bulk&& other) = default;
/**
* @brief Assignment operator.
* @param other Other line_bulk object.
* @return Reference to this object.
*/
- GPIOD_API line_bulk& operator=(const line_bulk& other) = default;
+ line_bulk& operator=(const line_bulk& other) = default;
/**
* @brief Move assignment operator.
* @param other Other line_bulk object.
* @return Reference to this object.
*/
- GPIOD_API line_bulk& operator=(line_bulk&& other) = default;
+ line_bulk& operator=(line_bulk&& other) = default;
/**
* @brief Destructor.
*/
- GPIOD_API ~line_bulk(void) = default;
+ ~line_bulk(void) = default;
/**
* @brief Add a line to this line_bulk object.
* @note The new line must be owned by the same chip as all the other
* lines already held by this line_bulk object.
*/
- GPIOD_API void append(const line& new_line);
+ void append(const line& new_line);
/**
* @brief Get the line at given offset.
* @note This method will throw if index is equal or greater than the
* number of lines currently held by this bulk.
*/
- GPIOD_API line& get(unsigned int index);
+ line& get(unsigned int index);
/**
* @brief Get the line at given offset without bounds checking.
* @return Reference to the line object.
* @note No bounds checking is performed.
*/
- GPIOD_API line& operator[](unsigned int index);
+ line& operator[](unsigned int index);
/**
* @brief Get the number of lines currently held by this object.
* @return Number of elements in this line_bulk.
*/
- GPIOD_API unsigned int size(void) const noexcept;
+ unsigned int size(void) const noexcept;
/**
* @brief Check if this line_bulk doesn't hold any lines.
* @return True if this object is empty, false otherwise.
*/
- GPIOD_API bool empty(void) const noexcept;
+ bool empty(void) const noexcept;
/**
* @brief Remove all lines from this object.
*/
- GPIOD_API void clear(void);
+ void clear(void);
/**
* @brief Request all lines held by this object.
* @param default_vals Vector of default values. Only relevant for
* output direction requests.
*/
- GPIOD_API void request(const line_request& config,
- const ::std::vector<int> default_vals = ::std::vector<int>()) const;
+ void request(const line_request& config,
+ const ::std::vector<int> default_vals = ::std::vector<int>()) const;
/**
* @brief Release all lines held by this object.
*/
- GPIOD_API void release(void) const;
+ void release(void) const;
/**
* @brief Read values from all lines held by this object.
* @return Vector containing line values the order of which corresponds
* with the order of lines in the internal array.
*/
- GPIOD_API ::std::vector<int> get_values(void) const;
+ ::std::vector<int> get_values(void) const;
/**
* @brief Set values of all lines held by this object.
* @param values Vector of values to set. Must be the same size as the
* number of lines held by this line_bulk.
*/
- GPIOD_API void set_values(const ::std::vector<int>& values) const;
+ void set_values(const ::std::vector<int>& values) const;
/**
* @brief Set configuration of all lines held by this object.
* number of lines held by this line_bulk.
* Only relevant for output direction requests.
*/
- GPIOD_API void set_config(int direction, ::std::bitset<32> flags,
- const ::std::vector<int> values = ::std::vector<int>()) const;
+ void set_config(int direction, ::std::bitset<32> flags,
+ const ::std::vector<int> values = ::std::vector<int>()) const;
/**
* @brief Set configuration flags of all lines held by this object.
* @param flags Replacement flags.
*/
- GPIOD_API void set_flags(::std::bitset<32> flags) const;
+ void set_flags(::std::bitset<32> flags) const;
/**
* @brief Change the direction all lines held by this object to input.
*/
- GPIOD_API void set_direction_input() const;
+ void set_direction_input() const;
/**
* @brief Change the direction all lines held by this object to output.
* @param values Vector of values to set. Must be the same size as the
* number of lines held by this line_bulk.
*/
- GPIOD_API void set_direction_output(const ::std::vector<int>& values) const;
+ void set_direction_output(const ::std::vector<int>& values) const;
/**
* @brief Poll the set of lines for line events.
* @return Returns a line_bulk object containing lines on which events
* occurred.
*/
- GPIOD_API line_bulk event_wait(const ::std::chrono::nanoseconds& timeout) const;
+ line_bulk event_wait(const ::std::chrono::nanoseconds& timeout) const;
/**
* @brief Check if this object holds any lines.
* @return True if this line_bulk holds at least one line, false otherwise.
*/
- GPIOD_API explicit operator bool(void) const noexcept;
+ explicit operator bool(void) const noexcept;
/**
* @brief Check if this object doesn't hold any lines.
* @return True if this line_bulk is empty, false otherwise.
*/
- GPIOD_API bool operator!(void) const noexcept;
+ bool operator!(void) const noexcept;
/**
* @brief Max number of lines that this object can hold.
*/
- GPIOD_API static const unsigned int MAX_LINES;
+ static const unsigned int MAX_LINES;
/**
* @brief Iterator for iterating over lines held by line_bulk.
/**
* @brief Default constructor. Builds an empty iterator object.
*/
- GPIOD_API iterator(void) = default;
+ iterator(void) = default;
/**
* @brief Copy constructor.
* @param other Other line_bulk iterator.
*/
- GPIOD_API iterator(const iterator& other) = default;
+ iterator(const iterator& other) = default;
/**
* @brief Move constructor.
* @param other Other line_bulk iterator.
*/
- GPIOD_API iterator(iterator&& other) = default;
+ iterator(iterator&& other) = default;
/**
* @brief Assignment operator.
* @param other Other line_bulk iterator.
* @return Reference to this iterator.
*/
- GPIOD_API iterator& operator=(const iterator& other) = default;
+ iterator& operator=(const iterator& other) = default;
/**
* @brief Move assignment operator.
* @param other Other line_bulk iterator.
* @return Reference to this iterator.
*/
- GPIOD_API iterator& operator=(iterator&& other) = default;
+ iterator& operator=(iterator&& other) = default;
/**
* @brief Destructor.
*/
- GPIOD_API ~iterator(void) = default;
+ ~iterator(void) = default;
/**
* @brief Advance the iterator by one element.
* @return Reference to this iterator.
*/
- GPIOD_API iterator& operator++(void);
+ iterator& operator++(void);
/**
* @brief Dereference current element.
* @return Current GPIO line by reference.
*/
- GPIOD_API const line& operator*(void) const;
+ const line& operator*(void) const;
/**
* @brief Member access operator.
* @return Current GPIO line by pointer.
*/
- GPIOD_API const line* operator->(void) const;
+ const line* operator->(void) const;
/**
* @brief Check if this operator points to the same element.
* @return True if this iterator points to the same GPIO line,
* false otherwise.
*/
- GPIOD_API bool operator==(const iterator& rhs) const noexcept;
+ bool operator==(const iterator& rhs) const noexcept;
/**
* @brief Check if this operator doesn't point to the same element.
* @return True if this iterator doesn't point to the same GPIO
* line, false otherwise.
*/
- GPIOD_API bool operator!=(const iterator& rhs) const noexcept;
+ bool operator!=(const iterator& rhs) const noexcept;
private:
* @brief Returns an iterator to the first line.
* @return A line_bulk iterator.
*/
- GPIOD_API iterator begin(void) noexcept;
+ iterator begin(void) noexcept;
/**
* @brief Returns an iterator to the element following the last line.
* @return A line_bulk iterator.
*/
- GPIOD_API iterator end(void) noexcept;
+ iterator end(void) noexcept;
private:
* @param iter A line iterator.
* @return Iterator unchanged.
*/
-GPIOD_API line_iter begin(line_iter iter) noexcept;
+line_iter begin(line_iter iter) noexcept;
/**
* @brief Support for range-based loops for line iterators.
* @param iter A line iterator.
* @return New end iterator.
*/
-GPIOD_API line_iter end(const line_iter& iter) noexcept;
+line_iter end(const line_iter& iter) noexcept;
/**
* @brief Allows to iterate over all lines owned by a GPIO chip.
/**
* @brief Default constructor. Creates the end iterator.
*/
- GPIOD_API line_iter(void) = default;
+ line_iter(void) = default;
/**
* @brief Constructor. Creates the begin iterator.
* @param owner Chip owning the GPIO lines over which we want to iterate.
*/
- GPIOD_API line_iter(const chip& owner);
+ line_iter(const chip& owner);
/**
* @brief Copy constructor.
* @param other Other line iterator.
*/
- GPIOD_API line_iter(const line_iter& other) = default;
+ line_iter(const line_iter& other) = default;
/**
* @brief Move constructor.
* @param other Other line iterator.
*/
- GPIOD_API line_iter(line_iter&& other) = default;
+ line_iter(line_iter&& other) = default;
/**
* @brief Assignment operator.
* @param other Other line iterator.
* @return Reference to this line_iter.
*/
- GPIOD_API line_iter& operator=(const line_iter& other) = default;
+ line_iter& operator=(const line_iter& other) = default;
/**
* @brief Move assignment operator.
* @param other Other line iterator.
* @return Reference to this line_iter.
*/
- GPIOD_API line_iter& operator=(line_iter&& other) = default;
+ line_iter& operator=(line_iter&& other) = default;
/**
* @brief Destructor.
*/
- GPIOD_API ~line_iter(void) = default;
+ ~line_iter(void) = default;
/**
* @brief Advance the iterator by one element.
* @return Reference to this iterator.
*/
- GPIOD_API line_iter& operator++(void);
+ line_iter& operator++(void);
/**
* @brief Dereference current element.
* @return Current GPIO line by reference.
*/
- GPIOD_API const line& operator*(void) const;
+ const line& operator*(void) const;
/**
* @brief Member access operator.
* @return Current GPIO line by pointer.
*/
- GPIOD_API const line* operator->(void) const;
+ const line* operator->(void) const;
/**
* @brief Check if this operator points to the same element.
* @return True if this iterator points to the same line_iter,
* false otherwise.
*/
- GPIOD_API bool operator==(const line_iter& rhs) const noexcept;
+ bool operator==(const line_iter& rhs) const noexcept;
/**
* @brief Check if this operator doesn't point to the same element.
* @return True if this iterator doesn't point to the same line_iter,
* false otherwise.
*/
- GPIOD_API bool operator!=(const line_iter& rhs) const noexcept;
+ bool operator!=(const line_iter& rhs) const noexcept;
private:
--- /dev/null
+/* SPDX-License-Identifier: LGPL-3.0-or-later */
+/* SPDX-FileCopyrightText: 2021 Bartosz Golaszewski <bgolaszewski@baylibre.com> */
+
+#ifndef __LIBGPIOD_GPIOD_CXX_INTERNAL_HPP__
+#define __LIBGPIOD_GPIOD_CXX_INTERNAL_HPP__
+
+#define GPIOD_CXX_API __attribute__((visibility("default")))
+
+#endif /* __LIBGPIOD_GPIOD_CXX_INTERNAL_HPP__ */
#include <gpiod.hpp>
#include <system_error>
+#include "internal.hpp"
+
namespace gpiod {
-line_iter begin(line_iter iter) noexcept
+GPIOD_CXX_API line_iter begin(line_iter iter) noexcept
{
return iter;
}
-line_iter end(const line_iter&) noexcept
+GPIOD_CXX_API line_iter end(const line_iter&) noexcept
{
return line_iter();
}
-line_iter::line_iter(const chip& owner)
+GPIOD_CXX_API line_iter::line_iter(const chip& owner)
: _m_current(owner.get_line(0))
{
}
-line_iter& line_iter::operator++(void)
+GPIOD_CXX_API line_iter& line_iter::operator++(void)
{
unsigned int offset = this->_m_current.offset() + 1;
chip owner = this->_m_current.get_chip();
return *this;
}
-const line& line_iter::operator*(void) const
+GPIOD_CXX_API const line& line_iter::operator*(void) const
{
return this->_m_current;
}
-const line* line_iter::operator->(void) const
+GPIOD_CXX_API const line* line_iter::operator->(void) const
{
return ::std::addressof(this->_m_current);
}
-bool line_iter::operator==(const line_iter& rhs) const noexcept
+GPIOD_CXX_API bool line_iter::operator==(const line_iter& rhs) const noexcept
{
return this->_m_current._m_line == rhs._m_current._m_line;
}
-bool line_iter::operator!=(const line_iter& rhs) const noexcept
+GPIOD_CXX_API bool line_iter::operator!=(const line_iter& rhs) const noexcept
{
return this->_m_current._m_line != rhs._m_current._m_line;
}
#include <map>
#include <system_error>
+#include "internal.hpp"
+
namespace gpiod {
namespace {
} /* namespace */
-line::line(void)
+GPIOD_CXX_API line::line(void)
: _m_line(nullptr),
_m_owner()
{
}
-line::line(::gpiod_line* line, const chip& owner)
+GPIOD_CXX_API line::line(::gpiod_line* line, const chip& owner)
: _m_line(line),
_m_owner(owner._m_chip)
{
}
-unsigned int line::offset(void) const
+GPIOD_CXX_API unsigned int line::offset(void) const
{
this->throw_if_null();
line::chip_guard lock_chip(*this);
return ::gpiod_line_offset(this->_m_line);
}
-::std::string line::name(void) const
+GPIOD_CXX_API ::std::string line::name(void) const
{
this->throw_if_null();
line::chip_guard lock_chip(*this);
return name ? ::std::string(name) : ::std::string();
}
-::std::string line::consumer(void) const
+GPIOD_CXX_API ::std::string line::consumer(void) const
{
this->throw_if_null();
line::chip_guard lock_chip(*this);
return consumer ? ::std::string(consumer) : ::std::string();
}
-int line::direction(void) const
+GPIOD_CXX_API int line::direction(void) const
{
this->throw_if_null();
line::chip_guard lock_chip(*this);
return dir == GPIOD_LINE_DIRECTION_INPUT ? DIRECTION_INPUT : DIRECTION_OUTPUT;
}
-bool line::is_active_low(void) const
+GPIOD_CXX_API bool line::is_active_low(void) const
{
this->throw_if_null();
line::chip_guard lock_chip(*this);
return ::gpiod_line_is_active_low(this->_m_line);
}
-int line::bias(void) const
+GPIOD_CXX_API int line::bias(void) const
{
this->throw_if_null();
line::chip_guard lock_chip(*this);
return bias_mapping.at(::gpiod_line_bias(this->_m_line));
}
-bool line::is_used(void) const
+GPIOD_CXX_API bool line::is_used(void) const
{
this->throw_if_null();
line::chip_guard lock_chip(*this);
return ::gpiod_line_is_used(this->_m_line);
}
-int line::drive(void) const
+GPIOD_CXX_API int line::drive(void) const
{
this->throw_if_null();
line::chip_guard lock_chip(*this);
return drive_mapping.at(::gpiod_line_drive(this->_m_line));
}
-void line::request(const line_request& config, int default_val) const
+GPIOD_CXX_API void line::request(const line_request& config, int default_val) const
{
this->throw_if_null();
bulk.request(config, { default_val });
}
-void line::release(void) const
+GPIOD_CXX_API void line::release(void) const
{
this->throw_if_null();
* polling for events on single lines directly.
*/
-int line::get_value(void) const
+GPIOD_CXX_API int line::get_value(void) const
{
this->throw_if_null();
return bulk.get_values()[0];
}
-void line::set_value(int val) const
+GPIOD_CXX_API void line::set_value(int val) const
{
this->throw_if_null();
bulk.set_values({ val });
}
-void line::set_config(int direction, ::std::bitset<32> flags,
- int value) const
+GPIOD_CXX_API void line::set_config(int direction, ::std::bitset<32> flags,
+ int value) const
{
this->throw_if_null();
bulk.set_config(direction, flags, { value });
}
-void line::set_flags(::std::bitset<32> flags) const
+GPIOD_CXX_API void line::set_flags(::std::bitset<32> flags) const
{
this->throw_if_null();
bulk.set_flags(flags);
}
-void line::set_direction_input() const
+GPIOD_CXX_API void line::set_direction_input() const
{
this->throw_if_null();
bulk.set_direction_input();
}
-void line::set_direction_output(int value) const
+GPIOD_CXX_API void line::set_direction_output(int value) const
{
this->throw_if_null();
bulk.set_direction_output({ value });
}
-bool line::event_wait(const ::std::chrono::nanoseconds& timeout) const
+GPIOD_CXX_API bool line::event_wait(const ::std::chrono::nanoseconds& timeout) const
{
this->throw_if_null();
return !!event_bulk;
}
-line_event line::make_line_event(const ::gpiod_line_event& event) const noexcept
+GPIOD_CXX_API line_event line::make_line_event(const ::gpiod_line_event& event) const noexcept
{
line_event ret;
return ret;
}
-line_event line::event_read(void) const
+GPIOD_CXX_API line_event line::event_read(void) const
{
this->throw_if_null();
line::chip_guard lock_chip(*this);
return this->make_line_event(event_buf);
}
-::std::vector<line_event> line::event_read_multiple(void) const
+GPIOD_CXX_API ::std::vector<line_event> line::event_read_multiple(void) const
{
this->throw_if_null();
line::chip_guard lock_chip(*this);
return events;
}
-int line::event_get_fd(void) const
+GPIOD_CXX_API int line::event_get_fd(void) const
{
this->throw_if_null();
line::chip_guard lock_chip(*this);
return ret;
}
-const chip line::get_chip(void) const
+GPIOD_CXX_API const chip line::get_chip(void) const
{
return chip(this->_m_owner);
}
-void line::reset(void)
+GPIOD_CXX_API void line::reset(void)
{
this->_m_line = nullptr;
this->_m_owner.reset();
}
-bool line::operator==(const line& rhs) const noexcept
+GPIOD_CXX_API bool line::operator==(const line& rhs) const noexcept
{
return this->_m_line == rhs._m_line;
}
-bool line::operator!=(const line& rhs) const noexcept
+GPIOD_CXX_API bool line::operator!=(const line& rhs) const noexcept
{
return this->_m_line != rhs._m_line;
}
-line::operator bool(void) const noexcept
+GPIOD_CXX_API line::operator bool(void) const noexcept
{
return this->_m_line != nullptr;
}
-bool line::operator!(void) const noexcept
+GPIOD_CXX_API bool line::operator!(void) const noexcept
{
return this->_m_line == nullptr;
}
-void line::throw_if_null(void) const
+GPIOD_CXX_API void line::throw_if_null(void) const
{
if (!this->_m_line)
throw ::std::logic_error("object not holding a GPIO line handle");
}
-line::chip_guard::chip_guard(const line& line)
+GPIOD_CXX_API line::chip_guard::chip_guard(const line& line)
: _m_chip(line._m_owner)
{
#include <map>
#include <system_error>
+#include "internal.hpp"
+
namespace gpiod {
-const ::std::bitset<32> line_request::FLAG_ACTIVE_LOW(GPIOD_BIT(0));
-const ::std::bitset<32> line_request::FLAG_OPEN_SOURCE(GPIOD_BIT(1));
-const ::std::bitset<32> line_request::FLAG_OPEN_DRAIN(GPIOD_BIT(2));
-const ::std::bitset<32> line_request::FLAG_BIAS_DISABLED(GPIOD_BIT(3));
-const ::std::bitset<32> line_request::FLAG_BIAS_PULL_DOWN(GPIOD_BIT(4));
-const ::std::bitset<32> line_request::FLAG_BIAS_PULL_UP(GPIOD_BIT(5));
+GPIOD_CXX_API const ::std::bitset<32> line_request::FLAG_ACTIVE_LOW(GPIOD_BIT(0));
+GPIOD_CXX_API const ::std::bitset<32> line_request::FLAG_OPEN_SOURCE(GPIOD_BIT(1));
+GPIOD_CXX_API const ::std::bitset<32> line_request::FLAG_OPEN_DRAIN(GPIOD_BIT(2));
+GPIOD_CXX_API const ::std::bitset<32> line_request::FLAG_BIAS_DISABLED(GPIOD_BIT(3));
+GPIOD_CXX_API const ::std::bitset<32> line_request::FLAG_BIAS_PULL_DOWN(GPIOD_BIT(4));
+GPIOD_CXX_API const ::std::bitset<32> line_request::FLAG_BIAS_PULL_UP(GPIOD_BIT(5));
namespace {
} /* namespace */
-const unsigned int line_bulk::MAX_LINES = 64;
+GPIOD_CXX_API const unsigned int line_bulk::MAX_LINES = 64;
-line_bulk::line_bulk(const ::std::vector<line>& lines)
+GPIOD_CXX_API line_bulk::line_bulk(const ::std::vector<line>& lines)
: _m_bulk()
{
this->_m_bulk.reserve(lines.size());
this->append(it);
}
-void line_bulk::append(const line& new_line)
+GPIOD_CXX_API void line_bulk::append(const line& new_line)
{
if (!new_line)
throw ::std::logic_error("line_bulk cannot hold empty line objects");
this->_m_bulk.push_back(new_line);
}
-line& line_bulk::get(unsigned int index)
+GPIOD_CXX_API line& line_bulk::get(unsigned int index)
{
return this->_m_bulk.at(index);
}
-line& line_bulk::operator[](unsigned int index)
+GPIOD_CXX_API line& line_bulk::operator[](unsigned int index)
{
return this->_m_bulk[index];
}
-unsigned int line_bulk::size(void) const noexcept
+GPIOD_CXX_API unsigned int line_bulk::size(void) const noexcept
{
return this->_m_bulk.size();
}
-bool line_bulk::empty(void) const noexcept
+GPIOD_CXX_API bool line_bulk::empty(void) const noexcept
{
return this->_m_bulk.empty();
}
-void line_bulk::clear(void)
+GPIOD_CXX_API void line_bulk::clear(void)
{
this->_m_bulk.clear();
}
-void line_bulk::request(const line_request& config, const ::std::vector<int> default_vals) const
+GPIOD_CXX_API void line_bulk::request(const line_request& config, const ::std::vector<int> default_vals) const
{
this->throw_if_empty();
line::chip_guard lock_chip(this->_m_bulk.front());
"error requesting GPIO lines");
}
-void line_bulk::release(void) const
+GPIOD_CXX_API void line_bulk::release(void) const
{
this->throw_if_empty();
line::chip_guard lock_chip(this->_m_bulk.front());
::gpiod_line_release_bulk(bulk.get());
}
-::std::vector<int> line_bulk::get_values(void) const
+GPIOD_CXX_API ::std::vector<int> line_bulk::get_values(void) const
{
this->throw_if_empty();
line::chip_guard lock_chip(this->_m_bulk.front());
return values;
}
-void line_bulk::set_values(const ::std::vector<int>& values) const
+GPIOD_CXX_API void line_bulk::set_values(const ::std::vector<int>& values) const
{
this->throw_if_empty();
line::chip_guard lock_chip(this->_m_bulk.front());
"error setting GPIO line values");
}
-void line_bulk::set_config(int direction, ::std::bitset<32> flags,
- const ::std::vector<int> values) const
+GPIOD_CXX_API void line_bulk::set_config(int direction, ::std::bitset<32> flags,
+ const ::std::vector<int> values) const
{
this->throw_if_empty();
line::chip_guard lock_chip(this->_m_bulk.front());
"error setting GPIO line config");
}
-void line_bulk::set_flags(::std::bitset<32> flags) const
+GPIOD_CXX_API void line_bulk::set_flags(::std::bitset<32> flags) const
{
this->throw_if_empty();
line::chip_guard lock_chip(this->_m_bulk.front());
"error setting GPIO line flags");
}
-void line_bulk::set_direction_input() const
+GPIOD_CXX_API void line_bulk::set_direction_input() const
{
this->throw_if_empty();
line::chip_guard lock_chip(this->_m_bulk.front());
"error setting GPIO line direction to input");
}
-void line_bulk::set_direction_output(const ::std::vector<int>& values) const
+GPIOD_CXX_API void line_bulk::set_direction_output(const ::std::vector<int>& values) const
{
this->throw_if_empty();
line::chip_guard lock_chip(this->_m_bulk.front());
"error setting GPIO line direction to output");
}
-line_bulk line_bulk::event_wait(const ::std::chrono::nanoseconds& timeout) const
+GPIOD_CXX_API line_bulk line_bulk::event_wait(const ::std::chrono::nanoseconds& timeout) const
{
this->throw_if_empty();
line::chip_guard lock_chip(this->_m_bulk.front());
return ret;
}
-line_bulk::operator bool(void) const noexcept
+GPIOD_CXX_API line_bulk::operator bool(void) const noexcept
{
return !this->_m_bulk.empty();
}
-bool line_bulk::operator!(void) const noexcept
+GPIOD_CXX_API bool line_bulk::operator!(void) const noexcept
{
return this->_m_bulk.empty();
}
-line_bulk::iterator::iterator(const ::std::vector<line>::iterator& it)
+GPIOD_CXX_API line_bulk::iterator::iterator(const ::std::vector<line>::iterator& it)
: _m_iter(it)
{
}
-line_bulk::iterator& line_bulk::iterator::operator++(void)
+GPIOD_CXX_API line_bulk::iterator& line_bulk::iterator::operator++(void)
{
this->_m_iter++;
return *this;
}
-const line& line_bulk::iterator::operator*(void) const
+GPIOD_CXX_API const line& line_bulk::iterator::operator*(void) const
{
return *this->_m_iter;
}
-const line* line_bulk::iterator::operator->(void) const
+GPIOD_CXX_API const line* line_bulk::iterator::operator->(void) const
{
return this->_m_iter.operator->();
}
-bool line_bulk::iterator::operator==(const iterator& rhs) const noexcept
+GPIOD_CXX_API bool line_bulk::iterator::operator==(const iterator& rhs) const noexcept
{
return this->_m_iter == rhs._m_iter;
}
-bool line_bulk::iterator::operator!=(const iterator& rhs) const noexcept
+GPIOD_CXX_API bool line_bulk::iterator::operator!=(const iterator& rhs) const noexcept
{
return this->_m_iter != rhs._m_iter;
}
-line_bulk::iterator line_bulk::begin(void) noexcept
+GPIOD_CXX_API line_bulk::iterator line_bulk::begin(void) noexcept
{
return line_bulk::iterator(this->_m_bulk.begin());
}
-line_bulk::iterator line_bulk::end(void) noexcept
+GPIOD_CXX_API line_bulk::iterator line_bulk::end(void) noexcept
{
return line_bulk::iterator(this->_m_bulk.end());
}
-void line_bulk::throw_if_empty(void) const
+GPIOD_CXX_API void line_bulk::throw_if_empty(void) const
{
if (this->_m_bulk.empty())
throw ::std::logic_error("line_bulk not holding any GPIO lines");
}
-line_bulk::line_bulk_ptr line_bulk::make_line_bulk_ptr(void) const
+GPIOD_CXX_API line_bulk::line_bulk_ptr line_bulk::make_line_bulk_ptr(void) const
{
line_bulk_ptr bulk(::gpiod_line_bulk_new(this->size()));
return bulk;
}
-line_bulk::line_bulk_ptr line_bulk::to_line_bulk(void) const
+GPIOD_CXX_API line_bulk::line_bulk_ptr line_bulk::to_line_bulk(void) const
{
line_bulk_ptr bulk = this->make_line_bulk_ptr();
return bulk;
}
-void line_bulk::line_bulk_deleter::operator()(::gpiod_line_bulk *bulk)
+GPIOD_CXX_API void line_bulk::line_bulk_deleter::operator()(::gpiod_line_bulk *bulk)
{
::gpiod_line_bulk_free(bulk);
}
* Commonly used utility macros.
*/
-/**
- * @brief Makes symbol visible.
- */
-#define GPIOD_API __attribute__((visibility("default")))
-
/**
* @brief Shift 1 by given offset.
* @param nr Bit position.
* @return True if the file exists and is a GPIO chip character device or a
* symbolic link to it.
*/
-bool gpiod_is_gpiochip_device(const char *path) GPIOD_API;
+bool gpiod_is_gpiochip_device(const char *path);
/**
* @brief Open a gpiochip by path.
* @param path Path to the gpiochip device file.
* @return GPIO chip handle or NULL if an error occurred.
*/
-struct gpiod_chip *gpiod_chip_open(const char *path) GPIOD_API;
+struct gpiod_chip *gpiod_chip_open(const char *path);
/**
* @brief Increase the refcount on this GPIO object.
* @param chip The GPIO chip object.
* @return Passed reference to the GPIO chip.
*/
-struct gpiod_chip *gpiod_chip_ref(struct gpiod_chip *chip) GPIOD_API;
+struct gpiod_chip *gpiod_chip_ref(struct gpiod_chip *chip);
/**
* @brief Decrease the refcount on this GPIO object. If the refcount reaches 0,
* close the chip device and free all associated resources.
* @param chip The GPIO chip object.
*/
-void gpiod_chip_unref(struct gpiod_chip *chip) GPIOD_API;
+void gpiod_chip_unref(struct gpiod_chip *chip);
/**
* @brief Get the GPIO chip name as represented in the kernel.
* @param chip The GPIO chip object.
* @return Pointer to a human-readable string containing the chip name.
*/
-const char *gpiod_chip_name(struct gpiod_chip *chip) GPIOD_API;
+const char *gpiod_chip_name(struct gpiod_chip *chip);
/**
* @brief Get the GPIO chip label as represented in the kernel.
* @param chip The GPIO chip object.
* @return Pointer to a human-readable string containing the chip label.
*/
-const char *gpiod_chip_label(struct gpiod_chip *chip) GPIOD_API;
+const char *gpiod_chip_label(struct gpiod_chip *chip);
/**
* @brief Get the number of GPIO lines exposed by this chip.
* @param chip The GPIO chip object.
* @return Number of GPIO lines.
*/
-unsigned int gpiod_chip_num_lines(struct gpiod_chip *chip) GPIOD_API;
+unsigned int gpiod_chip_num_lines(struct gpiod_chip *chip);
/**
* @brief Get the handle to the GPIO line at given offset.
* @return Pointer to the GPIO line handle or NULL if an error occured.
*/
struct gpiod_line *
-gpiod_chip_get_line(struct gpiod_chip *chip, unsigned int offset) GPIOD_API;
+gpiod_chip_get_line(struct gpiod_chip *chip, unsigned int offset);
/**
* @brief Retrieve a set of lines and store them in a line bulk object.
*/
struct gpiod_line_bulk *
gpiod_chip_get_lines(struct gpiod_chip *chip, unsigned int *offsets,
- unsigned int num_offsets) GPIOD_API;
+ unsigned int num_offsets);
/**
* @brief Retrieve all lines exposed by a chip and store them in a bulk object.
* @return New line bulk object or NULL on error.
*/
struct gpiod_line_bulk *
-gpiod_chip_get_all_lines(struct gpiod_chip *chip) GPIOD_API;
+gpiod_chip_get_all_lines(struct gpiod_chip *chip);
/**
* @brief Map a GPIO line's name to its offset within the chip.
* @return Offset of the line within the chip or -1 if a line with given name
* is not exposed by the chip.
*/
-int gpiod_chip_find_line(struct gpiod_chip *chip, const char *name) GPIOD_API;
+int gpiod_chip_find_line(struct gpiod_chip *chip, const char *name);
/**
* @}
* @param max_lines Maximum number of lines this object can hold.
* @return New line bulk object or NULL on error.
*/
-struct gpiod_line_bulk *gpiod_line_bulk_new(unsigned int max_lines) GPIOD_API;
+struct gpiod_line_bulk *gpiod_line_bulk_new(unsigned int max_lines);
/**
* @brief Reset a bulk object. Remove all lines and set size to 0.
* @param bulk Bulk object to reset.
*/
-void gpiod_line_bulk_reset(struct gpiod_line_bulk *bulk) GPIOD_API;
+void gpiod_line_bulk_reset(struct gpiod_line_bulk *bulk);
/**
* @brief Release all resources allocated for this bulk object.
* @param bulk Bulk object to free.
*/
-void gpiod_line_bulk_free(struct gpiod_line_bulk *bulk) GPIOD_API;
+void gpiod_line_bulk_free(struct gpiod_line_bulk *bulk);
/**
* @brief Add a single line to a GPIO bulk object.
* the other lines already held by this object.
*/
int gpiod_line_bulk_add_line(struct gpiod_line_bulk *bulk,
- struct gpiod_line *line) GPIOD_API;
+ struct gpiod_line *line);
/**
* @brief Retrieve the line handle from a line bulk object at given index.
* the number of lines this bulk can hold.
*/
struct gpiod_line *
-gpiod_line_bulk_get_line(struct gpiod_line_bulk *bulk,
- unsigned int index) GPIOD_API;
+gpiod_line_bulk_get_line(struct gpiod_line_bulk *bulk, unsigned int index);
/**
* @brief Retrieve the number of GPIO lines held by this line bulk object.
* @param bulk Line bulk object.
* @return Number of lines held by this line bulk.
*/
-unsigned int gpiod_line_bulk_num_lines(struct gpiod_line_bulk *bulk) GPIOD_API;
+unsigned int gpiod_line_bulk_num_lines(struct gpiod_line_bulk *bulk);
/**
* @brief Values returned by the callback passed to
*/
void gpiod_line_bulk_foreach_line(struct gpiod_line_bulk *bulk,
gpiod_line_bulk_foreach_cb func,
- void *data) GPIOD_API;
+ void *data);
/**
* @}
* @param line GPIO line object.
* @return Line offset.
*/
-unsigned int gpiod_line_offset(struct gpiod_line *line) GPIOD_API;
+unsigned int gpiod_line_offset(struct gpiod_line *line);
/**
* @brief Read the GPIO line name.
* routine returns a pointer to a null-terminated string or NULL if
* the line is unnamed.
*/
-const char *gpiod_line_name(struct gpiod_line *line) GPIOD_API;
+const char *gpiod_line_name(struct gpiod_line *line);
/**
* @brief Read the GPIO line consumer name.
* kernel. This routine returns a pointer to a null-terminated string
* or NULL if the line is not used.
*/
-const char *gpiod_line_consumer(struct gpiod_line *line) GPIOD_API;
+const char *gpiod_line_consumer(struct gpiod_line *line);
/**
* @brief Read the GPIO line direction setting.
* @param line GPIO line object.
* @return Returns GPIOD_LINE_DIRECTION_INPUT or GPIOD_LINE_DIRECTION_OUTPUT.
*/
-int gpiod_line_direction(struct gpiod_line *line) GPIOD_API;
+int gpiod_line_direction(struct gpiod_line *line);
/**
* @brief Check if the signal of this line is inverted.
* @param line GPIO line object.
* @return True if this line is "active-low", false otherwise.
*/
-bool gpiod_line_is_active_low(struct gpiod_line *line) GPIOD_API;
+bool gpiod_line_is_active_low(struct gpiod_line *line);
/**
* @brief Read the GPIO line bias setting.
* @return Returns GPIOD_LINE_BIAS_PULL_UP, GPIOD_LINE_BIAS_PULL_DOWN,
* GPIOD_LINE_BIAS_DISABLE or GPIOD_LINE_BIAS_UNKNOWN.
*/
-int gpiod_line_bias(struct gpiod_line *line) GPIOD_API;
+int gpiod_line_bias(struct gpiod_line *line);
/**
* @brief Check if the line is currently in use.
* requested by another process or hogged by the kernel. It only matters that
* the line is used and we can't request it.
*/
-bool gpiod_line_is_used(struct gpiod_line *line) GPIOD_API;
+bool gpiod_line_is_used(struct gpiod_line *line);
/**
* @brief Read the GPIO line drive setting.
* @return Returns GPIOD_LINE_DRIVE_PUSH_PULL, GPIOD_LINE_DRIVE_OPEN_DRAIN or
* GPIOD_LINE_DRIVE_OPEN_SOURCE.
*/
-int gpiod_line_drive(struct gpiod_line *line) GPIOD_API;
+int gpiod_line_drive(struct gpiod_line *line);
/**
* @brief Get the handle to the GPIO chip controlling this line.
* @param line The GPIO line object.
* @return Pointer to the GPIO chip handle controlling this line.
*/
-struct gpiod_chip *gpiod_line_get_chip(struct gpiod_line *line) GPIOD_API;
+struct gpiod_chip *gpiod_line_get_chip(struct gpiod_line *line);
/**
* @}
*/
int gpiod_line_request(struct gpiod_line *line,
const struct gpiod_line_request_config *config,
- int default_val) GPIOD_API;
+ int default_val);
/**
* @brief Reserve a single line, set the direction to input.
* @param consumer Name of the consumer.
* @return 0 if the line was properly reserved, -1 on failure.
*/
-int gpiod_line_request_input(struct gpiod_line *line,
- const char *consumer) GPIOD_API;
+int gpiod_line_request_input(struct gpiod_line *line, const char *consumer);
/**
* @brief Reserve a single line, set the direction to output.
* @return 0 if the line was properly reserved, -1 on failure.
*/
int gpiod_line_request_output(struct gpiod_line *line,
- const char *consumer, int default_val) GPIOD_API;
+ const char *consumer, int default_val);
/**
* @brief Request rising edge event notifications on a single line.
* @return 0 if the operation succeeds, -1 on failure.
*/
int gpiod_line_request_rising_edge_events(struct gpiod_line *line,
- const char *consumer) GPIOD_API;
+ const char *consumer);
/**
* @brief Request falling edge event notifications on a single line.
* @return 0 if the operation succeeds, -1 on failure.
*/
int gpiod_line_request_falling_edge_events(struct gpiod_line *line,
- const char *consumer) GPIOD_API;
+ const char *consumer);
/**
* @brief Request all event type notifications on a single line.
* @return 0 if the operation succeeds, -1 on failure.
*/
int gpiod_line_request_both_edges_events(struct gpiod_line *line,
- const char *consumer) GPIOD_API;
+ const char *consumer);
/**
* @brief Reserve a single line, set the direction to input.
* @return 0 if the line was properly reserved, -1 on failure.
*/
int gpiod_line_request_input_flags(struct gpiod_line *line,
- const char *consumer, int flags) GPIOD_API;
+ const char *consumer, int flags);
/**
* @brief Reserve a single line, set the direction to output.
*/
int gpiod_line_request_output_flags(struct gpiod_line *line,
const char *consumer, int flags,
- int default_val) GPIOD_API;
+ int default_val);
/**
* @brief Request rising edge event notifications on a single line.
*/
int gpiod_line_request_rising_edge_events_flags(struct gpiod_line *line,
const char *consumer,
- int flags) GPIOD_API;
+ int flags);
/**
* @brief Request falling edge event notifications on a single line.
*/
int gpiod_line_request_falling_edge_events_flags(struct gpiod_line *line,
const char *consumer,
- int flags) GPIOD_API;
+ int flags);
/**
* @brief Request all event type notifications on a single line.
*/
int gpiod_line_request_both_edges_events_flags(struct gpiod_line *line,
const char *consumer,
- int flags) GPIOD_API;
+ int flags);
/**
* @brief Reserve a set of GPIO lines.
*/
int gpiod_line_request_bulk(struct gpiod_line_bulk *bulk,
const struct gpiod_line_request_config *config,
- const int *default_vals) GPIOD_API;
+ const int *default_vals);
/**
* @brief Reserve a set of GPIO lines, set the direction to input.
* @return 0 if the lines were properly reserved, -1 on failure.
*/
int gpiod_line_request_bulk_input(struct gpiod_line_bulk *bulk,
- const char *consumer) GPIOD_API;
+ const char *consumer);
/**
* @brief Reserve a set of GPIO lines, set the direction to output.
*/
int gpiod_line_request_bulk_output(struct gpiod_line_bulk *bulk,
const char *consumer,
- const int *default_vals) GPIOD_API;
+ const int *default_vals);
/**
* @brief Request rising edge event notifications on a set of lines.
* @return 0 if the operation succeeds, -1 on failure.
*/
int gpiod_line_request_bulk_rising_edge_events(struct gpiod_line_bulk *bulk,
- const char *consumer) GPIOD_API;
+ const char *consumer);
/**
* @brief Request falling edge event notifications on a set of lines.
* @return 0 if the operation succeeds, -1 on failure.
*/
int gpiod_line_request_bulk_falling_edge_events(struct gpiod_line_bulk *bulk,
- const char *consumer) GPIOD_API;
+ const char *consumer);
/**
* @brief Request all event type notifications on a set of lines.
* @return 0 if the operation succeeds, -1 on failure.
*/
int gpiod_line_request_bulk_both_edges_events(struct gpiod_line_bulk *bulk,
- const char *consumer) GPIOD_API;
+ const char *consumer);
/**
* @brief Reserve a set of GPIO lines, set the direction to input.
* @return 0 if the lines were properly reserved, -1 on failure.
*/
int gpiod_line_request_bulk_input_flags(struct gpiod_line_bulk *bulk,
- const char *consumer,
- int flags) GPIOD_API;
+ const char *consumer, int flags);
/**
* @brief Reserve a set of GPIO lines, set the direction to output.
*/
int gpiod_line_request_bulk_output_flags(struct gpiod_line_bulk *bulk,
const char *consumer, int flags,
- const int *default_vals) GPIOD_API;
+ const int *default_vals);
/**
* @brief Request rising edge event notifications on a set of lines.
*/
int gpiod_line_request_bulk_rising_edge_events_flags(
struct gpiod_line_bulk *bulk,
- const char *consumer,
- int flags) GPIOD_API;
+ const char *consumer, int flags);
/**
* @brief Request falling edge event notifications on a set of lines.
*/
int gpiod_line_request_bulk_falling_edge_events_flags(
struct gpiod_line_bulk *bulk,
- const char *consumer,
- int flags) GPIOD_API;
+ const char *consumer, int flags);
/**
* @brief Request all event type notifications on a set of lines.
*/
int gpiod_line_request_bulk_both_edges_events_flags(
struct gpiod_line_bulk *bulk,
- const char *consumer,
- int flags) GPIOD_API;
+ const char *consumer, int flags);
/**
* @brief Release a previously reserved line.
* @param line GPIO line object.
*/
-void gpiod_line_release(struct gpiod_line *line) GPIOD_API;
+void gpiod_line_release(struct gpiod_line *line);
/**
* @brief Release a set of previously reserved lines.
* If the lines were not previously requested together, the behavior is
* undefined.
*/
-void gpiod_line_release_bulk(struct gpiod_line_bulk *bulk) GPIOD_API;
+void gpiod_line_release_bulk(struct gpiod_line_bulk *bulk);
/**
* @}
* @return 0 or 1 if the operation succeeds. On error this routine returns -1
* and sets the last error number.
*/
-int gpiod_line_get_value(struct gpiod_line *line) GPIOD_API;
+int gpiod_line_get_value(struct gpiod_line *line);
/**
* @brief Read current values of a set of GPIO lines.
* the same order, the lines are added to line_bulk. If the lines were not
* previously requested together, the behavior is undefined.
*/
-int gpiod_line_get_value_bulk(struct gpiod_line_bulk *bulk,
- int *values) GPIOD_API;
+int gpiod_line_get_value_bulk(struct gpiod_line_bulk *bulk, int *values);
/**
* @brief Set the value of a single GPIO line.
* @return 0 is the operation succeeds. In case of an error this routine
* returns -1 and sets the last error number.
*/
-int gpiod_line_set_value(struct gpiod_line *line, int value) GPIOD_API;
+int gpiod_line_set_value(struct gpiod_line *line, int value);
/**
* @brief Set the values of a set of GPIO lines.
* If the lines were not previously requested together, the behavior is
* undefined.
*/
-int gpiod_line_set_value_bulk(struct gpiod_line_bulk *bulk,
- const int *values) GPIOD_API;
+int gpiod_line_set_value_bulk(struct gpiod_line_bulk *bulk, const int *values);
/**
* @}
* returns -1 and sets the last error number.
*/
int gpiod_line_set_config(struct gpiod_line *line, int direction,
- int flags, int value) GPIOD_API;
+ int flags, int value);
/**
* @brief Update the configuration of a set of GPIO lines.
* undefined.
*/
int gpiod_line_set_config_bulk(struct gpiod_line_bulk *bulk,
- int direction, int flags,
- const int *values) GPIOD_API;
+ int direction, int flags, const int *values);
/**
* @return 0 is the operation succeeds. In case of an error this routine
* returns -1 and sets the last error number.
*/
-int gpiod_line_set_flags(struct gpiod_line *line, int flags) GPIOD_API;
+int gpiod_line_set_flags(struct gpiod_line *line, int flags);
/**
* @brief Update the configuration flags of a set of GPIO lines.
* If the lines were not previously requested together, the behavior is
* undefined.
*/
-int gpiod_line_set_flags_bulk(struct gpiod_line_bulk *bulk,
- int flags) GPIOD_API;
+int gpiod_line_set_flags_bulk(struct gpiod_line_bulk *bulk, int flags);
/**
* @brief Set the direction of a single GPIO line to input.
* @return 0 is the operation succeeds. In case of an error this routine
* returns -1 and sets the last error number.
*/
-int gpiod_line_set_direction_input(struct gpiod_line *line) GPIOD_API;
+int gpiod_line_set_direction_input(struct gpiod_line *line);
/**
* @brief Set the direction of a set of GPIO lines to input.
* undefined.
*/
int
-gpiod_line_set_direction_input_bulk(struct gpiod_line_bulk *bulk) GPIOD_API;
+gpiod_line_set_direction_input_bulk(struct gpiod_line_bulk *bulk);
/**
* @brief Set the direction of a single GPIO line to output.
* @return 0 is the operation succeeds. In case of an error this routine
* returns -1 and sets the last error number.
*/
-int gpiod_line_set_direction_output(struct gpiod_line *line,
- int value) GPIOD_API;
+int gpiod_line_set_direction_output(struct gpiod_line *line, int value);
/**
* @brief Set the direction of a set of GPIO lines to output.
* undefined.
*/
int gpiod_line_set_direction_output_bulk(struct gpiod_line_bulk *bulk,
- const int *values) GPIOD_API;
+ const int *values);
/**
* @}
* occurred.
*/
int gpiod_line_event_wait(struct gpiod_line *line,
- const struct timespec *timeout) GPIOD_API;
+ const struct timespec *timeout);
/**
* @brief Wait for events on a set of lines.
*/
int gpiod_line_event_wait_bulk(struct gpiod_line_bulk *bulk,
const struct timespec *timeout,
- struct gpiod_line_bulk *event_bulk) GPIOD_API;
+ struct gpiod_line_bulk *event_bulk);
/**
* @brief Read next pending event from the GPIO line.
* @note This function will block if no event was queued for this line.
*/
int gpiod_line_event_read(struct gpiod_line *line,
- struct gpiod_line_event *event) GPIOD_API;
+ struct gpiod_line_event *event);
/**
* @brief Read up to a certain number of events from the GPIO line.
*/
int gpiod_line_event_read_multiple(struct gpiod_line *line,
struct gpiod_line_event *events,
- unsigned int num_events) GPIOD_API;
+ unsigned int num_events);
/**
* @brief Get the event file descriptor.
* Users may want to poll the event file descriptor on their own. This routine
* allows to access it.
*/
-int gpiod_line_event_get_fd(struct gpiod_line *line) GPIOD_API;
+int gpiod_line_event_get_fd(struct gpiod_line *line);
/**
* @brief Read the last GPIO event directly from a file descriptor.
* directly read the event data from it using this routine. This function
* translates the kernel representation of the event to the libgpiod format.
*/
-int gpiod_line_event_read_fd(int fd, struct gpiod_line_event *event) GPIOD_API;
+int gpiod_line_event_read_fd(int fd, struct gpiod_line_event *event);
/**
* @brief Read up to a certain number of events directly from a file descriptor.
* failure -1 is returned.
*/
int gpiod_line_event_read_fd_multiple(int fd, struct gpiod_line_event *events,
- unsigned int num_events) GPIOD_API;
+ unsigned int num_events);
/**
* @}
* @brief Get the API version of the library as a human-readable string.
* @return Human-readable string containing the library version.
*/
-const char *gpiod_version_string(void) GPIOD_API;
+const char *gpiod_version_string(void);
/**
* @}
# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <bartekgola@gmail.com>
lib_LTLIBRARIES = libgpiod.la
-libgpiod_la_SOURCES = core.c helpers.c misc.c uapi/gpio.h
+libgpiod_la_SOURCES = core.c helpers.c internal.h misc.c uapi/gpio.h
libgpiod_la_CFLAGS = -Wall -Wextra -g -std=gnu89
libgpiod_la_CFLAGS += -fvisibility=hidden -I$(top_srcdir)/include/
libgpiod_la_CFLAGS += -include $(top_builddir)/config.h
#include <sys/types.h>
#include <unistd.h>
+#include "internal.h"
#include "uapi/gpio.h"
#define LINE_REQUEST_MAX_LINES 64
#define BULK_SINGLE_LINE_INIT(line) \
{ 1, 1, { (line) } }
-struct gpiod_line_bulk *gpiod_line_bulk_new(unsigned int max_lines)
+GPIOD_API struct gpiod_line_bulk *gpiod_line_bulk_new(unsigned int max_lines)
{
struct gpiod_line_bulk *bulk;
size_t size;
return bulk;
}
-void gpiod_line_bulk_reset(struct gpiod_line_bulk *bulk)
+GPIOD_API void gpiod_line_bulk_reset(struct gpiod_line_bulk *bulk)
{
bulk->num_lines = 0;
memset(bulk->lines, 0, bulk->max_lines * sizeof(struct line *));
}
-void gpiod_line_bulk_free(struct gpiod_line_bulk *bulk)
+GPIOD_API void gpiod_line_bulk_free(struct gpiod_line_bulk *bulk)
{
free(bulk);
}
-int gpiod_line_bulk_add_line(struct gpiod_line_bulk *bulk,
- struct gpiod_line *line)
+GPIOD_API int gpiod_line_bulk_add_line(struct gpiod_line_bulk *bulk,
+ struct gpiod_line *line)
{
if (bulk->num_lines == bulk->max_lines) {
errno = EINVAL;
return 0;
}
-struct gpiod_line *
+GPIOD_API struct gpiod_line *
gpiod_line_bulk_get_line(struct gpiod_line_bulk *bulk, unsigned int index)
{
if (index >= bulk->num_lines) {
return bulk->lines[index];
}
-unsigned int gpiod_line_bulk_num_lines(struct gpiod_line_bulk *bulk)
+GPIOD_API unsigned int gpiod_line_bulk_num_lines(struct gpiod_line_bulk *bulk)
{
return bulk->num_lines;
}
-void gpiod_line_bulk_foreach_line(struct gpiod_line_bulk *bulk,
- gpiod_line_bulk_foreach_cb func, void *data)
+GPIOD_API void gpiod_line_bulk_foreach_line(struct gpiod_line_bulk *bulk,
+ gpiod_line_bulk_foreach_cb func,
+ void *data)
{
unsigned int index;
int ret;
(index) < (bulk)->num_lines; \
(index)++, (line) = (bulk)->lines[(index)])
-bool gpiod_is_gpiochip_device(const char *path)
+GPIOD_API bool gpiod_is_gpiochip_device(const char *path)
{
char *name, *realname, *sysfsp, sysfsdev[16], devstr[16];
struct stat statbuf;
return ret;
}
-struct gpiod_chip *gpiod_chip_open(const char *path)
+GPIOD_API struct gpiod_chip *gpiod_chip_open(const char *path)
{
struct gpiochip_info info;
struct gpiod_chip *chip;
return NULL;
}
-struct gpiod_chip *gpiod_chip_ref(struct gpiod_chip *chip)
+GPIOD_API struct gpiod_chip *gpiod_chip_ref(struct gpiod_chip *chip)
{
chip->refcount++;
return chip;
}
-void gpiod_chip_unref(struct gpiod_chip *chip)
+GPIOD_API void gpiod_chip_unref(struct gpiod_chip *chip)
{
struct gpiod_line *line;
unsigned int i;
free(chip);
}
-const char *gpiod_chip_name(struct gpiod_chip *chip)
+GPIOD_API const char *gpiod_chip_name(struct gpiod_chip *chip)
{
return chip->name;
}
-const char *gpiod_chip_label(struct gpiod_chip *chip)
+GPIOD_API const char *gpiod_chip_label(struct gpiod_chip *chip)
{
return chip->label;
}
-unsigned int gpiod_chip_num_lines(struct gpiod_chip *chip)
+GPIOD_API unsigned int gpiod_chip_num_lines(struct gpiod_chip *chip)
{
return chip->num_lines;
}
static int line_update(struct gpiod_line *line);
-struct gpiod_line *
+GPIOD_API struct gpiod_line *
gpiod_chip_get_line(struct gpiod_chip *chip, unsigned int offset)
{
struct gpiod_line *line;
return line->fd_handle->fd;
}
-struct gpiod_chip *gpiod_line_get_chip(struct gpiod_line *line)
+GPIOD_API struct gpiod_chip *gpiod_line_get_chip(struct gpiod_line *line)
{
return line->chip;
}
-unsigned int gpiod_line_offset(struct gpiod_line *line)
+GPIOD_API unsigned int gpiod_line_offset(struct gpiod_line *line)
{
return line->offset;
}
-const char *gpiod_line_name(struct gpiod_line *line)
+GPIOD_API const char *gpiod_line_name(struct gpiod_line *line)
{
return line->name[0] == '\0' ? NULL : line->name;
}
-const char *gpiod_line_consumer(struct gpiod_line *line)
+GPIOD_API const char *gpiod_line_consumer(struct gpiod_line *line)
{
return line->consumer[0] == '\0' ? NULL : line->consumer;
}
-int gpiod_line_direction(struct gpiod_line *line)
+GPIOD_API int gpiod_line_direction(struct gpiod_line *line)
{
return line->direction;
}
-bool gpiod_line_is_active_low(struct gpiod_line *line)
+GPIOD_API bool gpiod_line_is_active_low(struct gpiod_line *line)
{
return line->active_low;
}
-int gpiod_line_bias(struct gpiod_line *line)
+GPIOD_API int gpiod_line_bias(struct gpiod_line *line)
{
if (line->info_flags & GPIOLINE_FLAG_BIAS_DISABLE)
return GPIOD_LINE_BIAS_DISABLED;
return GPIOD_LINE_BIAS_UNKNOWN;
}
-bool gpiod_line_is_used(struct gpiod_line *line)
+GPIOD_API bool gpiod_line_is_used(struct gpiod_line *line)
{
return line->info_flags & GPIOLINE_FLAG_KERNEL;
}
-int gpiod_line_drive(struct gpiod_line *line)
+GPIOD_API int gpiod_line_drive(struct gpiod_line *line)
{
if (line->info_flags & GPIOLINE_FLAG_OPEN_DRAIN)
return GPIOD_LINE_DRIVE_OPEN_DRAIN;
return 0;
}
-int gpiod_line_request(struct gpiod_line *line,
- const struct gpiod_line_request_config *config,
- int default_val)
+GPIOD_API int gpiod_line_request(struct gpiod_line *line,
+ const struct gpiod_line_request_config *config,
+ int default_val)
{
struct gpiod_line_bulk bulk = BULK_SINGLE_LINE_INIT(line);
request == GPIOD_LINE_REQUEST_EVENT_BOTH_EDGES;
}
-int gpiod_line_request_bulk(struct gpiod_line_bulk *bulk,
- const struct gpiod_line_request_config *config,
- const int *vals)
+GPIOD_API int
+gpiod_line_request_bulk(struct gpiod_line_bulk *bulk,
+ const struct gpiod_line_request_config *config,
+ const int *vals)
{
if (line_request_is_direction(config->request_type))
return line_request_values(bulk, config, vals);
return -1;
}
-void gpiod_line_release(struct gpiod_line *line)
+GPIOD_API void gpiod_line_release(struct gpiod_line *line)
{
struct gpiod_line_bulk bulk = BULK_SINGLE_LINE_INIT(line);
gpiod_line_release_bulk(&bulk);
}
-void gpiod_line_release_bulk(struct gpiod_line_bulk *bulk)
+GPIOD_API void gpiod_line_release_bulk(struct gpiod_line_bulk *bulk)
{
struct gpiod_line *line;
unsigned int idx;
}
}
-int gpiod_line_get_value(struct gpiod_line *line)
+GPIOD_API int gpiod_line_get_value(struct gpiod_line *line)
{
struct gpiod_line_bulk bulk = BULK_SINGLE_LINE_INIT(line);
int rv, value;
return value;
}
-int gpiod_line_get_value_bulk(struct gpiod_line_bulk *bulk, int *values)
+GPIOD_API int gpiod_line_get_value_bulk(struct gpiod_line_bulk *bulk,
+ int *values)
{
struct gpio_v2_line_values lv;
struct gpiod_line *line;
return 0;
}
-int gpiod_line_set_value(struct gpiod_line *line, int value)
+GPIOD_API int gpiod_line_set_value(struct gpiod_line *line, int value)
{
struct gpiod_line_bulk bulk = BULK_SINGLE_LINE_INIT(line);
return gpiod_line_set_value_bulk(&bulk, &value);
}
-int gpiod_line_set_value_bulk(struct gpiod_line_bulk *bulk, const int *values)
+GPIOD_API int gpiod_line_set_value_bulk(struct gpiod_line_bulk *bulk,
+ const int *values)
{
struct gpio_v2_line_values lv;
struct gpiod_line *line;
return 0;
}
-int gpiod_line_set_config(struct gpiod_line *line, int direction,
- int flags, int value)
+GPIOD_API int gpiod_line_set_config(struct gpiod_line *line, int direction,
+ int flags, int value)
{
struct gpiod_line_bulk bulk = BULK_SINGLE_LINE_INIT(line);
return gpiod_line_set_config_bulk(&bulk, direction, flags, &value);
}
-int gpiod_line_set_config_bulk(struct gpiod_line_bulk *bulk,
- int direction, int flags,
- const int *values)
+GPIOD_API int gpiod_line_set_config_bulk(struct gpiod_line_bulk *bulk,
+ int direction, int flags,
+ const int *values)
{
struct gpio_v2_line_config hcfg;
struct gpiod_line *line;
return 0;
}
-int gpiod_line_set_flags(struct gpiod_line *line, int flags)
+GPIOD_API int gpiod_line_set_flags(struct gpiod_line *line, int flags)
{
struct gpiod_line_bulk bulk = BULK_SINGLE_LINE_INIT(line);
return gpiod_line_set_flags_bulk(&bulk, flags);
}
-int gpiod_line_set_flags_bulk(struct gpiod_line_bulk *bulk, int flags)
+GPIOD_API int gpiod_line_set_flags_bulk(struct gpiod_line_bulk *bulk, int flags)
{
struct gpiod_line *line;
int values[LINE_REQUEST_MAX_LINES];
flags, values);
}
-int gpiod_line_set_direction_input(struct gpiod_line *line)
+GPIOD_API int gpiod_line_set_direction_input(struct gpiod_line *line)
{
return gpiod_line_set_config(line, GPIOD_LINE_REQUEST_DIRECTION_INPUT,
line->req_flags, 0);
}
-int gpiod_line_set_direction_input_bulk(struct gpiod_line_bulk *bulk)
+GPIOD_API int gpiod_line_set_direction_input_bulk(struct gpiod_line_bulk *bulk)
{
struct gpiod_line *line;
line->req_flags, NULL);
}
-int gpiod_line_set_direction_output(struct gpiod_line *line, int value)
+GPIOD_API int gpiod_line_set_direction_output(struct gpiod_line *line,
+ int value)
{
return gpiod_line_set_config(line, GPIOD_LINE_REQUEST_DIRECTION_OUTPUT,
line->req_flags, value);
}
-int gpiod_line_set_direction_output_bulk(struct gpiod_line_bulk *bulk,
- const int *values)
+GPIOD_API int gpiod_line_set_direction_output_bulk(struct gpiod_line_bulk *bulk,
+ const int *values)
{
struct gpiod_line *line;
line->req_flags, values);
}
-int gpiod_line_event_wait(struct gpiod_line *line,
- const struct timespec *timeout)
+GPIOD_API int gpiod_line_event_wait(struct gpiod_line *line,
+ const struct timespec *timeout)
{
struct gpiod_line_bulk bulk = BULK_SINGLE_LINE_INIT(line);
return gpiod_line_event_wait_bulk(&bulk, timeout, NULL);
}
-int gpiod_line_event_wait_bulk(struct gpiod_line_bulk *bulk,
- const struct timespec *timeout,
- struct gpiod_line_bulk *event_bulk)
+GPIOD_API int gpiod_line_event_wait_bulk(struct gpiod_line_bulk *bulk,
+ const struct timespec *timeout,
+ struct gpiod_line_bulk *event_bulk)
{
struct pollfd fds[LINE_REQUEST_MAX_LINES];
unsigned int off, num_lines;
return 1;
}
-int gpiod_line_event_read(struct gpiod_line *line,
- struct gpiod_line_event *event)
+GPIOD_API int gpiod_line_event_read(struct gpiod_line *line,
+ struct gpiod_line_event *event)
{
int ret;
return 0;
}
-int gpiod_line_event_read_multiple(struct gpiod_line *line,
- struct gpiod_line_event *events,
- unsigned int num_events)
+GPIOD_API int gpiod_line_event_read_multiple(struct gpiod_line *line,
+ struct gpiod_line_event *events,
+ unsigned int num_events)
{
int fd;
return gpiod_line_event_read_fd_multiple(fd, events, num_events);
}
-int gpiod_line_event_get_fd(struct gpiod_line *line)
+GPIOD_API int gpiod_line_event_get_fd(struct gpiod_line *line)
{
if (line->state != LINE_REQUESTED_EVENTS) {
errno = EPERM;
return line_get_fd(line);
}
-int gpiod_line_event_read_fd(int fd, struct gpiod_line_event *event)
+GPIOD_API int gpiod_line_event_read_fd(int fd, struct gpiod_line_event *event)
{
int ret;
return 0;
}
-int gpiod_line_event_read_fd_multiple(int fd, struct gpiod_line_event *events,
- unsigned int num_events)
+GPIOD_API int gpiod_line_event_read_fd_multiple(int fd,
+ struct gpiod_line_event *events,
+ unsigned int num_events)
{
/*
* 16 is the maximum number of events the kernel can store in the FIFO
#include <stdio.h>
#include <string.h>
-struct gpiod_line_bulk *
+#include "internal.h"
+
+GPIOD_API struct gpiod_line_bulk *
gpiod_chip_get_lines(struct gpiod_chip *chip,
unsigned int *offsets, unsigned int num_offsets)
{
return bulk;
}
-struct gpiod_line_bulk *gpiod_chip_get_all_lines(struct gpiod_chip *chip)
+GPIOD_API struct gpiod_line_bulk *
+gpiod_chip_get_all_lines(struct gpiod_chip *chip)
{
struct gpiod_line_bulk *bulk;
struct gpiod_line *line;
return bulk;
}
-int gpiod_chip_find_line(struct gpiod_chip *chip, const char *name)
+GPIOD_API int gpiod_chip_find_line(struct gpiod_chip *chip, const char *name)
{
unsigned int offset, num_lines;
struct gpiod_line *line;
return -1;
}
-int gpiod_line_request_input(struct gpiod_line *line, const char *consumer)
+GPIOD_API int gpiod_line_request_input(struct gpiod_line *line,
+ const char *consumer)
{
struct gpiod_line_request_config config = {
.consumer = consumer,
return gpiod_line_request(line, &config, 0);
}
-int gpiod_line_request_output(struct gpiod_line *line,
- const char *consumer, int default_val)
+GPIOD_API int gpiod_line_request_output(struct gpiod_line *line,
+ const char *consumer, int default_val)
{
struct gpiod_line_request_config config = {
.consumer = consumer,
return gpiod_line_request(line, &config, default_val);
}
-int gpiod_line_request_input_flags(struct gpiod_line *line,
- const char *consumer, int flags)
+GPIOD_API int gpiod_line_request_input_flags(struct gpiod_line *line,
+ const char *consumer, int flags)
{
struct gpiod_line_request_config config = {
.consumer = consumer,
return gpiod_line_request(line, &config, 0);
}
-int gpiod_line_request_output_flags(struct gpiod_line *line,
- const char *consumer, int flags,
- int default_val)
+GPIOD_API int gpiod_line_request_output_flags(struct gpiod_line *line,
+ const char *consumer, int flags,
+ int default_val)
{
struct gpiod_line_request_config config = {
.consumer = consumer,
return gpiod_line_request(line, &config, 0);
}
-int gpiod_line_request_rising_edge_events(struct gpiod_line *line,
- const char *consumer)
+GPIOD_API int gpiod_line_request_rising_edge_events(struct gpiod_line *line,
+ const char *consumer)
{
return line_event_request_type(line, consumer, 0,
GPIOD_LINE_REQUEST_EVENT_RISING_EDGE);
}
-int gpiod_line_request_falling_edge_events(struct gpiod_line *line,
- const char *consumer)
+GPIOD_API int gpiod_line_request_falling_edge_events(struct gpiod_line *line,
+ const char *consumer)
{
return line_event_request_type(line, consumer, 0,
GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE);
}
-int gpiod_line_request_both_edges_events(struct gpiod_line *line,
- const char *consumer)
+GPIOD_API int gpiod_line_request_both_edges_events(struct gpiod_line *line,
+ const char *consumer)
{
return line_event_request_type(line, consumer, 0,
GPIOD_LINE_REQUEST_EVENT_BOTH_EDGES);
}
-int gpiod_line_request_rising_edge_events_flags(struct gpiod_line *line,
- const char *consumer,
- int flags)
+GPIOD_API int
+gpiod_line_request_rising_edge_events_flags(struct gpiod_line *line,
+ const char *consumer,
+ int flags)
{
return line_event_request_type(line, consumer, flags,
GPIOD_LINE_REQUEST_EVENT_RISING_EDGE);
}
-int gpiod_line_request_falling_edge_events_flags(struct gpiod_line *line,
- const char *consumer,
- int flags)
+GPIOD_API int
+gpiod_line_request_falling_edge_events_flags(struct gpiod_line *line,
+ const char *consumer,
+ int flags)
{
return line_event_request_type(line, consumer, flags,
GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE);
}
-int gpiod_line_request_both_edges_events_flags(struct gpiod_line *line,
- const char *consumer, int flags)
+GPIOD_API int
+gpiod_line_request_both_edges_events_flags(struct gpiod_line *line,
+ const char *consumer, int flags)
{
return line_event_request_type(line, consumer, flags,
GPIOD_LINE_REQUEST_EVENT_BOTH_EDGES);
}
-int gpiod_line_request_bulk_input(struct gpiod_line_bulk *bulk,
- const char *consumer)
+GPIOD_API int gpiod_line_request_bulk_input(struct gpiod_line_bulk *bulk,
+ const char *consumer)
{
struct gpiod_line_request_config config = {
.consumer = consumer,
return gpiod_line_request_bulk(bulk, &config, 0);
}
-int gpiod_line_request_bulk_output(struct gpiod_line_bulk *bulk,
- const char *consumer,
- const int *default_vals)
+GPIOD_API int gpiod_line_request_bulk_output(struct gpiod_line_bulk *bulk,
+ const char *consumer,
+ const int *default_vals)
{
struct gpiod_line_request_config config = {
.consumer = consumer,
return gpiod_line_request_bulk(bulk, &config, 0);
}
-int gpiod_line_request_bulk_rising_edge_events(struct gpiod_line_bulk *bulk,
- const char *consumer)
+GPIOD_API int
+gpiod_line_request_bulk_rising_edge_events(struct gpiod_line_bulk *bulk,
+ const char *consumer)
{
return line_event_request_type_bulk(bulk, consumer, 0,
GPIOD_LINE_REQUEST_EVENT_RISING_EDGE);
}
-int gpiod_line_request_bulk_falling_edge_events(struct gpiod_line_bulk *bulk,
- const char *consumer)
+GPIOD_API int
+gpiod_line_request_bulk_falling_edge_events(struct gpiod_line_bulk *bulk,
+ const char *consumer)
{
return line_event_request_type_bulk(bulk, consumer, 0,
GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE);
}
-int gpiod_line_request_bulk_both_edges_events(struct gpiod_line_bulk *bulk,
- const char *consumer)
+GPIOD_API int
+gpiod_line_request_bulk_both_edges_events(struct gpiod_line_bulk *bulk,
+ const char *consumer)
{
return line_event_request_type_bulk(bulk, consumer, 0,
GPIOD_LINE_REQUEST_EVENT_BOTH_EDGES);
}
-int gpiod_line_request_bulk_input_flags(struct gpiod_line_bulk *bulk,
- const char *consumer, int flags)
+GPIOD_API int gpiod_line_request_bulk_input_flags(struct gpiod_line_bulk *bulk,
+ const char *consumer,
+ int flags)
{
struct gpiod_line_request_config config = {
.consumer = consumer,
return gpiod_line_request_bulk(bulk, &config, 0);
}
-int gpiod_line_request_bulk_output_flags(struct gpiod_line_bulk *bulk,
- const char *consumer, int flags,
- const int *default_vals)
+GPIOD_API int gpiod_line_request_bulk_output_flags(struct gpiod_line_bulk *bulk,
+ const char *consumer,
+ int flags,
+ const int *default_vals)
{
struct gpiod_line_request_config config = {
.consumer = consumer,
return gpiod_line_request_bulk(bulk, &config, default_vals);
}
-int gpiod_line_request_bulk_rising_edge_events_flags(
+GPIOD_API int gpiod_line_request_bulk_rising_edge_events_flags(
struct gpiod_line_bulk *bulk,
const char *consumer, int flags)
{
GPIOD_LINE_REQUEST_EVENT_RISING_EDGE);
}
-int gpiod_line_request_bulk_falling_edge_events_flags(
+GPIOD_API int gpiod_line_request_bulk_falling_edge_events_flags(
struct gpiod_line_bulk *bulk,
const char *consumer, int flags)
{
GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE);
}
-int gpiod_line_request_bulk_both_edges_events_flags(
+GPIOD_API int gpiod_line_request_bulk_both_edges_events_flags(
struct gpiod_line_bulk *bulk,
const char *consumer, int flags)
{
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/* SPDX-FileCopyrightText: 2021 Bartosz Golaszewski <bgolaszewski@baylibre.com> */
+
+#ifndef __LIBGPIOD_GPIOD_INTERNAL_H__
+#define __LIBGPIOD_GPIOD_INTERNAL_H__
+
+/* For internal library use only. */
+
+#define GPIOD_API __attribute__((visibility("default")))
+
+#endif /* __LIBGPIOD_GPIOD_INTERNAL_H__ */
#include <gpiod.h>
-const char *gpiod_version_string(void)
+#include "internal.h"
+
+GPIOD_API const char *gpiod_version_string(void)
{
return GPIOD_VERSION_STR;
}