OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // 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 | 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 UPDATE_ENGINE_ACTION_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_H__ |
6 #define UPDATE_ENGINE_ACTION_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_H__ |
7 | 7 |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <tr1/memory> | 9 #include <tr1/memory> |
10 #include <iostream> | 10 #include <iostream> |
11 | |
12 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
13 #include <base/logging.h> | 12 #include "chromeos/obsolete_logging.h" |
14 | |
15 #include "update_engine/action_processor.h" | 13 #include "update_engine/action_processor.h" |
| 14 #include "update_engine/action_pipe.h" |
16 | 15 |
17 // The structure of these classes (Action, ActionPipe, ActionProcessor, etc.) | 16 // The structure of these classes (Action, ActionPipe, ActionProcessor, etc.) |
18 // is based on the KSAction* classes from the Google Update Engine code at | 17 // is based on the KSAction* classes from the Google Update Engine code at |
19 // http://code.google.com/p/update-engine/ . The author of this file sends | 18 // http://code.google.com/p/update-engine/ . The author of this file sends |
20 // a big thanks to that team for their high quality design, implementation, | 19 // a big thanks to that team for their high quality design, implementation, |
21 // and documentation. | 20 // and documentation. |
22 // | 21 // |
23 // Readers may want to consult this wiki page from the Update Engine site: | 22 // Readers may want to consult this wiki page from the Update Engine site: |
24 // http://code.google.com/p/update-engine/wiki/ActionProcessor | 23 // http://code.google.com/p/update-engine/wiki/ActionProcessor |
25 // Although it's referring to the Objective-C KSAction* classes, much | 24 // Although it's referring to the Objective-C KSAction* classes, much |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // of object that this class expects. | 149 // of object that this class expects. |
151 // This is generally called by ActionPipe::Bond() | 150 // This is generally called by ActionPipe::Bond() |
152 void set_out_pipe( | 151 void set_out_pipe( |
153 // this type is a fancy way of saying: a shared_ptr to an | 152 // this type is a fancy way of saying: a shared_ptr to an |
154 // ActionPipe<OutputObjectType>. | 153 // ActionPipe<OutputObjectType>. |
155 const shared_ptr<ActionPipe< | 154 const shared_ptr<ActionPipe< |
156 typename ActionTraits<SubClass>::OutputObjectType> >& | 155 typename ActionTraits<SubClass>::OutputObjectType> >& |
157 out_pipe) { | 156 out_pipe) { |
158 out_pipe_ = out_pipe; | 157 out_pipe_ = out_pipe; |
159 } | 158 } |
160 protected: | 159 |
161 // Returns true iff there is an associated input pipe. If there's an input | 160 // Returns true iff there is an associated input pipe. If there's an input |
162 // pipe, there's an input object, but it may have been constructed with the | 161 // pipe, there's an input object, but it may have been constructed with the |
163 // default ctor if the previous action didn't call SetOutputObject(). | 162 // default ctor if the previous action didn't call SetOutputObject(). |
164 bool HasInputObject() const { return in_pipe_.get(); } | 163 bool HasInputObject() const { return in_pipe_.get(); } |
165 | 164 |
166 // returns a const reference to the object in the input pipe. | 165 // returns a const reference to the object in the input pipe. |
167 const typename ActionTraits<SubClass>::InputObjectType& GetInputObject() | 166 const typename ActionTraits<SubClass>::InputObjectType& GetInputObject() |
168 const { | 167 const { |
169 CHECK(HasInputObject()); | 168 CHECK(HasInputObject()); |
170 return in_pipe_->contents(); | 169 return in_pipe_->contents(); |
171 } | 170 } |
172 | 171 |
173 // Returns true iff there's an output pipe. | 172 // Returns true iff there's an output pipe. |
174 bool HasOutputPipe() const { | 173 bool HasOutputPipe() const { |
175 return out_pipe_.get(); | 174 return out_pipe_.get(); |
176 } | 175 } |
177 | 176 |
178 // Copies the object passed into the output pipe. It will be accessible to | 177 // Copies the object passed into the output pipe. It will be accessible to |
179 // the next Action via that action's input pipe (which is the same as this | 178 // the next Action via that action's input pipe (which is the same as this |
180 // Action's output pipe). | 179 // Action's output pipe). |
181 void SetOutputObject( | 180 void SetOutputObject( |
182 const typename ActionTraits<SubClass>::OutputObjectType& out_obj) { | 181 const typename ActionTraits<SubClass>::OutputObjectType& out_obj) { |
183 CHECK(HasOutputPipe()); | 182 CHECK(HasOutputPipe()); |
184 out_pipe_->set_contents(out_obj); | 183 out_pipe_->set_contents(out_obj); |
185 } | 184 } |
186 | 185 |
| 186 // Returns a reference to the object sitting in the output pipe. |
| 187 const typename ActionTraits<SubClass>::OutputObjectType& GetOutputObject() { |
| 188 CHECK(HasOutputPipe()); |
| 189 return out_pipe_->contents(); |
| 190 } |
| 191 |
| 192 protected: |
187 // We use a shared_ptr to the pipe. shared_ptr objects destroy what they | 193 // We use a shared_ptr to the pipe. shared_ptr objects destroy what they |
188 // point to when the last such shared_ptr object dies. We consider the | 194 // point to when the last such shared_ptr object dies. We consider the |
189 // Actions on either end of a pipe to "own" the pipe. When the last Action | 195 // Actions on either end of a pipe to "own" the pipe. When the last Action |
190 // of the two dies, the ActionPipe will die, too. | 196 // of the two dies, the ActionPipe will die, too. |
191 shared_ptr<ActionPipe<typename ActionTraits<SubClass>::InputObjectType> > | 197 shared_ptr<ActionPipe<typename ActionTraits<SubClass>::InputObjectType> > |
192 in_pipe_; | 198 in_pipe_; |
193 shared_ptr<ActionPipe<typename ActionTraits<SubClass>::OutputObjectType> > | 199 shared_ptr<ActionPipe<typename ActionTraits<SubClass>::OutputObjectType> > |
194 out_pipe_; | 200 out_pipe_; |
195 }; | 201 }; |
196 | 202 |
197 }; // namespace chromeos_update_engine | 203 }; // namespace chromeos_update_engine |
198 | 204 |
199 #endif // UPDATE_ENGINE_ACTION_H__ | 205 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_H__ |
OLD | NEW |