• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef ANDROID_DETACHED_BUFFER_HUB_HANDLE_H
17 #define ANDROID_DETACHED_BUFFER_HUB_HANDLE_H
18 #include <pdx/channel_handle.h>
19 #include <memory>
20 namespace android {
21 // A wrapper that holds a pdx::LocalChannelHandle object. From the handle, a BufferHub buffer can be
22 // created. Current implementation assumes that the underlying transport is using libpdx (thus
23 // holding a pdx::LocalChannelHandle object), but future implementation can change it to a Binder
24 // backend if ever needed.
25 class DetachedBufferHandle {
26 public:
Create(pdx::LocalChannelHandle handle)27     static std::unique_ptr<DetachedBufferHandle> Create(pdx::LocalChannelHandle handle) {
28         return std::unique_ptr<DetachedBufferHandle>(new DetachedBufferHandle(std::move(handle)));
29     }
30     // Accessors to get or take the internal pdx::LocalChannelHandle.
handle()31     pdx::LocalChannelHandle& handle() { return mHandle; }
handle()32     const pdx::LocalChannelHandle& handle() const { return mHandle; }
33     // Returns whether the DetachedBufferHandle holds a BufferHub channel.
isValid()34     bool isValid() const { return mHandle.valid(); }
35 private:
36     // Constructs a DetachedBufferHandle from a pdx::LocalChannelHandle.
DetachedBufferHandle(pdx::LocalChannelHandle handle)37     explicit DetachedBufferHandle(pdx::LocalChannelHandle handle) : mHandle(std::move(handle)) {}
38     pdx::LocalChannelHandle mHandle;
39 };
40 } // namespace android
41 #endif // ANDROID_DETACHED_BUFFER_HUB_HANDLE_H
42