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;
27 static GDBusNodeInfo *introspection_data = NULL;
28 static guint owner_id;
30 static const gchar introspection_xml[] =
32 " <interface name='org.tizen.system.sensord'>"
33 " <method name='check_privilege'>"
34 " <arg type='i' name='response' direction='out'/>"
36 " <method name='wristup_lcdon_cnt'>"
37 " <arg type='i' name='response' direction='out'/>"
39 " <method name='wristup_total_cnt'>"
40 " <arg type='i' name='response' direction='out'/>"
45 static void method_call_handler(GDBusConnection *conn,
46 const gchar *sender, const gchar *object_path,
47 const gchar *iface_name, const gchar *method_name,
48 GVariant *parameters, GDBusMethodInvocation *invocation,
53 if (g_strcmp0(method_name, "check_privilege") == 0) {
54 _D("check_privilege called");
56 } else if (g_strcmp0(method_name, "wristup_lcdon_cnt") == 0) {
57 _D("wristup_lcdon_cnt called, %d", wrist_up_lcdon_cnt);
58 ret = wrist_up_lcdon_cnt;
59 } else if (g_strcmp0(method_name, "wristup_total_cnt") == 0) {
60 _D("wristup_total_cnt called, %d", wrist_up_total_cnt);
61 ret = wrist_up_total_cnt;
63 _D("No matched method call");
67 g_dbus_method_invocation_return_value(invocation,
68 g_variant_new("(i)", ret));
71 static const GDBusInterfaceVTable interface_vtable =
78 static void on_bus_acquired(GDBusConnection *connection,
82 guint registration_id;
85 _E("connection is null");
89 registration_id = g_dbus_connection_register_object(connection,
91 introspection_data->interfaces[0],
94 NULL, /* user_data_free_func */
97 if (registration_id == 0)
98 _E("Failed to g_dbus_connection_register_object");
100 _I("Gdbus method call registrated");
103 static void on_name_acquired(GDBusConnection *conn,
104 const gchar *name, gpointer user_data)
108 static void on_name_lost(GDBusConnection *conn,
109 const gchar *name, gpointer user_data)
111 _E("Dbus name is lost!");
114 int get_lcdon_count(void)
116 return wrist_up_lcdon_cnt;
119 void increase_lcdon_count(void)
121 wrist_up_lcdon_cnt++;
124 void reset_lcdon_count(void)
126 wrist_up_lcdon_cnt = 0;
129 int get_total_count(void)
131 return wrist_up_total_cnt;
134 void increase_total_count(void)
136 wrist_up_total_cnt++;
139 void reset_total_count(void)
141 wrist_up_total_cnt = 0;
146 #ifndef GLIB_VERSION_2_36
150 introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
151 if (introspection_data == NULL) {
152 _E("Failed to init g_dbus_node_info_new_for_xml");
156 owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
158 (GBusNameOwnerFlags) (G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT
159 | G_BUS_NAME_OWNER_FLAGS_REPLACE),
165 wrist_up_total_cnt = 0;
166 wrist_up_lcdon_cnt = 0;
172 g_bus_unown_name(owner_id);
174 if (introspection_data)
175 g_dbus_node_info_unref(introspection_data);