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 #include "enumerator_manager.h"
17
18 namespace OHOS::Camera {
EnumeratorManager()19 EnumeratorManager::EnumeratorManager() {}
20
~EnumeratorManager()21 EnumeratorManager::~EnumeratorManager()
22 {
23 uvcVideo_->V4L2UvcDetectUnInit();
24 uvcVideo_ = nullptr;
25 }
26
Init()27 RetCode EnumeratorManager::Init()
28 {
29 uvcVideo_ = std::make_shared<HosV4L2UVC>();
30 if (uvcVideo_ == nullptr) {
31 CAMERA_LOGE("%s Create HosV4L2UVC fail", __FUNCTION__);
32 return RC_ERROR;
33 }
34 uvcVideo_->V4L2UvcDetectInit([&](const std::string& hardwareName,
35 std::vector<DeviceControl>& deviceControl,
36 std::vector<DeviceFormat>& deviceFormat, bool uvcState) {
37 UvcCallBack(hardwareName, deviceControl, deviceFormat, uvcState);
38 });
39 return RC_OK;
40 }
41
SetCallBack(UvcDataCb cb)42 void EnumeratorManager::SetCallBack(UvcDataCb cb)
43 {
44 uvcCb_ = cb;
45 }
46
UvcCallBack(const std::string hardwareName,std::vector<DeviceControl> & deviceControl,std::vector<DeviceFormat> & deviceFormat,bool uvcState)47 void EnumeratorManager::UvcCallBack(const std::string hardwareName,
48 std::vector<DeviceControl>& deviceControl,
49 std::vector<DeviceFormat>& deviceFormat, bool uvcState)
50 {
51 if (uvcCb_ == nullptr) {
52 CAMERA_LOGE("%s uvcCb_ is nullptr", __FUNCTION__);
53 return;
54 }
55 uvcCb_(hardwareName, deviceControl, deviceFormat, uvcState);
56 }
57 } // namespace OHOS::Camera