--- /dev/null
+/*
+ * deviced
+ *
+ * Copyright (c) 2019 - 2013 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 <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <libsyscommon/dbus-system.h>
+#include <hw/board.h>
+
+#include "core/log.h"
+#include "core/common.h"
+#include "core/devices.h"
+#include "core/config-parser.h"
+
+struct board_info {
+ char *serial;
+ char *num;
+ int revision;
+};
+
+static struct board_info info;
+static struct hw_board *board_dev;
+
+static GVariant *dbus_revision_handler(GDBusConnection *conn,
+ const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
+ GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
+{
+ int ret;
+ if (!board_dev->get_device_revision) {
+ _E("GetHWRev not supported.");
+ ret = -ENOTSUP;
+ goto revision_fail;
+ }
+ ret = board_dev->get_device_revision(&info.revision);
+ if (ret < 0) {
+ _E("Fail to get revision.");
+ goto revision_fail;
+ }
+ _D("Revision: %d", info.revision);
+ return g_variant_new("(i)", info.revision);
+
+revision_fail:
+ return g_variant_new("(i)", ret);
+}
+
+static GVariant *dbus_serial_handler(GDBusConnection *conn,
+ const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
+ GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
+{
+ int ret;
+ if (!board_dev->get_device_serial) {
+ _E("GetSerial not supported.");
+ ret = -ENOTSUP;
+ goto serial_out;
+ }
+ ret = board_dev->get_device_serial(&info.serial);
+ if (ret < 0) {
+ _E("Failed to get serial.");
+ goto serial_out;
+ }
+ _D("Serial(%s) len(%d).", info.serial, strlen(info.serial));
+
+serial_out:
+ return g_variant_new("(si)", info.serial, ret);
+}
+
+static GVariant *dbus_num_handler(GDBusConnection *conn,
+ const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
+ GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
+{
+ int ret;
+ char *p;
+ if (!board_dev->get_device_serial) {
+ _E("GetNum not supported.");
+ ret = -ENOTSUP;
+ goto num_out;
+ }
+ ret = board_dev->get_device_serial(&info.num);
+ if (ret < 0) {
+ _E("Failed to get num.");
+ goto num_out;
+ }
+
+ p = strchr(info.num, ',');
+ if (p) {
+ ++p;
+ strcpy(info.num, p);
+ }
+ _D("Num(%s) len(%d).", info.num, strlen(info.num));
+
+num_out:
+ return g_variant_new("(si)", info.num, ret);
+}
+
+static const dbus_method_s dbus_methods[] = {
+ { "GetSerial", NULL, "si", dbus_serial_handler },
+ { "GetHWRev", NULL, "i", dbus_revision_handler },
+ { "GetNum", NULL, "si", dbus_num_handler},
+};
+
+static const dbus_interface_u dbus_interface = {
+ .oh = NULL,
+ .name = DEVICED_INTERFACE_BOARD,
+ .methods = dbus_methods,
+ .nr_methods = ARRAY_SIZE(dbus_methods),
+};
+
+static int board_probe(void *data)
+{
+ struct hw_info *info;
+ int ret;
+
+ if (board_dev)
+ return 0;
+
+ ret = hw_get_info(BOARD_HARDWARE_DEVICE_ID,
+ (const struct hw_info**)&info);
+ if (ret < 0) {
+ _E("Failed to load board shared library: %d", ret);
+ return -ENODEV;
+ }
+
+ if (!info->open) {
+ _E("Failed to open board device: open(NULL)");
+ return -ENODEV;
+ }
+
+ ret = info->open(info, NULL, (struct hw_common**)&board_dev);
+ if (ret < 0) {
+ _E("Failed to get board device structure: %d", ret);
+ return -ENODEV;
+ }
+
+ _I("Board device structure load success.");
+ return 0;
+}
+
+static void board_init(void *data)
+{
+ int ret;
+
+ ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_BOARD, &dbus_interface);
+ if (ret < 0)
+ _E("Failed to init dbus method: %d", ret);
+ ret = board_dev->get_device_serial(&info.serial);
+ if (ret < 0)
+ _E("Failed to get serial info: %d", ret);
+}
+
+static const struct device_ops board_device_ops = {
+ .name = "board",
+ .probe = board_probe,
+ .init = board_init,
+};
+
+DEVICE_OPS_REGISTER(&board_device_ops)