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 | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame^] | 15 | #include "cros-disks/power-manager-observer-interface.h" |
| 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 | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 20 | class ArchiveManager; |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 21 | class DeviceEvent; |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 22 | class DiskManager; |
Szymon Sidor | 2733b51 | 2011-06-30 18:00:51 -0700 | [diff] [blame] | 23 | class FormatManager; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 24 | class MountManager; |
| 25 | class Platform; |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 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, |
| 38 | // &archive_manager, |
| 39 | // &disk_manager, &format_manager); |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 40 | // |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 41 | // At this point the server should be attached to the main loop. |
| 42 | // |
| 43 | class CrosDisksServer : public org::chromium::CrosDisks_adaptor, |
| 44 | public DBus::IntrospectableAdaptor, |
Ben Chan | b092d75 | 2011-07-13 11:44:38 -0700 | [diff] [blame] | 45 | public DBus::PropertiesAdaptor, |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 46 | public DBus::ObjectAdaptor, |
Ben Chan | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame^] | 47 | public DeviceEventDispatcherInterface, |
| 48 | public SessionManagerObserverInterface { |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 49 | public: |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 50 | CrosDisksServer(DBus::Connection& connection, // NOLINT |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 51 | Platform* platform, |
| 52 | ArchiveManager* archive_manager, |
| 53 | DiskManager* disk_manager, |
| 54 | FormatManager* format_manager); |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 55 | virtual ~CrosDisksServer(); |
| 56 | |
Szymon Sidor | 2733b51 | 2011-06-30 18:00:51 -0700 | [diff] [blame] | 57 | // Called by FormatManager when the formatting is finished |
| 58 | virtual void SignalFormattingFinished(const std::string& device_path, |
| 59 | int status); |
| 60 | |
| 61 | // Returns filesystem of a device. In case of any error (unrecognised device, |
| 62 | // unrecognised file system returns empty string |
| 63 | virtual std::string GetDeviceFilesystem(const std::string& device_path, |
| 64 | ::DBus::Error &error); // NOLINT |
| 65 | |
| 66 | // A method for asynchronous formating device using specified file system. |
| 67 | // Assumes device path is vaild (should it be invaild singal |
| 68 | // FormattingFinished(false) will be sent) |
| 69 | // Return true if formatting is successfully INITIALIZED, rather than finished |
| 70 | virtual bool FormatDevice(const std::string& device_path, |
| 71 | const std::string& filesystem, ::DBus::Error &error); // NOLINT |
| 72 | |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 73 | // A method for checking if the daemon is running. Always returns true. |
| 74 | virtual bool IsAlive(DBus::Error& error); // NOLINT |
| 75 | |
Ben Chan | d3fdc72 | 2011-07-21 18:15:22 -0700 | [diff] [blame] | 76 | // TODO(benchan): Deprecate this method. |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 77 | // Unmounts a device when invoked. |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 78 | virtual void FilesystemUnmount(const std::string& device_path, |
| 79 | const std::vector<std::string>& mount_options, |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 80 | DBus::Error& error); // NOLINT |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 81 | |
Ben Chan | d3fdc72 | 2011-07-21 18:15:22 -0700 | [diff] [blame] | 82 | // Mounts a path when invoked. |
| 83 | virtual void Mount(const std::string& path, |
| 84 | const std::string& filesystem_type, |
| 85 | const std::vector<std::string>& options, |
| 86 | DBus::Error& error); // NOLINT |
| 87 | |
| 88 | // Unmounts a path when invoked. |
| 89 | virtual void Unmount(const std::string& path, |
| 90 | const std::vector<std::string>& options, |
| 91 | DBus::Error& error); // NOLINT |
| 92 | |
| 93 | // TODO(benchan): Deprecate this method. |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 94 | // Mounts a device when invoked. |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 95 | virtual std::string FilesystemMount(const std::string& device_path, |
| 96 | const std::string& filesystem_type, |
| 97 | const std::vector<std::string>& mount_options, |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 98 | DBus::Error& error); // NOLINT |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 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 |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 101 | // the system. |
Ben Chan | 490319f | 2011-05-06 14:00:42 -0700 | [diff] [blame] | 102 | virtual std::vector<std::string> EnumerateDevices( |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 103 | DBus::Error& error); // NOLINT |
Ben Chan | 490319f | 2011-05-06 14:00:42 -0700 | [diff] [blame] | 104 | |
| 105 | // Returns a list of device sysfs paths for all auto-mountable disk devices |
| 106 | // attached to the system. Currently, all external disk devices, which are |
| 107 | // neither on the boot device nor virtual, are considered auto-mountable. |
| 108 | virtual std::vector<std::string> EnumerateAutoMountableDevices( |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 109 | DBus::Error& error); // NOLINT |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 110 | |
| 111 | // Returns properties of a disk device attached to the system. |
| 112 | virtual DBusDisk GetDeviceProperties(const std::string& device_path, |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 113 | DBus::Error& error); // NOLINT |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 114 | |
Ben Chan | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame^] | 115 | // Implements the SessionManagerObserverInterface interface to handle |
| 116 | // the event when the session has been started. |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 117 | virtual void OnSessionStarted(const std::string& user); |
| 118 | |
Ben Chan | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame^] | 119 | // Implements the SessionManagerObserverInterface interface to handle |
| 120 | // the event when the session has been stopped. |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 121 | virtual void OnSessionStopped(const std::string& user); |
| 122 | |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 123 | private: |
Ben Chan | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame^] | 124 | // Implements the DeviceEventDispatcherInterface to dispatch a device event |
| 125 | // by emitting the corresponding D-Bus signal. |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 126 | void DispatchDeviceEvent(const DeviceEvent& event); |
| 127 | |
Ben Chan | b092d75 | 2011-07-13 11:44:38 -0700 | [diff] [blame] | 128 | // Initializes DBus properties. |
| 129 | void InitializeProperties(); |
| 130 | |
| 131 | // Overrides PropertiesAdaptor::on_set_property to handle |
| 132 | // org.freedesktop.DBus.Properties.Set calls. |
| 133 | virtual void on_set_property(DBus::InterfaceAdaptor& interface, // NOLINT |
| 134 | const std::string& property, const DBus::Variant& value); |
| 135 | |
Ben Chan | 490319f | 2011-05-06 14:00:42 -0700 | [diff] [blame] | 136 | // Returns a list of device sysfs paths for all disk devices attached to |
| 137 | // the system. If auto_mountable_only is true, only auto-mountable disk |
| 138 | // devices are returned. |
| 139 | std::vector<std::string> DoEnumerateDevices(bool auto_mountable_only) const; |
| 140 | |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 141 | Platform* platform_; |
| 142 | |
| 143 | ArchiveManager* archive_manager_; |
| 144 | |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 145 | DiskManager* disk_manager_; |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 146 | |
Szymon Sidor | 2733b51 | 2011-06-30 18:00:51 -0700 | [diff] [blame] | 147 | FormatManager* format_manager_; |
| 148 | |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 149 | std::vector<MountManager*> mount_managers_; |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 150 | }; |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 151 | |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 152 | } // namespace cros_disks |
| 153 | |
| 154 | #endif // CROS_DISKS_SERVER_IMPL_H_ |