gdbus: refactor gdbus proxy functions 34/160134/5
authorSegwon <segwon.han@samsung.com>
Tue, 14 Nov 2017 13:13:29 +0000 (22:13 +0900)
committerSegwon <segwon.han@samsung.com>
Wed, 15 Nov 2017 06:12:38 +0000 (15:12 +0900)
 - changed to static
 - proxy init function has been modified to return error.

Change-Id: I220d66e31d19c4cd7e27caa18f2c5cd2cba19b00
Signed-off-by: Segwon <segwon.han@samsung.com>
15 files changed:
include/gdbus/peripheral_gdbus_gpio.h
include/gdbus/peripheral_gdbus_i2c.h
include/gdbus/peripheral_gdbus_pwm.h
include/gdbus/peripheral_gdbus_spi.h
include/gdbus/peripheral_gdbus_uart.h
src/gdbus/peripheral_gdbus_gpio.c
src/gdbus/peripheral_gdbus_i2c.c
src/gdbus/peripheral_gdbus_pwm.c
src/gdbus/peripheral_gdbus_spi.c
src/gdbus/peripheral_gdbus_uart.c
src/peripheral_gpio.c
src/peripheral_i2c.c
src/peripheral_pwm.c
src/peripheral_spi.c
src/peripheral_uart.c

index f9e35e6..3fd5307 100644 (file)
@@ -17,9 +17,6 @@
 #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);
 
index 30604c7..0670442 100644 (file)
@@ -17,9 +17,6 @@
 #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);
 
index 0ce6159..148e938 100644 (file)
@@ -17,9 +17,6 @@
 #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);
 
index d6be9b5..8a6ac61 100644 (file)
@@ -16,9 +16,6 @@
 #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);
 
index d19440c..175452c 100644 (file)
@@ -16,9 +16,6 @@
 #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);
 
index 17a7f2f..ca5badd 100644 (file)
 
 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(
@@ -46,16 +47,19 @@ void gpio_proxy_init(void)
                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;
@@ -68,7 +72,9 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio)
        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,
@@ -115,7 +121,10 @@ int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio)
        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,
@@ -128,5 +137,7 @@ int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio)
                return PERIPHERAL_ERROR_UNKNOWN;
        }
 
+       __gpio_proxy_deinit();
+
        return ret;
 }
\ No newline at end of file
index 63fda68..b10b10f 100644 (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(
@@ -44,9 +45,17 @@ void i2c_proxy_init(void)
                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);
@@ -61,7 +70,9 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address)
        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,
@@ -95,7 +106,10 @@ int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c)
        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,
@@ -108,5 +122,7 @@ int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c)
                return PERIPHERAL_ERROR_UNKNOWN;
        }
 
+       __i2c_proxy_deinit();
+
        return ret;
 }
\ No newline at end of file
index f512e2c..3279d15 100644 (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(
@@ -47,9 +48,17 @@ void pwm_proxy_init(void)
                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);
@@ -64,7 +73,9 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin)
        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,
@@ -119,7 +130,10 @@ int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm)
        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,
@@ -132,5 +146,7 @@ int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm)
                return PERIPHERAL_ERROR_UNKNOWN;
        }
 
+       __pwm_proxy_deinit();
+
        return ret;
 }
\ No newline at end of file
index e286f40..80e267a 100644 (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(
@@ -44,9 +45,17 @@ void spi_proxy_init(void)
                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);
@@ -61,7 +70,9 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs)
        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,
@@ -95,7 +106,10 @@ int peripheral_gdbus_spi_close(peripheral_spi_h spi)
        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,
@@ -108,5 +122,7 @@ int peripheral_gdbus_spi_close(peripheral_spi_h spi)
                return PERIPHERAL_ERROR_UNKNOWN;
        }
 
+       __spi_proxy_deinit();
+
        return ret;
 }
\ No newline at end of file
index 16111dd..99620b6 100644 (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(
@@ -44,9 +45,17 @@ void uart_proxy_init(void)
                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);
@@ -61,7 +70,9 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port)
        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,
@@ -94,8 +105,10 @@ int peripheral_gdbus_uart_close(peripheral_uart_h uart)
        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,
@@ -107,5 +120,7 @@ int peripheral_gdbus_uart_close(peripheral_uart_h uart)
                return PERIPHERAL_ERROR_UNKNOWN;
        }
 
+       __uart_proxy_deinit();
+
        return ret;
 }
\ No newline at end of file
index a66cbaa..6a03a5a 100644 (file)
@@ -69,8 +69,6 @@ int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio)
        }
        handle->pin = gpio_pin;
 
-       gpio_proxy_init();
-
        ret = peripheral_gdbus_gpio_open(handle);
 
        if (ret != PERIPHERAL_ERROR_NONE) {
@@ -99,7 +97,6 @@ int peripheral_gpio_close(peripheral_gpio_h gpio)
        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;
@@ -124,7 +121,6 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct
        return ret;
 }
 
-
 /**
  * @brief Sets the edge mode of the gpio pin.
  */
index 60e0c59..d729356 100644 (file)
@@ -74,8 +74,6 @@ int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c)
                return PERIPHERAL_ERROR_OUT_OF_MEMORY;
        }
 
-       i2c_proxy_init();
-
        ret = peripheral_gdbus_i2c_open(handle, bus, address);
 
        if (ret != PERIPHERAL_ERROR_NONE) {
@@ -98,7 +96,6 @@ int peripheral_i2c_close(peripheral_i2c_h i2c)
        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;
index 1329bf1..e21bcbb 100644 (file)
@@ -66,8 +66,6 @@ int peripheral_pwm_open(int chip, int pin, peripheral_pwm_h *pwm)
                return PERIPHERAL_ERROR_OUT_OF_MEMORY;
        }
 
-       pwm_proxy_init();
-
        ret = peripheral_gdbus_pwm_open(handle, chip, pin);
 
        if (ret != PERIPHERAL_ERROR_NONE) {
@@ -90,7 +88,6 @@ int peripheral_pwm_close(peripheral_pwm_h pwm)
        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;
index b25dee4..68e9761 100644 (file)
@@ -66,8 +66,6 @@ int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi)
                return PERIPHERAL_ERROR_OUT_OF_MEMORY;
        }
 
-       spi_proxy_init();
-
        ret = peripheral_gdbus_spi_open(handle, bus, cs);
 
        if (ret != PERIPHERAL_ERROR_NONE) {
@@ -91,7 +89,6 @@ int peripheral_spi_close(peripheral_spi_h spi)
        if (ret < PERIPHERAL_ERROR_NONE)
                _E("Failed to close SPI device, continuing anyway, ret : %d", ret);
 
-       spi_proxy_deinit();
        free(spi);
 
        return ret;
index 70d711a..ad58c0c 100644 (file)
@@ -67,8 +67,6 @@ int peripheral_uart_open(int port, peripheral_uart_h *uart)
                return PERIPHERAL_ERROR_OUT_OF_MEMORY;
        }
 
-       uart_proxy_init();
-
        ret = peripheral_gdbus_uart_open(handle, port);
 
        if (ret != PERIPHERAL_ERROR_NONE) {
@@ -94,7 +92,6 @@ int peripheral_uart_close(peripheral_uart_h uart)
        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;