80e1a576f17c49fb49fea1e651d7c9cd1ff918b0
[platform/core/appfw/appcore-widget.git] / include / widget_base.h
1 /*
2  * Copyright (c) 2015 - 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 #pragma once
18
19 #include <stdbool.h>
20 #include <libintl.h>
21 #include <bundle.h>
22 #include <aul.h>
23 #include <app_common.h>
24 #include <appcore_multiwindow_base.h>
25
26 #define FEATURE_SHELL_APPWIDGET "http://tizen.org/feature/shell.appwidget"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 typedef enum widget_base_destroy_type {
33         WIDGET_BASE_DESTROY_TYPE_PERMANENT = 0x00,
34         WIDGET_BASE_DESTROY_TYPE_TEMPORARY = 0x01,
35 } widget_base_destroy_type_e;
36
37 typedef enum widget_base_error {
38         WIDGET_BASE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Operation is successfully completed */
39         WIDGET_BASE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid function parameter */
40         WIDGET_BASE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
41         WIDGET_BASE_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy */
42         WIDGET_BASE_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
43         WIDGET_BASE_ERROR_CANCELED = TIZEN_ERROR_CANCELED, /**< Operation Canceled */
44         WIDGET_BASE_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
45         WIDGET_BASE_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< Time out */
46         WIDGET_BASE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
47         WIDGET_BASE_ERROR_FILE_NO_SPACE_ON_DEVICE = TIZEN_ERROR_FILE_NO_SPACE_ON_DEVICE, /**< No space left on device */
48         WIDGET_BASE_ERROR_FAULT = TIZEN_ERROR_WIDGET | 0x0001, /**< Fault - Unable to recover from the error */
49         WIDGET_BASE_ERROR_ALREADY_EXIST = TIZEN_ERROR_WIDGET | 0x0002, /**< Already exists */
50         WIDGET_BASE_ERROR_ALREADY_STARTED = TIZEN_ERROR_WIDGET | 0x0004, /**< Operation is already started */
51         WIDGET_BASE_ERROR_NOT_EXIST = TIZEN_ERROR_WIDGET | 0x0008, /**< Not exists */
52         WIDGET_BASE_ERROR_DISABLED = TIZEN_ERROR_WIDGET | 0x0010, /**< Disabled */
53         WIDGET_BASE_ERROR_MAX_EXCEEDED = TIZEN_ERROR_WIDGET | 0x0011, /**< Maximum number of instances exceeded (Since 3.0) */
54 } widget_base_error_e;
55
56 typedef appcore_multiwindow_base_instance_h widget_base_instance_h;
57
58 typedef struct _widget_base_class_ops {
59         int (*create)(widget_base_instance_h instance_h, bundle *content,
60                         int w, int h, void *class_data);
61         int (*destroy)(widget_base_instance_h instance_h,
62                         widget_base_destroy_type_e reason, bundle *content,
63                         void *class_data);
64         int (*pause)(widget_base_instance_h instance_h, void *class_data);
65         int (*resume)(widget_base_instance_h instance_h, void *class_data);
66         int (*resize)(widget_base_instance_h instance_h, int w, int h, void *class_data);
67         int (*update)(widget_base_instance_h instance_h, bundle *content, int force,
68                         void *class_data);
69 } widget_base_class_ops;
70
71 typedef struct _widget_base_ops {
72         int (*create)(void *data);
73         int (*terminate)(void *data);
74         void (*init)(int argc, char **argv, void *data);
75         void (*finish)(void);
76         void (*run)(void *data);
77         void (*exit)(void *data);
78         void (*trim_memory)(void *data);
79 } widget_base_ops;
80
81 typedef struct _widget_base_class {
82         char *id;
83         widget_base_class_ops ops;
84 } widget_base_class;
85
86 typedef bool (*widget_base_instance_cb)(widget_base_instance_h instance, void *data);
87
88 int widget_base_foreach_context(widget_base_instance_cb cb, void *data);
89 int widget_base_terminate_context(widget_base_instance_h instance_h);
90 int widget_base_add_event_handler(app_event_handler_h *event_handler,
91                                         app_event_type_e event_type,
92                                         app_event_cb callback,
93                                         void *user_data);
94 int widget_base_remove_event_handler(app_event_handler_h
95                                                 event_handler);
96 int widget_base_context_set_content_info(widget_base_instance_h instance_h,
97                 bundle *content_info);
98 int widget_base_context_get_tag(widget_base_instance_h instance_h, void **tag);
99 int widget_base_context_set_tag(widget_base_instance_h instance_h, void *tag);
100 void *widget_base_context_get_user_data(widget_base_instance_h instance_h);
101 int widget_base_context_set_user_data(widget_base_instance_h instance_h,
102                 void *user_data);
103 int widget_base_context_get_id(widget_base_instance_h instance_h, char **id);
104 const char *widget_base_get_viewer_endpoint(void);
105 int widget_base_init(widget_base_ops ops, int argc, char **argv, void *data);
106 int widget_base_on_create(void);
107 int widget_base_on_terminate(void);
108 int widget_base_on_init(int argc, char **argv);
109 void widget_base_on_finish(void);
110 void widget_base_on_run(void);
111 void widget_base_on_exit(void);
112 int widget_base_on_trim_memory(void);
113 widget_base_ops widget_base_get_default_ops(void);
114 void widget_base_fini(void);
115 int widget_base_exit(void);
116 int widget_base_context_window_bind(
117                 widget_base_instance_h instance_h, const char *id,
118                 Ecore_Wl2_Window *wl_win);
119 int widget_base_class_on_create(widget_base_instance_h instance_h,
120                 bundle *content, int w, int h);
121 int widget_base_class_on_pause(widget_base_instance_h instance_h);
122 int widget_base_class_on_resume(widget_base_instance_h instance_h);
123 int widget_base_class_on_resize(widget_base_instance_h instance_h,
124                 int w, int h);
125 int widget_base_class_on_update(widget_base_instance_h instance_h,
126                 bundle *content, int force);
127 int widget_base_class_on_destroy(widget_base_instance_h instance_h,
128                 widget_base_destroy_type_e reason, bundle *content);
129 widget_base_class widget_base_class_get_default(void);
130 widget_base_class *widget_base_class_add(widget_base_class cls,
131                 const char *class_id, void *class_data);
132
133 #ifdef __cplusplus
134 }
135 #endif