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 | d4ae1b1 | 2014-07-03 00:01:58 -0700 | [diff] [blame] | 5 | #ifndef CROS_DISKS_CROS_DISKS_SERVER_H_ |
| 6 | #define CROS_DISKS_CROS_DISKS_SERVER_H_ |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
Ben Chan | 5ccd9fe | 2013-11-13 18:28:27 -0800 | [diff] [blame] | 11 | #include "cros-disks/dbus_adaptors/org.chromium.CrosDisks.h" |
| 12 | #include "cros-disks/device_event_dispatcher_interface.h" |
| 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 | 5ccd9fe | 2013-11-13 18:28:27 -0800 | [diff] [blame] | 15 | #include "cros-disks/format_manager_observer_interface.h" |
Ben Chan | 8fb742b | 2014-04-28 23:46:57 -0700 | [diff] [blame] | 16 | #include "cros-disks/mount_entry.h" |
Ben Chan | 5ccd9fe | 2013-11-13 18:28:27 -0800 | [diff] [blame] | 17 | #include "cros-disks/session_manager_observer_interface.h" |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 18 | |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 19 | namespace cros_disks { |
| 20 | |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 21 | class DiskManager; |
Szymon Sidor | 2733b51 | 2011-06-30 18:00:51 -0700 | [diff] [blame] | 22 | class FormatManager; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 23 | class MountManager; |
| 24 | class Platform; |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 25 | |
Ben Chan | 2a5ea75 | 2011-12-21 09:48:19 -0800 | [diff] [blame] | 26 | struct DeviceEvent; |
| 27 | |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 28 | // The d-bus server for the cros-disks daemon. |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 29 | // |
| 30 | // Example Usage: |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 31 | // |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 32 | // DBus::Connection server_conn = DBus::Connection::SystemBus(); |
Ben Chan | a8661cb | 2014-04-17 11:38:02 -0700 | [diff] [blame] | 33 | // CHECK(server_conn.acquire_name("org.chromium.CrosDisks")); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 34 | // ArchiveManager archive_manager(...); |
| 35 | // DiskManager disk_manager(...); |
Szymon Sidor | 2733b51 | 2011-06-30 18:00:51 -0700 | [diff] [blame] | 36 | // FormatManager format_manager; |
| 37 | // CrosDisksServer* server = new(std::nothrow) |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 38 | // CrosDisksServer(server_conn, &platform, |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 39 | // &disk_manager, &format_manager); |
Ben Chan | f47fc35 | 2013-05-03 11:28:57 -0700 | [diff] [blame] | 40 | // server.RegisterMountManager(&disk_manager); |
| 41 | // server.RegisterMountManager(&archive_manager); |
Ben Chan | bdc3974 | 2011-05-11 17:51:26 -0700 | [diff] [blame] | 42 | // |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 43 | // At this point the server should be attached to the main loop. |
| 44 | // |
| 45 | class CrosDisksServer : public org::chromium::CrosDisks_adaptor, |
| 46 | public DBus::IntrospectableAdaptor, |
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); |
Ben Chan | 5512355 | 2014-08-24 16:22:16 -0700 | [diff] [blame] | 56 | ~CrosDisksServer() override = default; |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 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. |
Ben Chan | 1c6c194 | 2014-08-12 09:48:29 -0700 | [diff] [blame] | 64 | void Format(const std::string& path, |
| 65 | const std::string& filesystem_type, |
| 66 | const std::vector<std::string>& options, |
| 67 | DBus::Error& error) override; // NOLINT |
Szymon Sidor | 2733b51 | 2011-06-30 18:00:51 -0700 | [diff] [blame] | 68 | |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 69 | // A method for checking if the daemon is running. Always returns true. |
Ben Chan | 1c6c194 | 2014-08-12 09:48:29 -0700 | [diff] [blame] | 70 | bool IsAlive(DBus::Error& error) override; // NOLINT |
Ryan Cairns | ea6505f | 2011-04-10 19:54:53 -0700 | [diff] [blame] | 71 | |
Ben Chan | d3fdc72 | 2011-07-21 18:15:22 -0700 | [diff] [blame] | 72 | // Mounts a path when invoked. |
Ben Chan | 1c6c194 | 2014-08-12 09:48:29 -0700 | [diff] [blame] | 73 | void Mount(const std::string& path, |
| 74 | const std::string& filesystem_type, |
| 75 | const std::vector<std::string>& options, |
| 76 | DBus::Error& error) override; // NOLINT |
Ben Chan | d3fdc72 | 2011-07-21 18:15:22 -0700 | [diff] [blame] | 77 | |
| 78 | // Unmounts a path when invoked. |
Ben Chan | 1c6c194 | 2014-08-12 09:48:29 -0700 | [diff] [blame] | 79 | void Unmount(const std::string& path, |
| 80 | const std::vector<std::string>& options, |
| 81 | DBus::Error& error) override; // NOLINT |
Ben Chan | d3fdc72 | 2011-07-21 18:15:22 -0700 | [diff] [blame] | 82 | |
Ben Chan | 8f51376 | 2011-11-14 12:44:42 -0800 | [diff] [blame] | 83 | // Unmounts all paths mounted by Mount() when invoked. |
Ben Chan | 1c6c194 | 2014-08-12 09:48:29 -0700 | [diff] [blame] | 84 | void UnmountAll(DBus::Error& error) override; // NOLINT |
Ben Chan | 8f51376 | 2011-11-14 12:44:42 -0800 | [diff] [blame] | 85 | |
Ben Chan | 490319f | 2011-05-06 14:00:42 -0700 | [diff] [blame] | 86 | // 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] | 87 | // the system. |
Ben Chan | 1c6c194 | 2014-08-12 09:48:29 -0700 | [diff] [blame] | 88 | std::vector<std::string> EnumerateDevices( |
| 89 | DBus::Error& error) override; // NOLINT |
Ben Chan | 490319f | 2011-05-06 14:00:42 -0700 | [diff] [blame] | 90 | |
| 91 | // Returns a list of device sysfs paths for all auto-mountable disk devices |
| 92 | // attached to the system. Currently, all external disk devices, which are |
| 93 | // neither on the boot device nor virtual, are considered auto-mountable. |
Ben Chan | 1c6c194 | 2014-08-12 09:48:29 -0700 | [diff] [blame] | 94 | std::vector<std::string> EnumerateAutoMountableDevices( |
| 95 | DBus::Error& error) override; // NOLINT |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 96 | |
Ben Chan | 8fb742b | 2014-04-28 23:46:57 -0700 | [diff] [blame] | 97 | // Returns a list of mount entries (<error type, source path, source type, |
| 98 | // mount path>) that are currently managed by cros-disks. |
Ben Chan | 1c6c194 | 2014-08-12 09:48:29 -0700 | [diff] [blame] | 99 | DBusMountEntries EnumerateMountEntries(DBus::Error& error) override; // NOLINT |
Ben Chan | 8fb742b | 2014-04-28 23:46:57 -0700 | [diff] [blame] | 100 | |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 101 | // Returns properties of a disk device attached to the system. |
Ben Chan | 1c6c194 | 2014-08-12 09:48:29 -0700 | [diff] [blame] | 102 | DBusDisk GetDeviceProperties(const std::string& device_path, |
| 103 | DBus::Error& error) override; // NOLINT |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 104 | |
Ben Chan | c1e766c | 2011-11-21 12:56:59 -0800 | [diff] [blame] | 105 | // Implements the FormatManagerObserverInterface interface to handle |
| 106 | // the event when a formatting operation has completed. |
Ben Chan | 1c6c194 | 2014-08-12 09:48:29 -0700 | [diff] [blame] | 107 | void OnFormatCompleted(const std::string& device_path, |
| 108 | FormatErrorType error_type) override; |
Ben Chan | c1e766c | 2011-11-21 12:56:59 -0800 | [diff] [blame] | 109 | |
Ben Chan | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame] | 110 | // Implements the SessionManagerObserverInterface interface to handle |
Ben Chan | 5988f29 | 2012-09-18 08:32:42 -0700 | [diff] [blame] | 111 | // the event when the screen is locked. |
Ben Chan | 1c6c194 | 2014-08-12 09:48:29 -0700 | [diff] [blame] | 112 | void OnScreenIsLocked() override; |
Ben Chan | 5988f29 | 2012-09-18 08:32:42 -0700 | [diff] [blame] | 113 | |
| 114 | // Implements the SessionManagerObserverInterface interface to handle |
| 115 | // the event when the screen is unlocked. |
Ben Chan | 1c6c194 | 2014-08-12 09:48:29 -0700 | [diff] [blame] | 116 | void OnScreenIsUnlocked() override; |
Ben Chan | 5988f29 | 2012-09-18 08:32:42 -0700 | [diff] [blame] | 117 | |
| 118 | // Implements the SessionManagerObserverInterface interface to handle |
Ben Chan | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame] | 119 | // the event when the session has been started. |
Ben Chan | 1c6c194 | 2014-08-12 09:48:29 -0700 | [diff] [blame] | 120 | void OnSessionStarted() override; |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 121 | |
Ben Chan | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame] | 122 | // Implements the SessionManagerObserverInterface interface to handle |
| 123 | // the event when the session has been stopped. |
Ben Chan | 1c6c194 | 2014-08-12 09:48:29 -0700 | [diff] [blame] | 124 | void OnSessionStopped() override; |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 125 | |
Ben Chan | f51ff00 | 2011-04-25 12:41:57 -0700 | [diff] [blame] | 126 | private: |
Ben Chan | 89cf29e | 2011-08-10 13:11:05 -0700 | [diff] [blame] | 127 | // Implements the DeviceEventDispatcherInterface to dispatch a device event |
| 128 | // by emitting the corresponding D-Bus signal. |
Ben Chan | 1c6c194 | 2014-08-12 09:48:29 -0700 | [diff] [blame] | 129 | void DispatchDeviceEvent(const DeviceEvent& event) override; |
Ben Chan | 6e72692 | 2011-06-28 15:54:32 -0700 | [diff] [blame] | 130 | |
Ben Chan | 490319f | 2011-05-06 14:00:42 -0700 | [diff] [blame] | 131 | // Returns a list of device sysfs paths for all disk devices attached to |
| 132 | // the system. If auto_mountable_only is true, only auto-mountable disk |
| 133 | // devices are returned. |
| 134 | std::vector<std::string> DoEnumerateDevices(bool auto_mountable_only) const; |
| 135 | |
Tatsuhisa Yamaguchi | b670bd1 | 2016-09-28 23:06:44 +0900 | [diff] [blame^] | 136 | // Finds and returns a mounter which can mount |source_path|, or nullptr if no |
| 137 | // one can. |
| 138 | MountManager* FindMounter(const std::string& source_path) const; |
| 139 | |
Ben Chan | 8f51376 | 2011-11-14 12:44:42 -0800 | [diff] [blame] | 140 | // Unmounts all paths mounted by Mount(). |
| 141 | void DoUnmountAll(); |
| 142 | |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 143 | Platform* platform_; |
| 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 | |
Ben Chan | d4ae1b1 | 2014-07-03 00:01:58 -0700 | [diff] [blame] | 154 | #endif // CROS_DISKS_CROS_DISKS_SERVER_H_ |