/* * Copyright 2015 Institut Laue-Langevin * * Licensed under the EUPL, Version 1.1 only (the "License"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * * http://joinup.ec.europa.eu/software/page/eupl * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. */ #include "RequestImpl.h" #include "../Application.h" #include "../Serializer.h" #include "ServicesImpl.h" #include "RequestSocketImpl.h" #include using namespace std; namespace cameo { RequestImpl::RequestImpl(application::This * application, const std::string & requesterApplicationName, int requesterApplicationId, const std::string& message, const std::string& serverUrl, int serverPort, int requesterPort) : m_application(application), m_message(message), m_requesterApplicationName(requesterApplicationName), m_requesterApplicationId(requesterApplicationId), m_timeout(0) { stringstream requesterEndpoint; requesterEndpoint << serverUrl << ":" << requesterPort; m_requesterEndpoint = requesterEndpoint.str(); stringstream requesterServerEndpoint; requesterServerEndpoint << serverUrl << ":" << serverPort; m_requesterServerEndpoint = requesterServerEndpoint.str(); } RequestImpl::~RequestImpl() { } void RequestImpl::setTimeout(int value) { m_timeout = value; } void RequestImpl::replyBinary(const std::string& response) { // Create a request socket. It is created for each request that could be optimized. unique_ptr requestSocket = m_application->createRequestSocket(m_requesterEndpoint, m_timeout); //requestSocket->requestAsync(m_application->m_impl->createRequestType(PROTO_RESPONSE), response); try { requestSocket->request(m_application->m_impl->createRequestType(PROTO_RESPONSE), response); } catch (const ConnectionTimeout&) { cout << "timeout while replying" << endl; } } void RequestImpl::reply(const std::string& response) { // Encode the data. string result; serialize(response, result); replyBinary(result); } }