123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- #ifndef UPDATE_ENGINE_COMMON_ACTION_H_
- #define UPDATE_ENGINE_COMMON_ACTION_H_
- #include <stdio.h>
- #include <memory>
- #include <string>
- #include <base/logging.h>
- #include <base/macros.h>
- #include "update_engine/common/action_pipe.h"
- #include "update_engine/common/action_processor.h"
- namespace chromeos_update_engine {
- class AbstractAction {
- public:
- AbstractAction() : processor_(nullptr) {}
- virtual ~AbstractAction() = default;
-
-
-
-
-
-
-
-
-
-
- virtual void PerformAction() = 0;
-
- virtual void ActionCompleted(ErrorCode code) {}
-
-
- void SetProcessor(ActionProcessor* processor) {
- if (processor)
- CHECK(!processor_);
- else
- CHECK(processor_);
- processor_ = processor;
- }
-
- bool IsRunning() const {
- if (!processor_)
- return false;
- return processor_->current_action() == this;
- }
-
-
-
-
-
- virtual void TerminateProcessing() {}
-
-
-
-
-
-
- virtual void SuspendAction() {}
- virtual void ResumeAction() {}
-
-
-
-
- virtual std::string Type() const = 0;
- protected:
-
- ActionProcessor* processor_;
- };
- template <typename T>
- class ActionPipe;
- template <typename T>
- class ActionTraits;
- template <typename SubClass>
- class Action : public AbstractAction {
- public:
- ~Action() override {}
-
-
-
-
- void set_in_pipe(
-
-
- const std::shared_ptr<
- ActionPipe<typename ActionTraits<SubClass>::InputObjectType>>&
- in_pipe) {
- in_pipe_ = in_pipe;
- }
-
-
-
-
- void set_out_pipe(
-
-
- const std::shared_ptr<
- ActionPipe<typename ActionTraits<SubClass>::OutputObjectType>>&
- out_pipe) {
- out_pipe_ = out_pipe;
- }
-
-
-
- bool HasInputObject() const { return in_pipe_.get(); }
-
- const typename ActionTraits<SubClass>::InputObjectType& GetInputObject()
- const {
- CHECK(HasInputObject());
- return in_pipe_->contents();
- }
-
- bool HasOutputPipe() const { return out_pipe_.get(); }
-
-
-
- void SetOutputObject(
- const typename ActionTraits<SubClass>::OutputObjectType& out_obj) {
- CHECK(HasOutputPipe());
- out_pipe_->set_contents(out_obj);
- }
-
- const typename ActionTraits<SubClass>::OutputObjectType& GetOutputObject() {
- CHECK(HasOutputPipe());
- return out_pipe_->contents();
- }
- protected:
-
-
-
-
- std::shared_ptr<ActionPipe<typename ActionTraits<SubClass>::InputObjectType>>
- in_pipe_;
- std::shared_ptr<ActionPipe<typename ActionTraits<SubClass>::OutputObjectType>>
- out_pipe_;
- };
- };
- #endif
|