43de9790cd6911267f7afa702d9afa7ae71c3e0d
[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 static void __inst_cb(const char *class_id, const char *id,
47                 appcore_multiwindow_base_instance_h cxt, void *data)
48 {
49         if (!__class_id)
50                 __class_id = strdup(class_id);
51 }
52
53 EXPORT_API int widget_app_restart(void)
54 {
55         int ret;
56         int status = AUL_WIDGET_INSTANCE_EVENT_APP_RESTART_REQUEST;
57         bundle *kb;
58
59         appcore_multiwindow_base_instance_foreach_full(__inst_cb, NULL);
60
61         kb = bundle_create();
62         bundle_add_str(kb, AUL_K_WIDGET_ID, __class_id);
63         bundle_add_byte(kb, AUL_K_WIDGET_STATUS, &status, sizeof(int));
64         ret = aul_app_com_send(widget_base_get_viewer_endpoint(), kb);
65         bundle_free(kb);
66         if (__class_id) {
67                 free(__class_id);
68                 __class_id = NULL;
69         }
70
71         if (ret != AUL_R_OK) {
72                 _E("failed to kill app");
73                 return WIDGET_ERROR_IO_ERROR;
74         }
75         return WIDGET_ERROR_NONE;
76 }
77