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_LIST_ENTRY_H_
6 #define LIBBRILLO_BRILLO_UDEV_UDEV_LIST_ENTRY_H_
7 
8 #include <memory>
9 
10 #include <base/macros.h>
11 #include <brillo/brillo_export.h>
12 
13 struct udev_list_entry;
14 
15 namespace brillo {
16 
17 // A udev list entry, which wraps a udev_list_entry C struct from libudev and
18 // related library functions into a C++ object.
19 class BRILLO_EXPORT UdevListEntry {
20  public:
21   // Constructs a UdevListEntry object by taking a raw pointer to a
22   // udev_list_entry struct as |list_entry|. The ownership of |list_entry| is
23   // not transferred, and thus it should outlive this object.
24   explicit UdevListEntry(udev_list_entry* list_entry);
25 
26   virtual ~UdevListEntry() = default;
27 
28   // Wraps udev_list_entry_get_next().
29   virtual std::unique_ptr<UdevListEntry> GetNext() const;
30 
31   // Wraps udev_list_entry_get_by_name().
32   virtual std::unique_ptr<UdevListEntry> GetByName(const char* name) const;
33 
34   // Wraps udev_list_entry_get_name().
35   virtual const char* GetName() const;
36 
37   // Wraps udev_list_entry_get_value().
38   virtual const char* GetValue() const;
39 
40  private:
41   // Allows MockUdevListEntry to invoke the private default constructor below.
42   friend class MockUdevListEntry;
43 
44   // Constructs a UdevListEntry object without referencing a udev_list_entry
45   // struct, which is only allowed to be called by MockUdevListEntry.
46   UdevListEntry();
47 
48   udev_list_entry* const list_entry_;
49 
50   DISALLOW_COPY_AND_ASSIGN(UdevListEntry);
51 };
52 
53 }  // namespace brillo
54 
55 #endif  // LIBBRILLO_BRILLO_UDEV_UDEV_LIST_ENTRY_H_
56