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 private: 37 struct HdfRemoteService *service_; 38 }; 39 40 class HdfDeathNotifier : public OHOS::IRemoteObject::DeathRecipient { 41 public: 42 HdfDeathNotifier(struct HdfRemoteService *service, struct HdfDeathRecipient *recipient); 43 virtual ~HdfDeathNotifier(); 44 void OnRemoteDied(const OHOS::wptr<OHOS::IRemoteObject> &object) override; 45 46 private: 47 struct HdfDeathRecipient *recipient_; 48 struct HdfRemoteService *service_; 49 }; 50 51 struct HdfRemoteServiceHolder { 52 HdfRemoteServiceHolder(); 53 ~HdfRemoteServiceHolder() = default; 54 55 bool SetInterfaceDescriptor(const char *desc); 56 struct HdfRemoteService service_; 57 OHOS::sptr<OHOS::IRemoteObject> remote_; 58 OHOS::sptr<OHOS::IRemoteObject::DeathRecipient> deathRecipient_; 59 std::u16string descriptor_; 60 }; 61 62 struct HdfRemoteService *HdfRemoteAdapterBind(OHOS::sptr<OHOS::IRemoteObject> binder); 63 64 #ifdef __cplusplus 65 } 66 #endif /* __cplusplus */ 67 #endif /* HDF_REMOTE_ADPATER_H */ 68