Alex Vakulenko | 89d9d5e | 2014-09-12 10:27:23 -0700 | [diff] [blame] | 1 | // Copyright 2014 The Chromium OS 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 BUFFET_LIBBUFFET_COMMAND_H_ |
| 6 | #define BUFFET_LIBBUFFET_COMMAND_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include <base/macros.h> |
| 11 | #include <base/memory/weak_ptr.h> |
Alex Vakulenko | 576c979 | 2014-09-22 16:49:45 -0700 | [diff] [blame] | 12 | #include <chromeos/variant_dictionary.h> |
Alex Vakulenko | 89d9d5e | 2014-09-12 10:27:23 -0700 | [diff] [blame] | 13 | |
| 14 | #include "libbuffet/export.h" |
| 15 | |
| 16 | namespace dbus { |
| 17 | class ObjectProxy; |
| 18 | } |
| 19 | |
| 20 | namespace buffet { |
| 21 | |
| 22 | class CommandListener; |
| 23 | class CommandPropertySet; |
| 24 | |
| 25 | // buffet::Command is a proxy class for GCD CommandInstance object delivered to |
| 26 | // command handling daemon over D-Bus. |
| 27 | class LIBBUFFET_EXPORT Command { |
| 28 | public: |
| 29 | Command(const dbus::ObjectPath& object_path, |
| 30 | CommandListener* command_listener); |
| 31 | |
| 32 | // Returns the command ID. |
| 33 | const std::string& GetID() const; |
| 34 | // Returns the full name of the command. |
| 35 | const std::string& GetName() const; |
| 36 | // Returns the command category. |
| 37 | const std::string& GetCategory() const; |
| 38 | // Returns the command parameters and their values. |
Alex Vakulenko | 576c979 | 2014-09-22 16:49:45 -0700 | [diff] [blame] | 39 | const chromeos::VariantDictionary& GetParameters() const; |
Alex Vakulenko | 89d9d5e | 2014-09-12 10:27:23 -0700 | [diff] [blame] | 40 | |
| 41 | // Updates the command execution progress. The |progress| must be between |
| 42 | // 0 and 100. Returns false if the progress value is incorrect. |
| 43 | void SetProgress(int progress); |
| 44 | // Aborts command execution. |
| 45 | void Abort(); |
| 46 | // Cancels command execution. |
| 47 | void Cancel(); |
| 48 | // Marks the command as completed successfully. |
| 49 | void Done(); |
| 50 | |
| 51 | // Command state getters. |
| 52 | int GetProgress() const; |
| 53 | const std::string& GetStatus() const; |
| 54 | |
| 55 | private: |
| 56 | CommandPropertySet* GetProperties() const; |
| 57 | dbus::ObjectProxy* GetObjectProxy() const; |
| 58 | |
| 59 | dbus::ObjectPath object_path_; |
| 60 | CommandListener* command_listener_; |
| 61 | |
| 62 | DISALLOW_COPY_AND_ASSIGN(Command); |
| 63 | }; |
| 64 | |
| 65 | } // namespace buffet |
| 66 | |
| 67 | #endif // BUFFET_LIBBUFFET_COMMAND_H_ |