1 /* 2 * Copyright (C) 2022 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_USER_FILE_CLIENT_H 17 #define INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_USER_FILE_CLIENT_H 18 19 #include "datashare_helper.h" 20 #include "datashare_predicates.h" 21 #include "napi_base_context.h" 22 #include "napi_error.h" 23 #include "napi/native_api.h" 24 #include "napi/native_node_api.h" 25 #include "napi_remote_object.h" 26 #include "uri.h" 27 28 namespace OHOS { 29 namespace Media { 30 #define EXPORT __attribute__ ((visibility ("default"))) 31 class UserFileClient { 32 public: UserFileClient()33 EXPORT UserFileClient() {} ~UserFileClient()34 EXPORT virtual ~UserFileClient() {} 35 EXPORT static bool IsValid(); 36 EXPORT static napi_status CheckIsStage(napi_env env, napi_callback_info info, bool &result); 37 EXPORT static sptr<IRemoteObject> ParseTokenInStageMode(napi_env env, napi_callback_info info); 38 EXPORT static sptr<IRemoteObject> ParseTokenInAbility(napi_env env, napi_callback_info info); 39 40 EXPORT static void Init(const sptr<IRemoteObject> &token, bool isSetHelper = false); 41 EXPORT static void Init(napi_env env, napi_callback_info info); 42 EXPORT static std::shared_ptr<DataShare::DataShareResultSet> Query(Uri &uri, 43 const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns, int &errCode); 44 EXPORT static int Insert(Uri &uri, const DataShare::DataShareValuesBucket &value); 45 EXPORT static int InsertExt(Uri &uri, const DataShare::DataShareValuesBucket &value, std::string &result); 46 EXPORT static int BatchInsert(Uri &uri, const std::vector<DataShare::DataShareValuesBucket> &values); 47 EXPORT static int Delete(Uri &uri, const DataShare::DataSharePredicates &predicates); 48 EXPORT static void NotifyChange(const Uri &uri); 49 EXPORT static void RegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver); 50 EXPORT static void UnregisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver); 51 EXPORT static int OpenFile(Uri &uri, const std::string &mode); 52 EXPORT static int Update(Uri &uri, const DataShare::DataSharePredicates &predicates, 53 const DataShare::DataShareValuesBucket &value); 54 EXPORT static void RegisterObserverExt(const Uri &uri, 55 std::shared_ptr<DataShare::DataShareObserver> dataObserver, bool isDescendants); 56 EXPORT static void UnregisterObserverExt(const Uri &uri, 57 std::shared_ptr<DataShare::DataShareObserver> dataObserver); 58 EXPORT static void Clear(); 59 private: 60 static inline std::shared_ptr<DataShare::DataShareHelper> sDataShareHelper_ = nullptr; 61 static std::shared_ptr<DataShare::DataShareHelper> GetDataShareHelper(napi_env env, napi_callback_info info); 62 }; 63 } 64 } 65 66 #endif // INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_USER_FILE_CLIENT_H