diff options
| author | 2018-11-06 15:46:44 -0800 | |
|---|---|---|
| committer | 2018-11-14 10:30:23 -0800 | |
| commit | 18d90eaf05d8b3a21a68d84ebf23ea2326067aad (patch) | |
| tree | 38758cab65d3d634dd2c7fba1c2eb15c81a36fc3 /services/bufferhub/BufferClient.cpp | |
| parent | 1029443fa64b7f66c06188431c81745d7a14bacb (diff) | |
Implement duplicate buffer
Allow BufferClient to generate a opaque token in hidl_handle (i.e.
native_handle_t) format that could be used for IBufferHub::import.
The service will keep a mapping from token to client. Token comparison
is handled in BufferHubService.cpp, as it's opaque to the users.
Test: BufferHubBuffer_test (passed)
Bug: 118614157
Change-Id: Ie2b0b650dba90fe2ed2f8091dd88acb9768f261f
Diffstat (limited to 'services/bufferhub/BufferClient.cpp')
| -rw-r--r-- | services/bufferhub/BufferClient.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/services/bufferhub/BufferClient.cpp b/services/bufferhub/BufferClient.cpp index b3662b265b..37fd75fe80 100644 --- a/services/bufferhub/BufferClient.cpp +++ b/services/bufferhub/BufferClient.cpp @@ -15,6 +15,7 @@ */ #include <bufferhub/BufferClient.h> +#include <bufferhub/BufferHubService.h> #include <hidl/HidlSupport.h> namespace android { @@ -26,9 +27,34 @@ namespace implementation { using hardware::hidl_handle; using hardware::Void; +BufferClient* BufferClient::create(BufferHubService* service, + const std::shared_ptr<BufferNode>& node) { + if (!service) { + ALOGE("%s: service cannot be nullptr.", __FUNCTION__); + return nullptr; + } else if (!node) { + ALOGE("%s: node cannot be nullptr.", __FUNCTION__); + return nullptr; + } + return new BufferClient(service, node); +} + Return<void> BufferClient::duplicate(duplicate_cb _hidl_cb) { - // TODO(b/118614157): implement token generation and registration - _hidl_cb(/*token=*/hidl_handle(), /*status=*/BufferHubStatus::NO_ERROR); + if (!mBufferNode) { + // Should never happen + ALOGE("%s: node is missing.", __FUNCTION__); + _hidl_cb(/*token=*/hidl_handle(), /*status=*/BufferHubStatus::BUFFER_FREED); + return Void(); + } + + sp<BufferHubService> service = mService.promote(); + if (service == nullptr) { + // Should never happen. Kill the process. + LOG_FATAL("%s: service died.", __FUNCTION__); + } + + const hidl_handle token = service->registerToken(this); + _hidl_cb(/*token=*/token, /*status=*/BufferHubStatus::NO_ERROR); return Void(); } |