1 /* 2 * Copyright (c) 2021 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 I_KV_STORE_DATA_SERVICE_H 17 #define I_KV_STORE_DATA_SERVICE_H 18 19 #include "iremote_broker.h" 20 #include "ikvstore_client_death_observer.h" 21 #include "ikvstore_observer.h" 22 #include "iremote_proxy.h" 23 #include "iremote_stub.h" 24 #include "message_parcel.h" 25 #include "types.h" 26 27 namespace OHOS::DistributedKv { 28 class IKvStoreDataService : public IRemoteBroker { 29 public: 30 enum { 31 GET_FEATURE_INTERFACE, 32 REGISTERCLIENTDEATHOBSERVER, 33 CLOSEKVSTORE, 34 CLOSEALLKVSTORE, 35 DELETEKVSTORE, 36 DELETEALLKVSTORE, 37 GETSINGLEKVSTORE, 38 GETLOCALDEVICE, 39 GETREMOTEDEVICES, 40 STARTWATCHDEVICECHANGE, 41 STOPWATCHDEVICECHANGE, 42 SERVICE_CMD_LAST, 43 }; 44 45 DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedKv.IKvStoreDataService"); 46 47 virtual sptr<IRemoteObject> GetFeatureInterface(const std::string &name) = 0; 48 49 virtual Status RegisterClientDeathObserver(const AppId &appId, sptr<IRemoteObject> observer) = 0; 50 51 protected: 52 static constexpr size_t MAX_IPC_CAPACITY = 800 * 1024; 53 }; 54 55 class KvStoreDataServiceStub : public IRemoteStub<IKvStoreDataService> { 56 public: 57 int API_EXPORT OnRemoteRequest(uint32_t code, MessageParcel &data, 58 MessageParcel &reply, MessageOption &option) override; 59 60 private: 61 int32_t NoSupport(MessageParcel &data, MessageParcel &reply); 62 int32_t GetFeatureInterfaceOnRemote(MessageParcel &data, MessageParcel &reply); 63 int32_t RegisterClientDeathObserverOnRemote(MessageParcel &data, MessageParcel &reply); 64 65 using RequestHandler = int32_t(KvStoreDataServiceStub::*)(MessageParcel&, MessageParcel&); 66 static constexpr RequestHandler HANDLERS[SERVICE_CMD_LAST] = { 67 [GET_FEATURE_INTERFACE] = &KvStoreDataServiceStub::GetFeatureInterfaceOnRemote, 68 [REGISTERCLIENTDEATHOBSERVER] = &KvStoreDataServiceStub::RegisterClientDeathObserverOnRemote, 69 [CLOSEKVSTORE] = &KvStoreDataServiceStub::NoSupport, 70 [CLOSEALLKVSTORE] = &KvStoreDataServiceStub::NoSupport, 71 [DELETEKVSTORE] = &KvStoreDataServiceStub::NoSupport, 72 [DELETEALLKVSTORE] = &KvStoreDataServiceStub::NoSupport, 73 [GETSINGLEKVSTORE] = &KvStoreDataServiceStub::NoSupport, 74 [GETLOCALDEVICE] = &KvStoreDataServiceStub::NoSupport, 75 [GETREMOTEDEVICES] = &KvStoreDataServiceStub::NoSupport, 76 [STARTWATCHDEVICECHANGE] = &KvStoreDataServiceStub::NoSupport, 77 [STOPWATCHDEVICECHANGE] = &KvStoreDataServiceStub::NoSupport, 78 }; 79 }; 80 81 class API_EXPORT KvStoreDataServiceProxy : public IRemoteProxy<IKvStoreDataService> { 82 public: 83 explicit KvStoreDataServiceProxy(const sptr<IRemoteObject> &impl); 84 ~KvStoreDataServiceProxy() = default; 85 sptr<IRemoteObject> GetFeatureInterface(const std::string &name) override; 86 87 Status RegisterClientDeathObserver(const AppId &appId, sptr<IRemoteObject> observer) override; 88 89 private: 90 static inline BrokerDelegator<KvStoreDataServiceProxy> delegator_; 91 }; 92 } // namespace OHOS::DistributedKv 93 94 #endif // I_KV_STORE_DATA_SERVICE_H 95