2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "common/filesystem/filesystem_storage.h"
19 #include "common/logger.h"
23 VirtualRoot::VirtualRoot(std::string const& name, std::string const& path, StorageType type,
25 : name_(name), path_(path), type_(type), state_(state) {
29 Storage::Storage(int id, StorageType type, StorageState state, std::string const& path,
30 std::string const& name)
31 : VirtualRoot(name, path, type, state), id_(id) {
35 case StorageType::kInternal:
38 case StorageType::kUsbDevice:
39 case StorageType::kUsbHost:
40 case StorageType::kMmc:
45 LoggerE("Unknown storage type: %d", type);
48 name_ += std::to_string(id);
52 picojson::value VirtualRoot::ToJson() const {
54 picojson::value v{picojson::object{}};
55 picojson::object& obj = v.get<picojson::object>();
57 obj["type"] = picojson::value(ToString(type_));
58 obj["state"] = picojson::value(ToString(state_));
59 obj["path"] = picojson::value(path_);
60 obj["name"] = picojson::value(name_);
65 picojson::value Storage::ToJson() const {
67 picojson::value value = VirtualRoot::ToJson();
68 picojson::object& obj = value.get<picojson::object>();
69 obj["storage_id"] = picojson::value(static_cast<double>(id_));
73 Storage::Storage(Storage const& other) : VirtualRoot(other) {
75 this->id_ = other.id_;
78 VirtualRoot::VirtualRoot(VirtualRoot const& other) {
80 this->path_ = other.path_;
81 this->name_ = other.name_;
82 this->state_ = other.state_;
83 this->type_ = other.type_;
86 std::string VirtualRoot::ToString(StorageType type) {
89 case StorageType::kInternal:
91 case StorageType::kUsbDevice:
92 case StorageType::kUsbHost:
93 case StorageType::kMmc:
96 LoggerE("Unknown storage type: %d", type);
101 std::string VirtualRoot::ToString(StorageState state) {
104 case StorageState::kUnmounted:
106 case StorageState::kUnmountable:
107 return "UNMOUNTABLE";
108 case StorageState::kMounted:
111 LoggerE("Unknown storage state: %d", state);
116 } // namespace common