TaskBrowser.hpp
Go to the documentation of this file.
00001 #ifndef NO_GPL
00002 /***************************************************************************
00003   tag: Peter Soetens  Thu Jul 3 15:31:33 CEST 2008  TaskBrowser.hpp
00004 
00005                         TaskBrowser.hpp -  description
00006                            -------------------
00007     begin                : Thu July 03 2008
00008     copyright            : (C) 2008 Peter Soetens
00009     email                : peter.soetens@fmtc.be
00010 
00011  ***************************************************************************
00012  *                                                                         *
00013  *   This program is free software; you can redistribute it and/or modify  *
00014  *   it under the terms of the GNU General Public License as published by  *
00015  *   the Free Software Foundation; either version 2 of the License, or     *
00016  *   (at your option) any later version.                                   *
00017  *                                                                         *
00018  *   This program is distributed in the hope that it will be useful,       *
00019  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00020  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00021  *   General Public License for more details.                              *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public             *
00024  *   License along with this program; if not, write to the Free Software   *
00025  *   Foundation, Inc., 59 Temple Place,                                    *
00026  *   Suite 330, Boston, MA  02111-1307  USA                                *
00027  ***************************************************************************/
00028 #else
00029 /***************************************************************************
00030   tag: Peter Soetens  Tue Dec 21 22:43:08 CET 2004  TaskBrowser.hpp
00031 
00032                         TaskBrowser.hpp -  description
00033                            -------------------
00034     begin                : Tue December 21 2004
00035     copyright            : (C) 2004 Peter Soetens
00036     email                : peter.soetens@mech.kuleuven.ac.be
00037 
00038  ***************************************************************************
00039  *   This library is free software; you can redistribute it and/or         *
00040  *   modify it under the terms of the GNU Lesser General Public            *
00041  *   License as published by the Free Software Foundation; either          *
00042  *   version 2.1 of the License, or (at your option) any later version.    *
00043  *                                                                         *
00044  *   This library is distributed in the hope that it will be useful,       *
00045  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00046  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00047  *   Lesser General Public License for more details.                       *
00048  *                                                                         *
00049  *   You should have received a copy of the GNU Lesser General Public      *
00050  *   License along with this library; if not, write to the Free Software   *
00051  *   Foundation, Inc., 59 Temple Place,                                    *
00052  *   Suite 330, Boston, MA  02111-1307  USA                                *
00053  *                                                                         *
00054  ***************************************************************************/
00055 #endif
00056 
00057 #ifndef ORO_TASKBROWSER_HPP
00058 #define ORO_TASKBROWSER_HPP
00059 
00060 
00061 #include <rtt/RTT.hpp>
00062 #include <rtt/TaskContext.hpp>
00063 #include <rtt/Service.hpp>
00064 #include <deque>
00065 #include <string>
00066 #include <sstream>
00067 #include <vector>
00068 #if defined(HAS_READLINE) && !defined(HAS_EDITLINE) && defined(_POSIX_VERSION)
00069 #include <signal.h>
00070 #endif
00071 
00072 #include <ocl/OCL.hpp>
00073 
00074 namespace OCL
00075 {
00086     class OCL_API TaskBrowser
00087         : public RTT::TaskContext
00088     {
00089         // the 'current' task context
00090         static RTT::TaskContext* taskcontext;
00091         // the TC we are using for completion.
00092         static RTT::TaskContext* peer;
00093         // the TaskBrowser
00094         static RTT::TaskContext* tb;
00095         // the current Context: is tb or taskcontext
00096         static RTT::TaskContext* context;
00097         static RTT::Service::shared_ptr taskobject;
00098         RTT::internal::DataSource<bool>::shared_ptr   accepted;
00099 
00100         int debug;
00101         /* A static variable for holding the line. */
00102         char *line_read;
00103         int lastc; // last command's number
00104 
00105         std::string storedname; 
00106         int storedline; 
00107         bool usehex;
00108 
00109         std::deque<RTT::TaskContext*> taskHistory;
00110 
00111         // store TC + program/state name + line number
00112         typedef std::map<std::pair<RTT::TaskContext*,std::string>,int> PTrace;
00113         PTrace ptraces;
00114         PTrace straces;
00115 
00118         base::DataSourceBase::shared_ptr last_expr;
00119 #if defined(HAS_READLINE) || defined(HAS_EDITLINE)
00120 #if defined(_POSIX_VERSION) && !defined(HAS_EDITLINE)
00121         static void rl_sigwinch_handler(int sig, siginfo_t *si, void *ctxt);
00122 #endif
00123         /* Read a string, and return a pointer to it.
00124            Returns NULL on EOF. */
00125         char *rl_gets ();
00126 
00127         // use this vector to generate candidate strings
00128         static std::vector<std::string> candidates;
00129         // Add successful matches of candidate strings to completes.
00130         static std::vector<std::string> completes;
00131         static std::vector<std::string>::iterator complete_iter;
00132 
00133         static std::string component_found;
00134         static std::string component;
00135         static std::string peerpath;
00136         static std::string text;
00137 
00138         // helper function
00139         static char* dupstr( const char *s );
00140 
00141         static void find_completes();
00142 
00143         static void find_ops();
00144         static void find_peers(std::string::size_type startpos);
00145 
00146         static char ** orocos_hmi_completion ( const char *text, int start, int end );
00147 
00148         static char *command_generator( const char *_text, int state );
00149 #endif
00150         static RTT::TaskContext* findPeer( std::string comm );
00151 
00152     protected:
00153 
00154         void listText(std::stringstream& txtss,int start, int end, int ln, char s);
00155 
00156         void doPrint( RTT::base::DataSourceBase::shared_ptr ds, bool recurse);
00157 
00158         void enterTask();
00159         void leaveTask();
00160 
00161         bool macrorecording;
00162         std::string macrotext;
00163         std::string macroname;
00164         std::stringstream sresult;
00165         void recordMacro(std::string name);
00166         void cancelMacro();
00167         void endMacro();
00168 
00169         void checkPorts();
00170         Service::shared_ptr stringToService(std::string const& names);
00171     public:
00172 
00176         enum ColorTheme { nocolors, 
00177                           darkbg, 
00178                           whitebg  
00179         };
00180 
00181         void setColorTheme( ColorTheme t );
00182 
00188         void switchTaskContext(std::string& path);
00189 
00196         void switchTaskContext( RTT::TaskContext* tc, bool store = true);
00197 
00201         void switchBack();
00202 
00208         void browserAction(std::string& act );
00209 
00213         void printResult( RTT::base::DataSourceBase* ds, bool recurse);
00214 
00218         void printHelp();
00219 
00223         void printHelp(std::string command);
00224 
00228         void printInfo(const std::string& peerpath);
00229 
00233         void printSource( const std::string m );
00234 
00238         void printOperation( const std::string m, Service::shared_ptr ops );
00239 
00243         bool printService( const std::string name);
00244 
00248         void printProgram( const std::string& pn, int line = -1, RTT::TaskContext* progpeer = 0 );
00249 
00253         void printProgram( int line = -1 );
00254 
00259         TaskBrowser( RTT::TaskContext* c );
00260 
00261         ~TaskBrowser();
00262 
00268         void loop();
00269 
00276         void evaluate(std::string& comm );
00277 
00281         void switchTask( RTT::TaskContext* c);
00282 
00286         static std::string prompt;
00290         static std::string coloron;
00294         static std::string underline;
00298         static std::string coloroff;
00299 
00303         static std::string red;
00304 
00308         static std::string green;
00309 
00313         static std::string blue;
00314 
00318         void evalCommand(std::string& comm );
00319 
00320 
00321     };
00322 
00323 }
00324 
00325 #endif


ocl
Author(s): OCL Development Team
autogenerated on Mon Oct 6 2014 03:16:37