aboutsummaryrefslogtreecommitdiff
path: root/libweaved/command.cc
blob: caee8b0d965d77d2a49dd9f3fd57e63d682c8ab3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "command.h"

#include "buffet/dbus-proxies.h"

namespace weaved {

Command::Command(com::android::Weave::CommandProxyInterface* proxy)
    : proxy_{proxy} {}

const std::string& Command::GetID() const {
  return proxy_->id();
}

const std::string& Command::GetName() const {
  return proxy_->name();
}

const std::string& Command::GetComponent() const {
  return proxy_->component();
}

Command::State Command::GetState() const {
  std::string state = proxy_->state();
  if (state == "queued")
    return Command::State::kQueued;
  else if (state == "inProgress")
    return Command::State::kInProgress;
  else if (state == "paused")
    return Command::State::kPaused;
  else if (state == "error")
    return Command::State::kError;
  else if (state == "done")
    return Command::State::kDone;
  else if (state == "cancelled")
    return Command::State::kCancelled;
  else if (state == "aborted")
    return Command::State::kAborted;
  else if (state == "expired")
    return Command::State::kExpired;
  LOG(WARNING) << "Unknown command state: " << state;
  return Command::State::kQueued;
}

Command::Origin Command::GetOrigin() const {
  std::string origin = proxy_->origin();
  if (origin == "local")
    return Command::Origin::kLocal;
  else if (origin == "cloud")
    return Command::Origin::kCloud;
  LOG(WARNING) << "Unknown command origin: " << origin;
  return Command::Origin::kLocal;
}

const brillo::VariantDictionary& Command::GetParameters() const {
  return proxy_->parameters();
}

bool Command::SetProgress(const brillo::VariantDictionary& progress,
                          brillo::ErrorPtr* error) {
  return proxy_->SetProgress(progress, error);
}

bool Command::Complete(const brillo::VariantDictionary& results,
                       brillo::ErrorPtr* error) {
  return proxy_->Complete(results, error);
}

bool Command::Abort(const std::string& error_code,
                    const std::string& error_message,
                    brillo::ErrorPtr* error) {
  return proxy_->Abort(error_code, error_message, error);
}

bool Command::Cancel(brillo::ErrorPtr* error) {
  return proxy_->Cancel(error);
}

}  // namespace weave