1 /* 2 * Copyright (C) 2021-2023 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 OHOS_IPC_SERVICES_DBINDER_DBINDER_STUB_H 17 #define OHOS_IPC_SERVICES_DBINDER_DBINDER_STUB_H 18 19 #include <string> 20 #include <parcel.h> 21 #include "ipc_object_stub.h" 22 23 namespace OHOS { 24 #ifdef BINDER_IPC_32BIT 25 typedef unsigned int binder_uintptr_t; 26 #else 27 typedef unsigned long long binder_uintptr_t; 28 #endif 29 30 class DBinderServiceStub : public IPCObjectStub { 31 public: 32 explicit DBinderServiceStub(const std::string &serviceName, const std::string &deviceID, 33 binder_uintptr_t binderObject); 34 ~DBinderServiceStub(); 35 36 /** 37 * @brief Gets the process protocol. 38 * @param code Indicates the message code of the request. 39 * @param data Indicates the object storing the data to be sent. 40 * @param reply Indicates the object receiving the response data. 41 * @param option Indicates a synchronous (default) or asynchronous request. 42 * @return Returns {@code 0} if valid notifications; returns an error code if the operation fails. 43 * @since 9 44 */ 45 int32_t ProcessProto(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 46 47 /** 48 * @brief Response processing of the request. 49 * @param code Indicates the service request code sent from the peer end. 50 * @param data Indicates the object sent from the peer end. 51 * @param reply Indicates the response message object sent from the remote service. 52 * @param options Indicates whether the operation is synchronous or asynchronous. 53 * @return Returns {@code 0} if the operation succeeds; returns an error code if the operation fails. 54 * @since 9 55 */ 56 int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 57 58 /** 59 * @brief Obtains the service name. 60 * @return Returns the service name. 61 * @since 9 62 */ 63 const std::string &GetServiceName(); 64 65 /** 66 * @brief Obtain the device ID. 67 * @return Returns the device ID. 68 * @since 9 69 */ 70 const std::string &GetDeviceID(); 71 72 /** 73 * @brief Obtain the binder object. 74 * @return Returns the binder object. 75 * @since 9 76 */ 77 binder_uintptr_t GetBinderObject() const; 78 79 private: 80 const std::string serviceName_; 81 const std::string deviceID_; 82 binder_uintptr_t binderObject_; 83 int32_t ProcessDeathRecipient(MessageParcel &data, MessageParcel &reply); 84 int32_t AddDbinderDeathRecipient(MessageParcel &data, MessageParcel &reply); 85 int32_t RemoveDbinderDeathRecipient(MessageParcel &data, MessageParcel &reply); 86 }; 87 } // namespace OHOS 88 #endif // OHOS_IPC_SERVICES_DBINDER_DBINDER_STUB_H 89