Index: src/Fragmentation/Automation/Controller/Commands/GetNextJobIdOperation.cpp
===================================================================
--- src/Fragmentation/Automation/Controller/Commands/GetNextJobIdOperation.cpp	(revision 98688531d72c70fdcf3a5a081fffe953746b3962)
+++ src/Fragmentation/Automation/Controller/Commands/GetNextJobIdOperation.cpp	(revision 98688531d72c70fdcf3a5a081fffe953746b3962)
@@ -0,0 +1,118 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2012 University of Bonn. All rights reserved.
+ * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
+ */
+
+/*
+ * GetNextJobIdOperation.cpp
+ *
+ *  Created on: Feb 16, 2012
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+// boost asio needs specific operator new
+#include <boost/asio.hpp>
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include <boost/bind.hpp>
+#include <iostream>
+#include "Connection.hpp" // Must come before boost/serialization headers.
+#include <boost/serialization/vector.hpp>
+#include "CodePatterns/Info.hpp"
+#include "CodePatterns/Log.hpp"
+#include "ControllerChoices.hpp"
+#include "types.hpp"
+
+#include "Controller/Commands/GetNextJobIdOperation.hpp"
+
+/** Handle connect operation to send number of done jobs.
+ *
+ * \param e error code if something went wrong
+ * \param endpoint_iterator endpoint of the connection
+ */
+void GetNextJobIdOperation::handle_connect(const boost::system::error_code& e,
+    boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
+{
+  Info info(__FUNCTION__);
+  if (!e)
+  {
+    // Successfully established connection. Give choice.
+          enum ControllerChoices choice = GetNextJobId;
+    connection_.async_write(choice,
+      boost::bind(&GetNextJobIdOperation::handle_ReceiveNextId, this,
+      boost::asio::placeholders::error));
+  } else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator()) {
+    // Try the next endpoint.
+    connection_.socket().close();
+    boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
+    connection_.socket().async_connect(endpoint,
+      boost::bind(&GetNextJobIdOperation::handle_connect, this,
+      boost::asio::placeholders::error, ++endpoint_iterator));
+  } else {
+    // An error occurred. Log it and return. Since we are not starting a new
+    // operation the io_service will run out of work to do and the client will
+    // exit.
+    ELOG(1, e.message());
+  }
+}
+
+/** Callback function when doneJobs have been received.
+ *
+ * \param e error code if something went wrong
+ */
+void GetNextJobIdOperation::handle_ReceiveNextId(const boost::system::error_code& e)
+{
+  Info info(__FUNCTION__);
+  if (!e)
+  {
+    // The connection::async_read() function will automatically
+    // decode the data that is written to the underlying socket.
+    LOG(1, "INFO: Obtaining next available job id ...");
+    connection_.async_read(nextid,
+      boost::bind(&GetNextJobIdOperation::handle_FinishOperation, this,
+      boost::asio::placeholders::error));
+  }
+  else
+  {
+    // An error occurred.
+    ELOG(1, e.message());
+  }
+}
+
+/** Callback function when an operation has been completed.
+ *
+ * \param e error code if something went wrong
+ */
+void GetNextJobIdOperation::handle_FinishOperation(const boost::system::error_code& e)
+{
+  Info info(__FUNCTION__);
+
+  // place id into nextids
+  nextids.push_back(nextid);
+  nextid = JobId::IllegalJob;
+
+  // and finish operation
+  Operation::handle_FinishOperation(e);
+}
+
+/** Getter for nextid.
+ *
+ * \sa checkResults()
+ * \param next available JobId_t
+ */
+size_t GetNextJobIdOperation::getNextId()
+{
+  ASSERT( nextids.size() != (size_t)0,
+      "GetNextJobIdOperation::getNextId() - no next id available.");
+  const JobId_t availableid = nextids.front();
+  nextids.pop_front();
+  return availableid;
+}
Index: src/Fragmentation/Automation/Controller/Commands/GetNextJobIdOperation.hpp
===================================================================
--- src/Fragmentation/Automation/Controller/Commands/GetNextJobIdOperation.hpp	(revision 98688531d72c70fdcf3a5a081fffe953746b3962)
+++ src/Fragmentation/Automation/Controller/Commands/GetNextJobIdOperation.hpp	(revision 98688531d72c70fdcf3a5a081fffe953746b3962)
@@ -0,0 +1,60 @@
+/*
+ * GetNextJobIdOperation.hpp
+ *
+ *  Created on: Feb 16, 2012
+ *      Author: heber
+ */
+
+#ifndef FRAGMENTCONTROLLER_GETNEXTJOBIDOPERATION_HPP_
+#define FRAGMENTCONTROLLER_GETNEXTJOBIDOPERATION_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <boost/asio.hpp>
+
+#include "Connection.hpp"
+
+#include "Controller/Commands/Operation.hpp"
+#include "JobId.hpp"
+#include "types.hpp"
+
+/** This Operations requests number of present jobs and present results (done
+ * jobs) from the server.
+ *
+ */
+class GetNextJobIdOperation : public Operation  {
+public:
+  /// Constructor for class GetNextJobIdOperation.
+  GetNextJobIdOperation(Connection &_connection) :
+    Operation(std::string("getnextjobid"), _connection),
+    nextid(JobId::IllegalJob)
+  {}
+  /// Destructor for class GetNextJobIdOperation
+  ~GetNextJobIdOperation() {}
+
+public:
+  // virtual function pointer to the connection handler
+  virtual void handle_connect(const boost::system::error_code& e,
+      boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
+
+  /// Callback function when doneJobs have been received.
+  void handle_ReceiveNextId(const boost::system::error_code& e);
+
+  /// Getter for nextid
+  size_t getNextId();
+
+protected:
+  /// Callback function when Operations finishes.
+  void handle_FinishOperation(const boost::system::error_code& e);
+
+  /// current jobs left to calculate and currently calculated results
+  std::list<JobId_t> nextids;
+
+  // temporary for receiving another job id
+  JobId_t nextid;
+};
+
+#endif /* FRAGMENTCONTROLLER_GETNEXTJOBIDOPERATION_HPP_ */
Index: src/Fragmentation/Automation/Controller/FragmentController.cpp
===================================================================
--- src/Fragmentation/Automation/Controller/FragmentController.cpp	(revision 6f2bc74265e4dfd79255657a1db5cc52e9511f44)
+++ src/Fragmentation/Automation/Controller/FragmentController.cpp	(revision 98688531d72c70fdcf3a5a081fffe953746b3962)
@@ -30,4 +30,5 @@
 #include "Controller/Commands/Operation.hpp"
 #include "Controller/Commands/CheckResultsOperation.hpp"
+#include "Controller/Commands/GetNextJobIdOperation.hpp"
 #include "Controller/Commands/ReceiveJobsOperation.hpp"
 #include "Controller/Commands/SendResultsOperation.hpp"
@@ -48,4 +49,5 @@
   // insert commands into registry
   Commands.registerInstance(new CheckResultsOperation(connection_));
+  Commands.registerInstance(new GetNextJobIdOperation(connection_));
   Commands.registerInstance(new ReceiveJobsOperation(connection_));
   Commands.registerInstance(new SendResultsOperation(connection_));
