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 OHOS_APPEXECFWK_DATASHARE_STUB_IMPL_H 17 #define OHOS_APPEXECFWK_DATASHARE_STUB_IMPL_H 18 19 #include <memory> 20 #include "datashare_stub.h" 21 #include "datashare_uv_queue.h" 22 #include "js_datashare_ext_ability.h" 23 #include "native_engine/native_value.h" 24 25 namespace OHOS { 26 namespace AppExecFwk { 27 using AbilityRuntime::JsDataShareExtAbility; 28 class DataShareStubImpl : public DataShareStub { 29 public: DataShareStubImpl(const std::shared_ptr<JsDataShareExtAbility> & extension,napi_env env)30 explicit DataShareStubImpl(const std::shared_ptr<JsDataShareExtAbility>& extension, napi_env env) 31 : extension_(extension) 32 { 33 uvQueue_ = std::make_shared<AbilityRuntime::DataShareUvQueue>(env); 34 } 35 ~DataShareStubImpl()36 virtual ~DataShareStubImpl() {} 37 38 std::vector<std::string> GetFileTypes(const Uri &uri, const std::string &mimeTypeFilter) override; 39 40 int OpenFile(const Uri &uri, const std::string &mode) override; 41 42 int OpenRawFile(const Uri &uri, const std::string &mode) override; 43 44 int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value) override; 45 46 int Update(const Uri &uri, const NativeRdb::ValuesBucket &value, 47 const NativeRdb::DataAbilityPredicates &predicates) override; 48 49 int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) override; 50 51 std::shared_ptr<NativeRdb::AbsSharedResultSet> Query(const Uri &uri, 52 std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates) override; 53 54 std::string GetType(const Uri &uri) override; 55 56 int BatchInsert(const Uri &uri, const std::vector<NativeRdb::ValuesBucket> &values) override; 57 58 bool RegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver) override; 59 60 bool UnregisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver) override; 61 62 bool NotifyChange(const Uri &uri) override; 63 64 Uri NormalizeUri(const Uri &uri) override; 65 66 Uri DenormalizeUri(const Uri &uri) override; 67 68 std::vector<std::shared_ptr<AppExecFwk::DataAbilityResult>> ExecuteBatch( 69 const std::vector<std::shared_ptr<AppExecFwk::DataAbilityOperation>> &operations) override; 70 private: 71 std::shared_ptr<JsDataShareExtAbility> GetOwner(); 72 73 private: 74 std::shared_ptr<JsDataShareExtAbility> extension_; 75 std::shared_ptr<AbilityRuntime::DataShareUvQueue> uvQueue_; 76 }; 77 } // namespace AppExecFwk 78 } // namespace OHOS 79 #endif // OHOS_APPEXECFWK_DATASHARE_STUB_IMPL_H 80 81