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 27namespace OHOS { 28namespace UDMF { 29class UdmfServiceClient final : public UdmfService { 30public: 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 ClearAsynProcess() override; 49 50private: 51 class ServiceDeathRecipient : public IRemoteObject::DeathRecipient { 52 public: 53 ServiceDeathRecipient(); 54 virtual ~ServiceDeathRecipient(); 55 56 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 57 }; 58 59 static std::shared_ptr<UdmfServiceClient> instance_; 60 static std::mutex mutex_; 61 static sptr<DistributedKv::IKvStoreDataService> kvDataServiceProxy_; 62 static sptr<DistributedKv::IKvStoreDataService> GetDistributedKvDataService(); 63 sptr<UdmfServiceProxy> udmfProxy_; 64}; 65} // namespace UDMF 66} // namespace OHOS 67#endif // UDMF_SERVICE_CLIENT_H