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 | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame] | 12 | #include "cros-disks/device-event-dispatcher-interface.h" |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 13 | #include "cros-disks/device-event-queue.h" |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 14 | #include "cros-disks/disk.h" |
Ben Chan | c1e766c | 2011-11-21 12:56:59 -0800 | [diff] [blame] | 15 | #include "cros-disks/format-manager-observer-interface.h" |
Ben Chan | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame] | 16 | #include "cros-disks/session-manager-observer-interface.h" |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 17 | |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 18 | namespace cros_disks { |
| 19 | |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 20 | class DiskManager; |
Szymon Sidor | 2733b51 | 2011-06-30 18:00:51 -0700 | [diff] [blame] | 21 | class FormatManager; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 22 | class MountManager; |
| 23 | class Platform; |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 24 | |
Ben Chan | 2a5ea75 | 2011-12-21 09:48:19 -0800 | [diff] [blame] | 25 | struct DeviceEvent; |
| 26 | |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 27 | // The d-bus server for the cros-disks daemon. |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 28 | // |
| 29 | // Example Usage: |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 30 | // |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 31 | // DBus::Connection server_conn = DBus::Connection::SystemBus(); |
| 32 | // server_conn.request_name("org.chromium.CrosDisks"); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 33 | // ArchiveManager archive_manager(...); |
| 34 | // DiskManager disk_manager(...); |
Szymon Sidor | 2733b51 | 2011-06-30 18:00:51 -0700 | [diff] [blame] | 35 | // FormatManager format_manager; |
| 36 | // CrosDisksServer* server = new(std::nothrow) |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 37 | // CrosDisksServer(server_conn, &platform, |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 38 | // &disk_manager, &format_manager); |
Ben Chan | f47fc35 | 2013-05-03 11:28:57 -0700 | [diff] [blame^] | 39 | // server.RegisterMountManager(&disk_manager); |
| 40 | // server.RegisterMountManager(&archive_manager); |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 41 | // |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 42 | // At this point the server should be attached to the main loop. |
| 43 | // |
| 44 | class CrosDisksServer : public org::chromium::CrosDisks_adaptor, |
| 45 | public DBus::IntrospectableAdaptor, |
Ben Chan | b092d75 | 2011-07-13 11:44:38 -0700 | [diff] [blame] | 46 | public DBus::PropertiesAdaptor, |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 47 | public DBus::ObjectAdaptor, |
Ben Chan | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame] | 48 | public DeviceEventDispatcherInterface, |
Ben Chan | c1e766c | 2011-11-21 12:56:59 -0800 | [diff] [blame] | 49 | public FormatManagerObserverInterface, |
Ben Chan | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame] | 50 | public SessionManagerObserverInterface { |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 51 | public: |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 52 | CrosDisksServer(DBus::Connection& connection, // NOLINT |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 53 | Platform* platform, |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 54 | DiskManager* disk_manager, |
| 55 | FormatManager* format_manager); |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 56 | virtual ~CrosDisksServer(); |
| 57 | |
Ben Chan | f47fc35 | 2013-05-03 11:28:57 -0700 | [diff] [blame^] | 58 | // Registers a mount manager. |
| 59 | void RegisterMountManager(MountManager* mount_manager); |
| 60 | |
Ben Chan | c1e766c | 2011-11-21 12:56:59 -0800 | [diff] [blame] | 61 | // A method for formatting a device specified by |path|. |
| 62 | // On completion, a FormatCompleted signal is emitted to indicate whether |
| 63 | // the operation succeeded or failed using a FormatErrorType enum value. |
| 64 | virtual void Format(const std::string& path, |
| 65 | const std::string& filesystem_type, |
| 66 | const std::vector<std::string>& options, |
| 67 | DBus::Error& error); // NOLINT |
Szymon Sidor | 2733b51 | 2011-06-30 18:00:51 -0700 | [diff] [blame] | 68 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 69 | // A method for asynchronous formatting device using specified file system. |
| 70 | // Assumes device path is valid (should it be invalid singal |
Szymon Sidor | 2733b51 | 2011-06-30 18:00:51 -0700 | [diff] [blame] | 71 | // FormattingFinished(false) will be sent) |
| 72 | // Return true if formatting is successfully INITIALIZED, rather than finished |
| 73 | virtual bool FormatDevice(const std::string& device_path, |
| 74 | const std::string& filesystem, ::DBus::Error &error); // NOLINT |
| 75 | |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 76 | // A method for checking if the daemon is running. Always returns true. |
| 77 | virtual bool IsAlive(DBus::Error& error); // NOLINT |
| 78 | |
Ben Chan | d3fdc72 | 2011-07-21 18:15:22 -0700 | [diff] [blame] | 79 | // Mounts a path when invoked. |
| 80 | virtual void Mount(const std::string& path, |
| 81 | const std::string& filesystem_type, |
| 82 | const std::vector<std::string>& options, |
| 83 | DBus::Error& error); // NOLINT |
| 84 | |
| 85 | // Unmounts a path when invoked. |
| 86 | virtual void Unmount(const std::string& path, |
| 87 | const std::vector<std::string>& options, |
| 88 | DBus::Error& error); // NOLINT |
| 89 | |
Ben Chan | 8f51376 | 2011-11-14 12:44:42 -0800 | [diff] [blame] | 90 | // Unmounts all paths mounted by Mount() when invoked. |
| 91 | virtual void UnmountAll(DBus::Error& error); // NOLINT |
| 92 | |
Ben Chan | 490319f | 2011-05-06 14:00:42 -0700 | [diff] [blame] | 93 | // 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] | 94 | // the system. |
Ben Chan | 490319f | 2011-05-06 14:00:42 -0700 | [diff] [blame] | 95 | virtual std::vector<std::string> EnumerateDevices( |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 96 | DBus::Error& error); // NOLINT |
Ben Chan | 490319f | 2011-05-06 14:00:42 -0700 | [diff] [blame] | 97 | |
| 98 | // Returns a list of device sysfs paths for all auto-mountable disk devices |
| 99 | // attached to the system. Currently, all external disk devices, which are |
| 100 | // neither on the boot device nor virtual, are considered auto-mountable. |
| 101 | virtual std::vector<std::string> EnumerateAutoMountableDevices( |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 102 | DBus::Error& error); // NOLINT |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 103 | |
| 104 | // Returns properties of a disk device attached to the system. |
| 105 | virtual DBusDisk GetDeviceProperties(const std::string& device_path, |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 106 | DBus::Error& error); // NOLINT |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 107 | |
Ben Chan | c1e766c | 2011-11-21 12:56:59 -0800 | [diff] [blame] | 108 | // Implements the FormatManagerObserverInterface interface to handle |
| 109 | // the event when a formatting operation has completed. |
| 110 | virtual void OnFormatCompleted(const std::string& device_path, |
| 111 | FormatErrorType error_type); |
| 112 | |
Ben Chan | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame] | 113 | // Implements the SessionManagerObserverInterface interface to handle |
Ben Chan | 5988f29 | 2012-09-18 08:32:42 -0700 | [diff] [blame] | 114 | // the event when the screen is locked. |
| 115 | virtual void OnScreenIsLocked(); |
| 116 | |
| 117 | // Implements the SessionManagerObserverInterface interface to handle |
| 118 | // the event when the screen is unlocked. |
| 119 | virtual void OnScreenIsUnlocked(); |
| 120 | |
| 121 | // Implements the SessionManagerObserverInterface interface to handle |
Ben Chan | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame] | 122 | // the event when the session has been started. |
Ben Chan | b3bf8d1 | 2013-04-23 13:57:55 -0700 | [diff] [blame] | 123 | virtual void OnSessionStarted(); |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 124 | |
Ben Chan | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame] | 125 | // Implements the SessionManagerObserverInterface interface to handle |
| 126 | // the event when the session has been stopped. |
Ben Chan | b3bf8d1 | 2013-04-23 13:57:55 -0700 | [diff] [blame] | 127 | virtual void OnSessionStopped(); |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 128 | |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 129 | private: |
Ben Chan | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame] | 130 | // Implements the DeviceEventDispatcherInterface to dispatch a device event |
| 131 | // by emitting the corresponding D-Bus signal. |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 132 | void DispatchDeviceEvent(const DeviceEvent& event); |
| 133 | |
Ben Chan | b092d75 | 2011-07-13 11:44:38 -0700 | [diff] [blame] | 134 | // Initializes DBus properties. |
| 135 | void InitializeProperties(); |
| 136 | |
| 137 | // Overrides PropertiesAdaptor::on_set_property to handle |
| 138 | // org.freedesktop.DBus.Properties.Set calls. |
| 139 | virtual void on_set_property(DBus::InterfaceAdaptor& interface, // NOLINT |
| 140 | const std::string& property, const DBus::Variant& value); |
| 141 | |
Ben Chan | 490319f | 2011-05-06 14:00:42 -0700 | [diff] [blame] | 142 | // Returns a list of device sysfs paths for all disk devices attached to |
| 143 | // the system. If auto_mountable_only is true, only auto-mountable disk |
| 144 | // devices are returned. |
| 145 | std::vector<std::string> DoEnumerateDevices(bool auto_mountable_only) const; |
| 146 | |
Ben Chan | 8f51376 | 2011-11-14 12:44:42 -0800 | [diff] [blame] | 147 | // Unmounts all paths mounted by Mount(). |
| 148 | void DoUnmountAll(); |
| 149 | |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 150 | Platform* platform_; |
| 151 | |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 152 | DiskManager* disk_manager_; |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 153 | |
Szymon Sidor | 2733b51 | 2011-06-30 18:00:51 -0700 | [diff] [blame] | 154 | FormatManager* format_manager_; |
| 155 | |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 156 | std::vector<MountManager*> mount_managers_; |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 157 | }; |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 158 | |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 159 | } // namespace cros_disks |
| 160 | |
| 161 | #endif // CROS_DISKS_SERVER_IMPL_H_ |