aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Caruso <ejcaruso@chromium.org>2019-09-26 11:44:14 -0700
committerCommit Bot <commit-bot@chromium.org>2019-10-25 17:57:18 +0000
commitb53333d25be58ca9d9803423f0ab0ec75079d345 (patch)
tree9df38448dba8731b3b57eed9226a88533781c275
parent56bdf2c0dff03c6fa28907b2f17dc09e4b77a955 (diff)
downloadplatform_external_libbrillo-b53333d25be58ca9d9803423f0ab0ec75079d345.tar.gz
platform_external_libbrillo-b53333d25be58ca9d9803423f0ab0ec75079d345.tar.bz2
platform_external_libbrillo-b53333d25be58ca9d9803423f0ab0ec75079d345.zip
libbrillo: add UdevDevice::Clone
UdevDevice does not allow access to the underlying libudev struct, so give another way to copy UdevDevice objects. BUG=chromium:986484 TEST=build, upcoming UdevWatcher changes Change-Id: Ibe6d0ccd23e663e6e893312d42968701d2044d58 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/1827463 Tested-by: Eric Caruso <ejcaruso@chromium.org> Commit-Queue: Eric Caruso <ejcaruso@chromium.org> Reviewed-by: Anand Mistry <amistry@chromium.org> Cr-Mirrored-From: https://chromium.googlesource.com/chromiumos/platform2 Cr-Mirrored-Commit: 4f80108567894cbcab38b877476be041f77f56a0
-rw-r--r--brillo/udev/mock_udev_device.h1
-rw-r--r--brillo/udev/udev_device.cc4
-rw-r--r--brillo/udev/udev_device.h4
3 files changed, 9 insertions, 0 deletions
diff --git a/brillo/udev/mock_udev_device.h b/brillo/udev/mock_udev_device.h
index 9e0c2ef..6e812d1 100644
--- a/brillo/udev/mock_udev_device.h
+++ b/brillo/udev/mock_udev_device.h
@@ -57,6 +57,7 @@ class BRILLO_EXPORT MockUdevDevice : public UdevDevice {
GetSysAttributeValue,
(const char*),
(const, override));
+ MOCK_METHOD(std::unique_ptr<UdevDevice>, Clone, (), (override));
private:
DISALLOW_COPY_AND_ASSIGN(MockUdevDevice);
diff --git a/brillo/udev/udev_device.cc b/brillo/udev/udev_device.cc
index b84fa36..2251699 100644
--- a/brillo/udev/udev_device.cc
+++ b/brillo/udev/udev_device.cc
@@ -121,4 +121,8 @@ const char* UdevDevice::GetSysAttributeValue(const char* attribute) const {
return udev_device_get_sysattr_value(device_, attribute);
}
+std::unique_ptr<UdevDevice> UdevDevice::Clone() {
+ return std::make_unique<UdevDevice>(device_);
+}
+
} // namespace brillo
diff --git a/brillo/udev/udev_device.h b/brillo/udev/udev_device.h
index 1f942a8..2704a22 100644
--- a/brillo/udev/udev_device.h
+++ b/brillo/udev/udev_device.h
@@ -95,6 +95,10 @@ class BRILLO_EXPORT UdevDevice {
// Wraps udev_device_get_sysattr_value().
virtual const char* GetSysAttributeValue(const char* attribute) const;
+ // Creates a copy of this UdevDevice pointing to the same underlying
+ // struct udev_device* (increasing its libudev reference count by 1).
+ virtual std::unique_ptr<UdevDevice> Clone();
+
private:
// Allows MockUdevDevice to invoke the private default constructor below.
friend class MockUdevDevice;