Home | History | Annotate | Download | only in weave
      1 // Copyright 2015 The Weave Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef LIBWEAVE_INCLUDE_WEAVE_COMMAND_H_
      6 #define LIBWEAVE_INCLUDE_WEAVE_COMMAND_H_
      7 
      8 #include <string>
      9 
     10 #include <base/values.h>
     11 #include <weave/error.h>
     12 
     13 namespace weave {
     14 
     15 class Command {
     16  public:
     17   enum class State {
     18     kQueued,
     19     kInProgress,
     20     kPaused,
     21     kError,
     22     kDone,
     23     kCancelled,
     24     kAborted,
     25     kExpired,
     26   };
     27 
     28   enum class Origin { kLocal, kCloud };
     29 
     30   // Returns the full command ID.
     31   virtual const std::string& GetID() const = 0;
     32 
     33   // Returns the full name of the command.
     34   virtual const std::string& GetName() const = 0;
     35 
     36   // Returns the full path to the component this command is intended for.
     37   virtual const std::string& GetComponent() const = 0;
     38 
     39   // Returns the command state.
     40   virtual Command::State GetState() const = 0;
     41 
     42   // Returns the origin of the command.
     43   virtual Command::Origin GetOrigin() const = 0;
     44 
     45   // Returns the command parameters.
     46   virtual const base::DictionaryValue& GetParameters() const = 0;
     47 
     48   // Returns the command progress.
     49   virtual const base::DictionaryValue& GetProgress() const = 0;
     50 
     51   // Returns the command results.
     52   virtual const base::DictionaryValue& GetResults() const = 0;
     53 
     54   // Returns the command error.
     55   virtual const Error* GetError() const = 0;
     56 
     57   // Updates the command progress. The |progress| should match the schema.
     58   // Returns false if |progress| value is incorrect.
     59   virtual bool SetProgress(const base::DictionaryValue& progress,
     60                            ErrorPtr* error) = 0;
     61 
     62   // Sets command into terminal "done" state.
     63   // Updates the command results. The |results| should match the schema.
     64   // Returns false if |results| value is incorrect.
     65   virtual bool Complete(const base::DictionaryValue& results,
     66                         ErrorPtr* error) = 0;
     67 
     68   // Sets command into paused state.
     69   // This is not terminal state. Command can be resumed with |SetProgress| call.
     70   virtual bool Pause(ErrorPtr* error) = 0;
     71 
     72   // Sets command into error state and assign error.
     73   // This is not terminal state. Command can be resumed with |SetProgress| call.
     74   virtual bool SetError(const Error* command_error, ErrorPtr* error) = 0;
     75 
     76   // Aborts command execution.
     77   // Sets command into terminal "aborted" state.
     78   virtual bool Abort(const Error* command_error, ErrorPtr* error) = 0;
     79 
     80   // Cancels command execution.
     81   // Sets command into terminal "canceled" state.
     82   virtual bool Cancel(ErrorPtr* error) = 0;
     83 
     84  protected:
     85   virtual ~Command() {}
     86 };
     87 
     88 }  // namespace weave
     89 
     90 #endif  // LIBWEAVE_INCLUDE_WEAVE_COMMAND_H_
     91