blob: caee8b0d965d77d2a49dd9f3fd57e63d682c8ab3 [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
Alex Vakulenko3bd3ece2015-12-09 12:29:01 -080034const std::string& Command::GetComponent() const {
35 return proxy_->component();
36}
37
Alex Vakulenkoabbcdea2015-10-09 19:33:15 -070038Command::State Command::GetState() const {
39 std::string state = proxy_->state();
40 if (state == "queued")
41 return Command::State::kQueued;
42 else if (state == "inProgress")
43 return Command::State::kInProgress;
44 else if (state == "paused")
45 return Command::State::kPaused;
46 else if (state == "error")
47 return Command::State::kError;
48 else if (state == "done")
49 return Command::State::kDone;
50 else if (state == "cancelled")
51 return Command::State::kCancelled;
52 else if (state == "aborted")
53 return Command::State::kAborted;
54 else if (state == "expired")
55 return Command::State::kExpired;
56 LOG(WARNING) << "Unknown command state: " << state;
57 return Command::State::kQueued;
58}
59
60Command::Origin Command::GetOrigin() const {
61 std::string origin = proxy_->origin();
62 if (origin == "local")
63 return Command::Origin::kLocal;
64 else if (origin == "cloud")
65 return Command::Origin::kCloud;
66 LOG(WARNING) << "Unknown command origin: " << origin;
67 return Command::Origin::kLocal;
68}
69
Alex Vakulenko41705852015-10-13 10:12:06 -070070const brillo::VariantDictionary& Command::GetParameters() const {
Alex Vakulenkoabbcdea2015-10-09 19:33:15 -070071 return proxy_->parameters();
72}
73
Alex Vakulenko41705852015-10-13 10:12:06 -070074bool Command::SetProgress(const brillo::VariantDictionary& progress,
75 brillo::ErrorPtr* error) {
Alex Vakulenkoabbcdea2015-10-09 19:33:15 -070076 return proxy_->SetProgress(progress, error);
77}
78
Alex Vakulenko41705852015-10-13 10:12:06 -070079bool Command::Complete(const brillo::VariantDictionary& results,
80 brillo::ErrorPtr* error) {
Alex Vakulenkoabbcdea2015-10-09 19:33:15 -070081 return proxy_->Complete(results, error);
82}
83
84bool Command::Abort(const std::string& error_code,
85 const std::string& error_message,
Alex Vakulenko41705852015-10-13 10:12:06 -070086 brillo::ErrorPtr* error) {
Alex Vakulenkoabbcdea2015-10-09 19:33:15 -070087 return proxy_->Abort(error_code, error_message, error);
88}
89
Alex Vakulenko41705852015-10-13 10:12:06 -070090bool Command::Cancel(brillo::ErrorPtr* error) {
Alex Vakulenkoabbcdea2015-10-09 19:33:15 -070091 return proxy_->Cancel(error);
92}
93
94} // namespace weave