blob: f2f92951e92e57bd99a0d65020ee5424b1c3c09e [file] [log] [blame]
Ryan Cairnsea6505f2011-04-10 19:54:53 -07001// 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 Chanbdc39742011-05-11 17:51:26 -07005#ifndef CROS_DISKS_SERVER_IMPL_H_
6#define CROS_DISKS_SERVER_IMPL_H_
Ryan Cairnsea6505f2011-04-10 19:54:53 -07007
8#include <string>
9#include <vector>
10
Ben Chanbdc39742011-05-11 17:51:26 -070011#include "cros-disks/cros-disks-server.h"
Ben Chan89cf29e2011-08-10 13:11:05 -070012#include "cros-disks/device-event-dispatcher-interface.h"
Ben Chan6e726922011-06-28 15:54:32 -070013#include "cros-disks/device-event-queue.h"
Ben Chanbdc39742011-05-11 17:51:26 -070014#include "cros-disks/disk.h"
Ben Chanc1e766c2011-11-21 12:56:59 -080015#include "cros-disks/format-manager-observer-interface.h"
Ben Chan89cf29e2011-08-10 13:11:05 -070016#include "cros-disks/session-manager-observer-interface.h"
Ben Chanbdc39742011-05-11 17:51:26 -070017
Ryan Cairnsea6505f2011-04-10 19:54:53 -070018namespace cros_disks {
19
Ben Chanf51ff002011-04-25 12:41:57 -070020class DiskManager;
Szymon Sidor2733b512011-06-30 18:00:51 -070021class FormatManager;
Ben Chan8dcede82011-07-25 20:56:13 -070022class MountManager;
23class Platform;
Ben Chanf51ff002011-04-25 12:41:57 -070024
Ben Chan2a5ea752011-12-21 09:48:19 -080025struct DeviceEvent;
26
Ben Chanbdc39742011-05-11 17:51:26 -070027// The d-bus server for the cros-disks daemon.
Ryan Cairnsea6505f2011-04-10 19:54:53 -070028//
29// Example Usage:
Ben Chanbdc39742011-05-11 17:51:26 -070030//
Ryan Cairnsea6505f2011-04-10 19:54:53 -070031// DBus::Connection server_conn = DBus::Connection::SystemBus();
32// server_conn.request_name("org.chromium.CrosDisks");
Ben Chan8dcede82011-07-25 20:56:13 -070033// ArchiveManager archive_manager(...);
34// DiskManager disk_manager(...);
Szymon Sidor2733b512011-06-30 18:00:51 -070035// FormatManager format_manager;
36// CrosDisksServer* server = new(std::nothrow)
Ben Chan8dcede82011-07-25 20:56:13 -070037// CrosDisksServer(server_conn, &platform,
Ben Chan8dcede82011-07-25 20:56:13 -070038// &disk_manager, &format_manager);
Ben Chanf47fc352013-05-03 11:28:57 -070039// server.RegisterMountManager(&disk_manager);
40// server.RegisterMountManager(&archive_manager);
Ben Chanbdc39742011-05-11 17:51:26 -070041//
Ryan Cairnsea6505f2011-04-10 19:54:53 -070042// At this point the server should be attached to the main loop.
43//
44class CrosDisksServer : public org::chromium::CrosDisks_adaptor,
45 public DBus::IntrospectableAdaptor,
Ben Chanb092d752011-07-13 11:44:38 -070046 public DBus::PropertiesAdaptor,
Ben Chan6e726922011-06-28 15:54:32 -070047 public DBus::ObjectAdaptor,
Ben Chan89cf29e2011-08-10 13:11:05 -070048 public DeviceEventDispatcherInterface,
Ben Chanc1e766c2011-11-21 12:56:59 -080049 public FormatManagerObserverInterface,
Ben Chan89cf29e2011-08-10 13:11:05 -070050 public SessionManagerObserverInterface {
Ryan Cairnsea6505f2011-04-10 19:54:53 -070051 public:
Ben Chan6e726922011-06-28 15:54:32 -070052 CrosDisksServer(DBus::Connection& connection, // NOLINT
Ben Chan8dcede82011-07-25 20:56:13 -070053 Platform* platform,
Ben Chan8dcede82011-07-25 20:56:13 -070054 DiskManager* disk_manager,
55 FormatManager* format_manager);
Ryan Cairnsea6505f2011-04-10 19:54:53 -070056 virtual ~CrosDisksServer();
57
Ben Chanf47fc352013-05-03 11:28:57 -070058 // Registers a mount manager.
59 void RegisterMountManager(MountManager* mount_manager);
60
Ben Chanc1e766c2011-11-21 12:56:59 -080061 // 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 Sidor2733b512011-06-30 18:00:51 -070068
Ben Chan9ed09e32011-11-22 16:24:06 -080069 // A method for asynchronous formatting device using specified file system.
70 // Assumes device path is valid (should it be invalid singal
Szymon Sidor2733b512011-06-30 18:00:51 -070071 // 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 Cairnsea6505f2011-04-10 19:54:53 -070076 // A method for checking if the daemon is running. Always returns true.
77 virtual bool IsAlive(DBus::Error& error); // NOLINT
78
Ben Chand3fdc722011-07-21 18:15:22 -070079 // 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 Chan8f513762011-11-14 12:44:42 -080090 // Unmounts all paths mounted by Mount() when invoked.
91 virtual void UnmountAll(DBus::Error& error); // NOLINT
92
Ben Chan490319f2011-05-06 14:00:42 -070093 // Returns a list of device sysfs paths for all disk devices attached to
Ben Chanf51ff002011-04-25 12:41:57 -070094 // the system.
Ben Chan490319f2011-05-06 14:00:42 -070095 virtual std::vector<std::string> EnumerateDevices(
Ben Chanbdc39742011-05-11 17:51:26 -070096 DBus::Error& error); // NOLINT
Ben Chan490319f2011-05-06 14:00:42 -070097
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 Chanbdc39742011-05-11 17:51:26 -0700102 DBus::Error& error); // NOLINT
Ben Chanf51ff002011-04-25 12:41:57 -0700103
104 // Returns properties of a disk device attached to the system.
105 virtual DBusDisk GetDeviceProperties(const std::string& device_path,
Ben Chanbdc39742011-05-11 17:51:26 -0700106 DBus::Error& error); // NOLINT
Ben Chanf51ff002011-04-25 12:41:57 -0700107
Ben Chanc1e766c2011-11-21 12:56:59 -0800108 // 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 Chan89cf29e2011-08-10 13:11:05 -0700113 // Implements the SessionManagerObserverInterface interface to handle
Ben Chan5988f292012-09-18 08:32:42 -0700114 // 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 Chan89cf29e2011-08-10 13:11:05 -0700122 // the event when the session has been started.
Ben Chanb3bf8d12013-04-23 13:57:55 -0700123 virtual void OnSessionStarted();
Ben Chan6e726922011-06-28 15:54:32 -0700124
Ben Chan89cf29e2011-08-10 13:11:05 -0700125 // Implements the SessionManagerObserverInterface interface to handle
126 // the event when the session has been stopped.
Ben Chanb3bf8d12013-04-23 13:57:55 -0700127 virtual void OnSessionStopped();
Ben Chan6e726922011-06-28 15:54:32 -0700128
Ben Chanf51ff002011-04-25 12:41:57 -0700129 private:
Ben Chan89cf29e2011-08-10 13:11:05 -0700130 // Implements the DeviceEventDispatcherInterface to dispatch a device event
131 // by emitting the corresponding D-Bus signal.
Ben Chan6e726922011-06-28 15:54:32 -0700132 void DispatchDeviceEvent(const DeviceEvent& event);
133
Ben Chanb092d752011-07-13 11:44:38 -0700134 // 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 Chan490319f2011-05-06 14:00:42 -0700142 // 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 Chan8f513762011-11-14 12:44:42 -0800147 // Unmounts all paths mounted by Mount().
148 void DoUnmountAll();
149
Ben Chan8dcede82011-07-25 20:56:13 -0700150 Platform* platform_;
151
Ben Chanf51ff002011-04-25 12:41:57 -0700152 DiskManager* disk_manager_;
Ben Chan6e726922011-06-28 15:54:32 -0700153
Szymon Sidor2733b512011-06-30 18:00:51 -0700154 FormatManager* format_manager_;
155
Ben Chan8dcede82011-07-25 20:56:13 -0700156 std::vector<MountManager*> mount_managers_;
Ryan Cairnsea6505f2011-04-10 19:54:53 -0700157};
Ryan Cairnsea6505f2011-04-10 19:54:53 -0700158
Ben Chanbdc39742011-05-11 17:51:26 -0700159} // namespace cros_disks
160
161#endif // CROS_DISKS_SERVER_IMPL_H_