blob: 8b7427f046d403e2246dd155419f25c5c6997fc7 [file] [log] [blame]
Alex Vakulenkoabbcdea2015-10-09 19:33:15 -07001/*
2 * Copyright 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "command.h"
18
19#include "buffet/dbus-proxies.h"
20
21namespace weaved {
22
Alex Vakulenkode94eb52015-12-08 17:11:20 -080023Command::Command(com::android::Weave::CommandProxyInterface* proxy)
24 : proxy_{proxy} {}
Alex Vakulenkoabbcdea2015-10-09 19:33:15 -070025
26const std::string& Command::GetID() const {
27 return proxy_->id();
28}
29
30const std::string& Command::GetName() const {
31 return proxy_->name();
32}
33
34Command::State Command::GetState() const {
35 std::string state = proxy_->state();
36 if (state == "queued")
37 return Command::State::kQueued;
38 else if (state == "inProgress")
39 return Command::State::kInProgress;
40 else if (state == "paused")
41 return Command::State::kPaused;
42 else if (state == "error")
43 return Command::State::kError;
44 else if (state == "done")
45 return Command::State::kDone;
46 else if (state == "cancelled")
47 return Command::State::kCancelled;
48 else if (state == "aborted")
49 return Command::State::kAborted;
50 else if (state == "expired")
51 return Command::State::kExpired;
52 LOG(WARNING) << "Unknown command state: " << state;
53 return Command::State::kQueued;
54}
55
56Command::Origin Command::GetOrigin() const {
57 std::string origin = proxy_->origin();
58 if (origin == "local")
59 return Command::Origin::kLocal;
60 else if (origin == "cloud")
61 return Command::Origin::kCloud;
62 LOG(WARNING) << "Unknown command origin: " << origin;
63 return Command::Origin::kLocal;
64}
65
Alex Vakulenko41705852015-10-13 10:12:06 -070066const brillo::VariantDictionary& Command::GetParameters() const {
Alex Vakulenkoabbcdea2015-10-09 19:33:15 -070067 return proxy_->parameters();
68}
69
Alex Vakulenko41705852015-10-13 10:12:06 -070070bool Command::SetProgress(const brillo::VariantDictionary& progress,
71 brillo::ErrorPtr* error) {
Alex Vakulenkoabbcdea2015-10-09 19:33:15 -070072 return proxy_->SetProgress(progress, error);
73}
74
Alex Vakulenko41705852015-10-13 10:12:06 -070075bool Command::Complete(const brillo::VariantDictionary& results,
76 brillo::ErrorPtr* error) {
Alex Vakulenkoabbcdea2015-10-09 19:33:15 -070077 return proxy_->Complete(results, error);
78}
79
80bool Command::Abort(const std::string& error_code,
81 const std::string& error_message,
Alex Vakulenko41705852015-10-13 10:12:06 -070082 brillo::ErrorPtr* error) {
Alex Vakulenkoabbcdea2015-10-09 19:33:15 -070083 return proxy_->Abort(error_code, error_message, error);
84}
85
Alex Vakulenko41705852015-10-13 10:12:06 -070086bool Command::Cancel(brillo::ErrorPtr* error) {
Alex Vakulenkoabbcdea2015-10-09 19:33:15 -070087 return proxy_->Cancel(error);
88}
89
90} // namespace weave