Initialize Tizen 2.3
[framework/system/deviced.git] / src / auto-test / time.c
1 /*
2  * test
3  *
4  * Copyright (c) 2013 Samsung Electronics Co., Ltd.
5  *
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
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 #include "test.h"
20
21 #define TIME_CHANGE_SIGNAL "STimeChanged"
22
23 static E_DBus_Signal_Handler *edbus_handler;
24 static E_DBus_Connection     *edbus_conn;
25
26 static void unregister_edbus_signal_handler(void)
27 {
28         e_dbus_signal_handler_del(edbus_conn, edbus_handler);
29         e_dbus_connection_close(edbus_conn);
30         e_dbus_shutdown();
31 }
32
33 static void time_changed(void *data, DBusMessage *msg)
34 {
35         DBusError err;
36         int val;
37         int r;
38
39         _I("edbus signal Received");
40
41         r = dbus_message_is_signal(msg, DEVICED_INTERFACE_TIME, TIME_CHANGE_SIGNAL);
42         if (!r) {
43                 _E("dbus_message_is_signal error");
44                 return;
45         }
46
47         _I("%s - %s", DEVICED_INTERFACE_TIME, TIME_CHANGE_SIGNAL);
48
49         unregister_edbus_signal_handler();
50         ecore_shutdown();
51 }
52
53 static int register_edbus_signal_handler(void)
54 {
55         int ret;
56
57         e_dbus_init();
58
59         edbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
60         if (!(edbus_conn)) {
61                 ret = -ECONNREFUSED;
62                 goto edbus_handler_out;
63         }
64
65         edbus_handler = e_dbus_signal_handler_add(edbus_conn, NULL, DEVICED_PATH_TIME,
66                         DEVICED_INTERFACE_TIME, TIME_CHANGE_SIGNAL, time_changed, NULL);
67         if (!(edbus_handler)) {
68                 ret = -ECONNREFUSED;
69                 goto edbus_handler_connection_out;
70         }
71         return 0;
72
73 edbus_handler_connection_out:
74         e_dbus_connection_close(edbus_conn);
75 edbus_handler_out:
76         e_dbus_shutdown();
77         return ret;
78 }
79
80 static void test_signal(void)
81 {
82         _I("test");
83         register_edbus_signal_handler();
84         ecore_main_loop_begin();
85 }
86
87 static void time_init(void *data)
88 {
89 }
90
91 static void time_exit(void *data)
92 {
93 }
94
95 static int time_unit(int argc, char **argv)
96 {
97         if (argv[1] == NULL)
98                 return -EINVAL;
99         else if (argc != 4)
100                 return -EAGAIN;
101         if (strcmp("wait", argv[2]) == 0)
102                 test_signal();
103         return 0;
104 }
105
106 static const struct test_ops power_test_ops = {
107         .priority = TEST_PRIORITY_NORMAL,
108         .name     = "time",
109         .init     = time_init,
110         .exit    = time_exit,
111         .unit    = time_unit,
112 };
113
114 TEST_OPS_REGISTER(&power_test_ops)