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 
00116         //file to store history
00117         const char* histfile;
00118 
00121         base::DataSourceBase::shared_ptr last_expr;
00122 #if defined(HAS_READLINE) || defined(HAS_EDITLINE)
00123 #if defined(_POSIX_VERSION) && !defined(HAS_EDITLINE)
00124         static void rl_sigwinch_handler(int sig, siginfo_t *si, void *ctxt);
00125 #endif
00126 
00127         static int rl_received_signal;
00128         static void rl_signal_handler(int sig, siginfo_t *si, void *ctxt);
00129 
00130         /* Custom implementation of rl_getc() to handle signals correctly. */
00131         static int rl_getc(FILE *);
00132 
00133         /* Read a string, and return a pointer to it.
00134            Returns NULL on EOF. */
00135         char *rl_gets ();
00136 
00137         // use this vector to generate candidate strings
00138         static std::vector<std::string> candidates;
00139         // Add successful matches of candidate strings to completes.
00140         static std::vector<std::string> completes;
00141         static std::vector<std::string>::iterator complete_iter;
00142 
00143         static std::string component_found;
00144         static std::string component;
00145         static std::string peerpath;
00146         static std::string text;
00147 
00148         // helper function
00149         static char* dupstr( const char *s );
00150 
00151         static void find_completes();
00152 
00153         static void find_ops();
00154         static void find_peers(std::string::size_type startpos);
00155 
00156         static char ** orocos_hmi_completion ( const char *text, int start, int end );
00157 
00158         static char *command_generator( const char *_text, int state );
00159 #endif
00160         static RTT::TaskContext* findPeer( std::string comm );
00161 
00162     protected:
00163 
00164         void listText(std::stringstream& txtss,int start, int end, int ln, char s);
00165 
00166         void doPrint( RTT::base::DataSourceBase::shared_ptr ds, bool recurse);
00167 
00168         void enterTask();
00169         void leaveTask();
00170 
00171         bool macrorecording;
00172         std::string macrotext;
00173         std::string macroname;
00174         std::stringstream sresult;
00175         void recordMacro(std::string name);
00176         void cancelMacro();
00177         void endMacro();
00178 
00179         void checkPorts();
00180         Service::shared_ptr stringToService(std::string const& names);
00181     public:
00182 
00186         enum ColorTheme { nocolors, 
00187                           darkbg, 
00188                           whitebg  
00189         };
00190 
00191         void setColorTheme( ColorTheme t );
00192 
00198         void switchTaskContext(std::string& path);
00199 
00206         void switchTaskContext( RTT::TaskContext* tc, bool store = true);
00207 
00211         void switchBack();
00212 
00218         void browserAction(std::string& act );
00219 
00223         void printResult( RTT::base::DataSourceBase* ds, bool recurse);
00224 
00228         void printHelp();
00229 
00233         void printHelp(std::string command);
00234 
00238         void printInfo(const std::string& peerpath);
00239 
00243         void printSource( const std::string m );
00244 
00248         void printOperation( const std::string m, Service::shared_ptr ops );
00249 
00253         bool printService( const std::string name);
00254 
00258         void printProgram( const std::string& pn, int line = -1, RTT::TaskContext* progpeer = 0 );
00259 
00263         void printProgram( int line = -1 );
00264 
00269         TaskBrowser( RTT::TaskContext* c );
00270 
00271         ~TaskBrowser();
00272 
00278         void loop();
00279 
00286         void evaluate(std::string& comm );
00287 
00291         void switchTask( RTT::TaskContext* c);
00292 
00296         static std::string prompt;
00300         static std::string coloron;
00304         static std::string underline;
00308         static std::string coloroff;
00309 
00313         static std::string red;
00314 
00318         static std::string green;
00319 
00323         static std::string blue;
00324 
00328         void evalCommand(std::string& comm );
00329 
00330 
00331     };
00332 
00333 }
00334 
00335 #endif


ocl
Author(s): OCL Development Team
autogenerated on Sun Nov 27 2016 03:45:31