• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef TIMER_CALL_BACK_H
17 #define TIMER_CALL_BACK_H
18 
19 #include <mutex>
20 #include "timer_call_back_stub.h"
21 #include "itimer_info.h"
22 #include "time_common.h"
23 #include "ability_context.h"
24 
25 namespace OHOS {
26 namespace MiscServices {
27 class TimerCallback : public TimerCallbackStub {
28 public:
29     DISALLOW_COPY_AND_MOVE(TimerCallback);
30     static sptr<TimerCallback> GetInstance();
31     virtual void NotifyTimer(const uint64_t timerId, const sptr<IRemoteObject> &timerCallback) override;
32     /**
33      * Get timer callback info.
34      *
35      * @param  timerInfo the timer info
36      * @param  timerInfo  the timer info
37      * @return Get timer callback info success or not
38      */
39     bool InsertTimerCallbackInfo(const uint64_t timerId, const std::shared_ptr<ITimerInfo> &timerInfo);
40     bool RemoveTimerCallbackInfo(const uint64_t timerId);
41 
42 private:
43     TimerCallback();
44     ~TimerCallback();
45 
46     static std::mutex instanceLock_;
47     static sptr<TimerCallback> instance_;
48     static std::map<uint64_t, std::shared_ptr<ITimerInfo>> timerInfoMap_;
49     static std::mutex timerInfoMutex_;
50 };
51 }  // namespace MiscServices
52 }  // namespace OHOS
53 
54 #endif  // TIMER_CALL_BACK_H