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 RTT_API 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 
00245         void setActivity( ActivityInterface* new_act );
00246 
00252         ActivityInterface* getActivity();
00253 
00259         virtual void clear();
00260 
00269         virtual bool ready();
00270 
00271         bool start();
00272 
00278         void updateHook();
00279 
00286         virtual void updateHook(std::vector<PortInterface*> const& updated_ports);
00287 
00293         ScriptingAccess* scripting()
00294         {
00295             return mscriptAcc;
00296         }
00297 
00303         const ScriptingAccess* scripting() const
00304         {
00305             return mscriptAcc;
00306         }
00307 
00314         ExecutionAccess* execution()
00315         {
00316             return mengAcc;
00317         }
00318 
00325         const ExecutionAccess* execution() const
00326         {
00327             return mengAcc;
00328         }
00329 
00334         MarshallingAccess* marshalling()
00335         {
00336             return marshAcc;
00337         }
00338 
00343         const MarshallingAccess* marshalling() const
00344         {
00345             return marshAcc;
00346         }
00347 
00351         PropertyBag* properties() {
00352             return mattributes.properties();
00353         }
00354 
00358         const PropertyBag* properties() const {
00359             return mattributes.properties();
00360         }
00361 
00365         DataFlowInterface* ports() {
00366             return &dataPorts;
00367         }
00368 
00372         const DataFlowInterface* ports() const {
00373             return &dataPorts;
00374         }
00375 
00376     private:
00377         // non copyable
00378         TaskContext( TaskContext& );
00379     protected:
00380         std::string mdescription;
00381 
00382         typedef std::map< std::string, TaskContext* > PeerMap;
00383         typedef std::vector< TaskContext* > Users;
00384         typedef std::vector< OperationInterface* > Objects;
00386         PeerMap         _task_map;
00388         Users         musers;
00390         Objects mobjects;
00391 
00392         ScriptingAccess* mscriptAcc;
00393 
00394         ExecutionAccess* mengAcc;
00395 
00396         MarshallingAccess* marshAcc;
00397 
00402         void addUser(TaskContext* user);
00403 
00408         void removeUser(TaskContext* user);
00409 
00410         void setup();
00411 
00412     protected:
00413         std::vector< PortInterface* > updated_ports;
00418         void dataOnPort(PortInterface*);
00419     private:
00423         DataFlowInterface dataPorts;
00424 
00429         ActivityInterface::shared_ptr our_act;
00430     };
00431 
00437     RTT_API bool connectPorts(TaskContext* A, TaskContext* B);
00438 
00445     RTT_API bool connectPeers(TaskContext* A, TaskContext* B);
00446 }
00447 
00448 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3