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 #include "disk-manager.h" |
| 6 |
| 7 #include "disk.h" |
| 8 |
| 9 #include <base/logging.h> |
| 10 #include <libudev.h> |
| 11 #include <vector> |
| 12 |
| 13 |
| 14 namespace cros_disks { |
| 15 |
| 16 DiskManager::DiskManager() |
| 17 : udev_(udev_new()), |
| 18 udev_monitor_fd_(0) { |
| 19 |
| 20 CHECK(udev_) << "Failed to initialize udev"; |
| 21 udev_monitor_ = udev_monitor_new_from_netlink(udev_, "udev"); |
| 22 udev_monitor_filter_add_match_subsystem_devtype(udev_monitor_, "block", NULL); |
| 23 udev_monitor_enable_receiving(udev_monitor_); |
| 24 udev_monitor_fd_ = udev_monitor_get_fd(udev_monitor_); |
| 25 } |
| 26 |
| 27 DiskManager::~DiskManager() { |
| 28 udev_monitor_unref(udev_monitor_); |
| 29 udev_unref(udev_); |
| 30 } |
| 31 |
| 32 std::vector<Disk> DiskManager::EnumerateDisks() { |
| 33 //TODO(rtc): implement this... |
| 34 std::vector<Disk> disks; |
| 35 return disks; |
| 36 } |
| 37 |
| 38 bool DiskManager::ProcessUdevChanges() { |
| 39 struct udev_device *dev = udev_monitor_receive_device(udev_monitor_); |
| 40 CHECK(dev) << "Unknown udev device"; |
| 41 LOG(INFO) << "Got Device"; |
| 42 LOG(INFO) << " Node: " << udev_device_get_devnode(dev); |
| 43 LOG(INFO) << " Subsystem: " << udev_device_get_subsystem(dev); |
| 44 LOG(INFO) << " Devtype: " << udev_device_get_devtype(dev); |
| 45 LOG(INFO) << " Action: " << udev_device_get_action(dev); |
| 46 udev_device_unref(dev); |
| 47 return true; |
| 48 } |
| 49 |
| 50 } // namespace cros_disks |
OLD | NEW |