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 #include "chromeos/dbus/mtp_file_entry.pb.h" | |
20 | 21 |
21 namespace dbus { | 22 namespace dbus { |
22 class Bus; | 23 class Bus; |
23 class Response; | |
24 } | 24 } |
25 | 25 |
26 class MtpStorageInfo; | |
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 { | |
Lei Zhang
2012/09/01 00:46:34
I hate to have this enum to match the one in the p
satorux1
2012/09/01 01:03:50
that sounds ok to me. mtp_file_entry_proto target
| |
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. | 35 // A class to represent information about a storage sent from mtpd. |
55 class CHROMEOS_EXPORT StorageInfo { | 36 class CHROMEOS_EXPORT StorageInfo { |
56 public: | 37 public: |
57 StorageInfo(); | 38 StorageInfo(); |
58 StorageInfo(const std::string& storage_name, dbus::Response* response); | 39 StorageInfo(const std::string& storage_name, |
40 const MtpStorageInfo& storage_info); | |
59 ~StorageInfo(); | 41 ~StorageInfo(); |
60 | 42 |
61 // Storage name. (e.g. usb:1,5:65537) | 43 // Storage name. (e.g. usb:1,5:65537) |
62 const std::string& storage_name() const { return storage_name_; } | 44 const std::string& storage_name() const { return storage_name_; } |
63 | 45 |
64 // Vendor. (e.g. Kodak) | 46 // Vendor. (e.g. Kodak) |
65 const std::string& vendor() const { return vendor_; } | 47 const std::string& vendor() const { return vendor_; } |
66 | 48 |
67 // Vendor ID. (e.g. 0x040a) | 49 // Vendor ID. (e.g. 0x040a) |
68 uint16 vendor_id() const { return vendor_id_; } | 50 uint16 vendor_id() const { return vendor_id_; } |
(...skipping 27 matching lines...) Expand all Loading... | |
96 | 78 |
97 // Storage description. (e.g. internal memory) | 79 // Storage description. (e.g. internal memory) |
98 const std::string& storage_description() const { | 80 const std::string& storage_description() const { |
99 return storage_description_; | 81 return storage_description_; |
100 } | 82 } |
101 | 83 |
102 // Volume identifier. (e.g. the serial number, should be unique) | 84 // Volume identifier. (e.g. the serial number, should be unique) |
103 const std::string& volume_identifier() const { return volume_identifier_; } | 85 const std::string& volume_identifier() const { return volume_identifier_; } |
104 | 86 |
105 private: | 87 private: |
106 void InitializeFromResponse(dbus::Response* response); | |
107 | |
108 // Device info. (A device can have multiple storages) | 88 // Device info. (A device can have multiple storages) |
109 std::string vendor_; | 89 std::string vendor_; |
110 uint16 vendor_id_; | 90 uint16 vendor_id_; |
111 std::string product_; | 91 std::string product_; |
112 uint16 product_id_; | 92 uint16 product_id_; |
113 uint32 device_flags_; | 93 uint32 device_flags_; |
114 | 94 |
115 // Storage info. | 95 // Storage info. |
116 std::string storage_name_; | 96 std::string storage_name_; |
117 uint16 storage_type_; | 97 uint16 storage_type_; |
118 uint16 filesystem_type_; | 98 uint16 filesystem_type_; |
119 uint16 access_capability_; | 99 uint16 access_capability_; |
120 uint64 max_capacity_; | 100 uint64 max_capacity_; |
121 uint64 free_space_in_bytes_; | 101 uint64 free_space_in_bytes_; |
122 uint64 free_space_in_objects_; | 102 uint64 free_space_in_objects_; |
123 std::string storage_description_; | 103 std::string storage_description_; |
124 std::string volume_identifier_; | 104 std::string volume_identifier_; |
125 }; | 105 }; |
126 | 106 |
127 // A class to represent information about a file entry sent from mtpd. | 107 // A class to represent information about a file entry sent from mtpd. |
128 class CHROMEOS_EXPORT FileEntry { | 108 class CHROMEOS_EXPORT FileEntry { |
129 public: | 109 public: |
130 FileEntry(); | 110 FileEntry(); |
131 explicit FileEntry(dbus::Response* response); | 111 explicit FileEntry(const MtpFileEntry& entry); |
132 ~FileEntry(); | 112 ~FileEntry(); |
133 | 113 |
134 // ID for the file. | 114 // ID for the file. |
135 uint32 item_id() const { return item_id_; } | 115 uint32 item_id() const { return item_id_; } |
136 | 116 |
137 // ID for the file's parent. | 117 // ID for the file's parent. |
138 uint32 parent_id() const { return parent_id_; } | 118 uint32 parent_id() const { return parent_id_; } |
139 | 119 |
140 // Name of the file. | 120 // Name of the file. |
141 const std::string& file_name() const { return file_name_; } | 121 const std::string& file_name() const { return file_name_; } |
142 | 122 |
143 // Size of the file. | 123 // Size of the file. |
144 uint64 file_size() const { return file_size_; } | 124 uint64 file_size() const { return file_size_; } |
145 | 125 |
146 // Modification time of the file. | 126 // Modification time of the file. |
147 base::Time modification_date() const { return modification_date_; } | 127 base::Time modification_time() const { return modification_time_; } |
148 | 128 |
149 // File type. | 129 // File type. |
150 FileType file_type() const { return file_type_; } | 130 MtpFileEntry_FileType file_type() const { return file_type_; } |
151 | 131 |
152 private: | 132 private: |
153 void InitializeFromResponse(dbus::Response* response); | |
154 | |
155 // Storage info. | 133 // Storage info. |
156 uint32 item_id_; | 134 uint32 item_id_; |
157 uint32 parent_id_; | 135 uint32 parent_id_; |
158 std::string file_name_; | 136 std::string file_name_; |
159 uint64 file_size_; | 137 uint64 file_size_; |
160 base::Time modification_date_; | 138 base::Time modification_time_; |
161 FileType file_type_; | 139 MtpFileEntry_FileType file_type_; |
162 }; | 140 }; |
163 | 141 |
164 // A class to make the actual DBus calls for mtpd service. | 142 // A class to make the actual DBus calls for mtpd service. |
165 // This class only makes calls, result/error handling should be done | 143 // This class only makes calls, result/error handling should be done |
166 // by callbacks. | 144 // by callbacks. |
167 class CHROMEOS_EXPORT MediaTransferProtocolDaemonClient { | 145 class CHROMEOS_EXPORT MediaTransferProtocolDaemonClient { |
168 public: | 146 public: |
169 // A callback to be called when DBus method call fails. | 147 // A callback to be called when DBus method call fails. |
170 typedef base::Callback<void()> ErrorCallback; | 148 typedef base::Callback<void()> ErrorCallback; |
171 | 149 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 // Create() should be used instead. | 274 // Create() should be used instead. |
297 MediaTransferProtocolDaemonClient(); | 275 MediaTransferProtocolDaemonClient(); |
298 | 276 |
299 private: | 277 private: |
300 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDaemonClient); | 278 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDaemonClient); |
301 }; | 279 }; |
302 | 280 |
303 } // namespace chromeos | 281 } // namespace chromeos |
304 | 282 |
305 #endif // CHROMEOS_DBUS_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_ | 283 #endif // CHROMEOS_DBUS_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_ |
OLD | NEW |