Home | History | Annotate | Download | only in binder
      1 /*
      2  * Copyright (C) 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef ANDROID_PARCEL_FILE_DESCRIPTOR_H_
     18 #define ANDROID_PARCEL_FILE_DESCRIPTOR_H_
     19 
     20 #include <android-base/unique_fd.h>
     21 #include <binder/Parcel.h>
     22 #include <binder/Parcelable.h>
     23 
     24 namespace android {
     25 namespace os {
     26 
     27 /*
     28  * C++ implementation of the Java class android.os.ParcelFileDescriptor
     29  */
     30 class ParcelFileDescriptor : public android::Parcelable {
     31 public:
     32     ParcelFileDescriptor();
     33     explicit ParcelFileDescriptor(android::base::unique_fd fd);
     34     ParcelFileDescriptor(ParcelFileDescriptor&& other) : mFd(std::move(other.mFd)) { }
     35     ~ParcelFileDescriptor() override;
     36 
     37     int get() const { return mFd.get(); }
     38     android::base::unique_fd release() { return std::move(mFd); }
     39     void reset(android::base::unique_fd fd = android::base::unique_fd()) { mFd = std::move(fd); }
     40 
     41     // android::Parcelable override:
     42     android::status_t writeToParcel(android::Parcel* parcel) const override;
     43     android::status_t readFromParcel(const android::Parcel* parcel) override;
     44 
     45 private:
     46     android::base::unique_fd mFd;
     47 };
     48 
     49 } // namespace os
     50 } // namespace android
     51 
     52 #endif // ANDROID_OS_PARCEL_FILE_DESCRIPTOR_H_
     53