common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / nsframework / framework_unified / client / NS_FrameworkCore / src / frameworkunified_timer.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17
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"
22
23 const UI_32 TIMER_CALLBACK_CMD_ID = 42;  // The answer to life, the universe, and everything
24 const PCSTR TIMER_SERVICE_NAME = "TIMER";
25
26
27 HANDLE FrameworkunifiedAttachTimerCallback(HANDLE hApp, UI_32 initMS, UI_32 repeatMS, CbFuncPtr CbFn) {
28   HANDLE timer = NULL;
29
30   if ((frameworkunifiedCheckValidAppHandle(hApp)) && (NULL != CbFn)) {
31     FrameworkunifiedAttachCallbackToDispatcher(hApp, TIMER_SERVICE_NAME, TIMER_CALLBACK_CMD_ID, CbFn);
32
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))
39                      };
40     timer = NS_TimerCreate(ti, CALLBACK_MESSAGE, pApp->hAppSndMsgQ);
41   }
42
43   return timer;
44 }
45
46 EFrameworkunifiedStatus FrameworkunifiedDetachTimerCallback(HANDLE hApp, HANDLE hTimer) {
47   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
48
49   if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != hTimer) {
50     EFrameworkunifiedStatus sDel = NS_TimerDelete(hTimer);
51     hTimer = NULL;
52
53     EFrameworkunifiedStatus sDet = FrameworkunifiedDetachCallbackFromDispatcher(hApp,
54                                                       TIMER_SERVICE_NAME,
55                                                       TIMER_CALLBACK_CMD_ID);
56
57     // out of coverage
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;
62     }
63   } else {
64     eStatus = eFrameworkunifiedStatusInvldParam;
65   }
66   return eStatus;
67 }