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