Initialize Tizen 2.3
[framework/system/deviced.git] / src / testmode / testmode.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 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 <stdbool.h>
20 #include <assert.h>
21 #include <limits.h>
22 #include "core/log.h"
23 #include "core/devices.h"
24 #include "core/edbus-handler.h"
25 #include "core/launch.h"
26
27 static DBusMessage *edbus_testmode_launch(E_DBus_Object *obj, DBusMessage *msg)
28 {
29         DBusError err;
30         DBusMessageIter iter;
31         DBusMessage *reply;
32         pid_t pid;
33         int ret;
34         int argc;
35         char *argv;
36         char param[32];
37
38         dbus_error_init(&err);
39
40         if (!dbus_message_get_args(msg, &err,
41                     DBUS_TYPE_STRING, &argv, DBUS_TYPE_INVALID)) {
42                 _E("there is no message");
43                 ret = -EINVAL;
44                 goto out;
45         }
46         sprintf(param, "%s", argv);
47         _D("param %s", param);
48
49         launch_evenif_exist("/usr/bin/testmode-env.sh", param);
50 out:
51         reply = dbus_message_new_method_return(msg);
52         dbus_message_iter_init_append(reply, &iter);
53         dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
54
55         return reply;
56 }
57
58 static const struct edbus_method edbus_methods[] = {
59         { "Launch", "s",   "i", edbus_testmode_launch },
60         /* Add methods here */
61 };
62
63 /* battery ops init funcion */
64 static void testmode_init(void *data)
65 {
66         int ret;
67
68         /* init dbus interface */
69         ret = register_edbus_method(DEVICED_PATH_TESTMODE,
70                         edbus_methods, ARRAY_SIZE(edbus_methods));
71         if (ret < 0)
72                 _E("fail to init edbus method(%d)", ret);
73 }
74
75 /* battery ops exit funcion */
76 static void testmode_exit(void *data)
77 {
78 }
79
80 static const struct device_ops battery_device_ops = {
81         .priority = DEVICE_PRIORITY_NORMAL,
82         .name     = "testmode",
83         .init     = testmode_init,
84         .exit     = testmode_exit,
85 };
86
87 DEVICE_OPS_REGISTER(&battery_device_ops)