Normally, a Timer object will be used within a main context,
thus it is OK to create a Timer without specifying the main context.
However, in the case that a service creates more threads,
this parameterized constructors would be convenient.
Change-Id: I835d56f220de2afc1f364ea7c816f74cd11610ce
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
// If the GVariant 'param' is floating, it is consumed.
void publish(const std::string& busName, const std::string& signalName, GVariant* param);
+ GMainContext* getMainContext();
+
GDBusConnection* getConnection();
static uid_t getActiveUser();
namespace ctx {
+ class ServiceBase;
class ITimerListener;
/* All timers expire in the context where the Timer object is created. */
class EXPORT_API Timer {
public:
Timer();
+ Timer(ServiceBase* hostService);
+ Timer(GMainContext* mainContext);
~Timer();
/* This is a helper function that chooses and executes one of the below three functions. */
{
}
+GMainContext* ServiceBase::getMainContext()
+{
+ return __mainContext;
+}
+
GDBusConnection* ServiceBase::getConnection()
{
return __connection;
#include <atomic>
#include <alarm.h>
+#include <ServiceBase.h>
#include <ITimerListener.h>
#include <Timer.h>
{
}
+Timer::Timer(GMainContext* mainContext) :
+ __context(mainContext)
+{
+ if (__context)
+ g_main_context_ref(__context);
+}
+
+Timer::Timer(ServiceBase* hostService) :
+ Timer(hostService->getMainContext())
+{
+}
+
Timer::~Timer()
{
cancelAll();