1 /*
2  * Copyright (C) 2024-2024 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 INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_HIGHLIGHT_ALBUM_NAPI_H
17 #define INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_HIGHLIGHT_ALBUM_NAPI_H
18 
19 #include "photo_album.h"
20 
21 #include "datashare_values_bucket.h"
22 #include "fetch_result.h"
23 #include "file_asset.h"
24 #include "napi_error.h"
25 
26 namespace OHOS {
27 namespace Media {
28 #define EXPORT __attribute__ ((visibility ("default")))
29 
30 struct HighlightAlbumInfo {
31     std::string uriStr;
32     std::vector<std::string> fetchColumn;
33 };
34 
35 class HighlightAlbumNapi {
36 public:
37     EXPORT HighlightAlbumNapi();
38     EXPORT ~HighlightAlbumNapi();
39 
40     EXPORT static napi_value Init(napi_env env, napi_value exports);
41     std::shared_ptr<PhotoAlbum> GetPhotoAlbumInstance() const;
42 private:
43     EXPORT static napi_value Constructor(napi_env env, napi_callback_info info);
44     EXPORT static void Destructor(napi_env env, void *nativeObject, void *finalizeHint);
45 
46     EXPORT static napi_value JSGetHighlightAlbumInfo(napi_env env, napi_callback_info info);
47     EXPORT static napi_value JSSetHighlightUserActionData(napi_env env, napi_callback_info info);
48     EXPORT static napi_value JSGetHighlightResource(napi_env env, napi_callback_info info);
49 
50     napi_env highlightmEnv_;
51     std::shared_ptr<PhotoAlbum> highlightAlbumPtr = nullptr;
52     static thread_local PhotoAlbum *pAlbumData_;
53     static thread_local napi_ref constructor_;
54 };
55 
56 struct HighlightAlbumNapiAsyncContext : public NapiError {
57     int32_t changedRows;
58     int32_t newCount;
59     std::vector<std::string> fetchColumn;
60     DataShare::DataSharePredicates predicates;
61     DataShare::DataShareValuesBucket valuesBucket;
62     std::vector<DataShare::DataShareValuesBucket> valuesBuckets;
63     std::string networkId;
64     std::string uri;
65     std::unique_ptr<FetchResult<FileAsset>> fetchResult;
66     ResultNapiType resultNapiType;
67     std::string highlightAlbumInfo;
68 
69     int32_t highlightAlbumInfoType = HighlightAlbumInfoType::INVALID_INFO;
70     int32_t highlightUserActionType = HighlightUserActionType::INVALID_USER_ACTION;
71 
72     int32_t actionData = 0;
73     std::string resourceUri;
74     size_t argc;
75     napi_value argv[NAPI_ARGC_MAX];
76     napi_async_work work;
77     napi_deferred deferred;
78     napi_ref callbackRef;
79     napi_value napiArrayBuffer;
80 
81     HighlightAlbumNapi *objectInfo;
82 };
83 } // namespace Media
84 } // namespace OHOS
85 
86 #endif  // INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_HIGHLIGHT_ALBUM_NAPI_H
87