Rename peripheral_i2c_context_h to peripheral_i2c_h 35/126035/2
authorHyeongsik Min <hyeongsik.min@samsung.com>
Wed, 19 Apr 2017 10:53:20 +0000 (19:53 +0900)
committerHyeongsik Min <hyeongsik.min@samsung.com>
Thu, 20 Apr 2017 03:35:10 +0000 (20:35 -0700)
Change-Id: I533ee1772cdd9b055deac139226bdac3d04d5889
Signed-off-by: Hyeongsik Min <hyeongsik.min@samsung.com>
include/peripheral_dbus.h
include/peripheral_internal.h
include/peripheral_io.h
src/peripheral_dbus.c
src/peripheral_i2c.c
test/peripheral-io-test.c

index c32b2cbf37593d447576ef259f70fb5f4d292a9d..1136792f5d2642a07bc46a69e4ec6d672e26b8b1 100644 (file)
@@ -34,7 +34,7 @@ GDBusConnection *get_dbus_connection(void);
 
 
 int peripheral_dbus_gpio(peripheral_gpio_h gpio, char * sensorid, char *funcname, int write_value, int *read_value);
-int peripheral_dbus_i2c(peripheral_i2c_context_h dev, char * sensorid, char *funcname, int value, unsigned char *data, int addr);
+int peripheral_dbus_i2c(peripheral_i2c_h i2c, char * sensorid, char *funcname, int value, unsigned char *data, int addr);
 int peripheral_dbus_pwm(peripheral_pwm_context_h dev, char * sensorid, char *funcname);
 
 #endif /* __PERIPHERAL_DBUS_H_ */
index 8ab8cc51870d2ef1b92050b51080cbb2e41a0dfb..f331b57c348fb9c9a5f6696470cc1e61efb664cd 100644 (file)
@@ -18,7 +18,7 @@
 #define __PERIPHERAL_INTERNAL_H__
 
 /**
- * @brief Internal struct for keep gpio context information
+ * @brief Internal struct for gpio context
  */
 struct _peripheral_gpio_s {
        int pin;
@@ -26,4 +26,11 @@ struct _peripheral_gpio_s {
        peripheral_gpio_edge_e edge;
 };
 
+/**
+ * @brief Internal struct for i2c context
+ */
+struct _peripheral_i2c_s {
+       int fd;
+};
+
 #endif /* __PERIPHERAL_INTERNAL_H__ */
index 7b164c09e52b8dad261f01a84cb4b7cd7bddce7b..44c9b5949fba5228c77a44cb245a2d757b37c4a8 100644 (file)
@@ -286,23 +286,17 @@ int peripheral_gpio_get_pin(peripheral_gpio_h gpio, int *gpio_pin);
  * @{
  */
 
-/**
- * @brief Struct for peripheral_gpio_s
- */
-struct _peripheral_i2c_s {
-       int fd;
-};
-typedef struct _peripheral_i2c_s *peripheral_i2c_context_h;
+typedef struct _peripheral_i2c_s *peripheral_i2c_h;
 
-peripheral_i2c_context_h peripheral_i2c_init(int bus);
+peripheral_i2c_h peripheral_i2c_init(int bus);
 
-int peripheral_i2c_stop(peripheral_i2c_context_h hnd);
+int peripheral_i2c_stop(peripheral_i2c_h i2c);
 
-int peripheral_i2c_set_address(peripheral_i2c_context_h hnd, int address);
+int peripheral_i2c_set_address(peripheral_i2c_h i2c, int address);
 
-int peripheral_i2c_read(peripheral_i2c_context_h hnd, uint8_t *data, int length);
+int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length);
 
-int peripheral_i2c_write(peripheral_i2c_context_h hnd, uint8_t *data, int length);
+int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length);
 
 
 /**
index 83eb624420337a074dd1e5b42b93aa10fc4c103e..e90997a2c2db9f5e63095b50cc894160067d1920 100644 (file)
@@ -101,7 +101,7 @@ int peripheral_dbus_gpio(peripheral_gpio_h gpio, char * sensorid, char *funcname
 
 }
 
-int peripheral_dbus_i2c(peripheral_i2c_context_h dev, char * sensorid, char *funcname, int value, unsigned char * data, int addr)
+int peripheral_dbus_i2c(peripheral_i2c_h i2c, char * sensorid, char *funcname, int value, unsigned char * data, int addr)
 {
        GError *error = NULL;
        GVariant *ret_value = NULL;
@@ -126,7 +126,7 @@ int peripheral_dbus_i2c(peripheral_i2c_context_h dev, char * sensorid, char *fun
                                                                                PERIPHERAL_DBUS_PATH,
                                                                                PERIPHERAL_DBUS_INTERFACE,
                                                                                sensorid,
-                                                                               g_variant_new("(siiayi)", funcname, value, dev->fd, builder, addr),
+                                                                               g_variant_new("(siiayi)", funcname, value, i2c->fd, builder, addr),
                                                                                G_VARIANT_TYPE("(iayi)"),
                                                                                G_DBUS_CALL_FLAGS_NONE,
                                                                                -1,
@@ -141,7 +141,7 @@ int peripheral_dbus_i2c(peripheral_i2c_context_h dev, char * sensorid, char *fun
                return PERIPHERAL_ERROR_UNKNOWN;
        }
 
-       g_variant_get(ret_value, "(iayi)", &(dev->fd), &ret_data, &ret);
+       g_variant_get(ret_value, "(iayi)", &(i2c->fd), &ret_data, &ret);
        g_variant_unref(ret_value);
 
        if (data != NULL) {
index 0ea2644a70836908ca5a4be37f4dc155600eeb37..35c5d061f789becf6cf37ff55c0e281435801276 100644 (file)
@@ -22,6 +22,7 @@
 #include "peripheral_io.h"
 #include "peripheral_dbus.h"
 #include "peripheral_common.h"
+#include "peripheral_internal.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -30,68 +31,68 @@ extern "C" {
 #define I2C_NAME       "i2c"
 int I2C_Addr = 0;
 
-peripheral_i2c_context_h peripheral_i2c_init(int bus)
+peripheral_i2c_h peripheral_i2c_init(int bus)
 {
-       peripheral_i2c_context_h dev;
+       peripheral_i2c_h i2c;
        int ret = PERIPHERAL_ERROR_NONE;
 
        assert(bus >= 0);
 
-       /* Initialize peripheral_i2c_context_h */
-       dev = (peripheral_i2c_context_h)malloc(sizeof(struct _peripheral_i2c_s));
+       /* Initialize peripheral_i2c_h */
+       i2c = (peripheral_i2c_h)malloc(sizeof(struct _peripheral_i2c_s));
 
-       if (dev == NULL) {
-               _E("Failed to allocate peripheral_i2c_context_h");
+       if (i2c == NULL) {
+               _E("Failed to allocate peripheral_i2c_h");
                return NULL;
        }
 
        if (!get_dbus_connection())
                set_dbus_connection();
 
-       ret = peripheral_dbus_i2c(dev, I2C_NAME, "INIT", bus, 0, I2C_Addr);
+       ret = peripheral_dbus_i2c(i2c, I2C_NAME, "INIT", bus, 0, I2C_Addr);
 
        if (ret != PERIPHERAL_ERROR_NONE) {
-               free(dev);
+               free(i2c);
                _E("[PERIPHERAL] I2C init error\n");
-               dev = NULL;
+               i2c = NULL;
        }
 
-       return dev;
+       return i2c;
 }
 
-int peripheral_i2c_stop(peripheral_i2c_context_h dev)
+int peripheral_i2c_stop(peripheral_i2c_h i2c)
 {
        int ret = PERIPHERAL_ERROR_NONE;
-       /* Free peripheral_i2c_context_h */
+       /* Free peripheral_i2c_h */
 
-       if (dev != NULL) {
-               ret = peripheral_dbus_i2c(dev, I2C_NAME, "STOP", 0, 0, I2C_Addr);
+       if (i2c != NULL) {
+               ret = peripheral_dbus_i2c(i2c, I2C_NAME, "STOP", 0, 0, I2C_Addr);
 
-               free(dev);
-               dev = NULL;
+               free(i2c);
+               i2c = NULL;
        }
 
        return ret;
 }
 
-int peripheral_i2c_set_address(peripheral_i2c_context_h dev, int address)
+int peripheral_i2c_set_address(peripheral_i2c_h i2c, int address)
 {
        /* Set the i2c slave address */
 
        //I2C_Addr = address;
-       return peripheral_dbus_i2c(dev, I2C_NAME, "SET_ADDR", address, 0, I2C_Addr);
+       return peripheral_dbus_i2c(i2c, I2C_NAME, "SET_ADDR", address, 0, I2C_Addr);
 }
 
-int peripheral_i2c_read(peripheral_i2c_context_h dev, uint8_t *data, int length)
+int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length)
 {
        /* Read i2c data */
-       return peripheral_dbus_i2c(dev, I2C_NAME, "READ", length, data, I2C_Addr);
+       return peripheral_dbus_i2c(i2c, I2C_NAME, "READ", length, data, I2C_Addr);
 }
 
-int peripheral_i2c_write(peripheral_i2c_context_h dev, uint8_t *data, int length)
+int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length)
 {
        /* Write i2c data */
-       return peripheral_dbus_i2c(dev, I2C_NAME, "WRITE", length, data, I2C_Addr);
+       return peripheral_dbus_i2c(i2c, I2C_NAME, "WRITE", length, data, I2C_Addr);
 }
 
 #ifdef __cplusplus
index 928f09e42a17b1005838f2d459618bae9c0b1482..857fb66c77879d23dc984a7999e4c59ada55e06e 100644 (file)
@@ -78,7 +78,7 @@ int i2c_test(void)
        int cnt = 0;
        int bus_num;
        unsigned char buf[10];
-       peripheral_i2c_context_h dev;
+       peripheral_i2c_h dev;
 
        printf(">> I2C bus number : ");
        if (scanf("%d", &bus_num) < 0)