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_IPC_FILE_DESCRIPTOR_H 17 #define OHOS_IPC_IPC_FILE_DESCRIPTOR_H 18 19 #include "parcel.h" 20 21 namespace OHOS { 22 class IPCFileDescriptor : public virtual Parcelable { 23 public: 24 IPCFileDescriptor(); 25 explicit IPCFileDescriptor(int fd); 26 ~IPCFileDescriptor(); 27 28 /** 29 * @brief Marshal the object. 30 * @param parcel Indicates the Parcel object to which the sequenceable object will be marshaled. 31 * @return Returns <b>true</b> if the marshalling is successful; returns <b>false</b> otherwise. 32 * @since 9 33 */ 34 bool Marshalling(Parcel &parcel) const override; 35 36 /** 37 * @brief Marshal the object. 38 * @param Parcel Indicates the Parcel object to which the sequenceable object will be marshaled. 39 * @param object Indicates the IPCFileDescriptor pointer object. 40 * @return Returns <b>true</b> if the marshalling is successful; returns <b>false</b> otherwise. 41 * @since 9 42 */ 43 static bool Marshalling(Parcel &parcel, const sptr<IPCFileDescriptor> &object); 44 45 /** 46 * @brief Unmarshal the object. 47 * @param Parcel Indicates the Parcel object to which the sequenceable object will be marshaled. 48 * @return Returns <b>true</b> if the marshalling is successful; returns <b>false</b> otherwise. 49 * @since 9 50 */ 51 static IPCFileDescriptor *Unmarshalling(Parcel &parcel); 52 53 /** 54 * @brief Gets the file descriptor. 55 * @return Returns the file descriptor. 56 * @since 9 57 */ 58 int GetFd() const; 59 60 /** 61 * @brief Sets the file descriptor. 62 * @param fd Indicates the file descriptor. 63 * @return void 64 * @since 9 65 */ 66 void SetFd(int fd); 67 68 private: 69 int fd_ = -1; 70 }; 71 } // namespace OHOS 72 #endif // OHOS_IPC_IPC_FILE_DESCRIPTOR_H 73