[b7a122]: src / org / esb / rpc / Channel.cpp  Maximize  Restore  History

Download this file

74 lines (60 with data), 2.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* File: Channel.cpp
* Author: HoelscJ
*
* Created on 11. Januar 2011, 17:07
*/
#include "Channel.h"
#include "org/esb/rpc/rpc.pb.h"
#include "google/protobuf/descriptor.h"
namespace org {
namespace esb {
namespace rpc {
Channel::Channel() {
}
Channel::Channel(org::esb::net::TcpSocket * s):_socket(s) {
}
Channel::~Channel() {
}
// Call the given method of the remote service. The signature of this
// procedure looks the same as Service::CallMethod(), but the requirements
// are less strict in one important way: the request and response objects
// need not be of any specific class as long as their descriptors are
// method->input_type() and method->output_type().
void Channel::CallMethod(const google::protobuf::MethodDescriptor* method,
google::protobuf::RpcController* controller,
const google::protobuf::Message* request,
google::protobuf::Message* response,
google::protobuf::Closure* done) {
//std::cout << "void Channel::CallMethod"<<std::endl;
org::esb::rpc::Request anRPCRequest;
org::esb::rpc::Response anRPCResponse;
std::string requestRawString;
std::string RPCResponseString;
request->SerializeToString(&requestRawString);
anRPCRequest.set_request_proto(requestRawString);
anRPCRequest.set_service_name(method->service()->full_name());
anRPCRequest.set_method_name(method->name());
if (_socket) {
std::string outdata;
anRPCRequest.SerializeToString(&outdata);
_socket->getOutputStream()->write(outdata);
std::string indata;
_socket->getInputStream()->read(indata);
anRPCResponse.ParseFromString(indata);
} else {
fprintf(stderr, "%s: No Server or Socket set !\n", __FUNCTION__);
}
if (anRPCResponse.has_error_reason() && anRPCResponse.error_reason() != NO_ERROR_OCCURRED) {
controller->SetFailed(anRPCResponse.error());
} else if (anRPCResponse.response_proto().size() > 0) {
// Build a response from the response_proto returned by the RPC.
response->ParseFromString(anRPCResponse.response_proto());
}
if (done) {
done->Run();
}
}
}
}
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks