Private
Public Access
2
0

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:
Jan Kiszka
2020-11-27 07:26:50 +01:00
committed by Tom Ingleby
parent 954b17ded4
commit 551486ffff
9 changed files with 105 additions and 1 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}
/**

View File

@@ -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

View File

@@ -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;
}
/**

View File

@@ -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

View File

@@ -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;
}
/**

View File

@@ -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;
}
/**

View File

@@ -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;
}
/**