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 CAMERA_MANAGER_CALLBACK_NAPI_H_ 17 #define CAMERA_MANAGER_CALLBACK_NAPI_H_ 18 19 #include "camera_log.h" 20 #include "napi/native_api.h" 21 #include "napi/native_node_api.h" 22 23 #include "hilog/log.h" 24 #include "camera_napi_utils.h" 25 26 #include "input/camera_manager.h" 27 28 #include <fstream> 29 #include <iostream> 30 #include <sstream> 31 #include <vector> 32 33 #include <fcntl.h> 34 #include <sys/stat.h> 35 #include <sys/time.h> 36 #include <sys/types.h> 37 38 namespace OHOS { 39 namespace CameraStandard { 40 class CameraManagerCallbackNapi : public CameraManagerCallback { 41 public: 42 explicit CameraManagerCallbackNapi(napi_env env, napi_ref callbackRef_); 43 virtual ~CameraManagerCallbackNapi(); 44 void OnCameraStatusChanged(const CameraStatusInfo &cameraStatusInfo) const override; 45 void OnFlashlightStatusChanged(const std::string &cameraID, const FlashStatus flashStatus) const override; 46 47 private: 48 void OnCameraStatusCallback(const CameraStatusInfo &cameraStatusInfo) const; 49 void OnCameraStatusCallbackAsync(const CameraStatusInfo &cameraStatusInfo) const; 50 51 napi_env env_ = nullptr; 52 napi_ref callbackRef_; 53 }; 54 55 struct CameraStatusCallbackInfo { 56 CameraStatusInfo info_; 57 const CameraManagerCallbackNapi* listener_; CameraStatusCallbackInfoCameraStatusCallbackInfo58 CameraStatusCallbackInfo(CameraStatusInfo info, const CameraManagerCallbackNapi* listener) 59 : info_(info), listener_(listener) {} ~CameraStatusCallbackInfoCameraStatusCallbackInfo60 ~CameraStatusCallbackInfo() 61 { 62 listener_ = nullptr; 63 } 64 }; 65 } // namespace CameraStandard 66 } // namespace OHOS 67 #endif /* CAMERA_MANAGER_CALLBACK_NAPI_H_ */ 68