aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;