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.
18 #include <native_service/frameworkunified_timer.h>
19 #include <native_service/frameworkunified_framework_if.h>
20 #include <native_service/ns_timer_if.h>
21 #include "frameworkunified_framework_core.h"
23 const UI_32 TIMER_CALLBACK_CMD_ID = 42; // The answer to life, the universe, and everything
24 const PCSTR TIMER_SERVICE_NAME = "TIMER";
27 HANDLE FrameworkunifiedAttachTimerCallback(HANDLE hApp, UI_32 initMS, UI_32 repeatMS, CbFuncPtr CbFn) {
30 if ((frameworkunifiedCheckValidAppHandle(hApp)) && (NULL != CbFn)) {
31 FrameworkunifiedAttachCallbackToDispatcher(hApp, TIMER_SERVICE_NAME, TIMER_CALLBACK_CMD_ID, CbFn);
33 CFrameworkunifiedFrameworkApp *pApp = const_cast<CFrameworkunifiedFrameworkApp *>(reinterpret_cast<const CFrameworkunifiedFrameworkApp *>(hApp));
34 NSTimerInfo ti = { WholeSeconds(initMS),
35 MSToNS(RemainderMs(initMS)),
36 TIMER_CALLBACK_CMD_ID,
37 WholeSeconds(repeatMS),
38 MSToNS(RemainderMs(repeatMS))
40 timer = NS_TimerCreate(ti, CALLBACK_MESSAGE, pApp->hAppSndMsgQ);
46 EFrameworkunifiedStatus FrameworkunifiedDetachTimerCallback(HANDLE hApp, HANDLE hTimer) {
47 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
49 if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != hTimer) {
50 EFrameworkunifiedStatus sDel = NS_TimerDelete(hTimer);
53 EFrameworkunifiedStatus sDet = FrameworkunifiedDetachCallbackFromDispatcher(hApp,
55 TIMER_CALLBACK_CMD_ID);
58 // Since the above frameworkunifiedCheckValidAppHandle(hApp) && NULL != hTimer have been confirmed,
59 // the condition will not be satisfied.
60 if (eFrameworkunifiedStatusOK != sDel || eFrameworkunifiedStatusOK != sDet) {
61 eStatus = eFrameworkunifiedStatusFail;
64 eStatus = eFrameworkunifiedStatusInvldParam;