4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 #ifndef __APPCORE_COMMON_H__
25 #define __APPCORE_COMMON_H__
28 * @file appcore-common.h
30 * @brief This file contains APIs of the Appcore library
34 * @addtogroup APPLICATION_FRAMEWORK
37 * @defgroup Appcore Appcore
39 * @brief A base library for application
56 #define _(str) gettext(str) /**< gettext alias */
58 #define gettext_noop(str) (str) /**< keyword for xgettext
59 to extract translatable strings */
60 #define N_(str) gettext_noop(str) /**< gettext_noop alias */
63 * System global events related to the application
64 * @see appcore_set_event_callback()
67 APPCORE_EVENT_UNKNOWN,
69 APPCORE_EVENT_LOW_MEMORY,
71 APPCORE_EVENT_LOW_BATTERY,
73 APPCORE_EVENT_LANG_CHANGE,
74 /**< Language setting is changed */
75 APPCORE_EVENT_REGION_CHANGE,
76 /**< Region setting is changed */
77 APPCORE_EVENT_SUSPENDED_STATE_CHANGE,
78 /**< The suspended state is changed */
83 * @see appcore_set_rotation_cb(), appcore_get_rotation_state()
88 APPCORE_RM_PORTRAIT_NORMAL,
90 APPCORE_RM_PORTRAIT_REVERSE,
91 /**< Portrait upside down mode */
92 APPCORE_RM_LANDSCAPE_NORMAL,
93 /**< Left handed landscape mode */
94 APPCORE_RM_LANDSCAPE_REVERSE,
95 /**< Right handed landscape mode */
100 * @see appcore_get_timeformat()
102 enum appcore_time_format {
103 APPCORE_TIME_FORMAT_UNKNOWN,
104 APPCORE_TIME_FORMAT_12,
105 APPCORE_TIME_FORMAT_24,
108 enum appcore_suspended_state {
109 APPCORE_SUSPENDED_STATE_WILL_ENTER_SUSPEND = 0,
110 APPCORE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND
114 * Appcore operations which are called during the application life-cycle
115 * @see appcore_efl_main()
119 /**< Callback data */
120 int (*create) (void *);
121 /**< Called before main loop \n
122 If this returns non-zero, Appcore does not run the main loop. */
123 int (*terminate) (void *);
124 /**< Called after main loop */
125 int (*pause) (void *);
126 /**< Called when every window goes back */
127 int (*resume) (void *);
128 /**< Called when any window comes on top */
129 int (*reset) (bundle *, void *);
130 /**< Called at the first idler
131 and every relaunching */
138 * Set the callback function which is called when the event occurs.
141 * This function sets a callback function for events from the system.
142 * Callback function is invoked every time the event occurs.
144 * @par Typical use case:
145 * To do something when predefined events (enum appcore_event) occur, use this API
147 * @par Method of function operation:
148 * Using Heynoti subscription, Vconf changed callback, and AUL, Appcore invokes the registered callback function.
150 * @par Important notes:
151 * Only one callback function can be set. If <I>cb</I> is NULL, unset the callback function about the event.\n
152 * Default behavior is performed when the specified event callback doesn't have registered.
154 * @param[in] event System event
155 * @param[in] cb callback function
156 * @param[in] data callback function data
158 * @return 0 on success, -1 on error (<I>errno</I> set)
161 * EINVAL - Invalid event type
164 * @post Callback is set/unset.
170 #include <appcore-common.h>
174 static int _lang_changed(void *);
175 static int _low_battery(void *);
176 static int _low_memory(void *);
177 static int _region_changed(void *);
179 int add_callbacks(struct appdata *data)
183 r = appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, _lang_changed,
186 // add exception handling
189 r = appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY, _low_battery,
192 // add exception handling
195 r = appcore_set_event_callback(APPCORE_EVENT_LOW_MEMORY, _low_memory,
198 // add exception handling
201 r = appcore_set_event_callback(APPCORE_EVENT_REGION_CHANGE,
202 _region_changed, data);
204 // add exception handling
212 int appcore_set_event_callback(enum appcore_event event,
213 int (*cb)(void *, void *), void *data);
217 * Set a rotation callback
220 * This function sets a callback function for rotation events. Callback function is invoked every time the rotation mode is changed.
222 * @par Typical use case:
223 * To do something when the rotation mode is changed, use this API
225 * @par Method of function operation:
226 * Appcore receives rotation change from Sensor framework. When Appcore receive the change, it invokes the registered callback function.
228 * @par Important notes:
229 * Locks the rotation mode, the registered callback is not invoked.
231 * @param[in] cb callback function
232 * @param[in] data callback function data
234 * @return 0 on success, -1 on error (<I>errno</I> set)
237 * EINVAL - <I>cb</I> is NULL
238 * EALREADY - rotation callback function already registered
240 * @pre Callback is not set.
242 * @see appcore_unset_rotation_cb(), appcore_get_rotation_state()
247 #include <appcore-common.h>
251 static int _rot_cb(enum appcore_rm, void *);
257 r = appcore_set_rotation_cb(_rot_cb, data);
259 // add exception handling
267 int appcore_set_rotation_cb(int (*cb) (void *event_info, enum appcore_rm, void *),
272 * Unset a rotation callback
275 * This function unsets a callback function for rotation events.
277 * @return 0 on success, -1 on error
279 * @pre Callback is set by appcore_set_rotation_cb().
281 * @see appcore_set_rotation_cb(), appcore_get_rotation_state()
286 #include <appcore-common.h>
295 r = appcore_unset_rotation_cb();
297 // add exception handling
304 int appcore_unset_rotation_cb(void);
308 * Get the current rotation mode.
311 * To get the current rotation mode, use this API.
313 * @par Method of function operation:
314 * This function gets the current rotation mode from Sensor framework.
316 * @param[out] curr current rotation mode\n
317 * If Sensor framework is not working, curr is set to APPCORE_RM_UNKNOWN.
319 * @return 0 on success, -1 on error (<I>errno</I> set)
322 * EINVAL - <I>curr</I> is NULL
326 * @see appcore_set_rotation_cb(), appcore_unset_rotation_cb()
331 #include <appcore-common.h>
337 enum appcore_rm curr;
341 r = appcore_get_rotation_state(&curr);
343 // add exception handling
350 int appcore_get_rotation_state(enum appcore_rm *curr);
354 * Get the current time format.
357 * To get the current time format, use this API.
359 * @par Method of function operation:
360 * This function gets the current time format from vconf.
362 * @param[out] timeformat current time format\n
363 * If vconf is not working, timeformat is set to APPCORE_TIME_FORMAT_UNKNOWN.
365 * @return 0 on success, -1 on error (<I>errno</I> set)
368 * EINVAL - <I>timeformat</I> is NULL
377 #include <appcore-common.h>
383 enum appcore_time_format timeformat;
387 r = appcore_get_timeformat(&timeformat);
389 // add exception handling
396 int appcore_get_timeformat(enum appcore_time_format *timeformat);
400 * Set the information for the internationalization.
403 * This function prepares to internationalize. To use gettext, use this API.
405 * @par Typical use case:
406 * This function provides convenience for using gettext.
408 * @par Method of function operation:
409 * Calls setlocale(), bindtextdomain() and textdomain() internally.
411 * @par Corner cases/exceptions:
412 * If <I>dirname</I> is NULL, the previously set base directory is used. Typically, it is /usr/share/locale.
414 * @param[in] domainname a message domain name(text domain name) \n Must be a non-empty string.
415 * @param[in] dirname the base directory for message catalogs belonging to the specified domain \n
417 * @return 0 on success, -1 on error (<I>errno</I> set)
420 * EINVAL - <I>domain</I> is NULL
423 * @post The environment variable LANG is set or changed.
429 #include <appcore-common.h>
438 r = appcore_set_i18n("i18n_example", NULL);
440 // add exception handling
447 int appcore_set_i18n(const char *domainname, const char *dirname);
451 * Set the measuring start time
454 * To measure the time, the start time should be set. This function set the start point.
456 * @par Typical use case:
457 * It is used to measure the time for doing something. \n
458 * This function set the start point. And, appcore_measure_time() returns
459 * the elapsed time from the start point.
461 * @see appcore_measure_time()
463 * @par Method of function operation:
464 * Store the current time to the internal variable.
467 * @post Current time is saved to the internal space.
472 #include <appcore-common.h>
478 appcore_measure_start();
482 printf("it takes %d msec to do something\n", appcore_measure_time());
488 void appcore_measure_start(void);
492 * Measure the time from appcore_measure_start()
495 * To measure the elapsed time from the start point.
497 * @par Typical use case:
498 * It is used to measure the time for doing something. \n
499 * This function returns the elapsed time from the start point set by appcore_measure_start().
501 * @see appcore_measure_start()
503 * @par Method of function operation:
504 * This function subtracts the current time from the start point.
506 * @par Corner cases/exceptions:
507 * If the start point is not set, returns 0.
509 * @return Milliseconds from appcore_measure_start()
517 #include <appcore-common.h>
523 appcore_measure_start();
527 printf("it takes %d msec to do something\n", appcore_measure_time());
533 int appcore_measure_time(void);
537 * Measure the time from a time specified in environment variable.
540 * To measure the elapsed time from a time specified in environment variable.
542 * @par Typical use case:
543 * It is used to measure the time from a time set by external.
544 * This function returns the elapsed time from a time specified in environment variable.
546 * @see appcore_measure_start()
548 * @par Method of function operation:
549 * This function subtracts the current time from a time specified in environment variable.
551 * @par Corner cases/exceptions:
552 * If <I>envnm</I> is NULL, "APP_START_TIME" set by launcher is used.
553 * If the environment variable is not set or invalid format, returns 0.
555 * @param[in] envnm environment variable name which has
556 * the start time (format: "%u %u", seconds, micro seconds)
558 * @return Milliseconds from a time specified in environment variable
566 #include <appcore-common.h>
575 printf("it takes %d msec from APP_START\n",
576 appcore_measure_time_from("APP_START_TIME"));
582 int appcore_measure_time_from(const char *envnm);
585 * Appcore UI operaions. Internal use only.
591 * Appcore init. Internal use only
593 * @par Important notes:
594 * Except special case, NEVER use this. Use the appcore EFL or GTK instead of this.
596 * @param[in] name Application name used for text domain name
597 * @param[in] ops UI operations
598 * @param[in] argc a count of the arguments
599 * @param[in] argv an array of pointers to the strings which are those arguments
601 * @return 0 on succes, -1 on error (<I>errno</I> set)
604 * EINVAL - <I>ops</I> or <I>ops</I>'s callback is NULL \n
605 * EALREADY - Appcore already in operation \n
609 * @see appcore_exit()
610 * @remarks Internal use only.
613 int appcore_init(const char *name, const struct ui_ops *ops,
614 int argc, char **argv);
618 * Appcore exit. Internal use only.
620 * @par Important notes:
621 * Except special case, NEVER use this.
625 * @see appcore_init()
626 * @remarks Internal use only.
629 void appcore_exit(void);
634 * Utility function for memory flushing
639 * @par Method of function operation:
640 * Calls application-specific memory flushing tool (e.g., elm_flush_all() for EFL),
641 * sqlite3_release_memory() if sqlite3 is used, and malloc_trim(). Also, trims native stack.
643 * @par Important notes:
644 * Currently, this function is automatically called in the following 2 cases:\n
645 * (1) when the application enters into the pause state and\n
646 * (2) when low memory event is invoked and the application is on pause.\n
647 * Developers can use this function when they want extra memory flush utility.
649 * @return 0 on success, -1 on error
651 * @pre Appcore is already initialized.
652 * @post Memory for the application is flushed.
658 #include <appcore-common.h>
666 r = appcore_flush_memory();
668 // add exception handling
676 int appcore_flush_memory(void);
680 * Set a open callback
681 * Only when application is running, if aul_open api is called, then this callback function is called.
682 * If your open_cb function return -1, then appcore doesn't raise window.
684 * @param[in] cb callback function
685 * @param[in] data callback function data
687 * @return 0 on success, -1 on error (<I>errno</I> set)
695 #include <appcore-common.h>
699 static int _open_cb(enum appcore_rm, void *);
705 r = appcore_set_open_cb(_open_cb, data);
707 // add exception handling
715 int appcore_set_open_cb(int (*cb) (void *), void *data);
727 #endif /* __APPCORE_COMMON_H__ */