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 CHROMEOS_PLATFORM_UPDATE_ENGINE_PIPE_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_PIPE_H__ |
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_PIPE_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_PIPE_H__ |
7 | 7 |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <iostream> | 9 #include <iostream> |
10 #include <map> | 10 #include <map> |
(...skipping 11 matching lines...) Expand all Loading... |
22 // This class serves as a temporary holding area for an object passed out | 22 // This class serves as a temporary holding area for an object passed out |
23 // from one Action and into another Action. It's templated so that it may | 23 // from one Action and into another Action. It's templated so that it may |
24 // contain any type of object that an Action outputs/inputs. Actions | 24 // contain any type of object that an Action outputs/inputs. Actions |
25 // cannot be bonded (i.e., connected with a pipe) if their output/input | 25 // cannot be bonded (i.e., connected with a pipe) if their output/input |
26 // object types differ (a compiler error will result). | 26 // object types differ (a compiler error will result). |
27 // | 27 // |
28 // An ActionPipe is generally created with the Bond() method and owned by | 28 // An ActionPipe is generally created with the Bond() method and owned by |
29 // the two Action objects. a shared_ptr is used so that when the last Action | 29 // the two Action objects. a shared_ptr is used so that when the last Action |
30 // pointing to an ActionPipe dies, the ActionPipe dies, too. | 30 // pointing to an ActionPipe dies, the ActionPipe dies, too. |
31 | 31 |
32 using std::map; | |
33 using std::string; | |
34 using std::tr1::shared_ptr; | |
35 | |
36 namespace chromeos_update_engine { | 32 namespace chromeos_update_engine { |
37 | 33 |
38 // Used by Actions an InputObjectType or OutputObjectType to specify that | 34 // Used by Actions an InputObjectType or OutputObjectType to specify that |
39 // for that type, no object is taken/given. | 35 // for that type, no object is taken/given. |
40 class NoneType {}; | 36 class NoneType {}; |
41 | 37 |
42 template<typename T> | 38 template<typename T> |
43 class Action; | 39 class Action; |
44 | 40 |
45 template<typename ObjectType> | 41 template<typename ObjectType> |
46 class ActionPipe { | 42 class ActionPipe { |
47 public: | 43 public: |
48 virtual ~ActionPipe() { | 44 virtual ~ActionPipe() { |
49 LOG(INFO) << "ActionPipe died"; | 45 LOG(INFO) << "ActionPipe died"; |
50 } | 46 } |
51 | 47 |
52 // This should be called by an Action on its input pipe. | 48 // This should be called by an Action on its input pipe. |
53 // Returns a reference to the stored object. | 49 // Returns a reference to the stored object. |
54 const ObjectType& contents() const { return contents_; } | 50 const ObjectType& contents() const { return contents_; } |
55 | 51 |
56 // This should be called by an Action on its output pipe. | 52 // This should be called by an Action on its output pipe. |
57 // Stores a copy of the passed object in this pipe. | 53 // Stores a copy of the passed object in this pipe. |
58 void set_contents(const ObjectType& contents) { contents_ = contents; } | 54 void set_contents(const ObjectType& contents) { contents_ = contents; } |
59 | 55 |
60 // Bonds two Actions together with a new ActionPipe. The ActionPipe is | 56 // Bonds two Actions together with a new ActionPipe. The ActionPipe is |
61 // jointly owned by the two Actions and will be automatically destroyed | 57 // jointly owned by the two Actions and will be automatically destroyed |
62 // when the last Action is destroyed. | 58 // when the last Action is destroyed. |
63 template<typename FromAction, typename ToAction> | 59 template<typename FromAction, typename ToAction> |
64 static void Bond(FromAction* from, ToAction* to) { | 60 static void Bond(FromAction* from, ToAction* to) { |
65 shared_ptr<ActionPipe<ObjectType> > pipe(new ActionPipe<ObjectType>); | 61 std::tr1::shared_ptr<ActionPipe<ObjectType> > pipe( |
| 62 new ActionPipe<ObjectType>); |
66 from->set_out_pipe(pipe); | 63 from->set_out_pipe(pipe); |
67 | 64 |
68 to->set_in_pipe(pipe); // If you get an error on this line, then | 65 to->set_in_pipe(pipe); // If you get an error on this line, then |
69 // it most likely means that the From object's OutputObjectType is | 66 // it most likely means that the From object's OutputObjectType is |
70 // different from the To object's InputObjectType. | 67 // different from the To object's InputObjectType. |
71 } | 68 } |
72 | 69 |
73 private: | 70 private: |
74 ObjectType contents_; | 71 ObjectType contents_; |
75 | 72 |
76 // The ctor is private. This is because this class should construct itself | 73 // The ctor is private. This is because this class should construct itself |
77 // via the static Bond() method. | 74 // via the static Bond() method. |
78 ActionPipe() {} | 75 ActionPipe() {} |
79 DISALLOW_COPY_AND_ASSIGN(ActionPipe); | 76 DISALLOW_COPY_AND_ASSIGN(ActionPipe); |
80 }; | 77 }; |
81 | 78 |
82 // Utility function | 79 // Utility function |
83 template<typename FromAction, typename ToAction> | 80 template<typename FromAction, typename ToAction> |
84 void BondActions(FromAction* from, ToAction* to) { | 81 void BondActions(FromAction* from, ToAction* to) { |
85 // TODO(adlr): find something like this that the compiler accepts: | 82 // TODO(adlr): find something like this that the compiler accepts: |
86 // COMPILE_ASSERT(typeof(typename FromAction::OutputObjectType) == | 83 // COMPILE_ASSERT(typeof(typename FromAction::OutputObjectType) == |
87 // typeof(typename ToAction::InputObjectType), | 84 // typeof(typename ToAction::InputObjectType), |
88 // FromAction_OutputObjectType_doesnt_match_ToAction_InputObjectType); | 85 // FromAction_OutputObjectType_doesnt_match_ToAction_InputObjectType); |
89 ActionPipe<typename FromAction::OutputObjectType>::Bond(from, to); | 86 ActionPipe<typename FromAction::OutputObjectType>::Bond(from, to); |
90 } | 87 } |
91 | 88 |
92 } // namespace chromeos_update_engine | 89 } // namespace chromeos_update_engine |
93 | 90 |
94 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PIPE_H__ | 91 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PIPE_H__ |
OLD | NEW |