2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.tizenopensource.org/license
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include "SampleTimer.h"
20 using namespace Osp::App;
21 using namespace Osp::Base;
22 using namespace Osp::Base::Collection;
23 using namespace Osp::Base::Runtime;
25 static int TIMER_INTERVAL_READY = 5000; // Timer interval for ready state (in msec)
26 static int TIMER_INTERVAL_RUN = 1000; // Timer interval for running state (in msec)
28 SampleTimer::SampleTimer(void)
35 SampleTimer::~SampleTimer(void)
41 SampleTimer::Construct(void)
46 TryReturn(_pTimer != null, E_FAILURE, "SampleServiceApp : [E_FAILURE] Failed to create _pTimer.");
47 AppLog("SampleServiceApp : _pTimer is created.");
49 r = _pTimer->Construct(*this);
50 TryReturn(IsFailed(r) != true, r, "SampleServiceApp : [%s] Failed to construct _pTimer", GetErrorMessage(r));
51 AppLog("SampleServiceApp : _pTimer is constructed.");
53 _pTimer->Start(TIMER_INTERVAL_READY);
59 SampleTimer::Start(void)
63 TryReturn(_pTimer != null, E_OBJ_NOT_FOUND, "SampleServiceApp : _pTimer is not constructed yet. create _pTimer instance and try Start() again.");
65 r = _pTimer->Cancel();
66 TryReturn(IsFailed(r) != true, r, "SampleServiceApp : [%s] Failed to cancel _pTimer", GetErrorMessage(r));
68 r = _pTimer->Start(TIMER_INTERVAL_RUN);
69 TryReturn(IsFailed(r) != true, r, "SampleServiceApp : [%s] Failed to start _pTimer", GetErrorMessage(r));
73 AppLog("SampleServiceApp : _pTimer is started.");
79 SampleTimer::Stop(void)
83 TryReturn(_pTimer != null, E_OBJ_NOT_FOUND, "SampleServiceApp : _pTimer is not constructed yet. create _pTimer instance and try Stop() again.");
85 r = _pTimer->Cancel();
86 TryReturn(!IsFailed(r), r, "SampleServiceApp : [%s] Failed to cancel _pTimer", GetErrorMessage(r));
88 r = _pTimer->Start(TIMER_INTERVAL_READY);
89 TryReturn(!IsFailed(r), r, "SampleServiceApp : [%s] Failed to start _pTimer", GetErrorMessage(r));
91 _isRepeatable = false;
93 AppLog("SampleServiceApp : _pTimer will be stopped.");
99 SampleTimer::OnTimerExpired(Timer& timer)
101 AppLog("SampleServiceApp : _pTimer is expired.");
105 App* pApp = App::GetInstance();
108 ArrayList* pList = new ArrayList();
111 pApp->SendUserEvent(TIMER_EXPIRED, pList);
113 pList->RemoveAll(true);
119 timer.Start(TIMER_INTERVAL_RUN);
124 timer.Start(TIMER_INTERVAL_READY);