TaskContext.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Tue Dec 21 22:43:08 CET 2004  TaskContext.hpp 
00003 
00004                         TaskContext.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  
00039 #ifndef ORO_TASK_CONTEXT_HPP
00040 #define ORO_TASK_CONTEXT_HPP
00041 
00042 #include "AttributeRepository.hpp"
00043 
00044 #include "rtt-config.h"
00045 #ifdef OROPKG_EXECUTION_ENGINE_EVENTS
00046 #include "EventService.hpp"
00047 #endif
00048 
00049 #include "DataFlowInterface.hpp"
00050 #include "ExecutionEngine.hpp"
00051 #include "ScriptingAccess.hpp"
00052 #include "ExecutionAccess.hpp"
00053 #include "MarshallingAccess.hpp"
00054 #include "TaskCore.hpp"
00055 #include "PropertyBag.hpp"
00056 
00057 #include <string>
00058 #include <map>
00059 
00060 namespace RTT
00061 {
00098     class TaskContext
00099         : public OperationInterface,
00100           public TaskCore
00101     {
00102     public:
00106         typedef std::vector< std::string > PeerList;
00119         TaskContext( const std::string& name, TaskState initial_state = Stopped );
00120 
00130         TaskContext(const std::string& name, ExecutionEngine* parent, TaskState initial_state = Stopped );
00131 
00132         virtual ~TaskContext();
00133 
00134         virtual const std::string& getName() const;
00135 
00136         virtual const std::string& getDescription() const;
00137 
00138         virtual void setDescription(const std::string& descr);
00139 
00140         virtual OperationInterface* getParent() { return this; }
00141 
00145         virtual void setParent(OperationInterface*) { }
00146 
00152         virtual void setEngine(ExecutionEngine*) { }
00153 
00160         void exportPorts();
00161 
00168         virtual bool addPeer( TaskContext* peer, std::string alias = "" );
00169 
00173         virtual void removePeer( const std::string& name );
00174 
00178         virtual void removePeer( TaskContext* peer );
00179 
00183         virtual bool connectPeers( TaskContext* peer );
00184 
00188         virtual bool connectPorts( TaskContext* peer );
00189 
00196         virtual void disconnect();
00197 
00203         virtual void reconnect();
00204 
00208         virtual void disconnectPeers( const std::string& name );
00209 
00214         virtual PeerList getPeerList() const;
00215 
00219         virtual bool hasPeer( const std::string& peer_name ) const;
00220 
00225         virtual TaskContext* getPeer(const std::string& peer_name ) const;
00226 
00235         virtual bool addObject( OperationInterface *obj );
00236 
00242         void clear();
00243 
00249         ScriptingAccess* scripting()
00250         {
00251             return mscriptAcc;
00252         }
00253 
00259         const ScriptingAccess* scripting() const
00260         {
00261             return mscriptAcc;
00262         }
00263 
00270         ExecutionAccess* execution()
00271         {
00272             return mengAcc;
00273         }
00274 
00281         const ExecutionAccess* execution() const
00282         {
00283             return mengAcc;
00284         }
00285 
00290         MarshallingAccess* marshalling()
00291         {
00292             return marshAcc;
00293         }
00294 
00299         const MarshallingAccess* marshalling() const
00300         {
00301             return marshAcc;
00302         }
00303 
00307         PropertyBag* properties() {
00308             return mattributes.properties();
00309         }
00310 
00314         const PropertyBag* properties() const {
00315             return mattributes.properties();
00316         }
00317 
00321         DataFlowInterface* ports() {
00322             return &dataPorts;
00323         }
00324         
00328         const DataFlowInterface* ports() const {
00329             return &dataPorts;
00330         }
00331 
00332     private:
00333         // non copyable
00334         TaskContext( TaskContext& );
00335     protected:
00336         std::string mdescription;
00337     
00338         typedef std::map< std::string, TaskContext* > PeerMap;
00339         typedef std::vector< TaskContext* > Users;
00340         typedef std::vector< OperationInterface* > Objects;
00342         PeerMap         _task_map;
00344         Users         musers;
00346         Objects mobjects;
00347 
00348         ScriptingAccess* mscriptAcc;
00349 
00350         ExecutionAccess* mengAcc;
00351 
00352         MarshallingAccess* marshAcc;
00353 
00358         void addUser(TaskContext* user);
00359 
00364         void removeUser(TaskContext* user);
00365 
00366         void setup();
00367 
00368     private:
00372         DataFlowInterface dataPorts;
00373     };
00374 
00380     bool connectPorts(TaskContext* A, TaskContext* B);
00381 
00388     bool connectPeers(TaskContext* A, TaskContext* B);
00389 }
00390 
00391 #endif

Generated on Tue Mar 25 17:41:52 2008 for OrocosReal-TimeToolkit by  doxygen 1.5.3