blob: dfa55810b2ecc63ee3fdedd7437f3e61427bcfc6 [file] [log] [blame]
Alex Vakulenko89d9d5e2014-09-12 10:27:23 -07001// 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
13namespace buffet {
14
15Command::Command(const dbus::ObjectPath& object_path,
16 CommandListener* command_listener)
17 : object_path_(object_path), command_listener_(command_listener) {}
18
19const std::string& Command::GetID() const {
20 return GetProperties()->id.value();
21}
22
23const std::string& Command::GetName() const {
24 return GetProperties()->name.value();
25}
26
27const std::string& Command::GetCategory() const {
28 return GetProperties()->category.value();
29}
30
Alex Vakulenko576c9792014-09-22 16:49:45 -070031const chromeos::VariantDictionary& Command::GetParameters() const {
Alex Vakulenko89d9d5e2014-09-12 10:27:23 -070032 return GetProperties()->parameters.value();
33}
34
35void Command::SetProgress(int progress) {
36 chromeos::dbus_utils::CallMethodAndBlock(GetObjectProxy(),
37 dbus_constants::kCommandInterface,
38 dbus_constants::kCommandSetProgress,
Christopher Wiley8ae320b2014-09-18 11:33:28 -070039 nullptr,
Alex Vakulenko89d9d5e2014-09-12 10:27:23 -070040 progress);
41}
42
43void Command::Abort() {
44 chromeos::dbus_utils::CallMethodAndBlock(GetObjectProxy(),
45 dbus_constants::kCommandInterface,
Christopher Wiley8ae320b2014-09-18 11:33:28 -070046 dbus_constants::kCommandAbort,
47 nullptr);
Alex Vakulenko89d9d5e2014-09-12 10:27:23 -070048}
49
50void Command::Cancel() {
51 chromeos::dbus_utils::CallMethodAndBlock(GetObjectProxy(),
52 dbus_constants::kCommandInterface,
Christopher Wiley8ae320b2014-09-18 11:33:28 -070053 dbus_constants::kCommandCancel,
54 nullptr);
Alex Vakulenko89d9d5e2014-09-12 10:27:23 -070055}
56
57void Command::Done() {
58 chromeos::dbus_utils::CallMethodAndBlock(GetObjectProxy(),
59 dbus_constants::kCommandInterface,
Christopher Wiley8ae320b2014-09-18 11:33:28 -070060 dbus_constants::kCommandDone,
61 nullptr);
Alex Vakulenko89d9d5e2014-09-12 10:27:23 -070062}
63
64int Command::GetProgress() const {
65 return GetProperties()->progress.value();
66}
67
68const std::string& Command::GetStatus() const {
69 return GetProperties()->status.value();
70}
71
72CommandPropertySet* Command::GetProperties() const {
73 return command_listener_->GetProperties(object_path_);
74}
75
76dbus::ObjectProxy* Command::GetObjectProxy() const {
77 return command_listener_->GetObjectProxy(object_path_);
78}
79
80} // namespace buffet