/home/sspr/src/www/orocos-1.0/export/build/orocos-ocl-1.4.0/taskbrowser/TaskBrowser.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Tue Dec 21 22:43:08 CET 2004  TaskBrowser.hpp 
00003 
00004                         TaskBrowser.hpp -  description
00005                            -------------------
00006     begin                : Tue December 21 2004
00007     copyright            : (C) 2004 Peter Soetens
00008     email                : peter.soetens@mech.kuleuven.ac.be
00009  
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU Lesser General Public            *
00013  *   License as published by the Free Software Foundation; either          *
00014  *   version 2.1 of the License, or (at your option) any later version.    *
00015  *                                                                         *
00016  *   This library is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00019  *   Lesser General Public License for more details.                       *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU Lesser General Public      *
00022  *   License along with this library; if not, write to the Free Software   *
00023  *   Foundation, Inc., 59 Temple Place,                                    *
00024  *   Suite 330, Boston, MA  02111-1307  USA                                *
00025  *                                                                         *
00026  ***************************************************************************/
00027  
00028  
00029 #ifndef ORO_TASKBROWSER_HPP
00030 #define ORO_TASKBROWSER_HPP
00031  
00032 
00033 #include <rtt/RTT.hpp>
00034 #include <rtt/TaskContext.hpp>
00035 #include "rtt/OperationInterface.hpp"
00036 #include "rtt/DispatchInterface.hpp"
00037 #include <deque>
00038 #include <string>
00039 #include <sstream>
00040 #include <vector>
00041 
00042 
00043 #include <ocl/OCL.hpp>
00044 
00045 namespace OCL
00046 {
00057     class TaskBrowser
00058         : public RTT::TaskContext
00059     {
00060         // the 'current' task context
00061         static RTT::TaskContext* taskcontext;
00062         // the TC we are using for completion.
00063         static RTT::TaskContext* peer;
00064         // the TaskBrowser
00065         static RTT::TaskContext* tb;
00066         // the current Context: is tb or taskcontext
00067         static RTT::TaskContext* context;
00068         static RTT::OperationInterface* taskobject;
00069         RTT::ConditionInterface* condition;
00070         RTT::DispatchInterface*   command;
00071         RTT::DataSource<bool>::shared_ptr   accepted;
00072 
00073         int debug;
00074         /* A static variable for holding the line. */
00075         char *line_read;
00076         int lastc; // last command's number
00077 
00078         std::string storedname; 
00079         int storedline; 
00080 
00081         std::deque<TaskContext*> taskHistory;
00082 
00083         // store TC + program/state name + line number
00084         typedef std::map<std::pair<TaskContext*,std::string>,int> PTrace;
00085         PTrace ptraces;
00086         PTrace straces;
00087 
00088         /* Read a string, and return a pointer to it.
00089            Returns NULL on EOF. */
00090         char *rl_gets ();
00091 
00092         // use this vector to generate candidate strings
00093         static std::vector<std::string> candidates;
00094         // Add successful matches of candidate strings to completes.
00095         static std::vector<std::string> completes;
00096         static std::vector<std::string>::iterator complete_iter;
00097 
00098         static std::string component;
00099         static std::string object;
00100         static std::string peerpath;
00101         static std::string method;
00102         static std::string datasource;
00103         static std::string text;
00104 
00105         // helper function
00106         static char* dupstr( const char *s );
00107 
00108         static RTT::TaskContext* findPeer( std::string comm );
00109 
00110         static void find_completes();
00111         
00112         static void find_ops();
00113         static void find_peers(std::string::size_type startpos);
00114 
00115         static char ** orocos_hmi_completion ( const char *text, int start, int end );
00116 
00117         static char *command_generator( const char *_text, int state );
00118 
00119     protected:
00120 
00121         void listText(std::stringstream& txtss,int start, int end, int ln, char s);
00122 
00123         void doPrint( RTT::DataSourceBase* ds, bool recurse);
00124 
00125         void enterTask();
00126         void leaveTask();
00127 
00128         bool macrorecording;
00129         std::string macrotext;
00130         std::string macroname;
00131         void recordMacro(std::string name);
00132         void cancelMacro();
00133         void endMacro();
00134 
00135         void checkPorts();
00136     public:
00137 
00141         enum ColorTheme { nocolors, 
00142                           darkbg, 
00143                           whitebg  
00144         };
00145 
00146         void setColorTheme( ColorTheme t );
00147 
00153         void switchTaskContext(std::string& path);
00154 
00161         void switchTaskContext( RTT::TaskContext* tc, bool store = true);
00162 
00166         void switchBack();
00167 
00173         void browserAction(std::string& act );
00174 
00178         void printResult( RTT::DataSourceBase* ds, bool recurse);
00179 
00183         void printHelp();
00184         
00188         void printInfo(const std::string& peerpath);
00189         
00193         void printCommand( const std::string c, OperationInterface* ops );
00194                 
00198         void printSource( const std::string m );
00199                 
00203         void printMethod( const std::string m, OperationInterface* ops );
00204 
00208         void printEvent( const std::string m, RTT::EventService* ops );
00209 
00213         void printProgram( const std::string& pn, int line = -1, TaskContext* progpeer = 0 );
00214 
00218         void printProgram( int line = -1 );
00219 
00224         TaskBrowser( RTT::TaskContext* c );
00225 
00226         ~TaskBrowser();
00227 
00233         void loop();
00234 
00241         void evaluate(std::string& comm );
00242 
00246         void switchTask( RTT::TaskContext* c);
00247 
00251         static std::string prompt;
00255         static std::string coloron;
00259         static std::string underline;
00263         static std::string coloroff;
00264 
00268         static std::string red;
00269 
00273         static std::string green;
00274 
00278         static std::string blue;
00279 
00283         void evalCommand(std::string& comm );
00284 
00285 
00286     };
00287 
00288 }
00289 
00290 #endif

Generated on Thu Nov 22 13:01:44 2007 for orocos-ocl by  doxygen 1.5.3