50be7da954e388813424e7c14531e55c35840411
[platform/core/appfw/appcore-widget.git] / src / widget_app.c
1 /*
2  * Copyright (c) 2015 - 2016 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
18 #include <stdlib.h>
19
20 #include <bundle.h>
21 #include <bundle_internal.h>
22 #include <aul.h>
23 #include <dlog.h>
24 #include <glib.h>
25 #include <glib-object.h>
26 #include <stdlib.h>
27 #include <app_control.h>
28 #include <app_control_internal.h>
29 #include <Elementary.h>
30 #include <widget_errno.h>
31 #include <widget_instance.h>
32 #include <widget_service_internal.h>
33 #include <aul_app_com.h>
34 #include <Ecore_Wayland.h>
35 #include <system_info.h>
36
37 #include "widget_app.h"
38 #include "widget-log.h"
39 #include "widget-private.h"
40 #include "widget_app_internal.h"
41
42 #ifdef LOG_TAG
43 #undef LOG_TAG
44 #endif
45
46 #define STR_MAX_BUF 128
47 #define LOG_TAG "CAPI_WIDGET_APPLICATION"
48 #define K_REASON    "__WC_K_REASON__"
49
50 typedef enum _widget_obj_state_e {
51         WC_READY = 0,
52         WC_RUNNING = 1,
53         WC_PAUSED = 2,
54         WC_TERMINATED = 3
55 } widget_obj_state_e;
56
57 struct app_event_handler {
58         app_event_type_e type;
59         app_event_cb cb;
60         void *data;
61 };
62
63 struct app_event_info {
64         app_event_type_e type;
65         void *value;
66 };
67
68 struct _widget_class {
69         void *user_data;
70         widget_instance_lifecycle_callback_s ops;
71         char *classid;
72         struct _widget_class *next;
73         struct _widget_class *prev;
74 };
75
76 struct _widget_context {
77         char *id;
78         struct _widget_class *provider;
79         int state;
80         void *tag;
81         Evas_Object *win;
82         bundle *content;
83         widget_instance_lifecycle_callback_s ops;
84 };
85
86 typedef struct _widget_class widget_class_s;
87 typedef struct _widget_context widget_context_s;
88
89 static int caller_pid = 0;
90 static widget_app_lifecycle_callback_s *app_ops;
91 static void *app_user_data = NULL;
92 static char *appid = NULL;
93 static widget_class_h class_provider = NULL;
94 static GList *contexts = NULL;
95 static char *viewer_endpoint = NULL;
96
97 static inline bool _is_widget_feature_enabled(void)
98 {
99         static bool feature = false;
100         static bool retrieved = false;
101         int ret;
102
103         if (retrieved == true)
104                 return feature;
105
106         ret = system_info_get_platform_bool(
107                         "http://tizen.org/feature/shell.appwidget", &feature);
108         if (ret != SYSTEM_INFO_ERROR_NONE) {
109                 _E("failed to get system info");
110                 return false;
111         }
112
113         retrieved = true;
114
115         return feature;
116 }
117
118 static gint __comp_by_id(gconstpointer a, gconstpointer b)
119 {
120         widget_context_s *wc = (widget_context_s *)a;
121
122         return strcmp(wc->id, (const char *)b);
123 }
124
125 static widget_context_s *__find_context_by_id(const char *id)
126 {
127         GList *ret = g_list_find_custom(contexts, id, __comp_by_id);
128
129         if (ret == NULL)
130                 return NULL;
131
132         return ret->data;
133 }
134
135 static int __send_update_status(const char *class_id, const char *instance_id,
136         int status, bundle *extra, int internal_only)
137 {
138         bundle *b = extra;
139
140         if (b == NULL)
141                 b = bundle_create();
142
143         bundle_add_str(b, WIDGET_K_ID, class_id);
144         bundle_add_str(b, WIDGET_K_INSTANCE, instance_id);
145         bundle_add_byte(b, WIDGET_K_STATUS, &status, sizeof(int));
146
147         _E("send update %s(%d) to %s", instance_id, status, viewer_endpoint);
148         aul_app_com_send(viewer_endpoint, b);
149
150         if (extra == NULL)
151                 bundle_free(b);
152
153         return 0;
154 }
155
156 static int __instance_create(widget_class_h handle, const char *id, bundle *b)
157 {
158         widget_context_s *wc = NULL;
159         int w = 0, h = 0;
160         char *w_str = NULL, *h_str = NULL;
161         char *remain = NULL;
162         int ret = 0;
163
164         wc = (widget_context_s *)malloc(sizeof(widget_context_s));
165         if (!wc)
166                 return WIDGET_ERROR_OUT_OF_MEMORY;
167
168         wc->state = WC_READY;
169         wc->id = g_strdup(id);
170         wc->provider = handle;
171         wc->win = NULL;
172
173         wc->content = bundle_dup(b);
174         bundle_get_str(b, WIDGET_K_WIDTH, &w_str);
175         bundle_get_str(b, WIDGET_K_HEIGHT, &h_str);
176
177         if (w_str)
178                 w = (int)g_ascii_strtoll(w_str, &remain, 10);
179
180         if (h_str)
181                 h = (int)g_ascii_strtoll(h_str, &remain, 10);
182
183         contexts = g_list_append(contexts, wc);
184
185         handle->ops.create(wc, b, w, h, handle->user_data);
186         ret = __send_update_status(handle->classid, wc->id,
187                         WIDGET_INSTANCE_EVENT_CREATE, b, 0);
188
189         return ret;
190 }
191
192 static int __instance_destroy(widget_class_h handle, const char *id,
193                 widget_destroy_type_e reason, bundle *b)
194 {
195         widget_context_s *wc = __find_context_by_id(id);
196         int ret = 0;
197
198         if (wc) {
199                 wc->state = WC_TERMINATED;
200                 handle->ops.destroy(wc, (widget_app_destroy_type_e)reason, b,
201                                 handle->user_data);
202
203                 ret = __send_update_status(handle->classid, id,
204                                 WIDGET_INSTANCE_EVENT_TERMINATE, b, 0);
205
206                 contexts = g_list_remove(contexts, wc);
207
208                 if (wc->id)
209                         free(wc->id);
210                 free(wc);
211         } else {
212                 _E("could not find widget obj: %s", id);
213                 ret = WIDGET_ERROR_INVALID_PARAMETER;
214         }
215
216         return ret;
217 }
218
219 static widget_class_h __find_class_handler(const char *class_id,
220                 widget_class_h handle)
221 {
222         if (!class_id || !handle)
223                 return NULL;
224
225         widget_class_h head = handle;
226
227         while (head) {
228                 if (head->classid && strcmp(head->classid, class_id) == 0)
229                         return head;
230
231                 head = head->next;
232         }
233
234         return NULL;
235 }
236
237 static void __control(bundle *b)
238 {
239         char *class_id = NULL;
240         char *id = NULL;
241         char *operation = NULL;
242         char *reason = NULL;
243         char *remain = NULL;
244         int destroy_type = WIDGET_DESTROY_TYPE_DEFAULT;
245
246         widget_class_h handle = NULL;
247         bundle_get_str(b, WIDGET_K_CLASS, &class_id);
248         /* for previous version compatibility, use appid for default class id */
249         if (class_id == NULL)
250                 class_id = appid;
251
252         bundle_get_str(b, WIDGET_K_INSTANCE, &id);
253         bundle_get_str(b, WIDGET_K_OPERATION, &operation);
254
255         handle = __find_class_handler(class_id, class_provider);
256         if (!handle) {
257                 _E("no handle provided: %s", class_id);
258                 goto error;
259         }
260
261         if (!operation) {
262                 _E("no operation provided");
263                 goto error;
264         }
265
266         if (strcmp(operation, "create") == 0) {
267                 __instance_create(handle, id, b);
268         } else if (strcmp(operation, "resize") == 0) {
269                 /* TODO */
270         } else if (strcmp(operation, "update") == 0) {
271                 /* TODO */
272         } else if (strcmp(operation, "destroy") == 0) {
273                 bundle_get_str(b, WIDGET_K_REASON, &reason);
274                 if (reason)
275                         destroy_type = (int)g_ascii_strtoll(reason, &remain,
276                                         10);
277
278                 __instance_destroy(handle, id, destroy_type, b);
279         } else if (strcmp(operation, "resume") == 0) {
280                 /* TODO */
281         } else if (strcmp(operation, "pause") == 0) {
282                 /* TODO */
283         }
284
285         return;
286 error:
287         LOGD("error on control");
288         return;
289 }
290
291 static void __show_all()
292 {
293         LOGD("resume");
294 }
295
296 static Eina_Bool __show_cb(void *data, int type, void *event)
297 {
298         Ecore_Wl_Event_Window_Show *ev = event;
299         LOGD("show %d %d", (unsigned int)ev->win, (unsigned int)ev->data[0]);
300         return ECORE_CALLBACK_RENEW;
301 }
302
303 static Eina_Bool __hide_cb(void *data, int type, void *event)
304 {
305         Ecore_Wl_Event_Window_Hide *ev = event;
306         LOGD("hide %d", (unsigned int)ev->win);
307         return ECORE_CALLBACK_RENEW;
308 }
309
310 static Eina_Bool __visibility_cb(void *data, int type, void *event)
311 {
312         Ecore_Wl_Event_Window_Visibility_Change *ev = event;
313         LOGD("visiblity change: %d %d", (unsigned int)ev->win,  (unsigned int)ev->fully_obscured);
314         return ECORE_CALLBACK_RENEW;
315 }
316
317 static Eina_Bool __lower_cb(void *data, int type, void *event)
318 {
319         LOGD("lower");
320         return ECORE_CALLBACK_RENEW;
321 }
322
323 static void __add_climsg()
324 {
325         ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __show_cb, NULL);
326         ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __hide_cb, NULL);
327         ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE, __visibility_cb, NULL);
328         ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER, __lower_cb, NULL);
329 }
330
331 static int __aul_handler(aul_type type, bundle *b, void *data)
332 {
333         char *caller = NULL;
334         char *remain = NULL;
335
336         switch (type) {
337         case AUL_START:
338                 if (b) {
339                         bundle_get_str(b, WIDGET_K_CALLER, &caller);
340                         if (caller) {
341                                 caller_pid = g_ascii_strtoll(caller, &remain,
342                                                 10);
343                         } else {
344                                 /* using caller appid and query pid using caller appid? */
345                                 _E("no caller pid");
346                         }
347                 }
348
349                 __control(b);
350                 break;
351         case AUL_RESUME:
352                 __show_all();
353                 break;
354         case AUL_TERMINATE:
355                 widget_app_exit();
356                 break;
357         default:
358                 break;
359         }
360
361         return 0;
362 }
363
364 static char *__get_domain_name(char *appid)
365 {
366         char *name_token;
367
368         if (appid == NULL) {
369                 _E("appid is NULL");
370                 return NULL;
371         }
372
373         name_token = strrchr(appid, '.');
374
375         if (name_token == NULL) {
376                 _E("appid is invalid");
377                 return appid;
378         }
379
380         name_token++;
381
382         return name_token;
383 }
384
385 extern int _set_i18n(const char *name);
386
387 static int __before_loop(int argc, char **argv)
388 {
389         int r;
390         bundle *kb = NULL;
391         char *wayland_display = NULL;
392         char *xdg_runtime_dir = NULL;
393         char *name;
394
395 #if !(GLIB_CHECK_VERSION(2, 36, 0))
396         g_type_init();
397 #endif
398
399         kb = bundle_import_from_argv(argc, argv);
400         if (kb) {
401                 bundle_get_str(kb, AUL_K_WAYLAND_WORKING_DIR, &xdg_runtime_dir);
402                 bundle_get_str(kb, AUL_K_WAYLAND_DISPLAY, &wayland_display);
403                 bundle_get_str(kb, WIDGET_K_ENDPOINT, &viewer_endpoint);
404                 if (viewer_endpoint) {
405                         _E("viewer endpoint :%s", viewer_endpoint);
406                         viewer_endpoint = strdup(viewer_endpoint);
407                 } else {
408                         _E("endpoint is missing");
409                 }
410
411                 if (xdg_runtime_dir)
412                         setenv("XDG_RUNTIME_DIR", xdg_runtime_dir, 1);
413
414                 if (wayland_display)
415                         setenv("WAYLAND_DISPLAY", wayland_display, 1);
416
417                 bundle_free(kb);
418                 kb = NULL;
419         } else {
420                 _E("failed to get launch argv");
421         }
422
423         elm_init(argc, argv);
424
425         r = aul_launch_init(__aul_handler, NULL);
426         if (r < 0) {
427                 return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
428                                 __FUNCTION__,
429                                 "Fail to call the aul_launch_init");
430         }
431
432         r = aul_launch_argv_handler(argc, argv);
433         if (r < 0) {
434                 return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
435                                 __FUNCTION__,
436                                 "Fail to call the aul_launch_argv_handler");
437         }
438
439         r = app_get_id(&appid);
440         if (r != APP_ERROR_NONE)
441                 return r;
442
443         name = __get_domain_name(appid);
444
445         if (name == NULL) {
446                 return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
447                                 __FUNCTION__,
448                                 "Fail to call __get_domain_name");
449         }
450
451         r = _set_i18n(name);
452
453         if (r < 0) {
454                 return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
455                                 __FUNCTION__,
456                                 "Fail to call _set_i18n");
457         }
458
459         __add_climsg();
460
461         class_provider = app_ops->create(app_user_data);
462         if (class_provider == NULL) {
463                 return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
464                                 __FUNCTION__, "widget_class is NULL");
465         }
466
467         return WIDGET_ERROR_NONE;
468 }
469
470 static void __after_loop()
471 {
472         if (app_ops->terminate)
473                 app_ops->terminate(app_user_data);
474
475         if (viewer_endpoint)
476                 free(viewer_endpoint);
477
478         elm_shutdown();
479 }
480
481 EXPORT_API int widget_app_main(int argc, char **argv,
482                 widget_app_lifecycle_callback_s *callback, void *user_data)
483 {
484         int r;
485
486         if (!_is_widget_feature_enabled()) {
487                 _E("not supported");
488                 return WIDGET_ERROR_NOT_SUPPORTED;
489         }
490
491         if (argc <= 0 || argv == NULL || callback == NULL)
492                 return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
493                                 __FUNCTION__, NULL);
494
495         if (callback->create == NULL)
496                 return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
497                                 __FUNCTION__,
498                                 "widget_app_create_cb() callback must be "
499                                 "registered");
500
501         app_ops = callback;
502         app_user_data = user_data;
503         r = __before_loop(argc, argv);
504         if (r < 0)
505                 return r;
506
507         ecore_main_loop_begin();
508         aul_status_update(STATUS_DYING);
509         __after_loop();
510
511         return WIDGET_ERROR_NONE;
512 }
513
514 EXPORT_API int widget_app_exit(void)
515 {
516         if (!_is_widget_feature_enabled()) {
517                 _E("not supported");
518                 return WIDGET_ERROR_NOT_SUPPORTED;
519         }
520
521         ecore_main_loop_quit();
522
523         return WIDGET_ERROR_NONE;
524 }
525
526 static gboolean __finish_event_cb(gpointer user_data)
527 {
528         if (user_data == NULL)
529                 return FALSE;
530
531         widget_context_s *wc = (widget_context_s *)user_data;
532
533         switch (wc->state) {
534         case WC_READY:
535
536                 break;
537         case WC_RUNNING:
538
539                 break;
540         case WC_PAUSED:
541
542                 break;
543         default:
544                 break;
545         }
546
547
548         return FALSE;
549 }
550
551 EXPORT_API int widget_app_terminate_context(widget_context_h context)
552 {
553         if (!_is_widget_feature_enabled()) {
554                 _E("not supported");
555                 return WIDGET_ERROR_NOT_SUPPORTED;
556         }
557
558         if (context == NULL)
559                 return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
560                                 __FUNCTION__, NULL);
561
562         g_idle_add(__finish_event_cb, context);
563         return WIDGET_ERROR_NONE;
564 }
565
566 EXPORT_API int widget_app_foreach_context(widget_context_cb cb, void *data)
567 {
568         GList *list;
569         widget_context_s *wc;
570
571         if (!_is_widget_feature_enabled()) {
572                 _E("not supported");
573                 return WIDGET_ERROR_NOT_SUPPORTED;
574         }
575
576         if (!cb)
577                 return WIDGET_ERROR_INVALID_PARAMETER;
578
579         list = g_list_first(contexts);
580
581         while (list) {
582                 wc = (widget_context_s *)list->data;
583                 if (wc) {
584                         if (!cb(wc, data))
585                                 break;
586                 }
587                 list = list->next;
588         }
589
590         return WIDGET_ERROR_NONE;
591 }
592
593 EXPORT_API int widget_app_add_event_handler(app_event_handler_h *event_handler,
594                 app_event_type_e event_type, app_event_cb callback,
595                 void *user_data)
596 {
597         if (!_is_widget_feature_enabled()) {
598                 _E("not supported");
599                 return WIDGET_ERROR_NOT_SUPPORTED;
600         }
601
602         /* TODO */
603         if (!event_handler || !callback)
604                 return WIDGET_ERROR_INVALID_PARAMETER;
605
606         switch (event_type) {
607         case APP_EVENT_LOW_MEMORY:
608         case APP_EVENT_LOW_BATTERY:
609         case APP_EVENT_LANGUAGE_CHANGED:
610         case APP_EVENT_DEVICE_ORIENTATION_CHANGED:
611         case APP_EVENT_REGION_FORMAT_CHANGED:
612         case APP_EVENT_SUSPENDED_STATE_CHANGED:
613
614                 break;
615         default:
616                 return WIDGET_ERROR_INVALID_PARAMETER;
617         }
618
619         return WIDGET_ERROR_NONE;
620 }
621
622 EXPORT_API int widget_app_remove_event_handler(app_event_handler_h
623                                                 event_handler)
624 {
625         if (!_is_widget_feature_enabled()) {
626                 _E("not supported");
627                 return WIDGET_ERROR_NOT_SUPPORTED;
628         }
629
630         /* TODO */
631         if (!event_handler)
632                 return WIDGET_ERROR_INVALID_PARAMETER;
633
634         return WIDGET_ERROR_NONE;
635 }
636
637 EXPORT_API const char *widget_app_get_id(widget_context_h context)
638 {
639         if (!_is_widget_feature_enabled()) {
640                 _E("not supported");
641                 set_last_result(WIDGET_ERROR_NOT_SUPPORTED);
642                 return NULL;
643         }
644
645         if (!context) {
646                 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
647                 return NULL;
648         }
649
650         set_last_result(WIDGET_ERROR_NONE);
651         return context->id;
652 }
653
654 EXPORT_API int widget_app_get_elm_win(widget_context_h context,
655                                         Evas_Object **win)
656 {
657         widget_context_s *cxt = (widget_context_s *)context;
658         Evas_Object *ret_win;
659         Ecore_Wl_Window *wl_win;
660
661         if (!_is_widget_feature_enabled()) {
662                 _E("not supported");
663                 return WIDGET_ERROR_NOT_SUPPORTED;
664         }
665
666         if (context == NULL || win == NULL)
667                 return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
668                                 __FUNCTION__, NULL);
669
670         ret_win = elm_win_add(NULL, cxt->id, ELM_WIN_BASIC);
671         if (ret_win == NULL) {
672                 _E("failed to create window");
673                 return WIDGET_ERROR_FAULT;
674         }
675
676         wl_win = elm_win_wl_window_get(ret_win);
677         if (wl_win == NULL) {
678                 _E("failed to get wayland window");
679                 evas_object_del(ret_win);
680                 return WIDGET_ERROR_FAULT;
681         }
682
683         ecore_wl_window_class_name_set(wl_win, cxt->id);
684
685         *win = ret_win;
686         cxt->win = ret_win;
687
688         return WIDGET_ERROR_NONE;
689 }
690
691 widget_class_h _widget_class_create(widget_class_s *prev, const char *class_id,
692                 widget_instance_lifecycle_callback_s callback, void *user_data)
693 {
694         widget_class_s *wc;
695
696         if (!_is_widget_feature_enabled()) {
697                 _E("not supported");
698                 set_last_result(WIDGET_ERROR_NOT_SUPPORTED);
699                 return NULL;
700         }
701
702         if (class_id == NULL) {
703                 set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
704                 return NULL;
705         }
706
707         wc = (widget_class_s *)malloc(sizeof(widget_class_s));
708         if (wc == NULL) {
709                 _E("failed to malloc : %s", __FUNCTION__);
710                 set_last_result(WIDGET_ERROR_OUT_OF_MEMORY);
711                 return NULL;
712         }
713
714         wc->classid = strdup(class_id);
715         wc->user_data = user_data;
716         wc->ops = callback;
717         wc->next = prev;
718         wc->prev = NULL;
719
720         set_last_result(WIDGET_ERROR_NONE);
721
722         if (prev)
723                 prev->prev = wc;
724
725         return wc;
726 }
727
728 EXPORT_API widget_class_h widget_app_class_add(widget_class_h widget_class,
729                 const char *class_id,
730                 widget_instance_lifecycle_callback_s callback, void *user_data)
731 {
732         return _widget_class_create(widget_class, class_id, callback,
733                         user_data);
734 }
735
736 EXPORT_API widget_class_h widget_app_class_create(
737                 widget_instance_lifecycle_callback_s callback, void *user_data)
738 {
739         return _widget_class_create(class_provider, appid, callback, user_data);
740 }
741
742 EXPORT_API int widget_app_context_set_tag(widget_context_h context, void *tag)
743 {
744         if (!_is_widget_feature_enabled()) {
745                 _E("not supported");
746                 return WIDGET_ERROR_NOT_SUPPORTED;
747         }
748
749         if (context == NULL)
750                 return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
751                                 __FUNCTION__, NULL);
752
753         context->tag = tag;
754
755         return WIDGET_ERROR_NONE;
756 }
757
758 EXPORT_API int widget_app_context_get_tag(widget_context_h context, void **tag)
759 {
760         if (!_is_widget_feature_enabled()) {
761                 _E("not supported");
762                 return WIDGET_ERROR_NOT_SUPPORTED;
763         }
764
765         if (context == NULL || tag == NULL)
766                 return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
767                                 __FUNCTION__, NULL);
768
769         *tag = context->tag;
770
771         return WIDGET_ERROR_NONE;
772 }
773
774 EXPORT_API int widget_app_context_set_content_info(widget_context_h context,
775                 bundle *content_info)
776 {
777         const char *class_id = NULL;
778         int ret = 0;
779
780         if (!_is_widget_feature_enabled()) {
781                 _E("not supported");
782                 return WIDGET_ERROR_NOT_SUPPORTED;
783         }
784
785         if (context == NULL || content_info == NULL)
786                 return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
787                                 __FUNCTION__, NULL);
788
789         if (context->provider == NULL)
790                 return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER,
791                                 __FUNCTION__, NULL);
792
793         class_id = context->provider->classid;
794
795         if (class_id == NULL)
796                 return widget_app_error(WIDGET_ERROR_FAULT, __FUNCTION__, NULL);
797
798         ret = __send_update_status(class_id, context->id,
799                         WIDGET_INSTANCE_EVENT_UPDATE, content_info, true);
800
801         if (ret < 0) {
802                 _E("failed to send content info: %s of %s (%d)", context->id,
803                                 class_id, ret);
804                 return widget_app_error(WIDGET_ERROR_IO_ERROR, __FUNCTION__,
805                                 NULL);
806         }
807
808         return WIDGET_ERROR_NONE;
809 }
810
811 EXPORT_API int widget_app_context_set_title(widget_context_h context,
812                 const char *title)
813 {
814         if (!_is_widget_feature_enabled()) {
815                 _E("not supported");
816                 return WIDGET_ERROR_NOT_SUPPORTED;
817         }
818
819         if (!context || !title)
820                 return WIDGET_ERROR_INVALID_PARAMETER;
821
822         if (context->win)
823                 elm_win_title_set(context->win, title);
824
825         return WIDGET_ERROR_NONE;
826 }
827