diff options
author | Alex Deymo <deymo@google.com> | 2015-11-09 17:04:30 -0800 |
---|---|---|
committer | Alex Deymo <deymo@google.com> | 2015-11-12 02:17:50 +0000 |
commit | 39910dcd1d68987ccee7c3031dc269233a8490bb (patch) | |
tree | b7569d7ff83b001d244eda59bb2efdee9a6f15ec /common/action_processor.h | |
parent | 82352f97b4621dbf6af8308ff0b0b17b0968b53a (diff) |
Split payload application code into a subdirectory.
This patch splits from the main libupdate_engine code the part that
is strictly used to download and apply a payload into a new static
library, moving the code to subdirectories. The new library is divided
in two subdirectories: common/ and payload_consumer/, and should not
depend on other update_engine files outside those two subdirectories.
The main difference between those two is that the common/ tools are more
generic and not tied to the payload consumer process, but otherwise they
are both compiled together.
There are still dependencies from the new libpayload_consumer library
into the main directory files and DBus generated files. Those will be
addressed in follow up CLs.
Bug: 25197634
Test: FEATURES=test emerge-link update_engine; `mm` on Brillo.
Change-Id: Id8d0204ea573627e6e26ca9ea17b9592ca95bc23
Diffstat (limited to 'common/action_processor.h')
-rw-r--r-- | common/action_processor.h | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/common/action_processor.h b/common/action_processor.h new file mode 100644 index 00000000..d61e12d7 --- /dev/null +++ b/common/action_processor.h @@ -0,0 +1,116 @@ +// +// Copyright (C) 2011 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef UPDATE_ENGINE_COMMON_ACTION_PROCESSOR_H_ +#define UPDATE_ENGINE_COMMON_ACTION_PROCESSOR_H_ + +#include <deque> + +#include <base/macros.h> + +#include "update_engine/common/error_code.h" + +// The structure of these classes (Action, ActionPipe, ActionProcessor, etc.) +// is based on the KSAction* classes from the Google Update Engine code at +// http://code.google.com/p/update-engine/ . The author of this file sends +// a big thanks to that team for their high quality design, implementation, +// and documentation. + +// See action.h for an overview of this class and other Action* classes. + +// An ActionProcessor keeps a queue of Actions and processes them in order. + +namespace chromeos_update_engine { + +class AbstractAction; +class ActionProcessorDelegate; + +class ActionProcessor { + public: + ActionProcessor(); + + virtual ~ActionProcessor(); + + // Starts processing the first Action in the queue. If there's a delegate, + // when all processing is complete, ProcessingDone() will be called on the + // delegate. + virtual void StartProcessing(); + + // Aborts processing. If an Action is running, it will have + // TerminateProcessing() called on it. The Action that was running + // will be lost and must be re-enqueued if this Processor is to use it. + void StopProcessing(); + + // Returns true iff an Action is currently processing. + bool IsRunning() const { return nullptr != current_action_; } + + // Adds another Action to the end of the queue. + virtual void EnqueueAction(AbstractAction* action); + + // Sets/gets the current delegate. Set to null to remove a delegate. + ActionProcessorDelegate* delegate() const { return delegate_; } + void set_delegate(ActionProcessorDelegate *delegate) { + delegate_ = delegate; + } + + // Returns a pointer to the current Action that's processing. + AbstractAction* current_action() const { + return current_action_; + } + + // Called by an action to notify processor that it's done. Caller passes self. + void ActionComplete(AbstractAction* actionptr, ErrorCode code); + + private: + // Actions that have not yet begun processing, in the order in which + // they'll be processed. + std::deque<AbstractAction*> actions_; + + // A pointer to the currently processing Action, if any. + AbstractAction* current_action_; + + // A pointer to the delegate, or null if none. + ActionProcessorDelegate *delegate_; + DISALLOW_COPY_AND_ASSIGN(ActionProcessor); +}; + +// A delegate object can be used to be notified of events that happen +// in an ActionProcessor. An instance of this class can be passed to an +// ActionProcessor to register itself. +class ActionProcessorDelegate { + public: + virtual ~ActionProcessorDelegate() = default; + + // Called when all processing in an ActionProcessor has completed. A pointer + // to the ActionProcessor is passed. |code| is set to the exit code of the + // last completed action. + virtual void ProcessingDone(const ActionProcessor* processor, + ErrorCode code) {} + + // Called when processing has stopped. Does not mean that all Actions have + // completed. If/when all Actions complete, ProcessingDone() will be called. + virtual void ProcessingStopped(const ActionProcessor* processor) {} + + // Called whenever an action has finished processing, either successfully + // or otherwise. + virtual void ActionCompleted(ActionProcessor* processor, + AbstractAction* action, + ErrorCode code) {} +}; + +} // namespace chromeos_update_engine + +#endif // UPDATE_ENGINE_COMMON_ACTION_PROCESSOR_H_ |