• 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     int32_t IsRemoteData(const QueryOption &query, bool &result) override;
44     int32_t SetAppShareOption(const std::string &intention, int32_t shareOption) override;
45     int32_t GetAppShareOption(const std::string &intention, int32_t &shareOption) override;
46     int32_t RemoveAppShareOption(const std::string &intention) override;
47     int32_t ObtainAsynProcess(AsyncProcessInfo& processInfo) override;
48     int32_t ClearAsynProcessByKey(const std::string &businessUdKey) override;
49     int32_t SetDelayInfo(const DataLoadInfo &dataLoadInfo, sptr<IRemoteObject> iUdmfNotifier,
50         std::string &key) override;
51     int32_t PushDelayData(const std::string &key, UnifiedData &unifiedData) override;
52     int32_t GetDataIfAvailable(const std::string &key, const DataLoadInfo &dataLoadInfo,
53         sptr<IRemoteObject> iUdmfNotifier, std::shared_ptr<UnifiedData> unifiedData) override;
54 
55 private:
56     class ServiceDeathRecipient : public IRemoteObject::DeathRecipient {
57     public:
58         ServiceDeathRecipient();
59         virtual ~ServiceDeathRecipient();
60 
61         void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
62     };
63 
64     static std::shared_ptr<UdmfServiceClient> instance_;
65     static std::mutex mutex_;
66     static sptr<DistributedKv::IKvStoreDataService> kvDataServiceProxy_;
67     static sptr<DistributedKv::IKvStoreDataService> GetDistributedKvDataService();
68     sptr<UdmfServiceProxy> udmfProxy_;
69 };
70 } // namespace UDMF
71 } // namespace OHOS
72 #endif // UDMF_SERVICE_CLIENT_H