#include <new>
#include <unique_ptr.h>
+#include <pthread.h>
#include <alarm.h>
#include <appfw/app.h>
static const int ALARM_PERIOD_MIN = 60;
static const int WEEKDAYS_CNT = 7;
}
+
+namespace Tizen { namespace System {
+
+static pthread_mutex_t alarm_lock;
+
_AlarmConditionHandler* pAlarmConditionHandler = null;
int RefAlarmConditionHandler = 0;
_AlarmConditionHandler*
pAlarmConditionHandler = new (std::nothrow) _AlarmConditionHandler;
}
RefAlarmConditionHandler ++;
+
return pAlarmConditionHandler;
}
_AlarmConditionHandler::_AlarmConditionHandler()
{
+ int errorCode = 0;
+
conditionList.Construct();
+
+ if(pthread_mutex_init(&alarm_lock, null))
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to init mutex.");
+ }
+
+ errorCode = vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, SettingEventCb, null);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT event listener");
+ }
}
_AlarmConditionHandler::~_AlarmConditionHandler()
{
+ int errorCode = 0;
+
+ errorCode = vconf_ignore_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, SettingEventCb);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT event listener");
+ }
+
+ if(pthread_mutex_destroy(&alarm_lock))
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to term mutex.");
+ }
}
result
if(r == E_OBJ_ALREADY_EXIST)
{
- SysLogException(NID_SYS, E_OBJ_ALREADY_EXIST, "The sspecified condition is already registered.");
+ SysLogException(NID_SYS, E_OBJ_ALREADY_EXIST, "The specified condition is already registered.");
r = E_OBJ_ALREADY_EXIST;
}
else if(r != E_SUCCESS)
expireTime.tm_mon -= _ADJUST_MONTH_FOR_TM;
ret = service_create(&service);
- SysTryCatch(NID_SYS, ret == SERVICE_ERROR_NONE, r = E_SYSTEM, r, "It is failed to create service");
+ SysTryCatch(NID_SYS, ret == SERVICE_ERROR_NONE, r = E_SYSTEM, r, "It is failed to create service");
ret = app_get_package(&packageName);
SysTryCatch(NID_SYS, ret == APP_ERROR_NONE, r = E_SYSTEM, r, "It is failed to get package name");
SysTryCatch(NID_SYS, ret == SERVICE_ERROR_NONE, r = E_SYSTEM, r, "It is failed to create service for %s", packageName);
ret = alarm_schedule_at_date(service, &expireTime, period * _SECOND_OF_MINUTE, &reservedAlarmId);
- SysTryCatch(NID_SYS, ret == ALARM_ERROR_NONE, r = E_SYSTEM, r, "It is failed to set the Alarm time for %s", packageName);
+ SysTryCatch(NID_SYS, ret == ALARM_ERROR_NONE, r = E_SYSTEM, r, "It is failed to set the Alarm time for %s", packageName);
time_t reserved, current;
ret = alarmmgr_get_next_duetime(reservedAlarmId, &reserved);
SysLog(NID_SYS, "current %lld, reserved: %lld", current, reserved);
alarm_cancel(reservedAlarmId);
r = E_INVALID_CONDITION;
+ SysLog(NID_SYS, "It is failed to register requested condition.");
goto CATCH;
}
_AppLaunchCondition* pAppLaunchCondition = null;
result r = E_SYSTEM;
+ SysLog(NID_SYS, "Unregister alarm condition is %ls", appLaunchCondition.GetConditionString().GetPointer());
SysTryReturnResult(NID_SYS, pMapEnum != null, E_SYSTEM, "Reserved condition list is empty");
ArrayList garbageCollector;
return Fire(condition);
}
+void
+_AlarmConditionHandler::SettingEventCb(keynode_t* node, void* userData)
+{
+ int ret = 0;
+ result r = E_SYSTEM;
+ Integer* pKey = null;
+ _AlarmConditionHandler* pAlarmCondHandler = null;
+ _AppLaunchCondition* pAppLaunchCondition = null;
+ _AppLaunchCondition* pNewAppLaunchCondition;
+ IMapEnumerator* pMapEnum;
+ IEnumerator* pEnum;
+ Tizen::Base::Collection::HashMap updateList;
+
+ SysLog(NID_SYS, "Alarm setting event cb is invoked");
+
+ pthread_mutex_lock(&alarm_lock);
+ pAlarmCondHandler = _AlarmConditionHandler::GetInstance();
+ if(pAlarmCondHandler == null)
+ {
+ SysLog(NID_SYS, "There is no _AlarmConditionHandler");
+ return;
+ }
+
+ pMapEnum = pAlarmCondHandler->GetAlarmConditionListN();
+ if(pMapEnum == null)
+ {
+ SysLog(NID_SYS, "Reserved condition list is empty");
+ return;
+ }
+
+ if (strcmp(VCONFKEY_SYSTEM_TIME_CHANGED, vconf_keynode_get_name(node)) == 0)
+ {
+ SysLog(NID_SYS, "System time is changed");
+
+ updateList.Construct();
+
+ while(pMapEnum->MoveNext() == E_SUCCESS)
+ {
+ pKey = static_cast<Integer *>(pMapEnum->GetKey());
+ pAppLaunchCondition = static_cast<_AppLaunchCondition *>(pMapEnum->GetValue());
+
+ AppId appId(pAppLaunchCondition->GetAppId());
+ String condition(pAppLaunchCondition->GetConditionString());
+
+ pNewAppLaunchCondition = pAlarmCondHandler->GetAppLaunchConditionN(*(new AppId(appId)), *(new String(condition)));
+ SysTryCatch(NID_SYS, pNewAppLaunchCondition != null, r = E_OUT_OF_MEMORY, r, "It is failed to create pAppLaunchCondition");
+
+ updateList.Add(pKey, pNewAppLaunchCondition);
+ }
+
+ delete pMapEnum;
+ pMapEnum = updateList.GetMapEnumeratorN();
+ SysTryCatch(NID_SYS, pMapEnum != null, r = E_SYSTEM, r, "Reserved condition list is empty");
+
+ while(pMapEnum->MoveNext() == E_SUCCESS)
+ {
+ pAppLaunchCondition = static_cast<_AppLaunchCondition *>(pMapEnum->GetValue());
+
+ SysLog(NID_SYS, "Alarm Unregister : %ls", pAppLaunchCondition->GetConditionString().GetPointer());
+ ret = pAlarmCondHandler->Unregister(*pAppLaunchCondition);
+ SysTryCatch(NID_SYS, ret == E_SUCCESS, r = E_SYSTEM, r, "It is failed to unregister the alarm condition %ls", pAppLaunchCondition->GetConditionString().GetPointer());
+ }
+
+ pMapEnum->Reset();
+ while(pMapEnum->MoveNext() == E_SUCCESS)
+ {
+ pAppLaunchCondition = static_cast<_AppLaunchCondition *>(pMapEnum->GetValue());
+
+ SysLog(NID_SYS, "Alarm Register : %ls", pAppLaunchCondition->GetConditionString().GetPointer());
+ ret = pAlarmCondHandler->Register(*pAppLaunchCondition);
+ SysTryCatch(NID_SYS, ret == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register the alarm condition %ls", pAppLaunchCondition->GetConditionString().GetPointer());
+ }
+ }
+
+CATCH:
+ if(pMapEnum != null)
+ delete pMapEnum;
+
+ pAlarmCondHandler->ReleaseInstance();
+ pthread_mutex_unlock(&alarm_lock);
+}
+
+IMapEnumerator*
+_AlarmConditionHandler::GetAlarmConditionListN(void)
+{
+ IMapEnumerator* pMapEnum = conditionList.GetMapEnumeratorN();
+ if(pMapEnum == null)
+ {
+ SysLog(NID_SYS, "Reserved condition list is empty");
+ return null;
+ }
+
+ return pMapEnum;
+}
+
+_AppLaunchCondition*
+_AlarmConditionHandler::GetAppLaunchConditionN(const AppId& appId, const Tizen::Base::String& condition)
+{
+ result r = E_SYSTEM;
+
+ _AppLaunchCondition* pAppLaunchCondition = new (std::nothrow) _AppLaunchCondition();
+ SysTryCatch(NID_SYS, pAppLaunchCondition != null, r = E_OUT_OF_MEMORY, r, "It is failed to create pAppLaunchCondition");
+
+ r = pAppLaunchCondition->Construct(appId, condition, null, AppManager::LAUNCH_OPTION_DEFAULT, null);
+ SysTryCatch(NID_SYS, !IsFailed(r), r, r, "It is failed to pAppLaunchCondition->Constructor");
+
+ return pAppLaunchCondition;
+
+CATCH:
+ if(pAppLaunchCondition != null)
+ delete pAppLaunchCondition;
+
+ return null;
+}
+
//////////////////////////////////////////////////////////////
// All plugins must provide both a creation and a destruction function
/////////////////////////////////////////////////////////////
_AlarmConditionHandler::ReleaseInstance();
}
+}
+}
}//extern "C"