Add a board info module 82/211082/10 submit/tizen/20190801.065937
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 30 Jul 2019 01:18:37 +0000 (10:18 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Thu, 1 Aug 2019 01:01:44 +0000 (10:01 +0900)
Change-Id: I89309dec1f198a5fbac3e4fbbbee484bcb6f5bf2
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
CMakeLists.txt
packaging/deviced.spec
src/board/board-info.c [new file with mode: 0644]

index 33ca1c4..b28ba3f 100644 (file)
@@ -155,6 +155,11 @@ IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on)
                DESTINATION /etc/deviced/usb-host-test/)
 ENDIF()
 
+IF(DEVICE_BOARD_MODULE STREQUAL on)
+       ADD_SOURCE(src/board PRODUCT_BOARD_SRCS)
+       SET(SRCS ${SRCS} ${PRODUCT_BOARD_SRCS})
+ENDIF()
+
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/deviced)
index fd8a375..e2da603 100644 (file)
@@ -163,6 +163,7 @@ Plugin libraries for IoT devices
        -DTIZEN_FEATURE_BATTERY_OVER_TEMPERATURE=on \
        -DTOUCH_SENSITIVITY_MODULE=on \
        -DDUMP_MODULE=on \
+       -DDEVICE_BOARD_MODULE=on \
        #eol
 
 %build
diff --git a/src/board/board-info.c b/src/board/board-info.c
new file mode 100644 (file)
index 0000000..2af9fd9
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * 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)