SET(PERIPHERAL-BUS "peripheral-bus")
SET(SRCS
src/daemon/peripheral_bus.c
+ src/daemon/peripheral_bus_util.c
src/daemon/peripheral_bus_pwm.c
src/daemon/peripheral_bus_i2c.c
src/daemon/peripheral_bus_gpio.c
#include "peripheral_bus_pwm.h"
#include "peripheral_bus_uart.h"
#include "peripheral_common.h"
-
-static 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);
- _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;
-}
+#include "peripheral_bus_util.h"
gboolean handle_gpio_open(
PeripheralIoGdbusGpio *gpio,
peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
pb_i2c_data_h i2c_handle = GUINT_TO_POINTER(handle);
GVariant *data_array = NULL;
+ uint8_t err_buf[2] = {0, };
const gchar *id;
/* Handle validation */
if (!i2c_handle || !i2c_handle->client_info.id) {
_E("i2c handle is not valid");
+ data_array = peripheral_bus_build_variant_ay(err_buf, sizeof(err_buf));
ret = PERIPHERAL_ERROR_UNKNOWN;
goto out;
}
id = g_dbus_method_invocation_get_sender(invocation);
if (strcmp(i2c_handle->client_info.id, id)) {
_E("Invalid access, handle id : %s, current id : %s", i2c_handle->client_info.id, id);
+ data_array = peripheral_bus_build_variant_ay(err_buf, sizeof(err_buf));
ret = PERIPHERAL_ERROR_INVALID_OPERATION;
goto out;
}
#include "i2c.h"
#include "peripheral_bus.h"
#include "peripheral_common.h"
+#include "peripheral_bus_util.h"
#define INITIAL_BUFFER_SIZE 128
#define MAX_BUFFER_SIZE 8192
int peripheral_bus_i2c_read(pb_i2c_data_h i2c, int length, GVariant **data_array)
{
- GVariantBuilder *builder;
- int ret, i;
+ uint8_t err_buf[2] = {0, };
+ int ret;
/* Limit maximum length */
if (length > MAX_BUFFER_SIZE) length = MAX_BUFFER_SIZE;
}
ret = i2c_read(i2c->fd, i2c->buffer, length);
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)"));
-
- for (i = 0; i < length; i++)
- g_variant_builder_add(builder, "(y)", i2c->buffer[i]);
- *data_array = g_variant_new("a(y)", builder);
- g_variant_builder_unref(builder);
+ *data_array = peripheral_bus_build_variant_ay(i2c->buffer, length);
return ret;
out:
- builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)"));
-
- for (i = 0; i < i2c->buffer_size; i++)
- g_variant_builder_add(builder, "(y)", 0x0);
- *data_array = g_variant_new("a(y)", builder);
- g_variant_builder_unref(builder);
+ *data_array = peripheral_bus_build_variant_ay(err_buf, sizeof(err_buf));
return ret;
}
#include "peripheral_io_gdbus.h"
#include "peripheral_bus.h"
#include "peripheral_common.h"
+#include "peripheral_bus_util.h"
#define INITIAL_BUFFER_SIZE 128
#define MAX_BUFFER_SIZE 8192
-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;
-}
-
static pb_uart_data_h peripheral_bus_uart_data_get(int port, GList **list)
{
GList *uart_list = *list;
#ifndef __PERIPHERAL_BUS_UART_H__
#define __PERIPHERAL_BUS_UART_H__
-GVariant *peripheral_bus_build_variant_ay(uint8_t *data, int length);
int peripheral_bus_uart_open(int port, pb_uart_data_h *uart, gpointer user_data);
int peripheral_bus_uart_close(pb_uart_data_h uart, gpointer user_data);
int peripheral_bus_uart_flush(pb_uart_data_h uart);
--- /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 <stdint.h>
+#include <string.h>
+#include <gio/gio.h>
+
+#include "peripheral_bus.h"
+#include "peripheral_common.h"
+
+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);
+ _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;
+}
+
+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;
+}
--- /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.
+ */
+
+#ifndef __PERIPHERAL_UTIL_H__
+#define __PERIPHERAL_UTIL_H__
+
+int peripheral_bus_get_client_info(GDBusMethodInvocation *invocation, peripheral_bus_s *pb_data, pb_client_info_s *client_info);
+GVariant *peripheral_bus_build_variant_ay(uint8_t *data, int length);
+
+#endif /* __PERIPHERAL_UTIL_H__ */