| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_PROCESSOR_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_PROCESSOR_H__ |
| 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_PROCESSOR_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_PROCESSOR_H__ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 | 11 |
| 12 // The structure of these classes (Action, ActionPipe, ActionProcessor, etc.) | 12 // The structure of these classes (Action, ActionPipe, ActionProcessor, etc.) |
| 13 // is based on the KSAction* classes from the Google Update Engine code at | 13 // is based on the KSAction* classes from the Google Update Engine code at |
| 14 // http://code.google.com/p/update-engine/ . The author of this file sends | 14 // http://code.google.com/p/update-engine/ . The author of this file sends |
| 15 // a big thanks to that team for their high quality design, implementation, | 15 // a big thanks to that team for their high quality design, implementation, |
| 16 // and documentation. | 16 // and documentation. |
| 17 | 17 |
| 18 // See action.h for an overview of this class and other other Action* classes. | 18 // See action.h for an overview of this class and other other Action* classes. |
| 19 | 19 |
| 20 // An ActionProcessor keeps a queue of Actions and processes them in order. | 20 // An ActionProcessor keeps a queue of Actions and processes them in order. |
| 21 | 21 |
| 22 namespace chromeos_update_engine { | 22 namespace chromeos_update_engine { |
| 23 | 23 |
| 24 // Action exit codes. |
| 25 enum ActionExitCode { |
| 26 kActionCodeSuccess = 0, |
| 27 kActionCodeError = 1, |
| 28 }; |
| 29 |
| 24 class AbstractAction; | 30 class AbstractAction; |
| 25 class ActionProcessorDelegate; | 31 class ActionProcessorDelegate; |
| 26 | 32 |
| 27 class ActionProcessor { | 33 class ActionProcessor { |
| 28 public: | 34 public: |
| 29 ActionProcessor(); | 35 ActionProcessor(); |
| 30 | 36 |
| 31 ~ActionProcessor(); | 37 ~ActionProcessor(); |
| 32 | 38 |
| 33 // Starts processing the first Action in the queue. If there's a delegate, | 39 // Starts processing the first Action in the queue. If there's a delegate, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 50 void set_delegate(ActionProcessorDelegate *delegate) { | 56 void set_delegate(ActionProcessorDelegate *delegate) { |
| 51 delegate_ = delegate; | 57 delegate_ = delegate; |
| 52 } | 58 } |
| 53 | 59 |
| 54 // Returns a pointer to the current Action that's processing. | 60 // Returns a pointer to the current Action that's processing. |
| 55 AbstractAction* current_action() const { | 61 AbstractAction* current_action() const { |
| 56 return current_action_; | 62 return current_action_; |
| 57 } | 63 } |
| 58 | 64 |
| 59 // Called by an action to notify processor that it's done. Caller passes self. | 65 // Called by an action to notify processor that it's done. Caller passes self. |
| 60 void ActionComplete(AbstractAction* actionptr, bool success); | 66 void ActionComplete(AbstractAction* actionptr, ActionExitCode code); |
| 61 | 67 |
| 62 private: | 68 private: |
| 63 // Actions that have not yet begun processing, in the order in which | 69 // Actions that have not yet begun processing, in the order in which |
| 64 // they'll be processed. | 70 // they'll be processed. |
| 65 std::deque<AbstractAction*> actions_; | 71 std::deque<AbstractAction*> actions_; |
| 66 | 72 |
| 67 // A pointer to the currrently processing Action, if any. | 73 // A pointer to the currrently processing Action, if any. |
| 68 AbstractAction* current_action_; | 74 AbstractAction* current_action_; |
| 69 | 75 |
| 70 // A pointer to the delegate, or NULL if none. | 76 // A pointer to the delegate, or NULL if none. |
| 71 ActionProcessorDelegate *delegate_; | 77 ActionProcessorDelegate *delegate_; |
| 72 DISALLOW_COPY_AND_ASSIGN(ActionProcessor); | 78 DISALLOW_COPY_AND_ASSIGN(ActionProcessor); |
| 73 }; | 79 }; |
| 74 | 80 |
| 75 // A delegate object can be used to be notified of events that happen | 81 // A delegate object can be used to be notified of events that happen |
| 76 // in an ActionProcessor. An instance of this class can be passed to an | 82 // in an ActionProcessor. An instance of this class can be passed to an |
| 77 // ActionProcessor to register itself. | 83 // ActionProcessor to register itself. |
| 78 class ActionProcessorDelegate { | 84 class ActionProcessorDelegate { |
| 79 public: | 85 public: |
| 80 // Called when all processing in an ActionProcessor has completed. A pointer | 86 // Called when all processing in an ActionProcessor has completed. A pointer |
| 81 // to the ActionProcessor is passed. success is true iff all actions | 87 // to the ActionProcessor is passed. |code| is set to the exit code of the |
| 82 // completed successfully | 88 // last completed action. |
| 83 virtual void ProcessingDone(const ActionProcessor* processor, bool success) {} | 89 virtual void ProcessingDone(const ActionProcessor* processor, |
| 90 ActionExitCode code) {} |
| 84 | 91 |
| 85 // Called when processing has stopped. Does not mean that all Actions have | 92 // Called when processing has stopped. Does not mean that all Actions have |
| 86 // completed. If/when all Actions complete, ProcessingDone() will be called. | 93 // completed. If/when all Actions complete, ProcessingDone() will be called. |
| 87 virtual void ProcessingStopped(const ActionProcessor* processor) {} | 94 virtual void ProcessingStopped(const ActionProcessor* processor) {} |
| 88 | 95 |
| 89 // Called whenever an action has finished processing, either successfully | 96 // Called whenever an action has finished processing, either successfully |
| 90 // or otherwise. | 97 // or otherwise. |
| 91 virtual void ActionCompleted(ActionProcessor* processor, | 98 virtual void ActionCompleted(ActionProcessor* processor, |
| 92 AbstractAction* action, | 99 AbstractAction* action, |
| 93 bool success) {} | 100 ActionExitCode code) {} |
| 94 }; | 101 }; |
| 95 | 102 |
| 96 } // namespace chromeos_update_engine | 103 } // namespace chromeos_update_engine |
| 97 | 104 |
| 98 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_PROCESSOR_H__ | 105 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_PROCESSOR_H__ |
| OLD | NEW |