summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2013-08-10 23:23:06 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2013-08-10 23:23:06 +0900
commit393040a9fea35f41cdf5e5f70de15764795f160d (patch)
tree384d327cbbef7ca3d0744b1226181d5291c0f6ea /src/lib/ecore
parent1e9d4bf28f88b6eb4dd073ac63519f9ea58ba94e (diff)
adjust (as discussed) to have enums for memory and battery state.
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/Ecore_Common.h71
-rw-r--r--src/lib/ecore/ecore.c34
2 files changed, 65 insertions, 40 deletions
diff --git a/src/lib/ecore/Ecore_Common.h b/src/lib/ecore/Ecore_Common.h
index c84921ddef..98279a757a 100644
--- a/src/lib/ecore/Ecore_Common.h
+++ b/src/lib/ecore/Ecore_Common.h
@@ -271,8 +271,8 @@ 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_LOW_MEMORY 6 /**< Low memory state changed, see ecore_low_memory_get() */ 274#define ECORE_EVENT_MEMORY_STATE 6 /**< Memory state changed, see ecore_memory_state_get() */
275#define ECORE_EVENT_LOW_BATTERY 7 /**< Low battery state changed, see ecore_low_battery_get() */ 275#define ECORE_EVENT_POWER_STATE 7 /**< Power state changed, see ecore_power_state_get() */
276#define ECORE_EVENT_LOCALE_CHANGED 8 /**< Locale changed */ 276#define ECORE_EVENT_LOCALE_CHANGED 8 /**< Locale changed */
277#define ECORE_EVENT_HOSTNAME_CHANGED 9 /**< Hostname changed */ 277#define ECORE_EVENT_HOSTNAME_CHANGED 9 /**< Hostname changed */
278#define ECORE_EVENT_SYSTEM_TIMEDATE_CHANGED 10 /**< Time or Date changed */ 278#define ECORE_EVENT_SYSTEM_TIMEDATE_CHANGED 10 /**< Time or Date changed */
@@ -519,14 +519,14 @@ EAPI void *ecore_event_current_event_get(void);
519 * 519 *
520 * Ecore is aware of some system events that one may be interested, they are described below: 520 * Ecore is aware of some system events that one may be interested, they are described below:
521 * 521 *
522 * @li #ECORE_EVENT_LOW_MEMORY indicates system changed its free 522 * @li #ECORE_EVENT_MEMORY_STATE indicates system changed its free
523 * memory status, going to or being back from "low memory" 523 * memory status, going to or being back from "low memory"
524 * state. When going to low memory state the libraries and 524 * state. When going to low memory state the libraries and
525 * applications may help the system by reducing memory usage, 525 * applications may help the system by reducing memory usage,
526 * dropping caches and unused resources. The event carries no 526 * dropping caches and unused resources. The event carries no
527 * information, the current state should be queried with 527 * information, the current state should be queried with
528 * ecore_low_memory_get(). 528 * ecore_low_memory_get().
529 * @li #ECORE_EVENT_LOW_BATTERY indicates system changed its battery 529 * @li #ECORE_EVENT_POWER_STATE indicates system changed its battery
530 * level, going to or being back from "low battery" state. When 530 * level, going to or being back from "low battery" state. When
531 * going to low battery state the libraries and applications may 531 * going to low battery state the libraries and applications may
532 * help the system by reducing number of wake ups and processing, 532 * help the system by reducing number of wake ups and processing,
@@ -558,19 +558,31 @@ EAPI void *ecore_event_current_event_get(void);
558 */ 558 */
559 559
560/** 560/**
561 * @brief Get the current status of low memory. 561 * @enum _Ecore_Memory_State
562 * @return #EINA_TRUE if low on memory, #EINA_FALSE if memory usage is under normal levels. 562 * In dicates current system memory state
563 * @since 1.8 563 * @since 1.8
564 */ 564 */
565EAPI Eina_Bool ecore_low_memory_get(void); 565enum _Ecore_Memory_State /* Memory state */
566{
567 ECORE_MEMORY_STATE_NORMAL, /**< The normal memory usage state. No need to do anything special here - operation as normal. */
568 ECORE_MEMORY_STATE_LOW /**< The system is low on memory resources. This would indicate that it may be a good idea to free memory you don't need and minimize footprint to avoid general system problems. */
569};
570typedef enum _Ecore_Memory_State Ecore_Memory_State;
571
572/**
573 * @brief Get the current status of memory on the system.
574 * @return The current memory state for the system as a whole.
575 * @since 1.8
576 */
577EAPI Ecore_Memory_State ecore_memory_state_get(void);
566 578
567/** 579/**
568 * @brief Set the low memory status. 580 * @brief Set the memory state.
569 * @param status #EINA_TRUE if low on memory, #EINA_FALSE if memory usage is under normal levels. 581 * @param state The memory state to set.
570 * 582 *
571 * This function will keep the information about the current low 583 * This function will store information about the current
572 * memory status and if it changed will automatically create an 584 * memory state and if it changed will automatically create an
573 * #ECORE_EVENT_LOW_MEMORY event. 585 * #ECORE_EVENT_MEMORY_STATE event.
574 * 586 *
575 * @note This function should not be called by user, instead a 587 * @note This function should not be called by user, instead a
576 * monitoring entity that is system dependent. Usually an ecore module 588 * monitoring entity that is system dependent. Usually an ecore module
@@ -578,22 +590,36 @@ EAPI Eina_Bool ecore_low_memory_get(void);
578 * 590 *
579 * @since 1.8 591 * @since 1.8
580 */ 592 */
581EAPI void ecore_low_memory_set(Eina_Bool status); 593EAPI void ecore_memory_state_set(Ecore_Memory_State state);
594
595
596/**
597 * @enum _Ecore_Power_State
598 * In dicates current system memory state
599 * @since 1.8
600 */
601enum _Ecore_Power_State /* Power state */
602{
603 ECORE_POWER_STATE_MAINS, /**< The system is connected to a mains supply of power, thus there is no need to limit processing to save battery life at all. */
604 ECORE_POWER_STATE_BATTERY, /**< The system is running off battery power, but is otherwise running normally. */
605 ECORE_POWER_STATE_LOW /**< The system is low on power (on battery) and the process should do its best to conserve power. For example it may reduce or suspend polling of network resources, turn off animations or reduce framerate etc. */
606};
607typedef enum _Ecore_Power_State Ecore_Power_State;
582 608
583/** 609/**
584 * @brief Get the current status of low battery. 610 * @brief Get the current power state.
585 * @return #EINA_TRUE if low on battery, #EINA_FALSE if battery level is reasonable. 611 * @return The current power state for the system.
586 * @since 1.8 612 * @since 1.8
587 */ 613 */
588EAPI Eina_Bool ecore_low_battery_get(void); 614EAPI Ecore_Power_State ecore_power_state_get(void);
589 615
590/** 616/**
591 * @brief Set the low battery status. 617 * @brief Set the power state.
592 * @param status #EINA_TRUE if low on battery, #EINA_FALSE if battery level is reasonable. 618 * @param state The power state to set.
593 * 619 *
594 * This function will keep the information about the current low 620 * This function will store information about the current power
595 * battery status and if it changed will automatically create an 621 * state and if it changed will automatically create an
596 * #ECORE_EVENT_LOW_BATTERY event. 622 * #ECORE_EVENT_POWER_STATE event.
597 * 623 *
598 * @note This function should not be called by user, instead a 624 * @note This function should not be called by user, instead a
599 * monitoring entity that is system dependent. Usually an ecore module 625 * monitoring entity that is system dependent. Usually an ecore module
@@ -601,7 +627,8 @@ EAPI Eina_Bool ecore_low_battery_get(void);
601 * 627 *
602 * @since 1.8 628 * @since 1.8
603 */ 629 */
604EAPI void ecore_low_battery_set(Eina_Bool status); 630EAPI void ecore_power_state_set(Ecore_Power_State state);
631
605 632
606/** 633/**
607 * @} 634 * @}
diff --git a/src/lib/ecore/ecore.c b/src/lib/ecore/ecore.c
index 489dc6074d..efdc344ce2 100644
--- a/src/lib/ecore/ecore.c
+++ b/src/lib/ecore/ecore.c
@@ -98,8 +98,8 @@ 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; 101static Ecore_Power_State _ecore_power_state = ECORE_POWER_STATE_MAINS;
102static Eina_Bool _ecore_low_battery = EINA_FALSE; 102static Ecore_Memory_State _ecore_memory_state = ECORE_MEMORY_STATE_NORMAL;
103 103
104#ifdef HAVE_SYSTEMD 104#ifdef HAVE_SYSTEMD
105static Ecore_Timer *_systemd_watchdog = NULL; 105static Ecore_Timer *_systemd_watchdog = NULL;
@@ -1008,34 +1008,32 @@ _thread_callback(void *data EINA_UNUSED,
1008 _ecore_main_call_flush(); 1008 _ecore_main_call_flush();
1009} 1009}
1010 1010
1011EAPI Eina_Bool 1011EAPI Ecore_Power_State
1012ecore_low_memory_get(void) 1012ecore_power_state_get(void)
1013{ 1013{
1014 return _ecore_low_memory; 1014 return _ecore_power_state;
1015} 1015}
1016 1016
1017EAPI void 1017EAPI void
1018ecore_low_memory_set(Eina_Bool status) 1018ecore_power_state_set(Ecore_Power_State state)
1019{ 1019{
1020 status = !!status; 1020 if (_ecore_power_state == state) return;
1021 if (_ecore_low_memory == status) return; 1021 _ecore_power_state = state;
1022 _ecore_low_memory = status; 1022 ecore_event_add(ECORE_EVENT_POWER_STATE, NULL, NULL, NULL);
1023 ecore_event_add(ECORE_EVENT_LOW_MEMORY, NULL, NULL, NULL);
1024} 1023}
1025 1024
1026EAPI Eina_Bool 1025EAPI Ecore_Memory_State
1027ecore_low_battery_get(void) 1026ecore_memory_state_get(void)
1028{ 1027{
1029 return _ecore_low_battery; 1028 return _ecore_memory_state;
1030} 1029}
1031 1030
1032EAPI void 1031EAPI void
1033ecore_low_battery_set(Eina_Bool status) 1032ecore_memory_state_set(Ecore_Memory_State state)
1034{ 1033{
1035 status = !!status; 1034 if (_ecore_memory_state == state) return;
1036 if (_ecore_low_battery == status) return; 1035 _ecore_memory_state = state;
1037 _ecore_low_battery = status; 1036 ecore_event_add(ECORE_EVENT_MEMORY_STATE, NULL, NULL, NULL);
1038 ecore_event_add(ECORE_EVENT_LOW_BATTERY, NULL, NULL, NULL);
1039} 1037}
1040 1038
1041 1039