• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 DATASHARE_STUB_IMPL_H
17 #define 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 "napi_remote_object.h"
24 
25 namespace OHOS {
26 namespace DataShare {
27 using DataShare::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<DataShare::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 DataShareValuesBucket &value) override;
45 
46     int Update(const Uri &uri, const DataSharePredicates &predicates,
47         const DataShareValuesBucket &value) override;
48 
49     int Delete(const Uri &uri, const DataSharePredicates &predicates) override;
50 
51     std::shared_ptr<DataShareResultSet> Query(const Uri &uri, const DataSharePredicates &predicates,
52         std::vector<std::string> &columns, DatashareBusinessError &businessError) override;
53 
54     std::string GetType(const Uri &uri) override;
55 
56     int BatchInsert(const Uri &uri, const std::vector<DataShareValuesBucket> &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 private:
69     std::shared_ptr<JsDataShareExtAbility> GetOwner();
70     bool CheckCallingPermission(const std::string &permission);
71     void GetCallingInfo(CallingInfo& callingInfo);
72     std::shared_ptr<JsDataShareExtAbility> extension_;
73     std::shared_ptr<DataShare::DataShareUvQueue> uvQueue_;
74     std::mutex mutex_;
75 };
76 } // namespace DataShare
77 } // namespace OHOS
78 #endif // DATASHARE_STUB_IMPL_H
79 
80