Christopher Wiley | 4b5f04c | 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 | 7c3226e | 2014-05-07 17:35:24 -0700 | [diff] [blame] | 7 | #include <map> |
Alex Vakulenko | ec41a0c | 2015-04-17 15:35:34 -0700 | [diff] [blame] | 8 | #include <set> |
Alex Vakulenko | 7c3226e | 2014-05-07 17:35:24 -0700 | [diff] [blame] | 9 | #include <string> |
| 10 | |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 11 | #include <base/bind.h> |
| 12 | #include <base/bind_helpers.h> |
Alex Vakulenko | 4f7778e | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 13 | #include <base/json/json_reader.h> |
Christopher Wiley | 2ffa004 | 2014-05-05 16:09:16 -0700 | [diff] [blame] | 14 | #include <base/json/json_writer.h> |
Christopher Wiley | 8994e01 | 2015-02-06 17:51:43 -0800 | [diff] [blame] | 15 | #include <base/time/time.h> |
Alex Vakulenko | 24e5f5d | 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 | 53e882a | 2014-11-22 05:59:14 +0400 | [diff] [blame] | 19 | #include <chromeos/key_value_store.h> |
Christopher Wiley | 2ffa004 | 2014-05-05 16:09:16 -0700 | [diff] [blame] | 20 | #include <dbus/bus.h> |
Christopher Wiley | 54028f9 | 2014-04-01 17:33:29 -0700 | [diff] [blame] | 21 | #include <dbus/object_path.h> |
Alex Vakulenko | f3d77e5 | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 22 | #include <dbus/values_util.h> |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 23 | |
Vitaly Buka | e74fe3c | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 24 | #include "buffet/base_api_handler.h" |
Alex Vakulenko | 4f7778e | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 25 | #include "buffet/commands/command_instance.h" |
Alex Vakulenko | acec6aa | 2015-04-20 11:00:54 -0700 | [diff] [blame] | 26 | #include "buffet/commands/schema_constants.h" |
Alex Vakulenko | ecf961a | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 27 | #include "buffet/states/state_change_queue.h" |
Alex Vakulenko | 95877b5 | 2014-09-19 15:31:09 -0700 | [diff] [blame] | 28 | #include "buffet/states/state_manager.h" |
Christopher Wiley | 357deca | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 29 | #include "buffet/storage_impls.h" |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 30 | |
Christopher Wiley | 68c07cc | 2014-07-29 14:07:10 -0700 | [diff] [blame] | 31 | using chromeos::dbus_utils::AsyncEventSequencer; |
Christopher Wiley | 1aa980e | 2014-08-11 10:51:20 -0700 | [diff] [blame] | 32 | using chromeos::dbus_utils::ExportedObjectManager; |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 33 | |
| 34 | namespace buffet { |
| 35 | |
Alex Vakulenko | ecf961a | 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 | b635153 | 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 | 91cc715 | 2015-03-20 09:46:57 -0700 | [diff] [blame] | 44 | org::chromium::Buffet::ManagerAdaptor::GetObjectPath()) { |
| 45 | } |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 46 | |
Vitaly Buka | 91cc715 | 2015-03-20 09:46:57 -0700 | [diff] [blame] | 47 | Manager::~Manager() { |
| 48 | } |
Alex Vakulenko | ecf961a | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 49 | |
Vitaly Buka | e46525b | 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 | 05fa681 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 55 | command_manager_ = |
| 56 | std::make_shared<CommandManager>(dbus_object_.GetObjectManager()); |
Vitaly Buka | e43871f | 2015-05-11 15:41:33 -0700 | [diff] [blame] | 57 | command_manager_->AddOnCommandDefChanged(base::Bind( |
| 58 | &Manager::OnCommandDefsChanged, weak_ptr_factory_.GetWeakPtr())); |
Christopher Wiley | c39f4a3 | 2015-02-12 13:42:16 -0800 | [diff] [blame] | 59 | command_manager_->Startup(base::FilePath{"/etc/buffet"}, |
| 60 | test_definitions_path); |
Vitaly Buka | e74fe3c | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 61 | state_change_queue_.reset(new StateChangeQueue(kMaxStateChangeQueueSize)); |
Alex Vakulenko | ecf961a | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 62 | state_manager_ = std::make_shared<StateManager>(state_change_queue_.get()); |
Alex Vakulenko | 95877b5 | 2014-09-19 15:31:09 -0700 | [diff] [blame] | 63 | state_manager_->Startup(); |
Vitaly Buka | bf4ba65 | 2015-05-14 16:57:23 -0700 | [diff] [blame^] | 64 | |
| 65 | std::unique_ptr<BuffetConfig> config{new BuffetConfig{state_path}}; |
| 66 | config->AddOnChangedCallback( |
| 67 | base::Bind(&Manager::OnConfigChanged, weak_ptr_factory_.GetWeakPtr())); |
Christopher Wiley | b024ca9 | 2015-03-24 14:30:17 -0700 | [diff] [blame] | 68 | config->Load(config_path); |
Vitaly Buka | bf4ba65 | 2015-05-14 16:57:23 -0700 | [diff] [blame^] | 69 | |
Christopher Wiley | 357deca | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 70 | // TODO(avakulenko): Figure out security implications of storing |
| 71 | // device info state data unencrypted. |
Vitaly Buka | e74fe3c | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 72 | device_info_.reset(new DeviceRegistrationInfo( |
| 73 | command_manager_, state_manager_, std::move(config), |
Vitaly Buka | bf4ba65 | 2015-05-14 16:57:23 -0700 | [diff] [blame^] | 74 | chromeos::http::Transport::CreateDefault(), xmpp_enabled)); |
| 75 | device_info_->AddOnRegistrationChangedCallback(base::Bind( |
| 76 | &Manager::OnRegistrationChanged, weak_ptr_factory_.GetWeakPtr())); |
Vitaly Buka | e74fe3c | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 77 | |
| 78 | base_api_handler_.reset( |
| 79 | new BaseApiHandler{device_info_->AsWeakPtr(), command_manager_}); |
| 80 | |
Vitaly Buka | bf4ba65 | 2015-05-14 16:57:23 -0700 | [diff] [blame^] | 81 | device_info_->Start(); |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 82 | dbus_adaptor_.RegisterWithDBusObject(&dbus_object_); |
| 83 | dbus_object_.RegisterAsync(cb); |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 86 | void Manager::CheckDeviceRegistered(DBusMethodResponse<std::string> response) { |
Alex Vakulenko | f3d77e5 | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 87 | LOG(INFO) << "Received call to Manager.CheckDeviceRegistered()"; |
Alex Vakulenko | b91dcfe | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 88 | chromeos::ErrorPtr error; |
Nathan Bullock | eec5846 | 2015-04-08 15:13:07 -0400 | [diff] [blame] | 89 | bool registered = device_info_->HaveRegistrationCredentials(&error); |
Alex Vakulenko | 7c3226e | 2014-05-07 17:35:24 -0700 | [diff] [blame] | 90 | // If it fails due to any reason other than 'device not registered', |
| 91 | // treat it as a real error and report it to the caller. |
| 92 | if (!registered && |
Alex Vakulenko | b91dcfe | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 93 | !error->HasError(kErrorDomainGCD, "device_not_registered")) { |
| 94 | response->ReplyWithError(error.get()); |
| 95 | return; |
Alex Vakulenko | 7c3226e | 2014-05-07 17:35:24 -0700 | [diff] [blame] | 96 | } |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 97 | |
Vitaly Buka | bf4ba65 | 2015-05-14 16:57:23 -0700 | [diff] [blame^] | 98 | response->Return(registered ? device_info_->GetConfig().device_id() |
| 99 | : std::string()); |
Alex Vakulenko | f3d77e5 | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 102 | void Manager::GetDeviceInfo(DBusMethodResponse<std::string> response) { |
Alex Vakulenko | f3d77e5 | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 103 | LOG(INFO) << "Received call to Manager.GetDeviceInfo()"; |
| 104 | |
Alex Vakulenko | b91dcfe | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 105 | chromeos::ErrorPtr error; |
| 106 | auto device_info = device_info_->GetDeviceInfo(&error); |
| 107 | if (!device_info) { |
| 108 | response->ReplyWithError(error.get()); |
| 109 | return; |
| 110 | } |
Alex Vakulenko | 7c3226e | 2014-05-07 17:35:24 -0700 | [diff] [blame] | 111 | |
Alex Vakulenko | b91dcfe | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 112 | std::string device_info_str; |
Nathan Bullock | f5b91bf | 2015-04-01 15:32:58 -0400 | [diff] [blame] | 113 | base::JSONWriter::WriteWithOptions(device_info.get(), |
| 114 | base::JSONWriter::OPTIONS_PRETTY_PRINT, &device_info_str); |
Alex Vakulenko | b91dcfe | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 115 | response->Return(device_info_str); |
Alex Vakulenko | f3d77e5 | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 118 | void Manager::RegisterDevice(DBusMethodResponse<std::string> response, |
| 119 | const chromeos::VariantDictionary& params) { |
Anton Muhin | 9cc03fd | 2014-10-16 18:59:57 +0400 | [diff] [blame] | 120 | LOG(INFO) << "Received call to Manager.RegisterDevice()"; |
Alex Vakulenko | f3d77e5 | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 121 | |
Alex Vakulenko | b91dcfe | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 122 | chromeos::ErrorPtr error; |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 123 | std::map<std::string, std::string> str_params; |
| 124 | for (const auto& pair : params) { |
| 125 | if (!pair.second.IsTypeCompatible<std::string>()) { |
| 126 | response->ReplyWithError(FROM_HERE, chromeos::errors::dbus::kDomain, |
| 127 | DBUS_ERROR_INVALID_ARGS, |
| 128 | "String value expected"); |
| 129 | return; |
| 130 | } |
Vitaly Buka | 91cc715 | 2015-03-20 09:46:57 -0700 | [diff] [blame] | 131 | str_params.emplace_hint(str_params.end(), pair.first, |
| 132 | pair.second.Get<std::string>()); |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 133 | } |
| 134 | std::string device_id = device_info_->RegisterDevice(str_params, &error); |
David Zeuthen | 2101c08 | 2015-02-12 15:24:21 -0500 | [diff] [blame] | 135 | if (!device_id.empty()) { |
Alex Vakulenko | b91dcfe | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 136 | response->Return(device_id); |
David Zeuthen | 2101c08 | 2015-02-12 15:24:21 -0500 | [diff] [blame] | 137 | return; |
| 138 | } |
| 139 | if (!error) { |
| 140 | // TODO(zeuthen): This can be changed to CHECK(error) once |
| 141 | // RegisterDevice() has been fixed to set |error| when failing. |
Vitaly Buka | 91cc715 | 2015-03-20 09:46:57 -0700 | [diff] [blame] | 142 | chromeos::Error::AddTo(&error, FROM_HERE, kErrorDomainGCD, "internal_error", |
David Zeuthen | 2101c08 | 2015-02-12 15:24:21 -0500 | [diff] [blame] | 143 | "device_id empty but error not set"); |
| 144 | } |
| 145 | response->ReplyWithError(error.get()); |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 148 | void Manager::UpdateState(DBusMethodResponse<> response, |
| 149 | const chromeos::VariantDictionary& property_set) { |
Alex Vakulenko | b91dcfe | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 150 | chromeos::ErrorPtr error; |
Alex Vakulenko | bfc70ad | 2014-10-29 09:53:52 -0700 | [diff] [blame] | 151 | base::Time timestamp = base::Time::Now(); |
Alex Vakulenko | b91dcfe | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 152 | bool all_success = true; |
Alex Vakulenko | bfc70ad | 2014-10-29 09:53:52 -0700 | [diff] [blame] | 153 | for (const auto& pair : property_set) { |
Vitaly Buka | 91cc715 | 2015-03-20 09:46:57 -0700 | [diff] [blame] | 154 | if (!state_manager_->SetPropertyValue(pair.first, pair.second, timestamp, |
| 155 | &error)) { |
Alex Vakulenko | b91dcfe | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 156 | // Remember that an error occurred but keep going and update the rest of |
| 157 | // the properties if possible. |
| 158 | all_success = false; |
| 159 | } |
Alex Vakulenko | bfc70ad | 2014-10-29 09:53:52 -0700 | [diff] [blame] | 160 | } |
Alex Vakulenko | b91dcfe | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 161 | if (!all_success) |
| 162 | response->ReplyWithError(error.get()); |
| 163 | else |
| 164 | response->Return(); |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Alex Vakulenko | ceab177 | 2015-01-20 10:50:04 -0800 | [diff] [blame] | 167 | bool Manager::GetState(chromeos::ErrorPtr* error, std::string* state) { |
| 168 | auto json = state_manager_->GetStateValuesAsJson(error); |
| 169 | if (!json) |
| 170 | return false; |
Nathan Bullock | f5b91bf | 2015-04-01 15:32:58 -0400 | [diff] [blame] | 171 | base::JSONWriter::WriteWithOptions( |
| 172 | json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, state); |
Alex Vakulenko | ceab177 | 2015-01-20 10:50:04 -0800 | [diff] [blame] | 173 | return true; |
| 174 | } |
| 175 | |
Vitaly Buka | 59af7ac | 2015-03-24 12:42:24 -0700 | [diff] [blame] | 176 | void Manager::AddCommand(DBusMethodResponse<std::string> response, |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 177 | const std::string& json_command) { |
Anton Muhin | d014d8b | 2014-10-30 17:49:48 +0400 | [diff] [blame] | 178 | static int next_id = 0; |
Alex Vakulenko | 4f7778e | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 179 | std::string error_message; |
| 180 | std::unique_ptr<base::Value> value(base::JSONReader::ReadAndReturnError( |
| 181 | json_command, base::JSON_PARSE_RFC, nullptr, &error_message)); |
| 182 | if (!value) { |
Alex Vakulenko | 90b3da9 | 2014-11-11 11:42:05 -0800 | [diff] [blame] | 183 | response->ReplyWithError(FROM_HERE, chromeos::errors::json::kDomain, |
Alex Vakulenko | b91dcfe | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 184 | chromeos::errors::json::kParseError, |
| 185 | error_message); |
Alex Vakulenko | 4f7778e | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 186 | return; |
| 187 | } |
Alex Vakulenko | b91dcfe | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 188 | chromeos::ErrorPtr error; |
Alex Vakulenko | 4f7778e | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 189 | auto command_instance = buffet::CommandInstance::FromJson( |
Alex Vakulenko | d419044 | 2015-04-20 12:33:52 -0700 | [diff] [blame] | 190 | value.get(), commands::attributes::kCommand_Visibility_Local, |
Alex Vakulenko | a031e1b | 2015-04-29 17:33:26 -0700 | [diff] [blame] | 191 | command_manager_->GetCommandDictionary(), nullptr, &error); |
Alex Vakulenko | b91dcfe | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 192 | if (!command_instance) { |
| 193 | response->ReplyWithError(error.get()); |
| 194 | return; |
| 195 | } |
Vitaly Buka | 59af7ac | 2015-03-24 12:42:24 -0700 | [diff] [blame] | 196 | std::string id = std::to_string(++next_id); |
| 197 | command_instance->SetID(id); |
Alex Vakulenko | b91dcfe | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 198 | command_manager_->AddCommand(std::move(command_instance)); |
Vitaly Buka | 59af7ac | 2015-03-24 12:42:24 -0700 | [diff] [blame] | 199 | response->Return(id); |
Alex Vakulenko | 4f7778e | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Vitaly Buka | 5515de0 | 2015-03-24 11:39:40 -0700 | [diff] [blame] | 202 | void Manager::GetCommand(DBusMethodResponse<std::string> response, |
| 203 | const std::string& id) { |
| 204 | const CommandInstance* command = command_manager_->FindCommand(id); |
| 205 | if (!command) { |
| 206 | response->ReplyWithError(FROM_HERE, kErrorDomainGCD, "unknown_command", |
| 207 | "Can't find command with id: " + id); |
| 208 | return; |
| 209 | } |
| 210 | std::string command_str; |
Nathan Bullock | f5b91bf | 2015-04-01 15:32:58 -0400 | [diff] [blame] | 211 | base::JSONWriter::WriteWithOptions(command->ToJson().get(), |
| 212 | base::JSONWriter::OPTIONS_PRETTY_PRINT, &command_str); |
Vitaly Buka | 5515de0 | 2015-03-24 11:39:40 -0700 | [diff] [blame] | 213 | response->Return(command_str); |
| 214 | } |
| 215 | |
Alex Vakulenko | acec6aa | 2015-04-20 11:00:54 -0700 | [diff] [blame] | 216 | void Manager::SetCommandVisibility( |
Alex Vakulenko | 8d78ebf | 2015-04-24 18:09:32 -0700 | [diff] [blame] | 217 | std::unique_ptr<chromeos::dbus_utils::DBusMethodResponse<>> response, |
Alex Vakulenko | acec6aa | 2015-04-20 11:00:54 -0700 | [diff] [blame] | 218 | const std::vector<std::string>& in_names, |
| 219 | const std::string& in_visibility) { |
| 220 | CommandDefinition::Visibility visibility; |
| 221 | chromeos::ErrorPtr error; |
| 222 | if (!visibility.FromString(in_visibility, &error)) { |
| 223 | response->ReplyWithError(error.get()); |
| 224 | return; |
| 225 | } |
| 226 | if (!command_manager_->SetCommandVisibility(in_names, visibility, &error)) { |
| 227 | response->ReplyWithError(error.get()); |
| 228 | return; |
| 229 | } |
| 230 | response->Return(); |
| 231 | } |
| 232 | |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 233 | std::string Manager::TestMethod(const std::string& message) { |
Alex Vakulenko | 35e3bab | 2014-08-15 11:45:46 -0700 | [diff] [blame] | 234 | LOG(INFO) << "Received call to test method: " << message; |
| 235 | return message; |
Christopher Wiley | 2ffa004 | 2014-05-05 16:09:16 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Vitaly Buka | 760d632 | 2015-04-17 00:41:31 -0700 | [diff] [blame] | 238 | bool Manager::UpdateDeviceInfo(chromeos::ErrorPtr* error, |
| 239 | const std::string& in_name, |
| 240 | const std::string& in_description, |
| 241 | const std::string& in_location) { |
| 242 | return device_info_->UpdateDeviceInfo(in_name, in_description, in_location, |
| 243 | error); |
Christopher Wiley | 2f77293 | 2015-02-15 15:42:04 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Vitaly Buka | 1fa6901 | 2015-03-18 23:33:44 -0700 | [diff] [blame] | 246 | void Manager::OnCommandDefsChanged() { |
| 247 | chromeos::ErrorPtr error; |
Alex Vakulenko | ec41a0c | 2015-04-17 15:35:34 -0700 | [diff] [blame] | 248 | // Limit only to commands that are visible to the local clients. |
| 249 | auto commands = command_manager_->GetCommandDictionary().GetCommandsAsJson( |
| 250 | [](const buffet::CommandDefinition* def) { |
| 251 | return def->GetVisibility().local; |
| 252 | }, true, &error); |
Vitaly Buka | 1fa6901 | 2015-03-18 23:33:44 -0700 | [diff] [blame] | 253 | CHECK(commands); |
| 254 | std::string json; |
Nathan Bullock | f5b91bf | 2015-04-01 15:32:58 -0400 | [diff] [blame] | 255 | base::JSONWriter::WriteWithOptions(commands.get(), |
| 256 | base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); |
Vitaly Buka | 1fa6901 | 2015-03-18 23:33:44 -0700 | [diff] [blame] | 257 | dbus_adaptor_.SetCommandDefs(json); |
| 258 | } |
| 259 | |
Vitaly Buka | bf4ba65 | 2015-05-14 16:57:23 -0700 | [diff] [blame^] | 260 | void Manager::OnRegistrationChanged(RegistrationStatus status) { |
| 261 | dbus_adaptor_.SetStatus(StatusToString(status)); |
| 262 | } |
| 263 | |
| 264 | void Manager::OnConfigChanged(const BuffetConfig& config) { |
| 265 | dbus_adaptor_.SetDeviceId(config.device_id()); |
| 266 | dbus_adaptor_.SetOemName(config.oem_name()); |
| 267 | dbus_adaptor_.SetModelName(config.model_name()); |
| 268 | dbus_adaptor_.SetModelId(config.model_id()); |
| 269 | dbus_adaptor_.SetName(config.name()); |
| 270 | dbus_adaptor_.SetDescription(config.description()); |
| 271 | dbus_adaptor_.SetLocation(config.location()); |
| 272 | dbus_adaptor_.SetAnonymousAccessRole(config.local_anonymous_access_role()); |
| 273 | } |
| 274 | |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 275 | } // namespace buffet |