LRAUV  revA
MissionItem.h
Go to the documentation of this file.
1 
10 #ifndef MISSIONITEM_H_
11 #define MISSIONITEM_H_
12 
14 #include "component/Behavior.h"
15 #include "data/Double.h"
16 #include "data/Location.h"
17 #include "logger/Logger.h"
18 
19 class Aggregate;
20 class Component;
21 class DefineBehavior;
22 class MissionNode;
23 class Trigger;
24 class ValueClause;
25 
32 {
33 public:
34 
36  virtual ~MissionItem();
37 
39  static MissionItem* Instance( MissionItem* parent, MissionNode* node,
40  unsigned int tablePos, Logger& logger );
41 
44  {
45  return aggregate_ ? ( Aggregate* )component_ : NULL;
46  }
47 
50  {
51  return component_;
52  }
53 
55  void setComponent( Behavior* component )
56  {
57  component_ = component;
58  }
59 
61  bool isParallel()
62  {
63  return parallel_;
64  }
65 
67  void setParallel( bool parallel )
68  {
69  parallel_ = parallel;
70  }
71 
73  bool isSequence()
74  {
75  return sequence_;
76  }
77 
79  void setSequence( bool sequence )
80  {
81  sequence_ = sequence;
82  }
83 
85  bool isAggregate() const
86  {
87  return aggregate_;
88  }
89 
92  {
93  return ( isSequence() || ( isAggregate() && !isParallel() ) );
94  }
95 
97  unsigned int getTablePosition()
98  {
99  return tablePos_;
100  }
101 
102  // returns Boolean BREAK clause
104  {
105  return breakClause_;
106  }
107 
108  // returns Boolean WHEN clause
110  {
111  return whenClause_;
112  }
113 
114  // returns Boolean WHEN clause
116  {
117  return whileClause_;
118  }
119 
120  // returns Boolean PREEMPTIVE clause
122  {
123  return preemptiveClause_;
124  }
125 
126  // indicates if the clause is preemptive
127  bool isPreemptive();
128 
130  void setRepeatIndex( int repeatIndex );
131 
134  {
135  return repeatIndex_;
136  }
137 
140  {
141  return repeatLimit_;
142  }
143 
144  unsigned int getTablePos()
145  {
146  return tablePos_;
147  }
148 
149  // Returns true if the item's missionState is BEHAVIOR_ACTIVE,
150  // Or is equal to the indicated activeItem,
151  // Or has a whenClause or whileClause true,
152  // But not an breakClause true!
153  bool isActive( MissionItem* activeItem );
154 
155  void initialize();
156 
157  void run();
158 
159  bool runIfUnsatisfied();
160 
161  bool satisfied();
162 
164  void preempted();
165 
166  void uninitialize( /*PCaller& pCaller*/ );
167 
169  bool isTimedOut()
170  {
171  return timedOut_;
172  }
173 
175  {
176  return initialized_;
177  }
178 
179  const Timestamp& getStartTime() const
180  {
181  return startTime_;
182  }
183 
186  {
187  return parentItem_;
188  }
189 
190  void addCall();
191 
192  void removeCall();
193 
194  DataReader* findArgReader( const Str& argName ) const;
195 
196 protected:
198  MissionItem( MissionItem* parent, unsigned int tablePos );
199 
200  // Initializer
201  void initializeFromScript( MissionNode* node, Logger& logger );
202 
203  // Interpret Repeat attribute
204  void interpretRepeat( MissionNode* node, const Str& name, Logger& logger );
205 
206  // Interpret RunIn elements
207  void interpretRunIn( MissionNode* node, const Str& name, Logger& logger );
208 
209  MissionItem* findItemByRefId( const Str& refId ) const;
210 
211  void putDefineBehavior( const Str& name, DefineBehavior* defineBehavior );
212 
213  DefineBehavior* findDefineBehavior( const Str& name ) const;
214 
217 
219  unsigned int tablePos_;
220 
223 
225  bool sequence_;
226 
228  bool parallel_;
229 
232 
235 
238 
241 
244 
247 
250 
253 
256 
259 
261  bool timedOut_;
262 
265 
268 
271 
274 
277 
280 
283 
284 private:
285  // Note that the copy constructor below is private and not given a body.
286  // Any attempt to call it will return a compiler error.
287  MissionItem( const MissionItem& old ); // disallow copy constructor
288 
289  void setCompleted();
290 
291  void setTimedOut();
292 
293 };
294 
295 
296 
297 #endif /*MISSIONITEM_H_*/
Client-side interface for injecting log data into the log queue.
Definition: Logger.h:30
void setSequence(bool sequence)
Tell the item to run in sequence.
Definition: MissionItem.h:79
DataReader * repeatArgReader_
Reads timeout argument at timeout init time.
Definition: MissionItem.h:255
bool isParallel()
Indicates if the item runs in parallel.
Definition: MissionItem.h:61
MissionItem * timeoutItem_
Aggregate commands to execute in the case of a timeout. Can be empty.
Definition: MissionItem.h:267
static MissionItem * Instance(MissionItem *parent, MissionNode *node, unsigned int tablePos, Logger &logger)
Returns an instance, or NULL if an instance can't be returned.
Definition: MissionItem.cpp:69
MissionNode * node_
Used only while reading mission from XML. Do not use later!
Definition: MissionItem.h:279
bool parallel_
Indicates if missionComponent should be run all the time.
Definition: MissionItem.h:228
int repeatIndex_
Number of Times repeated so far.
Definition: MissionItem.h:249
Wraps a Behavior or Aggregate with mission-specific settings pertaining to that item.
Definition: MissionItem.h:31
bool sequence_
Indicates if missionComponent should be run sequentially.
Definition: MissionItem.h:225
bool satisfied()
Definition: MissionItem.cpp:276
MissionItem * findItemByRefId(const Str &refId) const
Definition: MissionItem.cpp:985
Collections of Behaviors (including other Aggregates) that make up a larger Behavior within a mission...
Definition: Aggregate.h:27
void setRepeatIndex(int repeatIndex)
resets the repeat index
Definition: MissionItem.cpp:93
ValueClause * getBreakClause()
Definition: MissionItem.h:103
void uninitialize()
Definition: MissionItem.cpp:333
void addCall()
Definition: MissionItem.cpp:348
bool isTimedOut()
True if this is timed out.
Definition: MissionItem.h:169
A DataAccessor that reads values from the Slate Contains a default dataValue that must not be NULL...
Definition: DataReader.h:30
void run()
Definition: MissionItem.cpp:183
Information to create a DefinedBehavior that is embedded in scripted code within a mission file...
Definition: DefineBehavior.h:74
MissionItem * getParent() const
Parent MissionItem.
Definition: MissionItem.h:185
bool isPreemptive()
Definition: MissionItem.cpp:86
bool initialized_
Flag used by parent aggregates.
Definition: MissionItem.h:276
const Timestamp & getStartTime() const
Definition: MissionItem.h:179
bool isAggregate() const
Indicates if the mission component is an aggreate behavior.
Definition: MissionItem.h:85
bool preempted_
True if the item is currently preempted.
Definition: MissionItem.h:273
Contains the ComponentRegistry class declaration.
void interpretRunIn(MissionNode *node, const Str &name, Logger &logger)
Definition: MissionItem.cpp:945
Aggregate * getAggregate() const
Returns the component as a Aggregate.
Definition: MissionItem.h:43
unsigned int getTablePosition()
Returns the position within the Aggregate.
Definition: MissionItem.h:97
Behavior is the abstract base class for components that implement mission behaviors and commands...
Definition: Behavior.h:32
void interpretRepeat(MissionNode *node, const Str &name, Logger &logger)
Definition: MissionItem.cpp:924
bool timedOut_
True if time since startTime exceed timeout.
Definition: MissionItem.h:261
bool isInitialized()
Definition: MissionItem.h:174
Timestamp startTime_
Keeps track of how long we've been running.
Definition: MissionItem.h:258
A ValueClause is a set of boolean conditions that may be specified as conditions for executing (or st...
Definition: ValueClause.h:26
void preempted()
Called when the mission component becomes preempted.
Definition: MissionItem.cpp:320
MissionItem * parentItem_
Parent MissionItem.
Definition: MissionItem.h:216
Behavior * component_
Single item.
Definition: MissionItem.h:222
Contains the Behavior class definition.
ValueClause * whenClause_
Boolean WHEN clauses.
Definition: MissionItem.h:237
void setTimedOut()
Definition: MissionItem.cpp:975
ValueClause * whileClause_
Boolean WHILE clause.
Definition: MissionItem.h:240
void initialize()
Definition: MissionItem.cpp:130
Wraps a TiXmlNode.
Definition: MissionNode.h:20
unsigned int tablePos_
Position within the Aggregate.
Definition: MissionItem.h:219
Replacement for standard template class string.
Definition: Str.h:12
int callCount_
Number of calls to this item.
Definition: MissionItem.h:246
ValueClause * getWhenClause()
Definition: MissionItem.h:109
DataReader * findArgReader(const Str &argName) const
Definition: MissionItem.cpp:1022
Abstract Base class for software components.
Definition: Component.h:53
bool isSequence()
Indicates if the item runs in sequence.
Definition: MissionItem.h:73
int repeatLimit_
Number of Times to repeat this item.
Definition: MissionItem.h:252
bool runIfUnsatisfied()
Definition: MissionItem.cpp:226
MissionItem(MissionItem *parent, unsigned int tablePos)
Protected Constructor.
Definition: MissionItem.cpp:378
virtual ~MissionItem()
Destructor.
Definition: MissionItem.cpp:29
DataReader * timeoutArgReader_
Reads timeout argument at timeout init time.
Definition: MissionItem.h:264
bool aggregate_
Aggregate item?
Definition: MissionItem.h:231
DefineBehavior * findDefineBehavior(const Str &name) const
Definition: MissionItem.cpp:1008
bool isActive(MissionItem *activeItem)
Definition: MissionItem.cpp:106
Contains the Logger class definition.
void setCompleted()
void initializeFromScript(MissionNode *node, Logger &logger)
Definition: MissionItem.cpp:405
FastMap< const Str, DefineBehavior * > * defineBehaviors_
Map of DefineBehavior instances.
Definition: MissionItem.h:270
int getRepeatLimit()
returns the repeat limit
Definition: MissionItem.h:139
void removeCall()
Definition: MissionItem.cpp:365
ValueClause * getWhileClause()
Definition: MissionItem.h:115
ValueClause * getPreemptiveClause()
Definition: MissionItem.h:121
void putDefineBehavior(const Str &name, DefineBehavior *defineBehavior)
Definition: MissionItem.cpp:999
bool isCompletable()
Indicates if the mission component is a command.
Definition: MissionItem.h:91
void setParallel(bool parallel)
Tell the item to run in parallel.
Definition: MissionItem.h:67
ValueClause * preemptiveClause_
Indicates that the clause is preemptive.
Definition: MissionItem.h:243
Contains the Location class definition.
ValueClause * breakClause_
Boolean BREAK clause.
Definition: MissionItem.h:234
Contains the Double class definition.
unsigned int getTablePos()
Definition: MissionItem.h:144
bool ignoreWhenWhile_
If true, this is a called item, so the when clause is ignored.
Definition: MissionItem.h:282
Behavior * getComponent() const
Returns the mission component.
Definition: MissionItem.h:49
Represents absolute times.
Definition: Timestamp.h:31
int getRepeatIndex()
returns the repeat index
Definition: MissionItem.h:133
void setComponent(Behavior *component)
Sets the mission component.
Definition: MissionItem.h:55