4 * Copyright (c) 2019 - 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include <libsyscommon/libgdbus.h>
23 #include "core/devices.h"
24 #include <hal/device/hal-board.h>
26 #define SERIAL_MAX 128
27 static bool board_dev_available = false;
29 static GVariant *dbus_revision_handler(GDBusConnection *conn,
30 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
31 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
36 ret = hal_device_board_get_device_revision(&revision);
37 if (!board_dev_available || (ret == -ENODEV)) {
38 _E("GetHWRev not supported.");
44 _E("Fail to get revision.");
48 _D("Revision: %d", revision);
50 return g_variant_new("(i)", revision);
53 return g_variant_new("(i)", ret);
56 static GVariant *dbus_num_handler(GDBusConnection *conn,
57 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
58 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
62 char serial[SERIAL_MAX] = {0, };
64 ret = hal_device_board_get_device_serial_number(serial, SERIAL_MAX);
65 if (!board_dev_available || (ret == -ENODEV)) {
66 _E("GetSerial not supported.");
72 _E("Failed to get serial.");
76 _D("Num(%s) len(%zu).", serial, strlen(serial));
80 result = g_variant_new("(si)", strdup(""), ret);
82 result = g_variant_new("(si)", serial, ret);
87 static GVariant *dbus_serial_handler(GDBusConnection *conn,
88 const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
89 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
94 char serial[SERIAL_MAX] = {0, };
96 ret = hal_device_board_get_device_serial_number(serial, SERIAL_MAX);
97 if (!board_dev_available || (ret == -ENODEV)) {
98 _E("GetNum not supported.");
104 _E("Failed to get num.");
108 p = strchr(serial, ',');
112 _D("Serial(%s) len(%zu).", serial, strlen(serial));
116 result = g_variant_new("(si)", strdup(""), ret);
118 result = g_variant_new("(si)", serial, ret);
123 static const dbus_method_s dbus_methods[] = {
124 { "GetSerial", NULL, "si", dbus_serial_handler },
125 { "GetHWRev", NULL, "i", dbus_revision_handler },
126 { "GetNum", NULL, "si", dbus_num_handler},
129 static const dbus_interface_u dbus_interface = {
131 .name = DEVICED_INTERFACE_BOARD,
132 .methods = dbus_methods,
133 .nr_methods = ARRAY_SIZE(dbus_methods),
136 static int board_probe(void *data)
140 if (board_dev_available)
143 ret = hal_device_board_get_backend();
145 _E("There is no HAL for board.");
146 board_dev_available = false;
151 _I("Board device structure load success.");
152 board_dev_available = true;
156 static void board_init(void *data)
160 ret = gdbus_add_object(NULL, DEVICED_PATH_BOARD, &dbus_interface);
162 _E("Failed to init dbus method: %d", ret);
165 static const struct device_ops board_device_ops = {
166 DECLARE_NAME_LEN("board"),
167 .probe = board_probe,
171 DEVICE_OPS_REGISTER(&board_device_ops)