Changeset 16732 for trunk/FACT++/src


Ignore:
Timestamp:
06/05/13 21:24:37 (11 years ago)
Author:
tbretz
Message:
Make use of the new StateMachineAsio which gets the CPU consumption to basically 0 by a more intelligent event management.
Location:
trunk/FACT++/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/biasctrl.cc

    r15250 r16732  
    77#include "Shell.h"
    88#include "StateMachineDim.h"
     9#include "StateMachineAsio.h"
    910#include "ConnectionUSB.h"
    1011#include "Configuration.h"
     
    15491550
    15501551template <class T, class S>
    1551 class StateMachineBias : public T, public ba::io_service, public ba::io_service::work
     1552class StateMachineBias : public StateMachineAsio<T>
    15521553{
    15531554    int Wrap(boost::function<void()> f)
     
    17981799        // Now wait until all connection have been closed and
    17991800        // all pending handlers have been processed
    1800         poll();
     1801        ba::io_service::poll();
    18011802
    18021803        if (evt.GetBool())
     
    18451846    int Execute()
    18461847    {
    1847         // Dispatch (execute) at most one handler from the queue. In contrary
    1848         // to run_one(), it doesn't wait until a handler is available
    1849         // which can be dispatched, so poll_one() might return with 0
    1850         // handlers dispatched. The handlers are always dispatched/executed
    1851         // synchronously, i.e. within the call to poll_one()
    1852         poll_one();
    1853 
    18541848        return fExpertMode && fBias.GetStatus()>=State::kConnected ?
    18551849            State::kExpertMode : fBias.GetStatus();
     
    18581852public:
    18591853    StateMachineBias(ostream &out=cout) :
    1860         T(out, "BIAS_CONTROL"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
    1861         fBias(*this, *this), fExpertMode(false)
    1862     {
    1863         // ba::io_service::work is a kind of keep_alive for the loop.
    1864         // It prevents the io_service to go to stopped state, which
    1865         // would prevent any consecutive calls to run()
    1866         // or poll() to do nothing. reset() could also revoke to the
    1867         // previous state but this might introduce some overhead of
    1868         // deletion and creation of threads and more.
    1869 
     1854        StateMachineAsio<T>(out, "BIAS_CONTROL"), fBias(*this, *this), fExpertMode(false)
     1855    {
    18701856        // State names
    18711857        T::AddStateName(State::kDisconnected, "Disconnected",
  • trunk/FACT++/src/drivectrl.cc

    r15458 r16732  
    1 #include <boost/bind.hpp>
    21#include <boost/regex.hpp>
    32
     
    1110#include "Shell.h"
    1211#include "StateMachineDim.h"
     12#include "StateMachineAsio.h"
    1313#include "Connection.h"
    1414#include "LocalControl.h"
     
    778778
    779779template <class T, class S>
    780 class StateMachineDrive : public T, public ba::io_service, public ba::io_service::work
     780class StateMachineDrive : public StateMachineAsio<T>
    781781{
    782782private:
     
    11791179        // Now wait until all connection have been closed and
    11801180        // all pending handlers have been processed
    1181         poll();
     1181        ba::io_service::poll();
    11821182
    11831183        if (evt.GetBool())
     
    12101210    int Execute()
    12111211    {
    1212         // Dispatch (execute) at most one handler from the queue. In contrary
    1213         // to run_one(), it doesn't wait until a handler is available
    1214         // which can be dispatched, so poll_one() might return with 0
    1215         // handlers dispatched. The handlers are always dispatched/executed
    1216         // synchronously, i.e. within the call to poll_one()
    1217         poll_one();
    1218 
    12191212        /*
    12201213        if (T::GetCurrentState()==Drive::State::kLocked)
     
    12711264public:
    12721265    StateMachineDrive(ostream &out=cout) :
    1273         T(out, "DRIVE_CONTROL"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
    1274         fDrive(*this, *this), fAutoResume(false), fSunRise(Time().GetNextSunRise())
     1266        StateMachineAsio<T>(out, "DRIVE_CONTROL"), fDrive(*this, *this),
     1267        fAutoResume(false), fSunRise(Time().GetNextSunRise())
    12751268    {
    12761269        // State names
  • trunk/FACT++/src/fadctrl.cc

    r16619 r16732  
    55#include "Shell.h"
    66#include "StateMachineDim.h"
     7#include "StateMachineAsio.h"
    78#include "Connection.h"
    89#include "LocalControl.h"
     
    544545
    545546template <class T>
    546 class StateMachineFAD : public T, public EventBuilderWrapper, public ba::io_service, public ba::io_service::work
     547class StateMachineFAD : public StateMachineAsio<T>, public EventBuilderWrapper
    547548{
    548549private:
     
    13861387    int Execute()
    13871388    {
    1388         // Dispatch (execute) at most one handler from the queue. In contrary
    1389         // to run_one(), it doesn't wait until a handler is available
    1390         // which can be dispatched, so poll_one() might return with 0
    1391         // handlers dispatched. The handlers are always dispatched/executed
    1392         // synchronously, i.e. within the call to poll_one()
    1393         poll_one();
    1394 
    13951389        // ===== Evaluate connection status =====
    13961390
     
    16481642public:
    16491643    StateMachineFAD(ostream &out=cout) :
    1650         T(out, "FAD_CONTROL"), EventBuilderWrapper(*static_cast<MessageImp*>(this)), ba::io_service::work(static_cast<ba::io_service&>(*this)),
     1644        StateMachineAsio<T>(out, "FAD_CONTROL"),
     1645        EventBuilderWrapper(*static_cast<MessageImp*>(this)),
    16511646        fStatus1(40), fStatus2(40), fStatusT(false),
    16521647        fDimStartRun("FAD_CONTROL/START_RUN", "X:1;X:1",
     
    16591654                                                  "|thread[bool]:true or false whether the event builder threads are running")
    16601655    {
    1661         // ba::io_service::work is a kind of keep_alive for the loop.
    1662         // It prevents the io_service to go to stopped state, which
    1663         // would prevent any consecutive calls to run()
    1664         // or poll() to do nothing. reset() could also revoke to the
    1665         // previous state but this might introduce some overhead of
    1666         // deletion and creation of threads and more.
    16671656        ResetConfig();
    16681657        SetOutputFormat(FAD::kNone);
     
    19491938        }
    19501939
    1951         tcp::resolver resolver(get_io_service());
     1940        tcp::resolver resolver(StateMachineAsio<T>::get_io_service());
    19521941
    19531942        boost::system::error_code ec;
  • trunk/FACT++/src/ftmctrl.cc

    r16444 r16732  
    55#include "Shell.h"
    66#include "StateMachineDim.h"
     7#include "StateMachineAsio.h"
    78#include "Connection.h"
    89#include "LocalControl.h"
     
    13971398
    13981399template <class T, class S>
    1399 class StateMachineFTM : public T, public ba::io_service, public ba::io_service::work
     1400class StateMachineFTM : public StateMachineAsio<T>
    14001401{
    14011402    int Wrap(function<void()> f)
     
    18771878        // Now wait until all connection have been closed and
    18781879        // all pending handlers have been processed
    1879         poll();
     1880        ba::io_service::poll();
    18801881
    18811882        if (evt.GetBool())
     
    19331934    int Execute()
    19341935    {
    1935         // Dispatch (execute) at most one handler from the queue. In contrary
    1936         // to run_one(), it doesn't wait until a handler is available
    1937         // which can be dispatched, so poll_one() might return with 0
    1938         // handlers dispatched. The handlers are always dispatched/executed
    1939         // synchronously, i.e. within the call to poll_one()
    1940         poll_one();
    1941 
    19421936        // If FTM is neither in data taking nor idle,
    19431937        // leave configuration state
     
    20332027public:
    20342028    StateMachineFTM(ostream &out=cout) :
    2035         T(out, "FTM_CONTROL"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
    2036         fFTM(*this, *this)
    2037     {
    2038         // ba::io_service::work is a kind of keep_alive for the loop.
    2039         // It prevents the io_service to go to stopped state, which
    2040         // would prevent any consecutive calls to run()
    2041         // or poll() to do nothing. reset() could also revoke to the
    2042         // previous state but this might introduce some overhead of
    2043         // deletion and creation of threads and more.
    2044 
    2045 
     2029        StateMachineAsio<T>(out, "FTM_CONTROL"), fFTM(*this, *this)
     2030    {
    20462031        // State names
    20472032        T::AddStateName(FTM::State::kDisconnected, "Disconnected",
Note: See TracChangeset for help on using the changeset viewer.