5e29aea8fc99af729f7f1e8d5fffc447c0f01e70
[platform/core/appfw/appcore-widget.git] / include / widget_app.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
18 #ifndef __TIZEN_APPFW_WIDGET_APP_H__
19 #define __TIZEN_APPFW_WIDGET_APP_H__
20
21 #include <tizen.h>
22 #include <app_common.h>
23 #include <bundle.h>
24 #include <widget_errno.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 /**
31  * @addtogroup CAPI_WIDGET_APP_MODULE
32  * @{
33  */
34
35
36 /**
37  * @brief Enumeration for destroy type of widget instance.
38  * @since_tizen 2.3.1
39  */
40 typedef enum widget_app_destroy_type {
41         WIDGET_APP_DESTROY_TYPE_PERMANENT = 0x00, /**< User deleted this widget from the viewer */
42         WIDGET_APP_DESTROY_TYPE_TEMPORARY = 0x01, /**< Widget is deleted because of other reasons (e.g. widget process is terminated temporarily by the system) */
43 } widget_app_destroy_type_e;
44
45
46 /**
47  * @brief The widget class handle.
48  * @since_tizen 2.3.1
49  */
50 typedef struct _widget_class *widget_class_h;
51
52
53 /**
54  * @brief The widget context handle.
55  * @since_tizen 2.3.1
56  */
57 typedef struct _widget_context *widget_context_h;
58
59
60 /**
61  * @brief Called when the widget instance starts.
62  * @details The callback function is called after widget instance is created.
63  *          In this callback, you can initialize resources for this instance.
64  * @since_tizen 2.3.1
65  * @param[in] context The context of widget instance
66  * @param[in] content The data set for the previous status
67  * @param[in] w The pixel value for widget width
68  * @param[in] h The pixel value for widget height
69  * @param[in] user_data The user data passed from widget_app_class_create function
70  *
71  * @return #WIDGET_ERROR_NONE on success,
72  *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
73  */
74 typedef int (*widget_instance_create_cb)(widget_context_h context, bundle *content, int w, int h, void *user_data);
75
76
77 /**
78  * @brief Called before the widget instance is destroyed.
79  * @details The callback function is called before widget instance is destroyed.
80  *          In this callback, you can finalize resources for this instance.
81  *          If reason is not #WIDGET_APP_DESTROY_TYPE_TEMPORARY, it should store the current status by using incoming bundle.
82  * @since_tizen 2.3.1
83  * @remark Note that the parameter 'content' is used to save the status of the widget instance.
84  *         As a input parameter, content contains the saved status of the widget instance.
85  *         You can fill the content parameter with the current status in this callback,
86  *         then the framework will save the content by receiving it as a output parameter.
87  *         Consequently, you should not use widget_app_context_set_content_info() api in this callback.
88  *         The content will be overwritten after this callback returns with the 'content' parameter.
89  * @param[in] context The context of widget instance
90  * @param[in] reason The reason for destruction
91  * @param[in,out] content The data set to save
92  * @param[in] user_data The user data passed from widget_app_class_create function
93  * @return #WIDGET_ERROR_NONE on success,
94  *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
95  */
96 typedef int (*widget_instance_destroy_cb)(widget_context_h context, widget_app_destroy_type_e reason, bundle *content, void *user_data);
97
98
99 /**
100  * @brief Called when the widget is invisible.
101  * @details The callback function is called when the widget is invisible.
102  *          The paused instance may be destroyed by framework.
103  * @since_tizen 2.3.1
104  * @param[in] context The context of widget instance
105  * @param[in] user_data The user data passed from widget_app_class_create function
106  * @return #WIDGET_ERROR_NONE on success,
107  *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
108  */
109 typedef int (*widget_instance_pause_cb)(widget_context_h context, void *user_data);
110
111
112 /**
113  * @brief Called when the widget is visible.
114  * @details The callback function is called when the widget is visible.
115  * @since_tizen 2.3.1
116  * @param[in] context The context of widget instance
117  * @param[in] user_data The user data passed from widget_app_class_create function
118  * @return #WIDGET_ERROR_NONE on success,
119  *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
120  */
121 typedef int (*widget_instance_resume_cb)(widget_context_h context, void *user_data);
122
123
124 /**
125  * @brief Called before the widget size is changed.
126  * @details The callback function is called before the widget size is changed.
127  * @since_tizen 2.3.1
128  * @param[in] context The context of widget instance
129  * @param[in] w The pixel value for widget width
130  * @param[in] h The pixel value for widget height
131  * @param[in] user_data The user data passed from widget_app_class_create function
132  * @return #WIDGET_ERROR_NONE on success,
133  *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
134  */
135 typedef int (*widget_instance_resize_cb)(widget_context_h context, int w, int h, void *user_data);
136
137
138 /**
139  * @brief Called when the event for updating widget is received.
140  * @details The callback function is called when the event for updating widget is received.
141  * @since_tizen 2.3.1
142  * @param[in] context The context of widget instance
143  * @param[in] content The data set for updating this widget. It will be provided by requester.
144  *                    Requester can use widget_service_trigger_update()
145  * @param[in] force Although the widget is paused, if it is TRUE, the widget can be updated
146  * @param[in] user_data The user data passed from widget_app_class_create function
147  * @return #WIDGET_ERROR_NONE on success,
148  *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
149  * @see widget_service_trigger_update()
150  */
151 typedef int (*widget_instance_update_cb)(widget_context_h context, bundle *content, int force, void *user_data);
152
153
154 /**
155  * @brief The structure type containing the set of callback functions for lifecycle of a widget instance.
156  * @since_tizen 2.3.1
157  */
158 typedef struct {
159         widget_instance_create_cb create; /**< The callback function is called after widget instance is created. */
160         widget_instance_destroy_cb destroy; /**< The callback function is called before widget instance is destroyed. */
161         widget_instance_pause_cb pause; /**< The callback function is called when the widget is invisible. */
162         widget_instance_resume_cb resume; /**< The callback function is called when the widget is visible. */
163         widget_instance_resize_cb resize; /**< The callback function is called before the widget size is changed. */
164         widget_instance_update_cb update; /**< The callback function is called when the event for updating widget is received. */
165 } widget_instance_lifecycle_callback_s;
166
167
168 /**
169  * @brief Called when the application starts.
170  * @details The callback function is called before the main loop of the application starts.
171  *          In this callback, you can initialize resources which can be shared among widget instances.
172  *          This function should return the handle for widget class so that it will be used for making instances of widget.
173  * @since_tizen 2.3.1
174  * @param[in] user_data The user data passed from the callback registration function
175  * @return The object of widget class
176  * @see widget_app_main()
177  * @code
178  *
179  * static widget_class_h __widget_app_created(void *user_data)
180  * {
181  *     widget_instance_lifecycle_callback_s callback = { .... };
182  *
183  *     return widget_app_class_create(callback);
184  * }
185  *
186  * @endcode
187  */
188 typedef widget_class_h (*widget_app_create_cb)(void *user_data);
189
190
191 /**
192  * @brief Called when the application's main loop exits.
193  * @details This callback function is called once after the main loop of the application exits.
194  *          You should release the application's resources in this function.
195  * @since_tizen 2.3.1
196  * @param[in] user_data The user data passed from the callback registration function
197  * @see widget_app_main()
198  */
199 typedef void (*widget_app_terminate_cb)(void *user_data);
200
201
202 /**
203  * @brief The structure for lifecycle of a widget application.
204  * @since_tizen 2.3.1
205  */
206 typedef struct {
207         widget_app_create_cb create; /**< The callback function is called before the main loop of the application starts. */
208         widget_app_terminate_cb terminate; /**< This callback function is called once after the main loop of the application exits. */
209 } widget_app_lifecycle_callback_s;
210
211
212 /**
213  * @brief Called for each widget context.
214  * @details This function will be called in the function of widget_app_foreach_context repeatedly.
215  * @since_tizen 2.3.1
216  * @param[in] context The context for widget instance
217  * @param[in] data The data for caller
218  * @return @c true to continue with the next iteration of the loop,
219  *         otherwise @c false to break out of the loop
220  * @see widget_app_foreach_context()
221  */
222 typedef bool (*widget_context_cb)(widget_context_h context, void *data);
223
224
225 /**
226  * @brief Runs the main loop of the application until widget_app_exit() is called.
227  * @since_tizen 2.3.1
228  * @param[in] argc The argument count
229  * @param[in] argv The argument vector
230  * @param[in] callback The set of callback functions to handle application events
231  * @param[in] user_data The user data to be passed to the callback functions
232  * @return #WIDGET_ERROR_NONE on success,
233  *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
234  * @retval #WIDGET_ERROR_NONE Successful
235  * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
236  * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
237  * @retval #WIDGET_ERROR_FAULT Unrecoverable error
238  * @see widget_app_exit()
239  */
240 int widget_app_main(int argc, char **argv, widget_app_lifecycle_callback_s *callback, void *user_data);
241
242
243 /**
244  * @brief Exits the main loop of the application.
245  * @details The main loop of the application stops and widget_app_terminate_cb() is invoked.
246  * @since_tizen 2.3.1
247  * @return #WIDGET_ERROR_NONE on success,
248  *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
249  * @retval #WIDGET_ERROR_NONE Successful
250  * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
251  * @retval #WIDGET_ERROR_FAULT Unrecoverable error
252  * @see widget_app_main()
253  * @see widget_app_terminate_cb()
254  */
255 int widget_app_exit(void);
256
257
258 /**
259  * @brief Finishes context for the widget instance.
260  * @since_tizen 2.3.1
261  * @param[in] context The context for widget instance
262  * @return #WIDGET_ERROR_NONE on success,
263  *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
264  * @retval #WIDGET_ERROR_NONE Successful
265  * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
266  * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
267  * @retval #WIDGET_ERROR_FAULT Unrecoverable error
268  */
269 int widget_app_terminate_context(widget_context_h context);
270
271
272 /**
273  * @brief Retrieves all widget contexts in this application.
274  * @since_tizen 2.3.1
275  * @param[in] callback The iteration callback function
276  * @param[in] data The data for the callback function
277  * @return #WIDGET_ERROR_NONE on success,
278  *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
279  * @retval #WIDGET_ERROR_NONE Successful
280  * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
281  * @retval #WIDGET_ERROR_CANCELED The iteration is canceled
282  * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
283  * @retval #WIDGET_ERROR_FAULT Unrecoverable error
284  * @see widget_app_foreach_context()
285  */
286 int widget_app_foreach_context(widget_context_cb callback, void *data);
287
288
289 /**
290  * @brief Adds the system event handler.
291  * @since_tizen 2.3.1
292  * @param[out] event_handler The event handler
293  * @param[in] event_type The system event type. APP_EVENT_DEVICE_ORIENTATION_CHANGED is not supported
294  * @param[in] callback The callback function
295  * @param[in] user_data The user data to be passed to the callback function
296  * @return #WIDGET_ERROR_NONE on success,
297  *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
298  * @retval #WIDGET_ERROR_NONE Successful
299  * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
300  * @retval #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
301  * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
302  * @retval #WIDGET_ERROR_FAULT Unrecoverable error
303  * @see app_event_type_e
304  * @see app_event_cb()
305  * @see watch_app_remove_event_handler()
306  */
307 int widget_app_add_event_handler(app_event_handler_h *event_handler, app_event_type_e event_type,
308                 app_event_cb callback, void *user_data);
309
310 /**
311  * @brief Removes registered event handler.
312  * @since_tizen 2.3.1
313  * @param[in] event_handler The event handler
314  * @return #WIDGET_ERROR_NONE on success,
315  *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
316  * @retval #WIDGET_ERROR_NONE Successful
317  * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
318  * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
319  * @retval #WIDGET_ERROR_FAULT Unrecoverable error
320  * @see watch_app_add_event_handler()
321  */
322 int widget_app_remove_event_handler(app_event_handler_h event_handler);
323
324
325 /**
326  * @brief Gets a widget instance id.
327  * @since_tizen 2.3.1
328  * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
329  * @remark You must not free returned Widget ID
330  * @param[in] context The context for widget instance
331  * @return Widget ID on success,
332  *         otherwise NULL
333  * @exception #WIDGET_ERROR_NOT_SUPPORTED Not supported
334  * @exception #WIDGET_ERROR_FAULT Unrecoverable error
335  * @see get_last_result()
336  */
337 const char *widget_app_get_id(widget_context_h context);
338
339
340 /**
341  * @brief Makes a class for widget instances.
342  * @since_tizen 2.3.1
343  * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
344  * @param[in] callback The set of lifecycle callbacks
345  * @param[in] user_data The user data to be passed to the callback functions
346  * @return The new widget class object,
347  *         NULL on error
348  * @exception #WIDGET_ERROR_NONE Successfully added
349  * @exception #WIDGET_ERROR_INVALID_PARAMETER Not supported
350  * @exception #WIDGET_ERROR_NOT_SUPPORTED Not supported
351  * @exception #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
352  * @see get_last_result()
353  */
354 widget_class_h widget_app_class_create(widget_instance_lifecycle_callback_s callback, void *user_data);
355
356
357 /**
358  * @brief Sets a tag in the context.
359  * @since_tizen 2.3.1
360  * @param[in] context The context for widget instance
361  * @param[in] tag The value to save
362  * @return #WIDGET_ERROR_NONE on success,
363  *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
364  * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
365  * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
366  * @retval #WIDGET_ERROR_FAULT Unrecoverable error
367  */
368 int widget_app_context_set_tag(widget_context_h context, void *tag);
369
370
371 /**
372  * @brief Gets the tag in the context.
373  * @since_tizen 2.3.1
374  * @param[in] context The context for widget instance
375  * @param[out] tag The value to get
376  * @return #WIDGET_ERROR_NONE on success,
377  *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
378  * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
379  * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
380  * @retval #WIDGET_ERROR_FAULT Unrecoverable error
381  */
382 int widget_app_context_get_tag(widget_context_h context, void **tag);
383
384
385 /**
386  * @brief Sets the content info to the widget.
387  * @since_tizen 2.3.1
388  * @param[in] context The context for widget instance
389  * @param[in] content_info The data set to save
390  * @return #WIDGET_ERROR_NONE on success,
391  *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
392  * @retval #WIDGET_ERROR_NONE Successfully sent
393  * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid argument
394  * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
395  * @retval #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
396  * @retval #WIDGET_ERROR_FAULT Unrecoverable error
397  */
398 int widget_app_context_set_content_info(widget_context_h context, bundle *content_info);
399
400
401 /**
402  * @brief Sends the title to the widget.
403  * @since_tizen 2.3.1
404  * @param[in] context The context for widget instance
405  * @param[in] title When an accessibility mode is turned on, this string will be read
406  * @return #WIDGET_ERROR_NONE on success,
407  *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
408  * @retval #WIDGET_ERROR_NONE Successfully sent
409  * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid argument
410  * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
411  * @retval #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
412  * @retval #WIDGET_ERROR_FAULT Unrecoverable error
413  */
414 int widget_app_context_set_title(widget_context_h context, const char *title);
415
416
417 /**
418  * @brief Adds an additional widget class for multi-class of widget instantiation.
419  * @since_tizen 3.0
420  * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
421  * @param[in] widget_class The result of widget_app_class_create()
422  * @param[in] class_id The class id of provider
423  * @param[in] callback The set of lifecycle callbacks
424  * @param[in] user_data The user data to be passed to the callback functions
425  * @return The new widget class object,
426  *         NULL on error
427  * @exception #WIDGET_ERROR_NONE Successfully added
428  * @exception #WIDGET_ERROR_INVALID_PARAMETER Not supported
429  * @exception #WIDGET_ERROR_NOT_SUPPORTED Not supported
430  * @exception #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
431  * @see get_last_result()
432  */
433 widget_class_h widget_app_class_add(widget_class_h widget_class, const char *class_id,
434                 widget_instance_lifecycle_callback_s callback, void *user_data);
435
436 /**
437  * @}
438  */
439
440 #ifdef __cplusplus
441 }
442 #endif
443
444 #endif /* __TIZEN_APPFW_WIDGET_APP_H__ */