2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_SystemManagerIf
19 /// \brief This file provides support for the System Manager client interface.
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "system_service/ss_system_timer.h"
24 #include <native_service/ns_timer_if.h>
25 #include <native_service/ns_message_center_if.h>
27 #include "ss_system_timer_local.h"
30 m_bInit(FALSE), m_hApp(NULL), m_hSnd(NULL), m_hTmr(NULL) {
31 bzero(&m_tTi, sizeof(m_tTi));
34 Timer::Timer(HANDLE hdl, UI_32 id, CbFuncPtr CbFn):
35 m_bInit(FALSE), m_hApp(NULL), m_hSnd(NULL), m_hTmr(NULL) {
36 bzero(&m_tTi, sizeof(m_tTi));
37 Initialize(hdl, id, CbFn);
44 } // LCOV_EXCL_BR_LINE 10:Because destructor
46 BOOL Timer::Initialize(HANDLE hApp, UI_32 id, CbFuncPtr CbFn) {
47 if (!m_bInit && hApp && id && CbFn) {
55 m_hSnd = McOpenSender(FrameworkunifiedGetAppName(m_hApp));
56 m_hTmr = NS_TimerCreate(m_tTi, CALLBACK_MESSAGE, m_hSnd);
62 void Timer::Reinitialize(UI_32 id) {
71 m_hSnd = McOpenSender(FrameworkunifiedGetAppName(m_hApp));
72 m_hTmr = NS_TimerCreate(m_tTi, CALLBACK_MESSAGE, m_hSnd);
78 void Timer::Shutdown() {
81 NS_TimerDelete(m_hTmr);
89 BOOL Timer::SetTime(UI_32 ss, UI_32 sms, UI_32 rs, UI_32 rms) {
92 m_tTi.t_nsec = (ss || sms) ? sms*NS_PER_MS : 1; // LCOV_EXCL_BR_LINE 11:Unexpected branch
94 m_tTi.rpt_nsec = rms*NS_PER_MS;
99 BOOL Timer::Start(UI_32 ss, UI_32 sms, UI_32 rs, UI_32 rms) {
101 SetTime(ss, sms, rs, rms);
102 FrameworkunifiedAttachCallbackToDispatcher(m_hApp, TIMER_SERVICE_NAME, m_tTi.iCmd, m_CbFn);
103 NS_TimerSetTime(m_hTmr, m_tTi);
108 BOOL Timer::Start() {
110 FrameworkunifiedAttachCallbackToDispatcher(m_hApp, TIMER_SERVICE_NAME, m_tTi.iCmd, m_CbFn);
111 m_tTi.t_nsec = (m_tTi.t_sec || m_tTi.t_nsec) ? m_tTi.t_nsec : 1; // LCOV_EXCL_BR_LINE 11:Unexpected branch
112 NS_TimerSetTime(m_hTmr, m_tTi);
119 NSTimerInfo ti = m_tTi;
124 NS_TimerSetTime(m_hTmr, ti);
125 FrameworkunifiedDetachCallbackFromDispatcher(m_hApp, TIMER_SERVICE_NAME, ti.iCmd);
130 // LCOV_EXCL_START 6:Because the condition cannot be set
131 TimerCtrl::TimerCtrl()
132 : m_hApp(NULL), m_nTimersMax(DEFAULT_NTIMERS) {
135 TimerCtrl::TimerCtrl(UI_32 ntimers)
136 : m_hApp(NULL), m_nTimersMax(ntimers) {
139 void TimerCtrl::Initialize(HANDLE hApp) {
140 if ( NULL != hApp ) {
142 if (m_aTimers.empty() && m_rTimers.empty()) {
143 for (UI_32 i = DEFAULT_TIMERID; i < DEFAULT_TIMERID+m_nTimersMax; ++i) {
144 m_aTimers.push_back(i);
150 void TimerCtrl::Shutdown() {
152 while (m_rTimers.begin() != m_rTimers.end()) {
153 Timer* p_timer = m_rTimers.begin()->second;
156 m_rTimers.erase(m_rTimers.begin());
160 UI_32 TimerCtrl::CreateTimer(CbFuncPtr CbFn) {
161 if (!m_aTimers.empty()) {
162 UI_32 id = m_aTimers.front();
163 m_aTimers.pop_front();
164 Timer* p_timer = new Timer(m_hApp, id, CbFn);
165 m_rTimers.insert(std::pair<UI_32, Timer*>(id, p_timer));
171 UI_32 TimerCtrl::DeleteTimer(UI_32 id) {
172 if (m_rTimers.find(id) != m_rTimers.end()) {
173 Timer* p_timer = m_rTimers.find(id)->second;
176 m_rTimers.erase(m_rTimers.find(id));
177 m_aTimers.push_back(id);
183 UI_32 TimerCtrl::SetTimer(UI_32 id, UI_32 ss, UI_32 sms, UI_32 rs, UI_32 rms) {
184 if (m_rTimers.find(id) != m_rTimers.end()) {
185 Timer* p_timer = m_rTimers.find(id)->second;
186 p_timer->SetTime(ss, sms, rs, rms);
191 UI_32 TimerCtrl::StartTimer(UI_32 id, UI_32 ss, UI_32 sms, UI_32 rs, UI_32 rms) {
192 if (m_rTimers.find(id) != m_rTimers.end()) {
193 Timer* p_timer = m_rTimers.find(id)->second;
194 p_timer->Start(ss, sms, rs, rms);
200 UI_32 TimerCtrl::StartTimerMulti(UI_32 id, UI_32 ss, UI_32 sms, UI_32 rs, UI_32 rms, UI_32 subId) {
201 if (m_rTimers.find(id) != m_rTimers.end()) {
202 Timer* p_timer = m_rTimers.find(id)->second;
204 p_timer->Reinitialize(id + subId);
205 p_timer->Start(ss, sms, rs, rms);
211 UI_32 TimerCtrl::StartTimer(UI_32 id) {
212 if (m_rTimers.find(id) != m_rTimers.end()) {
213 Timer* p_timer = m_rTimers.find(id)->second;
220 UI_32 TimerCtrl::StopTimer(UI_32 id) {
221 if (m_rTimers.find(id) != m_rTimers.end()) {
222 Timer* p_timer = m_rTimers.find(id)->second;