• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GENERAL_CONTROLLER_SERVICE_IMPL_H
17 #define GENERAL_CONTROLLER_SERVICE_IMPL_H
18 
19 #include <memory>
20 
21 #include "concurrent_map.h"
22 #include "data_share_manager_impl.h"
23 #include "executor_pool.h"
24 #include "general_controller.h"
25 #include "uri.h"
26 
27 namespace OHOS {
28 namespace AAFwk {
29 class IDataAbilityObserver;
30 }
31 
32 namespace DataShare {
33 using ChangeInfo = AAFwk::ChangeInfo;
34 
35 struct TimedQueryResult {
36     bool isFinish_;
37     DatashareBusinessError businessError_;
38     std::shared_ptr<DataShareResultSet> resultSet_;
39 
TimedQueryResultTimedQueryResult40     explicit TimedQueryResult(bool isFinish, DatashareBusinessError businessError,
41         std::shared_ptr<DataShareResultSet> resultSet) : isFinish_(isFinish),
42         businessError_(businessError), resultSet_(resultSet) {}
43 };
44 
45 class GeneralControllerServiceImpl : public GeneralController {
46 public:
47     GeneralControllerServiceImpl(const std::string &ext);
48 
49     virtual ~GeneralControllerServiceImpl();
50 
51     int Insert(const Uri &uri, const DataShareValuesBucket &value) override;
52 
53     int Update(const Uri &uri, const DataSharePredicates &predicates, const DataShareValuesBucket &value) override;
54 
55     int Delete(const Uri &uri, const DataSharePredicates &predicates) override;
56 
57     std::shared_ptr<DataShareResultSet> Query(const Uri &uri, const DataSharePredicates &predicates,
58         std::vector<std::string> &columns, DatashareBusinessError &businessError, DataShareOption &option) override;
59 
60     int RegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver) override;
61 
62     int UnregisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver) override;
63 
64     void NotifyChange(const Uri &uri) override;
65 
66     int RegisterObserverExtProvider(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver,
67         bool isDescendants) override;
68 
69     int UnregisterObserverExtProvider(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver) override;
70 
71     int NotifyChangeExtProvider(const ChangeInfo &changeInfo) override;
72 
73     std::pair<int32_t, int32_t> InsertEx(const Uri &uri, const DataShareValuesBucket &value) override;
74 
75     std::pair<int32_t, int32_t> UpdateEx(
76         const Uri &uri, const DataSharePredicates &predicates, const DataShareValuesBucket &value) override;
77 
78     std::pair<int32_t, int32_t> DeleteEx(const Uri &uri, const DataSharePredicates &predicates) override;
79 
80 private:
81     void ReRegisterObserver();
82 
83     void SetRegisterCallback();
84 
85     std::pair<std::shared_ptr<DataShareResultSet>, DatashareBusinessError> TimedQuery(
86         std::shared_ptr<DataShareServiceProxy> proxy, const UriInfo &paramSet,
87         const DataSharePredicates &predicates, const std::vector<std::string> &columns);
88 
89     ConcurrentMap<sptr<AAFwk::IDataAbilityObserver>, std::list<Uri>> observers_;
90 
91     std::string extUri_;
92 
93     std::shared_ptr<ExecutorPool> pool_;
94 
95     static constexpr int MAX_RETRY_COUNT = 3;
96 
97     static constexpr int RANDOM_MIN = 50;
98 
99     static constexpr int RANDOM_MAX = 150;
100 };
101 } // namespace DataShare
102 } // namespace OHOS
103 #endif // GENERAL_CONTROLLER_SERVICE_IMPL_H
104