Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -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 | |
Alex Vakulenko | af23b32 | 2014-05-08 16:25:45 -0700 | [diff] [blame] | 5 | #include <iostream> // NOLINT(readability/streams) |
Alex Vakulenko | 7a1dc0b | 2014-08-15 11:45:46 -0700 | [diff] [blame] | 6 | #include <memory> |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 7 | #include <string> |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 8 | #include <sysexits.h> |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 9 | |
Chris Sosa | ababc5c | 2014-04-09 15:42:01 -0700 | [diff] [blame] | 10 | #include <base/command_line.h> |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 11 | #include <base/logging.h> |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 12 | #include <base/memory/ref_counted.h> |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 13 | #include <base/memory/scoped_ptr.h> |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 14 | #include <base/values.h> |
Alex Vakulenko | a904434 | 2014-08-23 19:31:27 -0700 | [diff] [blame] | 15 | #include <chromeos/any.h> |
Alex Vakulenko | e4879a2 | 2014-08-20 15:47:36 -0700 | [diff] [blame] | 16 | #include <chromeos/data_encoding.h> |
Alex Vakulenko | 63cd5fa | 2014-08-27 08:04:22 -0700 | [diff] [blame] | 17 | #include <chromeos/dbus/data_serialization.h> |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 18 | #include <dbus/bus.h> |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 19 | #include <dbus/message.h> |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 20 | #include <dbus/object_proxy.h> |
Christopher Wiley | adb901d | 2014-05-07 09:58:45 -0700 | [diff] [blame] | 21 | #include <dbus/object_manager.h> |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 22 | #include <dbus/values_util.h> |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 23 | |
Alex Vakulenko | 89d9d5e | 2014-09-12 10:27:23 -0700 | [diff] [blame^] | 24 | #include "buffet/libbuffet/dbus_constants.h" |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 25 | |
Alex Vakulenko | 3379706 | 2014-05-12 15:55:25 -0700 | [diff] [blame] | 26 | using namespace buffet::dbus_constants; // NOLINT(build/namespaces) |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 27 | |
| 28 | namespace { |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 29 | static const int default_timeout_ms = 1000; |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 30 | |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 31 | void usage() { |
| 32 | std::cerr << "Possible commands:" << std::endl; |
Alex Vakulenko | 7a1dc0b | 2014-08-15 11:45:46 -0700 | [diff] [blame] | 33 | std::cerr << " " << kManagerTestMethod << " <message>" << std::endl; |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 34 | std::cerr << " " << kManagerCheckDeviceRegistered << std::endl; |
| 35 | std::cerr << " " << kManagerGetDeviceInfo << std::endl; |
| 36 | std::cerr << " " << kManagerStartRegisterDevice |
| 37 | << " param1 = val1¶m2 = val2..." << std::endl; |
| 38 | std::cerr << " " << kManagerFinishRegisterDevice |
| 39 | << " device_id" << std::endl; |
Alex Vakulenko | 665c885 | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 40 | std::cerr << " " << kManagerAddCommand |
| 41 | << " '{\"name\":\"command_name\",\"parameters\":{}}'" |
| 42 | << std::endl; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 43 | std::cerr << " " << kManagerUpdateStateMethod << std::endl; |
Christopher Wiley | adb901d | 2014-05-07 09:58:45 -0700 | [diff] [blame] | 44 | std::cerr << " " << dbus::kObjectManagerGetManagedObjects << std::endl; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 47 | class BuffetHelperProxy { |
| 48 | public: |
| 49 | int Init() { |
| 50 | dbus::Bus::Options options; |
| 51 | options.bus_type = dbus::Bus::SYSTEM; |
| 52 | bus_ = new dbus::Bus(options); |
| 53 | manager_proxy_ = bus_->GetObjectProxy( |
| 54 | kServiceName, |
| 55 | dbus::ObjectPath(kManagerServicePath)); |
Christopher Wiley | adb901d | 2014-05-07 09:58:45 -0700 | [diff] [blame] | 56 | root_proxy_ = bus_->GetObjectProxy( |
| 57 | kServiceName, |
| 58 | dbus::ObjectPath(kRootServicePath)); |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 59 | return EX_OK; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 62 | int CallTestMethod(const CommandLine::StringVector& args) { |
Alex Vakulenko | 7a1dc0b | 2014-08-15 11:45:46 -0700 | [diff] [blame] | 63 | std::string message; |
| 64 | if (!args.empty()) |
| 65 | message = args.front(); |
| 66 | |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 67 | dbus::MethodCall method_call(kManagerInterface, kManagerTestMethod); |
Alex Vakulenko | 7a1dc0b | 2014-08-15 11:45:46 -0700 | [diff] [blame] | 68 | dbus::MessageWriter writer(&method_call); |
| 69 | writer.AppendString(message); |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 70 | scoped_ptr<dbus::Response> response( |
| 71 | manager_proxy_->CallMethodAndBlock(&method_call, default_timeout_ms)); |
| 72 | if (!response) { |
| 73 | std::cout << "Failed to receive a response." << std::endl; |
| 74 | return EX_UNAVAILABLE; |
| 75 | } |
Alex Vakulenko | 7a1dc0b | 2014-08-15 11:45:46 -0700 | [diff] [blame] | 76 | dbus::MessageReader reader(response.get()); |
| 77 | std::string response_message; |
| 78 | if (!reader.PopString(&response_message)) { |
| 79 | std::cout << "No valid response." << std::endl; |
| 80 | return EX_SOFTWARE; |
| 81 | } |
| 82 | std::cout << "Received a response: " << response_message << std::endl; |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 83 | return EX_OK; |
| 84 | } |
| 85 | |
| 86 | int CallManagerCheckDeviceRegistered(const CommandLine::StringVector& args) { |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 87 | if (!args.empty()) { |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 88 | std::cerr << "Invalid number of arguments for " |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 89 | << "Manager." << kManagerCheckDeviceRegistered << std::endl; |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 90 | usage(); |
| 91 | return EX_USAGE; |
| 92 | } |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 93 | dbus::MethodCall method_call( |
| 94 | kManagerInterface, kManagerCheckDeviceRegistered); |
| 95 | |
| 96 | scoped_ptr<dbus::Response> response( |
| 97 | manager_proxy_->CallMethodAndBlock(&method_call, default_timeout_ms)); |
| 98 | if (!response) { |
| 99 | std::cout << "Failed to receive a response." << std::endl; |
| 100 | return EX_UNAVAILABLE; |
| 101 | } |
| 102 | |
| 103 | dbus::MessageReader reader(response.get()); |
| 104 | std::string device_id; |
| 105 | if (!reader.PopString(&device_id)) { |
| 106 | std::cout << "No device ID in response." << std::endl; |
| 107 | return EX_SOFTWARE; |
| 108 | } |
| 109 | |
| 110 | std::cout << "Device ID: " |
| 111 | << (device_id.empty() ? std::string("<unregistered>") : device_id) |
| 112 | << std::endl; |
| 113 | return EX_OK; |
| 114 | } |
| 115 | |
| 116 | int CallManagerGetDeviceInfo(const CommandLine::StringVector& args) { |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 117 | if (!args.empty()) { |
| 118 | std::cerr << "Invalid number of arguments for " |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 119 | << "Manager." << kManagerGetDeviceInfo << std::endl; |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 120 | usage(); |
| 121 | return EX_USAGE; |
| 122 | } |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 123 | dbus::MethodCall method_call( |
| 124 | kManagerInterface, kManagerGetDeviceInfo); |
| 125 | |
| 126 | scoped_ptr<dbus::Response> response( |
| 127 | manager_proxy_->CallMethodAndBlock(&method_call, default_timeout_ms)); |
| 128 | if (!response) { |
| 129 | std::cout << "Failed to receive a response." << std::endl; |
| 130 | return EX_UNAVAILABLE; |
| 131 | } |
| 132 | |
| 133 | dbus::MessageReader reader(response.get()); |
| 134 | std::string device_info; |
| 135 | if (!reader.PopString(&device_info)) { |
| 136 | std::cout << "No device info in response." << std::endl; |
| 137 | return EX_SOFTWARE; |
| 138 | } |
| 139 | |
| 140 | std::cout << "Device Info: " |
| 141 | << (device_info.empty() ? std::string("<unregistered>") : device_info) |
| 142 | << std::endl; |
| 143 | return EX_OK; |
| 144 | } |
| 145 | |
| 146 | int CallManagerStartRegisterDevice(const CommandLine::StringVector& args) { |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 147 | if (args.size() > 1) { |
| 148 | std::cerr << "Invalid number of arguments for " |
| 149 | << "Manager." << kManagerStartRegisterDevice << std::endl; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 150 | usage(); |
Chris Sosa | ababc5c | 2014-04-09 15:42:01 -0700 | [diff] [blame] | 151 | return EX_USAGE; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 152 | } |
Alex Vakulenko | 7a1dc0b | 2014-08-15 11:45:46 -0700 | [diff] [blame] | 153 | chromeos::dbus_utils::Dictionary params; |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 154 | |
| 155 | if (!args.empty()) { |
Alex Vakulenko | e4879a2 | 2014-08-20 15:47:36 -0700 | [diff] [blame] | 156 | auto key_values = chromeos::data_encoding::WebParamsDecode(args.front()); |
Alex Vakulenko | a0424dd | 2014-06-13 16:10:17 -0700 | [diff] [blame] | 157 | for (const auto& pair : key_values) { |
Alex Vakulenko | a904434 | 2014-08-23 19:31:27 -0700 | [diff] [blame] | 158 | params.insert(std::make_pair(pair.first, chromeos::Any(pair.second))); |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 162 | dbus::MethodCall method_call( |
| 163 | kManagerInterface, kManagerStartRegisterDevice); |
| 164 | dbus::MessageWriter writer(&method_call); |
Alex Vakulenko | a904434 | 2014-08-23 19:31:27 -0700 | [diff] [blame] | 165 | CHECK(chromeos::dbus_utils::AppendValueToWriter(&writer, params)) |
| 166 | << "Failed to send the parameters over D-Bus"; |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 167 | |
| 168 | static const int timeout_ms = 3000; |
| 169 | scoped_ptr<dbus::Response> response( |
| 170 | manager_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); |
| 171 | if (!response) { |
| 172 | std::cout << "Failed to receive a response." << std::endl; |
| 173 | return EX_UNAVAILABLE; |
| 174 | } |
| 175 | |
| 176 | dbus::MessageReader reader(response.get()); |
| 177 | std::string info; |
| 178 | if (!reader.PopString(&info)) { |
| 179 | std::cout << "No valid response." << std::endl; |
| 180 | return EX_SOFTWARE; |
| 181 | } |
| 182 | |
| 183 | std::cout << "Registration started: " << info << std::endl; |
| 184 | return EX_OK; |
| 185 | } |
| 186 | |
| 187 | int CallManagerFinishRegisterDevice(const CommandLine::StringVector& args) { |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 188 | if (args.size() > 1) { |
| 189 | std::cerr << "Invalid number of arguments for " |
| 190 | << "Manager." << kManagerFinishRegisterDevice << std::endl; |
| 191 | usage(); |
| 192 | return EX_USAGE; |
| 193 | } |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 194 | dbus::MethodCall method_call( |
| 195 | kManagerInterface, kManagerFinishRegisterDevice); |
| 196 | dbus::MessageWriter writer(&method_call); |
| 197 | std::string user_auth_code; |
| 198 | if (!args.empty()) { user_auth_code = args.front(); } |
| 199 | writer.AppendString(user_auth_code); |
| 200 | static const int timeout_ms = 10000; |
| 201 | scoped_ptr<dbus::Response> response( |
| 202 | manager_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); |
| 203 | if (!response) { |
| 204 | std::cout << "Failed to receive a response." << std::endl; |
| 205 | return EX_UNAVAILABLE; |
| 206 | } |
| 207 | |
| 208 | dbus::MessageReader reader(response.get()); |
| 209 | std::string device_id; |
| 210 | if (!reader.PopString(&device_id)) { |
| 211 | std::cout << "No device ID in response." << std::endl; |
| 212 | return EX_SOFTWARE; |
| 213 | } |
| 214 | |
| 215 | std::cout << "Device ID is " |
| 216 | << (device_id.empty() ? std::string("<unregistered>") : device_id) |
| 217 | << std::endl; |
| 218 | return EX_OK; |
| 219 | } |
| 220 | |
| 221 | int CallManagerUpdateState(const CommandLine::StringVector& args) { |
Chris Sosa | ababc5c | 2014-04-09 15:42:01 -0700 | [diff] [blame] | 222 | if (args.size() != 1) { |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 223 | std::cerr << "Invalid number of arguments for " |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 224 | << "Manager." << kManagerUpdateStateMethod << std::endl; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 225 | usage(); |
Chris Sosa | ababc5c | 2014-04-09 15:42:01 -0700 | [diff] [blame] | 226 | return EX_USAGE; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 227 | } |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 228 | dbus::MethodCall method_call( |
| 229 | kManagerInterface, kManagerUpdateStateMethod); |
| 230 | dbus::MessageWriter writer(&method_call); |
| 231 | writer.AppendString(args.front()); |
| 232 | scoped_ptr<dbus::Response> response( |
| 233 | manager_proxy_->CallMethodAndBlock(&method_call, default_timeout_ms)); |
| 234 | if (!response) { |
| 235 | std::cout << "Failed to receive a response." << std::endl; |
| 236 | return EX_UNAVAILABLE; |
| 237 | } |
| 238 | return EX_OK; |
| 239 | } |
| 240 | |
Alex Vakulenko | 665c885 | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 241 | int CallManagerAddCommand(const CommandLine::StringVector& args) { |
| 242 | if (args.size() != 1) { |
| 243 | std::cerr << "Invalid number of arguments for " |
| 244 | << "Manager." << kManagerAddCommand << std::endl; |
| 245 | usage(); |
| 246 | return EX_USAGE; |
| 247 | } |
| 248 | dbus::MethodCall method_call( |
| 249 | kManagerInterface, kManagerAddCommand); |
| 250 | dbus::MessageWriter writer(&method_call); |
| 251 | writer.AppendString(args.front()); |
| 252 | scoped_ptr<dbus::Response> response( |
| 253 | manager_proxy_->CallMethodAndBlock(&method_call, default_timeout_ms)); |
| 254 | if (!response) { |
| 255 | std::cout << "Failed to receive a response." << std::endl; |
| 256 | return EX_UNAVAILABLE; |
| 257 | } |
| 258 | return EX_OK; |
| 259 | } |
| 260 | |
Christopher Wiley | adb901d | 2014-05-07 09:58:45 -0700 | [diff] [blame] | 261 | int CallRootGetManagedObjects(const CommandLine::StringVector& args) { |
| 262 | if (!args.empty()) { |
| 263 | std::cerr << "Invalid number of arguments for " |
| 264 | << dbus::kObjectManagerGetManagedObjects << std::endl; |
| 265 | usage(); |
| 266 | return EX_USAGE; |
| 267 | } |
| 268 | dbus::MethodCall method_call( |
| 269 | dbus::kObjectManagerInterface, dbus::kObjectManagerGetManagedObjects); |
| 270 | scoped_ptr<dbus::Response> response( |
| 271 | root_proxy_->CallMethodAndBlock(&method_call, default_timeout_ms)); |
| 272 | if (!response) { |
| 273 | std::cout << "Failed to receive a response." << std::endl; |
| 274 | return EX_UNAVAILABLE; |
| 275 | } |
| 276 | std::cout << response->ToString() << std::endl; |
| 277 | return EX_OK; |
| 278 | } |
| 279 | |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 280 | private: |
| 281 | scoped_refptr<dbus::Bus> bus_; |
Alex Vakulenko | a0424dd | 2014-06-13 16:10:17 -0700 | [diff] [blame] | 282 | dbus::ObjectProxy* manager_proxy_{nullptr}; |
| 283 | dbus::ObjectProxy* root_proxy_{nullptr}; |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 284 | }; |
| 285 | |
Alex Vakulenko | 3379706 | 2014-05-12 15:55:25 -0700 | [diff] [blame] | 286 | } // namespace |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 287 | |
| 288 | int main(int argc, char** argv) { |
| 289 | CommandLine::Init(argc, argv); |
| 290 | CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 291 | CommandLine::StringVector args = cl->GetArgs(); |
| 292 | if (args.empty()) { |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 293 | usage(); |
Chris Sosa | ababc5c | 2014-04-09 15:42:01 -0700 | [diff] [blame] | 294 | return EX_USAGE; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 297 | // Pop the command off of the args list. |
| 298 | std::string command = args.front(); |
| 299 | args.erase(args.begin()); |
| 300 | int err = EX_USAGE; |
| 301 | BuffetHelperProxy helper; |
| 302 | err = helper.Init(); |
| 303 | if (err) { |
| 304 | std::cerr << "Error initializing proxies." << std::endl; |
| 305 | return err; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 308 | if (command.compare(kManagerTestMethod) == 0) { |
| 309 | err = helper.CallTestMethod(args); |
| 310 | } else if (command.compare(kManagerCheckDeviceRegistered) == 0 || |
| 311 | command.compare("cr") == 0) { |
| 312 | err = helper.CallManagerCheckDeviceRegistered(args); |
| 313 | } else if (command.compare(kManagerGetDeviceInfo) == 0 || |
| 314 | command.compare("di") == 0) { |
| 315 | err = helper.CallManagerGetDeviceInfo(args); |
| 316 | } else if (command.compare(kManagerStartRegisterDevice) == 0 || |
| 317 | command.compare("sr") == 0) { |
| 318 | err = helper.CallManagerStartRegisterDevice(args); |
| 319 | } else if (command.compare(kManagerFinishRegisterDevice) == 0 || |
| 320 | command.compare("fr") == 0) { |
| 321 | err = helper.CallManagerFinishRegisterDevice(args); |
| 322 | } else if (command.compare(kManagerUpdateStateMethod) == 0 || |
| 323 | command.compare("us") == 0) { |
| 324 | err = helper.CallManagerUpdateState(args); |
Alex Vakulenko | 665c885 | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 325 | } else if (command.compare(kManagerAddCommand) == 0 || |
| 326 | command.compare("ac") == 0) { |
| 327 | err = helper.CallManagerAddCommand(args); |
Christopher Wiley | adb901d | 2014-05-07 09:58:45 -0700 | [diff] [blame] | 328 | } else if (command.compare(dbus::kObjectManagerGetManagedObjects) == 0) { |
| 329 | err = helper.CallRootGetManagedObjects(args); |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 330 | } else { |
| 331 | std::cerr << "Unknown command: " << command << std::endl; |
| 332 | usage(); |
| 333 | } |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 334 | |
Christopher Wiley | 48e3728 | 2014-05-08 14:43:58 -0700 | [diff] [blame] | 335 | if (err) { |
| 336 | std::cerr << "Done, with errors." << std::endl; |
| 337 | } else { |
| 338 | std::cout << "Done." << std::endl; |
| 339 | } |
| 340 | return err; |
| 341 | } |