From: Hokwon Song Date: Thu, 17 Oct 2013 07:45:10 +0000 (+0900) Subject: Fix duplicated alarms. X-Git-Tag: submit/tizen/20131210.080830^2^2~49^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c56a863ca20b2a578c5770ce83314e62f8ead995;p=platform%2Fframework%2Fnative%2Fappfw.git Fix duplicated alarms. Change-Id: Ia535c8b911e2753825718aa5e11a28d5a65240ed Signed-off-by: Hokwon Song --- diff --git a/src/app/FApp_AppImpl.cpp b/src/app/FApp_AppImpl.cpp index b1b52fb..e831e70 100644 --- a/src/app/FApp_AppImpl.cpp +++ b/src/app/FApp_AppImpl.cpp @@ -351,29 +351,6 @@ _AppImpl::OnService(service_s* service, void* user_data) // call for callbacks // ptr to member function - (pAppImpl->*pAppImpl->__pRequestHandler)(service, req, handler); - - std::unique_ptr pOperation(null); - char* pBuf = null; - - int errVal = service_get_operation(service, &pBuf); - pOperation.reset(pBuf); - - if((errVal == SERVICE_ERROR_NONE) && (!strcmp((const char*)pOperation.get(), "osp.operation.ALARM"))) - { - std::unique_ptr pAlarmId(null); - char* pBuf = null; - - errVal = service_get_extra_data(service, SERVICE_DATA_ALARM_ID, &pBuf); - pAlarmId.reset(pBuf); - SysTryReturnVoidResult(NID_SYS, errVal == SERVICE_ERROR_NONE, E_SYSTEM, "It is failed to get reserved alarm id."); - int alarmId = atoi((const char*)pAlarmId.get()); - - _AlarmManager* pAlarmManager = _AlarmManager::GetInstance(); - pAlarmManager->OnAlarmExpired(alarmId); - - return; - } } pAppImpl->__pIAppImpl->OnService(service, initialLaunch); diff --git a/src/system/FSys_AlarmManager.cpp b/src/system/FSys_AlarmManager.cpp index 7ddeb62..d15ba62 100644 --- a/src/system/FSys_AlarmManager.cpp +++ b/src/system/FSys_AlarmManager.cpp @@ -86,6 +86,29 @@ _AlarmManager::~_AlarmManager() alarm_cancel_all(); } +int alarm_callback(alarm_id_t alarmId, void *user_param) +{ + _AlarmManager* pAlarmManager = _AlarmManager::GetInstance(); + pAlarmManager->OnAlarmExpired((int)alarmId); + return 0; +} + +result +_AlarmManager::Construct(void) +{ + int errorCode; + Tizen::App::App* pApp = null; + pApp = Tizen::App::App::GetInstance(); + String appId = pApp->GetAppId(); + std::unique_ptr pAppId(_StringConverter::CopyToCharArrayN(appId)); + + errorCode = alarmmgr_init(pAppId.get()); + SysTryReturnResult(NID_SYS, errorCode == ALARMMGR_RESULT_SUCCESS, E_SYSTEM, "It is failed to init alarmmgr. error [%d]", errorCode); + errorCode = alarmmgr_set_cb(alarm_callback, null); + SysTryReturnResult(NID_SYS, errorCode == ALARMMGR_RESULT_SUCCESS, E_SYSTEM, "It is failed to set cb to alarmmgr. error [%d]", errorCode); + return E_SUCCESS; +} + _AlarmManager* _AlarmManager::GetInstance(void) { @@ -100,10 +123,12 @@ _AlarmManager::GetInstance(void) void _AlarmManager::InitSingleton(void) { + result r = E_SUCCESS; _AlarmManager* pAlarmManager = new (std::nothrow) _AlarmManager(); SysTryReturnVoidResult(NID_SYS, pAlarmManager, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - + r = pAlarmManager->Construct(); + SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to construct alarm manager."); __pAlarmManager = pAlarmManager; std::atexit(DestroySingleton); } @@ -163,7 +188,7 @@ _AlarmManager::ReserveAlarm(Tizen::Base::String appId, Tizen::Base::DateTime sta ret = alarmmgr_set_type(pAlarmInfo, ALARM_TYPE_NOLAUNCH); SysTryCatch(NID_SYS, ret == ALARMMGR_RESULT_SUCCESS, r = E_SYSTEM, r, "It is failed to set repeat mode"); - ret = alarmmgr_add_alarm_appsvc_with_localtime(pAlarmInfo,(void *)pBundle, &reservedAlarmId); + ret = alarmmgr_add_alarm_with_localtime(pAlarmInfo, null, &reservedAlarmId); SysTryCatch(NID_SYS, ret == ALARMMGR_RESULT_SUCCESS, r = E_SYSTEM, r, "Alarm creation failed!!! Alrmgr error code is %d", ret); CATCH: diff --git a/src/system/inc/FSys_AlarmManager.h b/src/system/inc/FSys_AlarmManager.h index 9fea083..6b953a6 100644 --- a/src/system/inc/FSys_AlarmManager.h +++ b/src/system/inc/FSys_AlarmManager.h @@ -45,6 +45,7 @@ public: static _AlarmManager* GetInstance(void); private: + result Construct(void); int ReserveAlarm(Tizen::Base::String appId, Tizen::Base::DateTime startTime, int period); result AddAlarmList(int alarmId, int period, Tizen::Base::String appId, Tizen::Base::DateTime* endTime); result RemoveAlarmList(int alarmId);