1 /* 2 * Copyright (C) 2023 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_MEDIA_ASSETS_CHANGE_REQUEST_NAPI_H 17 #define INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_MEDIA_ASSETS_CHANGE_REQUEST_NAPI_H 18 19 #include <vector> 20 21 #include "datashare_helper.h" 22 #include "datashare_predicates.h" 23 #include "file_asset.h" 24 #include "media_change_request_napi.h" 25 #include "values_bucket.h" 26 27 namespace OHOS { 28 namespace Media { 29 #define EXPORT __attribute__ ((visibility ("default"))) 30 enum class AssetsChangeOperation { 31 BATCH_SET_FAVORITE, 32 BATCH_SET_HIDDEN, 33 BATCH_SET_USER_COMMENT, 34 }; 35 36 class MediaAssetsChangeRequestNapi : public MediaChangeRequestNapi { 37 public: 38 EXPORT MediaAssetsChangeRequestNapi() = default; 39 EXPORT ~MediaAssetsChangeRequestNapi() override = default; 40 41 EXPORT static napi_value Init(napi_env env, napi_value exports); 42 43 std::vector<std::string> GetFileAssetUriArray() const; 44 bool GetFavoriteStatus() const; 45 bool GetHiddenStatus() const; 46 std::string GetUpdatedUserComment() const; 47 napi_value ApplyChanges(napi_env env, napi_callback_info info) override; 48 49 private: 50 EXPORT static napi_value Constructor(napi_env env, napi_callback_info info); 51 EXPORT static void Destructor(napi_env env, void* nativeObject, void* finalizeHint); 52 53 EXPORT static napi_value JSSetFavorite(napi_env env, napi_callback_info info); 54 EXPORT static napi_value JSSetHidden(napi_env env, napi_callback_info info); 55 EXPORT static napi_value JSSetUserComment(napi_env env, napi_callback_info info); 56 57 bool CheckChangeOperations(napi_env env); 58 59 static thread_local napi_ref constructor_; 60 bool isFavorite_; 61 bool isHidden_; 62 std::string userComment_; 63 std::vector<std::shared_ptr<FileAsset>> fileAssets_; 64 std::vector<AssetsChangeOperation> assetsChangeOperations_; 65 }; 66 67 struct MediaAssetsChangeRequestAsyncContext : public NapiError { 68 size_t argc; 69 napi_value argv[NAPI_ARGC_MAX]; 70 napi_async_work work; 71 napi_deferred deferred; 72 napi_ref callbackRef; 73 74 MediaAssetsChangeRequestNapi* objectInfo; 75 std::vector<AssetsChangeOperation> assetsChangeOperations; 76 }; 77 } // namespace Media 78 } // namespace OHOS 79 80 #endif // INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_MEDIA_ASSETS_CHANGE_REQUEST_NAPI_H