SET(PERIPHERAL-BUS "peripheral-bus")
SET(SRCS
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_pwm.c
src/gdbus/peripheral_gdbus_spi.c
src/gdbus/peripheral_gdbus_uart.c
+ src/handle/peripheral_handle_common.c
src/handle/peripheral_handle_pwm.c
src/handle/peripheral_handle_i2c.c
src/handle/peripheral_handle_gpio.c
* limitations under the License.
*/
-#ifndef __PERIPHERAL_UTIL_H__
-#define __PERIPHERAL_UTIL_H__
+#ifndef __PERIPHERAL_HANDLE_COMMON_H__
+#define __PERIPHERAL_HANDLE_COMMON_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);
+#include <gio/gio.h>
-int peripheral_bus_get_client_info(
- GDBusMethodInvocation *invocation,
- peripheral_bus_s *pb_data,
- pb_client_info_s *client_info);
+#include "peripheral_bus.h"
-int peripheral_bus_handle_is_valid(
- GDBusMethodInvocation *invocation,
- pb_data_h handle,
- GList *list);
+pb_data_h peripheral_bus_data_new(GList **plist);
+int peripheral_bus_data_free(pb_data_h handle);
-#endif /* __PERIPHERAL_UTIL_H__ */
+#endif /* __PERIPHERAL_HANDLE_COMMON_H__ */
#ifndef __PERIPHERAL_LOG_H__
#define __PERIPHERAL_LOG_H__
-#include <unistd.h>
+// #include <unistd.h>
#include <dlog.h>
#undef LOG_TAG
#include "peripheral_bus.h"
#include "peripheral_handle_gpio.h"
#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
#include "peripheral_gdbus_gpio.h"
#include "privilege_checker.h"
#include "peripheral_bus.h"
#include "peripheral_handle_i2c.h"
#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
#include "peripheral_gdbus_i2c.h"
#include "privilege_checker.h"
#include "peripheral_bus.h"
#include "peripheral_handle_pwm.h"
#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
#include "peripheral_gdbus_pwm.h"
#include "privilege_checker.h"
#include "peripheral_bus.h"
#include "peripheral_handle_spi.h"
#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
#include "peripheral_gdbus_spi.h"
#include "privilege_checker.h"
#include "peripheral_bus.h"
#include "peripheral_handle_uart.h"
#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
#include "peripheral_gdbus_uart.h"
#include "privilege_checker.h"
--- /dev/null
+/*
+ * 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 "peripheral_handle_common.h"
+#include "peripheral_log.h"
+
+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;
+}
\ No newline at end of file
#include "peripheral_interface_gpio.h"
#include "peripheral_bus.h"
#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
+#include "peripheral_handle_common.h"
static bool peripheral_bus_gpio_is_available(int pin, peripheral_bus_s *pb_data)
{
#include "peripheral_interface_i2c.h"
#include "peripheral_bus.h"
#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
+#include "peripheral_handle_common.h"
#define INITIAL_BUFFER_SIZE 128
#define MAX_BUFFER_SIZE 8192
#include "peripheral_interface_pwm.h"
#include "peripheral_bus.h"
#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
+#include "peripheral_handle_common.h"
static bool peripheral_bus_pwm_is_available(int chip, int pin, peripheral_bus_s *pb_data)
{
#include "peripheral_interface_spi.h"
#include "peripheral_bus.h"
#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
+#include "peripheral_handle_common.h"
static bool __peripheral_bus_spi_is_available(int bus, int cs, peripheral_bus_s *pb_data)
{
#include "peripheral_io_gdbus.h"
#include "peripheral_bus.h"
#include "peripheral_log.h"
-#include "peripheral_bus_util.h"
+#include "peripheral_handle_common.h"
#define INITIAL_BUFFER_SIZE 128
#define MAX_BUFFER_SIZE 8192
+++ /dev/null
-/*
- * 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 "peripheral_bus.h"
-#include "peripheral_log.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;
-}
-
-// TODO : This function will be removed (unused)
-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;
-
- 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);
-
- 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;
-}