• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     EXPORT static napi_value AnalysisAlbumInit(napi_env env, napi_value exports);
42     std::shared_ptr<PhotoAlbum> GetPhotoAlbumInstance() const;
43 private:
44     EXPORT static napi_value Constructor(napi_env env, napi_callback_info info);
45     EXPORT static void Destructor(napi_env env, void *nativeObject, void *finalizeHint);
46 
47     EXPORT static napi_value JSGetHighlightAlbumInfo(napi_env env, napi_callback_info info);
48     EXPORT static napi_value JSSetHighlightUserActionData(napi_env env, napi_callback_info info);
49     EXPORT static napi_value JSGetHighlightResource(napi_env env, napi_callback_info info);
50     EXPORT static napi_value JSGetOrderPosition(napi_env env, napi_callback_info info);
51     EXPORT static napi_value JSSetHighlightSubtitle(napi_env env, napi_callback_info info);
52     EXPORT static napi_value JSDeleteHighlightAlbums(napi_env env, napi_callback_info info);
53 
54     napi_env highlightmEnv_;
55     std::shared_ptr<PhotoAlbum> highlightAlbumPtr = nullptr;
56     static thread_local PhotoAlbum *pAlbumData_;
57     static thread_local napi_ref constructor_;
58     static thread_local napi_ref analysisAlbumConstructor_;
59 };
60 
61 struct HighlightAlbumNapiAsyncContext : public NapiError {
62     int32_t changedRows;
63     int32_t newCount;
64     std::vector<std::string> fetchColumn;
65     DataShare::DataSharePredicates predicates;
66     DataShare::DataShareValuesBucket valuesBucket;
67     std::vector<DataShare::DataShareValuesBucket> valuesBuckets;
68     std::string networkId;
69     std::string uri;
70     std::unique_ptr<FetchResult<FileAsset>> fetchResult;
71     ResultNapiType resultNapiType;
72     std::string highlightAlbumInfo;
73     std::vector<std::string> assetIdArray;
74     std::vector<int32_t> orderPositionArray;
75     int32_t albumId;
76     PhotoAlbumSubType subType;
77 
78     int32_t highlightAlbumInfoType = HighlightAlbumInfoType::INVALID_INFO;
79     int32_t highlightUserActionType = HighlightUserActionType::INVALID_USER_ACTION;
80 
81     int32_t actionData = 0;
82     std::string resourceUri;
83     std::string subtitle;
84     size_t argc;
85     napi_value argv[NAPI_ARGC_MAX];
86     napi_async_work work;
87     napi_deferred deferred;
88     napi_ref callbackRef;
89     napi_value napiArrayBuffer;
90 
91     HighlightAlbumNapi *objectInfo;
92 };
93 } // namespace Media
94 } // namespace OHOS
95 
96 #endif  // INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_HIGHLIGHT_ALBUM_NAPI_H
97