api: add feature invalid check. 77/152877/1 submit/tizen/20170927.094753
authorSegwon <segwon.han@samsung.com>
Wed, 27 Sep 2017 09:31:42 +0000 (18:31 +0900)
committerSegwon <segwon.han@samsung.com>
Wed, 27 Sep 2017 09:34:02 +0000 (18:34 +0900)
   - add dependency the system info package.
   - almost api return the PERIPHERAL_ERROR_NOT_SUPPORTED

Signed-off-by: Segwon <segwon.han@samsung.com>
Change-Id: I1c3cc4a8575cf18eec0d0338cca862555b02070c

CMakeLists.txt
packaging/capi-system-peripheral-io.spec
src/peripheral_gpio.c
src/peripheral_i2c.c
src/peripheral_pwm.c
src/peripheral_spi.c
src/peripheral_uart.c

index 931ace5..c7ae260 100644 (file)
@@ -9,7 +9,7 @@ SET(fw_name "${project_prefix}-${service}-${submodule}")
 
 PROJECT(${fw_name})
 
-SET(dependents "dlog glib-2.0 gio-2.0 gio-unix-2.0 capi-base-common")
+SET(dependents "dlog glib-2.0 gio-2.0 gio-unix-2.0 capi-base-common capi-system-info")
 SET(pc_dependents "capi-base-common")
 
 SET(CMAKE_INSTALL_PREFIX ${prefix})
index 93ce366..2f105bc 100644 (file)
@@ -12,6 +12,7 @@ BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(gio-2.0)
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(capi-base-common)
+BuildRequires:  pkgconfig(capi-system-info)
 
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
index afb09f3..93d1231 100644 (file)
@@ -18,6 +18,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <assert.h>
+#include <system_info.h>
 
 #include "peripheral_io.h"
 #include "peripheral_gdbus_gpio.h"
 #include "peripheral_internal.h"
 #include "peripheral_io_gdbus.h"
 
+#define PERIPHERAL_IO_GPIO_FEATURE "http://tizen.org/feature/peripheral_io.gpio"
+
+#define GPIO_FEATURE_UNKNOWN -1
+#define GPIO_FEATURE_FALSE    0
+#define GPIO_FEATURE_TRUE     1
+
+static int gpio_feature = GPIO_FEATURE_UNKNOWN;
+
+static bool __is_feature_supported()
+{
+       bool feature = false;
+
+       if (gpio_feature == GPIO_FEATURE_UNKNOWN) {
+               system_info_get_platform_bool(PERIPHERAL_IO_GPIO_FEATURE, &feature);
+               gpio_feature = (feature ? GPIO_FEATURE_TRUE : GPIO_FEATURE_FALSE);
+       }
+       return (gpio_feature == GPIO_FEATURE_TRUE ? true : false);
+}
+
 typedef struct {
        peripheral_gpio_h handle;
        peripheral_gpio_interrupted_cb callback;
@@ -114,6 +134,7 @@ int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio)
        int ret = PERIPHERAL_ERROR_NONE;
        peripheral_gpio_h handle;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio handle");
        RETVM_IF(gpio_pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin number");
 
@@ -149,6 +170,7 @@ int peripheral_gpio_close(peripheral_gpio_h gpio)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
 
        /* call gpio_close */
@@ -170,6 +192,7 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
        RETVM_IF((direction < PERIPHERAL_GPIO_DIRECTION_IN) || (direction > PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid direction input");
 
@@ -189,6 +212,7 @@ int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
        RETVM_IF((edge < PERIPHERAL_GPIO_EDGE_NONE) || (edge > PERIPHERAL_GPIO_EDGE_BOTH), PERIPHERAL_ERROR_INVALID_PARAMETER, "edge input is invalid");
 
@@ -207,6 +231,7 @@ int peripheral_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_i
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
        RETVM_IF(callback == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio interrupted callback is NULL");
 
@@ -231,6 +256,7 @@ int peripheral_gpio_unset_interrupted_cb(peripheral_gpio_h gpio)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
 
        ret = peripheral_gdbus_gpio_unset_interrupted_cb(gpio);
@@ -253,6 +279,7 @@ int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
        RETVM_IF(value == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio read value is invalid");
 
@@ -271,6 +298,7 @@ int peripheral_gpio_write(peripheral_gpio_h gpio, uint32_t value)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
        RETVM_IF((value != 0) && (value != 1), PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio value is invalid");
 
index 6393494..dc3cbee 100644 (file)
 #include <stdlib.h>
 #include <unistd.h>
 #include <assert.h>
+#include <system_info.h>
 
 #include "peripheral_io.h"
 #include "peripheral_gdbus_i2c.h"
 #include "peripheral_common.h"
 #include "peripheral_internal.h"
 
+#define PERIPHERAL_IO_I2C_FEATURE "http://tizen.org/feature/peripheral_io.i2c"
+
+#define I2C_FEATURE_UNKNOWN -1
+#define I2C_FEATURE_FALSE    0
+#define I2C_FEATURE_TRUE     1
+
 /* i2c_smbus_xfer read or write markers */
 #define I2C_SMBUS_READ 1
 #define I2C_SMBUS_WRITE        0
 #define I2C_SMBUS_BYTE_DATA        2
 #define I2C_SMBUS_WORD_DATA        3
 
+static int i2c_feature = I2C_FEATURE_UNKNOWN;
+
+static bool __is_feature_supported()
+{
+       bool feature = false;
+
+       if (i2c_feature == I2C_FEATURE_UNKNOWN) {
+               system_info_get_platform_bool(PERIPHERAL_IO_I2C_FEATURE, &feature);
+               i2c_feature = (feature ? I2C_FEATURE_TRUE : I2C_FEATURE_FALSE);
+       }
+
+       return (i2c_feature == I2C_FEATURE_TRUE ? true : false);
+}
+
 int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c)
 {
        peripheral_i2c_h handle;
        int ret = PERIPHERAL_ERROR_NONE;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c handle");
        RETVM_IF(bus < 0 || address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
@@ -67,6 +89,7 @@ int peripheral_i2c_close(peripheral_i2c_h i2c)
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
 
        ret = peripheral_gdbus_i2c_close(i2c);
@@ -84,6 +107,7 @@ int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length)
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
        RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
@@ -98,6 +122,7 @@ int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length)
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
        RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
@@ -113,6 +138,7 @@ int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t
        int ret;
        uint16_t w_data, dummy = 0;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
        RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
@@ -130,6 +156,7 @@ int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_
        int ret;
        uint16_t dummy = 0;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
 
        ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, reg, I2C_SMBUS_BYTE_DATA, (uint16_t)data, &dummy);
@@ -144,6 +171,7 @@ int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_
        int ret;
        uint16_t dummy = 0, data_out;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
        RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
@@ -161,6 +189,7 @@ int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16
        int ret;
        uint16_t dummy = 0;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
 
        ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, reg, I2C_SMBUS_WORD_DATA, data, &dummy);
index 3ea42e0..70c0992 100644 (file)
 #include <stdlib.h>
 #include <unistd.h>
 #include <assert.h>
+#include <system_info.h>
 
 #include "peripheral_io.h"
 #include "peripheral_gdbus_pwm.h"
 #include "peripheral_common.h"
 #include "peripheral_internal.h"
 
+#define PERIPHERAL_IO_PWM_FEATURE "http://tizen.org/feature/peripheral_io.pwm"
+
+#define PWM_FEATURE_UNKNOWN -1
+#define PWM_FEATURE_FALSE    0
+#define PWM_FEATURE_TRUE     1
+
+static int pwm_feature = PWM_FEATURE_UNKNOWN;
+
+static bool __is_feature_supported()
+{
+       bool feature = false;
+
+       if (pwm_feature == PWM_FEATURE_UNKNOWN) {
+               system_info_get_platform_bool(PERIPHERAL_IO_PWM_FEATURE, &feature);
+               pwm_feature = (feature ? PWM_FEATURE_TRUE : PWM_FEATURE_FALSE);
+       }
+
+       return (pwm_feature == PWM_FEATURE_TRUE ? true : false);
+}
+
+
 int peripheral_pwm_open(int chip, int pin, peripheral_pwm_h *pwm)
 {
        peripheral_pwm_h handle;
        int ret = PERIPHERAL_ERROR_NONE;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
        RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm handle");
        RETVM_IF(chip < 0 || pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
@@ -58,6 +81,7 @@ int peripheral_pwm_close(peripheral_pwm_h pwm)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
        RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
 
        if ((ret = peripheral_gdbus_pwm_close(pwm)) < 0)
@@ -73,6 +97,7 @@ int peripheral_pwm_set_period(peripheral_pwm_h pwm, uint32_t period_ns)
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
        RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
 
        ret = peripheral_gdbus_pwm_set_period(pwm, (int)period_ns);
@@ -86,6 +111,7 @@ int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_cycle_ns)
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
        RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
 
        ret = peripheral_gdbus_pwm_set_duty_cycle(pwm, (int)duty_cycle_ns);
@@ -99,6 +125,7 @@ int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
        RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
        RETVM_IF((polarity < PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH) || (polarity > PERIPHERAL_PWM_POLARITY_ACTIVE_LOW), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid polarity parameter");
 
@@ -113,6 +140,7 @@ int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, bool enable)
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
        RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
 
        ret = peripheral_gdbus_pwm_set_enable(pwm, enable);
index 07fefdf..f5ac28e 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <system_info.h>
 
 #include "peripheral_io.h"
 #include "peripheral_gdbus_spi.h"
 #include "peripheral_common.h"
 #include "peripheral_internal.h"
 
+#define PERIPHERAL_IO_SPI_FEATURE "http://tizen.org/feature/peripheral_io.spi"
+
+#define SPI_FEATURE_UNKNOWN -1
+#define SPI_FEATURE_FALSE    0
+#define SPI_FEATURE_TRUE     1
+
+static int spi_feature = SPI_FEATURE_UNKNOWN;
+
+static bool __is_feature_supported()
+{
+       bool feature = false;
+
+       if (spi_feature == SPI_FEATURE_UNKNOWN) {
+               system_info_get_platform_bool(PERIPHERAL_IO_SPI_FEATURE, &feature);
+               spi_feature = (feature ? SPI_FEATURE_TRUE : SPI_FEATURE_FALSE);
+       }
+
+       return (spi_feature == SPI_FEATURE_TRUE ? true : false);
+}
+
 int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi)
 {
        peripheral_spi_h handle;
        int ret = PERIPHERAL_ERROR_NONE;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi handle");
        RETVM_IF(bus < 0 || cs < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
@@ -59,6 +81,7 @@ int peripheral_spi_close(peripheral_spi_h spi)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
 
        ret = peripheral_gdbus_spi_close(spi);
@@ -75,6 +98,7 @@ int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode)
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
        RETVM_IF((mode < PERIPHERAL_SPI_MODE_0) || (mode > PERIPHERAL_SPI_MODE_3), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi mode parameter");
 
@@ -89,6 +113,7 @@ int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
        RETVM_IF((bit_order < PERIPHERAL_SPI_BIT_ORDER_MSB) || (bit_order > PERIPHERAL_SPI_BIT_ORDER_LSB), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid bit order parameter");
 
@@ -104,6 +129,7 @@ int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits)
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
 
        ret = peripheral_gdbus_spi_set_bits_per_word(spi, (unsigned char)bits);
@@ -117,6 +143,7 @@ int peripheral_spi_set_frequency(peripheral_spi_h spi, uint32_t freq_hz)
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
 
        ret = peripheral_gdbus_spi_set_frequency(spi, (unsigned int)freq_hz);
@@ -130,6 +157,7 @@ int peripheral_spi_read(peripheral_spi_h spi, uint8_t *data, uint32_t length)
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
        RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
@@ -144,6 +172,7 @@ int peripheral_spi_write(peripheral_spi_h spi, uint8_t *data, uint32_t length)
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
        RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
@@ -158,6 +187,7 @@ int peripheral_spi_transfer(peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxda
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
        RETVM_IF(txdata == NULL || rxdata == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
index f90d433..7c7d4da 100644 (file)
 #include <stdlib.h>
 #include <unistd.h>
 #include <assert.h>
+#include <system_info.h>
 
 #include "peripheral_io.h"
 #include "peripheral_gdbus_uart.h"
 #include "peripheral_common.h"
 #include "peripheral_internal.h"
 
+#define PERIPHERAL_IO_UART_FEATURE "http://tizen.org/feature/peripheral_io.uart"
+
+#define UART_FEATURE_UNKNOWN -1
+#define UART_FEATURE_FALSE    0
+#define UART_FEATURE_TRUE     1
+
+static int uart_feature = UART_FEATURE_UNKNOWN;
+
+static bool __is_feature_supported()
+{
+       bool feature = false;
+
+       if (uart_feature == UART_FEATURE_UNKNOWN) {
+               system_info_get_platform_bool(PERIPHERAL_IO_UART_FEATURE, &feature);
+               uart_feature = (feature ? UART_FEATURE_TRUE : UART_FEATURE_FALSE);
+       }
+
+       return (uart_feature == UART_FEATURE_TRUE ? true : false);
+}
+
 /**
  * @brief Initializes uart communication and creates uart handle.
  */
@@ -32,6 +53,7 @@ int peripheral_uart_open(int port, peripheral_uart_h *uart)
        peripheral_uart_h handle;
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid uart handle");
        RETVM_IF(port < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid port number");
 
@@ -63,6 +85,7 @@ int peripheral_uart_close(peripheral_uart_h uart)
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
 
        ret = peripheral_gdbus_uart_close(uart);
@@ -83,6 +106,7 @@ int peripheral_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_r
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
        RETVM_IF((baud < PERIPHERAL_UART_BAUD_RATE_0) || (baud > PERIPHERAL_UART_BAUD_RATE_230400), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid baud input");
 
@@ -97,6 +121,7 @@ int peripheral_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_s
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
        RETVM_IF((byte_size < PERIPHERAL_UART_BYTE_SIZE_5BIT) || (byte_size > PERIPHERAL_UART_BYTE_SIZE_8BIT), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
@@ -111,6 +136,7 @@ int peripheral_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
        RETVM_IF((parity < PERIPHERAL_UART_PARITY_NONE) || (parity > PERIPHERAL_UART_PARITY_ODD), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
@@ -125,6 +151,7 @@ int peripheral_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_b
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
        RETVM_IF((stop_bits < PERIPHERAL_UART_STOP_BITS_1BIT) || (stop_bits > PERIPHERAL_UART_STOP_BITS_2BIT), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
@@ -143,6 +170,7 @@ int peripheral_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_sof
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
        RETVM_IF((sw_flow_control < PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE) || (sw_flow_control > PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid sw_flow_control parameter");
        RETVM_IF((hw_flow_control < PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE) || (hw_flow_control > PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid hw_flow_control parameter");
@@ -164,6 +192,7 @@ int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, uint32_t length)
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
        RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
@@ -181,6 +210,7 @@ int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, uint32_t length
 {
        int ret;
 
+       RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
        RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");