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 PHOTO_NAPI_H_
17 #define PHOTO_NAPI_H_
18 
19 #include "camera_napi_utils.h"
20 
21 namespace OHOS {
22 namespace CameraStandard {
23 static const char PHOTO_NAPI_CLASS_NAME[] = "Photo";
24 
25 class PhotoNapi {
26 public:
27     static napi_value Init(napi_env env, napi_value exports);
28     static napi_value CreatePhoto(napi_env env, napi_value mainImage);
29     static napi_value CreateRawPhoto(napi_env env, napi_value mainImage);
30     PhotoNapi();
31     ~PhotoNapi();
32 
33     static napi_value GetMain(napi_env env, napi_callback_info info);
34     static napi_value GetRaw(napi_env env, napi_callback_info info);
35     static napi_value Release(napi_env env, napi_callback_info info);
36 
37 private:
38     static void PhotoNapiDestructor(napi_env env, void* nativeObject, void* finalize_hint);
39     static napi_value PhotoNapiConstructor(napi_env env, napi_callback_info info);
40 
41     static thread_local napi_ref sConstructor_;
42     static thread_local napi_value sMainImage_;
43     static thread_local napi_value sRawImage_;
44     static thread_local uint32_t photoTaskId;
45 
46     napi_env env_;
47     napi_value mainImage_;
48     napi_value rawImage_;
49 };
50 
51 struct PhotoAsyncContext : public AsyncContext {
52     PhotoNapi* objectInfo;
53 
~PhotoAsyncContextPhotoAsyncContext54     ~PhotoAsyncContext()
55     {
56         objectInfo = nullptr;
57     }
58 };
59 } // namespace CameraStandard
60 } // namespace OHOS
61 #endif /* PHOTO_NAPI_H_ */