OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 DISK_MANAGER_H__ |
| 6 #define DISK_MANAGER_H__ |
| 7 |
| 8 #include <libudev.h> |
| 9 #include <vector> |
| 10 |
| 11 namespace cros_disks { |
| 12 |
| 13 class Disk; |
| 14 |
| 15 // The DiskManager is responsible for reading device state from udev. |
| 16 // Said changes could be the result of a udev notification or a synchronous |
| 17 // call to enumerate the relevant storage devices attached to the system. |
| 18 // |
| 19 // Sample Usage: |
| 20 // |
| 21 // DiskManager manager; |
| 22 // manager.EnumerateDisks(); |
| 23 // select(manager.udev_monitor_fd())... |
| 24 // |
| 25 // This class is designed to run within a single-threaded GMainLoop application |
| 26 // and should not be considered thread safe. |
| 27 class DiskManager { |
| 28 public: |
| 29 DiskManager(); |
| 30 virtual ~DiskManager(); |
| 31 |
| 32 // Lists the current block devices attached to the system. |
| 33 virtual std::vector<Disk> EnumerateDisks(); |
| 34 |
| 35 // Reads the changes from udev. Must be called to clear the |
| 36 // fd. |
| 37 bool ProcessUdevChanges(); |
| 38 |
| 39 // A file descriptor that can be select()ed or poll()ed for system changes. |
| 40 int udev_monitor_fd() const { return udev_monitor_fd_; } |
| 41 |
| 42 private: |
| 43 |
| 44 // The root udev object. |
| 45 struct udev* udev_; |
| 46 |
| 47 // Provides access to udev changes as they occur. |
| 48 struct udev_monitor* udev_monitor_; |
| 49 |
| 50 // A file descriptor that indicates changes to the system. |
| 51 int udev_monitor_fd_; |
| 52 }; |
| 53 |
| 54 } // namespace cros_disks |
| 55 |
| 56 #endif // DISK_MANAGER_H__ |
OLD | NEW |