File: ArServerHandlerMapping.h

package info (click to toggle)
libaria 2.8.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 13,628 kB
  • ctags: 16,574
  • sloc: cpp: 135,490; makefile: 925; python: 597; java: 570; ansic: 182
file content (193 lines) | stat: -rw-r--r-- 7,573 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#ifndef ARSERVERHANDLERMAPPING_H
#define ARSERVERHANDLERMAPPING_H

#include "Aria.h"
#include "ArServerBase.h"
#include "ArServerHandlerCommands.h"
#include "ArTempDirectoryHelper.h"

/// Class that handles the starting, stopping, and status of mapping
class ArServerHandlerMapping
{
public:
  /// Constructor
  AREXPORT ArServerHandlerMapping(ArServerBase *server, ArRobot *robot,
				  ArLaser *laser, 
				  const char *baseDirectory = "",
				  const char *tempDirectory = "",
				  bool useReflectorValues = false,
				  ArLaser *laser2 = NULL, 
				  const char *sickSuffix = NULL,
				  const char *sick2Suffix = NULL,
				  std::list<ArLaser *> *extraLasers = NULL);
  /// Deconstructor
  AREXPORT virtual ~ArServerHandlerMapping();
  /// Starts a new map unless ones already made
  AREXPORT void serverMappingStart(ArServerClient *client, 
				   ArNetPacket *packet);
  /// Ends a map
  AREXPORT void serverMappingEnd(ArServerClient *client, 
				 ArNetPacket *packet);
  /// Gets the mapping status
  AREXPORT void serverMappingStatus(ArServerClient *client, 
				    ArNetPacket *packet);
  /// Returns if we're mapping or not
  AREXPORT bool isMapping(void);

  /// Forces a reading to be taken
  AREXPORT void forceReading(void);

  /// Gets the filename we're using (make sure the robot's locked)
  AREXPORT const char *getFileName(void);
  /// Gets the mapname we're using (make sure the robot's locked)
  AREXPORT const char *getMapName(void);
  /// Adds the simple commands to the simple command handler passed in
  AREXPORT void addSimpleCommands(ArServerHandlerCommands *handlerCommands);
  /// Adds a loop start to the log
  AREXPORT void simpleLoopStart(ArArgumentBuilder *arg);
  /// Adds a loop end to the log
  AREXPORT void simpleLoopEnd(ArArgumentBuilder *arg);
  /// Adds a string for adding to the log when we start
  AREXPORT void addStringForStartOfLogs(
	  const char *str, ArListPos::Pos position = ArListPos::LAST);
  /// Removes a string for adding to the log when we start
  AREXPORT void remStringForStartOfLogs(const char *str);
  /// Adds a tag to the logg (has robot pose and stuff) (make sure the
  /// robot's locked)
  AREXPORT void addTagToLog(const char *str);
  /// Adds an info to the log (has no robot pose) (make sure the
  /// robot's locked)
  AREXPORT void addInfoToLog(const char *str);
  /// Adds a new type of location data to the logger
  AREXPORT bool addLocationData(
	  const char *name, 
	  ArRetFunctor3<int, ArTime, ArPose *, ArPoseWithTime *> *functor);

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  // Callback Methods
  //
  //   The mapping callbacks are invoked in the order in which they appear
  //   in this header file.  Namely:
  //      1. MappingStart
  //      2. MappingBegun (this is logically "mapping started")
  //      3. MappingEnd
  //      4. MappingEnded
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  /// Adds a callback for the start of mapping
  AREXPORT void addMappingStartCallback(
	  ArFunctor *functor, ArListPos::Pos position = ArListPos::LAST);
  /// Removes a callback for the start of mapping
  AREXPORT void remMappingStartCallback(ArFunctor *functor);

  /// Adds a callback for just after mapping has started
  AREXPORT void addMappingBegunCallback(
	  ArFunctor *functor, ArListPos::Pos position = ArListPos::LAST);
  /// Removes a callback for just after mapping has started
  AREXPORT void remMappingBegunCallback(ArFunctor *functor);

  /// Adds a callback for the end of mapping
  AREXPORT void addMappingEndCallback(
	  ArFunctor *functor, ArListPos::Pos position = ArListPos::LAST);
  /// Removes a callback for the end of mapping
  AREXPORT void remMappingEndCallback(ArFunctor *functor);

  /// Adds a callback that is invoked after mapping has been ended. 
  AREXPORT void addMappingEndedCallback(
	  ArFunctor *functor, ArListPos::Pos position = ArListPos::LAST);
  /// Removes a callback from the list invoked after mapping has been ended.
  AREXPORT void remMappingEndedCallback(ArFunctor *functor);
  

  /// Adds a callback to be called before moving from temp dir to base dir
  AREXPORT void addPreMoveCallback(
	  ArFunctor *functor, ArListPos::Pos position = ArListPos::LAST);
  /// Removes a callback to be called before moving from temp dir to base dir
  AREXPORT void remPreMoveCallback(ArFunctor *functor);
  
  /// Adds a callback to be called after moving from temp dir to base dir
  AREXPORT void addPostMoveCallback(
	  ArFunctor *functor, ArListPos::Pos position = ArListPos::LAST);
  /// Removes a callback to be called after moving from temp dir to base dir
  AREXPORT void remPostMoveCallback(ArFunctor *functor);


  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  // Misc Methods 
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  /// The packet handler for starting/stopping scans from the lcd
  AREXPORT bool packetHandler(ArRobotPacket *packet);
  /// Get location data map (mostly for internal things)
  AREXPORT const std::map<std::string, ArRetFunctor3<int, ArTime, ArPose *, ArPoseWithTime *> *, 
		 ArStrCaseCmpOp> *getLocationDataMap(void);
  /// A method to add the strings for the start of a log just straight to an ArMap
  AREXPORT void addStringsForStartOfLogToMap(ArMap *arMap);


  /// Returns a pointer to the optional zip file installed on this handler.
  AREXPORT ArZippable *getZipFile();
  
  /// Returns a pointer to a second optional zip file used to contain snapshot images.
  AREXPORT ArZippable *getSnapshotZipFile();
 
  /// Sets the optional zip file installed on this handler.
  AREXPORT void setZipFile(ArZippable *zipFile);
  
  /// Sets the optional zip file installed on this handler.
  AREXPORT void setSnapshotZipFile(ArZippable *zipFile);

protected:


  AREXPORT std::string makeFilePathName(const char *fileName);

  ArServerBase *myServer;
  ArRobot *myRobot;
  ArLaser *myLaser;
  ArLaser *myLaser2;
  bool myUseReflectorValues;
  
  std::list<ArFunctor *> myMappingStartCallbacks;
  std::list<ArFunctor *> myMappingBegunCallbacks;
  std::list<ArFunctor *> myMappingEndCallbacks;
  std::list<ArFunctor *> myMappingEndedCallbacks;
  
  std::list<ArFunctor *> myPreMoveCallbacks;
  std::list<ArFunctor *> myPostMoveCallbacks;

  std::list<std::string> myStringsForStartOfLog;
  ArLaserLogger *myLaserLogger;
  ArLaserLogger *myLaserLogger2;
  std::string myMapName;
  std::string myFileName;
  std::string myFileName2;
  
  std::string mySuffix;
  std::string mySuffix2;

  std::list<ArLaser *> *myExtraLasers;
  
  ArTempDirectoryHelper myTempDirectoryHelper;

  /// Optional zip file in which mapping results may be saved
  ArZippable *myZipFile;
  /// Second optional zip file in which snaphots may be saved 
  ArZippable *mySnapshotZipFile;

  std::map<std::string, ArRetFunctor3<int, ArTime, ArPose *, 
				      ArPoseWithTime *> *, 
	   ArStrCaseCmpOp> myLocationDataMap;

  ArFunctor2C<ArServerHandlerMapping, ArServerClient *, ArNetPacket *> myMappingStartCB;
  ArFunctor2C<ArServerHandlerMapping, ArServerClient *, ArNetPacket *> myMappingEndCB;
  ArFunctor2C<ArServerHandlerMapping, ArServerClient *, ArNetPacket *> myMappingStatusCB;
  ArServerHandlerCommands *myHandlerCommands;
  ArRetFunctor1C<bool, ArServerHandlerMapping, ArRobotPacket *> myPacketHandlerCB;
  ArFunctor1C<ArServerHandlerMapping, ArArgumentBuilder *> myLoopStartCB;
  ArFunctor1C<ArServerHandlerMapping, ArArgumentBuilder *> myLoopEndCB;
};



#endif // ARSERVERHANDLERMAPPING_H