blob: 4df7c4f4614bd7b59db3378d6f9082f95360bd90 [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
23Command::Command(com::android::Weave::CommandProxy* proxy) : proxy_{proxy} {}
24
25const std::string& Command::GetID() const {
26 return proxy_->id();
27}
28
29const std::string& Command::GetName() const {
30 return proxy_->name();
31}
32
33Command::State Command::GetState() const {
34 std::string state = proxy_->state();
35 if (state == "queued")
36 return Command::State::kQueued;
37 else if (state == "inProgress")
38 return Command::State::kInProgress;
39 else if (state == "paused")
40 return Command::State::kPaused;
41 else if (state == "error")
42 return Command::State::kError;
43 else if (state == "done")
44 return Command::State::kDone;
45 else if (state == "cancelled")
46 return Command::State::kCancelled;
47 else if (state == "aborted")
48 return Command::State::kAborted;
49 else if (state == "expired")
50 return Command::State::kExpired;
51 LOG(WARNING) << "Unknown command state: " << state;
52 return Command::State::kQueued;
53}
54
55Command::Origin Command::GetOrigin() const {
56 std::string origin = proxy_->origin();
57 if (origin == "local")
58 return Command::Origin::kLocal;
59 else if (origin == "cloud")
60 return Command::Origin::kCloud;
61 LOG(WARNING) << "Unknown command origin: " << origin;
62 return Command::Origin::kLocal;
63}
64
65const chromeos::VariantDictionary& Command::GetParameters() const {
66 return proxy_->parameters();
67}
68
69bool Command::SetProgress(const chromeos::VariantDictionary& progress,
70 chromeos::ErrorPtr* error) {
71 return proxy_->SetProgress(progress, error);
72}
73
74bool Command::Complete(const chromeos::VariantDictionary& results,
75 chromeos::ErrorPtr* error) {
76 return proxy_->Complete(results, error);
77}
78
79bool Command::Abort(const std::string& error_code,
80 const std::string& error_message,
81 chromeos::ErrorPtr* error) {
82 return proxy_->Abort(error_code, error_message, error);
83}
84
85bool Command::Cancel(chromeos::ErrorPtr* error) {
86 return proxy_->Cancel(error);
87}
88
89} // namespace weave