2 * Copyright (c) 2015 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
37 * @brief Destroy type of widget instance
40 typedef enum widget_app_destroy_type {
41 WIDGET_APP_DESTROY_TYPE_DEFAULT = 0x00, /**< Deleted */
42 WIDGET_APP_DESTROY_TYPE_UPGRADE = 0x01, /**< Deleted for upgrading */
43 WIDGET_APP_DESTROY_TYPE_UNINSTALL = 0x02, /**< Deleted by uninstalling */
44 WIDGET_APP_DESTROY_TYPE_TERMINATE = 0x03, /**< Deleted for reboot device */
45 WIDGET_APP_DESTROY_TYPE_FAULT = 0x04, /**< Deleted by system-fault */
46 WIDGET_APP_DESTROY_TYPE_TEMPORARY = 0x05, /**< Temporarly deleted, will be created again */
47 WIDGET_APP_DESTROY_TYPE_UNKNOWN = 0x06 /**< Undefined reason */
48 } widget_app_destroy_type_e; /**< Delete type */
51 * @brief The handle for widget class.
54 typedef struct _widget_class* widget_class_h;
57 * @brief The handle for widget context
60 typedef struct _widget_context* widget_context_h;
63 * @brief Called when the widget instance starts.
66 * @details The callback function is called after widget instance is created.
67 * In this callback, you can initialize resources for this instance.
69 * @param[in] context The context of widget instance.
70 * @param[in] content The data set for the previous status
71 * @param[in] w The pixel value for widget width
72 * @param[in] h The pixel value for widget height
73 * @param[in] user_data The user data passed from widget_app_class_create function
75 * @return #WIDGET_ERROR_NONE on success,
76 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
78 typedef int (*widget_instance_create_cb)(widget_context_h context, bundle *content, int w, int h, void *user_data);
81 * @brief Called before the widget instance is destroyed.
84 * @details The callback function is called before widget instance is destroyed.
85 * In this callback, you can finalize resources for this instance.
86 * If reason is not #WIDGET_APP_DESTROY_TYPE_DEFAULT, It should store the current status by using incoming bundle.
88 * @param[in] context The context of widget instance.
89 * @param[in] reason The reason for destruction
90 * @param[in,out] content The data set to save
91 * @param[in] user_data The user data passed from widget_app_class_create function
92 * @remark Note that the parameter 'content' is used to save the status of the widget instance.
93 * As a input parameter, content contains the saved status of the widget instance.
94 * You can fill the content parameter with the current status in this callback,
95 * then the framework will save the content by receiving it as a output parameter.
96 * Consequently, you should not use widget_app_context_set_content_info() api in this callback.
97 * The content will be overwritten after this callback returns with the 'content' parameter.
99 * @return #WIDGET_ERROR_NONE on success,
100 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
102 typedef int (*widget_instance_destroy_cb)(widget_context_h context, widget_app_destroy_type_e reason, bundle *content, void *user_data);
105 * @brief Called when the widget is invisible.
108 * @details The callback function is called when the widget is invisible.
109 * The paused instance may be destroyed by framework
111 * @param[in] context The context of widget instance.
112 * @param[in] user_data The user data passed from widget_app_class_create function
113 * @return #WIDGET_ERROR_NONE on success,
114 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
116 typedef int (*widget_instance_pause_cb)(widget_context_h context, void *user_data);
119 * @brief Called when the widget is visible.
122 * @details The callback function is called when the widget is visible.
124 * @param[in] context The context of widget instance.
125 * @param[in] user_data The user data passed from widget_app_class_create function
126 * @return #WIDGET_ERROR_NONE on success,
127 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
129 typedef int (*widget_instance_resume_cb)(widget_context_h context, void *user_data);
132 * @brief Called before the widget size is changed.
135 * @details The callback function is called before the widget size is changed.
137 * @param[in] context The context of widget instance.
138 * @param[in] w The pixel value for widget width
139 * @param[in] h The pixel value for widget height
140 * @param[in] user_data The user data passed from widget_app_class_create function
141 * @return #WIDGET_ERROR_NONE on success,
142 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
144 typedef int (*widget_instance_resize_cb)(widget_context_h context, int w, int h, void *user_data);
147 * @brief Called when the event for updating widget is received.
150 * @details The callback function is called when the event for updating widget is received.
152 * @param[in] context The context of widget instance.
153 * @param[in] content The data set for updating this widget. It will be provided by requester.
154 * Requester can use widget_service_trigger_update().
155 * @param[in] force Although the widget is paused, if it is TRUE, the widget can be updated.
156 * @param[in] user_data The user data passed from widget_app_class_create function
157 * @return #WIDGET_ERROR_NONE on success,
158 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
159 * @see widget_service_trigger_update
161 typedef int (*widget_instance_update_cb)(widget_context_h context, bundle *content, int force, void *user_data);
164 * @brief The structure for lifecycle of a widget instance
169 widget_instance_create_cb create; /**< The callback function is called after widget instance is created. */
170 widget_instance_destroy_cb destroy; /**< The callback function is called before widget instance is destroyed. */
171 widget_instance_pause_cb pause; /**< The callback function is called when the widget is invisible. */
172 widget_instance_resume_cb resume; /**< The callback function is called when the widget is visible. */
173 widget_instance_resize_cb resize; /**< The callback function is called before the widget size is changed. */
174 widget_instance_update_cb update; /**< The callback function is called when the event for updating widget is received. */
175 } widget_instance_lifecycle_callback_s;
178 * @brief Called when the application starts.
181 * @details The callback function is called before the main loop of the application starts.
182 * In this callback, you can initialize resources which can be shared among widget instances.
183 * This function should return the handle for widget class so that it will be used for making instances of widget.
185 * @param[in] user_data The user data passed from the callback registration function
186 * @return The object of widget class
187 * @see widget_app_main()
190 * static widget_class_h __widget_app_created(void *user_data)
192 * widget_instance_lifecycle_callback_s callback = { .... };
194 * return widget_app_class_create(callback);
199 typedef widget_class_h (*widget_app_create_cb)(void *user_data);
202 * @brief Called when the application's main loop exits.
203 * @details This callback function is called once after the main loop of the application exits.
204 * You should release the application's resources in this function.
207 * @param[in] user_data The user data passed from the callback registration function
208 * @see widget_app_main()
210 typedef void (*widget_app_terminate_cb)(void *user_data);
213 * @brief The structure for lifecycle of a widget application
218 widget_app_create_cb create; /**< The callback function is called before the main loop of the application starts. */
219 widget_app_terminate_cb terminate; /**< This callback function is called once after the main loop of the application exits. */
220 } widget_app_lifecycle_callback_s;
223 * @brief Called for each widget context
226 * @details This function will be called in the function of widget_app_foreach_context repeatedly.
228 * @param[in] context The context for widget instance
229 * @param[in] data The data for caller
230 * @return true to continue with the next iteration of the loop,
231 * otherwise false to break out of the loop.
232 * @see widget_app_foreach_context
234 typedef bool (*widget_context_cb)(widget_context_h context, void *data);
237 * @brief Runs the main loop of the application until widget_app_exit() is called.
240 * @param[in] argc The argument count
241 * @param[in] argv The argument vector
242 * @param[in] callback The set of callback functions to handle application events
243 * @param[in] user_data The user data to be passed to the callback functions
245 * @return @c 0 on success,
246 * otherwise a negative error value.
247 * @retval #WIDGET_ERROR_NONE Successful
248 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
249 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
250 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
251 * @see widget_app_exit
253 int widget_app_main(int argc, char **argv, widget_app_lifecycle_callback_s *callback, void *user_data);
256 * @brief Exits the main loop of the application.
257 * @details The main loop of the application stops and widget_app_terminate_cb() is invoked.
260 * @return @c 0 on success,
261 * otherwise a negative error value.
262 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
263 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
264 * @see widget_app_main
265 * @see widget_app_terminate_cb
267 int widget_app_exit(void);
270 * @brief Finishes context for the widget instance
273 * @param[in] context The context for widget instance
275 * @return @c 0 on success, otherwise a negative error value.
276 * @retval #WIDGET_ERROR_NONE Successfull
277 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
278 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
279 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
281 int widget_app_terminate_context(widget_context_h context);
284 * @brief Retrieves all widget contexts in this application
287 * @param[in] callback The iteration callback function
288 * @param[in] data The data for the callback function
290 * @return 0 on success, otherwise a negative error value
291 * @retval #WIDGET_ERROR_NONE Successfull
292 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
293 * @retval #WIDGET_ERROR_CANCELED The iteration is canceled
294 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
295 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
296 * @see widget_app_foreach_context
298 int widget_app_foreach_context(widget_context_cb callback, void *data);
301 * @brief Adds the system event handler
304 * @param[out] event_handler The event handler
305 * @param[in] event_type The system event type. APP_EVENT_DEVICE_ORIENTATION_CHANGED is not supported
306 * @param[in] callback The callback function
307 * @param[in] user_data The user data to be passed to the callback function
309 * @return 0 on success, otherwise a negative error value
310 * @retval #WIDGET_ERROR_NONE Successfull
311 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
312 * @retval #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
313 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
314 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
315 * @see app_event_type_e
317 * @see watch_app_remove_event_handler
319 int widget_app_add_event_handler(app_event_handler_h *event_handler, app_event_type_e event_type,
320 app_event_cb callback, void *user_data);
323 * @brief Removes registered event handler
326 * @param[in] event_handler The event handler
328 * @return 0 on success, otherwise a negative error value
329 * @retval #WIDGET_ERROR_NONE Successfull
330 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
331 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
332 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
333 * @see watch_app_add_event_handler
335 int widget_app_remove_event_handler(app_event_handler_h event_handler);
338 * @brief Gets a widget instance id
341 * @param[in] context The context for widget instance
343 * @return Widget ID on success, otherwise NULL
344 * You can get the returned value using get_last_result()
345 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
346 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
347 * @remark You must not free returned Widget ID
348 * @see get_last_result
350 const char* widget_app_get_id(widget_context_h context);
353 * @brief Makes a class for widget instances.
356 * @param[in] callback The set of lifecycle callbacks
357 * @param[in] user_data The user data to be passed to the callback functions
358 * @return The handle of class on success, otherwise NULL
359 * You can get the returned value using get_last_result()
360 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
361 * @see get_last_result
363 widget_class_h widget_app_class_create(widget_instance_lifecycle_callback_s callback, void *user_data);
366 * @brief Sets a tag in the context
369 * @param[in] context The context for widget instance
370 * @param[in] tag The value to save
372 * @return 0 on success, otherwise a negative error value
373 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
374 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
375 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
377 int widget_app_context_set_tag(widget_context_h context, void *tag);
380 * @brief Gets the tag in the context
383 * @param[in] context The context for widget instance
384 * @param[out] tag The value to get
386 * @return 0 on success, otherwise a negative error value
387 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
388 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
389 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
391 int widget_app_context_get_tag(widget_context_h context, void **tag);
394 * @brief Sets the content info to the widget
396 * @param[in] context The context for widget instance
397 * @param[in] content_info The data set to save
398 * @return #WIDGET_ERROR_NONE on success,
399 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
400 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid argument
401 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
402 * @retval #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
403 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
404 * @retval #WIDGET_ERROR_NONE Successfully sent
406 int widget_app_context_set_content_info(widget_context_h context, bundle *content_info);
409 * @brief Sends the title to the widget
411 * @param[in] context The context for widget instance
412 * @param[in] title When an accessibility mode is turned on, this string will be read.
413 * @return #WIDGET_ERROR_NONE on success,
414 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
415 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid argument
416 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
417 * @retval #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
418 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
419 * @retval #WIDGET_ERROR_NONE Successfully sent
421 int widget_app_context_set_title(widget_context_h context, const char *title);
431 #endif /* __TIZEN_APPFW_WIDGET_APP_H__ */