1 /* 2 * Copyright (c) 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_DCAMERA_HDF_OPERATE_H 17 #define OHOS_DCAMERA_HDF_OPERATE_H 18 19 #include <condition_variable> 20 #include <mutex> 21 22 #include "iservstat_listener_hdi.h" 23 #include "idevmgr_hdi.h" 24 #include "iservmgr_hdi.h" 25 #include "single_instance.h" 26 27 using OHOS::HDI::DeviceManager::V1_0::IDeviceManager; 28 using OHOS::HDI::ServiceManager::V1_0::IServiceManager; 29 using OHOS::HDI::ServiceManager::V1_0::IServStatListener; 30 using OHOS::HDI::ServiceManager::V1_0::ServiceStatus; 31 using OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub; 32 const std::string CAMERA_SERVICE_NAME = "distributed_camera_service"; 33 const std::string PROVIDER_SERVICE_NAME = "distributed_camera_provider_service"; 34 constexpr uint16_t INVALID_VALUE = 0xffff; 35 constexpr int32_t WAIT_TIME = 2000; 36 37 namespace OHOS { 38 namespace DistributedHardware { 39 class DCameraHdfOperate { 40 DECLARE_SINGLE_INSTANCE(DCameraHdfOperate); 41 42 public: 43 int32_t LoadDcameraHDFImpl(); 44 int32_t UnLoadDcameraHDFImpl(); 45 46 private: 47 int32_t WaitLoadCameraService(); 48 int32_t WaitLoadProviderService(); 49 50 private: 51 OHOS::sptr<IDeviceManager> devmgr_; 52 OHOS::sptr<IServiceManager> servMgr_; 53 uint16_t cameraServStatus_ = INVALID_VALUE; 54 uint16_t providerServStatus_ = INVALID_VALUE; 55 std::condition_variable hdfOperateCon_; 56 std::mutex hdfOperateMutex_; 57 }; 58 59 class DCameraHdfServStatListener : public OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub { 60 public: 61 using StatusCallback = std::function<void(const ServiceStatus &)>; DCameraHdfServStatListener(StatusCallback callback)62 explicit DCameraHdfServStatListener(StatusCallback callback) : callback_(std::move(callback)) 63 { 64 } 65 ~DCameraHdfServStatListener() = default; 66 void OnReceive(const ServiceStatus& status) override; 67 68 private: 69 StatusCallback callback_; 70 }; 71 } // namespace DistributedHardware 72 } // namespace OHOS 73 #endif // OHOS_DCAMERA_HDF_OPERATE_H