• 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_CLIENT_H
17 #define UDMF_SERVICE_CLIENT_H
18 
19 #include <mutex>
20 #include <string>
21 
22 #include "ikvstore_data_service.h"
23 #include "iremote_object.h"
24 #include "udmf_service.h"
25 #include "udmf_service_proxy.h"
26 
27 namespace OHOS {
28 namespace UDMF {
29 class UdmfServiceClient final : public UdmfService {
30 public:
31     explicit UdmfServiceClient(const sptr<UdmfServiceProxy> &proxy);
32     ~UdmfServiceClient() override = default;
33     static std::shared_ptr<UdmfServiceClient> GetInstance();
34 
35     int32_t SetData(CustomOption &option, UnifiedData &unifiedData, std::string &key) override;
36     int32_t GetData(const QueryOption &query, UnifiedData &unifiedData) override;
37     int32_t GetBatchData(const QueryOption &query, std::vector<UnifiedData> &unifiedDataSet) override;
38     int32_t UpdateData(const QueryOption &query, UnifiedData &unifiedData) override;
39     int32_t DeleteData(const QueryOption &query, std::vector<UnifiedData> &unifiedDataSet) override;
40     int32_t GetSummary(const QueryOption &query, Summary &summary) override;
41     int32_t AddPrivilege(const QueryOption &query, Privilege &privilege) override;
42     int32_t Sync(const QueryOption &query, const std::vector<std::string> &devices) override;
43 
44 private:
45     class ServiceDeathRecipient : public IRemoteObject::DeathRecipient {
46     public:
47         ServiceDeathRecipient();
48         virtual ~ServiceDeathRecipient();
49 
50         void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
51     };
52 
53     static std::shared_ptr<UdmfServiceClient> instance_;
54     static std::mutex mutex_;
55     static sptr<DistributedKv::IKvStoreDataService> kvDataServiceProxy_;
56     static sptr<DistributedKv::IKvStoreDataService> GetDistributedKvDataService();
57     sptr<UdmfServiceProxy> udmfProxy_;
58 };
59 } // namespace UDMF
60 } // namespace OHOS
61 #endif // UDMF_SERVICE_CLIENT_H