Alex Vakulenko | abbcdea | 2015-10-09 19:33:15 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 21 | namespace weaved { |
| 22 | |
Alex Vakulenko | de94eb5 | 2015-12-08 17:11:20 -0800 | [diff] [blame^] | 23 | Command::Command(com::android::Weave::CommandProxyInterface* proxy) |
| 24 | : proxy_{proxy} {} |
Alex Vakulenko | abbcdea | 2015-10-09 19:33:15 -0700 | [diff] [blame] | 25 | |
| 26 | const std::string& Command::GetID() const { |
| 27 | return proxy_->id(); |
| 28 | } |
| 29 | |
| 30 | const std::string& Command::GetName() const { |
| 31 | return proxy_->name(); |
| 32 | } |
| 33 | |
| 34 | Command::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 | |
| 56 | Command::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 Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame] | 66 | const brillo::VariantDictionary& Command::GetParameters() const { |
Alex Vakulenko | abbcdea | 2015-10-09 19:33:15 -0700 | [diff] [blame] | 67 | return proxy_->parameters(); |
| 68 | } |
| 69 | |
Alex Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame] | 70 | bool Command::SetProgress(const brillo::VariantDictionary& progress, |
| 71 | brillo::ErrorPtr* error) { |
Alex Vakulenko | abbcdea | 2015-10-09 19:33:15 -0700 | [diff] [blame] | 72 | return proxy_->SetProgress(progress, error); |
| 73 | } |
| 74 | |
Alex Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame] | 75 | bool Command::Complete(const brillo::VariantDictionary& results, |
| 76 | brillo::ErrorPtr* error) { |
Alex Vakulenko | abbcdea | 2015-10-09 19:33:15 -0700 | [diff] [blame] | 77 | return proxy_->Complete(results, error); |
| 78 | } |
| 79 | |
| 80 | bool Command::Abort(const std::string& error_code, |
| 81 | const std::string& error_message, |
Alex Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame] | 82 | brillo::ErrorPtr* error) { |
Alex Vakulenko | abbcdea | 2015-10-09 19:33:15 -0700 | [diff] [blame] | 83 | return proxy_->Abort(error_code, error_message, error); |
| 84 | } |
| 85 | |
Alex Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame] | 86 | bool Command::Cancel(brillo::ErrorPtr* error) { |
Alex Vakulenko | abbcdea | 2015-10-09 19:33:15 -0700 | [diff] [blame] | 87 | return proxy_->Cancel(error); |
| 88 | } |
| 89 | |
| 90 | } // namespace weave |