• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef OHOS_CAMERA_H_CAMERA_HOST_MANAGER_H
17 #define OHOS_CAMERA_H_CAMERA_HOST_MANAGER_H
18 
19 #include <refbase.h>
20 #include <iostream>
21 #include <memory>
22 #include <mutex>
23 #include <string>
24 #include <vector>
25 #include "camera_metadata_info.h"
26 #include "v1_0/icamera_device.h"
27 #include "v1_0/icamera_host.h"
28 #include "v1_1/icamera_device.h"
29 #include "v1_1/icamera_host.h"
30 #include "icamera_device_service.h"
31 #include "icamera_service_callback.h"
32 #include "iservstat_listener_hdi.h"
33 
34 namespace OHOS {
35 namespace CameraStandard {
36 using namespace OHOS::HDI::Camera::V1_0;
37 using namespace OHOS::HDI;
38 class HCameraHostManager : public virtual RefBase, public HDI::ServiceManager::V1_0::ServStatListenerStub {
39 public:
40     class StatusCallback {
41     public:
42         virtual ~StatusCallback() = default;
43         virtual void OnCameraStatus(const std::string& cameraId, CameraStatus status) = 0;
44         virtual void OnFlashlightStatus(const std::string& cameraId, FlashStatus status) = 0;
45     };
46 
47     explicit HCameraHostManager(StatusCallback* statusCallback);
48     ~HCameraHostManager() override;
49 
50     int32_t Init(void);
51     void DeInit(void);
52     void AddCameraDevice(const std::string& cameraId, sptr<ICameraDeviceService> cameraDevice);
53     virtual int32_t GetVersionByCamera(const std::string& cameraId);
54     void RemoveCameraDevice(const std::string& cameraId);
55     void CloseCameraDevice(const std::string& cameraId);
56 
57     virtual int32_t GetCameras(std::vector<std::string> &cameraIds);
58     virtual int32_t GetCameraAbility(std::string &cameraId, std::shared_ptr<OHOS::Camera::CameraMetadata> &ability);
59     virtual int32_t OpenCameraDevice(std::string &cameraId,
60                                      const sptr<ICameraDeviceCallback> &callback,
61                                      sptr<OHOS::HDI::Camera::V1_1::ICameraDevice> &pDevice);
62     virtual int32_t SetFlashlight(const std::string& cameraId, bool isEnable);
63     virtual int32_t Prelaunch(const std::string& cameraId);
64 
65     // HDI::ServiceManager::V1_0::IServStatListener
66     void OnReceive(const HDI::ServiceManager::V1_0::ServiceStatus& status) override;
67     std::vector<sptr<ICameraDeviceService>> CameraConflictDetection(const std::string& cameraId);
68 
69 private:
70     struct CameraDeviceInfo;
71     class CameraHostInfo;
72 
73     void AddCameraHost(const std::string& svcName);
74     void RemoveCameraHost(const std::string& svcName);
75     sptr<CameraHostInfo> FindCameraHostInfo(const std::string& cameraId);
76     bool IsCameraHostInfoAdded(const std::string& svcName);
77 
78     std::mutex mutex_;
79     std::mutex deviceMutex_;
80     StatusCallback* statusCallback_;
81     std::vector<sptr<CameraHostInfo>> cameraHostInfos_;
82     std::map<std::string, sptr<ICameraDeviceService>> cameraDevices_;
83 };
84 } // namespace CameraStandard
85 } // namespace OHOS
86 #endif // OHOS_CAMERA_H_CAMERA_HOST_MANAGER_H
87