]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/tutorial/cpp/CppClient.cpp
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
22 #include <thrift/protocol/TBinaryProtocol.h>
23 #include <thrift/transport/TSocket.h>
24 #include <thrift/transport/TTransportUtils.h>
26 #include "../gen-cpp/Calculator.h"
29 using namespace apache::thrift
;
30 using namespace apache::thrift::protocol
;
31 using namespace apache::thrift::transport
;
33 using namespace tutorial
;
34 using namespace shared
;
37 std::shared_ptr
<TTransport
> socket(new TSocket("localhost", 9090));
38 std::shared_ptr
<TTransport
> transport(new TBufferedTransport(socket
));
39 std::shared_ptr
<TProtocol
> protocol(new TBinaryProtocol(transport
));
40 CalculatorClient
client(protocol
);
46 cout
<< "ping()" << endl
;
48 cout
<< "1 + 1 = " << client
.add(1, 1) << endl
;
51 work
.op
= Operation::DIVIDE
;
56 client
.calculate(1, work
);
57 cout
<< "Whoa? We can divide by zero!" << endl
;
58 } catch (InvalidOperation
& io
) {
59 cout
<< "InvalidOperation: " << io
.why
<< endl
;
60 // or using generated operator<<: cout << io << endl;
61 // or by using std::exception native method what(): cout << io.what() << endl;
64 work
.op
= Operation::SUBTRACT
;
67 int32_t diff
= client
.calculate(1, work
);
68 cout
<< "15 - 10 = " << diff
<< endl
;
70 // Note that C++ uses return by reference for complex types to avoid
71 // costly copy construction
73 client
.getStruct(ss
, 1);
74 cout
<< "Received log: " << ss
<< endl
;
77 } catch (TException
& tx
) {
78 cout
<< "ERROR: " << tx
.what() << endl
;