Index: src/Fragmentation/Automation/FragmentController.hpp
===================================================================
--- src/Fragmentation/Automation/FragmentController.hpp	(revision dba6d162581bd1026fa90391ce4c3c62bdde0d38)
+++ src/Fragmentation/Automation/FragmentController.hpp	(revision 5adb84984c3a69ab1022d16497045fd243ee9087)
@@ -34,96 +34,225 @@
 {
 public:
-  FragmentController(boost::asio::io_service& io_service, const std::string& host, const std::string& service);
+  FragmentController(boost::asio::io_service& io_service, const std::string& _host, const std::string& _service);
   ~FragmentController();
 
-  /// Handle completion of a calculate operation.
-  void handle_connect_calc(const boost::system::error_code& e,
-      boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
-
-  /// Handle completion of a CheckResults operation.
-  void handle_connect_check(const boost::system::error_code& e,
-      boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
-
-  /// Handle completion of a GetResults operation.
-  void handle_connect_get(const boost::system::error_code& e,
-      boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
-
-  /// Handle completion of a Shutdown operation.
-  void handle_connect_shutdown(const boost::system::error_code& e,
-      boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
-
-  /// Handle completion of an operation.
-  void handle_FinishOperation(const boost::system::error_code& e);
-
-  /// Callback function when bunch of jobs have been sent.
-  void handle_SendJobs(const boost::system::error_code& e);
-
-  /// Callback function when doneJobs have been received.
-  void handle_ReceiveDoneJobs(const boost::system::error_code& e);
-
-  /// Callback function when results are about to be received.
-  void handle_ReceivingResults(const boost::system::error_code& e);
-
-  /// Callback function when results have been received.
-  void handle_ReceivedResults(const boost::system::error_code& e);
-
-  /// place number of jobs into this controller
-  void addJobs(const std::vector<FragmentJob> &jobs);
-
-  /// prepares the calculation of the results
-  void calculateResults();
-  
-  enum Exitflag_t {
-    OkFlag = 0,
-    ErrorFlag = 255
-  };
+  class Operation {
+  public:
+    Operation(Connection &_connection, const std::string& _host, const std::string& _service);
+    virtual ~Operation();
+  public:
+    /// The Connection to the server.
+    Connection &connection_;
+
+    // virtual function pointer to the operation to do
+    virtual void operator()() = 0;
+
+    /// Handle completion of an operation.
+    void handle_FinishOperation(const boost::system::error_code& e);
+
+    enum Exitflag_t {
+      OkFlag = 0,
+      ErrorFlag = 255
+    };
+
+    // get the exit flag of the last operations
+    size_t getExitflag() const
+    {
+      return Exitflag;
+    }
+
+  protected:
+    /// internal function to resolve host name and ip address
+    boost::asio::ip::tcp::resolver::iterator getEndpointIterator();
+
+    /// internal function to disconnect from server
+    void disconnect();
+
+  protected:
+    /// host name of server
+    const std::string host;
+
+    // service to connect to to
+    const std::string service;
+
+    /// flag of operation to give on program exit
+    enum Exitflag_t Exitflag;
+  };
+
+  class ReceiveJobsOperation : public Operation {
+  public:
+    /// Constructor for class ReceiveJobsOperation.
+    ReceiveJobsOperation(Connection &_connection, const std::string& _host, const std::string& _service) :
+      Operation(_connection, _host, _service) {}
+    /// Destructor for class ReceiveJobsOperation
+    ~ReceiveJobsOperation() {}
+
+  public:
+    /// Placing receive jobs operations into an io_service
+    virtual void operator()();
+
+    /// Handle completion of a calculate operation.
+    void handle_connect_calc(const boost::system::error_code& e,
+        boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
+
+    /// Callback function when bunch of jobs have been sent.
+    void handle_SendJobs(const boost::system::error_code& e);
+
+    /// Handle completion of an operation.
+    void handle_FinishOperation(const boost::system::error_code& e);
+
+    /// internal function to connect to server and send jobs for calculation
+    void connect_calc();
+
+    /// Setter for jobs
+    void addJobs(const std::vector<FragmentJob> &jobs);
+
+    /// Getter for number of size of jobs
+    size_t getPresentJobs() const;
+
+  protected:
+    /// bunch of jobs
+    std::vector<FragmentJob> jobs;
+  };
+
+  struct CheckResultsOperation : public Operation  {
+  public:
+    /// Constructor for class CheckResultsOperation.
+    CheckResultsOperation(Connection &_connection, const std::string& _host, const std::string& _service) :
+      Operation(_connection, _host, _service),
+      doneJobs(0)
+    {}
+    /// Destructor for class CheckResultsOperation
+    ~CheckResultsOperation() {}
+
+  public:
+    // placing receive jobs operations into an io_service
+    virtual void operator()();
+
+    /// Handle completion of a CheckResults operation.
+    void handle_connect_check(const boost::system::error_code& e,
+        boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
+
+    /// Callback function when doneJobs have been received.
+    void handle_ReceiveDoneJobs(const boost::system::error_code& e);
+
+    /// Handle completion of an operation.
+    void handle_FinishOperation(const boost::system::error_code& e);
+
+    /// internal function to connect to server and check done jobs
+    void connect_check();
+
+    /// Getter for doneJobs
+    size_t getDoneJobs() const;
+
+  protected:
+    /// currently calculated results
+    size_t doneJobs;
+  };
+
+  struct SendResultsOperation : public Operation  {
+  public:
+    /// Constructor for class SendResultsOperation.
+    SendResultsOperation(Connection &_connection, const std::string& _host, const std::string& _service) :
+      Operation(_connection, _host, _service) {}
+    /// Destructor for class SendResultsOperation
+    ~SendResultsOperation() {}
+
+  public:
+    // placing receive jobs operations into an io_service
+    virtual void operator()();
+
+    /// Handle completion of a GetResults operation.
+    void handle_connect_get(const boost::system::error_code& e,
+        boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
+
+          /// Callback function when results are about to be received.
+          void handle_ReceivingResults(const boost::system::error_code& e);
+
+          /// Callback function when results have been received.
+          void handle_ReceivedResults(const boost::system::error_code& e);
+
+    /// internal function to connect to server and receive calculated results
+    void connect_get();
+
+    /// Getter for results
+    std::vector<FragmentResult> getResults();
+
+  protected:
+    /// bunch of results
+    std::vector<FragmentResult> results;
+  };
+
+  struct ShutdownOperation : public Operation  {
+  public:
+    /// Constructor for class ShutdownOperation.
+    ShutdownOperation(Connection &_connection, const std::string& _host, const std::string& _service) :
+      Operation(_connection, _host, _service) {}
+    /// Destructor for class ShutdownOperation
+    ~ShutdownOperation() {}
+
+  public:
+    // placing receive jobs operations into an io_service
+    virtual void operator()();
+
+    /// Handle completion of a Shutdown operation.
+    void handle_connect_shutdown(const boost::system::error_code& e,
+        boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
+
+    /// internal function to connect to server and receive calculated results
+    void connect_shutdown();
+
+  };
+
+protected:
+  /// The Connection to the server.
+  Connection connection_;
+
+public:
+
+  ReceiveJobsOperation recjobs;
+  CheckResultsOperation checkres;
+  SendResultsOperation  sendres;
+  ShutdownOperation shutdown;
 
   // get the exit flag of the last operations
   size_t getExitflag() const
   {
-    return Exitflag;
-  }
-
-  /// prepares the receival of the results
-  void obtainResults();
-
-  /// prepares the server's shutdown
-  void shutdown();
+    if (recjobs.getExitflag() != 0)
+      return recjobs.getExitflag();
+    if (checkres.getExitflag() != 0)
+      return checkres.getExitflag();
+    if (sendres.getExitflag() != 0)
+      return sendres.getExitflag();
+    if (shutdown.getExitflag() != 0)
+      return shutdown.getExitflag();
+    return 0;
+  }
+
+  /// place number of jobs into this controller
+  void addJobs(const std::vector<FragmentJob> &jobs)
+  {
+    recjobs.addJobs(jobs);
+  }
 
   /// get the results for the current jobs
-  std::vector<FragmentResult> getResults();
-
-  /// get the number of finished results for the current jobs
-  void checkResults();
+  std::vector<FragmentResult> getResults()
+  {
+    return sendres.getResults();
+  }
 
   /// Getter for doneJobs
-  size_t getDoneJobs() const;
+  size_t getDoneJobs() const
+  {
+    return checkres.getDoneJobs();
+  }
 
   /// Getter for number of jobs in the queue
-  size_t getPresentJobs() const;
+  size_t getPresentJobs() const
+  {
+    return recjobs.getPresentJobs();
+  }
 
 private:
-  /// internal function to resolve host name and ip address
-  boost::asio::ip::tcp::resolver::iterator getEndpointIterator();
-
-  /// internal function to connect to server and send jobs for calculation
-  void connect_calc();
-
-  /// internal function to connect to server and check done jobs
-  void connect_check();
-
-  /// internal function to connect to server and receive calculated results
-  void connect_get();
-
-  /// internal function to connect to server and receive calculated results
-  void connect_shutdown();
-
-  /// internal function to disconnect from server
-  void disconnect();
-
-private:
-  /// The Connection to the server.
-  Connection connection_;
-
   /// host name of server
   const std::string host;
@@ -131,16 +260,4 @@
   // service to connect to to
   const std::string service;
-
-  /// bunch of jobs
-  std::vector<FragmentJob> jobs;
-
-  /// flag to give on program exit
-  enum Exitflag_t Exitflag;
-
-  /// bunch of results
-  std::vector<FragmentResult> results;
-
-  /// currently calculated results
-  size_t doneJobs;
 };
 
