Chromium Code Reviews| 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 CHROMEOS_DBUS_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_ | 9 #ifndef CHROMEOS_DBUS_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_ |
| 10 #define CHROMEOS_DBUS_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_ | 10 #define CHROMEOS_DBUS_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_ |
| 11 | 11 |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/callback.h" | 16 #include "base/callback.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "chromeos/chromeos_export.h" | 18 #include "chromeos/chromeos_export.h" |
| 19 #include "chromeos/dbus/dbus_client_implementation_type.h" | 19 #include "chromeos/dbus/dbus_client_implementation_type.h" |
| 20 | 20 |
| 21 class MtpFileEntry; | |
| 22 class MtpStorageInfo; | |
| 23 | |
| 21 namespace dbus { | 24 namespace dbus { |
| 22 class Bus; | 25 class Bus; |
| 23 class Response; | |
| 24 } | 26 } |
| 25 | 27 |
| 26 namespace chromeos { | 28 namespace chromeos { |
| 27 | 29 |
| 28 // Mode to open a storage in. | 30 // Mode to open a storage in. |
| 29 enum OpenStorageMode { | 31 enum OpenStorageMode { |
| 30 OPEN_STORAGE_MODE_READ_ONLY, | 32 OPEN_STORAGE_MODE_READ_ONLY, |
| 31 }; | 33 }; |
| 32 | 34 |
| 33 // Values match libmtp values unless noted below. | |
| 34 // TODO(thestig) See if we can do better than this. | |
| 35 enum FileType { | |
| 36 FILE_TYPE_FOLDER = 0, | |
| 37 FILE_TYPE_JPEG = 14, | |
| 38 FILE_TYPE_JFIF = 15, | |
| 39 FILE_TYPE_TIFF = 16, | |
| 40 FILE_TYPE_BMP = 17, | |
| 41 FILE_TYPE_GIF = 18, | |
| 42 FILE_TYPE_PICT = 19, | |
| 43 FILE_TYPE_PNG = 20, | |
| 44 FILE_TYPE_WINDOWSIMAGEFORMAT = 25, | |
| 45 FILE_TYPE_JP2 = 40, | |
| 46 FILE_TYPE_JPX = 41, | |
| 47 // Truly unknown file type. | |
| 48 FILE_TYPE_UNKNOWN = 44, | |
| 49 // There's more file types to map to, but right now they are not interesting. | |
| 50 // Just assign a dummy value for now. | |
| 51 FILE_TYPE_OTHER = 9999 | |
| 52 }; | |
| 53 | |
| 54 // A class to represent information about a storage sent from mtpd. | |
| 55 class CHROMEOS_EXPORT StorageInfo { | |
| 56 public: | |
| 57 StorageInfo(); | |
| 58 StorageInfo(const std::string& storage_name, dbus::Response* response); | |
| 59 ~StorageInfo(); | |
| 60 | |
| 61 // Storage name. (e.g. usb:1,5:65537) | |
| 62 const std::string& storage_name() const { return storage_name_; } | |
| 63 | |
| 64 // Vendor. (e.g. Kodak) | |
| 65 const std::string& vendor() const { return vendor_; } | |
| 66 | |
| 67 // Vendor ID. (e.g. 0x040a) | |
| 68 uint16 vendor_id() const { return vendor_id_; } | |
| 69 | |
| 70 // Product. (e.g. DC4800) | |
| 71 const std::string& product() const { return product_; } | |
| 72 | |
| 73 // Vendor ID. (e.g. 0x0160) | |
| 74 uint16 product_id() const { return product_id_; } | |
| 75 | |
| 76 // Device flags as defined by libmtp. | |
| 77 uint32 device_flags() const { return device_flags_; } | |
| 78 | |
| 79 // Storage type as defined in libmtp. (e.g. PTP_ST_FixedROM) | |
| 80 uint16 storage_type() const { return storage_type_; } | |
| 81 | |
| 82 // File system type as defined in libmtp. (e.g. PTP_FST_DCF) | |
| 83 uint16 filesystem_type() const { return filesystem_type_; } | |
| 84 | |
| 85 // Access capability as defined in libmtp. (e.g. PTP_AC_ReadWrite) | |
| 86 uint16 access_capability() const { return access_capability_; } | |
| 87 | |
| 88 // Max capacity in bytes. | |
| 89 uint64 max_capacity() const { return max_capacity_; } | |
| 90 | |
| 91 // Free space in byte. | |
| 92 uint64 free_space_in_bytes() const { return free_space_in_bytes_; } | |
| 93 | |
| 94 // Free space in number of objects. | |
| 95 uint64 free_space_in_objects() const { return free_space_in_objects_; } | |
| 96 | |
| 97 // Storage description. (e.g. internal memory) | |
| 98 const std::string& storage_description() const { | |
| 99 return storage_description_; | |
| 100 } | |
| 101 | |
| 102 // Volume identifier. (e.g. the serial number, should be unique) | |
| 103 const std::string& volume_identifier() const { return volume_identifier_; } | |
| 104 | |
| 105 private: | |
| 106 void InitializeFromResponse(dbus::Response* response); | |
| 107 | |
| 108 // Device info. (A device can have multiple storages) | |
| 109 std::string vendor_; | |
| 110 uint16 vendor_id_; | |
| 111 std::string product_; | |
| 112 uint16 product_id_; | |
| 113 uint32 device_flags_; | |
| 114 | |
| 115 // Storage info. | |
| 116 std::string storage_name_; | |
| 117 uint16 storage_type_; | |
| 118 uint16 filesystem_type_; | |
| 119 uint16 access_capability_; | |
| 120 uint64 max_capacity_; | |
| 121 uint64 free_space_in_bytes_; | |
| 122 uint64 free_space_in_objects_; | |
| 123 std::string storage_description_; | |
| 124 std::string volume_identifier_; | |
| 125 }; | |
| 126 | |
| 127 // A class to represent information about a file entry sent from mtpd. | |
| 128 class CHROMEOS_EXPORT FileEntry { | |
| 129 public: | |
| 130 FileEntry(); | |
| 131 explicit FileEntry(dbus::Response* response); | |
| 132 ~FileEntry(); | |
| 133 | |
| 134 // ID for the file. | |
| 135 uint32 item_id() const { return item_id_; } | |
| 136 | |
| 137 // ID for the file's parent. | |
| 138 uint32 parent_id() const { return parent_id_; } | |
| 139 | |
| 140 // Name of the file. | |
| 141 const std::string& file_name() const { return file_name_; } | |
| 142 | |
| 143 // Size of the file. | |
| 144 uint64 file_size() const { return file_size_; } | |
| 145 | |
| 146 // Modification time of the file. | |
| 147 base::Time modification_date() const { return modification_date_; } | |
| 148 | |
| 149 // File type. | |
| 150 FileType file_type() const { return file_type_; } | |
| 151 | |
| 152 private: | |
| 153 void InitializeFromResponse(dbus::Response* response); | |
| 154 | |
| 155 // Storage info. | |
| 156 uint32 item_id_; | |
| 157 uint32 parent_id_; | |
| 158 std::string file_name_; | |
| 159 uint64 file_size_; | |
| 160 base::Time modification_date_; | |
| 161 FileType file_type_; | |
| 162 }; | |
| 163 | |
| 164 // A class to make the actual DBus calls for mtpd service. | 35 // A class to make the actual DBus calls for mtpd service. |
| 165 // This class only makes calls, result/error handling should be done | 36 // This class only makes calls, result/error handling should be done |
| 166 // by callbacks. | 37 // by callbacks. |
| 167 class CHROMEOS_EXPORT MediaTransferProtocolDaemonClient { | 38 class CHROMEOS_EXPORT MediaTransferProtocolDaemonClient { |
| 168 public: | 39 public: |
| 169 // A callback to be called when DBus method call fails. | 40 // A callback to be called when DBus method call fails. |
| 170 typedef base::Callback<void()> ErrorCallback; | 41 typedef base::Callback<void()> ErrorCallback; |
| 171 | 42 |
| 172 // A callback to handle the result of EnumerateAutoMountableDevices. | 43 // A callback to handle the result of EnumerateAutoMountableDevices. |
| 173 // The argument is the enumerated storage names. | 44 // The argument is the enumerated storage names. |
| 174 typedef base::Callback<void(const std::vector<std::string>& storage_names) | 45 typedef base::Callback<void(const std::vector<std::string>& storage_names) |
| 175 > EnumerateStorageCallback; | 46 > EnumerateStorageCallback; |
| 176 | 47 |
| 177 // A callback to handle the result of GetStorageInfo. | 48 // A callback to handle the result of GetStorageInfo. |
| 178 // The argument is the information about the specified storage. | 49 // The argument is the information about the specified storage. |
| 179 typedef base::Callback<void(const StorageInfo& storage_info) | 50 typedef base::Callback<void(const MtpStorageInfo& storage_info) |
| 180 > GetStorageInfoCallback; | 51 > GetStorageInfoCallback; |
| 181 | 52 |
| 182 // A callback to handle the result of OpenStorage. | 53 // A callback to handle the result of OpenStorage. |
| 183 // The argument is the returned handle. | 54 // The argument is the returned handle. |
| 184 typedef base::Callback<void(const std::string& handle)> OpenStorageCallback; | 55 typedef base::Callback<void(const std::string& handle)> OpenStorageCallback; |
| 185 | 56 |
| 186 // A callback to handle the result of CloseStorage. | 57 // A callback to handle the result of CloseStorage. |
| 187 typedef base::Callback<void()> CloseStorageCallback; | 58 typedef base::Callback<void()> CloseStorageCallback; |
| 188 | 59 |
| 189 // A callback to handle the result of ReadDirectoryByPath/Id. | 60 // A callback to handle the result of ReadDirectoryByPath/Id. |
| 190 // The argument is a vector of file entries. | 61 // The argument is a vector of file entries. |
| 191 typedef base::Callback<void(const std::vector<FileEntry>& file_entries) | 62 typedef base::Callback<void(const std::vector<MtpFileEntry>& file_entries) |
| 192 > ReadDirectoryCallback; | 63 > ReadDirectoryCallback; |
| 193 | 64 |
| 194 // A callback to handle the result of ReadFileByPath/Id. | 65 // A callback to handle the result of ReadFileByPath/Id. |
| 195 // The argument is a string containing the file data. | 66 // The argument is a string containing the file data. |
| 196 // TODO(thestig) Consider using a file descriptor instead of the data. | 67 // TODO(thestig) Consider using a file descriptor instead of the data. |
| 197 typedef base::Callback<void(const std::string& data)> ReadFileCallback; | 68 typedef base::Callback<void(const std::string& data)> ReadFileCallback; |
| 198 | 69 |
| 199 // A callback to handle the result of GetFileInfoByPath/Id. | 70 // A callback to handle the result of GetFileInfoByPath/Id. |
| 200 // The argument is a file entry. | 71 // The argument is a file entry. |
| 201 typedef base::Callback<void(const FileEntry& file_entry) | 72 typedef base::Callback<void(const MtpFileEntry& file_entry) |
| 202 > GetFileInfoCallback; | 73 > GetFileInfoCallback; |
| 203 | 74 |
| 204 // A callback to handle storage attach/detach events. | 75 // A callback to handle storage attach/detach events. |
| 205 // The first argument is true for attach, false for detach. | 76 // The first argument is true for attach, false for detach. |
| 206 // The second argument is the storage name. | 77 // The second argument is the storage name. |
| 207 typedef base::Callback<void(bool is_attach, | 78 typedef base::Callback<void(bool is_attach, |
| 208 const std::string& storage_name) | 79 const std::string& storage_name) |
| 209 > MTPStorageEventHandler; | 80 > MTPStorageEventHandler; |
| 210 | 81 |
| 211 virtual ~MediaTransferProtocolDaemonClient(); | 82 virtual ~MediaTransferProtocolDaemonClient(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 protected: | 166 protected: |
| 296 // Create() should be used instead. | 167 // Create() should be used instead. |
| 297 MediaTransferProtocolDaemonClient(); | 168 MediaTransferProtocolDaemonClient(); |
| 298 | 169 |
| 299 private: | 170 private: |
| 300 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDaemonClient); | 171 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDaemonClient); |
| 301 }; | 172 }; |
| 302 | 173 |
| 303 } // namespace chromeos | 174 } // namespace chromeos |
| 304 | 175 |
| 305 #endif // CHROMEOS_DBUS_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_ | 176 #endif // CHROMEOS_DBUS_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_ |
|
satorux1
2012/09/06 17:20:05
129 lines reduced!
| |
| OLD | NEW |