diff options
author | Howard Chen <howardsoc@google.com> | 2017-11-09 13:58:28 +0800 |
---|---|---|
committer | Howard Chen <howardsoc@google.com> | 2017-11-13 13:54:03 +0800 |
commit | 8e42f5ae87e907e353fa8d094013b9431a9b8cda (patch) | |
tree | 126a08fffd2cefe17497177a211bfa6259ad4e4b /base/HidlSupport.cpp | |
parent | 30b8a425aba4190fe3b7090393b80945121f2e02 (diff) | |
download | libhidl-8e42f5ae87e907e353fa8d094013b9431a9b8cda.tar.gz |
Refine HidlMemory
Add construct from a const hidl_memory& so that we can easily
copy it out of a synchronous callback
Bug: 67758915
Test: hidl_test
Change-Id: I0e10cc4c9321197787657f957ea184a5e7262744
Diffstat (limited to 'base/HidlSupport.cpp')
-rw-r--r-- | base/HidlSupport.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/base/HidlSupport.cpp b/base/HidlSupport.cpp index aec3fed..8f3c057 100644 --- a/base/HidlSupport.cpp +++ b/base/HidlSupport.cpp @@ -273,9 +273,15 @@ bool hidl_string::empty() const { return mSize == 0; } +sp<HidlMemory> HidlMemory::getInstance(const hidl_memory& mem) { + sp<HidlMemory> instance = new HidlMemory(); + instance->hidl_memory::operator=(mem); + return instance; +} + sp<HidlMemory> HidlMemory::getInstance(hidl_memory&& mem) { sp<HidlMemory> instance = new HidlMemory(); - *instance = std::move(mem); + instance->hidl_memory::operator=(std::move(mem)); return instance; } @@ -295,6 +301,11 @@ sp<HidlMemory> HidlMemory::getInstance(const hidl_string& name, int fd, uint64_t return instance; } +HidlMemory::HidlMemory() : hidl_memory() {} + +HidlMemory::HidlMemory(const hidl_string& name, hidl_handle&& handle, size_t size) + : hidl_memory(name, std::move(handle), size) {} + // it's required to have at least one out-of-line method to avoid weak vtable HidlMemory::~HidlMemory() { hidl_memory::~hidl_memory(); |