1 #ifndef ANDROID_DVR_BUFFER_HUB_QUEUE_PARCELABLE_H_
2 #define ANDROID_DVR_BUFFER_HUB_QUEUE_PARCELABLE_H_
3 
4 #if defined(__clang__)
5 #pragma clang diagnostic push
6 #pragma clang diagnostic ignored "-Weverything"
7 #endif
8 
9 // The following headers are included without checking every warning.
10 // TODO(b/72172820): Remove the workaround once we have enforced -Weverything
11 // in these headers and their dependencies.
12 #include <pdx/channel_parcelable.h>
13 
14 #if defined(__clang__)
15 #pragma clang diagnostic pop
16 #endif
17 
18 namespace android {
19 namespace dvr {
20 
21 enum BufferHubQueueParcelableMagic : uint32_t {
22   Producer = 0x62687170,  // 'bhqp'
23   Consumer = 0x62687163,  // 'bhqc'
24 };
25 
26 template <BufferHubQueueParcelableMagic Magic>
27 class BufferHubQueueParcelable : public Parcelable {
28  public:
29   BufferHubQueueParcelable() = default;
30 
31   BufferHubQueueParcelable(BufferHubQueueParcelable&& other) noexcept = default;
32   BufferHubQueueParcelable& operator=(BufferHubQueueParcelable&& other) noexcept {
33     channel_parcelable_ = std::move(other.channel_parcelable_);
34     return *this;
35   }
36 
37   // Constructs an parcelable contains the channel parcelable.
BufferHubQueueParcelable(std::unique_ptr<pdx::ChannelParcelable> channel_parcelable)38   explicit BufferHubQueueParcelable(
39       std::unique_ptr<pdx::ChannelParcelable> channel_parcelable)
40       : channel_parcelable_(std::move(channel_parcelable)) {}
41 
42   BufferHubQueueParcelable(const BufferHubQueueParcelable&) = delete;
43   void operator=(const BufferHubQueueParcelable&) = delete;
44 
45   bool IsValid() const;
46 
47   // Returns a channel handle constructed from this parcelable object and takes
48   // the ownership of all resources from the parcelable object.
49   pdx::LocalChannelHandle TakeChannelHandle();
50 
51   // Serializes the queue parcelable into the given parcel. Note that no system
52   // resources are getting duplicated, nor did the parcel takes ownership of the
53   // queue parcelable. Thus, the parcelable object must remain valid for the
54   // lifetime of the parcel.
55   status_t writeToParcel(Parcel* parcel) const override;
56 
57   // Deserialize the queue parcelable from the given parcel. Note that system
58   // resources are duplicated from the parcel into the queue parcelable. Returns
59   // error if the targeting parcelable object is already valid.
60   status_t readFromParcel(const Parcel* parcel) override;
61 
62  private:
63   std::unique_ptr<pdx::ChannelParcelable> channel_parcelable_;
64 };
65 
66 using ProducerQueueParcelable =
67     BufferHubQueueParcelable<BufferHubQueueParcelableMagic::Producer>;
68 using ConsumerQueueParcelable =
69     BufferHubQueueParcelable<BufferHubQueueParcelableMagic::Consumer>;
70 
71 }  // namespace dvr
72 }  // namespace android
73 
74 #endif  // ANDROID_DVR_BUFFER_HUB_QUEUE_PARCELABLE_H_
75