EventDrivenActivity.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jan 19 14:11:19 CET 2004  EventDrivenActivity.hpp
00003 
00004                         EventDrivenActivity.hpp -  description
00005                            -------------------
00006     begin                : Mon January 19 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 TASK_EVENT_DRIVEN_HPP
00039 #define TASK_EVENT_DRIVEN_HPP
00040 
00041 #include "NonPeriodicActivity.hpp"
00042 #include "Event.hpp"
00043 #include "Buffer.hpp"
00044 #include <set>
00045 
00046 #ifdef ORO_PRAGMA_INTERFACE
00047 #pragma interface
00048 #endif
00049 
00050 namespace RTT
00051 {
00052 
00061     class RTT_API EventDrivenActivity
00062         : public NonPeriodicActivity
00063     {
00064         // The set of events that can trigger this activity
00065         typedef std::vector< Event< void() >* > Events;
00066         Events   m_events;
00067 
00068         // The set of connection handles which link m_events with the activity
00069         typedef std::vector<Handle> Handles;
00070         Handles  m_handles;
00071 
00072         // The set of pending events (i.e. events that have been emitted since
00073         // the last time the activity went to sleep)
00074         typedef Buffer< Event< void() >*, BlockingPolicy, NonBlockingPolicy > Triggers;
00075         Triggers* m_pending_events;
00076 
00077         // The set of wakeup events (i.e. the events which triggered the
00078         // current wakeup of the activity)
00079         typedef std::vector< Event< void() >* > Wakeup;
00080         Wakeup   m_wakeup;
00081 
00082         // The trigger method, called by the event. \c event_id is the index of
00083         // the event in m_events.
00084         void event_trigger(Event<void()>* event);
00085 
00086     public:
00095         EventDrivenActivity(int priority, RunnableInterface* _r = 0 );
00096 
00106         EventDrivenActivity(int scheduler, int priority, RunnableInterface* _r = 0 );
00107 
00115         EventDrivenActivity(int priority, const std::string& name, RunnableInterface* _r = 0 );
00116 
00120         ~EventDrivenActivity();
00121 
00122         bool start();
00123         bool stop();
00124         void loop();
00125         bool breakLoop();
00126 
00131         std::vector<Event<void()>*> const& getWakeupEvents() const;
00132 
00137         bool addEvent( Event<void(void)>* _event);
00138     };
00139 
00140 }
00141 
00142 
00143 #endif
Generated on Thu Dec 23 13:22:37 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3