summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2013-08-08 20:09:37 -0300
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2013-08-09 12:14:00 -0300
commit0a9c78896b875c265c80177a6b5fde16b7820339 (patch)
tree044e6742edf2c8e91c5a690cecb1990b73fc6fbe /src/lib/ecore
parent76eceda2ee4bd6a284389c74a60083bc6d5f8b1c (diff)
ecore: add system-level events.
- ECORE_EVENT_LOW_MEMORY: Low memory state changed - ECORE_EVENT_LOW_BATTERY: Low battery state changed - ECORE_EVENT_LOCALE_CHANGED: Locale changed - ECORE_EVENT_HOSTNAME_CHANGED: Hostname changed - ECORE_EVENT_SYSTEM_TIMEDATE_CHANGED: Time or Date changed
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/Ecore_Common.h102
-rw-r--r--src/lib/ecore/ecore.c34
2 files changed, 135 insertions, 1 deletions
diff --git a/src/lib/ecore/Ecore_Common.h b/src/lib/ecore/Ecore_Common.h
index 3d794a8096..c84921ddef 100644
--- a/src/lib/ecore/Ecore_Common.h
+++ b/src/lib/ecore/Ecore_Common.h
@@ -271,7 +271,12 @@ EAPI int ecore_thread_main_loop_end(void);
271#define ECORE_EVENT_SIGNAL_EXIT 3 /**< Exit signal event */ 271#define ECORE_EVENT_SIGNAL_EXIT 3 /**< Exit signal event */
272#define ECORE_EVENT_SIGNAL_POWER 4 /**< Power signal event */ 272#define ECORE_EVENT_SIGNAL_POWER 4 /**< Power signal event */
273#define ECORE_EVENT_SIGNAL_REALTIME 5 /**< Realtime signal event */ 273#define ECORE_EVENT_SIGNAL_REALTIME 5 /**< Realtime signal event */
274#define ECORE_EVENT_COUNT 6 274#define ECORE_EVENT_LOW_MEMORY 6 /**< Low memory state changed, see ecore_low_memory_get() */
275#define ECORE_EVENT_LOW_BATTERY 7 /**< Low battery state changed, see ecore_low_battery_get() */
276#define ECORE_EVENT_LOCALE_CHANGED 8 /**< Locale changed */
277#define ECORE_EVENT_HOSTNAME_CHANGED 9 /**< Hostname changed */
278#define ECORE_EVENT_SYSTEM_TIMEDATE_CHANGED 10 /**< Time or Date changed */
279#define ECORE_EVENT_COUNT 11
275 280
276typedef struct _Ecore_Win32_Handler Ecore_Win32_Handler; /**< A handle for HANDLE handlers on Windows */ 281typedef struct _Ecore_Win32_Handler Ecore_Win32_Handler; /**< A handle for HANDLE handlers on Windows */
277typedef struct _Ecore_Event_Handler Ecore_Event_Handler; /**< A handle for an event handler */ 282typedef struct _Ecore_Event_Handler Ecore_Event_Handler; /**< A handle for an event handler */
@@ -510,6 +515,101 @@ EAPI void *ecore_event_current_event_get(void);
510 */ 515 */
511 516
512/** 517/**
518 * @defgroup Ecore_System_Events System Events
519 *
520 * Ecore is aware of some system events that one may be interested, they are described below:
521 *
522 * @li #ECORE_EVENT_LOW_MEMORY indicates system changed its free
523 * memory status, going to or being back from "low memory"
524 * state. When going to low memory state the libraries and
525 * applications may help the system by reducing memory usage,
526 * dropping caches and unused resources. The event carries no
527 * information, the current state should be queried with
528 * ecore_low_memory_get().
529 * @li #ECORE_EVENT_LOW_BATTERY indicates system changed its battery
530 * level, going to or being back from "low battery" state. When
531 * going to low battery state the libraries and applications may
532 * help the system by reducing number of wake ups and processing,
533 * increasing @ref Ecore_Animator frame time values, reducing the
534 * number of @ref Ecore_Timer and @ref Ecore_Idler or even going
535 * to extreme of trading quality over speed to finish tasks
536 * sooner. The event carries no information, the current state
537 * should be queried with ecore_low_battery_get().
538 * @li #ECORE_EVENT_LOCALE_CHANGED indicates the system locale and/or
539 * language changed. This event carries no information and there
540 * is no ecore specific call to get the new locale. It is advised
541 * that the emitter of this event to set the new locale, for
542 * instance in POSIX one should call setlocale() before adding the
543 * event. Libraries and applications should then reload their
544 * resources and reformat their strings to use the new values.
545 * @li #ECORE_EVENT_HOSTNAME_CHANGED indicates the system hostname
546 * changed. This event carries no information and the new value
547 * should be queried with platform specific calls, such as
548 * gethostname() on POSIX.
549 * @li #ECORE_EVENT_SYSTEM_TIMEDATE_CHANGED indicates the system time
550 * or date changed. This may happen as result of Daylight Saving
551 * changes, NTP fixing the clock, changing timezones or user
552 * setting a new date manually. This event carries no information
553 * and the new value should be queried with ecore_time_unix_get()
554 * or platform specific such as gettimeofday()
555 *
556 * @ingroup Ecore_Event_Group
557 * @{
558 */
559
560/**
561 * @brief Get the current status of low memory.
562 * @return #EINA_TRUE if low on memory, #EINA_FALSE if memory usage is under normal levels.
563 * @since 1.8
564 */
565EAPI Eina_Bool ecore_low_memory_get(void);
566
567/**
568 * @brief Set the low memory status.
569 * @param status #EINA_TRUE if low on memory, #EINA_FALSE if memory usage is under normal levels.
570 *
571 * This function will keep the information about the current low
572 * memory status and if it changed will automatically create an
573 * #ECORE_EVENT_LOW_MEMORY event.
574 *
575 * @note This function should not be called by user, instead a
576 * monitoring entity that is system dependent. Usually an ecore module
577 * that is platform-specific.
578 *
579 * @since 1.8
580 */
581EAPI void ecore_low_memory_set(Eina_Bool status);
582
583/**
584 * @brief Get the current status of low battery.
585 * @return #EINA_TRUE if low on battery, #EINA_FALSE if battery level is reasonable.
586 * @since 1.8
587 */
588EAPI Eina_Bool ecore_low_battery_get(void);
589
590/**
591 * @brief Set the low battery status.
592 * @param status #EINA_TRUE if low on battery, #EINA_FALSE if battery level is reasonable.
593 *
594 * This function will keep the information about the current low
595 * battery status and if it changed will automatically create an
596 * #ECORE_EVENT_LOW_BATTERY event.
597 *
598 * @note This function should not be called by user, instead a
599 * monitoring entity that is system dependent. Usually an ecore module
600 * that is platform-specific.
601 *
602 * @since 1.8
603 */
604EAPI void ecore_low_battery_set(Eina_Bool status);
605
606/**
607 * @}
608 */
609
610
611
612/**
513 * @defgroup Ecore_Exe_Group Process Spawning Functions 613 * @defgroup Ecore_Exe_Group Process Spawning Functions
514 * 614 *
515 * This module is responsible for managing portable processes using Ecore. 615 * This module is responsible for managing portable processes using Ecore.
diff --git a/src/lib/ecore/ecore.c b/src/lib/ecore/ecore.c
index 879f130d8d..28726a2229 100644
--- a/src/lib/ecore/ecore.c
+++ b/src/lib/ecore/ecore.c
@@ -98,6 +98,9 @@ static int _thread_id = -1;
98static int _thread_id_max = 0; 98static int _thread_id_max = 0;
99static int _thread_id_update = 0; 99static int _thread_id_update = 0;
100 100
101static Eina_Bool _ecore_low_memory = EINA_FALSE;
102static Eina_Bool _ecore_low_battery = EINA_FALSE;
103
101#ifdef HAVE_SYSTEMD 104#ifdef HAVE_SYSTEMD
102static Ecore_Timer *_systemd_watchdog = NULL; 105static Ecore_Timer *_systemd_watchdog = NULL;
103#endif 106#endif
@@ -915,6 +918,37 @@ _thread_callback(void *data EINA_UNUSED,
915 _ecore_main_call_flush(); 918 _ecore_main_call_flush();
916} 919}
917 920
921EAPI Eina_Bool
922ecore_low_memory_get(void)
923{
924 return _ecore_low_memory;
925}
926
927EAPI void
928ecore_low_memory_set(Eina_Bool status)
929{
930 status = !!status;
931 if (_ecore_low_memory == status) return;
932 _ecore_low_memory = status;
933 ecore_event_add(ECORE_EVENT_LOW_MEMORY, NULL, NULL, NULL);
934}
935
936EAPI Eina_Bool
937ecore_low_battery_get(void)
938{
939 return _ecore_low_battery;
940}
941
942EAPI void
943ecore_low_battery_set(Eina_Bool status)
944{
945 status = !!status;
946 if (_ecore_low_battery == status) return;
947 _ecore_low_battery = status;
948 ecore_event_add(ECORE_EVENT_LOW_BATTERY, NULL, NULL, NULL);
949}
950
951
918static const Eo_Class_Description parent_class_desc = { 952static const Eo_Class_Description parent_class_desc = {
919 EO_VERSION, 953 EO_VERSION,
920 "ecore_parent", 954 "ecore_parent",