aboutsummaryrefslogtreecommitdiff
path: root/include/weave/command.h
blob: 91949f6182aa4b84dd80ff3a71497148cf7513ef (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
// Copyright 2015 The Weave Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef LIBWEAVE_INCLUDE_WEAVE_COMMAND_H_
#define LIBWEAVE_INCLUDE_WEAVE_COMMAND_H_

#include <string>

#include <base/values.h>
#include <weave/error.h>

namespace weave {

class Command {
 public:
  enum class State {
    kQueued,
    kInProgress,
    kPaused,
    kError,
    kDone,
    kCancelled,
    kAborted,
    kExpired,
  };

  enum class Origin { kLocal, kCloud };

  // Returns the full command ID.
  virtual const std::string& GetID() const = 0;

  // Returns the full name of the command.
  virtual const std::string& GetName() const = 0;

  // Returns the full path to the component this command is intended for.
  virtual const std::string& GetComponent() const = 0;

  // Returns the command state.
  virtual Command::State GetState() const = 0;

  // Returns the origin of the command.
  virtual Command::Origin GetOrigin() const = 0;

  // Returns the command parameters.
  virtual const base::DictionaryValue& GetParameters() const = 0;

  // Returns the command progress.
  virtual const base::DictionaryValue& GetProgress() const = 0;

  // Returns the command results.
  virtual const base::DictionaryValue& GetResults() const = 0;

  // Returns the command error.
  virtual const Error* GetError() const = 0;

  // Updates the command progress. The |progress| should match the schema.
  // Returns false if |progress| value is incorrect.
  virtual bool SetProgress(const base::DictionaryValue& progress,
                           ErrorPtr* error) = 0;

  // Sets command into terminal "done" state.
  // Updates the command results. The |results| should match the schema.
  // Returns false if |results| value is incorrect.
  virtual bool Complete(const base::DictionaryValue& results,
                        ErrorPtr* error) = 0;

  // Sets command into paused state.
  // This is not terminal state. Command can be resumed with |SetProgress| call.
  virtual bool Pause(ErrorPtr* error) = 0;

  // Sets command into error state and assign error.
  // This is not terminal state. Command can be resumed with |SetProgress| call.
  virtual bool SetError(const Error* command_error, ErrorPtr* error) = 0;

  // Aborts command execution.
  // Sets command into terminal "aborted" state.
  virtual bool Abort(const Error* command_error, ErrorPtr* error) = 0;

  // Cancels command execution.
  // Sets command into terminal "canceled" state.
  virtual bool Cancel(ErrorPtr* error) = 0;

 protected:
  virtual ~Command() {}
};

}  // namespace weave

#endif  // LIBWEAVE_INCLUDE_WEAVE_COMMAND_H_