• 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 UDMF_SERVICE_IMPL_H
17 #define UDMF_SERVICE_IMPL_H
18 
19 #include <map>
20 #include <memory>
21 #include <mutex>
22 #include <vector>
23 
24 #include "error_code.h"
25 #include "store_cache.h"
26 #include "udmf_service_stub.h"
27 #include "unified_data.h"
28 #include "unified_types.h"
29 #include "visibility.h"
30 namespace OHOS {
31 namespace UDMF {
32 /*
33  * UDMF server implementation
34  */
35 class API_EXPORT UdmfServiceImpl final : public UdmfServiceStub {
36 public:
37     UdmfServiceImpl();
38     ~UdmfServiceImpl() = default;
39 
40     int32_t SetData(CustomOption &option, UnifiedData &unifiedData, std::string &key) override;
41     int32_t GetData(const QueryOption &query, UnifiedData &unifiedData) override;
42     int32_t GetBatchData(const QueryOption &query, std::vector<UnifiedData> &unifiedDataSet) override;
43     int32_t UpdateData(const QueryOption &query, UnifiedData &unifiedData) override;
44     int32_t DeleteData(const QueryOption &query, std::vector<UnifiedData> &unifiedDataSet) override;
45     int32_t GetSummary(const QueryOption &query, Summary &summary) override;
46     int32_t AddPrivilege(const QueryOption &query, Privilege &privilege) override;
47     int32_t Sync(const QueryOption &query, const std::vector<std::string> &devices) override;
48     int32_t IsRemoteData(const QueryOption &query, bool &result) override;
49     int32_t SetAppShareOption(const std::string &intention, int32_t shareOption) override;
50     int32_t GetAppShareOption(const std::string &intention, int32_t &shareOption) override;
51     int32_t RemoveAppShareOption(const std::string &intention) override;
52     int32_t OnInitialize() override;
53     int32_t OnBind(const BindInfo &bindInfo) override;
54 
55 private:
56     int32_t SaveData(CustomOption &option, UnifiedData &unifiedData, std::string &key);
57     int32_t RetrieveData(const QueryOption &query, UnifiedData &unifiedData);
58     int32_t QueryDataCommon(const QueryOption &query, std::vector<UnifiedData> &dataSet, std::shared_ptr<Store> &store);
59     int32_t ProcessUri(const QueryOption &query, UnifiedData &unifiedData);
60     void SetRemoteUri(const QueryOption &query, std::vector<std::shared_ptr<UnifiedRecord>> &records);
61     bool IsPermissionInCache(const QueryOption &query);
62     bool IsReadAndKeep(const std::vector<Privilege> &privileges, const QueryOption &query);
63 
64     using StaticActs = DistributedData::StaticActs;
65     class UdmfStatic : public StaticActs {
66     public:
~UdmfStatic()67         ~UdmfStatic() override {};
68         int32_t OnAppInstall(const std::string &bundleName, int32_t user, int32_t index) override;
69         int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index) override;
70         int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) override;
71     };
72     class Factory {
73     public:
74         Factory();
75         ~Factory();
76 
77     private:
78         std::shared_ptr<UdmfServiceImpl> product_;
79         std::shared_ptr<UdmfStatic> staticActs_;
80     };
81     static Factory factory_;
82     std::map<std::string, Privilege> privilegeCache_;
83     std::shared_ptr<ExecutorPool> executors_;
84 };
85 } // namespace UDMF
86 } // namespace OHOS
87 #endif // UDMF_SERVICE_IMPL_H
88