RequestImpl.cpp 1.84 KB
Newer Older
legoc's avatar
legoc committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
 * 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.
 */

17
#include "RequestImpl.h"
legoc's avatar
legoc committed
18

19
#include "../Application.h"
20
#include "../Serializer.h"
21
#include "ServicesImpl.h"
22
#include <sstream>
legoc's avatar
legoc committed
23
24
25
26
27

using namespace std;

namespace cameo {

28
RequestImpl::RequestImpl(const application::This * application, const std::string & requesterApplicationName, int requesterApplicationId, const std::string& message, const std::string& serverUrl, int serverPort, int requesterPort) :
legoc's avatar
legoc committed
29
30
	m_application(application),
	m_message(message),
31
	m_requesterApplicationName(requesterApplicationName),
legoc's avatar
legoc committed
32
	m_requesterApplicationId(requesterApplicationId) {
33
34
35
36
37
38
39
40

	stringstream requesterEndpoint;
	requesterEndpoint << serverUrl << ":" << requesterPort;
	m_requesterEndpoint = requesterEndpoint.str();

	stringstream requesterServerEndpoint;
	requesterServerEndpoint << serverUrl << ":" << serverPort;
	m_requesterServerEndpoint = requesterServerEndpoint.str();
legoc's avatar
legoc committed
41
42
43
44
45
}

RequestImpl::~RequestImpl() {
}

legoc's avatar
legoc committed
46
void RequestImpl::replyBinary(const std::string& response) {
legoc's avatar
legoc committed
47
48
49
50
	string strRequestType = m_application->m_impl->createRequest(PROTO_RESPONSE);
	m_application->m_impl->tryRequestWithOnePartReply(strRequestType, response, m_requesterEndpoint);
}

legoc's avatar
legoc committed
51
void RequestImpl::reply(const std::string& response) {
legoc's avatar
legoc committed
52
53
54
55
56

	// encode the data
	string result;
	serialize(response, result);

legoc's avatar
legoc committed
57
	replyBinary(result);
legoc's avatar
legoc committed
58
59
60
61
}

}