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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.