summaryrefslogtreecommitdiff
path: root/services/bufferhub/BufferHubService.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'services/bufferhub/BufferHubService.cpp')
-rw-r--r--services/bufferhub/BufferHubService.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/services/bufferhub/BufferHubService.cpp b/services/bufferhub/BufferHubService.cpp
index b72b556c6e..3bfd9cbe7e 100644
--- a/services/bufferhub/BufferHubService.cpp
+++ b/services/bufferhub/BufferHubService.cpp
@@ -16,6 +16,7 @@
#include <android/hardware_buffer.h>
#include <bufferhub/BufferHubService.h>
+#include <cutils/native_handle.h>
#include <log/log.h>
namespace android {
@@ -41,7 +42,7 @@ Return<void> BufferHubService::allocateBuffer(const HardwareBufferDescription& d
return Void();
}
- sp<BufferClient> client = new BufferClient(node);
+ sp<BufferClient> client = BufferClient::create(this, node);
// Add it to list for bookkeeping and dumpsys.
std::lock_guard<std::mutex> lock(mClientListMutex);
mClientList.push_back(client);
@@ -57,6 +58,25 @@ Return<void> BufferHubService::importBuffer(const hidl_handle& /*nativeHandle*/,
return Void();
}
+hidl_handle BufferHubService::registerToken(const BufferClient* client) {
+ uint32_t token;
+ std::lock_guard<std::mutex> lock(mTokenMapMutex);
+ do {
+ token = mTokenEngine();
+ } while (mTokenMap.find(token) != mTokenMap.end());
+
+ // native_handle_t use int[], so here need one slots to fit in uint32_t
+ native_handle_t* handle = native_handle_create(/*numFds=*/0, /*numInts=*/1);
+ handle->data[0] = token;
+
+ // returnToken owns the native_handle_t* thus doing lifecycle management
+ hidl_handle returnToken;
+ returnToken.setTo(handle, /*shoudOwn=*/true);
+
+ mTokenMap.emplace(token, client);
+ return returnToken;
+}
+
} // namespace implementation
} // namespace V1_0
} // namespace bufferhub