1*1a96fba6SXin Li // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 2*1a96fba6SXin Li // Use of this source code is governed by a BSD-style license that can be 3*1a96fba6SXin Li // found in the LICENSE file. 4*1a96fba6SXin Li 5*1a96fba6SXin Li #ifndef LIBBRILLO_BRILLO_UDEV_UDEV_DEVICE_H_ 6*1a96fba6SXin Li #define LIBBRILLO_BRILLO_UDEV_UDEV_DEVICE_H_ 7*1a96fba6SXin Li 8*1a96fba6SXin Li #include <stdint.h> 9*1a96fba6SXin Li #include <sys/types.h> 10*1a96fba6SXin Li 11*1a96fba6SXin Li #include <memory> 12*1a96fba6SXin Li 13*1a96fba6SXin Li #include <base/macros.h> 14*1a96fba6SXin Li #include <brillo/brillo_export.h> 15*1a96fba6SXin Li #include <brillo/udev/udev_list_entry.h> 16*1a96fba6SXin Li 17*1a96fba6SXin Li struct udev_device; 18*1a96fba6SXin Li 19*1a96fba6SXin Li namespace brillo { 20*1a96fba6SXin Li 21*1a96fba6SXin Li // A udev device, which wraps a udev_device C struct from libudev and related 22*1a96fba6SXin Li // library functions into a C++ object. 23*1a96fba6SXin Li class BRILLO_EXPORT UdevDevice { 24*1a96fba6SXin Li public: 25*1a96fba6SXin Li // Constructs a UdevDevice object by taking a raw pointer to a udev_device 26*1a96fba6SXin Li // struct as |device|. The ownership of |device| is not transferred, but its 27*1a96fba6SXin Li // reference count is increased by one during the lifetime of this object. 28*1a96fba6SXin Li explicit UdevDevice(udev_device* device); 29*1a96fba6SXin Li 30*1a96fba6SXin Li // Destructs this UdevDevice object and decreases the reference count of the 31*1a96fba6SXin Li // underlying udev_device struct by one. 32*1a96fba6SXin Li virtual ~UdevDevice(); 33*1a96fba6SXin Li 34*1a96fba6SXin Li // Wraps udev_device_get_parent(). 35*1a96fba6SXin Li virtual std::unique_ptr<UdevDevice> GetParent() const; 36*1a96fba6SXin Li 37*1a96fba6SXin Li // Wraps udev_device_get_parent_with_subsystem_devtype(). 38*1a96fba6SXin Li virtual std::unique_ptr<UdevDevice> GetParentWithSubsystemDeviceType( 39*1a96fba6SXin Li const char* subsystem, const char* device_type) const; 40*1a96fba6SXin Li 41*1a96fba6SXin Li // Wraps udev_device_get_is_initialized(). 42*1a96fba6SXin Li virtual bool IsInitialized() const; 43*1a96fba6SXin Li 44*1a96fba6SXin Li // Wraps udev_device_get_usec_since_initialized(). 45*1a96fba6SXin Li virtual uint64_t GetMicrosecondsSinceInitialized() const; 46*1a96fba6SXin Li 47*1a96fba6SXin Li // Wraps udev_device_get_seqnum(). 48*1a96fba6SXin Li virtual uint64_t GetSequenceNumber() const; 49*1a96fba6SXin Li 50*1a96fba6SXin Li // Wraps udev_device_get_devpath(). 51*1a96fba6SXin Li virtual const char* GetDevicePath() const; 52*1a96fba6SXin Li 53*1a96fba6SXin Li // Wraps udev_device_get_devnode(). 54*1a96fba6SXin Li virtual const char* GetDeviceNode() const; 55*1a96fba6SXin Li 56*1a96fba6SXin Li // Wraps udev_device_get_devnum(). 57*1a96fba6SXin Li virtual dev_t GetDeviceNumber() const; 58*1a96fba6SXin Li 59*1a96fba6SXin Li // Wraps udev_device_get_devtype(). 60*1a96fba6SXin Li virtual const char* GetDeviceType() const; 61*1a96fba6SXin Li 62*1a96fba6SXin Li // Wraps udev_device_get_driver(). 63*1a96fba6SXin Li virtual const char* GetDriver() const; 64*1a96fba6SXin Li 65*1a96fba6SXin Li // Wraps udev_device_get_subsystem(). 66*1a96fba6SXin Li virtual const char* GetSubsystem() const; 67*1a96fba6SXin Li 68*1a96fba6SXin Li // Wraps udev_device_get_syspath(). 69*1a96fba6SXin Li virtual const char* GetSysPath() const; 70*1a96fba6SXin Li 71*1a96fba6SXin Li // Wraps udev_device_get_sysname(). 72*1a96fba6SXin Li virtual const char* GetSysName() const; 73*1a96fba6SXin Li 74*1a96fba6SXin Li // Wraps udev_device_get_sysnum(). 75*1a96fba6SXin Li virtual const char* GetSysNumber() const; 76*1a96fba6SXin Li 77*1a96fba6SXin Li // Wraps udev_device_get_action(). 78*1a96fba6SXin Li virtual const char* GetAction() const; 79*1a96fba6SXin Li 80*1a96fba6SXin Li // Wraps udev_device_get_devlinks_list_entry(). 81*1a96fba6SXin Li virtual std::unique_ptr<UdevListEntry> GetDeviceLinksListEntry() const; 82*1a96fba6SXin Li 83*1a96fba6SXin Li // Wraps udev_device_get_properties_list_entry(). 84*1a96fba6SXin Li virtual std::unique_ptr<UdevListEntry> GetPropertiesListEntry() const; 85*1a96fba6SXin Li 86*1a96fba6SXin Li // Wraps udev_device_get_property_value(). 87*1a96fba6SXin Li virtual const char* GetPropertyValue(const char* key) const; 88*1a96fba6SXin Li 89*1a96fba6SXin Li // Wraps udev_device_get_tags_list_entry(). 90*1a96fba6SXin Li virtual std::unique_ptr<UdevListEntry> GetTagsListEntry() const; 91*1a96fba6SXin Li 92*1a96fba6SXin Li // Wraps udev_device_get_sysattr_list_entry(). 93*1a96fba6SXin Li virtual std::unique_ptr<UdevListEntry> GetSysAttributeListEntry() const; 94*1a96fba6SXin Li 95*1a96fba6SXin Li // Wraps udev_device_get_sysattr_value(). 96*1a96fba6SXin Li virtual const char* GetSysAttributeValue(const char* attribute) const; 97*1a96fba6SXin Li 98*1a96fba6SXin Li // Creates a copy of this UdevDevice pointing to the same underlying 99*1a96fba6SXin Li // struct udev_device* (increasing its libudev reference count by 1). 100*1a96fba6SXin Li virtual std::unique_ptr<UdevDevice> Clone(); 101*1a96fba6SXin Li 102*1a96fba6SXin Li private: 103*1a96fba6SXin Li // Allows MockUdevDevice to invoke the private default constructor below. 104*1a96fba6SXin Li friend class MockUdevDevice; 105*1a96fba6SXin Li 106*1a96fba6SXin Li // Constructs a UdevDevice object without referencing a udev_device struct, 107*1a96fba6SXin Li // which is only allowed to be called by MockUdevDevice. 108*1a96fba6SXin Li UdevDevice(); 109*1a96fba6SXin Li 110*1a96fba6SXin Li udev_device* device_; 111*1a96fba6SXin Li 112*1a96fba6SXin Li DISALLOW_COPY_AND_ASSIGN(UdevDevice); 113*1a96fba6SXin Li }; 114*1a96fba6SXin Li 115*1a96fba6SXin Li } // namespace brillo 116*1a96fba6SXin Li 117*1a96fba6SXin Li #endif // LIBBRILLO_BRILLO_UDEV_UDEV_DEVICE_H_ 118