-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mraa: Add patch to enable explicit cleanup of resources
Enables proper node-red node teardown. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
- Loading branch information
1 parent
6ffa9e2
commit 633a77e
Showing
5 changed files
with
265 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
250 changes: 250 additions & 0 deletions
250
recipes-app/mraa/files/0004-api-Add-explicit-close-methods-to-classes.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
From 28b3c1966212b9497d99681c331ec0ae483c9814 Mon Sep 17 00:00:00 2001 | ||
From: Jan Kiszka <jan.kiszka@siemens.com> | ||
Date: Fri, 27 Nov 2020 07:26:50 +0100 | ||
Subject: [PATCH 4/4] 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. | ||
|
||
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> | ||
--- | ||
api/mraa/aio.hpp | 11 +++++++++++ | ||
api/mraa/gpio.hpp | 11 +++++++++++ | ||
api/mraa/i2c.hpp | 12 ++++++++++++ | ||
api/mraa/iio.hpp | 13 ++++++++++++- | ||
api/mraa/led.hpp | 12 ++++++++++++ | ||
api/mraa/pwm.hpp | 11 +++++++++++ | ||
api/mraa/spi.hpp | 12 ++++++++++++ | ||
api/mraa/uart.hpp | 12 ++++++++++++ | ||
api/mraa/uart_ow.hpp | 12 ++++++++++++ | ||
9 files changed, 105 insertions(+), 1 deletion(-) | ||
|
||
diff --git a/api/mraa/aio.hpp b/api/mraa/aio.hpp | ||
index 75c45bf..4e0272e 100644 | ||
--- a/api/mraa/aio.hpp | ||
+++ b/api/mraa/aio.hpp | ||
@@ -73,8 +73,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 | ||
diff --git a/api/mraa/gpio.hpp b/api/mraa/gpio.hpp | ||
index 909ca43..2b5d798 100644 | ||
--- a/api/mraa/gpio.hpp | ||
+++ b/api/mraa/gpio.hpp | ||
@@ -141,8 +141,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 | ||
diff --git a/api/mraa/i2c.hpp b/api/mraa/i2c.hpp | ||
index e0ea945..c666d42 100644 | ||
--- a/api/mraa/i2c.hpp | ||
+++ b/api/mraa/i2c.hpp | ||
@@ -81,8 +81,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; | ||
} | ||
|
||
/** | ||
diff --git a/api/mraa/iio.hpp b/api/mraa/iio.hpp | ||
index ec3090f..a0051fa 100644 | ||
--- a/api/mraa/iio.hpp | ||
+++ b/api/mraa/iio.hpp | ||
@@ -129,9 +129,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 | ||
diff --git a/api/mraa/led.hpp b/api/mraa/led.hpp | ||
index dcbc37a..316198a 100644 | ||
--- a/api/mraa/led.hpp | ||
+++ b/api/mraa/led.hpp | ||
@@ -87,8 +87,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; | ||
} | ||
|
||
/** | ||
diff --git a/api/mraa/pwm.hpp b/api/mraa/pwm.hpp | ||
index 494541b..f25661d 100644 | ||
--- a/api/mraa/pwm.hpp | ||
+++ b/api/mraa/pwm.hpp | ||
@@ -84,8 +84,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 | ||
diff --git a/api/mraa/spi.hpp b/api/mraa/spi.hpp | ||
index 855d389..339f4b0 100644 | ||
--- a/api/mraa/spi.hpp | ||
+++ b/api/mraa/spi.hpp | ||
@@ -103,8 +103,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; | ||
} | ||
|
||
/** | ||
diff --git a/api/mraa/uart.hpp b/api/mraa/uart.hpp | ||
index c7b217e..4a1bad4 100644 | ||
--- a/api/mraa/uart.hpp | ||
+++ b/api/mraa/uart.hpp | ||
@@ -93,8 +93,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; | ||
} | ||
|
||
/** | ||
diff --git a/api/mraa/uart_ow.hpp b/api/mraa/uart_ow.hpp | ||
index 2d7b459..222f6fb 100644 | ||
--- a/api/mraa/uart_ow.hpp | ||
+++ b/api/mraa/uart_ow.hpp | ||
@@ -93,8 +93,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; | ||
} | ||
|
||
/** | ||
-- | ||
2.26.2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters