libgdbus: Move common gdbus interfaces to libsystem package
[platform/core/system/storaged.git] / src / shared / apps.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2015 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 <stdarg.h>
20 #include <device/display.h>
21 #include "log.h"
22 #include "apps.h"
23
24 #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
25 #define POPUP_METHOD_LAUNCH "PopupLaunch"
26
27 static const struct app_dbus_match {
28         const char *type;
29         const char *bus;
30         const char *path;
31         const char *iface;
32         const char *method;
33 } app_match[] = {
34         { POPUP_DEFAULT, POPUP_BUS_NAME, POPUP_PATH_SYSTEM, POPUP_INTERFACE_SYSTEM, POPUP_METHOD_LAUNCH },
35 };
36
37 int launch_system_app(char *type, int num, ...)
38 {
39         char *app_type;
40         va_list args;
41         int i, match, ret;
42
43         if (type)
44                 app_type = type;
45         else
46                 app_type = POPUP_DEFAULT;
47
48         match = -1;
49         for (i = 0 ; i < ARRAY_SIZE(app_match) ; i++) {
50                 if (strncmp(app_type, app_match[i].type, strlen(app_type)))
51                         continue;
52                 match = i;
53                 break;
54         }
55         if (match < 0) {
56                 _E("Failed to find app matched (%s)", app_type);
57                 return -EINVAL;
58         }
59
60         va_start(args, num);
61
62         ret = dbus_handle_method_async_pairs(app_match[match].bus,
63                         app_match[match].path,
64                         app_match[match].iface,
65                         app_match[match].method,
66                         num, args);
67
68         va_end(args);
69
70         ret = device_display_change_state(DISPLAY_STATE_NORMAL);
71         if (ret != DEVICE_ERROR_NONE)
72                 _E("Failed to change display state");
73
74         return ret;
75 }
76