2 * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef __TIZEN_APPFW_WIDGET_APP_H__
19 #define __TIZEN_APPFW_WIDGET_APP_H__
22 #include <app_control.h>
23 #include <app_common.h>
25 #include <widget_errno.h>
32 * @addtogroup CAPI_WIDGET_APP_MODULE
38 * @brief Enumeration for destroy type of widget instance.
41 typedef enum widget_app_destroy_type {
42 WIDGET_APP_DESTROY_TYPE_PERMANENT = 0x00, /**< User deleted this widget from the viewer */
43 WIDGET_APP_DESTROY_TYPE_TEMPORARY = 0x01, /**< Widget is deleted because of other reasons (e.g. widget process is terminated temporarily by the system) */
44 } widget_app_destroy_type_e;
48 * @brief The widget class handle.
51 typedef struct _widget_class *widget_class_h;
55 * @brief The widget context handle.
58 typedef struct _widget_context *widget_context_h;
62 * @brief Called when the widget instance starts.
63 * @details The callback function is called after widget instance is created.
64 * In this callback, you can initialize resources for this instance.
66 * @param[in] context The context of widget instance
67 * @param[in] content The data set for the previous status
68 * @param[in] w The pixel value for widget width
69 * @param[in] h The pixel value for widget height
70 * @param[in] user_data The user data passed from widget_app_class_create function
72 * @return #WIDGET_ERROR_NONE on success,
73 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
75 typedef int (*widget_instance_create_cb)(widget_context_h context, bundle *content, int w, int h, void *user_data);
79 * @brief Called before the widget instance is destroyed.
80 * @details The callback function is called before widget instance is destroyed.
81 * In this callback, you can finalize resources for this instance.
82 * If reason is not #WIDGET_APP_DESTROY_TYPE_TEMPORARY, it should store the current status by using incoming bundle.
84 * @remark Note that the parameter 'content' is used to save the status of the widget instance.
85 * As a input parameter, content contains the saved status of the widget instance.
86 * You can fill the content parameter with the current status in this callback,
87 * then the framework will save the content by receiving it as a output parameter.
88 * Consequently, you should not use widget_app_context_set_content_info() api in this callback.
89 * The content will be overwritten after this callback returns with the 'content' parameter.
90 * @param[in] context The context of widget instance
91 * @param[in] reason The reason for destruction
92 * @param[in,out] content The data set to save
93 * @param[in] user_data The user data passed from widget_app_class_create function
94 * @return #WIDGET_ERROR_NONE on success,
95 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
97 typedef int (*widget_instance_destroy_cb)(widget_context_h context, widget_app_destroy_type_e reason, bundle *content, void *user_data);
101 * @brief Called when the widget is invisible.
102 * @details The callback function is called when the widget is invisible.
103 * The paused instance may be destroyed by framework.
105 * @param[in] context The context of widget instance
106 * @param[in] user_data The user data passed from widget_app_class_create function
107 * @return #WIDGET_ERROR_NONE on success,
108 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
110 typedef int (*widget_instance_pause_cb)(widget_context_h context, void *user_data);
114 * @brief Called when the widget is visible.
115 * @details The callback function is called when the widget is visible.
117 * @param[in] context The context of widget instance
118 * @param[in] user_data The user data passed from widget_app_class_create function
119 * @return #WIDGET_ERROR_NONE on success,
120 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
122 typedef int (*widget_instance_resume_cb)(widget_context_h context, void *user_data);
126 * @brief Called before the widget size is changed.
127 * @details The callback function is called before the widget size is changed.
129 * @param[in] context The context of widget instance
130 * @param[in] w The pixel value for widget width
131 * @param[in] h The pixel value for widget height
132 * @param[in] user_data The user data passed from widget_app_class_create function
133 * @return #WIDGET_ERROR_NONE on success,
134 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
136 typedef int (*widget_instance_resize_cb)(widget_context_h context, int w, int h, void *user_data);
140 * @brief Called when the event for updating widget is received.
141 * @details The callback function is called when the event for updating widget is received.
143 * @param[in] context The context of widget instance
144 * @param[in] content The data set for updating this widget. It will be provided by requester.
145 * Requester can use widget_service_trigger_update()
146 * @param[in] force Although the widget is paused, if it is TRUE, the widget can be updated
147 * @param[in] user_data The user data passed from widget_app_class_create function
148 * @return #WIDGET_ERROR_NONE on success,
149 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
150 * @see widget_service_trigger_update()
152 typedef int (*widget_instance_update_cb)(widget_context_h context, bundle *content, int force, void *user_data);
156 * @brief The structure type containing the set of callback functions for lifecycle of a widget instance.
160 widget_instance_create_cb create; /**< The callback function is called after widget instance is created. */
161 widget_instance_destroy_cb destroy; /**< The callback function is called before widget instance is destroyed. */
162 widget_instance_pause_cb pause; /**< The callback function is called when the widget is invisible. */
163 widget_instance_resume_cb resume; /**< The callback function is called when the widget is visible. */
164 widget_instance_resize_cb resize; /**< The callback function is called before the widget size is changed. */
165 widget_instance_update_cb update; /**< The callback function is called when the event for updating widget is received. */
166 } widget_instance_lifecycle_callback_s;
170 * @brief Called when the application starts.
171 * @details The callback function is called before the main loop of the application starts.
172 * In this callback, you can initialize resources which can be shared among widget instances.
173 * This function should return the handle for widget class so that it will be used for making instances of widget.
175 * @param[in] user_data The user data passed from the callback registration function
176 * @return The object of widget class
177 * @see widget_app_main()
180 * static widget_class_h __widget_app_created(void *user_data)
182 * widget_instance_lifecycle_callback_s callback = { .... };
184 * return widget_app_class_create(callback);
189 typedef widget_class_h (*widget_app_create_cb)(void *user_data);
193 * @brief Called when the application's main loop exits.
194 * @details This callback function is called once after the main loop of the application exits.
195 * You should release the application's resources in this function.
197 * @param[in] user_data The user data passed from the callback registration function
198 * @see widget_app_main()
200 typedef void (*widget_app_terminate_cb)(void *user_data);
204 * @brief The structure for lifecycle of a widget application.
208 widget_app_create_cb create; /**< The callback function is called before the main loop of the application starts. */
209 widget_app_terminate_cb terminate; /**< This callback function is called once after the main loop of the application exits. */
210 } widget_app_lifecycle_callback_s;
214 * @brief Called for each widget context.
215 * @details This function will be called in the function of widget_app_foreach_context repeatedly.
217 * @param[in] context The context for widget instance
218 * @param[in] data The data for caller
219 * @return @c true to continue with the next iteration of the loop,
220 * otherwise @c false to break out of the loop
221 * @see widget_app_foreach_context()
223 typedef bool (*widget_context_cb)(widget_context_h context, void *data);
227 * @brief Runs the main loop of the application until widget_app_exit() is called.
229 * @param[in] argc The argument count
230 * @param[in] argv The argument vector
231 * @param[in] callback The set of callback functions to handle application events
232 * @param[in] user_data The user data to be passed to the callback functions
233 * @return #WIDGET_ERROR_NONE on success,
234 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
235 * @retval #WIDGET_ERROR_NONE Successful
236 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
237 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
238 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
239 * @see widget_app_exit()
241 int widget_app_main(int argc, char **argv, widget_app_lifecycle_callback_s *callback, void *user_data);
245 * @brief Exits the main loop of the application.
246 * @details The main loop of the application stops and widget_app_terminate_cb() is invoked.
248 * @return #WIDGET_ERROR_NONE on success,
249 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
250 * @retval #WIDGET_ERROR_NONE Successful
251 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
252 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
253 * @see widget_app_main()
254 * @see widget_app_terminate_cb()
256 int widget_app_exit(void);
260 * @brief Finishes context for the widget instance.
262 * @param[in] context The context for widget instance
263 * @return #WIDGET_ERROR_NONE on success,
264 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
265 * @retval #WIDGET_ERROR_NONE Successful
266 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
267 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
268 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
270 int widget_app_terminate_context(widget_context_h context);
274 * @brief Retrieves all widget contexts in this application.
276 * @param[in] callback The iteration callback function
277 * @param[in] data The data for the callback function
278 * @return #WIDGET_ERROR_NONE on success,
279 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
280 * @retval #WIDGET_ERROR_NONE Successful
281 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
282 * @retval #WIDGET_ERROR_CANCELED The iteration is canceled
283 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
284 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
285 * @see widget_app_foreach_context()
287 int widget_app_foreach_context(widget_context_cb callback, void *data);
291 * @brief Adds the system event handler.
293 * @param[out] event_handler The event handler
294 * @param[in] event_type The system event type. APP_EVENT_DEVICE_ORIENTATION_CHANGED is not supported
295 * @param[in] callback The callback function
296 * @param[in] user_data The user data to be passed to the callback function
297 * @return #WIDGET_ERROR_NONE on success,
298 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
299 * @retval #WIDGET_ERROR_NONE Successful
300 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
301 * @retval #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
302 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
303 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
304 * @see app_event_type_e
305 * @see app_event_cb()
306 * @see watch_app_remove_event_handler()
308 int widget_app_add_event_handler(app_event_handler_h *event_handler, app_event_type_e event_type,
309 app_event_cb callback, void *user_data);
312 * @brief Removes registered event handler.
314 * @param[in] event_handler The event handler
315 * @return #WIDGET_ERROR_NONE on success,
316 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
317 * @retval #WIDGET_ERROR_NONE Successful
318 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
319 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
320 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
321 * @see watch_app_add_event_handler()
323 int widget_app_remove_event_handler(app_event_handler_h event_handler);
327 * @brief Gets a widget instance id.
329 * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
330 * @remark You must not free returned Widget ID
331 * @param[in] context The context for widget instance
332 * @return Widget ID on success,
334 * @exception #WIDGET_ERROR_NOT_SUPPORTED Not supported
335 * @exception #WIDGET_ERROR_FAULT Unrecoverable error
336 * @see get_last_result()
338 const char *widget_app_get_id(widget_context_h context);
342 * @brief Makes a class for widget instances.
344 * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
345 * @param[in] callback The set of lifecycle callbacks
346 * @param[in] user_data The user data to be passed to the callback functions
347 * @return The new widget class object,
349 * @exception #WIDGET_ERROR_NONE Successfully added
350 * @exception #WIDGET_ERROR_INVALID_PARAMETER Not supported
351 * @exception #WIDGET_ERROR_NOT_SUPPORTED Not supported
352 * @exception #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
353 * @see get_last_result()
355 widget_class_h widget_app_class_create(widget_instance_lifecycle_callback_s callback, void *user_data);
359 * @brief Sets a tag in the context.
361 * @param[in] context The context for widget instance
362 * @param[in] tag The value to save
363 * @return #WIDGET_ERROR_NONE on success,
364 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
365 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
366 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
367 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
369 int widget_app_context_set_tag(widget_context_h context, void *tag);
373 * @brief Gets the tag in the context.
375 * @param[in] context The context for widget instance
376 * @param[out] tag The value to get
377 * @return #WIDGET_ERROR_NONE on success,
378 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
379 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
380 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
381 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
383 int widget_app_context_get_tag(widget_context_h context, void **tag);
387 * @brief Sets the content info to the widget.
389 * @param[in] context The context for widget instance
390 * @param[in] content_info The data set to save
391 * @return #WIDGET_ERROR_NONE on success,
392 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
393 * @retval #WIDGET_ERROR_NONE Successfully sent
394 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid argument
395 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
396 * @retval #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
397 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
399 int widget_app_context_set_content_info(widget_context_h context, bundle *content_info);
403 * @brief Sends the title to the widget.
405 * @param[in] context The context for widget instance
406 * @param[in] title When an accessibility mode is turned on, this string will be read
407 * @return #WIDGET_ERROR_NONE on success,
408 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
409 * @retval #WIDGET_ERROR_NONE Successfully sent
410 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid argument
411 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
412 * @retval #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
413 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
415 int widget_app_context_set_title(widget_context_h context, const char *title);
419 * @brief Adds an additional widget class for multi-class of widget instantiation.
421 * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
422 * @param[in] widget_class The result of widget_app_class_create()
423 * @param[in] class_id The class id of provider
424 * @param[in] callback The set of lifecycle callbacks
425 * @param[in] user_data The user data to be passed to the callback functions
426 * @return The new widget class object,
428 * @exception #WIDGET_ERROR_NONE Successfully added
429 * @exception #WIDGET_ERROR_INVALID_PARAMETER Not supported
430 * @exception #WIDGET_ERROR_NOT_SUPPORTED Not supported
431 * @exception #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
432 * @see get_last_result()
434 widget_class_h widget_app_class_add(widget_class_h widget_class, const char *class_id,
435 widget_instance_lifecycle_callback_s callback, void *user_data);
445 #endif /* __TIZEN_APPFW_WIDGET_APP_H__ */