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 21 #include "ability_context.h" 22 #include "itimer_info.h" 23 #include "time_common.h" 24 #include "timer_call_back_stub.h" 25 26 namespace OHOS { 27 namespace MiscServices { 28 class TimerCallback : public TimerCallbackStub { 29 public: 30 DISALLOW_COPY_AND_MOVE(TimerCallback); 31 static sptr<TimerCallback> GetInstance(); 32 virtual void NotifyTimer(const uint64_t timerId, const sptr<IRemoteObject> &timerCallback) override; 33 /** 34 * Get timer callback info. 35 * 36 * @param timerInfo the timer info 37 * @param timerInfo the timer info 38 * @return Get timer callback info success or not 39 */ 40 bool InsertTimerCallbackInfo(const uint64_t timerId, const std::shared_ptr<ITimerInfo> &timerInfo); 41 bool RemoveTimerCallbackInfo(const uint64_t timerId); 42 43 private: 44 TimerCallback(); 45 ~TimerCallback(); 46 47 static std::mutex instanceLock_; 48 static sptr<TimerCallback> instance_; 49 static std::map<uint64_t, std::shared_ptr<ITimerInfo>> timerInfoMap_; 50 static std::mutex timerInfoMutex_; 51 }; 52 } // namespace MiscServices 53 } // namespace OHOS 54 55 #endif // TIMER_CALL_BACK_H