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
74 * @return #WIDGET_ERROR_NONE on success,
75 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
77 typedef int (*widget_instance_create_cb)(widget_context_h context, bundle *content, int w, int h);
80 * @brief Called before the widget instance is destroyed.
83 * @details The callback function is called before widget instance is destroyed.
84 * In this callback, you can finalize resources for this instance.
85 * If reason is not #WIDGET_APP_DESTROY_TYPE_DEFAULT, It should store the current status by using incoming bundle.
87 * @param[in] context The context of widget instance.
88 * @param[in] reason The reason for destruction
89 * @param[in,out] content The data set to save
90 * @remark Note that the parameter 'content' is used to save the status of the widget instance.
91 * As a input parameter, content contains the saved status of the widget instance.
92 * You can fill the content parameter with the current status in this callback,
93 * then the framework will save the content by receiving it as a output parameter.
94 * Consequently, you should not use widget_app_context_set_content_info() api in this callback.
95 * The content will be overwritten after this callback returns with the 'content' parameter.
97 * @return #WIDGET_ERROR_NONE on success,
98 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
100 typedef int (*widget_instance_destroy_cb)(widget_context_h context, widget_app_destroy_type_e reason, bundle *content);
103 * @brief Called when the widget is invisible.
106 * @details The callback function is called when the widget is invisible.
107 * The paused instance may be destroyed by framework
109 * @param[in] context The context of widget instance.
110 * @return #WIDGET_ERROR_NONE on success,
111 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
113 typedef int (*widget_instance_pause_cb)(widget_context_h context);
116 * @brief Called when the widget is visible.
119 * @details The callback function is called when the widget is visible.
121 * @param[in] context The context of widget instance.
122 * @return #WIDGET_ERROR_NONE on success,
123 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
125 typedef int (*widget_instance_resume_cb)(widget_context_h context);
128 * @brief Called before the widget size is changed.
131 * @details The callback function is called before the widget size is changed.
133 * @param[in] context The context of widget instance.
134 * @param[in] w The pixel value for widget width
135 * @param[in] h The pixel value for widget height
136 * @return #WIDGET_ERROR_NONE on success,
137 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
139 typedef int (*widget_instance_resize_cb)(widget_context_h context, int w, int h);
142 * @brief Called when the event for updating widget is received.
145 * @details The callback function is called when the event for updating widget is received.
147 * @param[in] context The context of widget instance.
148 * @param[in] content The data set for updating this widget. It will be provided by requester.
149 * Requester can use widget_service_trigger_update().
150 * @param[in] force Although the widget is paused, if it is TRUE, the widget can be updated.
151 * @return #WIDGET_ERROR_NONE on success,
152 * otherwise an error code (see WIDGET_ERROR_XXX) on failure
153 * @see widget_service_trigger_update
155 typedef int (*widget_instance_update_cb)(widget_context_h context, bundle *content, int force);
158 * @brief The structure for lifecycle of a widget instance
163 widget_instance_create_cb create; /**< The callback function is called after widget instance is created. */
164 widget_instance_destroy_cb destroy; /**< The callback function is called before widget instance is destroyed. */
165 widget_instance_pause_cb pause; /**< The callback function is called when the widget is invisible. */
166 widget_instance_resume_cb resume; /**< The callback function is called when the widget is visible. */
167 widget_instance_resize_cb resize; /**< The callback function is called before the widget size is changed. */
168 widget_instance_update_cb update; /**< The callback function is called when the event for updating widget is received. */
169 } widget_instance_lifecycle_callback_s;
172 * @brief Called when the application starts.
175 * @details The callback function is called before the main loop of the application starts.
176 * In this callback, you can initialize resources which can be shared among widget instances.
177 * This function should return the handle for widget class so that it will be used for making instances of widget.
179 * @param[in] user_data The user data passed from the callback registration function
180 * @return The object of widget class
181 * @see widget_app_main()
184 * static widget_class_h __widget_app_created(void *user_data)
186 * widget_instance_lifecycle_callback_s callback = { .... };
188 * return widget_app_class_create(callback);
193 typedef widget_class_h (*widget_app_create_cb)(void *user_data);
196 * @brief Called when the application's main loop exits.
197 * @details This callback function is called once after the main loop of the application exits.
198 * You should release the application's resources in this function.
201 * @param[in] user_data The user data passed from the callback registration function
202 * @see widget_app_main()
204 typedef void (*widget_app_terminate_cb)(void *user_data);
207 * @brief The structure for lifecycle of a widget application
212 widget_app_create_cb create; /**< The callback function is called before the main loop of the application starts. */
213 widget_app_terminate_cb terminate; /**< This callback function is called once after the main loop of the application exits. */
214 } widget_app_lifecycle_callback_s;
217 * @brief Called for each widget context
220 * @details This function will be called in the function of widget_app_foreach_context repeatedly.
222 * @param[in] context The context for widget instance
223 * @param[in] data The data for caller
224 * @return true to continue with the next iteration of the loop,
225 * otherwise false to break out of the loop.
226 * @see widget_app_foreach_context
228 typedef bool (*widget_context_cb)(widget_context_h context, void *data);
231 * @brief Runs the main loop of the application until widget_app_exit() is called.
234 * @param[in] argc The argument count
235 * @param[in] argv The argument vector
236 * @param[in] callback The set of callback functions to handle application events
237 * @param[in] user_data The user data to be passed to the callback functions
239 * @return @c 0 on success,
240 * otherwise a negative error value.
241 * @retval #WIDGET_ERROR_NONE Successful
242 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
243 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
244 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
245 * @see widget_app_exit
247 int widget_app_main(int argc, char **argv, widget_app_lifecycle_callback_s *callback, void *user_data);
250 * @brief Exits the main loop of the application.
251 * @details The main loop of the application stops and widget_app_terminate_cb() is invoked.
254 * @return @c 0 on success,
255 * otherwise a negative error value.
256 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
257 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
258 * @see widget_app_main
259 * @see widget_app_terminate_cb
261 int widget_app_exit(void);
264 * @brief Finishes context for the widget instance
267 * @param[in] context The context for widget instance
269 * @return @c 0 on success, otherwise a negative error value.
270 * @retval #WIDGET_ERROR_NONE Successfull
271 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
272 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
273 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
275 int widget_app_terminate_context(widget_context_h context);
278 * @brief Retrieves all widget contexts in this application
281 * @param[in] callback The iteration callback function
282 * @param[in] data The data for the callback function
284 * @return 0 on success, otherwise a negative error value
285 * @retval #WIDGET_ERROR_NONE Successfull
286 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
287 * @retval #WIDGET_ERROR_CANCELED The iteration is canceled
288 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
289 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
290 * @see widget_app_foreach_context
292 int widget_app_foreach_context(widget_context_cb callback, void *data);
295 * @brief Adds the system event handler
298 * @param[out] event_handler The event handler
299 * @param[in] event_type The system event type. APP_EVENT_DEVICE_ORIENTATION_CHANGED is not supported
300 * @param[in] callback The callback function
301 * @param[in] user_data The user data to be passed to the callback function
303 * @return 0 on success, otherwise a negative error value
304 * @retval #WIDGET_ERROR_NONE Successfull
305 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
306 * @retval #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
307 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
308 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
309 * @see app_event_type_e
311 * @see watch_app_remove_event_handler
313 int widget_app_add_event_handler(app_event_handler_h *event_handler, app_event_type_e event_type,
314 app_event_cb callback, void *user_data);
317 * @brief Removes registered event handler
320 * @param[in] event_handler The event handler
322 * @return 0 on success, otherwise a negative error value
323 * @retval #WIDGET_ERROR_NONE Successfull
324 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
325 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
326 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
327 * @see watch_app_add_event_handler
329 int widget_app_remove_event_handler(app_event_handler_h event_handler);
332 * @brief Gets a widget instance id
335 * @param[in] context The context for widget instance
337 * @return Widget ID on success, otherwise NULL
338 * You can get the returned value using get_last_result()
339 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
340 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
341 * @remark You must not free returned Widget ID
342 * @see get_last_result
344 const char* widget_app_get_id(widget_context_h context);
347 * @brief Makes a class for widget instances.
350 * @param[in] callback The set of lifecycle callbacks
351 * @return The handle of class on success, otherwise NULL
352 * You can get the returned value using get_last_result()
353 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
354 * @see get_last_result
356 widget_class_h widget_app_class_create(widget_instance_lifecycle_callback_s callback);
359 * @brief Sets a tag in the context
362 * @param[in] context The context for widget instance
363 * @param[in] tag The value to save
365 * @return 0 on success, otherwise a negative error value
366 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
367 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
368 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
370 int widget_app_context_set_tag(widget_context_h context, void *tag);
373 * @brief Gets the tag in the context
376 * @param[in] context The context for widget instance
377 * @param[out] tag The value to get
379 * @return 0 on success, otherwise a negative error value
380 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
381 * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
382 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
384 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_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 * @retval #WIDGET_ERROR_NONE Successfully sent
399 int widget_app_context_set_content_info(widget_context_h context, bundle *content_info);
402 * @brief Sends the title to the widget
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_INVALID_PARAMETER Invalid argument
409 * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
410 * @retval #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
411 * @retval #WIDGET_ERROR_FAULT Unrecoverable error
412 * @retval #WIDGET_ERROR_NONE Successfully sent
414 int widget_app_context_set_title(widget_context_h context, const char *title);
424 #endif /* __TIZEN_APPFW_WIDGET_APP_H__ */