blob: 52f14e2f847c13d6a4831d8a65c585d0ae48adf0 [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 Chan89cf29e2011-08-10 13:11:05 -070015#include "cros-disks/power-manager-observer-interface.h"
16#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 Chan8dcede82011-07-25 20:56:13 -070020class ArchiveManager;
Ben Chan6e726922011-06-28 15:54:32 -070021class DeviceEvent;
Ben Chanf51ff002011-04-25 12:41:57 -070022class DiskManager;
Szymon Sidor2733b512011-06-30 18:00:51 -070023class FormatManager;
Ben Chan8dcede82011-07-25 20:56:13 -070024class MountManager;
25class Platform;
Ben Chanf51ff002011-04-25 12:41:57 -070026
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,
38// &archive_manager,
39// &disk_manager, &format_manager);
Ben Chanbdc39742011-05-11 17:51:26 -070040//
Ryan Cairnsea6505f2011-04-10 19:54:53 -070041// At this point the server should be attached to the main loop.
42//
43class CrosDisksServer : public org::chromium::CrosDisks_adaptor,
44 public DBus::IntrospectableAdaptor,
Ben Chanb092d752011-07-13 11:44:38 -070045 public DBus::PropertiesAdaptor,
Ben Chan6e726922011-06-28 15:54:32 -070046 public DBus::ObjectAdaptor,
Ben Chan89cf29e2011-08-10 13:11:05 -070047 public DeviceEventDispatcherInterface,
48 public SessionManagerObserverInterface {
Ryan Cairnsea6505f2011-04-10 19:54:53 -070049 public:
Ben Chan6e726922011-06-28 15:54:32 -070050 CrosDisksServer(DBus::Connection& connection, // NOLINT
Ben Chan8dcede82011-07-25 20:56:13 -070051 Platform* platform,
52 ArchiveManager* archive_manager,
53 DiskManager* disk_manager,
54 FormatManager* format_manager);
Ryan Cairnsea6505f2011-04-10 19:54:53 -070055 virtual ~CrosDisksServer();
56
Szymon Sidor2733b512011-06-30 18:00:51 -070057 // 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 Cairnsea6505f2011-04-10 19:54:53 -070073 // A method for checking if the daemon is running. Always returns true.
74 virtual bool IsAlive(DBus::Error& error); // NOLINT
75
Ben Chand3fdc722011-07-21 18:15:22 -070076 // TODO(benchan): Deprecate this method.
Ryan Cairnsea6505f2011-04-10 19:54:53 -070077 // Unmounts a device when invoked.
Ben Chanf51ff002011-04-25 12:41:57 -070078 virtual void FilesystemUnmount(const std::string& device_path,
79 const std::vector<std::string>& mount_options,
Ben Chanbdc39742011-05-11 17:51:26 -070080 DBus::Error& error); // NOLINT
Ryan Cairnsea6505f2011-04-10 19:54:53 -070081
Ben Chand3fdc722011-07-21 18:15:22 -070082 // 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 Cairnsea6505f2011-04-10 19:54:53 -070094 // Mounts a device when invoked.
Ben Chanf51ff002011-04-25 12:41:57 -070095 virtual std::string FilesystemMount(const std::string& device_path,
96 const std::string& filesystem_type,
97 const std::vector<std::string>& mount_options,
Ben Chanbdc39742011-05-11 17:51:26 -070098 DBus::Error& error); // NOLINT
Ryan Cairnsea6505f2011-04-10 19:54:53 -070099
Ben Chan490319f2011-05-06 14:00:42 -0700100 // Returns a list of device sysfs paths for all disk devices attached to
Ben Chanf51ff002011-04-25 12:41:57 -0700101 // the system.
Ben Chan490319f2011-05-06 14:00:42 -0700102 virtual std::vector<std::string> EnumerateDevices(
Ben Chanbdc39742011-05-11 17:51:26 -0700103 DBus::Error& error); // NOLINT
Ben Chan490319f2011-05-06 14:00:42 -0700104
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 Chanbdc39742011-05-11 17:51:26 -0700109 DBus::Error& error); // NOLINT
Ben Chanf51ff002011-04-25 12:41:57 -0700110
111 // Returns properties of a disk device attached to the system.
112 virtual DBusDisk GetDeviceProperties(const std::string& device_path,
Ben Chanbdc39742011-05-11 17:51:26 -0700113 DBus::Error& error); // NOLINT
Ben Chanf51ff002011-04-25 12:41:57 -0700114
Ben Chan89cf29e2011-08-10 13:11:05 -0700115 // Implements the SessionManagerObserverInterface interface to handle
116 // the event when the session has been started.
Ben Chan6e726922011-06-28 15:54:32 -0700117 virtual void OnSessionStarted(const std::string& user);
118
Ben Chan89cf29e2011-08-10 13:11:05 -0700119 // Implements the SessionManagerObserverInterface interface to handle
120 // the event when the session has been stopped.
Ben Chan6e726922011-06-28 15:54:32 -0700121 virtual void OnSessionStopped(const std::string& user);
122
Ben Chanf51ff002011-04-25 12:41:57 -0700123 private:
Ben Chan89cf29e2011-08-10 13:11:05 -0700124 // Implements the DeviceEventDispatcherInterface to dispatch a device event
125 // by emitting the corresponding D-Bus signal.
Ben Chan6e726922011-06-28 15:54:32 -0700126 void DispatchDeviceEvent(const DeviceEvent& event);
127
Ben Chanb092d752011-07-13 11:44:38 -0700128 // 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 Chan490319f2011-05-06 14:00:42 -0700136 // 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 Chan8dcede82011-07-25 20:56:13 -0700141 Platform* platform_;
142
143 ArchiveManager* archive_manager_;
144
Ben Chanf51ff002011-04-25 12:41:57 -0700145 DiskManager* disk_manager_;
Ben Chan6e726922011-06-28 15:54:32 -0700146
Szymon Sidor2733b512011-06-30 18:00:51 -0700147 FormatManager* format_manager_;
148
Ben Chan8dcede82011-07-25 20:56:13 -0700149 std::vector<MountManager*> mount_managers_;
Ryan Cairnsea6505f2011-04-10 19:54:53 -0700150};
Ryan Cairnsea6505f2011-04-10 19:54:53 -0700151
Ben Chanbdc39742011-05-11 17:51:26 -0700152} // namespace cros_disks
153
154#endif // CROS_DISKS_SERVER_IMPL_H_