#ifndef __PERIPHERAL_GDBUS_GPIO_H__
#define __PERIPHERAL_GDBUS_GPIO_H__
-void gpio_proxy_init(void);
-void gpio_proxy_deinit(void);
-
int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio);
int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio);
#ifndef __PERIPHERAL_GDBUS_I2C_H__
#define __PERIPHERAL_GDBUS_I2C_H__
-void i2c_proxy_init(void);
-void i2c_proxy_deinit(void);
-
int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address);
int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c);
#ifndef __PERIPHERAL_GDBUS_PWM_H__
#define __PERIPHERAL_GDBUS_PWM_H__
-void pwm_proxy_init(void);
-void pwm_proxy_deinit(void);
-
int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin);
int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm);
#ifndef __PERIPHERAL_GDBUS_SPI_H_
#define __PERIPHERAL_GDBUS_SPI_H_
-void spi_proxy_init(void);
-void spi_proxy_deinit();
-
int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs);
int peripheral_gdbus_spi_close(peripheral_spi_h spi);
#ifndef __PERIPHERAL_GDBUS_UART_H_
#define __PERIPHERAL_GDBUS_UART_H_
-void uart_proxy_init(void);
-void uart_proxy_deinit();
-
int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port);
int peripheral_gdbus_uart_close(peripheral_uart_h uart);
static PeripheralIoGdbusGpio *gpio_proxy = NULL;
-void gpio_proxy_init(void)
+static int __gpio_proxy_init()
{
GError *error = NULL;
if (gpio_proxy != NULL) {
+ _E("Gpio proxy is already created");
g_object_ref(gpio_proxy);
- return;
+ return PERIPHERAL_ERROR_NONE;
}
gpio_proxy = peripheral_io_gdbus_gpio_proxy_new_for_bus_sync(
PERIPHERAL_GDBUS_GPIO_PATH,
NULL,
&error);
+
if (gpio_proxy == NULL) {
- _E("Can not create gpio proxy : %s", error->message);
+ _E("Failed to create gpio proxy : %s", error->message);
g_error_free(error);
- return;
+ return PERIPHERAL_ERROR_UNKNOWN;
}
+
+ return PERIPHERAL_ERROR_NONE;
}
-void gpio_proxy_deinit()
+static void __gpio_proxy_deinit()
{
- if (gpio_proxy) {
+ if (gpio_proxy != NULL) {
g_object_unref(gpio_proxy);
if (!G_IS_OBJECT(gpio_proxy))
gpio_proxy = NULL;
gint32 ret = PERIPHERAL_ERROR_NONE;
GUnixFDList *fd_list = NULL;
- if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+ ret = __gpio_proxy_init();
+ if (ret != PERIPHERAL_ERROR_NONE)
+ return ret;
if (peripheral_io_gdbus_gpio_call_open_sync(
gpio_proxy,
GError *error = NULL;
peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+ if (gpio_proxy == NULL) {
+ _E("Can't try to gpio close because gpio proxy is NULL.");
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
if (peripheral_io_gdbus_gpio_call_close_sync(
gpio_proxy,
return PERIPHERAL_ERROR_UNKNOWN;
}
+ __gpio_proxy_deinit();
+
return ret;
}
\ No newline at end of file
static PeripheralIoGdbusI2c *i2c_proxy = NULL;
-void i2c_proxy_init(void)
+static int __i2c_proxy_init()
{
GError *error = NULL;
if (i2c_proxy != NULL) {
+ _E("I2c proxy is already created");
g_object_ref(i2c_proxy);
- return;
+ return PERIPHERAL_ERROR_NONE;
}
i2c_proxy = peripheral_io_gdbus_i2c_proxy_new_for_bus_sync(
PERIPHERAL_GDBUS_I2C_PATH,
NULL,
&error);
+
+ if (i2c_proxy == NULL) {
+ _E("Failed to create i2c proxy : %s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return PERIPHERAL_ERROR_NONE;
}
-void i2c_proxy_deinit()
+static void __i2c_proxy_deinit()
{
if (i2c_proxy) {
g_object_unref(i2c_proxy);
peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
GUnixFDList *fd_list = NULL;
- if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+ ret = __i2c_proxy_init();
+ if (ret != PERIPHERAL_ERROR_NONE)
+ return ret;
if (peripheral_io_gdbus_i2c_call_open_sync(
i2c_proxy,
GError *error = NULL;
peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+ if (i2c_proxy == NULL) {
+ _E("Can't try to i2c close because i2c proxy is NULL.");
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
if (peripheral_io_gdbus_i2c_call_close_sync(
i2c_proxy,
return PERIPHERAL_ERROR_UNKNOWN;
}
+ __i2c_proxy_deinit();
+
return ret;
}
\ No newline at end of file
static PeripheralIoGdbusPwm *pwm_proxy = NULL;
-void pwm_proxy_init(void)
+static int __pwm_proxy_init()
{
GError *error = NULL;
if (pwm_proxy != NULL) {
+ _E("Pwm proxy is already created");
g_object_ref(pwm_proxy);
- return;
+ return PERIPHERAL_ERROR_NONE;
}
pwm_proxy = peripheral_io_gdbus_pwm_proxy_new_for_bus_sync(
PERIPHERAL_GDBUS_PWM_PATH,
NULL,
&error);
+
+ if (pwm_proxy == NULL) {
+ _E("Failed to create pwm proxy : %s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return PERIPHERAL_ERROR_NONE;
}
-void pwm_proxy_deinit()
+static void __pwm_proxy_deinit()
{
if (pwm_proxy) {
g_object_unref(pwm_proxy);
peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
GUnixFDList *fd_list = NULL;
- if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+ ret = __pwm_proxy_init();
+ if (ret != PERIPHERAL_ERROR_NONE)
+ return ret;
if (peripheral_io_gdbus_pwm_call_open_sync(
pwm_proxy,
GError *error = NULL;
peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+ if (pwm_proxy == NULL) {
+ _E("Can't try to pwm close because pwm proxy is NULL.");
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
if (peripheral_io_gdbus_pwm_call_close_sync(
pwm_proxy,
return PERIPHERAL_ERROR_UNKNOWN;
}
+ __pwm_proxy_deinit();
+
return ret;
}
\ No newline at end of file
static PeripheralIoGdbusSpi *spi_proxy = NULL;
-void spi_proxy_init(void)
+static int __spi_proxy_init()
{
GError *error = NULL;
if (spi_proxy != NULL) {
+ _E("Spi proxy is already created");
g_object_ref(spi_proxy);
- return;
+ return PERIPHERAL_ERROR_NONE;
}
spi_proxy = peripheral_io_gdbus_spi_proxy_new_for_bus_sync(
PERIPHERAL_GDBUS_SPI_PATH,
NULL,
&error);
+
+ if (spi_proxy == NULL) {
+ _E("Failed to create spi proxy : %s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return PERIPHERAL_ERROR_NONE;
}
-void spi_proxy_deinit()
+static void __spi_proxy_deinit()
{
if (spi_proxy) {
g_object_unref(spi_proxy);
peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
GUnixFDList *fd_list = NULL;
- if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+ ret = __spi_proxy_init();
+ if (ret != PERIPHERAL_ERROR_NONE)
+ return ret;
if (peripheral_io_gdbus_spi_call_open_sync(
spi_proxy,
GError *error = NULL;
peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+ if (spi_proxy == NULL) {
+ _E("Can't try to spi close because spi proxy is NULL.");
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
if (peripheral_io_gdbus_spi_call_close_sync(
spi_proxy,
return PERIPHERAL_ERROR_UNKNOWN;
}
+ __spi_proxy_deinit();
+
return ret;
}
\ No newline at end of file
static PeripheralIoGdbusUart *uart_proxy = NULL;
-void uart_proxy_init(void)
+static int __uart_proxy_init()
{
GError *error = NULL;
if (uart_proxy != NULL) {
+ _E("Uart proxy is already created");
g_object_ref(uart_proxy);
- return;
+ return PERIPHERAL_ERROR_NONE;
}
uart_proxy = peripheral_io_gdbus_uart_proxy_new_for_bus_sync(
PERIPHERAL_GDBUS_UART_PATH,
NULL,
&error);
+
+ if (uart_proxy == NULL) {
+ _E("Failed to create uart proxy : %s", error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return PERIPHERAL_ERROR_NONE;
}
-void uart_proxy_deinit()
+static void __uart_proxy_deinit()
{
if (uart_proxy) {
g_object_unref(uart_proxy);
peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
GUnixFDList *fd_list = NULL;
- if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+ ret = __uart_proxy_init();
+ if (ret != PERIPHERAL_ERROR_NONE)
+ return ret;
if (peripheral_io_gdbus_uart_call_open_sync(
uart_proxy,
GError *error = NULL;
peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
+ if (uart_proxy == NULL) {
+ _E("Can't try to uart close because uart proxy is NULL.");
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
if (peripheral_io_gdbus_uart_call_close_sync(
uart_proxy,
uart->handle,
return PERIPHERAL_ERROR_UNKNOWN;
}
+ __uart_proxy_deinit();
+
return ret;
}
\ No newline at end of file
}
handle->pin = gpio_pin;
- gpio_proxy_init();
-
ret = peripheral_gdbus_gpio_open(handle);
if (ret != PERIPHERAL_ERROR_NONE) {
ret = peripheral_gdbus_gpio_close(gpio);
if (ret != PERIPHERAL_ERROR_NONE)
_E("Failed to close the gpio pin, ret : %d", ret);
- gpio_proxy_deinit();
free(gpio);
gpio = NULL;
return ret;
}
-
/**
* @brief Sets the edge mode of the gpio pin.
*/
return PERIPHERAL_ERROR_OUT_OF_MEMORY;
}
- i2c_proxy_init();
-
ret = peripheral_gdbus_i2c_open(handle, bus, address);
if (ret != PERIPHERAL_ERROR_NONE) {
ret = peripheral_gdbus_i2c_close(i2c);
if (ret != PERIPHERAL_ERROR_NONE)
_E("Failed to close i2c communcation, ret : %d", ret);
- i2c_proxy_deinit();
free(i2c);
i2c = NULL;
return PERIPHERAL_ERROR_OUT_OF_MEMORY;
}
- pwm_proxy_init();
-
ret = peripheral_gdbus_pwm_open(handle, chip, pin);
if (ret != PERIPHERAL_ERROR_NONE) {
if ((ret = peripheral_gdbus_pwm_close(pwm)) < 0)
_E("Failed to close PWM chip, continuing anyway, ret : %d", ret);
- pwm_proxy_deinit();
free(pwm);
return ret;
return PERIPHERAL_ERROR_OUT_OF_MEMORY;
}
- spi_proxy_init();
-
ret = peripheral_gdbus_spi_open(handle, bus, cs);
if (ret != PERIPHERAL_ERROR_NONE) {
if (ret < PERIPHERAL_ERROR_NONE)
_E("Failed to close SPI device, continuing anyway, ret : %d", ret);
- spi_proxy_deinit();
free(spi);
return ret;
return PERIPHERAL_ERROR_OUT_OF_MEMORY;
}
- uart_proxy_init();
-
ret = peripheral_gdbus_uart_open(handle, port);
if (ret != PERIPHERAL_ERROR_NONE) {
ret = peripheral_gdbus_uart_close(uart);
if (ret < PERIPHERAL_ERROR_NONE)
_E("Failed to close uart communication, continuing anyway, ret : %d", ret);
- uart_proxy_deinit();
free(uart);
uart = NULL;