CommandDispatch.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Tue Dec 21 22:43:07 CET 2004  CommandDispatch.hpp
00003 
00004                         CommandDispatch.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 General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/
00037 
00038 #ifndef EXECUTION_COMMAND_DISPATCH
00039 #define EXECUTION_COMMAND_DISPATCH
00040 
00041 #include "DataSource.hpp"
00042 #include "DispatchInterface.hpp"
00043 #include "ConditionInterface.hpp"
00044 
00045 
00046 namespace RTT
00047 {
00048     class TryCommand;
00049     class CommandProcessor;
00050 
00059     class RTT_API CommandDispatch
00060         : public DispatchInterface
00061     {
00062         bool send;
00063         bool maccepted;
00064         CommandProcessor* proc;
00065         CommandInterface* com;
00066         ConditionInterface* mcn;
00067 
00072         struct Dispatcher : public CommandInterface {
00073             bool mexecuted, mvalid;
00074             CommandDispatch* cd;
00075             // trick: set mvalid to true internally but return in valid(): mexecuted && mvalid.
00076             Dispatcher(CommandDispatch* c) : mexecuted(false), mvalid(true), cd(c) {}
00077             void readArguments() {}
00078             bool execute() { mvalid=cd->com->execute(); mexecuted=true; return mvalid;}
00079             void reset() { mexecuted=false; mvalid=true; }
00080             virtual Dispatcher* clone() const { return new Dispatcher(cd); }
00081         } dispatcher;
00082 
00083     public:
00087         CommandDispatch(CommandProcessor* p, CommandInterface* c, ConditionInterface* cn );
00088 
00093         ~CommandDispatch();
00094 
00095         void readArguments();
00096 
00097         bool ready() const;
00098 
00099         bool execute();
00100 
00105         bool dispatch();
00106 
00111         void reset();
00112 
00117         bool sent() const;
00118 
00124         bool accepted() const;
00125 
00130         bool executed() const;
00131 
00136         bool valid() const;
00137 
00144         bool done() const;
00145 
00146         virtual ConditionInterface* createCondition() const;
00147 
00148         DispatchInterface* clone() const;
00149 
00150         DispatchInterface* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const;
00151     };
00152 }
00153 
00154 #endif
Generated on Thu Dec 23 13:22:36 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3