api: Add explicit close methods to classes
This is needed for bindings to languages which perform implicit and lazy object cleanups. The explicit close methods allow to release resources when they are no longer required, permitting deterministic reuse. One example is node-red-node-intel-gpio which will use the new calls on node closing. Fixes #1044. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
@@ -76,8 +76,19 @@ class Aio
|
||||
*/
|
||||
~Aio()
|
||||
{
|
||||
if (m_aio != NULL) {
|
||||
mraa_aio_close(m_aio);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Closes AIO explicitly, prior to implicit closing on object destruction
|
||||
*/
|
||||
void
|
||||
close()
|
||||
{
|
||||
mraa_aio_close(m_aio);
|
||||
m_aio = NULL;
|
||||
}
|
||||
/**
|
||||
* Read a value from the AIO pin. By default mraa will shift
|
||||
* the raw value up or down to a 10 bit value.
|
||||
|
||||
@@ -144,8 +144,19 @@ class Gpio
|
||||
*/
|
||||
~Gpio()
|
||||
{
|
||||
if (m_gpio != NULL) {
|
||||
mraa_gpio_close(m_gpio);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Closes Gpio explicitly, prior to implicit closing on object destruction
|
||||
*/
|
||||
void
|
||||
close()
|
||||
{
|
||||
mraa_gpio_close(m_gpio);
|
||||
m_gpio = NULL;
|
||||
}
|
||||
/**
|
||||
* Set the edge mode for ISR
|
||||
*
|
||||
|
||||
@@ -84,8 +84,20 @@ class I2c
|
||||
*/
|
||||
~I2c()
|
||||
{
|
||||
if (m_i2c != NULL) {
|
||||
mraa_i2c_stop(m_i2c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes I2c explicitly, prior to implicit closing on object destruction
|
||||
*/
|
||||
void
|
||||
close()
|
||||
{
|
||||
mraa_i2c_stop(m_i2c);
|
||||
m_i2c = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the i2c Frequency for communication. Your board may not support
|
||||
|
||||
@@ -131,9 +131,20 @@ class Iio
|
||||
*/
|
||||
~Iio()
|
||||
{
|
||||
if (m_iio != NULL) {
|
||||
mraa_iio_close(m_iio);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes Iio explicitly, prior to implicit closing on object destruction
|
||||
*/
|
||||
void
|
||||
close()
|
||||
{
|
||||
mraa_iio_close(m_iio);
|
||||
m_iio = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get device name
|
||||
|
||||
@@ -90,8 +90,20 @@ class Led
|
||||
*/
|
||||
~Led()
|
||||
{
|
||||
if (m_led != NULL) {
|
||||
mraa_led_close(m_led);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Closes LED explicitly, prior to implicit closing on object destruction
|
||||
*/
|
||||
void
|
||||
close()
|
||||
{
|
||||
mraa_led_close(m_led);
|
||||
m_led = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set LED brightness value
|
||||
|
||||
@@ -87,8 +87,19 @@ class Pwm
|
||||
*/
|
||||
~Pwm()
|
||||
{
|
||||
if (m_pwm != NULL) {
|
||||
mraa_pwm_close(m_pwm);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Closes Pwm explicitly, prior to implicit closing on object destruction
|
||||
*/
|
||||
void
|
||||
close()
|
||||
{
|
||||
mraa_pwm_close(m_pwm);
|
||||
m_pwm = NULL;
|
||||
}
|
||||
/**
|
||||
* Set the output duty-cycle percentage, as a float
|
||||
*
|
||||
|
||||
@@ -106,8 +106,20 @@ class Spi
|
||||
*/
|
||||
~Spi()
|
||||
{
|
||||
if (m_spi != NULL) {
|
||||
mraa_spi_stop(m_spi);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes Spi explicitly, prior to implicit closing on object destruction
|
||||
*/
|
||||
void
|
||||
close()
|
||||
{
|
||||
mraa_spi_stop(m_spi);
|
||||
m_spi = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the SPI device mode. see spidev0-3
|
||||
|
||||
@@ -96,8 +96,20 @@ class Uart
|
||||
*/
|
||||
~Uart()
|
||||
{
|
||||
if (m_uart != NULL) {
|
||||
mraa_uart_stop(m_uart);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Closes Uart explicitly, prior to implicit closing on object destruction
|
||||
*/
|
||||
void
|
||||
close()
|
||||
{
|
||||
mraa_uart_stop(m_uart);
|
||||
m_uart = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string with tty device path within Linux
|
||||
|
||||
@@ -96,8 +96,20 @@ class UartOW
|
||||
*/
|
||||
~UartOW()
|
||||
{
|
||||
if (m_uart != NULL) {
|
||||
mraa_uart_ow_stop(m_uart);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Closes UartOW explicitly, prior to implicit closing on object destruction
|
||||
*/
|
||||
void
|
||||
close()
|
||||
{
|
||||
mraa_uart_ow_stop(m_uart);
|
||||
m_uart = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string with tty device path within Linux
|
||||
|
||||
Reference in New Issue
Block a user