Index: /trunk/FACT++/src/agilentctrl.cc
===================================================================
--- /trunk/FACT++/src/agilentctrl.cc	(revision 16726)
+++ /trunk/FACT++/src/agilentctrl.cc	(revision 16727)
@@ -4,4 +4,5 @@
 #include "Event.h"
 #include "StateMachineDim.h"
+#include "StateMachineAsio.h"
 #include "Connection.h"
 #include "LocalControl.h"
@@ -315,5 +316,5 @@
 
 template <class T, class S>
-class StateMachineAgilent : public T, public ba::io_service, public ba::io_service::work
+class StateMachineAgilent : public StateMachineAsio<T>
 {
 private:
@@ -341,5 +342,5 @@
         // Now wait until all connection have been closed and
         // all pending handlers have been processed
-        poll();
+        ba::io_service::poll();
 
         if (evt.GetBool())
@@ -354,14 +355,4 @@
     int Execute()
     {
-        // Dispatch (execute) at most one handler from the queue. In contrary
-        // to run_one(), it doesn't wait until a handler is available
-        // which can be dispatched, so poll_one() might return with 0
-        // handlers dispatched. The handlers are always dispatched/executed
-        // synchronously, i.e. within the call to poll_one()
-        poll_one();
-
-        if (!fAgilent.IsConnected())
-            return State::kDisconnected;
-
         return fAgilent.GetState();
     }
@@ -427,14 +418,6 @@
 public:
     StateMachineAgilent(ostream &out=cout) :
-        T(out, "AGILENT_CONTROL"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
-        fAgilent(*this, *this)
-    {
-        // ba::io_service::work is a kind of keep_alive for the loop.
-        // It prevents the io_service to go to stopped state, which
-        // would prevent any consecutive calls to run()
-        // or poll() to do nothing. reset() could also revoke to the
-        // previous state but this might introduce some overhead of
-        // deletion and creation of threads and more.
-
+        StateMachineAsio<T>(out, "AGILENT_CONTROL"), fAgilent(*this, *this)
+    {
         // State names
         T::AddStateName(State::kDisconnected, "Disconnected",
Index: /trunk/FACT++/src/lidctrl.cc
===================================================================
--- /trunk/FACT++/src/lidctrl.cc	(revision 16726)
+++ /trunk/FACT++/src/lidctrl.cc	(revision 16727)
@@ -1,3 +1,2 @@
-#include <boost/bind.hpp>
 #include <boost/array.hpp>
 
@@ -12,4 +11,5 @@
 #include "Event.h"
 #include "StateMachineDim.h"
+#include "StateMachineAsio.h"
 #include "Connection.h"
 #include "LocalControl.h"
@@ -460,5 +460,5 @@
 
 template <class T, class S>
-class StateMachineLidControl : public T, public ba::io_service, public ba::io_service::work
+class StateMachineLidControl : public StateMachineAsio<T>
 {
 private:
@@ -529,11 +529,4 @@
     int Execute()
     {
-        // Dispatch (execute) at most one handler from the queue. In contrary
-        // to run_one(), it doesn't wait until a handler is available
-        // which can be dispatched, so poll_one() might return with 0
-        // handlers dispatched. The handlers are always dispatched/executed
-        // synchronously, i.e. within the call to poll_one()
-        poll_one();
-
         const int rc = fLid.GetState();
 
@@ -551,14 +544,6 @@
 public:
     StateMachineLidControl(ostream &out=cout) :
-        T(out, "LID_CONTROL"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
-        fLid(*this, *this)
-    {
-        // ba::io_service::work is a kind of keep_alive for the loop.
-        // It prevents the io_service to go to stopped state, which
-        // would prevent any consecutive calls to run()
-        // or poll() to do nothing. reset() could also revoke to the
-        // previous state but this might introduce some overhead of
-        // deletion and creation of threads and more.
-
+        StateMachineAsio<T>(out, "LID_CONTROL"), fLid(*this, *this)
+    {
         // State names
         T::AddStateName(Lid::State::kDisconnected, "NoConnection",
Index: /trunk/FACT++/src/magiclidar.cc
===================================================================
--- /trunk/FACT++/src/magiclidar.cc	(revision 16726)
+++ /trunk/FACT++/src/magiclidar.cc	(revision 16727)
@@ -1,8 +1,3 @@
-#include <boost/bind.hpp>
 #include <boost/array.hpp>
-
-//#include <string>    // std::string
-//#include <algorithm> // std::transform
-//#include <cctype>    // std::tolower
 
 #include "FACT.h"
@@ -11,4 +6,5 @@
 #include "Shell.h"
 #include "StateMachineDim.h"
+#include "StateMachineAsio.h"
 #include "Connection.h"
 #include "LocalControl.h"
@@ -353,5 +349,5 @@
 
 template <class T, class S>
-class StateMachineLidar : public T, public ba::io_service, public ba::io_service::work
+class StateMachineLidar : public StateMachineAsio<T>
 {
 private:
@@ -407,11 +403,4 @@
     int Execute()
     {
-        // Dispatch (execute) at most one handler from the queue. In contrary
-        // to run_one(), it doesn't wait until a handler is available
-        // which can be dispatched, so poll_one() might return with 0
-        // handlers dispatched. The handlers are always dispatched/executed
-        // synchronously, i.e. within the call to poll_one()
-        poll_one();
-
         return fLidar.GetState();
     }
@@ -420,14 +409,6 @@
 public:
     StateMachineLidar(ostream &out=cout) :
-        T(out, "MAGIC_LIDAR"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
-        fLidar(*this, *this)
-    {
-        // ba::io_service::work is a kind of keep_alive for the loop.
-        // It prevents the io_service to go to stopped state, which
-        // would prevent any consecutive calls to run()
-        // or poll() to do nothing. reset() could also revoke to the
-        // previous state but this might introduce some overhead of
-        // deletion and creation of threads and more.
-
+        StateMachineAsio<T>(out, "MAGIC_LIDAR"), fLidar(*this, *this)
+    {
         // State names
         T::AddStateName(State::kDisconnected, "NoConnection",
Index: /trunk/FACT++/src/magicweather.cc
===================================================================
--- /trunk/FACT++/src/magicweather.cc	(revision 16726)
+++ /trunk/FACT++/src/magicweather.cc	(revision 16727)
@@ -1,3 +1,2 @@
-#include <boost/bind.hpp>
 #include <boost/array.hpp>
 
@@ -11,4 +10,5 @@
 #include "Shell.h"
 #include "StateMachineDim.h"
+#include "StateMachineAsio.h"
 #include "Connection.h"
 #include "LocalControl.h"
@@ -195,5 +195,5 @@
     }
 
-    boost::asio::deadline_timer fKeepAlive;
+    ba::deadline_timer fKeepAlive;
 
     void PostRequest()
@@ -341,5 +341,5 @@
 
 template <class T, class S>
-class StateMachineWeather : public T, public ba::io_service, public ba::io_service::work
+class StateMachineWeather : public StateMachineAsio<T>
 {
 private:
@@ -382,5 +382,5 @@
         // Now wait until all connection have been closed and
         // all pending handlers have been processed
-        poll();
+        ba::io_service::poll();
 
         if (evt.GetBool())
@@ -395,27 +395,11 @@
     int Execute()
     {
-        // Dispatch (execute) at most one handler from the queue. In contrary
-        // to run_one(), it doesn't wait until a handler is available
-        // which can be dispatched, so poll_one() might return with 0
-        // handlers dispatched. The handlers are always dispatched/executed
-        // synchronously, i.e. within the call to poll_one()
-        poll_one();
-
         return fWeather.GetState();
     }
-
 
 public:
     StateMachineWeather(ostream &out=cout) :
-        T(out, "MAGIC_WEATHER"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
-        fWeather(*this, *this)
-    {
-        // ba::io_service::work is a kind of keep_alive for the loop.
-        // It prevents the io_service to go to stopped state, which
-        // would prevent any consecutive calls to run()
-        // or poll() to do nothing. reset() could also revoke to the
-        // previous state but this might introduce some overhead of
-        // deletion and creation of threads and more.
-
+        StateMachineAsio<T>(out, "MAGIC_WEATHER"), fWeather(*this, *this)
+    {
         // State names
         T::AddStateName(State::kDisconnected, "NoConnection",
@@ -458,4 +442,6 @@
     }
 };
+
+
 
 // ------------------------------------------------------------------------
Index: /trunk/FACT++/src/pwrctrl.cc
===================================================================
--- /trunk/FACT++/src/pwrctrl.cc	(revision 16726)
+++ /trunk/FACT++/src/pwrctrl.cc	(revision 16727)
@@ -1,3 +1,2 @@
-#include <boost/bind.hpp>
 #include <boost/array.hpp>
 
@@ -10,4 +9,5 @@
 #include "Event.h"
 #include "StateMachineDim.h"
+#include "StateMachineAsio.h"
 #include "Connection.h"
 #include "LocalControl.h"
@@ -330,5 +330,5 @@
 
 template <class T, class S>
-class StateMachinePowerControl : public T, public ba::io_service, public ba::io_service::work
+class StateMachinePowerControl : public StateMachineAsio<T>
 {
 private:
@@ -393,11 +393,4 @@
     int Execute()
     {
-        // Dispatch (execute) at most one handler from the queue. In contrary
-        // to run_one(), it doesn't wait until a handler is available
-        // which can be dispatched, so poll_one() might return with 0
-        // handlers dispatched. The handlers are always dispatched/executed
-        // synchronously, i.e. within the call to poll_one()
-        poll_one();
-
         const int rc = fPower.GetState();
 
@@ -411,14 +404,6 @@
 public:
     StateMachinePowerControl(ostream &out=cout) :
-        T(out, "PWR_CONTROL"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
-        fPower(*this, *this)
-    {
-        // ba::io_service::work is a kind of keep_alive for the loop.
-        // It prevents the io_service to go to stopped state, which
-        // would prevent any consecutive calls to run()
-        // or poll() to do nothing. reset() could also revoke to the
-        // previous state but this might introduce some overhead of
-        // deletion and creation of threads and more.
-
+        StateMachineAsio<T>(out, "PWR_CONTROL"), fPower(*this, *this)
+    {
         // State names
         T::AddStateName(Power::State::kDisconnected, "NoConnection",
@@ -508,5 +493,5 @@
 void SetupConfiguration(Configuration &conf)
 {
-    po::options_description control("Lid control");
+    po::options_description control("Interlock control");
     control.add_options()
         ("no-dim,d",   po_switch(),    "Disable dim services")
@@ -534,5 +519,5 @@
 {
     cout <<
-        "The pwrctrl is an interface to the LID control hardware.\n"
+        "The pwrctrl is an interface to the interlock hardware.\n"
         "\n"
         "The default is that the program is started without user intercation. "
Index: /trunk/FACT++/src/tngweather.cc
===================================================================
--- /trunk/FACT++/src/tngweather.cc	(revision 16726)
+++ /trunk/FACT++/src/tngweather.cc	(revision 16727)
@@ -1,3 +1,2 @@
-#include <boost/bind.hpp>
 #include <boost/array.hpp>
 
@@ -11,4 +10,5 @@
 #include "Shell.h"
 #include "StateMachineDim.h"
+#include "StateMachineAsio.h"
 #include "Connection.h"
 #include "LocalControl.h"
@@ -407,5 +407,5 @@
 
 template <class T, class S>
-class StateMachineWeather : public T, public ba::io_service, public ba::io_service::work
+class StateMachineWeather : public StateMachineAsio<T>
 {
 private:
@@ -461,11 +461,4 @@
     int Execute()
     {
-        // Dispatch (execute) at most one handler from the queue. In contrary
-        // to run_one(), it doesn't wait until a handler is available
-        // which can be dispatched, so poll_one() might return with 0
-        // handlers dispatched. The handlers are always dispatched/executed
-        // synchronously, i.e. within the call to poll_one()
-        poll_one();
-
         return fWeather.GetState();
     }
@@ -474,14 +467,6 @@
 public:
     StateMachineWeather(ostream &out=cout) :
-        T(out, "TNG_WEATHER"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
-        fWeather(*this, *this)
-    {
-        // ba::io_service::work is a kind of keep_alive for the loop.
-        // It prevents the io_service to go to stopped state, which
-        // would prevent any consecutive calls to run()
-        // or poll() to do nothing. reset() could also revoke to the
-        // previous state but this might introduce some overhead of
-        // deletion and creation of threads and more.
-
+        StateMachineAsio<T>(out, "TNG_WEATHER"), fWeather(*this, *this)
+    {
         // State names
         T::AddStateName(State::kDisconnected, "NoConnection",
