void cancel(unsigned int timerId);
void cancelAll();
- /* This runs in a simliar manner to g_idle_add() */
+ /* This runs in a simliar manner to g_idle_add(). */
unsigned int addIdle(ITimerListener* listener);
- /* This runs in a simliar manner to g_timeout_add().
- However, if wakeLock == true, this does not accept the intervals longer than TIMEOUT_MAX. */
- unsigned int addTimeout(unsigned int intervalMs, ITimerListener* listener, bool wakeLock = false);
+ /* This runs in a simliar manner to g_timeout_add(). */
+ unsigned int addTimeout(unsigned int intervalMs, ITimerListener* listener);
/* This runs on the alarm-service, thus the device will be woken up whenever the interval passes.
Unlike the above functions, this takes an interval in minutes. */
unsigned int addAlarm(unsigned int intervalMin, ITimerListener* listener);
- static void setDBusConnection(GDBusConnection* conn);
-
- static const unsigned int TIMEOUT_MAX; /* milli-seconds */
-
private:
struct ListenerInfo;
#include <ITimerListener.h>
#include <Timer.h>
-#define TIMEOUT_MAX_SECONDS 10
-#define TIMEOUT_MARGIN 100
-#define MILLIS_PER_MIN 60000
+#define MILLIS_PER_MIN 60000
#define TIMER_ID (++__timerCnt)
#define INIT_CONTEXT if (!__context) __context = g_main_context_ref_thread_default()
using namespace ctx;
-const unsigned int Timer::TIMEOUT_MAX = TIMEOUT_MAX_SECONDS * 1000;
-static GDBusConnection* __dbusConnection = NULL;
static std::atomic_uint __timerCnt;
struct ctx::Timer::ListenerInfo {
unsigned int intervalMs;
GSource* gSrc;
int alarmId;
- bool wakeLock;
ListenerInfo(Timer* t, ITimerListener* l) :
timer(t),
listener(l),
timerId(0),
intervalMs(0),
gSrc(NULL),
- alarmId(-1),
- wakeLock(false) {}
+ alarmId(-1) {}
};
-static void __lockingRequestDone(GObject* srcObj, GAsyncResult* res, gpointer userData)
-{
- GError *gerr = NULL;
- GVariant* param = g_dbus_connection_call_finish(__dbusConnection, res, &gerr);
- HANDLE_GERROR(gerr);
- if (param)
- g_variant_unref(param);
-}
-
-static void __requestLock(unsigned int timeoutMs)
-{
- IF_FAIL_VOID_TAG(__dbusConnection, _E, "No DBus Connection");
- _D("Lock %u (+%d) ms", timeoutMs, TIMEOUT_MARGIN);
-
- int timeoutExtended = static_cast<int>(timeoutMs) + TIMEOUT_MARGIN;
-
- g_dbus_connection_call(__dbusConnection,
- "org.tizen.system.deviced", "/Org/Tizen/System/DeviceD/Display",
- "org.tizen.system.deviced.display", "lockstate",
- g_variant_new("(sssi)", "lcdoff", "staycurstate", "NULL", timeoutExtended),
- NULL, G_DBUS_CALL_FLAGS_NONE, CTX_DBUS_TIMEOUT, NULL, __lockingRequestDone, NULL);
-}
-
Timer::Timer() :
__context(NULL)
{
if (intervalMs == 0)
return addIdle(listener);
- if (intervalMs <= TIMEOUT_MAX)
- return addTimeout(intervalMs, listener, true);
+ if (intervalMs < MILLIS_PER_MIN)
+ return addTimeout(intervalMs, listener);
unsigned int intervalMin = intervalMs / MILLIS_PER_MIN;
-
- if (intervalMin > 0)
- return addAlarm(intervalMin, listener);
-
- return 0;
+ return addAlarm(intervalMin, listener);
}
void Timer::cancel(unsigned int timerId)
return info->timerId;
}
-unsigned int Timer::addTimeout(unsigned int intervalMs, ITimerListener* listener, bool wakeLock)
+unsigned int Timer::addTimeout(unsigned int intervalMs, ITimerListener* listener)
{
INIT_CONTEXT;
info->timerId = TIMER_ID;
info->intervalMs = intervalMs;
info->gSrc = gSrc;
- info->wakeLock = wakeLock;
_D("Add Timeout <Id: %u, Interval: %u ms>", info->timerId, intervalMs);
__listeners.insert(info);
- if (wakeLock)
- __requestLock(intervalMs);
-
g_source_set_callback(gSrc, __onGSourceExpired, info, NULL);
g_source_attach(gSrc, __context);
g_source_unref(gSrc);
return G_SOURCE_REMOVE;
}
- if (info->wakeLock)
- __requestLock(info->intervalMs);
-
return G_SOURCE_CONTINUE;
}
alarmmgr_remove_alarm(info->alarmId);
delete info;
}
-
-void Timer::setDBusConnection(GDBusConnection* conn)
-{
- __dbusConnection = conn;
-}