Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 1 | // Copyright 2014 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 "buffet/manager.h" |
| 6 | |
Alex Vakulenko | b3aac25 | 2014-05-07 17:35:24 -0700 | [diff] [blame] | 7 | #include <map> |
Alex Vakulenko | 9ea5a32 | 2015-04-17 15:35:34 -0700 | [diff] [blame] | 8 | #include <set> |
Alex Vakulenko | b3aac25 | 2014-05-07 17:35:24 -0700 | [diff] [blame] | 9 | #include <string> |
| 10 | |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 11 | #include <base/bind.h> |
| 12 | #include <base/bind_helpers.h> |
Alex Vakulenko | 665c885 | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 13 | #include <base/json/json_reader.h> |
Christopher Wiley | b76eb29 | 2014-05-05 16:09:16 -0700 | [diff] [blame] | 14 | #include <base/json/json_writer.h> |
Christopher Wiley | cd41966 | 2015-02-06 17:51:43 -0800 | [diff] [blame] | 15 | #include <base/time/time.h> |
Alex Vakulenko | a8b95bc | 2014-08-27 11:00:57 -0700 | [diff] [blame] | 16 | #include <chromeos/dbus/async_event_sequencer.h> |
| 17 | #include <chromeos/dbus/exported_object_manager.h> |
| 18 | #include <chromeos/errors/error.h> |
Anton Muhin | 332df19 | 2014-11-22 05:59:14 +0400 | [diff] [blame] | 19 | #include <chromeos/key_value_store.h> |
Christopher Wiley | b76eb29 | 2014-05-05 16:09:16 -0700 | [diff] [blame] | 20 | #include <dbus/bus.h> |
Christopher Wiley | 9001624 | 2014-04-01 17:33:29 -0700 | [diff] [blame] | 21 | #include <dbus/object_path.h> |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 22 | #include <dbus/values_util.h> |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 23 | |
Vitaly Buka | 72410b2 | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 24 | #include "buffet/base_api_handler.h" |
Alex Vakulenko | 665c885 | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 25 | #include "buffet/commands/command_instance.h" |
Alex Vakulenko | e03af6d | 2015-04-20 11:00:54 -0700 | [diff] [blame] | 26 | #include "buffet/commands/schema_constants.h" |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 27 | #include "buffet/states/state_change_queue.h" |
Alex Vakulenko | 07216fe | 2014-09-19 15:31:09 -0700 | [diff] [blame] | 28 | #include "buffet/states/state_manager.h" |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 29 | #include "buffet/storage_impls.h" |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 30 | |
Christopher Wiley | 2d2d92b | 2014-07-29 14:07:10 -0700 | [diff] [blame] | 31 | using chromeos::dbus_utils::AsyncEventSequencer; |
Christopher Wiley | b5dd5ea | 2014-08-11 10:51:20 -0700 | [diff] [blame] | 32 | using chromeos::dbus_utils::ExportedObjectManager; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 33 | |
| 34 | namespace buffet { |
| 35 | |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 36 | namespace { |
| 37 | // Max of 100 state update events should be enough in the queue. |
| 38 | const size_t kMaxStateChangeQueueSize = 100; |
| 39 | } // anonymous namespace |
| 40 | |
Alex Vakulenko | f2784de | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 41 | Manager::Manager(const base::WeakPtr<ExportedObjectManager>& object_manager) |
| 42 | : dbus_object_(object_manager.get(), |
| 43 | object_manager->GetBus(), |
Vitaly Buka | 7ad8ffb | 2015-03-20 09:46:57 -0700 | [diff] [blame] | 44 | org::chromium::Buffet::ManagerAdaptor::GetObjectPath()) { |
| 45 | } |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 46 | |
Vitaly Buka | 7ad8ffb | 2015-03-20 09:46:57 -0700 | [diff] [blame] | 47 | Manager::~Manager() { |
| 48 | } |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 49 | |
Vitaly Buka | 76e7059 | 2015-04-16 11:39:02 -0700 | [diff] [blame] | 50 | void Manager::Start(const base::FilePath& config_path, |
| 51 | const base::FilePath& state_path, |
| 52 | const base::FilePath& test_definitions_path, |
| 53 | bool xmpp_enabled, |
| 54 | const AsyncEventSequencer::CompletionAction& cb) { |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 55 | command_manager_ = |
| 56 | std::make_shared<CommandManager>(dbus_object_.GetObjectManager()); |
Vitaly Buka | 5e6ff6c | 2015-05-11 15:41:33 -0700 | [diff] [blame] | 57 | command_manager_->AddOnCommandDefChanged(base::Bind( |
| 58 | &Manager::OnCommandDefsChanged, weak_ptr_factory_.GetWeakPtr())); |
Christopher Wiley | bb5b848 | 2015-02-12 13:42:16 -0800 | [diff] [blame] | 59 | command_manager_->Startup(base::FilePath{"/etc/buffet"}, |
| 60 | test_definitions_path); |
Vitaly Buka | 72410b2 | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 61 | state_change_queue_.reset(new StateChangeQueue(kMaxStateChangeQueueSize)); |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 62 | state_manager_ = std::make_shared<StateManager>(state_change_queue_.get()); |
Vitaly Buka | dbb8c35 | 2015-05-27 09:27:08 -0700 | [diff] [blame] | 63 | state_manager_->AddOnChangedCallback( |
| 64 | base::Bind(&Manager::OnStateChanged, weak_ptr_factory_.GetWeakPtr())); |
Alex Vakulenko | 07216fe | 2014-09-19 15:31:09 -0700 | [diff] [blame] | 65 | state_manager_->Startup(); |
Vitaly Buka | ee7a3af | 2015-05-14 16:57:23 -0700 | [diff] [blame] | 66 | |
| 67 | std::unique_ptr<BuffetConfig> config{new BuffetConfig{state_path}}; |
| 68 | config->AddOnChangedCallback( |
| 69 | base::Bind(&Manager::OnConfigChanged, weak_ptr_factory_.GetWeakPtr())); |
Christopher Wiley | 583d64b | 2015-03-24 14:30:17 -0700 | [diff] [blame] | 70 | config->Load(config_path); |
Vitaly Buka | ee7a3af | 2015-05-14 16:57:23 -0700 | [diff] [blame] | 71 | |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 72 | // TODO(avakulenko): Figure out security implications of storing |
| 73 | // device info state data unencrypted. |
Vitaly Buka | 72410b2 | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 74 | device_info_.reset(new DeviceRegistrationInfo( |
| 75 | command_manager_, state_manager_, std::move(config), |
Vitaly Buka | ee7a3af | 2015-05-14 16:57:23 -0700 | [diff] [blame] | 76 | chromeos::http::Transport::CreateDefault(), xmpp_enabled)); |
| 77 | device_info_->AddOnRegistrationChangedCallback(base::Bind( |
| 78 | &Manager::OnRegistrationChanged, weak_ptr_factory_.GetWeakPtr())); |
Vitaly Buka | 72410b2 | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 79 | |
Vitaly Buka | 2f7efdb | 2015-05-27 16:00:21 -0700 | [diff] [blame^] | 80 | base_api_handler_.reset(new BaseApiHandler{ |
| 81 | device_info_->AsWeakPtr(), state_manager_, command_manager_}); |
Vitaly Buka | 72410b2 | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 82 | |
Vitaly Buka | ee7a3af | 2015-05-14 16:57:23 -0700 | [diff] [blame] | 83 | device_info_->Start(); |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 84 | dbus_adaptor_.RegisterWithDBusObject(&dbus_object_); |
| 85 | dbus_object_.RegisterAsync(cb); |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 88 | void Manager::CheckDeviceRegistered(DBusMethodResponse<std::string> response) { |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 89 | LOG(INFO) << "Received call to Manager.CheckDeviceRegistered()"; |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 90 | chromeos::ErrorPtr error; |
Nathan Bullock | 5e022a3 | 2015-04-08 15:13:07 -0400 | [diff] [blame] | 91 | bool registered = device_info_->HaveRegistrationCredentials(&error); |
Alex Vakulenko | b3aac25 | 2014-05-07 17:35:24 -0700 | [diff] [blame] | 92 | // If it fails due to any reason other than 'device not registered', |
| 93 | // treat it as a real error and report it to the caller. |
| 94 | if (!registered && |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 95 | !error->HasError(kErrorDomainGCD, "device_not_registered")) { |
| 96 | response->ReplyWithError(error.get()); |
| 97 | return; |
Alex Vakulenko | b3aac25 | 2014-05-07 17:35:24 -0700 | [diff] [blame] | 98 | } |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 99 | |
Vitaly Buka | ee7a3af | 2015-05-14 16:57:23 -0700 | [diff] [blame] | 100 | response->Return(registered ? device_info_->GetConfig().device_id() |
| 101 | : std::string()); |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 104 | void Manager::GetDeviceInfo(DBusMethodResponse<std::string> response) { |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 105 | LOG(INFO) << "Received call to Manager.GetDeviceInfo()"; |
| 106 | |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 107 | chromeos::ErrorPtr error; |
| 108 | auto device_info = device_info_->GetDeviceInfo(&error); |
| 109 | if (!device_info) { |
| 110 | response->ReplyWithError(error.get()); |
| 111 | return; |
| 112 | } |
Alex Vakulenko | b3aac25 | 2014-05-07 17:35:24 -0700 | [diff] [blame] | 113 | |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 114 | std::string device_info_str; |
Nathan Bullock | 4b6c0fb | 2015-04-01 15:32:58 -0400 | [diff] [blame] | 115 | base::JSONWriter::WriteWithOptions(device_info.get(), |
| 116 | base::JSONWriter::OPTIONS_PRETTY_PRINT, &device_info_str); |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 117 | response->Return(device_info_str); |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 120 | void Manager::RegisterDevice(DBusMethodResponse<std::string> response, |
Vitaly Buka | cad2e33 | 2015-05-14 23:33:32 -0700 | [diff] [blame] | 121 | const std::string& ticket_id) { |
Anton Muhin | beb1c5b | 2014-10-16 18:59:57 +0400 | [diff] [blame] | 122 | LOG(INFO) << "Received call to Manager.RegisterDevice()"; |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 123 | |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 124 | chromeos::ErrorPtr error; |
Vitaly Buka | cad2e33 | 2015-05-14 23:33:32 -0700 | [diff] [blame] | 125 | std::string device_id = device_info_->RegisterDevice(ticket_id, &error); |
David Zeuthen | 1dbad47 | 2015-02-12 15:24:21 -0500 | [diff] [blame] | 126 | if (!device_id.empty()) { |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 127 | response->Return(device_id); |
David Zeuthen | 1dbad47 | 2015-02-12 15:24:21 -0500 | [diff] [blame] | 128 | return; |
| 129 | } |
| 130 | if (!error) { |
| 131 | // TODO(zeuthen): This can be changed to CHECK(error) once |
| 132 | // RegisterDevice() has been fixed to set |error| when failing. |
Vitaly Buka | 7ad8ffb | 2015-03-20 09:46:57 -0700 | [diff] [blame] | 133 | chromeos::Error::AddTo(&error, FROM_HERE, kErrorDomainGCD, "internal_error", |
David Zeuthen | 1dbad47 | 2015-02-12 15:24:21 -0500 | [diff] [blame] | 134 | "device_id empty but error not set"); |
| 135 | } |
| 136 | response->ReplyWithError(error.get()); |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 139 | void Manager::UpdateState(DBusMethodResponse<> response, |
| 140 | const chromeos::VariantDictionary& property_set) { |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 141 | chromeos::ErrorPtr error; |
Vitaly Buka | 247620b | 2015-05-26 15:42:20 -0700 | [diff] [blame] | 142 | if (!state_manager_->SetProperties(property_set, &error)) |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 143 | response->ReplyWithError(error.get()); |
| 144 | else |
| 145 | response->Return(); |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Alex Vakulenko | 61ad4db | 2015-01-20 10:50:04 -0800 | [diff] [blame] | 148 | bool Manager::GetState(chromeos::ErrorPtr* error, std::string* state) { |
| 149 | auto json = state_manager_->GetStateValuesAsJson(error); |
| 150 | if (!json) |
| 151 | return false; |
Nathan Bullock | 4b6c0fb | 2015-04-01 15:32:58 -0400 | [diff] [blame] | 152 | base::JSONWriter::WriteWithOptions( |
| 153 | json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, state); |
Alex Vakulenko | 61ad4db | 2015-01-20 10:50:04 -0800 | [diff] [blame] | 154 | return true; |
| 155 | } |
| 156 | |
Vitaly Buka | 64fc5fc | 2015-03-24 12:42:24 -0700 | [diff] [blame] | 157 | void Manager::AddCommand(DBusMethodResponse<std::string> response, |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 158 | const std::string& json_command) { |
Anton Muhin | 5191e81 | 2014-10-30 17:49:48 +0400 | [diff] [blame] | 159 | static int next_id = 0; |
Alex Vakulenko | 665c885 | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 160 | std::string error_message; |
| 161 | std::unique_ptr<base::Value> value(base::JSONReader::ReadAndReturnError( |
| 162 | json_command, base::JSON_PARSE_RFC, nullptr, &error_message)); |
| 163 | if (!value) { |
Alex Vakulenko | ac8037d | 2014-11-11 11:42:05 -0800 | [diff] [blame] | 164 | response->ReplyWithError(FROM_HERE, chromeos::errors::json::kDomain, |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 165 | chromeos::errors::json::kParseError, |
| 166 | error_message); |
Alex Vakulenko | 665c885 | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 167 | return; |
| 168 | } |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 169 | chromeos::ErrorPtr error; |
Alex Vakulenko | 665c885 | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 170 | auto command_instance = buffet::CommandInstance::FromJson( |
Alex Vakulenko | f784e21 | 2015-04-20 12:33:52 -0700 | [diff] [blame] | 171 | value.get(), commands::attributes::kCommand_Visibility_Local, |
Alex Vakulenko | d1978d3 | 2015-04-29 17:33:26 -0700 | [diff] [blame] | 172 | command_manager_->GetCommandDictionary(), nullptr, &error); |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 173 | if (!command_instance) { |
| 174 | response->ReplyWithError(error.get()); |
| 175 | return; |
| 176 | } |
Vitaly Buka | 64fc5fc | 2015-03-24 12:42:24 -0700 | [diff] [blame] | 177 | std::string id = std::to_string(++next_id); |
| 178 | command_instance->SetID(id); |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 179 | command_manager_->AddCommand(std::move(command_instance)); |
Vitaly Buka | 64fc5fc | 2015-03-24 12:42:24 -0700 | [diff] [blame] | 180 | response->Return(id); |
Alex Vakulenko | 665c885 | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Vitaly Buka | 3886e8f | 2015-03-24 11:39:40 -0700 | [diff] [blame] | 183 | void Manager::GetCommand(DBusMethodResponse<std::string> response, |
| 184 | const std::string& id) { |
| 185 | const CommandInstance* command = command_manager_->FindCommand(id); |
| 186 | if (!command) { |
| 187 | response->ReplyWithError(FROM_HERE, kErrorDomainGCD, "unknown_command", |
| 188 | "Can't find command with id: " + id); |
| 189 | return; |
| 190 | } |
| 191 | std::string command_str; |
Nathan Bullock | 4b6c0fb | 2015-04-01 15:32:58 -0400 | [diff] [blame] | 192 | base::JSONWriter::WriteWithOptions(command->ToJson().get(), |
| 193 | base::JSONWriter::OPTIONS_PRETTY_PRINT, &command_str); |
Vitaly Buka | 3886e8f | 2015-03-24 11:39:40 -0700 | [diff] [blame] | 194 | response->Return(command_str); |
| 195 | } |
| 196 | |
Alex Vakulenko | e03af6d | 2015-04-20 11:00:54 -0700 | [diff] [blame] | 197 | void Manager::SetCommandVisibility( |
Alex Vakulenko | 41f73a9 | 2015-04-24 18:09:32 -0700 | [diff] [blame] | 198 | std::unique_ptr<chromeos::dbus_utils::DBusMethodResponse<>> response, |
Alex Vakulenko | e03af6d | 2015-04-20 11:00:54 -0700 | [diff] [blame] | 199 | const std::vector<std::string>& in_names, |
| 200 | const std::string& in_visibility) { |
| 201 | CommandDefinition::Visibility visibility; |
| 202 | chromeos::ErrorPtr error; |
| 203 | if (!visibility.FromString(in_visibility, &error)) { |
| 204 | response->ReplyWithError(error.get()); |
| 205 | return; |
| 206 | } |
| 207 | if (!command_manager_->SetCommandVisibility(in_names, visibility, &error)) { |
| 208 | response->ReplyWithError(error.get()); |
| 209 | return; |
| 210 | } |
| 211 | response->Return(); |
| 212 | } |
| 213 | |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 214 | std::string Manager::TestMethod(const std::string& message) { |
Alex Vakulenko | 7a1dc0b | 2014-08-15 11:45:46 -0700 | [diff] [blame] | 215 | LOG(INFO) << "Received call to test method: " << message; |
| 216 | return message; |
Christopher Wiley | b76eb29 | 2014-05-05 16:09:16 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Vitaly Buka | fa94706 | 2015-04-17 00:41:31 -0700 | [diff] [blame] | 219 | bool Manager::UpdateDeviceInfo(chromeos::ErrorPtr* error, |
| 220 | const std::string& in_name, |
| 221 | const std::string& in_description, |
| 222 | const std::string& in_location) { |
| 223 | return device_info_->UpdateDeviceInfo(in_name, in_description, in_location, |
| 224 | error); |
Christopher Wiley | c900e48 | 2015-02-15 15:42:04 -0800 | [diff] [blame] | 225 | } |
| 226 | |
Vitaly Buka | ff81db6 | 2015-05-14 21:25:45 -0700 | [diff] [blame] | 227 | bool Manager::UpdateServiceConfig(chromeos::ErrorPtr* error, |
| 228 | const std::string& client_id, |
| 229 | const std::string& client_secret, |
| 230 | const std::string& api_key, |
| 231 | const std::string& oauth_url, |
| 232 | const std::string& service_url) { |
| 233 | return device_info_->UpdateServiceConfig(client_id, client_secret, api_key, |
| 234 | oauth_url, service_url, error); |
| 235 | } |
| 236 | |
Vitaly Buka | aabadee | 2015-03-18 23:33:44 -0700 | [diff] [blame] | 237 | void Manager::OnCommandDefsChanged() { |
Alex Vakulenko | 9ea5a32 | 2015-04-17 15:35:34 -0700 | [diff] [blame] | 238 | // Limit only to commands that are visible to the local clients. |
| 239 | auto commands = command_manager_->GetCommandDictionary().GetCommandsAsJson( |
| 240 | [](const buffet::CommandDefinition* def) { |
| 241 | return def->GetVisibility().local; |
Vitaly Buka | dbb8c35 | 2015-05-27 09:27:08 -0700 | [diff] [blame] | 242 | }, true, nullptr); |
Vitaly Buka | aabadee | 2015-03-18 23:33:44 -0700 | [diff] [blame] | 243 | CHECK(commands); |
| 244 | std::string json; |
Nathan Bullock | 4b6c0fb | 2015-04-01 15:32:58 -0400 | [diff] [blame] | 245 | base::JSONWriter::WriteWithOptions(commands.get(), |
| 246 | base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); |
Vitaly Buka | aabadee | 2015-03-18 23:33:44 -0700 | [diff] [blame] | 247 | dbus_adaptor_.SetCommandDefs(json); |
| 248 | } |
| 249 | |
Vitaly Buka | dbb8c35 | 2015-05-27 09:27:08 -0700 | [diff] [blame] | 250 | void Manager::OnStateChanged() { |
| 251 | auto state = state_manager_->GetStateValuesAsJson(nullptr); |
| 252 | CHECK(state); |
| 253 | std::string json; |
| 254 | base::JSONWriter::WriteWithOptions( |
| 255 | state.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); |
| 256 | dbus_adaptor_.SetState(json); |
| 257 | } |
| 258 | |
Vitaly Buka | ee7a3af | 2015-05-14 16:57:23 -0700 | [diff] [blame] | 259 | void Manager::OnRegistrationChanged(RegistrationStatus status) { |
| 260 | dbus_adaptor_.SetStatus(StatusToString(status)); |
| 261 | } |
| 262 | |
| 263 | void Manager::OnConfigChanged(const BuffetConfig& config) { |
| 264 | dbus_adaptor_.SetDeviceId(config.device_id()); |
| 265 | dbus_adaptor_.SetOemName(config.oem_name()); |
| 266 | dbus_adaptor_.SetModelName(config.model_name()); |
| 267 | dbus_adaptor_.SetModelId(config.model_id()); |
| 268 | dbus_adaptor_.SetName(config.name()); |
| 269 | dbus_adaptor_.SetDescription(config.description()); |
| 270 | dbus_adaptor_.SetLocation(config.location()); |
| 271 | dbus_adaptor_.SetAnonymousAccessRole(config.local_anonymous_access_role()); |
| 272 | } |
| 273 | |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 274 | } // namespace buffet |