1 /*
2 * Copyright (c) 2025 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 "usb_timer_wraper.h"
17 #include "usb_errors.h"
18
19 namespace OHOS {
20 namespace USB {
21
22 std::shared_ptr<UsbTimerWrapper> UsbTimerWrapper::instance_;
23 std::mutex UsbTimerWrapper::insMutex_;
24
GetInstance()25 std::shared_ptr<UsbTimerWrapper> UsbTimerWrapper::GetInstance()
26 {
27 std::lock_guard<std::mutex> guard(insMutex_);
28 if (instance_ == nullptr) {
29 USB_HILOGI(MODULE_USB_SERVICE, "reset to new instance");
30 instance_.reset(new UsbTimerWrapper());
31 }
32 return instance_;
33 }
34
UsbTimerWrapper()35 UsbTimerWrapper::UsbTimerWrapper()
36 {
37 int32_t ret = static_cast<int32_t>(usbDelayTimer_.Setup());
38 if (ret != UEC_OK) {
39 USB_HILOGE(MODULE_USB_SERVICE, "set up usbDelayTimer_ failed %{public}u", ret);
40 return;
41 }
42 }
43
~UsbTimerWrapper()44 UsbTimerWrapper::~UsbTimerWrapper()
45 {
46 usbDelayTimer_.Shutdown();
47 }
48
Unregister(uint32_t timerId)49 void UsbTimerWrapper::Unregister(uint32_t timerId)
50 {
51 usbDelayTimer_.Unregister(timerId);
52 }
53
Register(const TimerCallback & callback,uint32_t interval,bool once)54 uint32_t UsbTimerWrapper::Register(const TimerCallback& callback, uint32_t interval, bool once)
55 {
56 return usbDelayTimer_.Register(callback, interval, once);
57 }
58
59 }
60 }