• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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_SMART_ALBUM_NAPI_H_
17 #define INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_SMART_ALBUM_NAPI_H_
18 
19 #include <algorithm>
20 #include <vector>
21 
22 #include "ability.h"
23 #include "ability_loader.h"
24 #include "abs_shared_result_set.h"
25 #include "data_ability_helper.h"
26 #include "data_ability_predicates.h"
27 #include "fetch_file_result_napi.h"
28 #include "fetch_result.h"
29 #include "smart_album_asset.h"
30 #include "medialibrary_napi_utils.h"
31 #include "medialibrary_db_const.h"
32 #include "napi/native_api.h"
33 #include "napi/native_node_api.h"
34 #include "result_set.h"
35 #include "uri.h"
36 #include "values_bucket.h"
37 #include "napi_remote_object.h"
38 #include "datashare_helper.h"
39 
40 namespace OHOS {
41 namespace Media {
42 static const std::string SMART_ALBUM_NAPI_CLASS_NAME = "SmartAlbum";
43 static const std::string USERFILEMGR_SMART_ALBUM_NAPI_CLASS_NAME = "UserFileMgrSmartAlbum";
44 
45 class SmartAlbumNapi {
46 public:
47     static napi_value Init(napi_env env, napi_value exports);
48     static napi_value UserFileMgrInit(napi_env env, napi_value exports);
49     static napi_value CreateSmartAlbumNapi(napi_env env, std::unique_ptr<SmartAlbumAsset> &albumData);
50     int32_t GetSmartAlbumId() const;
51     std::string GetSmartAlbumName() const;
52     std::string GetSmartAlbumUri() const;
53     int32_t GetAlbumPrivateType() const;
54     void SetAlbumCapacity(int32_t albumCapacity);
55     std::string GetNetworkId() const;
56     std::string GetTypeMask() const;
57     SmartAlbumNapi();
58     ~SmartAlbumNapi();
59 
60 private:
61     static void SmartAlbumNapiDestructor(napi_env env, void* nativeObject, void* finalize_hint);
62     static napi_value SmartAlbumNapiConstructor(napi_env env, napi_callback_info info);
63     void SetSmartAlbumNapiProperties();
64 
65     static napi_value JSGetSmartAlbumId(napi_env env, napi_callback_info info);
66     static napi_value JSGetSmartAlbumName(napi_env env, napi_callback_info info);
67     static napi_value JSGetSmartAlbumUri(napi_env env, napi_callback_info info);
68     static napi_value JSGetSmartAlbumTag(napi_env env, napi_callback_info info);
69     static napi_value JSGetSmartAlbumCapacity(napi_env env, napi_callback_info info);
70     static napi_value JSGetSmartAlbumCategoryId(napi_env env, napi_callback_info info);
71     static napi_value JSGetSmartAlbumCategoryName(napi_env env, napi_callback_info info);
72     static napi_value JSGetSmartAlbumCoverUri(napi_env env, napi_callback_info info);
73     static napi_value JSGetSmartAlbumDateModified(napi_env env, napi_callback_info info);
74 
75     static napi_value JSSmartAlbumNameSetter(napi_env env, napi_callback_info info);
76     static napi_value JSCommitModify(napi_env env, napi_callback_info info);
77     static napi_value JSAddAsset(napi_env env, napi_callback_info info);
78     static napi_value JSRemoveAsset(napi_env env, napi_callback_info info);
79     static napi_value JSGetSmartAlbumFileAssets(napi_env env, napi_callback_info info);
80     static napi_value UserFileMgrGetAssets(napi_env env, napi_callback_info info);
81     static napi_value UserFileMgrDeleteAsset(napi_env env, napi_callback_info info);
82     static napi_value UserFileMgrRecoverAsset(napi_env env, napi_callback_info info);
83 
84     static thread_local SmartAlbumAsset *sAlbumData_;
85     std::shared_ptr<SmartAlbumAsset> smartAlbumAssetPtr = nullptr;
86     napi_env env_;
87 
88     static thread_local napi_ref sConstructor_;
89     static thread_local napi_ref userFileMgrConstructor_;
90 };
91 
92 struct SmartAlbumNapiAsyncContext : public NapiError {
93     napi_async_work work;
94     napi_deferred deferred;
95     napi_ref callbackRef;
96     SmartAlbumNapi *objectInfo;
97     std::shared_ptr<SmartAlbumAsset> objectPtr;
98     bool status;
99     int32_t changedRows;
100     std::string selection;
101     OHOS::DataShare::DataShareValuesBucket valuesBucket;
102     std::vector<std::string> selectionArgs;
103     std::string order;
104     std::string uri;
105     std::string networkId;
106     std::unique_ptr<FetchResult<FileAsset>> fetchResult;
107     std::vector<int32_t> assetIds;
108 
109     size_t argc;
110     napi_value argv[NAPI_ARGC_MAX];
111     ResultNapiType resultNapiType;
112     std::vector<uint32_t> mediaTypes;
113     std::string typeMask;
114     OHOS::DataShare::DataSharePredicates predicates;
115     std::vector<std::string> fetchColumn;
116 };
117 } // namespace Media
118 } // namespace OHOS
119 
120 #endif  // INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_SMART_ALBUM_NAPI_H_
121