Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 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 | |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 5 | #ifndef CROS_DISKS_SERVER_IMPL_H_ |
| 6 | #define CROS_DISKS_SERVER_IMPL_H_ |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 11 | #include "cros-disks/cros-disks-server.h" |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame^] | 12 | #include "cros-disks/device-event-queue.h" |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 13 | #include "cros-disks/disk.h" |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame^] | 14 | #include "cros-disks/power-manager-observer.h" |
| 15 | #include "cros-disks/session-manager-observer.h" |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 16 | |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 17 | namespace cros_disks { |
| 18 | |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame^] | 19 | class DeviceEvent; |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 20 | class DiskManager; |
| 21 | |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 22 | // The d-bus server for the cros-disks daemon. |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 23 | // |
| 24 | // Example Usage: |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 25 | // |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 26 | // DBus::Connection server_conn = DBus::Connection::SystemBus(); |
| 27 | // server_conn.request_name("org.chromium.CrosDisks"); |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 28 | // DiskManager manager; |
| 29 | // CrosDisksServer* server = new(std::nothrow) CrosDisksServer(server_conn, |
| 30 | // &manager); |
| 31 | // |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 32 | // At this point the server should be attached to the main loop. |
| 33 | // |
| 34 | class CrosDisksServer : public org::chromium::CrosDisks_adaptor, |
| 35 | public DBus::IntrospectableAdaptor, |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame^] | 36 | public DBus::ObjectAdaptor, |
| 37 | public PowerManagerObserver, |
| 38 | public SessionManagerObserver { |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 39 | public: |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame^] | 40 | CrosDisksServer(DBus::Connection& connection, // NOLINT |
| 41 | DiskManager* disk_manager); |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 42 | virtual ~CrosDisksServer(); |
| 43 | |
| 44 | // A method for checking if the daemon is running. Always returns true. |
| 45 | virtual bool IsAlive(DBus::Error& error); // NOLINT |
| 46 | |
| 47 | // Unmounts a device when invoked. |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 48 | virtual void FilesystemUnmount(const std::string& device_path, |
| 49 | const std::vector<std::string>& mount_options, |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 50 | DBus::Error& error); // NOLINT |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 51 | |
| 52 | // Mounts a device when invoked. |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 53 | virtual std::string FilesystemMount(const std::string& device_path, |
| 54 | const std::string& filesystem_type, |
| 55 | const std::vector<std::string>& mount_options, |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 56 | DBus::Error& error); // NOLINT |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 57 | |
Ben Chan | 490319f | 2011-05-06 14:00:42 -0700 | [diff] [blame] | 58 | // Returns a list of device sysfs paths for all disk devices attached to |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 59 | // the system. |
Ben Chan | 490319f | 2011-05-06 14:00:42 -0700 | [diff] [blame] | 60 | virtual std::vector<std::string> EnumerateDevices( |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 61 | DBus::Error& error); // NOLINT |
Ben Chan | 490319f | 2011-05-06 14:00:42 -0700 | [diff] [blame] | 62 | |
| 63 | // Returns a list of device sysfs paths for all auto-mountable disk devices |
| 64 | // attached to the system. Currently, all external disk devices, which are |
| 65 | // neither on the boot device nor virtual, are considered auto-mountable. |
| 66 | virtual std::vector<std::string> EnumerateAutoMountableDevices( |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 67 | DBus::Error& error); // NOLINT |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 68 | |
| 69 | // Returns properties of a disk device attached to the system. |
| 70 | virtual DBusDisk GetDeviceProperties(const std::string& device_path, |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 71 | DBus::Error& error); // NOLINT |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 72 | |
| 73 | // Emits appropriate DBus signals notifying device changes. |
| 74 | void SignalDeviceChanges(); |
| 75 | |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame^] | 76 | // Implements the PowerManagerObserver interface to handle the event |
| 77 | // when the screen is locked. |
| 78 | virtual void OnScreenIsLocked(); |
| 79 | |
| 80 | // Implements the PowerManagerObserver interface to handle the event |
| 81 | // when the screen is unlocked. |
| 82 | virtual void OnScreenIsUnlocked(); |
| 83 | |
| 84 | // Implements the SessionManagerObserver interface to handle the event |
| 85 | // when the session has been started. |
| 86 | virtual void OnSessionStarted(const std::string& user); |
| 87 | |
| 88 | // Implements the SessionManagerObserver interface to handle the event |
| 89 | // when the session has been stopped. |
| 90 | virtual void OnSessionStopped(const std::string& user); |
| 91 | |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 92 | private: |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame^] | 93 | // Dispatches a device event by emitting the corresponding D-Bus signal. |
| 94 | void DispatchDeviceEvent(const DeviceEvent& event); |
| 95 | |
| 96 | // Dispatches all queued device events by emitting the corresponding |
| 97 | // D-Bus signals. |
| 98 | void DispatchQueuedDeviceEvents(); |
| 99 | |
Ben Chan | 490319f | 2011-05-06 14:00:42 -0700 | [diff] [blame] | 100 | // Returns a list of device sysfs paths for all disk devices attached to |
| 101 | // the system. If auto_mountable_only is true, only auto-mountable disk |
| 102 | // devices are returned. |
| 103 | std::vector<std::string> DoEnumerateDevices(bool auto_mountable_only) const; |
| 104 | |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame^] | 105 | // A list of deferred disk events to be fired. |
| 106 | DeviceEventQueue device_event_queue_; |
| 107 | |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 108 | DiskManager* disk_manager_; |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame^] | 109 | |
| 110 | // This variable is set to true if any new device event should be queued |
| 111 | // instead of being dispatched immediately. |
| 112 | bool is_device_event_queued_; |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 113 | }; |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 114 | |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 115 | } // namespace cros_disks |
| 116 | |
| 117 | #endif // CROS_DISKS_SERVER_IMPL_H_ |