4 * Copyright (c) 2014 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 <sensor_log.h>
21 #include <dbus_util.h>
24 static int wrist_up_total_cnt;
25 static int wrist_up_lcdon_cnt;
26 static int wrist_up_algo;
28 static GDBusNodeInfo *introspection_data = NULL;
29 static guint owner_id;
31 static const gchar introspection_xml[] =
33 " <interface name='org.tizen.system.sensord'>"
34 " <method name='check_privilege'>"
35 " <arg type='i' name='response' direction='out'/>"
37 " <method name='wristup_lcdon_cnt'>"
38 " <arg type='i' name='response' direction='out'/>"
40 " <method name='wristup_total_cnt'>"
41 " <arg type='i' name='response' direction='out'/>"
43 " <method name='wristup_algo'>"
44 " <arg type='i' name='response' direction='out'/>"
49 static void method_call_handler(GDBusConnection *conn,
50 const gchar *sender, const gchar *object_path,
51 const gchar *iface_name, const gchar *method_name,
52 GVariant *parameters, GDBusMethodInvocation *invocation,
57 if (g_strcmp0(method_name, "check_privilege") == 0) {
58 _D("check_privilege called");
60 } else if (g_strcmp0(method_name, "wristup_lcdon_cnt") == 0) {
61 _D("wristup_lcdon_cnt called, %d", wrist_up_lcdon_cnt);
62 ret = wrist_up_lcdon_cnt;
63 } else if (g_strcmp0(method_name, "wristup_total_cnt") == 0) {
64 _D("wristup_total_cnt called, %d", wrist_up_total_cnt);
65 ret = wrist_up_total_cnt;
66 } else if (g_strcmp0(method_name, "wristup_algo") == 0) {
67 _D("wristup_algo called, %d", wrist_up_algo);
70 _D("No matched method call");
74 g_dbus_method_invocation_return_value(invocation,
75 g_variant_new("(i)", ret));
78 static const GDBusInterfaceVTable interface_vtable =
85 static void on_bus_acquired(GDBusConnection *connection,
89 guint registration_id;
92 _E("connection is null");
96 registration_id = g_dbus_connection_register_object(connection,
98 introspection_data->interfaces[0],
100 NULL, /* user_data */
101 NULL, /* user_data_free_func */
102 NULL); /* GError** */
104 if (registration_id == 0)
105 _E("Failed to g_dbus_connection_register_object");
107 _I("Gdbus method call registrated");
110 static void on_name_acquired(GDBusConnection *conn,
111 const gchar *name, gpointer user_data)
115 static void on_name_lost(GDBusConnection *conn,
116 const gchar *name, gpointer user_data)
118 _E("Dbus name is lost!");
121 int get_lcdon_count(void)
123 return wrist_up_lcdon_cnt;
126 void increase_lcdon_count(void)
128 wrist_up_lcdon_cnt++;
131 void reset_lcdon_count(void)
133 wrist_up_lcdon_cnt = 0;
136 int get_total_count(void)
138 return wrist_up_total_cnt;
141 void increase_total_count(void)
143 wrist_up_total_cnt++;
146 void reset_total_count(void)
148 wrist_up_total_cnt = 0;
151 void set_wrist_up_algo(int mode)
153 wrist_up_algo = mode;
158 #ifndef GLIB_VERSION_2_36
162 introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
163 if (introspection_data == NULL) {
164 _E("Failed to init g_dbus_node_info_new_for_xml");
168 owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
170 (GBusNameOwnerFlags) (G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT
171 | G_BUS_NAME_OWNER_FLAGS_REPLACE),
177 wrist_up_total_cnt = 0;
178 wrist_up_lcdon_cnt = 0;
184 g_bus_unown_name(owner_id);
186 if (introspection_data)
187 g_dbus_node_info_unref(introspection_data);