Changeset 16727 for trunk/FACT++/src


Ignore:
Timestamp:
06/05/13 20:36:57 (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:
6 edited

Legend:

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

    r14537 r16727  
    44#include "Event.h"
    55#include "StateMachineDim.h"
     6#include "StateMachineAsio.h"
    67#include "Connection.h"
    78#include "LocalControl.h"
     
    315316
    316317template <class T, class S>
    317 class StateMachineAgilent : public T, public ba::io_service, public ba::io_service::work
     318class StateMachineAgilent : public StateMachineAsio<T>
    318319{
    319320private:
     
    341342        // Now wait until all connection have been closed and
    342343        // all pending handlers have been processed
    343         poll();
     344        ba::io_service::poll();
    344345
    345346        if (evt.GetBool())
     
    354355    int Execute()
    355356    {
    356         // Dispatch (execute) at most one handler from the queue. In contrary
    357         // to run_one(), it doesn't wait until a handler is available
    358         // which can be dispatched, so poll_one() might return with 0
    359         // handlers dispatched. The handlers are always dispatched/executed
    360         // synchronously, i.e. within the call to poll_one()
    361         poll_one();
    362 
    363         if (!fAgilent.IsConnected())
    364             return State::kDisconnected;
    365 
    366357        return fAgilent.GetState();
    367358    }
     
    427418public:
    428419    StateMachineAgilent(ostream &out=cout) :
    429         T(out, "AGILENT_CONTROL"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
    430         fAgilent(*this, *this)
    431     {
    432         // ba::io_service::work is a kind of keep_alive for the loop.
    433         // It prevents the io_service to go to stopped state, which
    434         // would prevent any consecutive calls to run()
    435         // or poll() to do nothing. reset() could also revoke to the
    436         // previous state but this might introduce some overhead of
    437         // deletion and creation of threads and more.
    438 
     420        StateMachineAsio<T>(out, "AGILENT_CONTROL"), fAgilent(*this, *this)
     421    {
    439422        // State names
    440423        T::AddStateName(State::kDisconnected, "Disconnected",
  • trunk/FACT++/src/lidctrl.cc

    r15122 r16727  
    1 #include <boost/bind.hpp>
    21#include <boost/array.hpp>
    32
     
    1211#include "Event.h"
    1312#include "StateMachineDim.h"
     13#include "StateMachineAsio.h"
    1414#include "Connection.h"
    1515#include "LocalControl.h"
     
    460460
    461461template <class T, class S>
    462 class StateMachineLidControl : public T, public ba::io_service, public ba::io_service::work
     462class StateMachineLidControl : public StateMachineAsio<T>
    463463{
    464464private:
     
    529529    int Execute()
    530530    {
    531         // Dispatch (execute) at most one handler from the queue. In contrary
    532         // to run_one(), it doesn't wait until a handler is available
    533         // which can be dispatched, so poll_one() might return with 0
    534         // handlers dispatched. The handlers are always dispatched/executed
    535         // synchronously, i.e. within the call to poll_one()
    536         poll_one();
    537 
    538531        const int rc = fLid.GetState();
    539532
     
    551544public:
    552545    StateMachineLidControl(ostream &out=cout) :
    553         T(out, "LID_CONTROL"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
    554         fLid(*this, *this)
    555     {
    556         // ba::io_service::work is a kind of keep_alive for the loop.
    557         // It prevents the io_service to go to stopped state, which
    558         // would prevent any consecutive calls to run()
    559         // or poll() to do nothing. reset() could also revoke to the
    560         // previous state but this might introduce some overhead of
    561         // deletion and creation of threads and more.
    562 
     546        StateMachineAsio<T>(out, "LID_CONTROL"), fLid(*this, *this)
     547    {
    563548        // State names
    564549        T::AddStateName(Lid::State::kDisconnected, "NoConnection",
  • trunk/FACT++/src/magiclidar.cc

    r15351 r16727  
    1 #include <boost/bind.hpp>
    21#include <boost/array.hpp>
    3 
    4 //#include <string>    // std::string
    5 //#include <algorithm> // std::transform
    6 //#include <cctype>    // std::tolower
    72
    83#include "FACT.h"
     
    116#include "Shell.h"
    127#include "StateMachineDim.h"
     8#include "StateMachineAsio.h"
    139#include "Connection.h"
    1410#include "LocalControl.h"
     
    353349
    354350template <class T, class S>
    355 class StateMachineLidar : public T, public ba::io_service, public ba::io_service::work
     351class StateMachineLidar : public StateMachineAsio<T>
    356352{
    357353private:
     
    407403    int Execute()
    408404    {
    409         // Dispatch (execute) at most one handler from the queue. In contrary
    410         // to run_one(), it doesn't wait until a handler is available
    411         // which can be dispatched, so poll_one() might return with 0
    412         // handlers dispatched. The handlers are always dispatched/executed
    413         // synchronously, i.e. within the call to poll_one()
    414         poll_one();
    415 
    416405        return fLidar.GetState();
    417406    }
     
    420409public:
    421410    StateMachineLidar(ostream &out=cout) :
    422         T(out, "MAGIC_LIDAR"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
    423         fLidar(*this, *this)
    424     {
    425         // ba::io_service::work is a kind of keep_alive for the loop.
    426         // It prevents the io_service to go to stopped state, which
    427         // would prevent any consecutive calls to run()
    428         // or poll() to do nothing. reset() could also revoke to the
    429         // previous state but this might introduce some overhead of
    430         // deletion and creation of threads and more.
    431 
     411        StateMachineAsio<T>(out, "MAGIC_LIDAR"), fLidar(*this, *this)
     412    {
    432413        // State names
    433414        T::AddStateName(State::kDisconnected, "NoConnection",
  • trunk/FACT++/src/magicweather.cc

    r14978 r16727  
    1 #include <boost/bind.hpp>
    21#include <boost/array.hpp>
    32
     
    1110#include "Shell.h"
    1211#include "StateMachineDim.h"
     12#include "StateMachineAsio.h"
    1313#include "Connection.h"
    1414#include "LocalControl.h"
     
    195195    }
    196196
    197     boost::asio::deadline_timer fKeepAlive;
     197    ba::deadline_timer fKeepAlive;
    198198
    199199    void PostRequest()
     
    341341
    342342template <class T, class S>
    343 class StateMachineWeather : public T, public ba::io_service, public ba::io_service::work
     343class StateMachineWeather : public StateMachineAsio<T>
    344344{
    345345private:
     
    382382        // Now wait until all connection have been closed and
    383383        // all pending handlers have been processed
    384         poll();
     384        ba::io_service::poll();
    385385
    386386        if (evt.GetBool())
     
    395395    int Execute()
    396396    {
    397         // Dispatch (execute) at most one handler from the queue. In contrary
    398         // to run_one(), it doesn't wait until a handler is available
    399         // which can be dispatched, so poll_one() might return with 0
    400         // handlers dispatched. The handlers are always dispatched/executed
    401         // synchronously, i.e. within the call to poll_one()
    402         poll_one();
    403 
    404397        return fWeather.GetState();
    405398    }
    406 
    407399
    408400public:
    409401    StateMachineWeather(ostream &out=cout) :
    410         T(out, "MAGIC_WEATHER"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
    411         fWeather(*this, *this)
    412     {
    413         // ba::io_service::work is a kind of keep_alive for the loop.
    414         // It prevents the io_service to go to stopped state, which
    415         // would prevent any consecutive calls to run()
    416         // or poll() to do nothing. reset() could also revoke to the
    417         // previous state but this might introduce some overhead of
    418         // deletion and creation of threads and more.
    419 
     402        StateMachineAsio<T>(out, "MAGIC_WEATHER"), fWeather(*this, *this)
     403    {
    420404        // State names
    421405        T::AddStateName(State::kDisconnected, "NoConnection",
     
    458442    }
    459443};
     444
     445
    460446
    461447// ------------------------------------------------------------------------
  • trunk/FACT++/src/pwrctrl.cc

    r16054 r16727  
    1 #include <boost/bind.hpp>
    21#include <boost/array.hpp>
    32
     
    109#include "Event.h"
    1110#include "StateMachineDim.h"
     11#include "StateMachineAsio.h"
    1212#include "Connection.h"
    1313#include "LocalControl.h"
     
    330330
    331331template <class T, class S>
    332 class StateMachinePowerControl : public T, public ba::io_service, public ba::io_service::work
     332class StateMachinePowerControl : public StateMachineAsio<T>
    333333{
    334334private:
     
    393393    int Execute()
    394394    {
    395         // Dispatch (execute) at most one handler from the queue. In contrary
    396         // to run_one(), it doesn't wait until a handler is available
    397         // which can be dispatched, so poll_one() might return with 0
    398         // handlers dispatched. The handlers are always dispatched/executed
    399         // synchronously, i.e. within the call to poll_one()
    400         poll_one();
    401 
    402395        const int rc = fPower.GetState();
    403396
     
    411404public:
    412405    StateMachinePowerControl(ostream &out=cout) :
    413         T(out, "PWR_CONTROL"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
    414         fPower(*this, *this)
    415     {
    416         // ba::io_service::work is a kind of keep_alive for the loop.
    417         // It prevents the io_service to go to stopped state, which
    418         // would prevent any consecutive calls to run()
    419         // or poll() to do nothing. reset() could also revoke to the
    420         // previous state but this might introduce some overhead of
    421         // deletion and creation of threads and more.
    422 
     406        StateMachineAsio<T>(out, "PWR_CONTROL"), fPower(*this, *this)
     407    {
    423408        // State names
    424409        T::AddStateName(Power::State::kDisconnected, "NoConnection",
     
    508493void SetupConfiguration(Configuration &conf)
    509494{
    510     po::options_description control("Lid control");
     495    po::options_description control("Interlock control");
    511496    control.add_options()
    512497        ("no-dim,d",   po_switch(),    "Disable dim services")
     
    534519{
    535520    cout <<
    536         "The pwrctrl is an interface to the LID control hardware.\n"
     521        "The pwrctrl is an interface to the interlock hardware.\n"
    537522        "\n"
    538523        "The default is that the program is started without user intercation. "
  • trunk/FACT++/src/tngweather.cc

    r14978 r16727  
    1 #include <boost/bind.hpp>
    21#include <boost/array.hpp>
    32
     
    1110#include "Shell.h"
    1211#include "StateMachineDim.h"
     12#include "StateMachineAsio.h"
    1313#include "Connection.h"
    1414#include "LocalControl.h"
     
    407407
    408408template <class T, class S>
    409 class StateMachineWeather : public T, public ba::io_service, public ba::io_service::work
     409class StateMachineWeather : public StateMachineAsio<T>
    410410{
    411411private:
     
    461461    int Execute()
    462462    {
    463         // Dispatch (execute) at most one handler from the queue. In contrary
    464         // to run_one(), it doesn't wait until a handler is available
    465         // which can be dispatched, so poll_one() might return with 0
    466         // handlers dispatched. The handlers are always dispatched/executed
    467         // synchronously, i.e. within the call to poll_one()
    468         poll_one();
    469 
    470463        return fWeather.GetState();
    471464    }
     
    474467public:
    475468    StateMachineWeather(ostream &out=cout) :
    476         T(out, "TNG_WEATHER"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
    477         fWeather(*this, *this)
    478     {
    479         // ba::io_service::work is a kind of keep_alive for the loop.
    480         // It prevents the io_service to go to stopped state, which
    481         // would prevent any consecutive calls to run()
    482         // or poll() to do nothing. reset() could also revoke to the
    483         // previous state but this might introduce some overhead of
    484         // deletion and creation of threads and more.
    485 
     469        StateMachineAsio<T>(out, "TNG_WEATHER"), fWeather(*this, *this)
     470    {
    486471        // State names
    487472        T::AddStateName(State::kDisconnected, "NoConnection",
Note: See TracChangeset for help on using the changeset viewer.