blob: ea4699d637e4488bf1568bca0d866636dea002eb [file] [log] [blame]
Lei Zhangf0ab3ae2012-08-03 18:02:201// Copyright (c) 2012 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
5#include "mtpd/storage_info.h"
6
7#include "string_helpers.h"
8
9namespace mtpd {
10
11StorageInfo::StorageInfo(const LIBMTP_device_entry_t& device,
12 const LIBMTP_devicestorage_t& storage)
13 : vendor_id_(device.vendor_id),
14 product_id_(device.product_id),
15 device_flags_(device.device_flags),
16 storage_type_(storage.StorageType),
17 filesystem_type_(storage.FilesystemType),
18 access_capability_(storage.AccessCapability),
19 max_capacity_(storage.MaxCapacity),
20 free_space_in_bytes_(storage.FreeSpaceInBytes),
21 free_space_in_objects_(storage.FreeSpaceInObjects) {
22 if (device.vendor)
23 vendor_ = device.vendor;
24 if (device.product)
25 product_ = device.product;
26 if (storage.StorageDescription)
27 storage_description_ = storage.StorageDescription;
28 if (storage.VolumeIdentifier)
29 volume_identifier_ = storage.VolumeIdentifier;
30}
31
32StorageInfo::~StorageInfo() {
33}
34
35DBusMTPStorage StorageInfo::ToDBusFormat() const {
36 // TODO(thestig) Move string constants to system_api/dbus/service_constants.h.
37 DBusMTPStorage entry;
38 entry["Vendor"].writer().append_string(EnsureUTF8String(vendor_).c_str());
39 entry["VendorId"].writer().append_uint16(vendor_id_);
40 entry["Product"].writer().append_string(EnsureUTF8String(product_).c_str());
41 entry["ProductId"].writer().append_uint16(product_id_);
42 entry["DeviceFlags"].writer().append_uint32(device_flags_);
43 entry["StorageType"].writer().append_uint16(storage_type_);
44 entry["FilesystemType"].writer().append_uint16(filesystem_type_);
45 entry["AccessCapability"].writer().append_uint16(access_capability_);
46 entry["MaxCapacity"].writer().append_uint64(max_capacity_);
47 entry["FreeSpaceInBytes"].writer().append_uint64(free_space_in_bytes_);
48 entry["FreeSpaceInObjects"].writer().append_uint64(free_space_in_objects_);
49 entry["StorageDescription"].writer().append_string(
50 EnsureUTF8String(storage_description_).c_str());
51 entry["VolumeIdentifier"].writer().append_string(
52 EnsureUTF8String(volume_identifier_).c_str());
53 return entry;
54}
55
56} // namespace mtpd