1 #ifndef ANDROID_DVR_HARDWARE_COMPOSER_AIDL_ANDROID_DVR_PARCELABLE_UNIQUE_FD_H 2 #define ANDROID_DVR_HARDWARE_COMPOSER_AIDL_ANDROID_DVR_PARCELABLE_UNIQUE_FD_H 3 4 #include <android-base/unique_fd.h> 5 #include <binder/Parcelable.h> 6 7 namespace android { 8 namespace dvr { 9 10 // Provide a wrapper to serialized base::unique_fd. The wrapper also handles the 11 // case where the FD is invalid (-1), unlike FileDescriptor which expects a 12 // valid FD. 13 class ParcelableUniqueFd : public Parcelable { 14 public: 15 ParcelableUniqueFd(); 16 explicit ParcelableUniqueFd(const base::unique_fd& fence); 17 ~ParcelableUniqueFd() override; 18 set_fence(const base::unique_fd & fence)19 void set_fence(const base::unique_fd& fence) { 20 fence_.reset(dup(fence.get())); 21 } fence()22 base::unique_fd fence() const { return base::unique_fd(dup(fence_.get())); } 23 24 status_t writeToParcel(Parcel* parcel) const override; 25 status_t readFromParcel(const Parcel* parcel) override; 26 27 private: 28 base::unique_fd fence_; 29 }; 30 31 } // namespace dvr 32 } // namespace android 33 34 #endif // ANDROID_DVR_HARDWARE_COMPOSER_AIDL_ANDROID_DVR_PARCELABLE_UNIQUE_FD_H 35