blob: 938a81d0f7233055e5b87fc9b8d28c49b42e155f [file] [log] [blame]
rspangler@google.com49fdf182009-10-10 00:57:34 +00001// Copyright (c) 2009 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
adlr@google.comc98a7ed2009-12-04 18:54:03 +00005#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_PROCESSOR_H__
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_PROCESSOR_H__
rspangler@google.com49fdf182009-10-10 00:57:34 +00007
8#include <deque>
9
10#include "base/basictypes.h"
11
12// The structure of these classes (Action, ActionPipe, ActionProcessor, etc.)
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
15// a big thanks to that team for their high quality design, implementation,
16// and documentation.
17
18// See action.h for an overview of this class and other other Action* classes.
19
20// An ActionProcessor keeps a queue of Actions and processes them in order.
21
22namespace chromeos_update_engine {
23
24class AbstractAction;
25class ActionProcessorDelegate;
26
27class ActionProcessor {
28 public:
29 ActionProcessor();
30
31 ~ActionProcessor();
32
33 // Starts processing the first Action in the queue. If there's a delegate,
34 // when all processing is complete, ProcessingDone() will be called on the
35 // delegate.
36 void StartProcessing();
37
38 // Aborts processing. If an Action is running, it will have
39 // TerminateProcessing() called on it. The Action that was running
40 // will be lost and must be re-enqueued if this Processor is to use it.
41 void StopProcessing();
42
43 // Returns true iff an Action is currently processing.
44 bool IsRunning() const { return NULL != current_action_; }
45
46 // Adds another Action to the end of the queue.
47 void EnqueueAction(AbstractAction* action);
48
49 // Sets the current delegate. Set to NULL to remove a delegate.
50 void set_delegate(ActionProcessorDelegate *delegate) {
51 delegate_ = delegate;
52 }
53
54 // Returns a pointer to the current Action that's processing.
55 AbstractAction* current_action() const {
56 return current_action_;
57 }
58
59 // Called by an action to notify processor that it's done. Caller passes self.
adlr@google.comc98a7ed2009-12-04 18:54:03 +000060 void ActionComplete(AbstractAction* actionptr, bool success);
rspangler@google.com49fdf182009-10-10 00:57:34 +000061
62 private:
63 // Actions that have not yet begun processing, in the order in which
64 // they'll be processed.
65 std::deque<AbstractAction*> actions_;
66
67 // A pointer to the currrently processing Action, if any.
68 AbstractAction* current_action_;
69
70 // A pointer to the delegate, or NULL if none.
71 ActionProcessorDelegate *delegate_;
72 DISALLOW_COPY_AND_ASSIGN(ActionProcessor);
73};
74
75// 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
77// ActionProcessor to register itself.
78class ActionProcessorDelegate {
79 public:
80 // Called when all processing in an ActionProcessor has completed. A pointer
81 // to the ActionProcessor is passed.
82 virtual void ProcessingDone(const ActionProcessor* processor) {}
83
84 // Called when processing has stopped. Does not mean that all Actions have
85 // completed. If/when all Actions complete, ProcessingDone() will be called.
86 virtual void ProcessingStopped(const ActionProcessor* processor) {}
87
88 // Called whenever an action has finished processing, either successfully
89 // or otherwise.
adlr@google.comc98a7ed2009-12-04 18:54:03 +000090 virtual void ActionCompleted(ActionProcessor* processor,
91 AbstractAction* action,
rspangler@google.com49fdf182009-10-10 00:57:34 +000092 bool success) {}
93};
94
95} // namespace chromeos_update_engine
96
adlr@google.comc98a7ed2009-12-04 18:54:03 +000097#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_PROCESSOR_H__