1 /*
2 * Copyright (c) 2021-2022 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 #include "camera_timer.h"
17 #include "camera_log.h"
18
19 namespace OHOS {
20 namespace CameraStandard {
CameraTimer()21 CameraTimer::CameraTimer() : timer_(std::make_unique<OHOS::Utils::Timer>("CameraServiceTimer"))
22 {
23 MEDIA_INFO_LOG("entered.");
24 timer_->Setup();
25 };
26
~CameraTimer()27 CameraTimer::~CameraTimer()
28 {
29 MEDIA_INFO_LOG("entered.");
30 if (timer_) {
31 timer_->Shutdown();
32 timer_ = nullptr;
33 }
34 }
35
Register(const TimerCallback & callback,uint32_t interval,bool once)36 uint32_t CameraTimer::Register(const TimerCallback& callback, uint32_t interval, bool once)
37 {
38 CHECK_ERROR_RETURN_RET_LOG(timer_ == nullptr, 0, "timer is nullptr");
39
40 uint32_t timerId = timer_->Register(callback, interval, once);
41 MEDIA_DEBUG_LOG("timerId: %{public}u", timerId);
42 return timerId;
43 }
44
Unregister(uint32_t timerId)45 void CameraTimer::Unregister(uint32_t timerId)
46 {
47 MEDIA_DEBUG_LOG("timerId: %{public}d", timerId);
48 CHECK_ERROR_RETURN_LOG(timer_ == nullptr, "timer is nullptr");
49
50 timer_->Unregister(timerId);
51 }
52 } // namespace CameraStandard
53 } // namespace OHOS