• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 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 "dp_timer.h"
17 
18 #include "basic_definitions.h"
19 #include "common_timer_errors.h"
20 #include "dp_log.h"
21 
22 namespace OHOS {
23 namespace CameraStandard {
24 namespace DeferredProcessing {
DpsTimer()25 DpsTimer::DpsTimer() : timer_(std::make_unique<Utils::Timer>("DpsManagerTimer"))
26 {
27     timer_->Setup();
28 }
29 
~DpsTimer()30 DpsTimer::~DpsTimer()
31 {
32     DP_CHECK_RETURN(!timer_);
33     timer_->Shutdown(true);
34     timer_ = nullptr;
35 }
36 
StartTimer(const TimerCallback & callback,uint32_t interval)37 uint32_t DpsTimer::StartTimer(const TimerCallback& callback, uint32_t interval)
38 {
39     DP_CHECK_ERROR_RETURN_RET_LOG(timer_ == nullptr, INVALID_TIMERID, "DpsTimer is nullptr");
40 
41     uint32_t ret = timer_->Register(callback, interval, true);
42     DP_CHECK_ERROR_RETURN_RET_LOG(ret == Utils::TIMER_ERR_DEAL_FAILED, INVALID_TIMERID, "Register timer failed");
43 
44     DP_DEBUG_LOG("timerId is %{public}u, interval is %{public}u", ret, interval);
45     return ret;
46 }
47 
StopTimer(uint32_t & timerId)48 void DpsTimer::StopTimer(uint32_t& timerId)
49 {
50     DP_DEBUG_LOG("timer shutting down, timerId = %{public}u", timerId);
51     DP_CHECK_ERROR_RETURN_LOG(timerId == INVALID_TIMERID, "Unregister timer failed, timerId is invalid");
52     DP_CHECK_ERROR_RETURN_LOG(timer_ == nullptr, "DpsTimer is nullptr");
53 
54     timer_->Unregister(timerId);
55     timerId = INVALID_TIMERID;
56 }
57 } // namespace DeferredProcessing
58 } // namespace CameraStandard
59 } // namespace OHOS