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