cbd7e4c2e5e8f9b8de8cfd1464f9b2a020e6350f
[platform/core/appfw/appcore-widget.git] / src / efl_base / widget_app_internal.c
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdlib.h>
18
19 #include <glib.h>
20 #include <glib-object.h>
21 #include <stdlib.h>
22 #include <sys/types.h>
23 #include <unistd.h>
24
25 #include <bundle.h>
26 #include <bundle_internal.h>
27 #include <aul.h>
28 #include <aul_app_com.h>
29 #include <dlog.h>
30 #include <appcore_multiwindow_base.h>
31
32 #include "widget_app.h"
33 #include "widget-log.h"
34 #include "widget-private.h"
35 #include "widget_app_internal.h"
36 #include "widget-private.h"
37 #include "widget_base.h"
38
39 #ifdef LOG_TAG
40 #undef LOG_TAG
41 #endif
42
43 #define LOG_TAG "CAPI_WIDGET_APPLICATION"
44 static char *__class_id;
45
46 /* LCOV_EXCL_START */
47 static void __inst_cb(const char *class_id, const char *id,
48                 appcore_multiwindow_base_instance_h cxt, void *data)
49 {
50         if (!__class_id)
51                 __class_id = strdup(class_id);
52 }
53 /* LCOV_EXCL_STOP */
54
55 EXPORT_API int widget_app_restart(void)
56 {
57         int ret;
58         int status = AUL_WIDGET_INSTANCE_EVENT_APP_RESTART_REQUEST;
59         bundle *kb;
60
61         appcore_multiwindow_base_instance_foreach_full(__inst_cb, NULL);
62
63         kb = bundle_create();
64         bundle_add_str(kb, AUL_K_WIDGET_ID, __class_id);
65         bundle_add_byte(kb, AUL_K_WIDGET_STATUS, &status, sizeof(int));
66         ret = aul_app_com_send(widget_base_get_viewer_endpoint(), kb);
67         bundle_free(kb);
68         if (__class_id) {
69                 free(__class_id);
70                 __class_id = NULL;
71         }
72
73         if (ret != AUL_R_OK) {
74                 _E("failed to kill app");
75                 return WIDGET_ERROR_IO_ERROR;
76         }
77         return WIDGET_ERROR_NONE;
78 }
79