Alex Vakulenko | 89d9d5e | 2014-09-12 10:27:23 -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 "libbuffet/command.h" |
| 6 | |
| 7 | #include <chromeos/dbus/dbus_method_invoker.h> |
| 8 | |
| 9 | #include "libbuffet/command_listener.h" |
| 10 | #include "libbuffet/dbus_constants.h" |
| 11 | #include "libbuffet/private/command_property_set.h" |
| 12 | |
| 13 | namespace buffet { |
| 14 | |
| 15 | Command::Command(const dbus::ObjectPath& object_path, |
| 16 | CommandListener* command_listener) |
| 17 | : object_path_(object_path), command_listener_(command_listener) {} |
| 18 | |
| 19 | const std::string& Command::GetID() const { |
| 20 | return GetProperties()->id.value(); |
| 21 | } |
| 22 | |
| 23 | const std::string& Command::GetName() const { |
| 24 | return GetProperties()->name.value(); |
| 25 | } |
| 26 | |
| 27 | const std::string& Command::GetCategory() const { |
| 28 | return GetProperties()->category.value(); |
| 29 | } |
| 30 | |
Alex Vakulenko | 576c979 | 2014-09-22 16:49:45 -0700 | [diff] [blame] | 31 | const chromeos::VariantDictionary& Command::GetParameters() const { |
Alex Vakulenko | 89d9d5e | 2014-09-12 10:27:23 -0700 | [diff] [blame] | 32 | return GetProperties()->parameters.value(); |
| 33 | } |
| 34 | |
| 35 | void Command::SetProgress(int progress) { |
| 36 | chromeos::dbus_utils::CallMethodAndBlock(GetObjectProxy(), |
| 37 | dbus_constants::kCommandInterface, |
| 38 | dbus_constants::kCommandSetProgress, |
Christopher Wiley | 8ae320b | 2014-09-18 11:33:28 -0700 | [diff] [blame] | 39 | nullptr, |
Alex Vakulenko | 89d9d5e | 2014-09-12 10:27:23 -0700 | [diff] [blame] | 40 | progress); |
| 41 | } |
| 42 | |
| 43 | void Command::Abort() { |
| 44 | chromeos::dbus_utils::CallMethodAndBlock(GetObjectProxy(), |
| 45 | dbus_constants::kCommandInterface, |
Christopher Wiley | 8ae320b | 2014-09-18 11:33:28 -0700 | [diff] [blame] | 46 | dbus_constants::kCommandAbort, |
| 47 | nullptr); |
Alex Vakulenko | 89d9d5e | 2014-09-12 10:27:23 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void Command::Cancel() { |
| 51 | chromeos::dbus_utils::CallMethodAndBlock(GetObjectProxy(), |
| 52 | dbus_constants::kCommandInterface, |
Christopher Wiley | 8ae320b | 2014-09-18 11:33:28 -0700 | [diff] [blame] | 53 | dbus_constants::kCommandCancel, |
| 54 | nullptr); |
Alex Vakulenko | 89d9d5e | 2014-09-12 10:27:23 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void Command::Done() { |
| 58 | chromeos::dbus_utils::CallMethodAndBlock(GetObjectProxy(), |
| 59 | dbus_constants::kCommandInterface, |
Christopher Wiley | 8ae320b | 2014-09-18 11:33:28 -0700 | [diff] [blame] | 60 | dbus_constants::kCommandDone, |
| 61 | nullptr); |
Alex Vakulenko | 89d9d5e | 2014-09-12 10:27:23 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | int Command::GetProgress() const { |
| 65 | return GetProperties()->progress.value(); |
| 66 | } |
| 67 | |
| 68 | const std::string& Command::GetStatus() const { |
| 69 | return GetProperties()->status.value(); |
| 70 | } |
| 71 | |
| 72 | CommandPropertySet* Command::GetProperties() const { |
| 73 | return command_listener_->GetProperties(object_path_); |
| 74 | } |
| 75 | |
| 76 | dbus::ObjectProxy* Command::GetObjectProxy() const { |
| 77 | return command_listener_->GetObjectProxy(object_path_); |
| 78 | } |
| 79 | |
| 80 | } // namespace buffet |