OrocosComponentLibrary  2.8.3
TaskBrowser.hpp
1 #ifndef NO_GPL
2 /***************************************************************************
3  tag: Peter Soetens Thu Jul 3 15:31:33 CEST 2008 TaskBrowser.hpp
4 
5  TaskBrowser.hpp - description
6  -------------------
7  begin : Thu July 03 2008
8  copyright : (C) 2008 Peter Soetens
9  email : peter.soetens@fmtc.be
10 
11  ***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  * This program is distributed in the hope that it will be useful, *
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
21  * General Public License for more details. *
22  * *
23  * You should have received a copy of the GNU General Public *
24  * License along with this program; if not, write to the Free Software *
25  * Foundation, Inc., 59 Temple Place, *
26  * Suite 330, Boston, MA 02111-1307 USA *
27  ***************************************************************************/
28 #else
29 /***************************************************************************
30  tag: Peter Soetens Tue Dec 21 22:43:08 CET 2004 TaskBrowser.hpp
31 
32  TaskBrowser.hpp - description
33  -------------------
34  begin : Tue December 21 2004
35  copyright : (C) 2004 Peter Soetens
36  email : peter.soetens@mech.kuleuven.ac.be
37 
38  ***************************************************************************
39  * This library is free software; you can redistribute it and/or *
40  * modify it under the terms of the GNU Lesser General Public *
41  * License as published by the Free Software Foundation; either *
42  * version 2.1 of the License, or (at your option) any later version. *
43  * *
44  * This library is distributed in the hope that it will be useful, *
45  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
46  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
47  * Lesser General Public License for more details. *
48  * *
49  * You should have received a copy of the GNU Lesser General Public *
50  * License along with this library; if not, write to the Free Software *
51  * Foundation, Inc., 59 Temple Place, *
52  * Suite 330, Boston, MA 02111-1307 USA *
53  * *
54  ***************************************************************************/
55 #endif
56 
57 #ifndef ORO_TASKBROWSER_HPP
58 #define ORO_TASKBROWSER_HPP
59 
60 
61 #include <rtt/RTT.hpp>
62 #include <rtt/TaskContext.hpp>
63 #include <rtt/Service.hpp>
64 #include <deque>
65 #include <string>
66 #include <sstream>
67 #include <vector>
68 #if defined(HAS_READLINE) && !defined(HAS_EDITLINE) && defined(_POSIX_VERSION)
69 #include <signal.h>
70 #endif
71 
72 #include <ocl/OCL.hpp>
73 
74 namespace OCL
75 {
86  class OCL_API TaskBrowser
87  : public RTT::TaskContext
88  {
89  // the 'current' task context
90  static RTT::TaskContext* taskcontext;
91  // the TC we are using for completion.
92  static RTT::TaskContext* peer;
93  // the TaskBrowser
94  static RTT::TaskContext* tb;
95  // the current Context: is tb or taskcontext
96  static RTT::TaskContext* context;
97  static RTT::Service::shared_ptr taskobject;
98  RTT::internal::DataSource<bool>::shared_ptr accepted;
99 
100  int debug;
101  /* A static variable for holding the line. */
102  char *line_read;
103  int lastc; // last command's number
104 
105  std::string storedname;
106  int storedline;
107  bool usehex;
108 
109  std::deque<RTT::TaskContext*> taskHistory;
110 
111  // store TC + program/state name + line number
112  typedef std::map<std::pair<RTT::TaskContext*,std::string>,int> PTrace;
113  PTrace ptraces;
114  PTrace straces;
115 
116  //file to store history
117  const char* histfile;
118 
121  base::DataSourceBase::shared_ptr last_expr;
122 #if defined(HAS_READLINE) || defined(HAS_EDITLINE)
123 #if defined(_POSIX_VERSION) && !defined(HAS_EDITLINE)
124  static void rl_sigwinch_handler(int sig, siginfo_t *si, void *ctxt);
125 #endif
126 
127  static int rl_received_signal;
128  static void rl_signal_handler(int sig, siginfo_t *si, void *ctxt);
129 
130  /* Custom implementation of rl_getc() to handle signals correctly. */
131  static int rl_getc(FILE *);
132 
133  /* Read a string, and return a pointer to it.
134  Returns NULL on EOF. */
135  char *rl_gets ();
136 
137  // use this vector to generate candidate strings
138  static std::vector<std::string> candidates;
139  // Add successful matches of candidate strings to completes.
140  static std::vector<std::string> completes;
141  static std::vector<std::string>::iterator complete_iter;
142 
143  static std::string component_found;
144  static std::string component;
145  static std::string peerpath;
146  static std::string text;
147 
148  // helper function
149  static char* dupstr( const char *s );
150 
151  static void find_completes();
152 
153  static void find_ops();
154  static void find_peers(std::string::size_type startpos);
155 
156  static char ** orocos_hmi_completion ( const char *text, int start, int end );
157 
158  static char *command_generator( const char *_text, int state );
159 #endif
160  static RTT::TaskContext* findPeer( std::string comm );
161 
162  protected:
163 
164  void listText(std::stringstream& txtss,int start, int end, int ln, char s);
165 
166  void doPrint( RTT::base::DataSourceBase::shared_ptr ds, bool recurse);
167 
168  void enterTask();
169  void leaveTask();
170 
171  bool macrorecording;
172  std::string macrotext;
173  std::string macroname;
174  std::stringstream sresult;
175  void recordMacro(std::string name);
176  void cancelMacro();
177  void endMacro();
178 
179  void checkPorts();
180  Service::shared_ptr stringToService(std::string const& names);
181  public:
182 
188  whitebg
189  };
190 
191  void setColorTheme( ColorTheme t );
192 
198  void switchTaskContext(std::string& path);
199 
206  void switchTaskContext( RTT::TaskContext* tc, bool store = true);
207 
211  void switchBack();
212 
218  void browserAction(std::string& act );
219 
223  void printResult( RTT::base::DataSourceBase* ds, bool recurse);
224 
228  void printHelp();
229 
233  void printHelp(std::string command);
234 
238  void printInfo(const std::string& peerpath);
239 
243  void printSource( const std::string m );
244 
248  void printOperation( const std::string m, Service::shared_ptr ops );
249 
253  bool printService( const std::string name);
254 
258  void printProgram( const std::string& pn, int line = -1, RTT::TaskContext* progpeer = 0 );
259 
263  void printProgram( int line = -1 );
264 
269  TaskBrowser( RTT::TaskContext* c );
270 
271  ~TaskBrowser();
272 
278  void loop();
279 
286  void evaluate(std::string& comm );
287 
291  void switchTask( RTT::TaskContext* c);
292 
296  static std::string prompt;
300  static std::string coloron;
304  static std::string underline;
308  static std::string coloroff;
309 
313  static std::string red;
314 
318  static std::string green;
319 
323  static std::string blue;
324 
328  void evalCommand(std::string& comm );
329 
330 
331  };
332 
333 }
334 
335 #endif
static std::string coloron
The &#39;turn color on&#39; escape sequence.
static std::string underline
The &#39;underline&#39; escape sequence.
This component allows a text client to browse the peers of a peer RTT::TaskContext and execute comman...
Definition: TaskBrowser.hpp:86
static std::string green
The green color.
static std::string blue
The blue color.
The Orocos Component Library.
Definition: Component.hpp:43
Do not use colors.
ColorTheme
The kinds of color themes the TaskBrowser supports.
static std::string prompt
The prompt.
static std::string coloroff
The &#39;turn color off&#39; escape sequence.
Use colors suitable for a dark background.
static std::string red
The red color.