summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHoward Chen <howardsoc@google.com>2017-11-09 13:58:28 +0800
committerHoward Chen <howardsoc@google.com>2017-11-13 13:54:03 +0800
commit8e42f5ae87e907e353fa8d094013b9431a9b8cda (patch)
tree126a08fffd2cefe17497177a211bfa6259ad4e4b
parent30b8a425aba4190fe3b7090393b80945121f2e02 (diff)
downloadlibhidl-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
-rw-r--r--base/HidlSupport.cpp13
-rw-r--r--base/include/hidl/HidlSupport.h13
2 files changed, 18 insertions, 8 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();
diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h
index e60f2f3..486fd0a 100644
--- a/base/include/hidl/HidlSupport.h
+++ b/base/include/hidl/HidlSupport.h
@@ -295,23 +295,22 @@ private:
// to support other type of hidl_memory without break the ABI.
class HidlMemory : public virtual hidl_memory, public virtual ::android::RefBase {
public:
+ static sp<HidlMemory> getInstance(const hidl_memory& mem);
+
static sp<HidlMemory> getInstance(hidl_memory&& mem);
static sp<HidlMemory> getInstance(const hidl_string& name, hidl_handle&& handle, uint64_t size);
// @param fd, shall be opened and points to the resource.
// @note this method takes the ownership of the fd and will close it in
// destructor
+ // @return nullptr in failure with the fd closed
static sp<HidlMemory> getInstance(const hidl_string& name, int fd, uint64_t size);
virtual ~HidlMemory();
+
protected:
- HidlMemory() : hidl_memory() {}
- HidlMemory(const hidl_string& name, hidl_handle&& handle, size_t size)
- : hidl_memory(name, std::move(handle), size) {}
- HidlMemory& operator=(hidl_memory&& src) {
- hidl_memory::operator=(src);
- return *this;
- }
+ HidlMemory();
+ HidlMemory(const hidl_string& name, hidl_handle&& handle, size_t size);
};
////////////////////////////////////////////////////////////////////////////////