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 HDF_REMOTE_ADPATER_H 17 #define HDF_REMOTE_ADPATER_H 18 19 #include <ipc_object_stub.h> 20 #include <parcel.h> 21 #include <string> 22 23 #include "hdf_remote_adapter_if.h" 24 #include "hdf_remote_service.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif /* __cplusplus */ 29 30 class HdfRemoteServiceStub : public OHOS::IPCObjectStub { 31 public: 32 explicit HdfRemoteServiceStub(struct HdfRemoteService *service); 33 int OnRemoteRequest(uint32_t code, 34 OHOS::MessageParcel &data, OHOS::MessageParcel &reply, OHOS::MessageOption &option) override; 35 ~HdfRemoteServiceStub(); 36 int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override; 37 private: 38 struct HdfRemoteService *service_; 39 }; 40 41 class HdfDeathNotifier : public OHOS::IRemoteObject::DeathRecipient { 42 public: 43 HdfDeathNotifier(struct HdfRemoteService *service, struct HdfDeathRecipient *recipient); 44 virtual ~HdfDeathNotifier(); 45 void OnRemoteDied(const OHOS::wptr<OHOS::IRemoteObject> &object) override; 46 47 private: 48 struct HdfDeathRecipient *recipient_; 49 struct HdfRemoteService *service_; 50 }; 51 52 struct HdfRemoteServiceHolder { 53 HdfRemoteServiceHolder(); 54 ~HdfRemoteServiceHolder() = default; 55 56 bool SetInterfaceDescriptor(const char *desc); 57 struct HdfRemoteService service_; 58 OHOS::sptr<OHOS::IRemoteObject> remote_; 59 OHOS::sptr<OHOS::IRemoteObject::DeathRecipient> deathRecipient_; 60 std::u16string descriptor_; 61 }; 62 63 struct HdfRemoteService *HdfRemoteAdapterBind(OHOS::sptr<OHOS::IRemoteObject> binder); 64 65 #ifdef __cplusplus 66 } 67 #endif /* __cplusplus */ 68 #endif /* HDF_REMOTE_ADPATER_H */ 69