• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef LIBBRILLO_BRILLO_UDEV_UDEV_ENUMERATE_H_
6 #define LIBBRILLO_BRILLO_UDEV_UDEV_ENUMERATE_H_
7 
8 #include <memory>
9 
10 #include <base/macros.h>
11 #include <brillo/brillo_export.h>
12 #include <brillo/udev/udev_list_entry.h>
13 
14 struct udev_enumerate;
15 
16 namespace brillo {
17 
18 // A udev enumerate class, which wraps a udev_enumerate C struct from libudev
19 // and related library functions into a C++ object.
20 class BRILLO_EXPORT UdevEnumerate {
21  public:
22   // Constructs a UdevEnumerate object by taking a raw pointer to a
23   // udev_enumerate struct as |enumerate|. The ownership of |enumerate| is not
24   // transferred, but its reference count is increased by one during the
25   // lifetime of this object.
26   explicit UdevEnumerate(udev_enumerate* enumerate);
27 
28   // Destructs this UdevEnumerate object and decreases the reference count of
29   // the underlying udev_enumerate struct by one.
30   virtual ~UdevEnumerate();
31 
32   // Wraps udev_enumerate_add_match_subsystem(). Returns true on success.
33   virtual bool AddMatchSubsystem(const char* subsystem);
34 
35   // Wraps udev_enumerate_add_nomatch_subsystem(). Returns true on success.
36   virtual bool AddNoMatchSubsystem(const char* subsystem);
37 
38   // Wraps udev_enumerate_add_match_sysattr(). Returns true on success.
39   virtual bool AddMatchSysAttribute(const char* attribute, const char* value);
40 
41   // Wraps udev_enumerate_add_nomatch_sysattr(). Returns true on success.
42   virtual bool AddNoMatchSysAttribute(const char* attribute, const char* value);
43 
44   // Wraps udev_enumerate_add_match_property(). Returns true on success.
45   virtual bool AddMatchProperty(const char* property, const char* value);
46 
47   // Wraps udev_enumerate_add_match_sysname(). Returns true on success.
48   virtual bool AddMatchSysName(const char* sys_name);
49 
50   // Wraps udev_enumerate_add_match_tag(). Returns true on success.
51   virtual bool AddMatchTag(const char* tag);
52 
53   // Wraps udev_enumerate_add_match_is_initialized(). Returns true on success.
54   virtual bool AddMatchIsInitialized();
55 
56   // Wraps udev_enumerate_add_syspath(). Returns true on success.
57   virtual bool AddSysPath(const char* sys_path);
58 
59   // Wraps udev_enumerate_scan_devices(). Returns true on success.
60   virtual bool ScanDevices();
61 
62   // Wraps udev_enumerate_scan_subsystems(). Returns true on success.
63   virtual bool ScanSubsystems();
64 
65   // Wraps udev_enumerate_get_list_entry().
66   virtual std::unique_ptr<UdevListEntry> GetListEntry() const;
67 
68  private:
69   // Allows MockUdevEnumerate to invoke the private default constructor below.
70   friend class MockUdevEnumerate;
71 
72   // Constructs a UdevEnumerate object without referencing a udev_enumerate
73   // struct, which is only allowed to be called by MockUdevEnumerate.
74   UdevEnumerate();
75 
76   udev_enumerate* enumerate_;
77 
78   DISALLOW_COPY_AND_ASSIGN(UdevEnumerate);
79 };
80 
81 }  // namespace brillo
82 
83 #endif  // LIBBRILLO_BRILLO_UDEV_UDEV_ENUMERATE_H_
84