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