| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Client code to talk to the Media Transfer Protocol daemon. The MTP daemon is | 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 | 6 // responsible for communicating with PTP / MTP capable devices like cameras |
| 7 // and smartphones. | 7 // and smartphones. |
| 8 | 8 |
| 9 #ifndef DEVICE_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_ | 9 #ifndef DEVICE_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_ |
| 10 #define DEVICE_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_ | 10 #define DEVICE_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_ |
| 11 | 11 |
| 12 #include <stddef.h> |
| 13 #include <stdint.h> |
| 14 |
| 12 #include <string> | 15 #include <string> |
| 13 #include <vector> | 16 #include <vector> |
| 14 | 17 |
| 15 #include "base/basictypes.h" | |
| 16 #include "base/callback.h" | 18 #include "base/callback.h" |
| 19 #include "base/macros.h" |
| 17 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 18 | 21 |
| 19 #if !defined(OS_LINUX) | 22 #if !defined(OS_LINUX) |
| 20 #error "Only used on Linux and ChromeOS" | 23 #error "Only used on Linux and ChromeOS" |
| 21 #endif | 24 #endif |
| 22 | 25 |
| 23 class MtpFileEntry; | 26 class MtpFileEntry; |
| 24 class MtpStorageInfo; | 27 class MtpStorageInfo; |
| 25 | 28 |
| 26 namespace dbus { | 29 namespace dbus { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 52 typedef base::Callback<void(const std::string& handle)> OpenStorageCallback; | 55 typedef base::Callback<void(const std::string& handle)> OpenStorageCallback; |
| 53 | 56 |
| 54 // A callback to handle the result of CloseStorage. | 57 // A callback to handle the result of CloseStorage. |
| 55 typedef base::Closure CloseStorageCallback; | 58 typedef base::Closure CloseStorageCallback; |
| 56 | 59 |
| 57 // A callback to handle the result of CreateDirectory. | 60 // A callback to handle the result of CreateDirectory. |
| 58 typedef base::Closure CreateDirectoryCallback; | 61 typedef base::Closure CreateDirectoryCallback; |
| 59 | 62 |
| 60 // A callback to handle the result of ReadDirectoryEntryIds. | 63 // A callback to handle the result of ReadDirectoryEntryIds. |
| 61 // The argument is a vector of file ids. | 64 // The argument is a vector of file ids. |
| 62 typedef base::Callback<void(const std::vector<uint32>& file_ids) | 65 typedef base::Callback<void(const std::vector<uint32_t>& file_ids)> |
| 63 > ReadDirectoryEntryIdsCallback; | 66 ReadDirectoryEntryIdsCallback; |
| 64 | 67 |
| 65 // A callback to handle the result of GetFileInfo. | 68 // A callback to handle the result of GetFileInfo. |
| 66 // The argument is a vector of file entries. | 69 // The argument is a vector of file entries. |
| 67 typedef base::Callback<void(const std::vector<MtpFileEntry>& file_entries) | 70 typedef base::Callback<void(const std::vector<MtpFileEntry>& file_entries) |
| 68 > GetFileInfoCallback; | 71 > GetFileInfoCallback; |
| 69 | 72 |
| 70 // A callback to handle the result of ReadFileChunkById. | 73 // A callback to handle the result of ReadFileChunkById. |
| 71 // The argument is a string containing the file data. | 74 // The argument is a string containing the file data. |
| 72 typedef base::Callback<void(const std::string& data)> ReadFileCallback; | 75 typedef base::Callback<void(const std::string& data)> ReadFileCallback; |
| 73 | 76 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // |handle| comes from a OpenStorageCallback. | 124 // |handle| comes from a OpenStorageCallback. |
| 122 virtual void CloseStorage(const std::string& handle, | 125 virtual void CloseStorage(const std::string& handle, |
| 123 const CloseStorageCallback& callback, | 126 const CloseStorageCallback& callback, |
| 124 const ErrorCallback& error_callback) = 0; | 127 const ErrorCallback& error_callback) = 0; |
| 125 | 128 |
| 126 // Calls CreateDirectory method. |callback| is called after the method call | 129 // Calls CreateDirectory method. |callback| is called after the method call |
| 127 // succeeds, otherwise, |error_callback| is called. | 130 // succeeds, otherwise, |error_callback| is called. |
| 128 // |parent_id| is an id of the parent directory. | 131 // |parent_id| is an id of the parent directory. |
| 129 // |directory_name| is name of new directory. | 132 // |directory_name| is name of new directory. |
| 130 virtual void CreateDirectory(const std::string& handle, | 133 virtual void CreateDirectory(const std::string& handle, |
| 131 const uint32 parent_id, | 134 const uint32_t parent_id, |
| 132 const std::string& directory_name, | 135 const std::string& directory_name, |
| 133 const CreateDirectoryCallback& callback, | 136 const CreateDirectoryCallback& callback, |
| 134 const ErrorCallback& error_callback) = 0; | 137 const ErrorCallback& error_callback) = 0; |
| 135 | 138 |
| 136 // Calls ReadDirectoryEntryIds method. |callback| is called after the method | 139 // Calls ReadDirectoryEntryIds method. |callback| is called after the method |
| 137 // call succeeds, otherwise, |error_callback| is called. | 140 // call succeeds, otherwise, |error_callback| is called. |
| 138 // |file_id| is a MTP-device specific id for a file. | 141 // |file_id| is a MTP-device specific id for a file. |
| 139 virtual void ReadDirectoryEntryIds( | 142 virtual void ReadDirectoryEntryIds( |
| 140 const std::string& handle, | 143 const std::string& handle, |
| 141 uint32 file_id, | 144 uint32_t file_id, |
| 142 const ReadDirectoryEntryIdsCallback& callback, | 145 const ReadDirectoryEntryIdsCallback& callback, |
| 143 const ErrorCallback& error_callback) = 0; | 146 const ErrorCallback& error_callback) = 0; |
| 144 | 147 |
| 145 // Calls GetFileInfo method. |callback| is called after the method | 148 // Calls GetFileInfo method. |callback| is called after the method |
| 146 // call succeeds, otherwise, |error_callback| is called. | 149 // call succeeds, otherwise, |error_callback| is called. |
| 147 // |file_ids| is a list of MTP-device specific file ids. | 150 // |file_ids| is a list of MTP-device specific file ids. |
| 148 // |offset| is the index into |file_ids| to read from. | 151 // |offset| is the index into |file_ids| to read from. |
| 149 // |entries_to_read| is the maximum number of file entries to read. | 152 // |entries_to_read| is the maximum number of file entries to read. |
| 150 virtual void GetFileInfo(const std::string& handle, | 153 virtual void GetFileInfo(const std::string& handle, |
| 151 const std::vector<uint32>& file_ids, | 154 const std::vector<uint32_t>& file_ids, |
| 152 size_t offset, | 155 size_t offset, |
| 153 size_t entries_to_read, | 156 size_t entries_to_read, |
| 154 const GetFileInfoCallback& callback, | 157 const GetFileInfoCallback& callback, |
| 155 const ErrorCallback& error_callback) = 0; | 158 const ErrorCallback& error_callback) = 0; |
| 156 | 159 |
| 157 // Calls ReadFileChunk method. |callback| is called after the method call | 160 // Calls ReadFileChunk method. |callback| is called after the method call |
| 158 // succeeds, otherwise, |error_callback| is called. | 161 // succeeds, otherwise, |error_callback| is called. |
| 159 // |file_id| is a MTP-device specific id for a file. | 162 // |file_id| is a MTP-device specific id for a file. |
| 160 // |offset| is the offset into the file. | 163 // |offset| is the offset into the file. |
| 161 // |bytes_to_read| cannot exceed 1 MiB. | 164 // |bytes_to_read| cannot exceed 1 MiB. |
| 162 virtual void ReadFileChunk(const std::string& handle, | 165 virtual void ReadFileChunk(const std::string& handle, |
| 163 uint32 file_id, | 166 uint32_t file_id, |
| 164 uint32 offset, | 167 uint32_t offset, |
| 165 uint32 bytes_to_read, | 168 uint32_t bytes_to_read, |
| 166 const ReadFileCallback& callback, | 169 const ReadFileCallback& callback, |
| 167 const ErrorCallback& error_callback) = 0; | 170 const ErrorCallback& error_callback) = 0; |
| 168 | 171 |
| 169 // Calls RenameObject method. |callback| is called after the method call | 172 // Calls RenameObject method. |callback| is called after the method call |
| 170 // succeeds, otherwise, |error_callback| is called. | 173 // succeeds, otherwise, |error_callback| is called. |
| 171 // |object_is| is an id of object to be renamed. | 174 // |object_is| is an id of object to be renamed. |
| 172 // |new_name| is new name of the object. | 175 // |new_name| is new name of the object. |
| 173 virtual void RenameObject(const std::string& handle, | 176 virtual void RenameObject(const std::string& handle, |
| 174 const uint32 object_id, | 177 const uint32_t object_id, |
| 175 const std::string& new_name, | 178 const std::string& new_name, |
| 176 const RenameObjectCallback& callback, | 179 const RenameObjectCallback& callback, |
| 177 const ErrorCallback& error_callback) = 0; | 180 const ErrorCallback& error_callback) = 0; |
| 178 | 181 |
| 179 // Calls CopyFileFromLocal method. |callback| is called after the method call | 182 // Calls CopyFileFromLocal method. |callback| is called after the method call |
| 180 // succeeds, otherwise, |error_callback| is called. | 183 // succeeds, otherwise, |error_callback| is called. |
| 181 // |source_file_descriptor| is a file descriptor of source file. | 184 // |source_file_descriptor| is a file descriptor of source file. |
| 182 // |parent_id| is a object id of a target directory. | 185 // |parent_id| is a object id of a target directory. |
| 183 // |file_name| is a file name of a target file. | 186 // |file_name| is a file name of a target file. |
| 184 virtual void CopyFileFromLocal(const std::string& handle, | 187 virtual void CopyFileFromLocal(const std::string& handle, |
| 185 const int source_file_descriptor, | 188 const int source_file_descriptor, |
| 186 const uint32 parent_id, | 189 const uint32_t parent_id, |
| 187 const std::string& file_name, | 190 const std::string& file_name, |
| 188 const CopyFileFromLocalCallback& callback, | 191 const CopyFileFromLocalCallback& callback, |
| 189 const ErrorCallback& error_callback) = 0; | 192 const ErrorCallback& error_callback) = 0; |
| 190 | 193 |
| 191 // Calls DeleteObject method. |callback| is called after the method call | 194 // Calls DeleteObject method. |callback| is called after the method call |
| 192 // succeeds, otherwise, |error_callback| is called. | 195 // succeeds, otherwise, |error_callback| is called. |
| 193 // |object_id| is an object id of a file or directory which is deleted. | 196 // |object_id| is an object id of a file or directory which is deleted. |
| 194 virtual void DeleteObject(const std::string& handle, | 197 virtual void DeleteObject(const std::string& handle, |
| 195 const uint32 object_id, | 198 const uint32_t object_id, |
| 196 const DeleteObjectCallback& callback, | 199 const DeleteObjectCallback& callback, |
| 197 const ErrorCallback& error_callback) = 0; | 200 const ErrorCallback& error_callback) = 0; |
| 198 | 201 |
| 199 // Registers given callback for events. Should only be called once. | 202 // Registers given callback for events. Should only be called once. |
| 200 // |storage_event_handler| is called when a mtp storage attach or detach | 203 // |storage_event_handler| is called when a mtp storage attach or detach |
| 201 // signal is received. | 204 // signal is received. |
| 202 virtual void ListenForChanges(const MTPStorageEventHandler& handler) = 0; | 205 virtual void ListenForChanges(const MTPStorageEventHandler& handler) = 0; |
| 203 | 206 |
| 204 // Factory function, creates a new instance and returns ownership. | 207 // Factory function, creates a new instance and returns ownership. |
| 205 static MediaTransferProtocolDaemonClient* Create(dbus::Bus* bus); | 208 static MediaTransferProtocolDaemonClient* Create(dbus::Bus* bus); |
| 206 | 209 |
| 207 protected: | 210 protected: |
| 208 // Create() should be used instead. | 211 // Create() should be used instead. |
| 209 MediaTransferProtocolDaemonClient(); | 212 MediaTransferProtocolDaemonClient(); |
| 210 | 213 |
| 211 private: | 214 private: |
| 212 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDaemonClient); | 215 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDaemonClient); |
| 213 }; | 216 }; |
| 214 | 217 |
| 215 } // namespace device | 218 } // namespace device |
| 216 | 219 |
| 217 #endif // DEVICE_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_
H_ | 220 #endif // DEVICE_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_
H_ |
| OLD | NEW |