• 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 
30 namespace OHOS {
31 namespace UDMF {
32 /*
33  * UDMF server implementation
34  */
35 class 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 OnInitialize() override;
49     int32_t OnBind(const BindInfo &bindInfo) override;
50 
51 private:
52     int32_t SaveData(CustomOption &option, UnifiedData &unifiedData, std::string &key);
53     int32_t RetrieveData(const QueryOption &query, UnifiedData &unifiedData);
54     int32_t QueryDataCommon(const QueryOption &query, std::vector<UnifiedData> &dataSet, std::shared_ptr<Store> &store);
55     int32_t ProcessUri(const QueryOption &query, UnifiedData &unifiedData);
56     void SetRemoteUri(const QueryOption &query, std::vector<std::shared_ptr<UnifiedRecord>> &records);
57     bool IsPermissionInCache(const QueryOption &query);
58 
59     using StaticActs = DistributedData::StaticActs;
60     class UdmfStatic : public StaticActs {
61     public:
~UdmfStatic()62         ~UdmfStatic() override {};
63         int32_t OnAppInstall(const std::string &bundleName, int32_t user, int32_t index) override;
64         int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index) override;
65         int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) override;
66     };
67     class Factory {
68     public:
69         Factory();
70         ~Factory();
71 
72     private:
73         std::shared_ptr<UdmfServiceImpl> product_;
74         std::shared_ptr<UdmfStatic> staticActs_;
75     };
76     static Factory factory_;
77     std::map<std::string, Privilege> privilegeCache_;
78     std::shared_ptr<ExecutorPool> executors_;
79 };
80 } // namespace UDMF
81 } // namespace OHOS
82 #endif // UDMF_SERVICE_IMPL_H
83