/* * 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. */ /* * SubmitResultOperation.cpp * * Created on: Feb 26, 2012 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif // boost asio needs specific operator new #include #include "CodePatterns/MemDebug.hpp" #include "SubmitResultOperation.hpp" #include #include "CodePatterns/Info.hpp" #include "CodePatterns/Log.hpp" #include "Results/FragmentResult.hpp" #include "WorkerChoices.hpp" /// Handle completion of a connect operation. void SubmitResultOperation::handle_connect(const boost::system::error_code& e, boost::asio::ip::tcp::resolver::iterator endpoint_iterator) { Info info(__FUNCTION__); if (!e) { // Successfully established connection. Start operation to read the list // of jobs. The connection::async_write() function will automatically // decode the data that is read from the underlying socket. LOG(1, "INFO: Sending address " << address << " ..."); connection_.async_write(address, boost::bind(&SubmitResultOperation::handle_SendChoice, 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(&SubmitResultOperation::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. exitflag = ErrorFlag; ELOG(1, e.message()); } } /// Callback function when address has been sent and result is about to void SubmitResultOperation::handle_SendChoice(const boost::system::error_code& e) { Info info(__FUNCTION__); if (!e) { // Successfully established connection. Start operation to read the list // of jobs. The connection::async_write() function will automatically // decode the data that is read from the underlying socket. enum WorkerChoices choice = SendResult; connection_.async_write(choice, boost::bind(&SubmitResultOperation::handle_SendResult, this, boost::asio::placeholders::error)); } 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. exitflag = ErrorFlag; ELOG(1, e.message()); } } /// Callback function when address has been sent and result is about to void SubmitResultOperation::handle_SendResult(const boost::system::error_code& e) { Info info(__FUNCTION__); if (!e) { // Successfully established connection. Start operation to read the list // of jobs. The connection::async_write() function will automatically // decode the data that is read from the underlying socket. LOG(1, "INFO: Sending result #" << result->getId() << " ..."); connection_.async_write(result, boost::bind(&SubmitResultOperation::handle_FinishOperation, this, boost::asio::placeholders::error)); } 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. exitflag = ErrorFlag; ELOG(1, e.message()); } } /// Callback function when result has been sent. void SubmitResultOperation::handle_FinishOperation(const boost::system::error_code& e) { Info info(__FUNCTION__); LOG(1, "INFO: result #" << result->getId() << " sent."); AsyncOperation::handle_FinishOperation(e); }