tizen 2.3 release
[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 DBusMessage *edbus_factory_15_launch(E_DBus_Object *obj, DBusMessage *msg)
59 {
60         DBusError err;
61         DBusMessageIter iter;
62         DBusMessage *reply;
63         pid_t pid;
64         int ret;
65         int argc;
66         char *argv;
67         char param[32];
68
69         dbus_error_init(&err);
70
71         if (!dbus_message_get_args(msg, &err,
72                     DBUS_TYPE_STRING, &argv, DBUS_TYPE_INVALID)) {
73                 _E("there is no message");
74                 ret = -EINVAL;
75                 goto out;
76         }
77         sprintf(param, "%s", argv);
78         _D("param %s", param);
79
80         launch_evenif_exist("/usr/bin/factory-15-env.sh", param);
81 out:
82         reply = dbus_message_new_method_return(msg);
83         dbus_message_iter_init_append(reply, &iter);
84         dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
85
86         return reply;
87 }
88
89
90 static const struct edbus_method edbus_methods[] = {
91         { "Launch", "s",   "i", edbus_testmode_launch },
92         { "factory15", "s",   "i", edbus_factory_15_launch },
93         /* Add methods here */
94 };
95
96 /* battery ops init funcion */
97 static void testmode_init(void *data)
98 {
99         int ret;
100
101         /* init dbus interface */
102         ret = register_edbus_method(DEVICED_PATH_TESTMODE,
103                         edbus_methods, ARRAY_SIZE(edbus_methods));
104         if (ret < 0)
105                 _E("fail to init edbus method(%d)", ret);
106 }
107
108 /* battery ops exit funcion */
109 static void testmode_exit(void *data)
110 {
111 }
112
113 static const struct device_ops battery_device_ops = {
114         .priority = DEVICE_PRIORITY_NORMAL,
115         .name     = "testmode",
116         .init     = testmode_init,
117         .exit     = testmode_exit,
118 };
119
120 DEVICE_OPS_REGISTER(&battery_device_ops)