1 /* 2 * Copyright (C) 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_MEDIA_ASSET_DATA_HANDLER_NAPI_H 17 #define INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_MEDIA_ASSET_DATA_HANDLER_NAPI_H 18 19 #include "medialibrary_napi_utils.h" 20 21 namespace OHOS { 22 namespace Media { 23 enum class ReturnDataType { 24 TYPE_IMAGE_SOURCE = 0, 25 TYPE_ARRAY_BUFFER, 26 TYPE_MOVING_PHOTO, 27 TYPE_TARGET_PATH, 28 TYPE_PICTURE, 29 }; 30 31 enum class DeliveryMode { 32 FAST = 0, 33 HIGH_QUALITY, 34 BALANCED_MODE, 35 }; 36 37 enum class SourceMode { 38 ORIGINAL_MODE = 0, 39 EDITED_MODE, 40 }; 41 42 enum class NotifyMode : int32_t { 43 FAST_NOTIFY = 0, 44 WAIT_FOR_HIGH_QUALITY, 45 }; 46 47 constexpr const char* ON_DATA_PREPARED_FUNC = "onDataPrepared"; 48 49 class NapiMediaAssetDataHandler { 50 public: 51 NapiMediaAssetDataHandler(napi_env env, napi_ref dataHandler, ReturnDataType dataType, const std::string &uri, 52 const std::string &destUri, SourceMode sourceMode); 53 void DeleteNapiReference(napi_env env); 54 ReturnDataType GetReturnDataType(); 55 std::string GetRequestUri(); 56 std::string GetDestUri(); 57 SourceMode GetSourceMode(); 58 void SetNotifyMode(NotifyMode trigger); 59 NotifyMode GetNotifyMode(); 60 void JsOnDataPrepared(napi_env env, napi_value exports, napi_value extraInfo); 61 void JsOnDataPrepared(napi_env env, napi_value pictures, napi_value exports, napi_value extraInfo); 62 63 private: 64 napi_env env_ = nullptr; 65 napi_ref dataHandlerRef_ = nullptr; 66 ReturnDataType dataType_; 67 std::string requestUri_; 68 std::string destUri_; 69 SourceMode sourceMode_; 70 NotifyMode notifyMode_ = NotifyMode::FAST_NOTIFY; 71 }; 72 } // Media 73 } // OHOS 74 #endif // INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_MEDIA_ASSET_DATA_HANDLER_NAPI_H 75