CacheStorage: Remove unused return value from put operation
[chromium-blink-merge.git] / device / media_transfer_protocol / media_transfer_protocol_daemon_client.h
blobc4c32c606b6cf0244a1353ccc6fceed980acf8c4
1 // Copyright (c) 2012 The Chromium 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.
5 // Client code to talk to the Media Transfer Protocol daemon. The MTP daemon is
6 // responsible for communicating with PTP / MTP capable devices like cameras
7 // and smartphones.
9 #ifndef DEVICE_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_
10 #define DEVICE_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_
12 #include <string>
13 #include <vector>
15 #include "base/basictypes.h"
16 #include "base/callback.h"
17 #include "build/build_config.h"
19 #if !defined(OS_LINUX)
20 #error "Only used on Linux and ChromeOS"
21 #endif
23 class MtpFileEntry;
24 class MtpStorageInfo;
26 namespace dbus {
27 class Bus;
30 namespace device {
32 // A class to make the actual DBus calls for mtpd service.
33 // This class only makes calls, result/error handling should be done
34 // by callbacks.
35 class MediaTransferProtocolDaemonClient {
36 public:
37 // A callback to be called when DBus method call fails.
38 typedef base::Closure ErrorCallback;
40 // A callback to handle the result of EnumerateAutoMountableDevices.
41 // The argument is the enumerated storage names.
42 typedef base::Callback<void(const std::vector<std::string>& storage_names)
43 > EnumerateStoragesCallback;
45 // A callback to handle the result of GetStorageInfo.
46 // The argument is the information about the specified storage.
47 typedef base::Callback<void(const MtpStorageInfo& storage_info)
48 > GetStorageInfoCallback;
50 // A callback to handle the result of OpenStorage.
51 // The argument is the returned handle.
52 typedef base::Callback<void(const std::string& handle)> OpenStorageCallback;
54 // A callback to handle the result of CloseStorage.
55 typedef base::Closure CloseStorageCallback;
57 // A callback to handle the result of CreateDirectory.
58 typedef base::Closure CreateDirectoryCallback;
60 // A callback to handle the result of ReadDirectoryEntryIds.
61 // The argument is a vector of file ids.
62 typedef base::Callback<void(const std::vector<uint32>& file_ids)
63 > ReadDirectoryEntryIdsCallback;
65 // A callback to handle the result of GetFileInfo.
66 // The argument is a vector of file entries.
67 typedef base::Callback<void(const std::vector<MtpFileEntry>& file_entries)
68 > GetFileInfoCallback;
70 // A callback to handle the result of ReadFileChunkById.
71 // The argument is a string containing the file data.
72 typedef base::Callback<void(const std::string& data)> ReadFileCallback;
74 // A callback to handle the result of RenameObject.
75 typedef base::Closure RenameObjectCallback;
77 // A callback to handle the result of CopyFileFromLocal.
78 typedef base::Closure CopyFileFromLocalCallback;
80 // A callback to handle the result of DeleteObject.
81 typedef base::Closure DeleteObjectCallback;
83 // A callback to handle storage attach/detach events.
84 // The first argument is true for attach, false for detach.
85 // The second argument is the storage name.
86 typedef base::Callback<void(bool is_attach,
87 const std::string& storage_name)
88 > MTPStorageEventHandler;
90 virtual ~MediaTransferProtocolDaemonClient();
92 // Calls EnumerateStorages method. |callback| is called after the
93 // method call succeeds, otherwise, |error_callback| is called.
94 virtual void EnumerateStorages(
95 const EnumerateStoragesCallback& callback,
96 const ErrorCallback& error_callback) = 0;
98 // Calls GetStorageInfo method. |callback| is called after the method call
99 // succeeds, otherwise, |error_callback| is called.
100 virtual void GetStorageInfo(const std::string& storage_name,
101 const GetStorageInfoCallback& callback,
102 const ErrorCallback& error_callback) = 0;
104 // Calls OpenStorage method. |callback| is called after the method call
105 // succeeds, otherwise, |error_callback| is called.
106 // OpenStorage returns a handle in |callback|.
107 virtual void OpenStorage(const std::string& storage_name,
108 const std::string& mode,
109 const OpenStorageCallback& callback,
110 const ErrorCallback& error_callback) = 0;
112 // Calls CloseStorage method. |callback| is called after the method call
113 // succeeds, otherwise, |error_callback| is called.
114 // |handle| comes from a OpenStorageCallback.
115 virtual void CloseStorage(const std::string& handle,
116 const CloseStorageCallback& callback,
117 const ErrorCallback& error_callback) = 0;
119 // Calls CreateDirectory method. |callback| is called after the method call
120 // succeeds, otherwise, |error_callback| is called.
121 // |parent_id| is an id of the parent directory.
122 // |directory_name| is name of new directory.
123 virtual void CreateDirectory(const std::string& handle,
124 const uint32 parent_id,
125 const std::string& directory_name,
126 const CreateDirectoryCallback& callback,
127 const ErrorCallback& error_callback) = 0;
129 // Calls ReadDirectoryEntryIds method. |callback| is called after the method
130 // call succeeds, otherwise, |error_callback| is called.
131 // |file_id| is a MTP-device specific id for a file.
132 virtual void ReadDirectoryEntryIds(
133 const std::string& handle,
134 uint32 file_id,
135 const ReadDirectoryEntryIdsCallback& callback,
136 const ErrorCallback& error_callback) = 0;
138 // Calls GetFileInfo method. |callback| is called after the method
139 // call succeeds, otherwise, |error_callback| is called.
140 // |file_ids| is a list of MTP-device specific file ids.
141 // |offset| is the index into |file_ids| to read from.
142 // |entries_to_read| is the maximum number of file entries to read.
143 virtual void GetFileInfo(const std::string& handle,
144 const std::vector<uint32>& file_ids,
145 size_t offset,
146 size_t entries_to_read,
147 const GetFileInfoCallback& callback,
148 const ErrorCallback& error_callback) = 0;
150 // Calls ReadFileChunk method. |callback| is called after the method call
151 // succeeds, otherwise, |error_callback| is called.
152 // |file_id| is a MTP-device specific id for a file.
153 // |offset| is the offset into the file.
154 // |bytes_to_read| cannot exceed 1 MiB.
155 virtual void ReadFileChunk(const std::string& handle,
156 uint32 file_id,
157 uint32 offset,
158 uint32 bytes_to_read,
159 const ReadFileCallback& callback,
160 const ErrorCallback& error_callback) = 0;
162 // Calls RenameObject method. |callback| is called after the method call
163 // succeeds, otherwise, |error_callback| is called.
164 // |object_is| is an id of object to be renamed.
165 // |new_name| is new name of the object.
166 virtual void RenameObject(const std::string& handle,
167 const uint32 object_id,
168 const std::string& new_name,
169 const RenameObjectCallback& callback,
170 const ErrorCallback& error_callback) = 0;
172 // Calls CopyFileFromLocal method. |callback| is called after the method call
173 // succeeds, otherwise, |error_callback| is called.
174 // |source_file_descriptor| is a file descriptor of source file.
175 // |parent_id| is a object id of a target directory.
176 // |file_name| is a file name of a target file.
177 virtual void CopyFileFromLocal(const std::string& handle,
178 const int source_file_descriptor,
179 const uint32 parent_id,
180 const std::string& file_name,
181 const CopyFileFromLocalCallback& callback,
182 const ErrorCallback& error_callback) = 0;
184 // Calls DeleteObject method. |callback| is called after the method call
185 // succeeds, otherwise, |error_callback| is called.
186 // |object_id| is an object id of a file or directory which is deleted.
187 virtual void DeleteObject(const std::string& handle,
188 const uint32 object_id,
189 const DeleteObjectCallback& callback,
190 const ErrorCallback& error_callback) = 0;
192 // Registers given callback for events. Should only be called once.
193 // |storage_event_handler| is called when a mtp storage attach or detach
194 // signal is received.
195 virtual void ListenForChanges(const MTPStorageEventHandler& handler) = 0;
197 // Factory function, creates a new instance and returns ownership.
198 static MediaTransferProtocolDaemonClient* Create(dbus::Bus* bus);
200 protected:
201 // Create() should be used instead.
202 MediaTransferProtocolDaemonClient();
204 private:
205 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDaemonClient);
208 } // namespace device
210 #endif // DEVICE_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_