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 | |
Alex Vakulenko | 3bd3ece | 2015-12-09 12:29:01 -0800 | [diff] [blame^] | 34 | const std::string& Command::GetComponent() const { |
| 35 | return proxy_->component(); |
| 36 | } |
| 37 | |
Alex Vakulenko | abbcdea | 2015-10-09 19:33:15 -0700 | [diff] [blame] | 38 | Command::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 | |
| 60 | Command::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 Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame] | 70 | const brillo::VariantDictionary& Command::GetParameters() const { |
Alex Vakulenko | abbcdea | 2015-10-09 19:33:15 -0700 | [diff] [blame] | 71 | return proxy_->parameters(); |
| 72 | } |
| 73 | |
Alex Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame] | 74 | bool Command::SetProgress(const brillo::VariantDictionary& progress, |
| 75 | brillo::ErrorPtr* error) { |
Alex Vakulenko | abbcdea | 2015-10-09 19:33:15 -0700 | [diff] [blame] | 76 | return proxy_->SetProgress(progress, error); |
| 77 | } |
| 78 | |
Alex Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame] | 79 | bool Command::Complete(const brillo::VariantDictionary& results, |
| 80 | brillo::ErrorPtr* error) { |
Alex Vakulenko | abbcdea | 2015-10-09 19:33:15 -0700 | [diff] [blame] | 81 | return proxy_->Complete(results, error); |
| 82 | } |
| 83 | |
| 84 | bool Command::Abort(const std::string& error_code, |
| 85 | const std::string& error_message, |
Alex Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame] | 86 | brillo::ErrorPtr* error) { |
Alex Vakulenko | abbcdea | 2015-10-09 19:33:15 -0700 | [diff] [blame] | 87 | return proxy_->Abort(error_code, error_message, error); |
| 88 | } |
| 89 | |
Alex Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame] | 90 | bool Command::Cancel(brillo::ErrorPtr* error) { |
Alex Vakulenko | abbcdea | 2015-10-09 19:33:15 -0700 | [diff] [blame] | 91 | return proxy_->Cancel(error); |
| 92 | } |
| 93 | |
| 94 | } // namespace weave |