directory: change directory 70/160970/4
authorSegwon <segwon.han@samsung.com>
Tue, 21 Nov 2017 02:41:43 +0000 (11:41 +0900)
committerSegwon Han <segwon.han@samsung.com>
Tue, 21 Nov 2017 06:28:40 +0000 (06:28 +0000)
 - remove daemon
 - add src/handle
 - add inc/handle
 - add src/gdbus
 - add inc/gdbus
 - add inc/interface

Change-Id: I925816afe27ec9804fb77a056706e72f65623442
Signed-off-by: Segwon <segwon.han@samsung.com>
73 files changed:
CMakeLists.txt
include/gdbus/peripheral_gdbus_gpio.h [new file with mode: 0644]
include/gdbus/peripheral_gdbus_i2c.h [new file with mode: 0644]
include/gdbus/peripheral_gdbus_pwm.h [new file with mode: 0644]
include/gdbus/peripheral_gdbus_spi.h [new file with mode: 0644]
include/gdbus/peripheral_gdbus_uart.h [new file with mode: 0644]
include/handle/peripheral_handle_gpio.h [new file with mode: 0644]
include/handle/peripheral_handle_i2c.h [new file with mode: 0644]
include/handle/peripheral_handle_pwm.h [new file with mode: 0644]
include/handle/peripheral_handle_spi.h [new file with mode: 0644]
include/handle/peripheral_handle_uart.h [new file with mode: 0644]
include/interface/peripheral_interface_common.h [new file with mode: 0644]
include/interface/peripheral_interface_gpio.h [new file with mode: 0644]
include/interface/peripheral_interface_i2c.h [new file with mode: 0644]
include/interface/peripheral_interface_pwm.h [new file with mode: 0644]
include/interface/peripheral_interface_spi.h [new file with mode: 0644]
include/interface/peripheral_interface_uart.h [new file with mode: 0644]
include/peripheral_bus.h [new file with mode: 0644]
include/peripheral_bus_board.h [new file with mode: 0644]
include/peripheral_bus_util.h [new file with mode: 0644]
include/peripheral_log.h [new file with mode: 0644]
include/privilege_checker.h [new file with mode: 0644]
src/daemon/include/peripheral_bus.h [deleted file]
src/daemon/include/peripheral_bus_board.h [deleted file]
src/daemon/include/peripheral_bus_util.h [deleted file]
src/daemon/include/peripheral_gdbus_gpio.h [deleted file]
src/daemon/include/peripheral_gdbus_i2c.h [deleted file]
src/daemon/include/peripheral_gdbus_pwm.h [deleted file]
src/daemon/include/peripheral_gdbus_spi.h [deleted file]
src/daemon/include/peripheral_gdbus_uart.h [deleted file]
src/daemon/include/peripheral_handle_gpio.h [deleted file]
src/daemon/include/peripheral_handle_i2c.h [deleted file]
src/daemon/include/peripheral_handle_pwm.h [deleted file]
src/daemon/include/peripheral_handle_spi.h [deleted file]
src/daemon/include/peripheral_handle_uart.h [deleted file]
src/daemon/include/peripheral_log.h [deleted file]
src/daemon/include/privilege_checker.h [deleted file]
src/daemon/peripheral_bus.c [deleted file]
src/daemon/peripheral_bus_board.c [deleted file]
src/daemon/peripheral_bus_util.c [deleted file]
src/daemon/peripheral_gdbus_gpio.c [deleted file]
src/daemon/peripheral_gdbus_i2c.c [deleted file]
src/daemon/peripheral_gdbus_pwm.c [deleted file]
src/daemon/peripheral_gdbus_spi.c [deleted file]
src/daemon/peripheral_gdbus_uart.c [deleted file]
src/daemon/peripheral_handle_gpio.c [deleted file]
src/daemon/peripheral_handle_i2c.c [deleted file]
src/daemon/peripheral_handle_pwm.c [deleted file]
src/daemon/peripheral_handle_spi.c [deleted file]
src/daemon/peripheral_handle_uart.c [deleted file]
src/daemon/peripheral_io.xml [deleted file]
src/daemon/privilege_checker.c [deleted file]
src/gdbus/peripheral_gdbus_gpio.c [new file with mode: 0644]
src/gdbus/peripheral_gdbus_i2c.c [new file with mode: 0644]
src/gdbus/peripheral_gdbus_pwm.c [new file with mode: 0644]
src/gdbus/peripheral_gdbus_spi.c [new file with mode: 0644]
src/gdbus/peripheral_gdbus_uart.c [new file with mode: 0644]
src/gdbus/peripheral_io.xml [new file with mode: 0644]
src/handle/peripheral_handle_gpio.c [new file with mode: 0644]
src/handle/peripheral_handle_i2c.c [new file with mode: 0644]
src/handle/peripheral_handle_pwm.c [new file with mode: 0644]
src/handle/peripheral_handle_spi.c [new file with mode: 0644]
src/handle/peripheral_handle_uart.c [new file with mode: 0644]
src/interface/include/peripheral_interface_common.h [deleted file]
src/interface/include/peripheral_interface_gpio.h [deleted file]
src/interface/include/peripheral_interface_i2c.h [deleted file]
src/interface/include/peripheral_interface_pwm.h [deleted file]
src/interface/include/peripheral_interface_spi.h [deleted file]
src/interface/include/peripheral_interface_uart.h [deleted file]
src/peripheral_bus.c [new file with mode: 0644]
src/peripheral_bus_board.c [new file with mode: 0644]
src/peripheral_bus_util.c [new file with mode: 0644]
src/privilege_checker.c [new file with mode: 0644]

index bddedcbc4174d175e85349313c30f167da2dbdd6..fbf16601f610e26843cc9702ca88abff283d98d6 100644 (file)
@@ -9,33 +9,35 @@ SET(dependents "dlog glib-2.0 gio-2.0 gio-unix-2.0 libsystemd-daemon iniparser l
 FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen)
 EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS
                 " \\
-                --generate-c-code ${CMAKE_SOURCE_DIR}/src/daemon/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/daemon/peripheral_io.xml \\
+                ${CMAKE_SOURCE_DIR}/src/gdbus/peripheral_io.xml \\
                 ")
 
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/daemon)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/daemon/include)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/interface/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/handle)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/gdbus)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/interface)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/gdbus)
 
 SET(PERIPHERAL-BUS "peripheral-bus")
 SET(SRCS
-       src/daemon/peripheral_bus.c
-       src/daemon/peripheral_bus_util.c
-       src/daemon/peripheral_gdbus_gpio.c
-       src/daemon/peripheral_gdbus_i2c.c
-       src/daemon/peripheral_gdbus_pwm.c
-       src/daemon/peripheral_gdbus_spi.c
-       src/daemon/peripheral_gdbus_uart.c
-       src/daemon/peripheral_handle_pwm.c
-       src/daemon/peripheral_handle_i2c.c
-       src/daemon/peripheral_handle_gpio.c
-       src/daemon/peripheral_handle_uart.c
-       src/daemon/peripheral_handle_spi.c
-       src/daemon/peripheral_bus_board.c
-       src/daemon/peripheral_io_gdbus.c
-       src/daemon/privilege_checker.c
+       src/peripheral_bus.c
+       src/peripheral_bus_util.c
+       src/peripheral_bus_board.c
+       src/privilege_checker.c
+       src/gdbus/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_spi.c
+       src/gdbus/peripheral_gdbus_uart.c
+       src/handle/peripheral_handle_pwm.c
+       src/handle/peripheral_handle_i2c.c
+       src/handle/peripheral_handle_gpio.c
+       src/handle/peripheral_handle_uart.c
+       src/handle/peripheral_handle_spi.c
        src/interface/peripheral_interface_gpio.c
        src/interface/peripheral_interface_i2c.c
        src/interface/peripheral_interface_pwm.c
diff --git a/include/gdbus/peripheral_gdbus_gpio.h b/include/gdbus/peripheral_gdbus_gpio.h
new file mode 100644 (file)
index 0000000..2d396ab
--- /dev/null
@@ -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_GPIO_H__
+#define __PERIPHERAL_GDBUS_GPIO_H__
+
+#include "peripheral_io_gdbus.h"
+
+gboolean handle_gpio_open(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               GUnixFDList *fd_list,
+               gint pin,
+               gpointer user_data);
+
+#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 (file)
index 0000000..cad264d
--- /dev/null
@@ -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_I2C_H__
+#define __PERIPHERAL_GDBUS_I2C_H__
+
+#include "peripheral_io_gdbus.h"
+
+gboolean handle_i2c_open(
+               PeripheralIoGdbusI2c *i2c,
+               GDBusMethodInvocation *invocation,
+               GUnixFDList *fd_list,
+               gint bus,
+               gint address,
+               gpointer user_data);
+
+#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 (file)
index 0000000..4ffae5e
--- /dev/null
@@ -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__
+
+#include "peripheral_io_gdbus.h"
+
+gboolean handle_pwm_open(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               GUnixFDList *fd_list,
+               gint chip,
+               gint pin,
+               gpointer user_data);
+
+#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 (file)
index 0000000..687528c
--- /dev/null
@@ -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_SPI_H__
+#define __PERIPHERAL_GDBUS_SPI_H__
+
+#include "peripheral_io_gdbus.h"
+
+gboolean handle_spi_open(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               GUnixFDList *fd_list,
+               gint bus,
+               gint cs,
+               gpointer user_data);
+
+#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 (file)
index 0000000..64bd84c
--- /dev/null
@@ -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_UART_H__
+#define __PERIPHERAL_GDBUS_UART_H__
+
+#include "peripheral_io_gdbus.h"
+
+gboolean handle_uart_open(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               GUnixFDList *fd_list,
+               gint port,
+               gpointer user_data);
+
+#endif /* __PERIPHERAL_GDBUS_UART_H__ */
diff --git a/include/handle/peripheral_handle_gpio.h b/include/handle/peripheral_handle_gpio.h
new file mode 100644 (file)
index 0000000..84b750f
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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_HANDLE_GPIO_H__
+#define __PERIPHERAL_HANDLE_GPIO_H__
+
+int peripheral_bus_gpio_open(gint pin, pb_data_h *handle, gpointer user_data);
+int peripheral_bus_gpio_close(pb_data_h handle);
+
+#endif /* __PERIPHERAL_HANDLE_GPIO_H__ */
diff --git a/include/handle/peripheral_handle_i2c.h b/include/handle/peripheral_handle_i2c.h
new file mode 100644 (file)
index 0000000..04bcd56
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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_HANDLE_I2C_H__
+#define __PERIPHERAL_HANDLE_I2C_H__
+
+int peripheral_bus_i2c_open(int bus, int address, pb_data_h *handle, gpointer user_data);
+int peripheral_bus_i2c_close(pb_data_h handle);
+
+#endif /* __PERIPHERAL_HANDLE_I2C_H__ */
diff --git a/include/handle/peripheral_handle_pwm.h b/include/handle/peripheral_handle_pwm.h
new file mode 100644 (file)
index 0000000..f42a396
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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_HANDLE_PWM_H__
+#define __PERIPHERAL_HANDLE_PWM_H__
+
+int peripheral_bus_pwm_open(int chip, int pin, pb_data_h *handle, gpointer user_data);
+int peripheral_bus_pwm_close(pb_data_h handle);
+
+#endif /* __PERIPHERAL_HANDLE_PWM_H__ */
diff --git a/include/handle/peripheral_handle_spi.h b/include/handle/peripheral_handle_spi.h
new file mode 100644 (file)
index 0000000..c0feda1
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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_HANDLE_SPI_H__
+#define __PERIPHERAL_HANDLE_SPI_H__
+
+int peripheral_bus_spi_open(int bus, int cs, pb_data_h *handle, gpointer user_data);
+int peripheral_bus_spi_close(pb_data_h handle);
+
+#endif /* __PERIPHERAL_HANDLE_SPI_H__ */
diff --git a/include/handle/peripheral_handle_uart.h b/include/handle/peripheral_handle_uart.h
new file mode 100644 (file)
index 0000000..57165b2
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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_HANDLE_UART_H__
+#define __PERIPHERAL_HANDLE_UART_H__
+
+int peripheral_bus_uart_open(int port, pb_data_h *handle, gpointer user_data);
+int peripheral_bus_uart_close(pb_data_h handle);
+
+#endif /* __PERIPHERAL_HANDLE_UART_H__ */
diff --git a/include/interface/peripheral_interface_common.h b/include/interface/peripheral_interface_common.h
new file mode 100644 (file)
index 0000000..d411ae7
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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_INTERFACE_COMMON_H__
+#define __PERIPHERAL_INTERFACE_COMMON_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <peripheral_io.h>
+
+#include "peripheral_log.h"
+
+#define MAX_ERR_LEN 255
+#define MAX_BUF_LEN 64
+
+#define CHECK_ERROR(expr) \
+       do { \
+               if (expr) { \
+                       if (errno == EAGAIN) \
+                               return PERIPHERAL_ERROR_TRY_AGAIN; \
+                       char errmsg[MAX_ERR_LEN]; \
+                       strerror_r(errno, errmsg, sizeof(errmsg)); \
+                       _E("Failed the %s(%d) function. errmsg: %s", __FUNCTION__, __LINE__, errmsg); \
+                       return PERIPHERAL_ERROR_IO_ERROR; \
+               } \
+       } while (0)
+
+#endif /*__PERIPHERAL_INTERFACE_COMMON_H__*/
\ No newline at end of file
diff --git a/include/interface/peripheral_interface_gpio.h b/include/interface/peripheral_interface_gpio.h
new file mode 100644 (file)
index 0000000..4dfab84
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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_INTERFACE_GPIO_H__
+#define __PERIPHERAL_INTERFACE_GPIO_H__
+
+int gpio_open(int gpiopin);
+int gpio_close(int gpiopin);
+
+#endif /*__PERIPHERAL_INTERFACE_GPIO_H__*/
diff --git a/include/interface/peripheral_interface_i2c.h b/include/interface/peripheral_interface_i2c.h
new file mode 100644 (file)
index 0000000..9aae2ff
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * 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_INTERFACE_I2C_H__
+#define __PERIPHERAL_INTERFACE_I2C_H__
+
+int i2c_open(int bus, int *fd);
+int i2c_close(int fd);
+int i2c_set_address(int fd, int address);
+
+#endif /* __PERIPHERAL_INTERFACE_I2C_H__ */
diff --git a/include/interface/peripheral_interface_pwm.h b/include/interface/peripheral_interface_pwm.h
new file mode 100644 (file)
index 0000000..7621bfc
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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_INTERFACE_PWM_H__
+#define __PERIPHERAL_INTERFACE_PWM_H__
+
+/**
+* @brief pwm_open() init pwm pin.
+*
+* @param[in] chip pwm chip number
+* @param[in] pin pwm pin number
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int pwm_open(int chip, int pin);
+
+/**
+* @brief pwm_close() deinit pwm pin.
+*
+* @param[in] chip pwm chip number
+* @param[in] pin pwm pin number
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int pwm_close(int chip, int pin);
+
+#endif /* __PERIPHERAL_INTERFACE_PWM_H__ */
diff --git a/include/interface/peripheral_interface_spi.h b/include/interface/peripheral_interface_spi.h
new file mode 100644 (file)
index 0000000..95994f0
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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_INTERFACE_SPI_H__
+#define __PERIPHERAL_INTERFACE_SPI_H__
+
+int spi_open(int bus, int cs, int *fd);
+int spi_close(int fd);
+
+#endif /* __PERIPHERAL_INTERFACE_SPI_H__ */
diff --git a/include/interface/peripheral_interface_uart.h b/include/interface/peripheral_interface_uart.h
new file mode 100644 (file)
index 0000000..0cecfb2
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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_INTERFACE_UART_H__
+#define __PERIPHERAL_INTERFACE_UART_H__
+
+/**
+* @brief uart_open() initializes uart port.
+*
+* @param[in] port uart port
+* @param[in] file_hndl handle of uart port
+* @return On success, handle of uart_context is returned. On failure, NULL is returned.
+*/
+int uart_open(int port, int *file_hndl);
+
+/**
+* @brief uart_close() closes uart port.
+*
+* @param[in] file_hndl handle of uart_context
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int uart_close(int file_hndl);
+
+#endif /* __PERIPHERAL_INTERFACE_UART_H__ */
+
diff --git a/include/peripheral_bus.h b/include/peripheral_bus.h
new file mode 100644 (file)
index 0000000..d4baf72
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * 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_BUS_H__
+#define __PERIPHERAL_BUS_H__
+
+#include <gio/gio.h>
+
+#include "peripheral_io_gdbus.h"
+#include "peripheral_bus_board.h"
+
+#define PERIPHERAL_PRIVILEGE "http://tizen.org/privilege/peripheralio"
+
+typedef enum {
+       PERIPHERAL_BUS_TYPE_GPIO = 0,
+       PERIPHERAL_BUS_TYPE_I2C,
+       PERIPHERAL_BUS_TYPE_PWM,
+       PERIPHERAL_BUS_TYPE_UART,
+       PERIPHERAL_BUS_TYPE_SPI,
+} peripheral_bus_type_e;
+
+typedef struct {
+       pb_board_s *board;
+       /* devices */
+       GList *gpio_list;
+       GList *i2c_list;
+       GList *pwm_list;
+       GList *uart_list;
+       GList *spi_list;
+       /* gdbus variable */
+       guint reg_id;
+       GDBusConnection *connection;
+       PeripheralIoGdbusGpio *gpio_skeleton;
+       PeripheralIoGdbusI2c *i2c_skeleton;
+       PeripheralIoGdbusPwm *pwm_skeleton;
+       PeripheralIoGdbusUart *uart_skeleton;
+       PeripheralIoGdbusSpi *spi_skeleton;
+} peripheral_bus_s;
+
+typedef struct {
+       char *id;
+       pid_t pid;
+       pid_t pgid;
+} pb_client_info_s;
+
+typedef struct {
+       int pin;
+} peripheral_bus_gpio_s;
+
+typedef struct {
+       int bus;
+       int address;
+       int fd;
+} peripheral_bus_i2c_s;
+
+typedef struct {
+       int chip;
+       int pin;
+} peripheral_bus_pwm_s;
+
+typedef struct {
+       int port;
+       int fd;
+} peripheral_bus_uart_s;
+
+typedef struct {
+       int bus;
+       int cs;
+       int fd;
+} peripheral_bus_spi_s;
+
+typedef struct {
+       peripheral_bus_type_e type;
+       uint watch_id;
+       GList **list;
+       /* client info */
+       pb_client_info_s client_info;
+       union {
+               peripheral_bus_gpio_s gpio;
+               peripheral_bus_i2c_s i2c;
+               peripheral_bus_pwm_s pwm;
+               peripheral_bus_uart_s uart;
+               peripheral_bus_spi_s spi;
+       } dev;
+} peripheral_bus_data_s;
+
+typedef peripheral_bus_data_s *pb_data_h;
+
+#endif /* __PERIPHERAL_BUS_H__ */
diff --git a/include/peripheral_bus_board.h b/include/peripheral_bus_board.h
new file mode 100644 (file)
index 0000000..c84b8b7
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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_BUS_BOARD_H__
+#define __PERIPHERAL_BUS_BOARD_H__
+
+#define BOARD_DEVICE_TREE      "/proc/device-tree/model"
+#define BOARD_PINS_MAX 4
+#define BOARD_ARGS_MAX 2
+
+typedef enum {
+       PB_BOARD_ARTIK710 = 0,
+       PB_BOARD_ARTIK530,
+       PB_BOARD_ARTIK520,
+       PB_BOARD_RP3_B,
+       PB_BOARD_UNKNOWN,
+} pb_board_type_e;
+
+typedef enum {
+       PB_BOARD_DEV_GPIO = 0,
+       PB_BOARD_DEV_I2C,
+       PB_BOARD_DEV_PWM,
+       PB_BOARD_DEV_UART,
+       PB_BOARD_DEV_SPI,
+       PB_BOARD_DEV_MAX,
+} pb_board_dev_e;
+
+typedef struct {
+       pb_board_type_e type;
+       char *name;
+       char *path;
+} pb_board_type_s;
+
+typedef struct {
+       pb_board_dev_e dev_type;
+       unsigned int pins[BOARD_PINS_MAX];
+       unsigned int num_pins;
+       unsigned int args[BOARD_ARGS_MAX];
+} pb_board_dev_s;
+
+typedef struct {
+       pb_board_type_e type;
+       pb_board_dev_s *dev;
+       unsigned int num_dev;
+} pb_board_s;
+
+pb_board_dev_s *peripheral_bus_board_find_device(pb_board_dev_e dev_type, pb_board_s *board, int arg, ...);
+pb_board_s *peripheral_bus_board_init(void);
+void peripheral_bus_board_deinit(pb_board_s *board);
+
+#endif /* __PERIPHERAL_BUS_BOARD_H__ */
diff --git a/include/peripheral_bus_util.h b/include/peripheral_bus_util.h
new file mode 100644 (file)
index 0000000..df2b6b1
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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_UTIL_H__
+#define __PERIPHERAL_UTIL_H__
+
+GVariant *peripheral_bus_build_variant_ay(uint8_t *data, int length);
+pb_data_h peripheral_bus_data_new(GList **plist);
+int peripheral_bus_data_free(pb_data_h handle);
+
+int peripheral_bus_get_client_info(
+               GDBusMethodInvocation *invocation,
+               peripheral_bus_s *pb_data,
+               pb_client_info_s *client_info);
+
+int peripheral_bus_handle_is_valid(
+               GDBusMethodInvocation *invocation,
+               pb_data_h handle,
+               GList *list);
+
+int peripheral_bus_check_privilege(
+               GDBusMethodInvocation *invocation,
+               peripheral_bus_s *pb_data);
+
+#endif /* __PERIPHERAL_UTIL_H__ */
diff --git a/include/peripheral_log.h b/include/peripheral_log.h
new file mode 100644 (file)
index 0000000..7198845
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * 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_LOG_H__
+#define __PERIPHERAL_LOG_H__
+
+#include <unistd.h>
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "PERIPHERAL-BUS"
+
+#define _E(fmt, arg...) LOGE(fmt, ##arg)
+#define _D(fmt, arg...) LOGD(fmt, ##arg)
+#define _W(fmt, arg...) LOGW(fmt, ##arg)
+
+#define RET_IF(expr) \
+       do { \
+               if (expr) { \
+                       _E("(%s)", #expr); \
+                       return; \
+               } \
+       } while (0)
+#define RETV_IF(expr, val) \
+       do {\
+               if (expr) { \
+                       _E("(%s)", #expr); \
+                       return (val); \
+               } \
+       } while (0)
+#define RETM_IF(expr, fmt, arg...) \
+       do {\
+               if (expr) { \
+                       _E(fmt, ##arg); \
+                       return; \
+               } \
+       } while (0)
+#define RETVM_IF(expr, val, fmt, arg...) \
+       do {\
+               if (expr) { \
+                       _E(fmt, ##arg); \
+                       return (val); \
+               } \
+       } while (0)
+
+#endif /* __PERIPHERAL_COMMON_H__ */
diff --git a/include/privilege_checker.h b/include/privilege_checker.h
new file mode 100644 (file)
index 0000000..a39fb8d
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * 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 __PRIVILEGE_CHECKER_H__
+#define __PRIVILEGE_CHECKER_H__
+
+#include <stdbool.h>
+
+void peripheral_privilege_init(void);
+void peripheral_privilege_deinit(void);
+bool peripheral_privilege_check(const char* client, const char* session, const char* user, const char* privilege);
+
+#endif /* __PRIVILEGE_CHECKER_H__ */
diff --git a/src/daemon/include/peripheral_bus.h b/src/daemon/include/peripheral_bus.h
deleted file mode 100644 (file)
index d4baf72..0000000
+++ /dev/null
@@ -1,102 +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_BUS_H__
-#define __PERIPHERAL_BUS_H__
-
-#include <gio/gio.h>
-
-#include "peripheral_io_gdbus.h"
-#include "peripheral_bus_board.h"
-
-#define PERIPHERAL_PRIVILEGE "http://tizen.org/privilege/peripheralio"
-
-typedef enum {
-       PERIPHERAL_BUS_TYPE_GPIO = 0,
-       PERIPHERAL_BUS_TYPE_I2C,
-       PERIPHERAL_BUS_TYPE_PWM,
-       PERIPHERAL_BUS_TYPE_UART,
-       PERIPHERAL_BUS_TYPE_SPI,
-} peripheral_bus_type_e;
-
-typedef struct {
-       pb_board_s *board;
-       /* devices */
-       GList *gpio_list;
-       GList *i2c_list;
-       GList *pwm_list;
-       GList *uart_list;
-       GList *spi_list;
-       /* gdbus variable */
-       guint reg_id;
-       GDBusConnection *connection;
-       PeripheralIoGdbusGpio *gpio_skeleton;
-       PeripheralIoGdbusI2c *i2c_skeleton;
-       PeripheralIoGdbusPwm *pwm_skeleton;
-       PeripheralIoGdbusUart *uart_skeleton;
-       PeripheralIoGdbusSpi *spi_skeleton;
-} peripheral_bus_s;
-
-typedef struct {
-       char *id;
-       pid_t pid;
-       pid_t pgid;
-} pb_client_info_s;
-
-typedef struct {
-       int pin;
-} peripheral_bus_gpio_s;
-
-typedef struct {
-       int bus;
-       int address;
-       int fd;
-} peripheral_bus_i2c_s;
-
-typedef struct {
-       int chip;
-       int pin;
-} peripheral_bus_pwm_s;
-
-typedef struct {
-       int port;
-       int fd;
-} peripheral_bus_uart_s;
-
-typedef struct {
-       int bus;
-       int cs;
-       int fd;
-} peripheral_bus_spi_s;
-
-typedef struct {
-       peripheral_bus_type_e type;
-       uint watch_id;
-       GList **list;
-       /* client info */
-       pb_client_info_s client_info;
-       union {
-               peripheral_bus_gpio_s gpio;
-               peripheral_bus_i2c_s i2c;
-               peripheral_bus_pwm_s pwm;
-               peripheral_bus_uart_s uart;
-               peripheral_bus_spi_s spi;
-       } dev;
-} peripheral_bus_data_s;
-
-typedef peripheral_bus_data_s *pb_data_h;
-
-#endif /* __PERIPHERAL_BUS_H__ */
diff --git a/src/daemon/include/peripheral_bus_board.h b/src/daemon/include/peripheral_bus_board.h
deleted file mode 100644 (file)
index c84b8b7..0000000
+++ /dev/null
@@ -1,64 +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_BUS_BOARD_H__
-#define __PERIPHERAL_BUS_BOARD_H__
-
-#define BOARD_DEVICE_TREE      "/proc/device-tree/model"
-#define BOARD_PINS_MAX 4
-#define BOARD_ARGS_MAX 2
-
-typedef enum {
-       PB_BOARD_ARTIK710 = 0,
-       PB_BOARD_ARTIK530,
-       PB_BOARD_ARTIK520,
-       PB_BOARD_RP3_B,
-       PB_BOARD_UNKNOWN,
-} pb_board_type_e;
-
-typedef enum {
-       PB_BOARD_DEV_GPIO = 0,
-       PB_BOARD_DEV_I2C,
-       PB_BOARD_DEV_PWM,
-       PB_BOARD_DEV_UART,
-       PB_BOARD_DEV_SPI,
-       PB_BOARD_DEV_MAX,
-} pb_board_dev_e;
-
-typedef struct {
-       pb_board_type_e type;
-       char *name;
-       char *path;
-} pb_board_type_s;
-
-typedef struct {
-       pb_board_dev_e dev_type;
-       unsigned int pins[BOARD_PINS_MAX];
-       unsigned int num_pins;
-       unsigned int args[BOARD_ARGS_MAX];
-} pb_board_dev_s;
-
-typedef struct {
-       pb_board_type_e type;
-       pb_board_dev_s *dev;
-       unsigned int num_dev;
-} pb_board_s;
-
-pb_board_dev_s *peripheral_bus_board_find_device(pb_board_dev_e dev_type, pb_board_s *board, int arg, ...);
-pb_board_s *peripheral_bus_board_init(void);
-void peripheral_bus_board_deinit(pb_board_s *board);
-
-#endif /* __PERIPHERAL_BUS_BOARD_H__ */
diff --git a/src/daemon/include/peripheral_bus_util.h b/src/daemon/include/peripheral_bus_util.h
deleted file mode 100644 (file)
index df2b6b1..0000000
+++ /dev/null
@@ -1,38 +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_UTIL_H__
-#define __PERIPHERAL_UTIL_H__
-
-GVariant *peripheral_bus_build_variant_ay(uint8_t *data, int length);
-pb_data_h peripheral_bus_data_new(GList **plist);
-int peripheral_bus_data_free(pb_data_h handle);
-
-int peripheral_bus_get_client_info(
-               GDBusMethodInvocation *invocation,
-               peripheral_bus_s *pb_data,
-               pb_client_info_s *client_info);
-
-int peripheral_bus_handle_is_valid(
-               GDBusMethodInvocation *invocation,
-               pb_data_h handle,
-               GList *list);
-
-int peripheral_bus_check_privilege(
-               GDBusMethodInvocation *invocation,
-               peripheral_bus_s *pb_data);
-
-#endif /* __PERIPHERAL_UTIL_H__ */
diff --git a/src/daemon/include/peripheral_gdbus_gpio.h b/src/daemon/include/peripheral_gdbus_gpio.h
deleted file mode 100644 (file)
index 2d396ab..0000000
+++ /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_GPIO_H__
-#define __PERIPHERAL_GDBUS_GPIO_H__
-
-#include "peripheral_io_gdbus.h"
-
-gboolean handle_gpio_open(
-               PeripheralIoGdbusGpio *gpio,
-               GDBusMethodInvocation *invocation,
-               GUnixFDList *fd_list,
-               gint pin,
-               gpointer user_data);
-
-#endif /* __PERIPHERAL_GDBUS_GPIO_H__ */
diff --git a/src/daemon/include/peripheral_gdbus_i2c.h b/src/daemon/include/peripheral_gdbus_i2c.h
deleted file mode 100644 (file)
index cad264d..0000000
+++ /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_I2C_H__
-#define __PERIPHERAL_GDBUS_I2C_H__
-
-#include "peripheral_io_gdbus.h"
-
-gboolean handle_i2c_open(
-               PeripheralIoGdbusI2c *i2c,
-               GDBusMethodInvocation *invocation,
-               GUnixFDList *fd_list,
-               gint bus,
-               gint address,
-               gpointer user_data);
-
-#endif /* __PERIPHERAL_GDBUS_I2C_H__ */
diff --git a/src/daemon/include/peripheral_gdbus_pwm.h b/src/daemon/include/peripheral_gdbus_pwm.h
deleted file mode 100644 (file)
index 4ffae5e..0000000
+++ /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__
-
-#include "peripheral_io_gdbus.h"
-
-gboolean handle_pwm_open(
-               PeripheralIoGdbusPwm *pwm,
-               GDBusMethodInvocation *invocation,
-               GUnixFDList *fd_list,
-               gint chip,
-               gint pin,
-               gpointer user_data);
-
-#endif /* __PERIPHERAL_GDBUS_PWM_H__ */
diff --git a/src/daemon/include/peripheral_gdbus_spi.h b/src/daemon/include/peripheral_gdbus_spi.h
deleted file mode 100644 (file)
index 687528c..0000000
+++ /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_SPI_H__
-#define __PERIPHERAL_GDBUS_SPI_H__
-
-#include "peripheral_io_gdbus.h"
-
-gboolean handle_spi_open(
-               PeripheralIoGdbusSpi *spi,
-               GDBusMethodInvocation *invocation,
-               GUnixFDList *fd_list,
-               gint bus,
-               gint cs,
-               gpointer user_data);
-
-#endif /* __PERIPHERAL_GDBUS_SPI_H__ */
diff --git a/src/daemon/include/peripheral_gdbus_uart.h b/src/daemon/include/peripheral_gdbus_uart.h
deleted file mode 100644 (file)
index 64bd84c..0000000
+++ /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_UART_H__
-#define __PERIPHERAL_GDBUS_UART_H__
-
-#include "peripheral_io_gdbus.h"
-
-gboolean handle_uart_open(
-               PeripheralIoGdbusUart *uart,
-               GDBusMethodInvocation *invocation,
-               GUnixFDList *fd_list,
-               gint port,
-               gpointer user_data);
-
-#endif /* __PERIPHERAL_GDBUS_UART_H__ */
diff --git a/src/daemon/include/peripheral_handle_gpio.h b/src/daemon/include/peripheral_handle_gpio.h
deleted file mode 100644 (file)
index 84b750f..0000000
+++ /dev/null
@@ -1,23 +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_HANDLE_GPIO_H__
-#define __PERIPHERAL_HANDLE_GPIO_H__
-
-int peripheral_bus_gpio_open(gint pin, pb_data_h *handle, gpointer user_data);
-int peripheral_bus_gpio_close(pb_data_h handle);
-
-#endif /* __PERIPHERAL_HANDLE_GPIO_H__ */
diff --git a/src/daemon/include/peripheral_handle_i2c.h b/src/daemon/include/peripheral_handle_i2c.h
deleted file mode 100644 (file)
index 04bcd56..0000000
+++ /dev/null
@@ -1,23 +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_HANDLE_I2C_H__
-#define __PERIPHERAL_HANDLE_I2C_H__
-
-int peripheral_bus_i2c_open(int bus, int address, pb_data_h *handle, gpointer user_data);
-int peripheral_bus_i2c_close(pb_data_h handle);
-
-#endif /* __PERIPHERAL_HANDLE_I2C_H__ */
diff --git a/src/daemon/include/peripheral_handle_pwm.h b/src/daemon/include/peripheral_handle_pwm.h
deleted file mode 100644 (file)
index f42a396..0000000
+++ /dev/null
@@ -1,23 +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_HANDLE_PWM_H__
-#define __PERIPHERAL_HANDLE_PWM_H__
-
-int peripheral_bus_pwm_open(int chip, int pin, pb_data_h *handle, gpointer user_data);
-int peripheral_bus_pwm_close(pb_data_h handle);
-
-#endif /* __PERIPHERAL_HANDLE_PWM_H__ */
diff --git a/src/daemon/include/peripheral_handle_spi.h b/src/daemon/include/peripheral_handle_spi.h
deleted file mode 100644 (file)
index c0feda1..0000000
+++ /dev/null
@@ -1,23 +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_HANDLE_SPI_H__
-#define __PERIPHERAL_HANDLE_SPI_H__
-
-int peripheral_bus_spi_open(int bus, int cs, pb_data_h *handle, gpointer user_data);
-int peripheral_bus_spi_close(pb_data_h handle);
-
-#endif /* __PERIPHERAL_HANDLE_SPI_H__ */
diff --git a/src/daemon/include/peripheral_handle_uart.h b/src/daemon/include/peripheral_handle_uart.h
deleted file mode 100644 (file)
index 57165b2..0000000
+++ /dev/null
@@ -1,23 +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_HANDLE_UART_H__
-#define __PERIPHERAL_HANDLE_UART_H__
-
-int peripheral_bus_uart_open(int port, pb_data_h *handle, gpointer user_data);
-int peripheral_bus_uart_close(pb_data_h handle);
-
-#endif /* __PERIPHERAL_HANDLE_UART_H__ */
diff --git a/src/daemon/include/peripheral_log.h b/src/daemon/include/peripheral_log.h
deleted file mode 100644 (file)
index 7198845..0000000
+++ /dev/null
@@ -1,58 +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_LOG_H__
-#define __PERIPHERAL_LOG_H__
-
-#include <unistd.h>
-#include <dlog.h>
-
-#undef LOG_TAG
-#define LOG_TAG "PERIPHERAL-BUS"
-
-#define _E(fmt, arg...) LOGE(fmt, ##arg)
-#define _D(fmt, arg...) LOGD(fmt, ##arg)
-#define _W(fmt, arg...) LOGW(fmt, ##arg)
-
-#define RET_IF(expr) \
-       do { \
-               if (expr) { \
-                       _E("(%s)", #expr); \
-                       return; \
-               } \
-       } while (0)
-#define RETV_IF(expr, val) \
-       do {\
-               if (expr) { \
-                       _E("(%s)", #expr); \
-                       return (val); \
-               } \
-       } while (0)
-#define RETM_IF(expr, fmt, arg...) \
-       do {\
-               if (expr) { \
-                       _E(fmt, ##arg); \
-                       return; \
-               } \
-       } while (0)
-#define RETVM_IF(expr, val, fmt, arg...) \
-       do {\
-               if (expr) { \
-                       _E(fmt, ##arg); \
-                       return (val); \
-               } \
-       } while (0)
-
-#endif /* __PERIPHERAL_COMMON_H__ */
diff --git a/src/daemon/include/privilege_checker.h b/src/daemon/include/privilege_checker.h
deleted file mode 100644 (file)
index a39fb8d..0000000
+++ /dev/null
@@ -1,26 +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 __PRIVILEGE_CHECKER_H__
-#define __PRIVILEGE_CHECKER_H__
-
-#include <stdbool.h>
-
-void peripheral_privilege_init(void);
-void peripheral_privilege_deinit(void);
-bool peripheral_privilege_check(const char* client, const char* session, const char* user, const char* privilege);
-
-#endif /* __PRIVILEGE_CHECKER_H__ */
diff --git a/src/daemon/peripheral_bus.c b/src/daemon/peripheral_bus.c
deleted file mode 100644 (file)
index d4c038f..0000000
+++ /dev/null
@@ -1,295 +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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <gio/gio.h>
-#include <systemd/sd-daemon.h>
-
-#include <peripheral_io.h>
-
-#include "peripheral_io_gdbus.h"
-#include "peripheral_bus.h"
-#include "peripheral_log.h"
-#include "peripheral_gdbus_gpio.h"
-#include "peripheral_gdbus_i2c.h"
-#include "peripheral_gdbus_pwm.h"
-#include "peripheral_gdbus_spi.h"
-#include "peripheral_gdbus_uart.h"
-
-#include "privilege_checker.h"
-
-#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"
-
-static gboolean __gpio_init(peripheral_bus_s *pb_data)
-{
-       GDBusObjectManagerServer *manager;
-       gboolean ret = FALSE;
-       GError *error = NULL;
-
-       /* Add interface to default object path */
-       pb_data->gpio_skeleton = peripheral_io_gdbus_gpio_skeleton_new();
-       /* Register for method callbacks as signal callbacks */
-       g_signal_connect(pb_data->gpio_skeleton,
-                       "handle-open",
-                       G_CALLBACK(handle_gpio_open),
-                       pb_data);
-
-       manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_GPIO_PATH);
-
-       /* Set connection to 'manager' */
-       g_dbus_object_manager_server_set_connection(manager, pb_data->connection);
-
-       /* Export 'manager' interface on peripheral-io DBUS */
-       ret = g_dbus_interface_skeleton_export(
-               G_DBUS_INTERFACE_SKELETON(pb_data->gpio_skeleton),
-               pb_data->connection, PERIPHERAL_GDBUS_GPIO_PATH, &error);
-
-       if (ret == FALSE) {
-               _E("Can not skeleton_export %s", error->message);
-               g_error_free(error);
-       }
-
-       return true;
-}
-
-static gboolean __i2c_init(peripheral_bus_s *pb_data)
-{
-       GDBusObjectManagerServer *manager;
-       gboolean ret = FALSE;
-       GError *error = NULL;
-
-       /* Add interface to default object path */
-       pb_data->i2c_skeleton = peripheral_io_gdbus_i2c_skeleton_new();
-       g_signal_connect(pb_data->i2c_skeleton,
-                       "handle-open",
-                       G_CALLBACK(handle_i2c_open),
-                       pb_data);
-
-       manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_I2C_PATH);
-
-       /* Set connection to 'manager' */
-       g_dbus_object_manager_server_set_connection(manager, pb_data->connection);
-
-       /* Export 'manager' interface on peripheral-io DBUS */
-       ret = g_dbus_interface_skeleton_export(
-               G_DBUS_INTERFACE_SKELETON(pb_data->i2c_skeleton),
-               pb_data->connection, PERIPHERAL_GDBUS_I2C_PATH, &error);
-
-       if (ret == FALSE) {
-               _E("Can not skeleton_export %s", error->message);
-               g_error_free(error);
-       }
-
-       return true;
-}
-
-static gboolean __pwm_init(peripheral_bus_s *pb_data)
-{
-       GDBusObjectManagerServer *manager;
-       gboolean ret = FALSE;
-       GError *error = NULL;
-
-       /* Add interface to default object path */
-       pb_data->pwm_skeleton = peripheral_io_gdbus_pwm_skeleton_new();
-       g_signal_connect(pb_data->pwm_skeleton,
-                       "handle-open",
-                       G_CALLBACK(handle_pwm_open),
-                       pb_data);
-
-       manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_PWM_PATH);
-
-       /* Set connection to 'manager' */
-       g_dbus_object_manager_server_set_connection(manager, pb_data->connection);
-
-       /* Export 'manager' interface on peripheral-io DBUS */
-       ret = g_dbus_interface_skeleton_export(
-               G_DBUS_INTERFACE_SKELETON(pb_data->pwm_skeleton),
-               pb_data->connection, PERIPHERAL_GDBUS_PWM_PATH, &error);
-
-       if (ret == FALSE) {
-               _E("Can not skeleton_export %s", error->message);
-               g_error_free(error);
-       }
-
-       return true;
-}
-
-static gboolean __uart_init(peripheral_bus_s *pb_data)
-{
-       GDBusObjectManagerServer *manager;
-       gboolean ret = FALSE;
-       GError *error = NULL;
-
-       /* Add interface to default object path */
-       pb_data->uart_skeleton = peripheral_io_gdbus_uart_skeleton_new();
-       g_signal_connect(pb_data->uart_skeleton,
-                       "handle-open",
-                       G_CALLBACK(handle_uart_open),
-                       pb_data);
-
-       manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_UART_PATH);
-
-       /* Set connection to 'manager' */
-       g_dbus_object_manager_server_set_connection(manager, pb_data->connection);
-
-       /* Export 'manager' interface on peripheral-io DBUS */
-       ret = g_dbus_interface_skeleton_export(
-               G_DBUS_INTERFACE_SKELETON(pb_data->uart_skeleton),
-               pb_data->connection, PERIPHERAL_GDBUS_UART_PATH, &error);
-
-       if (ret == FALSE) {
-               _E("Can not skeleton_export %s", error->message);
-               g_error_free(error);
-       }
-
-       return true;
-}
-
-static gboolean __spi_init(peripheral_bus_s *pb_data)
-{
-       GDBusObjectManagerServer *manager;
-       gboolean ret = FALSE;
-       GError *error = NULL;
-
-       /* Add interface to default object path */
-       pb_data->spi_skeleton = peripheral_io_gdbus_spi_skeleton_new();
-       g_signal_connect(pb_data->spi_skeleton,
-                       "handle-open",
-                       G_CALLBACK(handle_spi_open),
-                       pb_data);
-
-       manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_SPI_PATH);
-
-       /* Set connection to 'manager' */
-       g_dbus_object_manager_server_set_connection(manager, pb_data->connection);
-
-       /* Export 'manager' interface on peripheral-io DBUS */
-       ret = g_dbus_interface_skeleton_export(
-               G_DBUS_INTERFACE_SKELETON(pb_data->spi_skeleton),
-               pb_data->connection, PERIPHERAL_GDBUS_SPI_PATH, &error);
-
-       if (ret == FALSE) {
-               _E("Can not skeleton_export %s", error->message);
-               g_error_free(error);
-       }
-
-       return true;
-}
-
-static void on_bus_acquired(GDBusConnection *connection,
-                                                       const gchar *name,
-                                                       gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-
-       pb_data->connection = connection;
-
-       if (__gpio_init(pb_data) == FALSE)
-               _E("Can not signal connect");
-
-       if (__i2c_init(pb_data) == FALSE)
-               _E("Can not signal connect");
-
-       if (__pwm_init(pb_data) == FALSE)
-               _E("Can not signal connect");
-
-       if (__uart_init(pb_data) == FALSE)
-               _E("Can not signal connect");
-
-       if (__spi_init(pb_data) == FALSE)
-               _E("Can not signal connect");
-}
-
-static void on_name_acquired(GDBusConnection *conn,
-                               const gchar *name, gpointer user_data)
-{
-}
-
-static void on_name_lost(GDBusConnection *conn,
-                               const gchar *name, gpointer user_data)
-{
-       _E("Dbus name is lost!");
-}
-
-static gboolean peripheral_bus_notify(gpointer data)
-{
-       _D("sd_notify(READY=1)");
-       sd_notify(0, "READY=1");
-
-       return G_SOURCE_REMOVE;
-}
-
-int main(int argc, char *argv[])
-{
-       GMainLoop *loop;
-       guint owner_id = 0;
-       peripheral_bus_s *pb_data;
-
-       pb_data = (peripheral_bus_s*)calloc(1, sizeof(peripheral_bus_s));
-       if (pb_data == NULL) {
-               _E("failed to allocate peripheral_bus_s");
-               return -1;
-       }
-
-       pb_data->board = peripheral_bus_board_init();
-       if (pb_data->board == NULL) {
-               _E("failed to init board");
-               return -1;
-       }
-
-       owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
-                                                         PERIPHERAL_GDBUS_NAME,
-                                                         (GBusNameOwnerFlags) (G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT
-                                                         | G_BUS_NAME_OWNER_FLAGS_REPLACE),
-                                                         on_bus_acquired,
-                                                         on_name_acquired,
-                                                         on_name_lost,
-                                                         pb_data,
-                                                         NULL);
-       if (!owner_id) {
-               _E("g_bus_own_name_error");
-               free(pb_data);
-               return -1;
-       }
-
-       loop = g_main_loop_new(NULL, FALSE);
-
-       g_idle_add(peripheral_bus_notify, NULL);
-
-       peripheral_privilege_init();
-
-       _D("Enter main loop!");
-       g_main_loop_run(loop);
-
-       peripheral_privilege_deinit();
-
-       if (pb_data) {
-               peripheral_bus_board_deinit(pb_data->board);
-               free(pb_data);
-       }
-
-       if (loop != NULL)
-               g_main_loop_unref(loop);
-
-       return 0;
-}
diff --git a/src/daemon/peripheral_bus_board.c b/src/daemon/peripheral_bus_board.c
deleted file mode 100644 (file)
index 48e2a0d..0000000
+++ /dev/null
@@ -1,274 +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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <iniparser.h>
-
-#include <peripheral_io.h>
-
-#include "peripheral_bus_board.h"
-#include "peripheral_log.h"
-
-#define STR_BUF_MAX 255
-
-#define BOARD_INI_BASE SYSCONFDIR "/peripheral-bus/"
-
-#define BOARD_INI_ARTIK710_PATH BOARD_INI_BASE "pio_board_artik710.ini"
-#define BOARD_INI_ARTIK520_PATH BOARD_INI_BASE "pio_board_artik520.ini"
-#define BOARD_INI_RP3_B_PATH    BOARD_INI_BASE "pio_board_rp3_b.ini"
-#define BOARD_INI_UNKNOWN_PATH  BOARD_INI_BASE "pio_board_unknown.ini"
-
-static const pb_board_type_s pb_board_type[] = {
-       {PB_BOARD_ARTIK710, "artik710 raptor", BOARD_INI_ARTIK710_PATH},
-       {PB_BOARD_ARTIK530, "artik530 raptor", BOARD_INI_ARTIK710_PATH},
-       {PB_BOARD_ARTIK520, "ARTIK5 board",    BOARD_INI_ARTIK520_PATH},
-       {PB_BOARD_RP3_B,    "Raspberry Pi 3 Model B", BOARD_INI_RP3_B_PATH},
-       {PB_BOARD_UNKNOWN,  "unknown board",   BOARD_INI_UNKNOWN_PATH},
-};
-
-static int peripheral_bus_board_get_device_type(char *string)
-{
-       if (0 == strncmp(string, "gpio", strlen("gpio")))
-               return PB_BOARD_DEV_GPIO;
-       else if (0 == strncmp(string, "i2c", strlen("i2c")))
-               return PB_BOARD_DEV_I2C;
-       else if (0 == strncmp(string, "pwm", strlen("pwm")))
-               return PB_BOARD_DEV_PWM;
-       else if (0 == strncmp(string, "uart", strlen("uart")))
-               return PB_BOARD_DEV_UART;
-       else if (0 == strncmp(string, "spi", strlen("spi")))
-               return PB_BOARD_DEV_SPI;
-
-       return -1;
-}
-
-static void peripheral_bus_board_ini_parse_key(pb_board_dev_e type, char *string, unsigned int *args)
-{
-       switch (type) {
-       case PB_BOARD_DEV_GPIO:
-               sscanf(string, "%*50[^0-9]%d", &args[0]);
-               break;
-       case PB_BOARD_DEV_I2C:
-               sscanf(string, "%*50[^-]-%d", &args[0]);
-               break;
-       case PB_BOARD_DEV_PWM:
-               sscanf(string, "%*50[^0-9]%d%*50[^0-9]%d", &args[0], &args[1]);
-               break;
-       case PB_BOARD_DEV_UART:
-               sscanf(string, "%*50[^0-9]%d", &args[0]);
-               break;
-       case PB_BOARD_DEV_SPI:
-               sscanf(string, "%*50[^0-9]%d.%d", &args[0], &args[1]);
-               break;
-       default:
-               break;
-       }
-}
-
-static int peripheral_bus_board_ini_parse_pins(char *string, unsigned int *pins)
-{
-       const char delimiter[] = ", ";
-       int cnt_pins = 0;
-       char *token, *ptr = NULL;
-
-       if (string == NULL) return 0;
-
-       token = strtok_r(string, delimiter, &ptr);
-       while (token) {
-               if (cnt_pins >= BOARD_PINS_MAX) break;
-
-               pins[cnt_pins++] = atoi(token);
-               token = strtok_r(NULL, delimiter, &ptr);
-       }
-
-       return cnt_pins;
-}
-
-static int peripheral_bus_board_ini_get_nkeys(dictionary *dict)
-{
-       int i, sec_num, key_num, ret = 0;
-       char *section;
-
-       sec_num = iniparser_getnsec(dict);
-       for (i = 0; i < sec_num; i++) {
-               section = iniparser_getsecname(dict, i);
-               key_num = iniparser_getsecnkeys(dict, section);
-               if (key_num <= 0) continue;
-               ret += key_num;
-       }
-
-       return ret;
-}
-
-static int peripheral_bus_board_get_type(void)
-{
-       int fd, i, ret = 0;
-       char str_buf[STR_BUF_MAX] = {0};
-       int type = PB_BOARD_UNKNOWN;
-
-       fd = open(BOARD_DEVICE_TREE, O_RDONLY);
-       if (fd < 0) {
-               strerror_r(errno, str_buf, STR_BUF_MAX);
-               _E("Cannot open %s, errmsg : %s", BOARD_DEVICE_TREE, str_buf);
-               return -ENXIO;
-       }
-
-       ret = read(fd, str_buf, STR_BUF_MAX);
-       if (ret < 0) {
-               _E("Failed to read model information, path: %s, ret: %d", BOARD_DEVICE_TREE, ret);
-               close(fd);
-               return -EIO;
-       }
-
-       str_buf[STR_BUF_MAX - 1] = '\0';
-
-       for (i = 0; i < PB_BOARD_UNKNOWN; i++) {
-               if (strstr(str_buf, pb_board_type[i].name)) {
-                       type = pb_board_type[i].type;
-                       break;
-               }
-       }
-
-       close(fd);
-
-       return type;
-}
-
-static pb_board_s *peripheral_bus_board_get_info()
-{
-       dictionary *dict = NULL;
-       int i, j, ret;
-       int sec_num, key_num, cnt_key = 0;
-       pb_board_dev_s *dev;
-       pb_board_dev_e enum_dev;
-       pb_board_s *board;
-
-       board = (pb_board_s*)calloc(1, sizeof(pb_board_s));
-       if (board == NULL) {
-               _E("Failed to allocate pb_board_s");
-               return NULL;
-       }
-
-       ret = peripheral_bus_board_get_type();
-       if (ret < 0) {
-               _E("Failed to get board type");
-               goto err_get_type;
-       }
-
-       board->type = (pb_board_type_e)ret;
-       dict = iniparser_load(pb_board_type[board->type].path);
-       if (dict == NULL) {
-               _E("Failed to load %s", pb_board_type[board->type].path);
-               goto err_get_type;
-       }
-
-       board->num_dev = peripheral_bus_board_ini_get_nkeys(dict);
-       if (board->num_dev == 0) {
-               _E("There is no device to open");
-               goto err_get_nkeys;
-       }
-
-       board->dev = calloc(board->num_dev, sizeof(pb_board_dev_s));
-       if (board->dev == NULL) {
-               _E("Failed to allocate pb_board_dev_s");
-               goto err_get_nkeys;
-       }
-
-       sec_num = iniparser_getnsec(dict);
-       for (i = 0; i < sec_num; i++) {
-               char *section, *key_str;
-               char **key_list = NULL;
-
-               section = iniparser_getsecname(dict, i);
-               ret = peripheral_bus_board_get_device_type(section);
-               if (ret < 0) continue;
-
-               enum_dev = (pb_board_dev_e)ret;
-               key_list = iniparser_getseckeys(dict, section);
-               key_num = iniparser_getsecnkeys(dict, section);
-               if (key_num <= 0) continue;
-
-               for (j = 0; j < key_num; j++) {
-                       dev = &board->dev[cnt_key];
-                       dev->dev_type = enum_dev;
-                       key_str = iniparser_getstring(dict, key_list[j], NULL);
-                       peripheral_bus_board_ini_parse_key(dev->dev_type, key_list[j], dev->args);
-                       dev->num_pins = peripheral_bus_board_ini_parse_pins(key_str, dev->pins);
-                       cnt_key++;
-               }
-
-               if (key_list)
-                       free(key_list);
-       }
-
-       iniparser_freedict(dict);
-
-       return board;
-
-err_get_nkeys:
-       iniparser_freedict(dict);
-
-err_get_type:
-       free(board);
-       return NULL;
-}
-
-pb_board_dev_s *peripheral_bus_board_find_device(pb_board_dev_e dev_type, pb_board_s *board, int arg, ...)
-{
-       int i, args[2] = {0, };
-       va_list ap;
-
-       RETV_IF(board == NULL, false);
-
-       args[0] = arg;
-       if (dev_type == PB_BOARD_DEV_PWM || dev_type == PB_BOARD_DEV_SPI) {
-               va_start(ap, arg);
-               args[1] = va_arg(ap, int);
-               va_end(ap);
-       }
-
-       for (i = 0; i < board->num_dev; i++) {
-               if (board->dev[i].dev_type != dev_type) continue;
-
-               if (board->dev[i].args[0] == args[0] && board->dev[i].args[1] == args[1])
-                       return &board->dev[i];
-       }
-
-       return NULL;
-}
-
-pb_board_s *peripheral_bus_board_init(void)
-{
-       pb_board_s *board;
-
-       board = peripheral_bus_board_get_info();
-
-       return board;
-}
-
-void peripheral_bus_board_deinit(pb_board_s *board)
-{
-       if (board) {
-               if (board->dev)
-                       free(board->dev);
-
-               free(board);
-       }
-}
diff --git a/src/daemon/peripheral_bus_util.c b/src/daemon/peripheral_bus_util.c
deleted file mode 100644 (file)
index eb27024..0000000
+++ /dev/null
@@ -1,200 +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.
- */
-
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <gio/gio.h>
-
-#include <cynara-creds-gdbus.h>
-#include <cynara-client.h>
-#include <cynara-session.h>
-
-#include "peripheral_bus.h"
-#include "peripheral_log.h"
-
-#include "privilege_checker.h"
-
-GVariant *peripheral_bus_build_variant_ay(uint8_t *data, int length)
-{
-       GVariantBuilder *builder;
-       GVariant *variant;
-       int i;
-
-       if (data == NULL)
-               return NULL;
-
-       builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)"));
-
-       for (i = 0; i < length; i++)
-               g_variant_builder_add(builder, "(y)", data[i]);
-
-       variant = g_variant_new("a(y)", builder);
-       g_variant_builder_unref(builder);
-
-       return variant;
-}
-
-pb_data_h peripheral_bus_data_new(GList **plist)
-{
-       GList *list = *plist;
-       pb_data_h handle;
-
-       handle = (pb_data_h)calloc(1, sizeof(peripheral_bus_data_s));
-       if (handle == NULL) {
-               _E("failed to allocate peripheral_bus_data_s");
-               return NULL;
-       }
-
-       *plist = g_list_append(list, handle);
-
-       return handle;
-}
-
-int peripheral_bus_data_free(pb_data_h handle)
-{
-       GList *list = *handle->list;
-       GList *link;
-
-       RETVM_IF(handle == NULL, -1, "handle is null");
-
-       link = g_list_find(list, handle);
-       if (!link) {
-               _E("handle does not exist in list");
-               return -1;
-       }
-
-       *handle->list = g_list_remove_link(list, link);
-
-       free(handle);
-       g_list_free(link);
-
-       return 0;
-}
-
-int peripheral_bus_check_privilege(
-               GDBusMethodInvocation *invocation,
-               peripheral_bus_s *pb_data)
-{
-       int pid;
-       const char *sender;
-       char *session;
-       char *client;
-       char *user;
-
-       sender = g_dbus_method_invocation_get_sender(invocation);
-
-       cynara_creds_gdbus_get_pid(pb_data->connection, sender, &pid);
-       session = cynara_session_from_pid(pid);
-
-       cynara_creds_gdbus_get_client(pb_data->connection, sender, CLIENT_METHOD_DEFAULT, &client);
-       cynara_creds_gdbus_get_user(pb_data->connection, sender, USER_METHOD_DEFAULT, &user);
-
-       if (!session || !client || !user) {
-               _E("Failed to get client info");
-               return -1;
-       }
-
-       if (!peripheral_privilege_check(client, session, user, PERIPHERAL_PRIVILEGE)) {
-               g_free(session);
-               g_free(client);
-               g_free(user);
-               return -EACCES;
-       }
-
-       g_free(session);
-       g_free(client);
-       g_free(user);
-
-       return 0;
-}
-
-int peripheral_bus_get_client_info(
-               GDBusMethodInvocation *invocation,
-               peripheral_bus_s *pb_data,
-               pb_client_info_s *client_info)
-{
-       guint pid = 0;
-       GError *error = NULL;
-       GVariant *_ret;
-       const gchar *id;
-       int err;
-
-       id = g_dbus_method_invocation_get_sender(invocation);
-       if (id == NULL) {
-               _E("Current id is NULL");
-               return -1;
-       }
-
-       _ret = g_dbus_connection_call_sync(pb_data->connection,
-               "org.freedesktop.DBus",
-               "/org/freedesktop/DBus",
-               "org.freedesktop.DBus",
-               "GetConnectionUnixProcessID",
-               g_variant_new("(s)", id),
-               NULL,
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               &error);
-
-       if (_ret == NULL) {
-               _E("Failed to get client pid, %s", error->message);
-               g_error_free(error);
-
-               return -1;
-       }
-
-       g_variant_get(_ret, "(u)", &pid);
-       g_variant_unref(_ret);
-
-       if ((err = peripheral_bus_check_privilege(invocation, pb_data)) < 0) {
-               _E("Permission denied(%d)", pid);
-               return err;
-       }
-
-       client_info->pid = (pid_t)pid;
-       client_info->pgid = getpgid(pid);
-       client_info->id = strdup(id);
-
-       return 0;
-}
-
-int peripheral_bus_handle_is_valid(
-               GDBusMethodInvocation *invocation,
-               pb_data_h handle,
-               GList *list)
-{
-       const gchar *id;
-
-       if (!g_list_find(list, handle)) {
-               _E("Cannot find handle");
-               return -1;
-       }
-
-       id = g_dbus_method_invocation_get_sender(invocation);
-       if (id == NULL) {
-               _E("Current id is NULL");
-               return -1;
-       }
-
-       if (strcmp(handle->client_info.id, id)) {
-               _E("Invalid access, handle id : %s, current id : %s", handle->client_info.id, id);
-               return -1;
-       }
-
-       return 0;
-}
diff --git a/src/daemon/peripheral_gdbus_gpio.c b/src/daemon/peripheral_gdbus_gpio.c
deleted file mode 100644 (file)
index 685c826..0000000
+++ /dev/null
@@ -1,73 +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 <peripheral_io.h>
-#include <gio/gunixfdlist.h>
-
-#include "peripheral_io_gdbus.h"
-#include "peripheral_bus.h"
-#include "peripheral_handle_gpio.h"
-#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
-#include "peripheral_gdbus_gpio.h"
-
-static void __gpio_on_name_vanished(GDBusConnection *connection,
-               const gchar     *name,
-               gpointer         user_data)
-{
-       pb_data_h gpio_handle = (pb_data_h)user_data;
-       _D("appid [%s] vanished ", name);
-
-       g_bus_unwatch_name(gpio_handle->watch_id);
-       peripheral_bus_gpio_close(gpio_handle);
-}
-
-gboolean handle_gpio_open(
-               PeripheralIoGdbusGpio *gpio,
-               GDBusMethodInvocation *invocation,
-               GUnixFDList *fd_list,
-               gint pin,
-               gpointer user_data)
-{
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       pb_data_h gpio_handle = NULL;
-
-       GUnixFDList *gpio_fd_list = NULL;
-
-       ret = peripheral_bus_check_privilege(invocation, pb_data);
-       if (ret != 0) {
-               _E("Permission denied.");
-               ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
-               goto out;
-       }
-
-       if ((ret = peripheral_bus_gpio_open(pin, &gpio_handle, user_data)) < PERIPHERAL_ERROR_NONE)
-               goto out;
-
-       gpio_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
-                       g_dbus_method_invocation_get_sender(invocation),
-                       G_BUS_NAME_WATCHER_FLAGS_NONE,
-                       NULL,
-                       __gpio_on_name_vanished,
-                       gpio_handle,
-                       NULL);
-
-out:
-       peripheral_io_gdbus_gpio_complete_open(gpio, invocation, gpio_fd_list, GPOINTER_TO_UINT(gpio_handle), ret);
-
-       return true;
-}
\ No newline at end of file
diff --git a/src/daemon/peripheral_gdbus_i2c.c b/src/daemon/peripheral_gdbus_i2c.c
deleted file mode 100644 (file)
index 5272fc7..0000000
+++ /dev/null
@@ -1,73 +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 <peripheral_io.h>
-
-#include "peripheral_io_gdbus.h"
-#include "peripheral_bus.h"
-#include "peripheral_handle_i2c.h"
-#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
-#include "peripheral_gdbus_i2c.h"
-
-static void __i2c_on_name_vanished(GDBusConnection *connection,
-               const gchar     *name,
-               gpointer         user_data)
-{
-       pb_data_h i2c_handle = (pb_data_h)user_data;
-       _D("appid [%s] vanished ", name);
-
-       g_bus_unwatch_name(i2c_handle->watch_id);
-       peripheral_bus_i2c_close(i2c_handle);
-}
-
-gboolean handle_i2c_open(
-               PeripheralIoGdbusI2c *i2c,
-               GDBusMethodInvocation *invocation,
-               GUnixFDList *fd_list,
-               gint bus,
-               gint address,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h i2c_handle = NULL;
-
-       GUnixFDList *i2c_fd_list = NULL;
-
-       ret = peripheral_bus_check_privilege(invocation, pb_data);
-       if (ret != 0) {
-               _E("Permission denied.");
-               ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
-               goto out;
-       }
-
-       if ((ret = peripheral_bus_i2c_open(bus, address, &i2c_handle, user_data)) < PERIPHERAL_ERROR_NONE)
-               goto out;
-
-       i2c_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
-                       g_dbus_method_invocation_get_sender(invocation),
-                       G_BUS_NAME_WATCHER_FLAGS_NONE,
-                       NULL,
-                       __i2c_on_name_vanished,
-                       i2c_handle,
-                       NULL);
-
-out:
-       peripheral_io_gdbus_i2c_complete_open(i2c, invocation, i2c_fd_list, GPOINTER_TO_UINT(i2c_handle), ret);
-
-       return true;
-}
diff --git a/src/daemon/peripheral_gdbus_pwm.c b/src/daemon/peripheral_gdbus_pwm.c
deleted file mode 100644 (file)
index 7c40024..0000000
+++ /dev/null
@@ -1,73 +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 <peripheral_io.h>
-
-#include "peripheral_io_gdbus.h"
-#include "peripheral_bus.h"
-#include "peripheral_handle_pwm.h"
-#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
-#include "peripheral_gdbus_pwm.h"
-
-static void __pwm_on_name_vanished(GDBusConnection *connection,
-               const gchar     *name,
-               gpointer         user_data)
-{
-       pb_data_h pwm_handle = (pb_data_h)user_data;
-       _D("appid [%s] vanished ", name);
-
-       g_bus_unwatch_name(pwm_handle->watch_id);
-       peripheral_bus_pwm_close(pwm_handle);
-}
-
-gboolean handle_pwm_open(
-               PeripheralIoGdbusPwm *pwm,
-               GDBusMethodInvocation *invocation,
-               GUnixFDList *fd_list,
-               gint chip,
-               gint pin,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h pwm_handle = NULL;
-
-       GUnixFDList *pwm_fd_list = NULL;
-
-       ret = peripheral_bus_check_privilege(invocation, pb_data);
-       if (ret != 0) {
-               _E("Permission denied.");
-               ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
-               goto out;
-       }
-
-       if ((ret = peripheral_bus_pwm_open(chip, pin, &pwm_handle, user_data)) <  PERIPHERAL_ERROR_NONE)
-               goto out;
-
-       pwm_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
-                       g_dbus_method_invocation_get_sender(invocation),
-                       G_BUS_NAME_WATCHER_FLAGS_NONE,
-                       NULL,
-                       __pwm_on_name_vanished,
-                       pwm_handle,
-                       NULL);
-
-out:
-       peripheral_io_gdbus_pwm_complete_open(pwm, invocation, pwm_fd_list, GPOINTER_TO_UINT(pwm_handle), ret);
-
-       return true;
-}
diff --git a/src/daemon/peripheral_gdbus_spi.c b/src/daemon/peripheral_gdbus_spi.c
deleted file mode 100644 (file)
index d8b590d..0000000
+++ /dev/null
@@ -1,74 +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 <peripheral_io.h>
-
-#include "peripheral_io_gdbus.h"
-#include "peripheral_bus.h"
-#include "peripheral_handle_spi.h"
-#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
-#include "peripheral_gdbus_spi.h"
-
-static void __spi_on_name_vanished(GDBusConnection *connection,
-               const gchar     *name,
-               gpointer         user_data)
-{
-       pb_data_h spi_handle = (pb_data_h)user_data;
-       _D("appid [%s] vanished ", name);
-
-       g_bus_unwatch_name(spi_handle->watch_id);
-       peripheral_bus_spi_close(spi_handle);
-}
-
-gboolean handle_spi_open(
-               PeripheralIoGdbusSpi *spi,
-               GDBusMethodInvocation *invocation,
-               GUnixFDList *fd_list,
-               gint bus,
-               gint cs,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h spi_handle = NULL;
-
-       GUnixFDList *spi_fd_list = NULL;
-
-       ret = peripheral_bus_check_privilege(invocation, pb_data);
-       if (ret != 0) {
-               _E("Permission denied.");
-               ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
-               goto out;
-       }
-
-       if ((ret = peripheral_bus_spi_open(bus, cs, &spi_handle, user_data)) < PERIPHERAL_ERROR_NONE)
-               goto out;
-
-       spi_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
-                       g_dbus_method_invocation_get_sender(invocation),
-                       G_BUS_NAME_WATCHER_FLAGS_NONE,
-                       NULL,
-                       __spi_on_name_vanished,
-                       spi_handle,
-                       NULL);
-
-out:
-       peripheral_io_gdbus_spi_complete_open(spi, invocation, spi_fd_list, GPOINTER_TO_UINT(spi_handle), ret);
-
-       return true;
-}
-
diff --git a/src/daemon/peripheral_gdbus_uart.c b/src/daemon/peripheral_gdbus_uart.c
deleted file mode 100644 (file)
index 06d028b..0000000
+++ /dev/null
@@ -1,72 +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 <peripheral_io.h>
-
-#include "peripheral_io_gdbus.h"
-#include "peripheral_bus.h"
-#include "peripheral_handle_uart.h"
-#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
-#include "peripheral_gdbus_uart.h"
-
-static void __uart_on_name_vanished(GDBusConnection *connection,
-               const gchar     *name,
-               gpointer         user_data)
-{
-       pb_data_h uart_handle = (pb_data_h)user_data;
-       _D("appid [%s] vanished ", name);
-
-       g_bus_unwatch_name(uart_handle->watch_id);
-       peripheral_bus_uart_close(uart_handle);
-}
-
-gboolean handle_uart_open(
-               PeripheralIoGdbusUart *uart,
-               GDBusMethodInvocation *invocation,
-               GUnixFDList *fd_list,
-               gint port,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h uart_handle = NULL;
-
-       GUnixFDList *uart_fd_list = NULL;
-
-       ret = peripheral_bus_check_privilege(invocation, pb_data);
-       if (ret != 0) {
-               _E("Permission denied.");
-               ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
-               goto out;
-       }
-
-       if ((ret = peripheral_bus_uart_open(port, &uart_handle, user_data)) < PERIPHERAL_ERROR_NONE)
-               goto out;
-
-       uart_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
-                       g_dbus_method_invocation_get_sender(invocation),
-                       G_BUS_NAME_WATCHER_FLAGS_NONE,
-                       NULL,
-                       __uart_on_name_vanished,
-                       uart_handle,
-                       NULL);
-
-out:
-       peripheral_io_gdbus_uart_complete_open(uart, invocation, uart_fd_list, GPOINTER_TO_UINT(uart_handle), ret);
-
-       return true;
-}
diff --git a/src/daemon/peripheral_handle_gpio.c b/src/daemon/peripheral_handle_gpio.c
deleted file mode 100644 (file)
index 6ee068d..0000000
+++ /dev/null
@@ -1,182 +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 <stdio.h>
-#include <stdlib.h>
-#include <gio/gio.h>
-#include <poll.h>
-#include <sys/time.h>
-#include <libudev.h>
-
-#include <peripheral_io.h>
-
-#include "peripheral_interface_gpio.h"
-#include "peripheral_bus.h"
-#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
-
-static bool peripheral_bus_gpio_is_available(int pin, peripheral_bus_s *pb_data)
-{
-       pb_board_dev_s *gpio = NULL;
-       pb_data_h handle;
-       GList *link;
-
-       RETV_IF(pb_data == NULL, false);
-       RETV_IF(pb_data->board == NULL, false);
-
-       gpio = peripheral_bus_board_find_device(PB_BOARD_DEV_GPIO, pb_data->board, pin);
-       if (gpio == NULL) {
-               _E("Not supported GPIO pin : %d", pin);
-               return false;
-       }
-
-       link = pb_data->gpio_list;
-       while (link) {
-               handle = (pb_data_h)link->data;
-               if (handle->dev.gpio.pin == pin) {
-                       _E("gpio %d is busy", pin);
-                       return false;
-               }
-               link = g_list_next(link);
-       }
-
-       return true;
-}
-
-static int gpio_wait_for_udev(int gpiopin)
-{
-       #define GPIO_NAME_LEN 8
-       struct udev *udev;
-       struct udev_monitor *monitor;
-       struct udev_device *dev;
-       struct pollfd pfd;
-       char gpio_name[GPIO_NAME_LEN];
-       int ret = -EIO;
-
-       udev = udev_new();
-       if (!udev) {
-               _E("Cannot create udev");
-               return ret;
-       }
-
-       monitor = udev_monitor_new_from_netlink(udev, "udev");
-       if (!monitor) {
-               _E("Cannot create udev monitor");
-               udev_unref(udev);
-               return ret;
-       }
-
-       ret = udev_monitor_filter_add_match_subsystem_devtype(monitor, "gpio", NULL);
-       if (ret < 0) {
-               _E("Failed to add monitor filter");
-               goto out;
-       }
-
-       ret = udev_monitor_enable_receiving(monitor);
-       if (ret < 0) {
-               _E("Failed to enable udev receiving");
-               goto out;
-       }
-
-       pfd.fd = udev_monitor_get_fd(monitor);
-       pfd.events = POLLIN;
-
-       snprintf(gpio_name, GPIO_NAME_LEN, "gpio%d", gpiopin);
-
-       for (int cnt = 0; cnt < 10; cnt++) {
-               if (poll(&pfd, 1, 100) < 0) {
-                       _E("Failed to watch udev monitor");
-                       goto out;
-               }
-
-               dev = udev_monitor_receive_device(monitor);
-               if (dev) {
-                       if (strcmp(udev_device_get_sysname(dev), gpio_name) == 0) {
-                               _D("udev for %s is initialized", gpio_name);
-                               ret = 0;
-                               goto out;
-                       }
-               }
-       }
-       _E("Time out");
-
-out:
-       udev_monitor_unref(monitor);
-       udev_unref(udev);
-
-       return ret;
-}
-
-
-int peripheral_bus_gpio_open(gint pin, pb_data_h *handle, gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       pb_data_h gpio_handle;
-       int ret;
-
-       if (!peripheral_bus_gpio_is_available(pin, pb_data)) {
-               _E("gpio %d is not available", pin);
-               return PERIPHERAL_ERROR_RESOURCE_BUSY;
-       }
-
-       if ((ret = gpio_open(pin)) < 0) {
-               _E("gpio_open error (%d)", ret);
-               goto open_err;
-       }
-
-       gpio_handle = peripheral_bus_data_new(&pb_data->gpio_list);
-       if (!gpio_handle) {
-               _E("peripheral_bus_data_new error");
-               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
-               goto err;
-       }
-
-       if (gpio_wait_for_udev(pin) < 0) {
-               _E("device nodes are not writable");
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-               goto err;
-       }
-
-       gpio_handle->type = PERIPHERAL_BUS_TYPE_GPIO;
-       gpio_handle->list = &pb_data->gpio_list;
-       gpio_handle->dev.gpio.pin = pin;
-
-       *handle = gpio_handle;
-
-       return PERIPHERAL_ERROR_NONE;
-
-err:
-       gpio_close(pin);
-
-open_err:
-       return ret;
-}
-
-int peripheral_bus_gpio_close(pb_data_h handle)
-{
-       peripheral_bus_gpio_s *gpio = &handle->dev.gpio;
-       int ret = PERIPHERAL_ERROR_NONE;
-
-       if ((ret = gpio_close(gpio->pin)) < 0)
-               return ret;
-
-       if (peripheral_bus_data_free(handle) < 0) {
-               _E("Failed to free gpio data");
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;;
-}
diff --git a/src/daemon/peripheral_handle_i2c.c b/src/daemon/peripheral_handle_i2c.c
deleted file mode 100644 (file)
index 88f8156..0000000
+++ /dev/null
@@ -1,121 +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 <stdio.h>
-#include <stdlib.h>
-#include <gio/gio.h>
-
-#include <peripheral_io.h>
-
-#include "peripheral_interface_i2c.h"
-#include "peripheral_bus.h"
-#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
-
-#define INITIAL_BUFFER_SIZE 128
-#define MAX_BUFFER_SIZE 8192
-
-static bool peripheral_bus_i2c_is_available(int bus, int address, peripheral_bus_s *pb_data)
-{
-       pb_board_dev_s *i2c = NULL;
-       pb_data_h handle;
-       GList *link;
-
-       RETV_IF(pb_data == NULL, false);
-       RETV_IF(pb_data->board == NULL, false);
-
-       i2c = peripheral_bus_board_find_device(PB_BOARD_DEV_I2C, pb_data->board, bus);
-       if (i2c == NULL) {
-               _E("Not supported I2C bus : %d", bus);
-               return false;
-       }
-
-       link = pb_data->i2c_list;
-       while (link) {
-               handle = (pb_data_h)link->data;
-               if (handle->dev.i2c.bus == bus && handle->dev.i2c.address == address) {
-                       _E("Resource is in use, bus : %d, address : %d", bus, address);
-                       return false;
-               }
-               link = g_list_next(link);
-       }
-
-       return true;
-}
-
-int peripheral_bus_i2c_open(int bus, int address, pb_data_h *handle, gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       pb_data_h i2c_handle;
-       int ret;
-       int fd;
-
-       if (!peripheral_bus_i2c_is_available(bus, address, pb_data)) {
-               _E("bus : %d, address : 0x%x is not available", bus, address);
-               return PERIPHERAL_ERROR_RESOURCE_BUSY;
-       }
-
-       if ((ret = i2c_open(bus, &fd)) < 0) {
-               _E("i2c_open error (%d)", ret);
-               goto open_err;
-       }
-
-       if ((ret = i2c_set_address(fd, address)) < 0) {
-               _E("i2c_set_address error (%d)", ret);
-               goto err;
-       }
-
-       i2c_handle = peripheral_bus_data_new(&pb_data->i2c_list);
-       if (!i2c_handle) {
-               _E("peripheral_bus_data_new error");
-               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
-               goto err;
-       }
-
-       i2c_handle->type = PERIPHERAL_BUS_TYPE_I2C;
-       i2c_handle->list = &pb_data->i2c_list;
-       i2c_handle->dev.i2c.fd = fd;
-       i2c_handle->dev.i2c.bus = bus;
-       i2c_handle->dev.i2c.address = address;
-
-       *handle = i2c_handle;
-
-       return PERIPHERAL_ERROR_NONE;
-
-err:
-       i2c_close(fd);
-
-open_err:
-       return ret;
-}
-
-int peripheral_bus_i2c_close(pb_data_h handle)
-{
-       peripheral_bus_i2c_s *i2c = &handle->dev.i2c;
-       int ret = PERIPHERAL_ERROR_NONE;
-
-       _D("bus : %d, address : 0x%x, pgid = %d", i2c->bus, i2c->address, handle->client_info.pgid);
-
-       if ((ret = i2c_close(i2c->fd)) < 0)
-               return ret;
-
-       if (peripheral_bus_data_free(handle) < 0) {
-               _E("Failed to free i2c data");
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
diff --git a/src/daemon/peripheral_handle_pwm.c b/src/daemon/peripheral_handle_pwm.c
deleted file mode 100644 (file)
index a9c657c..0000000
+++ /dev/null
@@ -1,106 +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 <stdio.h>
-#include <stdlib.h>
-#include <gio/gio.h>
-
-#include <peripheral_io.h>
-
-#include "peripheral_interface_pwm.h"
-#include "peripheral_bus.h"
-#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
-
-static bool peripheral_bus_pwm_is_available(int chip, int pin, peripheral_bus_s *pb_data)
-{
-       pb_board_dev_s *pwm = NULL;
-       pb_data_h handle;
-       GList *link;
-
-       RETV_IF(pb_data == NULL, false);
-       RETV_IF(pb_data->board == NULL, false);
-
-       pwm = peripheral_bus_board_find_device(PB_BOARD_DEV_PWM, pb_data->board, chip, pin);
-       if (pwm == NULL) {
-               _E("Not supported PWM chip : %d, pin : %d", chip, pin);
-               return false;
-       }
-
-       link = pb_data->pwm_list;
-       while (link) {
-               handle = (pb_data_h)link->data;
-               if (handle->dev.pwm.chip == chip && handle->dev.pwm.pin == pin) {
-                       _E("Resource is in use, chip : %d, pin : %d", chip, pin);
-                       return false;
-               }
-               link = g_list_next(link);
-       }
-
-       return true;
-}
-
-int peripheral_bus_pwm_open(int chip, int pin, pb_data_h *handle, gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       pb_data_h pwm_handle;
-       int ret;
-
-       if (!peripheral_bus_pwm_is_available(chip, pin, pb_data)) {
-               _E("pwm %d.%d is not available", chip, pin);
-               return PERIPHERAL_ERROR_RESOURCE_BUSY;
-       }
-
-       if ((ret = pwm_open(chip, pin)) < 0)
-               goto open_err;
-
-       pwm_handle = peripheral_bus_data_new(&pb_data->pwm_list);
-       if (!pwm_handle) {
-               _E("peripheral_bus_data_new error");
-               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
-               goto err;
-       }
-
-       pwm_handle->type = PERIPHERAL_BUS_TYPE_PWM;
-       pwm_handle->list = &pb_data->pwm_list;
-       pwm_handle->dev.pwm.chip = chip;
-       pwm_handle->dev.pwm.pin = pin;
-       *handle = pwm_handle;
-
-       return PERIPHERAL_ERROR_NONE;
-
-err:
-       pwm_close(chip, pin);
-
-open_err:
-       return ret;
-}
-
-int peripheral_bus_pwm_close(pb_data_h handle)
-{
-       peripheral_bus_pwm_s *pwm = &handle->dev.pwm;
-       int ret = PERIPHERAL_ERROR_NONE;
-
-       if ((ret = pwm_close(pwm->chip, pwm->pin)) < 0)
-               return ret;
-
-       if (peripheral_bus_data_free(handle) < 0) {
-               _E("Failed to free i2c data");
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
diff --git a/src/daemon/peripheral_handle_spi.c b/src/daemon/peripheral_handle_spi.c
deleted file mode 100644 (file)
index e1d7f07..0000000
+++ /dev/null
@@ -1,111 +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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <gio/gio.h>
-
-#include <peripheral_io.h>
-
-#include "peripheral_interface_spi.h"
-#include "peripheral_bus.h"
-#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
-
-static bool __peripheral_bus_spi_is_available(int bus, int cs, peripheral_bus_s *pb_data)
-{
-       pb_board_dev_s *spi = NULL;
-       pb_data_h handle;
-       GList *link;
-
-       RETV_IF(pb_data == NULL, false);
-       RETV_IF(pb_data->board == NULL, false);
-
-       spi = peripheral_bus_board_find_device(PB_BOARD_DEV_SPI, pb_data->board, bus, cs);
-       if (spi == NULL) {
-               _E("Not supported SPI bus : %d, cs : %d", bus, cs);
-               return false;
-       }
-
-       link = pb_data->spi_list;
-       while (link) {
-               handle = (pb_data_h)link->data;
-               if (handle->dev.spi.bus == bus && handle->dev.spi.cs == cs) {
-                       _E("Resource is in use, bus : %d, cs : %d", bus, cs);
-                       return false;
-               }
-               link = g_list_next(link);
-       }
-
-       return true;
-}
-
-int peripheral_bus_spi_open(int bus, int cs, pb_data_h *handle, gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       pb_data_h spi_handle;
-       int ret = PERIPHERAL_ERROR_NONE;
-       int fd;
-
-       if (!__peripheral_bus_spi_is_available(bus, cs, pb_data)) {
-               _E("spi %d.%d is not available", bus, cs);
-               return PERIPHERAL_ERROR_RESOURCE_BUSY;
-       }
-
-       if ((ret = spi_open(bus, cs, &fd)) < 0) {
-               _E("spi_open error (%d)", ret);
-               goto err_open;
-       }
-
-       spi_handle = peripheral_bus_data_new(&pb_data->spi_list);
-       if (!spi_handle) {
-               _E("peripheral_bus_data_new error");
-               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
-               goto err_spi_data;
-       }
-
-       spi_handle->type = PERIPHERAL_BUS_TYPE_SPI;
-       spi_handle->list = &pb_data->spi_list;
-       spi_handle->dev.spi.fd = fd;
-       spi_handle->dev.spi.bus = bus;
-       spi_handle->dev.spi.cs = cs;
-
-       *handle = spi_handle;
-
-       return PERIPHERAL_ERROR_NONE;
-
-err_spi_data:
-       spi_close(fd);
-
-err_open:
-       return ret;
-}
-
-int peripheral_bus_spi_close(pb_data_h handle)
-{
-       peripheral_bus_spi_s *spi = &handle->dev.spi;
-       int ret = PERIPHERAL_ERROR_NONE;
-
-       if ((ret = spi_close(spi->fd)) < 0)
-               return ret;
-
-       if (peripheral_bus_data_free(handle) < 0) {
-               _E("Failed to free spi data");
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
\ No newline at end of file
diff --git a/src/daemon/peripheral_handle_uart.c b/src/daemon/peripheral_handle_uart.c
deleted file mode 100644 (file)
index a73007a..0000000
+++ /dev/null
@@ -1,116 +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 <stdio.h>
-#include <stdlib.h>
-#include <gio/gio.h>
-
-#include <peripheral_io.h>
-
-#include "peripheral_interface_uart.h"
-#include "peripheral_io_gdbus.h"
-#include "peripheral_bus.h"
-#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
-
-#define INITIAL_BUFFER_SIZE 128
-#define MAX_BUFFER_SIZE 8192
-
-static bool __peripheral_bus_uart_is_available(int port, peripheral_bus_s *pb_data)
-{
-       pb_board_dev_s *uart = NULL;
-       pb_data_h handle;
-       GList *link;
-
-       RETV_IF(pb_data == NULL, false);
-       RETV_IF(pb_data->board == NULL, false);
-
-       uart = peripheral_bus_board_find_device(PB_BOARD_DEV_UART, pb_data->board, port);
-       if (uart == NULL) {
-               _E("Not supported UART port : %d", port);
-               return false;
-       }
-
-       link = pb_data->uart_list;
-       while (link) {
-               handle = (pb_data_h)link->data;
-               if (handle->dev.uart.port == port) {
-                       _E("Resource is in use, port : %d", port);
-                       return false;
-               }
-               link = g_list_next(link);
-       }
-
-       return true;
-}
-
-int peripheral_bus_uart_open(int port, pb_data_h *handle, gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       pb_data_h uart_handle;
-       int ret = PERIPHERAL_ERROR_NONE;
-       int fd;
-
-       if (!__peripheral_bus_uart_is_available(port, pb_data)) {
-               _E("uart %d is not available", port);
-               return PERIPHERAL_ERROR_RESOURCE_BUSY;
-       }
-
-       if ((ret = uart_open(port, &fd)) < 0) {
-               _E("uart_open error (%d)", ret);
-               goto open_err;
-       }
-
-       uart_handle = peripheral_bus_data_new(&pb_data->uart_list);
-       if (!uart_handle) {
-               _E("peripheral_bus_data_new error");
-               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
-               goto err;
-       }
-
-       uart_handle->type = PERIPHERAL_BUS_TYPE_UART;
-       uart_handle->list = &pb_data->uart_list;
-       uart_handle->dev.uart.fd = fd;
-       uart_handle->dev.uart.port = port;
-
-       *handle = uart_handle;
-
-       return PERIPHERAL_ERROR_NONE;
-
-err:
-       uart_close(fd);
-
-open_err:
-       return ret;
-}
-
-int peripheral_bus_uart_close(pb_data_h handle)
-{
-       peripheral_bus_uart_s *uart = &handle->dev.uart;
-       int ret = PERIPHERAL_ERROR_NONE;
-
-       _D("uart_close, port : %d, id = %s", uart->port, handle->client_info.id);
-
-       if ((ret = uart_close(uart->fd)) < 0)
-               return ret;
-
-       if (peripheral_bus_data_free(handle) < 0) {
-               _E("Failed to free uart data");
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
\ No newline at end of file
diff --git a/src/daemon/peripheral_io.xml b/src/daemon/peripheral_io.xml
deleted file mode 100644 (file)
index 6b987a3..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<node>
-       <interface name="org.tizen.peripheral_io.gpio">
-               <method name="Open">
-                       <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
-                       <arg type="i" name="pin" direction="in"/>
-                       <arg type="u" name="handle" direction="out"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-       </interface>
-       <interface name="org.tizen.peripheral_io.i2c">
-               <method name="Open">
-                       <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
-                       <arg type="i" name="bus" direction="in"/>
-                       <arg type="i" name="address" direction="in"/>
-                       <arg type="u" name="handle" direction="out"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-       </interface>
-       <interface name="org.tizen.peripheral_io.pwm">
-               <method name="Open">
-                       <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
-                       <arg type="i" name="chip" direction="in"/>
-                       <arg type="i" name="pin" direction="in"/>
-                       <arg type="u" name="handle" direction="out"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-       </interface>
-       <interface name="org.tizen.peripheral_io.uart">
-               <method name="Open">
-                       <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
-                       <arg type="i" name="port" direction="in"/>
-                       <arg type="u" name="handle" direction="out"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-       </interface>
-       <interface name="org.tizen.peripheral_io.spi">
-               <method name="Open">
-                       <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
-                       <arg type="i" name="bus" direction="in"/>
-                       <arg type="i" name="cs" direction="in"/>
-                       <arg type="u" name="handle" direction="out"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-       </interface>
-</node>
diff --git a/src/daemon/privilege_checker.c b/src/daemon/privilege_checker.c
deleted file mode 100644 (file)
index e35298d..0000000
+++ /dev/null
@@ -1,77 +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.
- */
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <glib.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <peripheral_io.h>
-
-#include <cynara-creds-gdbus.h>
-#include <cynara-client.h>
-#include <cynara-session.h>
-
-#include "peripheral_bus.h"
-#include "peripheral_log.h"
-
-#define CACHE_SIZE  100
-
-static cynara *__cynara;
-
-void peripheral_privilege_init(void)
-{
-       int err;
-       cynara_configuration* conf = NULL;
-
-       err = cynara_configuration_create(&conf);
-       RETM_IF(err != CYNARA_API_SUCCESS, "Failed to create cynara configuration");
-
-       err = cynara_configuration_set_cache_size(conf, CACHE_SIZE);
-       if (err != CYNARA_API_SUCCESS) {
-               _E("Failed to set cynara cache size");
-               cynara_configuration_destroy(conf);
-               return;
-       }
-
-       err = cynara_initialize(&__cynara, conf);
-       cynara_configuration_destroy(conf);
-       if (err != CYNARA_API_SUCCESS) {
-               _E("Failed to initialize cynara");
-               __cynara = NULL;
-               return;
-       }
-
-       _D("Cynara initialized");
-}
-
-void peripheral_privilege_deinit(void)
-{
-       if (__cynara)
-               cynara_finish(__cynara);
-
-       _D("Cynara deinitialized");
-}
-
-bool peripheral_privilege_check(const char* client, const char* session, const char* user, const char* privilege)
-{
-       RETVM_IF(!privilege, true, "Invalid parameter");
-       RETVM_IF(!__cynara, false, "Cynara does not initialized");
-
-       int ret = cynara_check(__cynara, client, session, user, privilege);
-       return (ret == CYNARA_API_ACCESS_ALLOWED);
-}
diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c
new file mode 100644 (file)
index 0000000..685c826
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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 <peripheral_io.h>
+#include <gio/gunixfdlist.h>
+
+#include "peripheral_io_gdbus.h"
+#include "peripheral_bus.h"
+#include "peripheral_handle_gpio.h"
+#include "peripheral_log.h"
+#include "peripheral_bus_util.h"
+#include "peripheral_gdbus_gpio.h"
+
+static void __gpio_on_name_vanished(GDBusConnection *connection,
+               const gchar     *name,
+               gpointer         user_data)
+{
+       pb_data_h gpio_handle = (pb_data_h)user_data;
+       _D("appid [%s] vanished ", name);
+
+       g_bus_unwatch_name(gpio_handle->watch_id);
+       peripheral_bus_gpio_close(gpio_handle);
+}
+
+gboolean handle_gpio_open(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               GUnixFDList *fd_list,
+               gint pin,
+               gpointer user_data)
+{
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       pb_data_h gpio_handle = NULL;
+
+       GUnixFDList *gpio_fd_list = NULL;
+
+       ret = peripheral_bus_check_privilege(invocation, pb_data);
+       if (ret != 0) {
+               _E("Permission denied.");
+               ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
+               goto out;
+       }
+
+       if ((ret = peripheral_bus_gpio_open(pin, &gpio_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+               goto out;
+
+       gpio_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
+                       g_dbus_method_invocation_get_sender(invocation),
+                       G_BUS_NAME_WATCHER_FLAGS_NONE,
+                       NULL,
+                       __gpio_on_name_vanished,
+                       gpio_handle,
+                       NULL);
+
+out:
+       peripheral_io_gdbus_gpio_complete_open(gpio, invocation, gpio_fd_list, GPOINTER_TO_UINT(gpio_handle), ret);
+
+       return true;
+}
\ No newline at end of file
diff --git a/src/gdbus/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c
new file mode 100644 (file)
index 0000000..5272fc7
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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 <peripheral_io.h>
+
+#include "peripheral_io_gdbus.h"
+#include "peripheral_bus.h"
+#include "peripheral_handle_i2c.h"
+#include "peripheral_log.h"
+#include "peripheral_bus_util.h"
+#include "peripheral_gdbus_i2c.h"
+
+static void __i2c_on_name_vanished(GDBusConnection *connection,
+               const gchar     *name,
+               gpointer         user_data)
+{
+       pb_data_h i2c_handle = (pb_data_h)user_data;
+       _D("appid [%s] vanished ", name);
+
+       g_bus_unwatch_name(i2c_handle->watch_id);
+       peripheral_bus_i2c_close(i2c_handle);
+}
+
+gboolean handle_i2c_open(
+               PeripheralIoGdbusI2c *i2c,
+               GDBusMethodInvocation *invocation,
+               GUnixFDList *fd_list,
+               gint bus,
+               gint address,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h i2c_handle = NULL;
+
+       GUnixFDList *i2c_fd_list = NULL;
+
+       ret = peripheral_bus_check_privilege(invocation, pb_data);
+       if (ret != 0) {
+               _E("Permission denied.");
+               ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
+               goto out;
+       }
+
+       if ((ret = peripheral_bus_i2c_open(bus, address, &i2c_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+               goto out;
+
+       i2c_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
+                       g_dbus_method_invocation_get_sender(invocation),
+                       G_BUS_NAME_WATCHER_FLAGS_NONE,
+                       NULL,
+                       __i2c_on_name_vanished,
+                       i2c_handle,
+                       NULL);
+
+out:
+       peripheral_io_gdbus_i2c_complete_open(i2c, invocation, i2c_fd_list, GPOINTER_TO_UINT(i2c_handle), ret);
+
+       return true;
+}
diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c
new file mode 100644 (file)
index 0000000..7c40024
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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 <peripheral_io.h>
+
+#include "peripheral_io_gdbus.h"
+#include "peripheral_bus.h"
+#include "peripheral_handle_pwm.h"
+#include "peripheral_log.h"
+#include "peripheral_bus_util.h"
+#include "peripheral_gdbus_pwm.h"
+
+static void __pwm_on_name_vanished(GDBusConnection *connection,
+               const gchar     *name,
+               gpointer         user_data)
+{
+       pb_data_h pwm_handle = (pb_data_h)user_data;
+       _D("appid [%s] vanished ", name);
+
+       g_bus_unwatch_name(pwm_handle->watch_id);
+       peripheral_bus_pwm_close(pwm_handle);
+}
+
+gboolean handle_pwm_open(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               GUnixFDList *fd_list,
+               gint chip,
+               gint pin,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h pwm_handle = NULL;
+
+       GUnixFDList *pwm_fd_list = NULL;
+
+       ret = peripheral_bus_check_privilege(invocation, pb_data);
+       if (ret != 0) {
+               _E("Permission denied.");
+               ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
+               goto out;
+       }
+
+       if ((ret = peripheral_bus_pwm_open(chip, pin, &pwm_handle, user_data)) <  PERIPHERAL_ERROR_NONE)
+               goto out;
+
+       pwm_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
+                       g_dbus_method_invocation_get_sender(invocation),
+                       G_BUS_NAME_WATCHER_FLAGS_NONE,
+                       NULL,
+                       __pwm_on_name_vanished,
+                       pwm_handle,
+                       NULL);
+
+out:
+       peripheral_io_gdbus_pwm_complete_open(pwm, invocation, pwm_fd_list, GPOINTER_TO_UINT(pwm_handle), ret);
+
+       return true;
+}
diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c
new file mode 100644 (file)
index 0000000..d8b590d
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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 <peripheral_io.h>
+
+#include "peripheral_io_gdbus.h"
+#include "peripheral_bus.h"
+#include "peripheral_handle_spi.h"
+#include "peripheral_log.h"
+#include "peripheral_bus_util.h"
+#include "peripheral_gdbus_spi.h"
+
+static void __spi_on_name_vanished(GDBusConnection *connection,
+               const gchar     *name,
+               gpointer         user_data)
+{
+       pb_data_h spi_handle = (pb_data_h)user_data;
+       _D("appid [%s] vanished ", name);
+
+       g_bus_unwatch_name(spi_handle->watch_id);
+       peripheral_bus_spi_close(spi_handle);
+}
+
+gboolean handle_spi_open(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               GUnixFDList *fd_list,
+               gint bus,
+               gint cs,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h spi_handle = NULL;
+
+       GUnixFDList *spi_fd_list = NULL;
+
+       ret = peripheral_bus_check_privilege(invocation, pb_data);
+       if (ret != 0) {
+               _E("Permission denied.");
+               ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
+               goto out;
+       }
+
+       if ((ret = peripheral_bus_spi_open(bus, cs, &spi_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+               goto out;
+
+       spi_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
+                       g_dbus_method_invocation_get_sender(invocation),
+                       G_BUS_NAME_WATCHER_FLAGS_NONE,
+                       NULL,
+                       __spi_on_name_vanished,
+                       spi_handle,
+                       NULL);
+
+out:
+       peripheral_io_gdbus_spi_complete_open(spi, invocation, spi_fd_list, GPOINTER_TO_UINT(spi_handle), ret);
+
+       return true;
+}
+
diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c
new file mode 100644 (file)
index 0000000..06d028b
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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 <peripheral_io.h>
+
+#include "peripheral_io_gdbus.h"
+#include "peripheral_bus.h"
+#include "peripheral_handle_uart.h"
+#include "peripheral_log.h"
+#include "peripheral_bus_util.h"
+#include "peripheral_gdbus_uart.h"
+
+static void __uart_on_name_vanished(GDBusConnection *connection,
+               const gchar     *name,
+               gpointer         user_data)
+{
+       pb_data_h uart_handle = (pb_data_h)user_data;
+       _D("appid [%s] vanished ", name);
+
+       g_bus_unwatch_name(uart_handle->watch_id);
+       peripheral_bus_uart_close(uart_handle);
+}
+
+gboolean handle_uart_open(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               GUnixFDList *fd_list,
+               gint port,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h uart_handle = NULL;
+
+       GUnixFDList *uart_fd_list = NULL;
+
+       ret = peripheral_bus_check_privilege(invocation, pb_data);
+       if (ret != 0) {
+               _E("Permission denied.");
+               ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
+               goto out;
+       }
+
+       if ((ret = peripheral_bus_uart_open(port, &uart_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+               goto out;
+
+       uart_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
+                       g_dbus_method_invocation_get_sender(invocation),
+                       G_BUS_NAME_WATCHER_FLAGS_NONE,
+                       NULL,
+                       __uart_on_name_vanished,
+                       uart_handle,
+                       NULL);
+
+out:
+       peripheral_io_gdbus_uart_complete_open(uart, invocation, uart_fd_list, GPOINTER_TO_UINT(uart_handle), ret);
+
+       return true;
+}
diff --git a/src/gdbus/peripheral_io.xml b/src/gdbus/peripheral_io.xml
new file mode 100644 (file)
index 0000000..6b987a3
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<node>
+       <interface name="org.tizen.peripheral_io.gpio">
+               <method name="Open">
+                       <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
+                       <arg type="i" name="pin" direction="in"/>
+                       <arg type="u" name="handle" direction="out"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+       </interface>
+       <interface name="org.tizen.peripheral_io.i2c">
+               <method name="Open">
+                       <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
+                       <arg type="i" name="bus" direction="in"/>
+                       <arg type="i" name="address" direction="in"/>
+                       <arg type="u" name="handle" direction="out"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+       </interface>
+       <interface name="org.tizen.peripheral_io.pwm">
+               <method name="Open">
+                       <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
+                       <arg type="i" name="chip" direction="in"/>
+                       <arg type="i" name="pin" direction="in"/>
+                       <arg type="u" name="handle" direction="out"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+       </interface>
+       <interface name="org.tizen.peripheral_io.uart">
+               <method name="Open">
+                       <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
+                       <arg type="i" name="port" direction="in"/>
+                       <arg type="u" name="handle" direction="out"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+       </interface>
+       <interface name="org.tizen.peripheral_io.spi">
+               <method name="Open">
+                       <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
+                       <arg type="i" name="bus" direction="in"/>
+                       <arg type="i" name="cs" direction="in"/>
+                       <arg type="u" name="handle" direction="out"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+       </interface>
+</node>
diff --git a/src/handle/peripheral_handle_gpio.c b/src/handle/peripheral_handle_gpio.c
new file mode 100644 (file)
index 0000000..6ee068d
--- /dev/null
@@ -0,0 +1,182 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <gio/gio.h>
+#include <poll.h>
+#include <sys/time.h>
+#include <libudev.h>
+
+#include <peripheral_io.h>
+
+#include "peripheral_interface_gpio.h"
+#include "peripheral_bus.h"
+#include "peripheral_log.h"
+#include "peripheral_bus_util.h"
+
+static bool peripheral_bus_gpio_is_available(int pin, peripheral_bus_s *pb_data)
+{
+       pb_board_dev_s *gpio = NULL;
+       pb_data_h handle;
+       GList *link;
+
+       RETV_IF(pb_data == NULL, false);
+       RETV_IF(pb_data->board == NULL, false);
+
+       gpio = peripheral_bus_board_find_device(PB_BOARD_DEV_GPIO, pb_data->board, pin);
+       if (gpio == NULL) {
+               _E("Not supported GPIO pin : %d", pin);
+               return false;
+       }
+
+       link = pb_data->gpio_list;
+       while (link) {
+               handle = (pb_data_h)link->data;
+               if (handle->dev.gpio.pin == pin) {
+                       _E("gpio %d is busy", pin);
+                       return false;
+               }
+               link = g_list_next(link);
+       }
+
+       return true;
+}
+
+static int gpio_wait_for_udev(int gpiopin)
+{
+       #define GPIO_NAME_LEN 8
+       struct udev *udev;
+       struct udev_monitor *monitor;
+       struct udev_device *dev;
+       struct pollfd pfd;
+       char gpio_name[GPIO_NAME_LEN];
+       int ret = -EIO;
+
+       udev = udev_new();
+       if (!udev) {
+               _E("Cannot create udev");
+               return ret;
+       }
+
+       monitor = udev_monitor_new_from_netlink(udev, "udev");
+       if (!monitor) {
+               _E("Cannot create udev monitor");
+               udev_unref(udev);
+               return ret;
+       }
+
+       ret = udev_monitor_filter_add_match_subsystem_devtype(monitor, "gpio", NULL);
+       if (ret < 0) {
+               _E("Failed to add monitor filter");
+               goto out;
+       }
+
+       ret = udev_monitor_enable_receiving(monitor);
+       if (ret < 0) {
+               _E("Failed to enable udev receiving");
+               goto out;
+       }
+
+       pfd.fd = udev_monitor_get_fd(monitor);
+       pfd.events = POLLIN;
+
+       snprintf(gpio_name, GPIO_NAME_LEN, "gpio%d", gpiopin);
+
+       for (int cnt = 0; cnt < 10; cnt++) {
+               if (poll(&pfd, 1, 100) < 0) {
+                       _E("Failed to watch udev monitor");
+                       goto out;
+               }
+
+               dev = udev_monitor_receive_device(monitor);
+               if (dev) {
+                       if (strcmp(udev_device_get_sysname(dev), gpio_name) == 0) {
+                               _D("udev for %s is initialized", gpio_name);
+                               ret = 0;
+                               goto out;
+                       }
+               }
+       }
+       _E("Time out");
+
+out:
+       udev_monitor_unref(monitor);
+       udev_unref(udev);
+
+       return ret;
+}
+
+
+int peripheral_bus_gpio_open(gint pin, pb_data_h *handle, gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       pb_data_h gpio_handle;
+       int ret;
+
+       if (!peripheral_bus_gpio_is_available(pin, pb_data)) {
+               _E("gpio %d is not available", pin);
+               return PERIPHERAL_ERROR_RESOURCE_BUSY;
+       }
+
+       if ((ret = gpio_open(pin)) < 0) {
+               _E("gpio_open error (%d)", ret);
+               goto open_err;
+       }
+
+       gpio_handle = peripheral_bus_data_new(&pb_data->gpio_list);
+       if (!gpio_handle) {
+               _E("peripheral_bus_data_new error");
+               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+               goto err;
+       }
+
+       if (gpio_wait_for_udev(pin) < 0) {
+               _E("device nodes are not writable");
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+               goto err;
+       }
+
+       gpio_handle->type = PERIPHERAL_BUS_TYPE_GPIO;
+       gpio_handle->list = &pb_data->gpio_list;
+       gpio_handle->dev.gpio.pin = pin;
+
+       *handle = gpio_handle;
+
+       return PERIPHERAL_ERROR_NONE;
+
+err:
+       gpio_close(pin);
+
+open_err:
+       return ret;
+}
+
+int peripheral_bus_gpio_close(pb_data_h handle)
+{
+       peripheral_bus_gpio_s *gpio = &handle->dev.gpio;
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       if ((ret = gpio_close(gpio->pin)) < 0)
+               return ret;
+
+       if (peripheral_bus_data_free(handle) < 0) {
+               _E("Failed to free gpio data");
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;;
+}
diff --git a/src/handle/peripheral_handle_i2c.c b/src/handle/peripheral_handle_i2c.c
new file mode 100644 (file)
index 0000000..88f8156
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <gio/gio.h>
+
+#include <peripheral_io.h>
+
+#include "peripheral_interface_i2c.h"
+#include "peripheral_bus.h"
+#include "peripheral_log.h"
+#include "peripheral_bus_util.h"
+
+#define INITIAL_BUFFER_SIZE 128
+#define MAX_BUFFER_SIZE 8192
+
+static bool peripheral_bus_i2c_is_available(int bus, int address, peripheral_bus_s *pb_data)
+{
+       pb_board_dev_s *i2c = NULL;
+       pb_data_h handle;
+       GList *link;
+
+       RETV_IF(pb_data == NULL, false);
+       RETV_IF(pb_data->board == NULL, false);
+
+       i2c = peripheral_bus_board_find_device(PB_BOARD_DEV_I2C, pb_data->board, bus);
+       if (i2c == NULL) {
+               _E("Not supported I2C bus : %d", bus);
+               return false;
+       }
+
+       link = pb_data->i2c_list;
+       while (link) {
+               handle = (pb_data_h)link->data;
+               if (handle->dev.i2c.bus == bus && handle->dev.i2c.address == address) {
+                       _E("Resource is in use, bus : %d, address : %d", bus, address);
+                       return false;
+               }
+               link = g_list_next(link);
+       }
+
+       return true;
+}
+
+int peripheral_bus_i2c_open(int bus, int address, pb_data_h *handle, gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       pb_data_h i2c_handle;
+       int ret;
+       int fd;
+
+       if (!peripheral_bus_i2c_is_available(bus, address, pb_data)) {
+               _E("bus : %d, address : 0x%x is not available", bus, address);
+               return PERIPHERAL_ERROR_RESOURCE_BUSY;
+       }
+
+       if ((ret = i2c_open(bus, &fd)) < 0) {
+               _E("i2c_open error (%d)", ret);
+               goto open_err;
+       }
+
+       if ((ret = i2c_set_address(fd, address)) < 0) {
+               _E("i2c_set_address error (%d)", ret);
+               goto err;
+       }
+
+       i2c_handle = peripheral_bus_data_new(&pb_data->i2c_list);
+       if (!i2c_handle) {
+               _E("peripheral_bus_data_new error");
+               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+               goto err;
+       }
+
+       i2c_handle->type = PERIPHERAL_BUS_TYPE_I2C;
+       i2c_handle->list = &pb_data->i2c_list;
+       i2c_handle->dev.i2c.fd = fd;
+       i2c_handle->dev.i2c.bus = bus;
+       i2c_handle->dev.i2c.address = address;
+
+       *handle = i2c_handle;
+
+       return PERIPHERAL_ERROR_NONE;
+
+err:
+       i2c_close(fd);
+
+open_err:
+       return ret;
+}
+
+int peripheral_bus_i2c_close(pb_data_h handle)
+{
+       peripheral_bus_i2c_s *i2c = &handle->dev.i2c;
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       _D("bus : %d, address : 0x%x, pgid = %d", i2c->bus, i2c->address, handle->client_info.pgid);
+
+       if ((ret = i2c_close(i2c->fd)) < 0)
+               return ret;
+
+       if (peripheral_bus_data_free(handle) < 0) {
+               _E("Failed to free i2c data");
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
diff --git a/src/handle/peripheral_handle_pwm.c b/src/handle/peripheral_handle_pwm.c
new file mode 100644 (file)
index 0000000..a9c657c
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <gio/gio.h>
+
+#include <peripheral_io.h>
+
+#include "peripheral_interface_pwm.h"
+#include "peripheral_bus.h"
+#include "peripheral_log.h"
+#include "peripheral_bus_util.h"
+
+static bool peripheral_bus_pwm_is_available(int chip, int pin, peripheral_bus_s *pb_data)
+{
+       pb_board_dev_s *pwm = NULL;
+       pb_data_h handle;
+       GList *link;
+
+       RETV_IF(pb_data == NULL, false);
+       RETV_IF(pb_data->board == NULL, false);
+
+       pwm = peripheral_bus_board_find_device(PB_BOARD_DEV_PWM, pb_data->board, chip, pin);
+       if (pwm == NULL) {
+               _E("Not supported PWM chip : %d, pin : %d", chip, pin);
+               return false;
+       }
+
+       link = pb_data->pwm_list;
+       while (link) {
+               handle = (pb_data_h)link->data;
+               if (handle->dev.pwm.chip == chip && handle->dev.pwm.pin == pin) {
+                       _E("Resource is in use, chip : %d, pin : %d", chip, pin);
+                       return false;
+               }
+               link = g_list_next(link);
+       }
+
+       return true;
+}
+
+int peripheral_bus_pwm_open(int chip, int pin, pb_data_h *handle, gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       pb_data_h pwm_handle;
+       int ret;
+
+       if (!peripheral_bus_pwm_is_available(chip, pin, pb_data)) {
+               _E("pwm %d.%d is not available", chip, pin);
+               return PERIPHERAL_ERROR_RESOURCE_BUSY;
+       }
+
+       if ((ret = pwm_open(chip, pin)) < 0)
+               goto open_err;
+
+       pwm_handle = peripheral_bus_data_new(&pb_data->pwm_list);
+       if (!pwm_handle) {
+               _E("peripheral_bus_data_new error");
+               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+               goto err;
+       }
+
+       pwm_handle->type = PERIPHERAL_BUS_TYPE_PWM;
+       pwm_handle->list = &pb_data->pwm_list;
+       pwm_handle->dev.pwm.chip = chip;
+       pwm_handle->dev.pwm.pin = pin;
+       *handle = pwm_handle;
+
+       return PERIPHERAL_ERROR_NONE;
+
+err:
+       pwm_close(chip, pin);
+
+open_err:
+       return ret;
+}
+
+int peripheral_bus_pwm_close(pb_data_h handle)
+{
+       peripheral_bus_pwm_s *pwm = &handle->dev.pwm;
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       if ((ret = pwm_close(pwm->chip, pwm->pin)) < 0)
+               return ret;
+
+       if (peripheral_bus_data_free(handle) < 0) {
+               _E("Failed to free i2c data");
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
diff --git a/src/handle/peripheral_handle_spi.c b/src/handle/peripheral_handle_spi.c
new file mode 100644 (file)
index 0000000..e1d7f07
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <gio/gio.h>
+
+#include <peripheral_io.h>
+
+#include "peripheral_interface_spi.h"
+#include "peripheral_bus.h"
+#include "peripheral_log.h"
+#include "peripheral_bus_util.h"
+
+static bool __peripheral_bus_spi_is_available(int bus, int cs, peripheral_bus_s *pb_data)
+{
+       pb_board_dev_s *spi = NULL;
+       pb_data_h handle;
+       GList *link;
+
+       RETV_IF(pb_data == NULL, false);
+       RETV_IF(pb_data->board == NULL, false);
+
+       spi = peripheral_bus_board_find_device(PB_BOARD_DEV_SPI, pb_data->board, bus, cs);
+       if (spi == NULL) {
+               _E("Not supported SPI bus : %d, cs : %d", bus, cs);
+               return false;
+       }
+
+       link = pb_data->spi_list;
+       while (link) {
+               handle = (pb_data_h)link->data;
+               if (handle->dev.spi.bus == bus && handle->dev.spi.cs == cs) {
+                       _E("Resource is in use, bus : %d, cs : %d", bus, cs);
+                       return false;
+               }
+               link = g_list_next(link);
+       }
+
+       return true;
+}
+
+int peripheral_bus_spi_open(int bus, int cs, pb_data_h *handle, gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       pb_data_h spi_handle;
+       int ret = PERIPHERAL_ERROR_NONE;
+       int fd;
+
+       if (!__peripheral_bus_spi_is_available(bus, cs, pb_data)) {
+               _E("spi %d.%d is not available", bus, cs);
+               return PERIPHERAL_ERROR_RESOURCE_BUSY;
+       }
+
+       if ((ret = spi_open(bus, cs, &fd)) < 0) {
+               _E("spi_open error (%d)", ret);
+               goto err_open;
+       }
+
+       spi_handle = peripheral_bus_data_new(&pb_data->spi_list);
+       if (!spi_handle) {
+               _E("peripheral_bus_data_new error");
+               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+               goto err_spi_data;
+       }
+
+       spi_handle->type = PERIPHERAL_BUS_TYPE_SPI;
+       spi_handle->list = &pb_data->spi_list;
+       spi_handle->dev.spi.fd = fd;
+       spi_handle->dev.spi.bus = bus;
+       spi_handle->dev.spi.cs = cs;
+
+       *handle = spi_handle;
+
+       return PERIPHERAL_ERROR_NONE;
+
+err_spi_data:
+       spi_close(fd);
+
+err_open:
+       return ret;
+}
+
+int peripheral_bus_spi_close(pb_data_h handle)
+{
+       peripheral_bus_spi_s *spi = &handle->dev.spi;
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       if ((ret = spi_close(spi->fd)) < 0)
+               return ret;
+
+       if (peripheral_bus_data_free(handle) < 0) {
+               _E("Failed to free spi data");
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
\ No newline at end of file
diff --git a/src/handle/peripheral_handle_uart.c b/src/handle/peripheral_handle_uart.c
new file mode 100644 (file)
index 0000000..a73007a
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <gio/gio.h>
+
+#include <peripheral_io.h>
+
+#include "peripheral_interface_uart.h"
+#include "peripheral_io_gdbus.h"
+#include "peripheral_bus.h"
+#include "peripheral_log.h"
+#include "peripheral_bus_util.h"
+
+#define INITIAL_BUFFER_SIZE 128
+#define MAX_BUFFER_SIZE 8192
+
+static bool __peripheral_bus_uart_is_available(int port, peripheral_bus_s *pb_data)
+{
+       pb_board_dev_s *uart = NULL;
+       pb_data_h handle;
+       GList *link;
+
+       RETV_IF(pb_data == NULL, false);
+       RETV_IF(pb_data->board == NULL, false);
+
+       uart = peripheral_bus_board_find_device(PB_BOARD_DEV_UART, pb_data->board, port);
+       if (uart == NULL) {
+               _E("Not supported UART port : %d", port);
+               return false;
+       }
+
+       link = pb_data->uart_list;
+       while (link) {
+               handle = (pb_data_h)link->data;
+               if (handle->dev.uart.port == port) {
+                       _E("Resource is in use, port : %d", port);
+                       return false;
+               }
+               link = g_list_next(link);
+       }
+
+       return true;
+}
+
+int peripheral_bus_uart_open(int port, pb_data_h *handle, gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       pb_data_h uart_handle;
+       int ret = PERIPHERAL_ERROR_NONE;
+       int fd;
+
+       if (!__peripheral_bus_uart_is_available(port, pb_data)) {
+               _E("uart %d is not available", port);
+               return PERIPHERAL_ERROR_RESOURCE_BUSY;
+       }
+
+       if ((ret = uart_open(port, &fd)) < 0) {
+               _E("uart_open error (%d)", ret);
+               goto open_err;
+       }
+
+       uart_handle = peripheral_bus_data_new(&pb_data->uart_list);
+       if (!uart_handle) {
+               _E("peripheral_bus_data_new error");
+               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+               goto err;
+       }
+
+       uart_handle->type = PERIPHERAL_BUS_TYPE_UART;
+       uart_handle->list = &pb_data->uart_list;
+       uart_handle->dev.uart.fd = fd;
+       uart_handle->dev.uart.port = port;
+
+       *handle = uart_handle;
+
+       return PERIPHERAL_ERROR_NONE;
+
+err:
+       uart_close(fd);
+
+open_err:
+       return ret;
+}
+
+int peripheral_bus_uart_close(pb_data_h handle)
+{
+       peripheral_bus_uart_s *uart = &handle->dev.uart;
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       _D("uart_close, port : %d, id = %s", uart->port, handle->client_info.id);
+
+       if ((ret = uart_close(uart->fd)) < 0)
+               return ret;
+
+       if (peripheral_bus_data_free(handle) < 0) {
+               _E("Failed to free uart data");
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
\ No newline at end of file
diff --git a/src/interface/include/peripheral_interface_common.h b/src/interface/include/peripheral_interface_common.h
deleted file mode 100644 (file)
index d411ae7..0000000
+++ /dev/null
@@ -1,43 +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_INTERFACE_COMMON_H__
-#define __PERIPHERAL_INTERFACE_COMMON_H__
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <peripheral_io.h>
-
-#include "peripheral_log.h"
-
-#define MAX_ERR_LEN 255
-#define MAX_BUF_LEN 64
-
-#define CHECK_ERROR(expr) \
-       do { \
-               if (expr) { \
-                       if (errno == EAGAIN) \
-                               return PERIPHERAL_ERROR_TRY_AGAIN; \
-                       char errmsg[MAX_ERR_LEN]; \
-                       strerror_r(errno, errmsg, sizeof(errmsg)); \
-                       _E("Failed the %s(%d) function. errmsg: %s", __FUNCTION__, __LINE__, errmsg); \
-                       return PERIPHERAL_ERROR_IO_ERROR; \
-               } \
-       } while (0)
-
-#endif /*__PERIPHERAL_INTERFACE_COMMON_H__*/
\ No newline at end of file
diff --git a/src/interface/include/peripheral_interface_gpio.h b/src/interface/include/peripheral_interface_gpio.h
deleted file mode 100644 (file)
index 4dfab84..0000000
+++ /dev/null
@@ -1,23 +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_INTERFACE_GPIO_H__
-#define __PERIPHERAL_INTERFACE_GPIO_H__
-
-int gpio_open(int gpiopin);
-int gpio_close(int gpiopin);
-
-#endif /*__PERIPHERAL_INTERFACE_GPIO_H__*/
diff --git a/src/interface/include/peripheral_interface_i2c.h b/src/interface/include/peripheral_interface_i2c.h
deleted file mode 100644 (file)
index 9aae2ff..0000000
+++ /dev/null
@@ -1,24 +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_INTERFACE_I2C_H__
-#define __PERIPHERAL_INTERFACE_I2C_H__
-
-int i2c_open(int bus, int *fd);
-int i2c_close(int fd);
-int i2c_set_address(int fd, int address);
-
-#endif /* __PERIPHERAL_INTERFACE_I2C_H__ */
diff --git a/src/interface/include/peripheral_interface_pwm.h b/src/interface/include/peripheral_interface_pwm.h
deleted file mode 100644 (file)
index 7621bfc..0000000
+++ /dev/null
@@ -1,38 +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_INTERFACE_PWM_H__
-#define __PERIPHERAL_INTERFACE_PWM_H__
-
-/**
-* @brief pwm_open() init pwm pin.
-*
-* @param[in] chip pwm chip number
-* @param[in] pin pwm pin number
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int pwm_open(int chip, int pin);
-
-/**
-* @brief pwm_close() deinit pwm pin.
-*
-* @param[in] chip pwm chip number
-* @param[in] pin pwm pin number
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int pwm_close(int chip, int pin);
-
-#endif /* __PERIPHERAL_INTERFACE_PWM_H__ */
diff --git a/src/interface/include/peripheral_interface_spi.h b/src/interface/include/peripheral_interface_spi.h
deleted file mode 100644 (file)
index 95994f0..0000000
+++ /dev/null
@@ -1,23 +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_INTERFACE_SPI_H__
-#define __PERIPHERAL_INTERFACE_SPI_H__
-
-int spi_open(int bus, int cs, int *fd);
-int spi_close(int fd);
-
-#endif /* __PERIPHERAL_INTERFACE_SPI_H__ */
diff --git a/src/interface/include/peripheral_interface_uart.h b/src/interface/include/peripheral_interface_uart.h
deleted file mode 100644 (file)
index 0cecfb2..0000000
+++ /dev/null
@@ -1,38 +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_INTERFACE_UART_H__
-#define __PERIPHERAL_INTERFACE_UART_H__
-
-/**
-* @brief uart_open() initializes uart port.
-*
-* @param[in] port uart port
-* @param[in] file_hndl handle of uart port
-* @return On success, handle of uart_context is returned. On failure, NULL is returned.
-*/
-int uart_open(int port, int *file_hndl);
-
-/**
-* @brief uart_close() closes uart port.
-*
-* @param[in] file_hndl handle of uart_context
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int uart_close(int file_hndl);
-
-#endif /* __PERIPHERAL_INTERFACE_UART_H__ */
-
diff --git a/src/peripheral_bus.c b/src/peripheral_bus.c
new file mode 100644 (file)
index 0000000..d4c038f
--- /dev/null
@@ -0,0 +1,295 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <gio/gio.h>
+#include <systemd/sd-daemon.h>
+
+#include <peripheral_io.h>
+
+#include "peripheral_io_gdbus.h"
+#include "peripheral_bus.h"
+#include "peripheral_log.h"
+#include "peripheral_gdbus_gpio.h"
+#include "peripheral_gdbus_i2c.h"
+#include "peripheral_gdbus_pwm.h"
+#include "peripheral_gdbus_spi.h"
+#include "peripheral_gdbus_uart.h"
+
+#include "privilege_checker.h"
+
+#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"
+
+static gboolean __gpio_init(peripheral_bus_s *pb_data)
+{
+       GDBusObjectManagerServer *manager;
+       gboolean ret = FALSE;
+       GError *error = NULL;
+
+       /* Add interface to default object path */
+       pb_data->gpio_skeleton = peripheral_io_gdbus_gpio_skeleton_new();
+       /* Register for method callbacks as signal callbacks */
+       g_signal_connect(pb_data->gpio_skeleton,
+                       "handle-open",
+                       G_CALLBACK(handle_gpio_open),
+                       pb_data);
+
+       manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_GPIO_PATH);
+
+       /* Set connection to 'manager' */
+       g_dbus_object_manager_server_set_connection(manager, pb_data->connection);
+
+       /* Export 'manager' interface on peripheral-io DBUS */
+       ret = g_dbus_interface_skeleton_export(
+               G_DBUS_INTERFACE_SKELETON(pb_data->gpio_skeleton),
+               pb_data->connection, PERIPHERAL_GDBUS_GPIO_PATH, &error);
+
+       if (ret == FALSE) {
+               _E("Can not skeleton_export %s", error->message);
+               g_error_free(error);
+       }
+
+       return true;
+}
+
+static gboolean __i2c_init(peripheral_bus_s *pb_data)
+{
+       GDBusObjectManagerServer *manager;
+       gboolean ret = FALSE;
+       GError *error = NULL;
+
+       /* Add interface to default object path */
+       pb_data->i2c_skeleton = peripheral_io_gdbus_i2c_skeleton_new();
+       g_signal_connect(pb_data->i2c_skeleton,
+                       "handle-open",
+                       G_CALLBACK(handle_i2c_open),
+                       pb_data);
+
+       manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_I2C_PATH);
+
+       /* Set connection to 'manager' */
+       g_dbus_object_manager_server_set_connection(manager, pb_data->connection);
+
+       /* Export 'manager' interface on peripheral-io DBUS */
+       ret = g_dbus_interface_skeleton_export(
+               G_DBUS_INTERFACE_SKELETON(pb_data->i2c_skeleton),
+               pb_data->connection, PERIPHERAL_GDBUS_I2C_PATH, &error);
+
+       if (ret == FALSE) {
+               _E("Can not skeleton_export %s", error->message);
+               g_error_free(error);
+       }
+
+       return true;
+}
+
+static gboolean __pwm_init(peripheral_bus_s *pb_data)
+{
+       GDBusObjectManagerServer *manager;
+       gboolean ret = FALSE;
+       GError *error = NULL;
+
+       /* Add interface to default object path */
+       pb_data->pwm_skeleton = peripheral_io_gdbus_pwm_skeleton_new();
+       g_signal_connect(pb_data->pwm_skeleton,
+                       "handle-open",
+                       G_CALLBACK(handle_pwm_open),
+                       pb_data);
+
+       manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_PWM_PATH);
+
+       /* Set connection to 'manager' */
+       g_dbus_object_manager_server_set_connection(manager, pb_data->connection);
+
+       /* Export 'manager' interface on peripheral-io DBUS */
+       ret = g_dbus_interface_skeleton_export(
+               G_DBUS_INTERFACE_SKELETON(pb_data->pwm_skeleton),
+               pb_data->connection, PERIPHERAL_GDBUS_PWM_PATH, &error);
+
+       if (ret == FALSE) {
+               _E("Can not skeleton_export %s", error->message);
+               g_error_free(error);
+       }
+
+       return true;
+}
+
+static gboolean __uart_init(peripheral_bus_s *pb_data)
+{
+       GDBusObjectManagerServer *manager;
+       gboolean ret = FALSE;
+       GError *error = NULL;
+
+       /* Add interface to default object path */
+       pb_data->uart_skeleton = peripheral_io_gdbus_uart_skeleton_new();
+       g_signal_connect(pb_data->uart_skeleton,
+                       "handle-open",
+                       G_CALLBACK(handle_uart_open),
+                       pb_data);
+
+       manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_UART_PATH);
+
+       /* Set connection to 'manager' */
+       g_dbus_object_manager_server_set_connection(manager, pb_data->connection);
+
+       /* Export 'manager' interface on peripheral-io DBUS */
+       ret = g_dbus_interface_skeleton_export(
+               G_DBUS_INTERFACE_SKELETON(pb_data->uart_skeleton),
+               pb_data->connection, PERIPHERAL_GDBUS_UART_PATH, &error);
+
+       if (ret == FALSE) {
+               _E("Can not skeleton_export %s", error->message);
+               g_error_free(error);
+       }
+
+       return true;
+}
+
+static gboolean __spi_init(peripheral_bus_s *pb_data)
+{
+       GDBusObjectManagerServer *manager;
+       gboolean ret = FALSE;
+       GError *error = NULL;
+
+       /* Add interface to default object path */
+       pb_data->spi_skeleton = peripheral_io_gdbus_spi_skeleton_new();
+       g_signal_connect(pb_data->spi_skeleton,
+                       "handle-open",
+                       G_CALLBACK(handle_spi_open),
+                       pb_data);
+
+       manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_SPI_PATH);
+
+       /* Set connection to 'manager' */
+       g_dbus_object_manager_server_set_connection(manager, pb_data->connection);
+
+       /* Export 'manager' interface on peripheral-io DBUS */
+       ret = g_dbus_interface_skeleton_export(
+               G_DBUS_INTERFACE_SKELETON(pb_data->spi_skeleton),
+               pb_data->connection, PERIPHERAL_GDBUS_SPI_PATH, &error);
+
+       if (ret == FALSE) {
+               _E("Can not skeleton_export %s", error->message);
+               g_error_free(error);
+       }
+
+       return true;
+}
+
+static void on_bus_acquired(GDBusConnection *connection,
+                                                       const gchar *name,
+                                                       gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+
+       pb_data->connection = connection;
+
+       if (__gpio_init(pb_data) == FALSE)
+               _E("Can not signal connect");
+
+       if (__i2c_init(pb_data) == FALSE)
+               _E("Can not signal connect");
+
+       if (__pwm_init(pb_data) == FALSE)
+               _E("Can not signal connect");
+
+       if (__uart_init(pb_data) == FALSE)
+               _E("Can not signal connect");
+
+       if (__spi_init(pb_data) == FALSE)
+               _E("Can not signal connect");
+}
+
+static void on_name_acquired(GDBusConnection *conn,
+                               const gchar *name, gpointer user_data)
+{
+}
+
+static void on_name_lost(GDBusConnection *conn,
+                               const gchar *name, gpointer user_data)
+{
+       _E("Dbus name is lost!");
+}
+
+static gboolean peripheral_bus_notify(gpointer data)
+{
+       _D("sd_notify(READY=1)");
+       sd_notify(0, "READY=1");
+
+       return G_SOURCE_REMOVE;
+}
+
+int main(int argc, char *argv[])
+{
+       GMainLoop *loop;
+       guint owner_id = 0;
+       peripheral_bus_s *pb_data;
+
+       pb_data = (peripheral_bus_s*)calloc(1, sizeof(peripheral_bus_s));
+       if (pb_data == NULL) {
+               _E("failed to allocate peripheral_bus_s");
+               return -1;
+       }
+
+       pb_data->board = peripheral_bus_board_init();
+       if (pb_data->board == NULL) {
+               _E("failed to init board");
+               return -1;
+       }
+
+       owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
+                                                         PERIPHERAL_GDBUS_NAME,
+                                                         (GBusNameOwnerFlags) (G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT
+                                                         | G_BUS_NAME_OWNER_FLAGS_REPLACE),
+                                                         on_bus_acquired,
+                                                         on_name_acquired,
+                                                         on_name_lost,
+                                                         pb_data,
+                                                         NULL);
+       if (!owner_id) {
+               _E("g_bus_own_name_error");
+               free(pb_data);
+               return -1;
+       }
+
+       loop = g_main_loop_new(NULL, FALSE);
+
+       g_idle_add(peripheral_bus_notify, NULL);
+
+       peripheral_privilege_init();
+
+       _D("Enter main loop!");
+       g_main_loop_run(loop);
+
+       peripheral_privilege_deinit();
+
+       if (pb_data) {
+               peripheral_bus_board_deinit(pb_data->board);
+               free(pb_data);
+       }
+
+       if (loop != NULL)
+               g_main_loop_unref(loop);
+
+       return 0;
+}
diff --git a/src/peripheral_bus_board.c b/src/peripheral_bus_board.c
new file mode 100644 (file)
index 0000000..48e2a0d
--- /dev/null
@@ -0,0 +1,274 @@
+/*
+ * 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <iniparser.h>
+
+#include <peripheral_io.h>
+
+#include "peripheral_bus_board.h"
+#include "peripheral_log.h"
+
+#define STR_BUF_MAX 255
+
+#define BOARD_INI_BASE SYSCONFDIR "/peripheral-bus/"
+
+#define BOARD_INI_ARTIK710_PATH BOARD_INI_BASE "pio_board_artik710.ini"
+#define BOARD_INI_ARTIK520_PATH BOARD_INI_BASE "pio_board_artik520.ini"
+#define BOARD_INI_RP3_B_PATH    BOARD_INI_BASE "pio_board_rp3_b.ini"
+#define BOARD_INI_UNKNOWN_PATH  BOARD_INI_BASE "pio_board_unknown.ini"
+
+static const pb_board_type_s pb_board_type[] = {
+       {PB_BOARD_ARTIK710, "artik710 raptor", BOARD_INI_ARTIK710_PATH},
+       {PB_BOARD_ARTIK530, "artik530 raptor", BOARD_INI_ARTIK710_PATH},
+       {PB_BOARD_ARTIK520, "ARTIK5 board",    BOARD_INI_ARTIK520_PATH},
+       {PB_BOARD_RP3_B,    "Raspberry Pi 3 Model B", BOARD_INI_RP3_B_PATH},
+       {PB_BOARD_UNKNOWN,  "unknown board",   BOARD_INI_UNKNOWN_PATH},
+};
+
+static int peripheral_bus_board_get_device_type(char *string)
+{
+       if (0 == strncmp(string, "gpio", strlen("gpio")))
+               return PB_BOARD_DEV_GPIO;
+       else if (0 == strncmp(string, "i2c", strlen("i2c")))
+               return PB_BOARD_DEV_I2C;
+       else if (0 == strncmp(string, "pwm", strlen("pwm")))
+               return PB_BOARD_DEV_PWM;
+       else if (0 == strncmp(string, "uart", strlen("uart")))
+               return PB_BOARD_DEV_UART;
+       else if (0 == strncmp(string, "spi", strlen("spi")))
+               return PB_BOARD_DEV_SPI;
+
+       return -1;
+}
+
+static void peripheral_bus_board_ini_parse_key(pb_board_dev_e type, char *string, unsigned int *args)
+{
+       switch (type) {
+       case PB_BOARD_DEV_GPIO:
+               sscanf(string, "%*50[^0-9]%d", &args[0]);
+               break;
+       case PB_BOARD_DEV_I2C:
+               sscanf(string, "%*50[^-]-%d", &args[0]);
+               break;
+       case PB_BOARD_DEV_PWM:
+               sscanf(string, "%*50[^0-9]%d%*50[^0-9]%d", &args[0], &args[1]);
+               break;
+       case PB_BOARD_DEV_UART:
+               sscanf(string, "%*50[^0-9]%d", &args[0]);
+               break;
+       case PB_BOARD_DEV_SPI:
+               sscanf(string, "%*50[^0-9]%d.%d", &args[0], &args[1]);
+               break;
+       default:
+               break;
+       }
+}
+
+static int peripheral_bus_board_ini_parse_pins(char *string, unsigned int *pins)
+{
+       const char delimiter[] = ", ";
+       int cnt_pins = 0;
+       char *token, *ptr = NULL;
+
+       if (string == NULL) return 0;
+
+       token = strtok_r(string, delimiter, &ptr);
+       while (token) {
+               if (cnt_pins >= BOARD_PINS_MAX) break;
+
+               pins[cnt_pins++] = atoi(token);
+               token = strtok_r(NULL, delimiter, &ptr);
+       }
+
+       return cnt_pins;
+}
+
+static int peripheral_bus_board_ini_get_nkeys(dictionary *dict)
+{
+       int i, sec_num, key_num, ret = 0;
+       char *section;
+
+       sec_num = iniparser_getnsec(dict);
+       for (i = 0; i < sec_num; i++) {
+               section = iniparser_getsecname(dict, i);
+               key_num = iniparser_getsecnkeys(dict, section);
+               if (key_num <= 0) continue;
+               ret += key_num;
+       }
+
+       return ret;
+}
+
+static int peripheral_bus_board_get_type(void)
+{
+       int fd, i, ret = 0;
+       char str_buf[STR_BUF_MAX] = {0};
+       int type = PB_BOARD_UNKNOWN;
+
+       fd = open(BOARD_DEVICE_TREE, O_RDONLY);
+       if (fd < 0) {
+               strerror_r(errno, str_buf, STR_BUF_MAX);
+               _E("Cannot open %s, errmsg : %s", BOARD_DEVICE_TREE, str_buf);
+               return -ENXIO;
+       }
+
+       ret = read(fd, str_buf, STR_BUF_MAX);
+       if (ret < 0) {
+               _E("Failed to read model information, path: %s, ret: %d", BOARD_DEVICE_TREE, ret);
+               close(fd);
+               return -EIO;
+       }
+
+       str_buf[STR_BUF_MAX - 1] = '\0';
+
+       for (i = 0; i < PB_BOARD_UNKNOWN; i++) {
+               if (strstr(str_buf, pb_board_type[i].name)) {
+                       type = pb_board_type[i].type;
+                       break;
+               }
+       }
+
+       close(fd);
+
+       return type;
+}
+
+static pb_board_s *peripheral_bus_board_get_info()
+{
+       dictionary *dict = NULL;
+       int i, j, ret;
+       int sec_num, key_num, cnt_key = 0;
+       pb_board_dev_s *dev;
+       pb_board_dev_e enum_dev;
+       pb_board_s *board;
+
+       board = (pb_board_s*)calloc(1, sizeof(pb_board_s));
+       if (board == NULL) {
+               _E("Failed to allocate pb_board_s");
+               return NULL;
+       }
+
+       ret = peripheral_bus_board_get_type();
+       if (ret < 0) {
+               _E("Failed to get board type");
+               goto err_get_type;
+       }
+
+       board->type = (pb_board_type_e)ret;
+       dict = iniparser_load(pb_board_type[board->type].path);
+       if (dict == NULL) {
+               _E("Failed to load %s", pb_board_type[board->type].path);
+               goto err_get_type;
+       }
+
+       board->num_dev = peripheral_bus_board_ini_get_nkeys(dict);
+       if (board->num_dev == 0) {
+               _E("There is no device to open");
+               goto err_get_nkeys;
+       }
+
+       board->dev = calloc(board->num_dev, sizeof(pb_board_dev_s));
+       if (board->dev == NULL) {
+               _E("Failed to allocate pb_board_dev_s");
+               goto err_get_nkeys;
+       }
+
+       sec_num = iniparser_getnsec(dict);
+       for (i = 0; i < sec_num; i++) {
+               char *section, *key_str;
+               char **key_list = NULL;
+
+               section = iniparser_getsecname(dict, i);
+               ret = peripheral_bus_board_get_device_type(section);
+               if (ret < 0) continue;
+
+               enum_dev = (pb_board_dev_e)ret;
+               key_list = iniparser_getseckeys(dict, section);
+               key_num = iniparser_getsecnkeys(dict, section);
+               if (key_num <= 0) continue;
+
+               for (j = 0; j < key_num; j++) {
+                       dev = &board->dev[cnt_key];
+                       dev->dev_type = enum_dev;
+                       key_str = iniparser_getstring(dict, key_list[j], NULL);
+                       peripheral_bus_board_ini_parse_key(dev->dev_type, key_list[j], dev->args);
+                       dev->num_pins = peripheral_bus_board_ini_parse_pins(key_str, dev->pins);
+                       cnt_key++;
+               }
+
+               if (key_list)
+                       free(key_list);
+       }
+
+       iniparser_freedict(dict);
+
+       return board;
+
+err_get_nkeys:
+       iniparser_freedict(dict);
+
+err_get_type:
+       free(board);
+       return NULL;
+}
+
+pb_board_dev_s *peripheral_bus_board_find_device(pb_board_dev_e dev_type, pb_board_s *board, int arg, ...)
+{
+       int i, args[2] = {0, };
+       va_list ap;
+
+       RETV_IF(board == NULL, false);
+
+       args[0] = arg;
+       if (dev_type == PB_BOARD_DEV_PWM || dev_type == PB_BOARD_DEV_SPI) {
+               va_start(ap, arg);
+               args[1] = va_arg(ap, int);
+               va_end(ap);
+       }
+
+       for (i = 0; i < board->num_dev; i++) {
+               if (board->dev[i].dev_type != dev_type) continue;
+
+               if (board->dev[i].args[0] == args[0] && board->dev[i].args[1] == args[1])
+                       return &board->dev[i];
+       }
+
+       return NULL;
+}
+
+pb_board_s *peripheral_bus_board_init(void)
+{
+       pb_board_s *board;
+
+       board = peripheral_bus_board_get_info();
+
+       return board;
+}
+
+void peripheral_bus_board_deinit(pb_board_s *board)
+{
+       if (board) {
+               if (board->dev)
+                       free(board->dev);
+
+               free(board);
+       }
+}
diff --git a/src/peripheral_bus_util.c b/src/peripheral_bus_util.c
new file mode 100644 (file)
index 0000000..eb27024
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <gio/gio.h>
+
+#include <cynara-creds-gdbus.h>
+#include <cynara-client.h>
+#include <cynara-session.h>
+
+#include "peripheral_bus.h"
+#include "peripheral_log.h"
+
+#include "privilege_checker.h"
+
+GVariant *peripheral_bus_build_variant_ay(uint8_t *data, int length)
+{
+       GVariantBuilder *builder;
+       GVariant *variant;
+       int i;
+
+       if (data == NULL)
+               return NULL;
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)"));
+
+       for (i = 0; i < length; i++)
+               g_variant_builder_add(builder, "(y)", data[i]);
+
+       variant = g_variant_new("a(y)", builder);
+       g_variant_builder_unref(builder);
+
+       return variant;
+}
+
+pb_data_h peripheral_bus_data_new(GList **plist)
+{
+       GList *list = *plist;
+       pb_data_h handle;
+
+       handle = (pb_data_h)calloc(1, sizeof(peripheral_bus_data_s));
+       if (handle == NULL) {
+               _E("failed to allocate peripheral_bus_data_s");
+               return NULL;
+       }
+
+       *plist = g_list_append(list, handle);
+
+       return handle;
+}
+
+int peripheral_bus_data_free(pb_data_h handle)
+{
+       GList *list = *handle->list;
+       GList *link;
+
+       RETVM_IF(handle == NULL, -1, "handle is null");
+
+       link = g_list_find(list, handle);
+       if (!link) {
+               _E("handle does not exist in list");
+               return -1;
+       }
+
+       *handle->list = g_list_remove_link(list, link);
+
+       free(handle);
+       g_list_free(link);
+
+       return 0;
+}
+
+int peripheral_bus_check_privilege(
+               GDBusMethodInvocation *invocation,
+               peripheral_bus_s *pb_data)
+{
+       int pid;
+       const char *sender;
+       char *session;
+       char *client;
+       char *user;
+
+       sender = g_dbus_method_invocation_get_sender(invocation);
+
+       cynara_creds_gdbus_get_pid(pb_data->connection, sender, &pid);
+       session = cynara_session_from_pid(pid);
+
+       cynara_creds_gdbus_get_client(pb_data->connection, sender, CLIENT_METHOD_DEFAULT, &client);
+       cynara_creds_gdbus_get_user(pb_data->connection, sender, USER_METHOD_DEFAULT, &user);
+
+       if (!session || !client || !user) {
+               _E("Failed to get client info");
+               return -1;
+       }
+
+       if (!peripheral_privilege_check(client, session, user, PERIPHERAL_PRIVILEGE)) {
+               g_free(session);
+               g_free(client);
+               g_free(user);
+               return -EACCES;
+       }
+
+       g_free(session);
+       g_free(client);
+       g_free(user);
+
+       return 0;
+}
+
+int peripheral_bus_get_client_info(
+               GDBusMethodInvocation *invocation,
+               peripheral_bus_s *pb_data,
+               pb_client_info_s *client_info)
+{
+       guint pid = 0;
+       GError *error = NULL;
+       GVariant *_ret;
+       const gchar *id;
+       int err;
+
+       id = g_dbus_method_invocation_get_sender(invocation);
+       if (id == NULL) {
+               _E("Current id is NULL");
+               return -1;
+       }
+
+       _ret = g_dbus_connection_call_sync(pb_data->connection,
+               "org.freedesktop.DBus",
+               "/org/freedesktop/DBus",
+               "org.freedesktop.DBus",
+               "GetConnectionUnixProcessID",
+               g_variant_new("(s)", id),
+               NULL,
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               &error);
+
+       if (_ret == NULL) {
+               _E("Failed to get client pid, %s", error->message);
+               g_error_free(error);
+
+               return -1;
+       }
+
+       g_variant_get(_ret, "(u)", &pid);
+       g_variant_unref(_ret);
+
+       if ((err = peripheral_bus_check_privilege(invocation, pb_data)) < 0) {
+               _E("Permission denied(%d)", pid);
+               return err;
+       }
+
+       client_info->pid = (pid_t)pid;
+       client_info->pgid = getpgid(pid);
+       client_info->id = strdup(id);
+
+       return 0;
+}
+
+int peripheral_bus_handle_is_valid(
+               GDBusMethodInvocation *invocation,
+               pb_data_h handle,
+               GList *list)
+{
+       const gchar *id;
+
+       if (!g_list_find(list, handle)) {
+               _E("Cannot find handle");
+               return -1;
+       }
+
+       id = g_dbus_method_invocation_get_sender(invocation);
+       if (id == NULL) {
+               _E("Current id is NULL");
+               return -1;
+       }
+
+       if (strcmp(handle->client_info.id, id)) {
+               _E("Invalid access, handle id : %s, current id : %s", handle->client_info.id, id);
+               return -1;
+       }
+
+       return 0;
+}
diff --git a/src/privilege_checker.c b/src/privilege_checker.c
new file mode 100644 (file)
index 0000000..e35298d
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <peripheral_io.h>
+
+#include <cynara-creds-gdbus.h>
+#include <cynara-client.h>
+#include <cynara-session.h>
+
+#include "peripheral_bus.h"
+#include "peripheral_log.h"
+
+#define CACHE_SIZE  100
+
+static cynara *__cynara;
+
+void peripheral_privilege_init(void)
+{
+       int err;
+       cynara_configuration* conf = NULL;
+
+       err = cynara_configuration_create(&conf);
+       RETM_IF(err != CYNARA_API_SUCCESS, "Failed to create cynara configuration");
+
+       err = cynara_configuration_set_cache_size(conf, CACHE_SIZE);
+       if (err != CYNARA_API_SUCCESS) {
+               _E("Failed to set cynara cache size");
+               cynara_configuration_destroy(conf);
+               return;
+       }
+
+       err = cynara_initialize(&__cynara, conf);
+       cynara_configuration_destroy(conf);
+       if (err != CYNARA_API_SUCCESS) {
+               _E("Failed to initialize cynara");
+               __cynara = NULL;
+               return;
+       }
+
+       _D("Cynara initialized");
+}
+
+void peripheral_privilege_deinit(void)
+{
+       if (__cynara)
+               cynara_finish(__cynara);
+
+       _D("Cynara deinitialized");
+}
+
+bool peripheral_privilege_check(const char* client, const char* session, const char* user, const char* privilege)
+{
+       RETVM_IF(!privilege, true, "Invalid parameter");
+       RETVM_IF(!__cynara, false, "Cynara does not initialized");
+
+       int ret = cynara_check(__cynara, client, session, user, privilege);
+       return (ret == CYNARA_API_ACCESS_ALLOWED);
+}