From: Segwon Date: Tue, 14 Nov 2017 08:54:05 +0000 (+0900) Subject: gdbus: move gdbus files to top level gdbus folder X-Git-Tag: submit/tizen_4.0/20171220.125806^2~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=04503068e5448f9b551778212a58302087e53fe8;p=platform%2Fcore%2Fapi%2Fperipheral-io.git gdbus: move gdbus files to top level gdbus folder Change-Id: If08e00e576cb8bdb099a740768870a6bdcf41d8b Signed-off-by: Segwon --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 335e42a..9b17fa7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,14 +19,15 @@ SET(VERSION ${version}) FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen) EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS " \\ - --generate-c-code ${CMAKE_SOURCE_DIR}/src/peripheral_io_gdbus \\ + --generate-c-code ${CMAKE_SOURCE_DIR}/src/gdbus/peripheral_io_gdbus \\ --c-namespace PeripheralIoGdbus \\ --interface-prefix org.tizen.peripheral_io. \\ - ${CMAKE_SOURCE_DIR}/src/peripheral_io.xml \\ + ${CMAKE_SOURCE_DIR}/src/gdbus/peripheral_io.xml \\ ") SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) +INCLUDE_DIRECTORIES(${INC_DIR}/gdbus) INCLUDE_DIRECTORIES(${INC_DIR}/interface) INCLUDE(FindPkgConfig) @@ -53,12 +54,12 @@ SET(SOURCES src/peripheral_gpio.c src/interface/peripheral_interface_pwm.c src/interface/peripheral_interface_spi.c src/interface/peripheral_interface_uart.c - src/peripheral_gdbus_gpio.c - src/peripheral_gdbus_i2c.c - src/peripheral_gdbus_pwm.c - src/peripheral_gdbus_uart.c - src/peripheral_gdbus_spi.c - src/peripheral_io_gdbus.c) + src/gdbus/peripheral_gdbus_gpio.c + src/gdbus/peripheral_gdbus_i2c.c + src/gdbus/peripheral_gdbus_pwm.c + src/gdbus/peripheral_gdbus_uart.c + src/gdbus/peripheral_gdbus_spi.c + src/gdbus/peripheral_io_gdbus.c) ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) diff --git a/include/gdbus/peripheral_gdbus.h b/include/gdbus/peripheral_gdbus.h new file mode 100644 index 0000000..ff726de --- /dev/null +++ b/include/gdbus/peripheral_gdbus.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __PERIPHERAL_GDBUS_H__ +#define __PERIPHERAL_GDBUS_H__ + +#include + +#define PERIPHERAL_GDBUS_INTERFACE "org.tizen.peripheral_io" +#define PERIPHERAL_GDBUS_GPIO_PATH "/Org/Tizen/Peripheral_io/Gpio" +#define PERIPHERAL_GDBUS_I2C_PATH "/Org/Tizen/Peripheral_io/I2c" +#define PERIPHERAL_GDBUS_PWM_PATH "/Org/Tizen/Peripheral_io/Pwm" +#define PERIPHERAL_GDBUS_UART_PATH "/Org/Tizen/Peripheral_io/Uart" +#define PERIPHERAL_GDBUS_SPI_PATH "/Org/Tizen/Peripheral_io/Spi" +#define PERIPHERAL_GDBUS_NAME "org.tizen.peripheral_io" + +#endif /* __PERIPHERAL_GDBUS_H__ */ diff --git a/include/gdbus/peripheral_gdbus_gpio.h b/include/gdbus/peripheral_gdbus_gpio.h new file mode 100644 index 0000000..39c67c5 --- /dev/null +++ b/include/gdbus/peripheral_gdbus_gpio.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#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); +int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction); +int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge); +int peripheral_gdbus_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data); +int peripheral_gdbus_gpio_unset_interrupted_cb(peripheral_gpio_h gpio); +int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value); +int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value); + +#endif /* __PERIPHERAL_GDBUS_GPIO_H__ */ diff --git a/include/gdbus/peripheral_gdbus_i2c.h b/include/gdbus/peripheral_gdbus_i2c.h new file mode 100644 index 0000000..7b2b899 --- /dev/null +++ b/include/gdbus/peripheral_gdbus_i2c.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#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); +int peripheral_gdbus_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length); +int peripheral_gdbus_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length); +int peripheral_gdbus_i2c_smbus_ioctl(peripheral_i2c_h i2c, uint8_t read_write, uint8_t command, uint32_t size, uint16_t data_in, uint16_t *data_out); + +#endif /* __PERIPHERAL_GDBUS_I2C_H__ */ diff --git a/include/gdbus/peripheral_gdbus_pwm.h b/include/gdbus/peripheral_gdbus_pwm.h new file mode 100644 index 0000000..f6d4c1c --- /dev/null +++ b/include/gdbus/peripheral_gdbus_pwm.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#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); +int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period); +int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle_ns); +int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity); +int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable); + +#endif /* __PERIPHERAL_GDBUS_PWM_H__ */ diff --git a/include/gdbus/peripheral_gdbus_spi.h b/include/gdbus/peripheral_gdbus_spi.h new file mode 100644 index 0000000..7ab743a --- /dev/null +++ b/include/gdbus/peripheral_gdbus_spi.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#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); +int peripheral_gdbus_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode); +int peripheral_gdbus_spi_set_bit_order(peripheral_spi_h spi, bool lsb); +int peripheral_gdbus_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits); +int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq_hz); +int peripheral_gdbus_spi_read(peripheral_spi_h spi, unsigned char *data, int length); +int peripheral_gdbus_spi_write(peripheral_spi_h spi, unsigned char *data, int length); +int peripheral_gdbus_spi_transfer(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length); + +#endif /* __PERIPHERAL_GDBUS_SPI_H_ */ diff --git a/include/gdbus/peripheral_gdbus_uart.h b/include/gdbus/peripheral_gdbus_uart.h new file mode 100644 index 0000000..15b5d06 --- /dev/null +++ b/include/gdbus/peripheral_gdbus_uart.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#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); +int peripheral_gdbus_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud); +int peripheral_gdbus_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size); +int peripheral_gdbus_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity); +int peripheral_gdbus_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits); +int peripheral_gdbus_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts); +int peripheral_gdbus_uart_read(peripheral_uart_h uart, uint8_t *data, int length); +int peripheral_gdbus_uart_write(peripheral_uart_h uart, uint8_t *data, int length); + +#endif /* __PERIPHERAL_GDBUS_UART_H_ */ diff --git a/include/peripheral_gdbus.h b/include/peripheral_gdbus.h deleted file mode 100644 index ff726de..0000000 --- a/include/peripheral_gdbus.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __PERIPHERAL_GDBUS_H__ -#define __PERIPHERAL_GDBUS_H__ - -#include - -#define PERIPHERAL_GDBUS_INTERFACE "org.tizen.peripheral_io" -#define PERIPHERAL_GDBUS_GPIO_PATH "/Org/Tizen/Peripheral_io/Gpio" -#define PERIPHERAL_GDBUS_I2C_PATH "/Org/Tizen/Peripheral_io/I2c" -#define PERIPHERAL_GDBUS_PWM_PATH "/Org/Tizen/Peripheral_io/Pwm" -#define PERIPHERAL_GDBUS_UART_PATH "/Org/Tizen/Peripheral_io/Uart" -#define PERIPHERAL_GDBUS_SPI_PATH "/Org/Tizen/Peripheral_io/Spi" -#define PERIPHERAL_GDBUS_NAME "org.tizen.peripheral_io" - -#endif /* __PERIPHERAL_GDBUS_H__ */ diff --git a/include/peripheral_gdbus_gpio.h b/include/peripheral_gdbus_gpio.h deleted file mode 100644 index 39c67c5..0000000 --- a/include/peripheral_gdbus_gpio.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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); -int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction); -int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge); -int peripheral_gdbus_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data); -int peripheral_gdbus_gpio_unset_interrupted_cb(peripheral_gpio_h gpio); -int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value); -int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value); - -#endif /* __PERIPHERAL_GDBUS_GPIO_H__ */ diff --git a/include/peripheral_gdbus_i2c.h b/include/peripheral_gdbus_i2c.h deleted file mode 100644 index 7b2b899..0000000 --- a/include/peripheral_gdbus_i2c.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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); -int peripheral_gdbus_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length); -int peripheral_gdbus_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length); -int peripheral_gdbus_i2c_smbus_ioctl(peripheral_i2c_h i2c, uint8_t read_write, uint8_t command, uint32_t size, uint16_t data_in, uint16_t *data_out); - -#endif /* __PERIPHERAL_GDBUS_I2C_H__ */ diff --git a/include/peripheral_gdbus_pwm.h b/include/peripheral_gdbus_pwm.h deleted file mode 100644 index f6d4c1c..0000000 --- a/include/peripheral_gdbus_pwm.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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); -int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period); -int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle_ns); -int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity); -int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable); - -#endif /* __PERIPHERAL_GDBUS_PWM_H__ */ diff --git a/include/peripheral_gdbus_spi.h b/include/peripheral_gdbus_spi.h deleted file mode 100644 index 7ab743a..0000000 --- a/include/peripheral_gdbus_spi.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#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); -int peripheral_gdbus_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode); -int peripheral_gdbus_spi_set_bit_order(peripheral_spi_h spi, bool lsb); -int peripheral_gdbus_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits); -int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq_hz); -int peripheral_gdbus_spi_read(peripheral_spi_h spi, unsigned char *data, int length); -int peripheral_gdbus_spi_write(peripheral_spi_h spi, unsigned char *data, int length); -int peripheral_gdbus_spi_transfer(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length); - -#endif /* __PERIPHERAL_GDBUS_SPI_H_ */ diff --git a/include/peripheral_gdbus_uart.h b/include/peripheral_gdbus_uart.h deleted file mode 100644 index 15b5d06..0000000 --- a/include/peripheral_gdbus_uart.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#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); -int peripheral_gdbus_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud); -int peripheral_gdbus_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size); -int peripheral_gdbus_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity); -int peripheral_gdbus_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits); -int peripheral_gdbus_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts); -int peripheral_gdbus_uart_read(peripheral_uart_h uart, uint8_t *data, int length); -int peripheral_gdbus_uart_write(peripheral_uart_h uart, uint8_t *data, int length); - -#endif /* __PERIPHERAL_GDBUS_UART_H_ */ diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c new file mode 100644 index 0000000..42025de --- /dev/null +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -0,0 +1,247 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "peripheral_io.h" +#include "peripheral_gdbus.h" +#include "peripheral_common.h" +#include "peripheral_internal.h" +#include "peripheral_io_gdbus.h" + +extern int peripheral_gpio_interrupted_cb_handler(int pin, int value, unsigned long long timestamp, int err); + +static PeripheralIoGdbusGpio *gpio_proxy = NULL; + +static void __peripheral_gpio_interrupted_cb(PeripheralIoGdbusGpio *gpio, gint pin, gint value, guint64 timestamp, gpointer user_data) +{ + int err = PERIPHERAL_ERROR_NONE; + if (!gpio) + err = PERIPHERAL_ERROR_IO_ERROR; + + peripheral_gpio_interrupted_cb_handler(pin, value, timestamp, err); +} + +void gpio_proxy_init(void) +{ + GError *error = NULL; + + if (gpio_proxy != NULL) { + g_object_ref(gpio_proxy); + return; + } + + gpio_proxy = peripheral_io_gdbus_gpio_proxy_new_for_bus_sync( + G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + PERIPHERAL_GDBUS_NAME, + PERIPHERAL_GDBUS_GPIO_PATH, + NULL, + &error); + if (gpio_proxy == NULL) { + _E("Can not create gpio proxy : %s", error->message); + g_error_free(error); + return; + } + + g_signal_connect(gpio_proxy, + "interrupted-cb", + G_CALLBACK(__peripheral_gpio_interrupted_cb), + NULL); +} + +void gpio_proxy_deinit() +{ + if (gpio_proxy) { + g_object_unref(gpio_proxy); + if (!G_IS_OBJECT(gpio_proxy)) + gpio_proxy = NULL; + } +} + +int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) +{ + GError *error = NULL; + gint32 ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_open_sync( + gpio_proxy, + gpio->pin, + &gpio->handle, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +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 (peripheral_io_gdbus_gpio_call_close_sync( + gpio_proxy, + gpio->handle, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_set_direction_sync( + gpio_proxy, + gpio->handle, + direction, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_set_edge_mode_sync( + gpio_proxy, + gpio->handle, + edge, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_set_interrupted_cb_sync( + gpio_proxy, + gpio->handle, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_unset_interrupted_cb_sync( + gpio_proxy, + gpio->handle, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_read_sync( + gpio_proxy, + gpio->handle, + value, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_gpio_call_write_sync( + gpio_proxy, + gpio->handle, + value, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} diff --git a/src/gdbus/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c new file mode 100644 index 0000000..e0a39ac --- /dev/null +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "peripheral_io.h" +#include "peripheral_gdbus.h" +#include "peripheral_common.h" +#include "peripheral_internal.h" +#include "peripheral_io_gdbus.h" + +static PeripheralIoGdbusI2c *i2c_proxy = NULL; + +void i2c_proxy_init(void) +{ + GError *error = NULL; + + if (i2c_proxy != NULL) { + g_object_ref(i2c_proxy); + return; + } + + i2c_proxy = peripheral_io_gdbus_i2c_proxy_new_for_bus_sync( + G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + PERIPHERAL_GDBUS_NAME, + PERIPHERAL_GDBUS_I2C_PATH, + NULL, + &error); +} + +void i2c_proxy_deinit() +{ + if (i2c_proxy) { + g_object_unref(i2c_proxy); + if (!G_IS_OBJECT(i2c_proxy)) + i2c_proxy = NULL; + } +} + +int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_i2c_call_open_sync( + i2c_proxy, + bus, + address, + &i2c->handle, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +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 (peripheral_io_gdbus_i2c_call_close_sync( + i2c_proxy, + i2c->handle, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + GVariant *data_array; + GVariantIter *iter; + guint8 str; + int i = 0; + + if (i2c_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_i2c_call_read_sync( + i2c_proxy, + i2c->handle, + length, + &data_array, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + g_variant_get(data_array, "a(y)", &iter); + while (g_variant_iter_loop(iter, "(y)", &str)) { + data[i] = str; + if (i++ == length) break; + } + g_variant_iter_free(iter); + g_variant_unref(data_array); + + return ret; +} + +int peripheral_gdbus_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + GVariantBuilder *builder; + GVariant *g_data; + int i = 0; + + if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); + + for (i = 0; i < length; i++) + g_variant_builder_add(builder, "(y)", data[i]); + g_variant_builder_add(builder, "(y)", 0x00); + + g_data = g_variant_new("a(y)", builder); + g_variant_builder_unref(builder); + + if (peripheral_io_gdbus_i2c_call_write_sync( + i2c_proxy, + i2c->handle, + length, + g_data, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_i2c_smbus_ioctl(peripheral_i2c_h i2c, uint8_t read_write, uint8_t command, uint32_t size, uint16_t data_in, uint16_t *data_out) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_i2c_call_smbus_ioctl_sync( + i2c_proxy, + i2c->handle, + read_write, + command, + size, + data_in, + data_out, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c new file mode 100644 index 0000000..e1fdae9 --- /dev/null +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "peripheral_io.h" +#include "peripheral_gdbus.h" +#include "peripheral_common.h" +#include "peripheral_internal.h" +#include "peripheral_io_gdbus.h" + +static PeripheralIoGdbusPwm *pwm_proxy = NULL; + +void pwm_proxy_init(void) +{ + GError *error = NULL; + + if (pwm_proxy != NULL) { + g_object_ref(pwm_proxy); + return; + } + + pwm_proxy = peripheral_io_gdbus_pwm_proxy_new_for_bus_sync( + G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + PERIPHERAL_GDBUS_NAME, + PERIPHERAL_GDBUS_PWM_PATH, + NULL, + &error); +} + +void pwm_proxy_deinit() +{ + if (pwm_proxy) { + g_object_unref(pwm_proxy); + if (!G_IS_OBJECT(pwm_proxy)) + pwm_proxy = NULL; + } +} + +int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_pwm_call_open_sync( + pwm_proxy, + chip, + pin, + &pwm->handle, + &ret, + NULL, + &error) == FALSE) { + _E("%s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +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 (peripheral_io_gdbus_pwm_call_close_sync( + pwm_proxy, + pwm->handle, + &ret, + NULL, + &error) == FALSE) { + _E("%s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_pwm_call_set_period_sync( + pwm_proxy, + pwm->handle, + period, + &ret, + NULL, + &error) == FALSE) { + _E("%s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle_ns) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync( + pwm_proxy, + pwm->handle, + duty_cycle_ns, + &ret, + NULL, + &error) == FALSE) { + _E("%s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_pwm_call_set_polarity_sync( + pwm_proxy, + pwm->handle, + polarity, + &ret, + NULL, + &error) == FALSE) { + _E("%s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_pwm_call_set_enable_sync( + pwm_proxy, + pwm->handle, + enable, + &ret, + NULL, + &error) == FALSE) { + _E("%s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c new file mode 100644 index 0000000..cc7a8a5 --- /dev/null +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -0,0 +1,303 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "peripheral_io.h" +#include "peripheral_gdbus.h" +#include "peripheral_common.h" +#include "peripheral_internal.h" +#include "peripheral_io_gdbus.h" + +static PeripheralIoGdbusSpi *spi_proxy = NULL; + +void spi_proxy_init(void) +{ + GError *error = NULL; + + if (spi_proxy != NULL) { + g_object_ref(spi_proxy); + return; + } + + spi_proxy = peripheral_io_gdbus_spi_proxy_new_for_bus_sync( + G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + PERIPHERAL_GDBUS_NAME, + PERIPHERAL_GDBUS_SPI_PATH, + NULL, + &error); +} + +void spi_proxy_deinit() +{ + if (spi_proxy) { + g_object_unref(spi_proxy); + if (!G_IS_OBJECT(spi_proxy)) + spi_proxy = NULL; + } +} + +int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_spi_call_open_sync( + spi_proxy, + bus, + cs, + &spi->handle, + &ret, + NULL, + &error) == FALSE) { + _E("%s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +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 (peripheral_io_gdbus_spi_call_close_sync( + spi_proxy, + spi->handle, + &ret, + NULL, + &error) == FALSE) { + _E("%s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_spi_call_set_mode_sync( + spi_proxy, + spi->handle, + (guchar)mode, + &ret, + NULL, + &error) == FALSE) { + _E("%s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_spi_set_bit_order(peripheral_spi_h spi, bool lsb) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_spi_call_set_bit_order_sync( + spi_proxy, + spi->handle, + lsb, + &ret, + NULL, + &error) == FALSE) { + _E("%s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_spi_call_set_bits_per_word_sync( + spi_proxy, + spi->handle, + bits, + &ret, + NULL, + &error) == FALSE) { + _E("%s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq_hz) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_spi_call_set_frequency_sync( + spi_proxy, + spi->handle, + freq_hz, + &ret, + NULL, + &error) == FALSE) { + _E("%s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_spi_read(peripheral_spi_h spi, unsigned char *data, int length) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + GVariant *data_array; + GVariantIter *iter; + guint8 str; + int i = 0; + + if (spi_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_spi_call_read_sync( + spi_proxy, + spi->handle, + length, + &data_array, + &ret, + NULL, + &error) == FALSE) { + _E("%s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + g_variant_get(data_array, "a(y)", &iter); + while (g_variant_iter_loop(iter, "(y)", &str)) { + data[i] = str; + if (i++ == length) break; + } + g_variant_iter_free(iter); + g_variant_unref(data_array); + + return ret; +} + +int peripheral_gdbus_spi_write(peripheral_spi_h spi, unsigned char *data, int length) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + GVariantBuilder *builder; + GVariant *data_array; + int i = 0; + + if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); + + for (i = 0; i < length; i++) + g_variant_builder_add(builder, "(y)", data[i]); + g_variant_builder_add(builder, "(y)", 0x00); + + data_array = g_variant_new("a(y)", builder); + g_variant_builder_unref(builder); + + if (peripheral_io_gdbus_spi_call_write_sync( + spi_proxy, + spi->handle, + length, + data_array, + &ret, + NULL, + &error) == FALSE) { + _E("%s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_spi_transfer(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + GVariantBuilder *builder; + GVariant *rx_data_array; + GVariant *tx_data_array; + GVariantIter *iter; + guint8 str; + int i = 0; + + if (spi_proxy == NULL || !rx_data || !tx_data) return PERIPHERAL_ERROR_UNKNOWN; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); + + for (i = 0; i < length; i++) + g_variant_builder_add(builder, "(y)", tx_data[i]); + g_variant_builder_add(builder, "(y)", 0x00); + + tx_data_array = g_variant_new("a(y)", builder); + g_variant_builder_unref(builder); + + if (peripheral_io_gdbus_spi_call_transfer_sync( + spi_proxy, + spi->handle, + length, + tx_data_array, + &rx_data_array, + &ret, + NULL, + &error) == FALSE) { + _E("%s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + i = 0; + g_variant_get(rx_data_array, "a(y)", &iter); + while (g_variant_iter_loop(iter, "(y)", &str)) { + rx_data[i] = str; + if (i++ == length) break; + } + g_variant_iter_free(iter); + g_variant_unref(rx_data_array); + + return ret; +} diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c new file mode 100644 index 0000000..78bc0c0 --- /dev/null +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -0,0 +1,277 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "peripheral_io.h" +#include "peripheral_gdbus.h" +#include "peripheral_common.h" +#include "peripheral_internal.h" +#include "peripheral_io_gdbus.h" + +static PeripheralIoGdbusUart *uart_proxy = NULL; + +void uart_proxy_init(void) +{ + GError *error = NULL; + + if (uart_proxy != NULL) { + g_object_ref(uart_proxy); + return; + } + + uart_proxy = peripheral_io_gdbus_uart_proxy_new_for_bus_sync( + G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + PERIPHERAL_GDBUS_NAME, + PERIPHERAL_GDBUS_UART_PATH, + NULL, + &error); +} + +void uart_proxy_deinit() +{ + if (uart_proxy) { + g_object_unref(uart_proxy); + if (!G_IS_OBJECT(uart_proxy)) + uart_proxy = NULL; + } +} + +int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + + if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_uart_call_open_sync( + uart_proxy, + port, + &uart->handle, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +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 (peripheral_io_gdbus_uart_call_close_sync( + uart_proxy, + uart->handle, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud) +{ + GError *error = NULL; + gint32 ret = PERIPHERAL_ERROR_NONE; + + if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_uart_call_set_baud_rate_sync( + uart_proxy, + uart->handle, + baud, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size) +{ + GError *error = NULL; + gint32 ret = PERIPHERAL_ERROR_NONE; + + if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_uart_call_set_byte_size_sync( + uart_proxy, + uart->handle, + byte_size, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity) +{ + GError *error = NULL; + gint32 ret = PERIPHERAL_ERROR_NONE; + + if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_uart_call_set_parity_sync( + uart_proxy, + uart->handle, + parity, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits) +{ + GError *error = NULL; + gint32 ret = PERIPHERAL_ERROR_NONE; + + if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_uart_call_set_stop_bits_sync( + uart_proxy, + uart->handle, + stop_bits, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts) +{ + GError *error = NULL; + gint32 ret = PERIPHERAL_ERROR_NONE; + + if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_uart_call_set_flow_control_sync( + uart_proxy, + uart->handle, + xonxoff, + rtscts, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_uart_read(peripheral_uart_h uart, uint8_t *data, int length) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + GVariant *data_array; + GVariantIter *iter; + guint8 str; + int i = 0; + + if (uart_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_uart_call_read_sync( + uart_proxy, + uart->handle, + length, + &data_array, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + g_variant_get(data_array, "a(y)", &iter); + while (g_variant_iter_loop(iter, "(y)", &str)) { + data[i] = str; + if (i++ == length) break; + } + g_variant_iter_free(iter); + g_variant_unref(data_array); + + return ret; +} + +int peripheral_gdbus_uart_write(peripheral_uart_h uart, uint8_t *data, int length) +{ + GError *error = NULL; + peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + GVariantBuilder *builder; + GVariant *g_data; + int i = 0; + + if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); + + for (i = 0; i < length; i++) + g_variant_builder_add(builder, "(y)", data[i]); + g_variant_builder_add(builder, "(y)", 0x00); + + g_data = g_variant_new("a(y)", builder); + g_variant_builder_unref(builder); + + if (peripheral_io_gdbus_uart_call_write_sync( + uart_proxy, + uart->handle, + length, + g_data, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} diff --git a/src/gdbus/peripheral_io.xml b/src/gdbus/peripheral_io.xml new file mode 100644 index 0000000..466efac --- /dev/null +++ b/src/gdbus/peripheral_io.xml @@ -0,0 +1,228 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/peripheral_gdbus_gpio.c b/src/peripheral_gdbus_gpio.c deleted file mode 100644 index 42025de..0000000 --- a/src/peripheral_gdbus_gpio.c +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "peripheral_io.h" -#include "peripheral_gdbus.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" - -extern int peripheral_gpio_interrupted_cb_handler(int pin, int value, unsigned long long timestamp, int err); - -static PeripheralIoGdbusGpio *gpio_proxy = NULL; - -static void __peripheral_gpio_interrupted_cb(PeripheralIoGdbusGpio *gpio, gint pin, gint value, guint64 timestamp, gpointer user_data) -{ - int err = PERIPHERAL_ERROR_NONE; - if (!gpio) - err = PERIPHERAL_ERROR_IO_ERROR; - - peripheral_gpio_interrupted_cb_handler(pin, value, timestamp, err); -} - -void gpio_proxy_init(void) -{ - GError *error = NULL; - - if (gpio_proxy != NULL) { - g_object_ref(gpio_proxy); - return; - } - - gpio_proxy = peripheral_io_gdbus_gpio_proxy_new_for_bus_sync( - G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - PERIPHERAL_GDBUS_NAME, - PERIPHERAL_GDBUS_GPIO_PATH, - NULL, - &error); - if (gpio_proxy == NULL) { - _E("Can not create gpio proxy : %s", error->message); - g_error_free(error); - return; - } - - g_signal_connect(gpio_proxy, - "interrupted-cb", - G_CALLBACK(__peripheral_gpio_interrupted_cb), - NULL); -} - -void gpio_proxy_deinit() -{ - if (gpio_proxy) { - g_object_unref(gpio_proxy); - if (!G_IS_OBJECT(gpio_proxy)) - gpio_proxy = NULL; - } -} - -int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_open_sync( - gpio_proxy, - gpio->pin, - &gpio->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -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 (peripheral_io_gdbus_gpio_call_close_sync( - gpio_proxy, - gpio->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_set_direction_sync( - gpio_proxy, - gpio->handle, - direction, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_set_edge_mode_sync( - gpio_proxy, - gpio->handle, - edge, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_set_interrupted_cb_sync( - gpio_proxy, - gpio->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_unset_interrupted_cb_sync( - gpio_proxy, - gpio->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_read_sync( - gpio_proxy, - gpio->handle, - value, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_write_sync( - gpio_proxy, - gpio->handle, - value, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} diff --git a/src/peripheral_gdbus_i2c.c b/src/peripheral_gdbus_i2c.c deleted file mode 100644 index e0a39ac..0000000 --- a/src/peripheral_gdbus_i2c.c +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "peripheral_io.h" -#include "peripheral_gdbus.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" - -static PeripheralIoGdbusI2c *i2c_proxy = NULL; - -void i2c_proxy_init(void) -{ - GError *error = NULL; - - if (i2c_proxy != NULL) { - g_object_ref(i2c_proxy); - return; - } - - i2c_proxy = peripheral_io_gdbus_i2c_proxy_new_for_bus_sync( - G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - PERIPHERAL_GDBUS_NAME, - PERIPHERAL_GDBUS_I2C_PATH, - NULL, - &error); -} - -void i2c_proxy_deinit() -{ - if (i2c_proxy) { - g_object_unref(i2c_proxy); - if (!G_IS_OBJECT(i2c_proxy)) - i2c_proxy = NULL; - } -} - -int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_i2c_call_open_sync( - i2c_proxy, - bus, - address, - &i2c->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -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 (peripheral_io_gdbus_i2c_call_close_sync( - i2c_proxy, - i2c->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - GVariant *data_array; - GVariantIter *iter; - guint8 str; - int i = 0; - - if (i2c_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_i2c_call_read_sync( - i2c_proxy, - i2c->handle, - length, - &data_array, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - g_variant_get(data_array, "a(y)", &iter); - while (g_variant_iter_loop(iter, "(y)", &str)) { - data[i] = str; - if (i++ == length) break; - } - g_variant_iter_free(iter); - g_variant_unref(data_array); - - return ret; -} - -int peripheral_gdbus_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - GVariantBuilder *builder; - GVariant *g_data; - int i = 0; - - if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); - - for (i = 0; i < length; i++) - g_variant_builder_add(builder, "(y)", data[i]); - g_variant_builder_add(builder, "(y)", 0x00); - - g_data = g_variant_new("a(y)", builder); - g_variant_builder_unref(builder); - - if (peripheral_io_gdbus_i2c_call_write_sync( - i2c_proxy, - i2c->handle, - length, - g_data, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_i2c_smbus_ioctl(peripheral_i2c_h i2c, uint8_t read_write, uint8_t command, uint32_t size, uint16_t data_in, uint16_t *data_out) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_i2c_call_smbus_ioctl_sync( - i2c_proxy, - i2c->handle, - read_write, - command, - size, - data_in, - data_out, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} diff --git a/src/peripheral_gdbus_pwm.c b/src/peripheral_gdbus_pwm.c deleted file mode 100644 index e1fdae9..0000000 --- a/src/peripheral_gdbus_pwm.c +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "peripheral_io.h" -#include "peripheral_gdbus.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" - -static PeripheralIoGdbusPwm *pwm_proxy = NULL; - -void pwm_proxy_init(void) -{ - GError *error = NULL; - - if (pwm_proxy != NULL) { - g_object_ref(pwm_proxy); - return; - } - - pwm_proxy = peripheral_io_gdbus_pwm_proxy_new_for_bus_sync( - G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - PERIPHERAL_GDBUS_NAME, - PERIPHERAL_GDBUS_PWM_PATH, - NULL, - &error); -} - -void pwm_proxy_deinit() -{ - if (pwm_proxy) { - g_object_unref(pwm_proxy); - if (!G_IS_OBJECT(pwm_proxy)) - pwm_proxy = NULL; - } -} - -int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_open_sync( - pwm_proxy, - chip, - pin, - &pwm->handle, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -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 (peripheral_io_gdbus_pwm_call_close_sync( - pwm_proxy, - pwm->handle, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_set_period_sync( - pwm_proxy, - pwm->handle, - period, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle_ns) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync( - pwm_proxy, - pwm->handle, - duty_cycle_ns, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_set_polarity_sync( - pwm_proxy, - pwm->handle, - polarity, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_set_enable_sync( - pwm_proxy, - pwm->handle, - enable, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} diff --git a/src/peripheral_gdbus_spi.c b/src/peripheral_gdbus_spi.c deleted file mode 100644 index cc7a8a5..0000000 --- a/src/peripheral_gdbus_spi.c +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "peripheral_io.h" -#include "peripheral_gdbus.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" - -static PeripheralIoGdbusSpi *spi_proxy = NULL; - -void spi_proxy_init(void) -{ - GError *error = NULL; - - if (spi_proxy != NULL) { - g_object_ref(spi_proxy); - return; - } - - spi_proxy = peripheral_io_gdbus_spi_proxy_new_for_bus_sync( - G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - PERIPHERAL_GDBUS_NAME, - PERIPHERAL_GDBUS_SPI_PATH, - NULL, - &error); -} - -void spi_proxy_deinit() -{ - if (spi_proxy) { - g_object_unref(spi_proxy); - if (!G_IS_OBJECT(spi_proxy)) - spi_proxy = NULL; - } -} - -int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_open_sync( - spi_proxy, - bus, - cs, - &spi->handle, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -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 (peripheral_io_gdbus_spi_call_close_sync( - spi_proxy, - spi->handle, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_set_mode_sync( - spi_proxy, - spi->handle, - (guchar)mode, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_spi_set_bit_order(peripheral_spi_h spi, bool lsb) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_set_bit_order_sync( - spi_proxy, - spi->handle, - lsb, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_set_bits_per_word_sync( - spi_proxy, - spi->handle, - bits, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq_hz) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_set_frequency_sync( - spi_proxy, - spi->handle, - freq_hz, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_spi_read(peripheral_spi_h spi, unsigned char *data, int length) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - GVariant *data_array; - GVariantIter *iter; - guint8 str; - int i = 0; - - if (spi_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_read_sync( - spi_proxy, - spi->handle, - length, - &data_array, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - g_variant_get(data_array, "a(y)", &iter); - while (g_variant_iter_loop(iter, "(y)", &str)) { - data[i] = str; - if (i++ == length) break; - } - g_variant_iter_free(iter); - g_variant_unref(data_array); - - return ret; -} - -int peripheral_gdbus_spi_write(peripheral_spi_h spi, unsigned char *data, int length) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - GVariantBuilder *builder; - GVariant *data_array; - int i = 0; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); - - for (i = 0; i < length; i++) - g_variant_builder_add(builder, "(y)", data[i]); - g_variant_builder_add(builder, "(y)", 0x00); - - data_array = g_variant_new("a(y)", builder); - g_variant_builder_unref(builder); - - if (peripheral_io_gdbus_spi_call_write_sync( - spi_proxy, - spi->handle, - length, - data_array, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_spi_transfer(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - GVariantBuilder *builder; - GVariant *rx_data_array; - GVariant *tx_data_array; - GVariantIter *iter; - guint8 str; - int i = 0; - - if (spi_proxy == NULL || !rx_data || !tx_data) return PERIPHERAL_ERROR_UNKNOWN; - - builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); - - for (i = 0; i < length; i++) - g_variant_builder_add(builder, "(y)", tx_data[i]); - g_variant_builder_add(builder, "(y)", 0x00); - - tx_data_array = g_variant_new("a(y)", builder); - g_variant_builder_unref(builder); - - if (peripheral_io_gdbus_spi_call_transfer_sync( - spi_proxy, - spi->handle, - length, - tx_data_array, - &rx_data_array, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - i = 0; - g_variant_get(rx_data_array, "a(y)", &iter); - while (g_variant_iter_loop(iter, "(y)", &str)) { - rx_data[i] = str; - if (i++ == length) break; - } - g_variant_iter_free(iter); - g_variant_unref(rx_data_array); - - return ret; -} diff --git a/src/peripheral_gdbus_uart.c b/src/peripheral_gdbus_uart.c deleted file mode 100644 index 78bc0c0..0000000 --- a/src/peripheral_gdbus_uart.c +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "peripheral_io.h" -#include "peripheral_gdbus.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" - -static PeripheralIoGdbusUart *uart_proxy = NULL; - -void uart_proxy_init(void) -{ - GError *error = NULL; - - if (uart_proxy != NULL) { - g_object_ref(uart_proxy); - return; - } - - uart_proxy = peripheral_io_gdbus_uart_proxy_new_for_bus_sync( - G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - PERIPHERAL_GDBUS_NAME, - PERIPHERAL_GDBUS_UART_PATH, - NULL, - &error); -} - -void uart_proxy_deinit() -{ - if (uart_proxy) { - g_object_unref(uart_proxy); - if (!G_IS_OBJECT(uart_proxy)) - uart_proxy = NULL; - } -} - -int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_uart_call_open_sync( - uart_proxy, - port, - &uart->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -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 (peripheral_io_gdbus_uart_call_close_sync( - uart_proxy, - uart->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_uart_call_set_baud_rate_sync( - uart_proxy, - uart->handle, - baud, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_uart_call_set_byte_size_sync( - uart_proxy, - uart->handle, - byte_size, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_uart_call_set_parity_sync( - uart_proxy, - uart->handle, - parity, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_uart_call_set_stop_bits_sync( - uart_proxy, - uart->handle, - stop_bits, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_uart_call_set_flow_control_sync( - uart_proxy, - uart->handle, - xonxoff, - rtscts, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_uart_read(peripheral_uart_h uart, uint8_t *data, int length) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - GVariant *data_array; - GVariantIter *iter; - guint8 str; - int i = 0; - - if (uart_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_uart_call_read_sync( - uart_proxy, - uart->handle, - length, - &data_array, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - g_variant_get(data_array, "a(y)", &iter); - while (g_variant_iter_loop(iter, "(y)", &str)) { - data[i] = str; - if (i++ == length) break; - } - g_variant_iter_free(iter); - g_variant_unref(data_array); - - return ret; -} - -int peripheral_gdbus_uart_write(peripheral_uart_h uart, uint8_t *data, int length) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - GVariantBuilder *builder; - GVariant *g_data; - int i = 0; - - if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); - - for (i = 0; i < length; i++) - g_variant_builder_add(builder, "(y)", data[i]); - g_variant_builder_add(builder, "(y)", 0x00); - - g_data = g_variant_new("a(y)", builder); - g_variant_builder_unref(builder); - - if (peripheral_io_gdbus_uart_call_write_sync( - uart_proxy, - uart->handle, - length, - g_data, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 408ed0a..c80e9c9 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -19,12 +19,12 @@ #include #include #include +#include #include "peripheral_io.h" #include "peripheral_gdbus_gpio.h" #include "peripheral_common.h" #include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" #define PERIPHERAL_IO_GPIO_FEATURE "http://tizen.org/feature/peripheral_io.gpio" diff --git a/src/peripheral_io.xml b/src/peripheral_io.xml deleted file mode 100644 index 466efac..0000000 --- a/src/peripheral_io.xml +++ /dev/null @@ -1,228 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -