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:
@@ -75,8 +75,19 @@ class Aio
|
||||
* Aio destructor
|
||||
*/
|
||||
~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
|
||||
|
||||
@@ -143,8 +143,19 @@ class Gpio
|
||||
* the owner
|
||||
*/
|
||||
~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
|
||||
|
||||
@@ -83,8 +83,20 @@ class I2c
|
||||
* slaves.
|
||||
*/
|
||||
~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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -131,9 +131,20 @@ class Iio
|
||||
*/
|
||||
~Iio()
|
||||
{
|
||||
mraa_iio_close(m_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
|
||||
|
||||
@@ -89,8 +89,20 @@ class Led
|
||||
* LED object destructor
|
||||
*/
|
||||
~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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -86,8 +86,19 @@ class Pwm
|
||||
* Pwm destructor
|
||||
*/
|
||||
~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
|
||||
|
||||
@@ -105,8 +105,20 @@ class Spi
|
||||
* Closes spi bus
|
||||
*/
|
||||
~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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -95,8 +95,20 @@ class Uart
|
||||
* Uart destructor
|
||||
*/
|
||||
~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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -95,8 +95,20 @@ class UartOW
|
||||
* Uart destructor
|
||||
*/
|
||||
~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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user