Files
spark/src/lib/api/service_compiler/templates/cpp/client.pb.cc
T
John Colvin 62bf1d069c Fix build errors caused by big merge, externals upgrade
A lot of server-side changes were just merged as part of the Brandon
project (crypto).  Many of those changes were in libspark (a lib on
which both the client and server depend), and upgrades to its external
dependencies.  As a result, windows counterparts of several upgraded
external libs needed to be similarly upgraded (or added for the first
time).  These libs include: boost, btree, catch, curl, fmt, nlohmann json,
openssl, range, rxcpp, websocketpp

This change also makes protobuf generation compatible with python3, and thus
eliminates the build's dependency on python2
2021-12-09 11:40:42 -05:00

68 lines
2.3 KiB
C++

{{#if service}}
#include "{{filename name}}.client.pb.h"
#include "lib/api/public/ApiUtils.h"
#include <future>
using namespace rxcpp;
using namespace rxcpp::sources;
using namespace rxcpp::operators;
{{ns-open package}}
{{#each service}}
// Constructor
{{name}}::{{name}}(std::unique_ptr<bts::api::ClientChannel> pchannel) : _pchannel(move(pchannel)) {}
{{name}}::{{name}}({{name}}&& other) : _pchannel(move(other._pchannel)) { }
{{#each method}}
{{#if server_streaming}}
rxcpp::observable<{{cap name}}Update> {{../name}}::subscribe_{{name}}(std::string const&qualifier) {
return
_pchannel->subscribe<{{output_type_cpp}}>({{@index}}, "{{name}}", qualifier)
| (bts::api::reconstitute<std::shared_ptr<{{output_type_cpp}}>,const {{key_type.cpptype}}, {{../name}}>());
}
rxcpp::observable<{{cap name}}Update> {{../name}}::subscribe_{{name}}() {
return
_pchannel->subscribe<{{output_type_cpp}}>({{@index}}, "{{name}}", "")
| (bts::api::reconstitute<std::shared_ptr<{{output_type_cpp}}>,const {{key_type.cpptype}}, {{../name}}>());
}
{{#if key_type.natural_key}}
{{key_type.cpptype}} {{../name}}::{{name}}_key(const {{output_type_cpp}}& row) {
return row.{{key_field}}();
}
{{else}}
const {{key_type.cpptype}}& {{../name}}::{{name}}_key(const {{output_type_cpp}}& row) {
return row.{{key_field}}();
}
{{/if}}
{{else}}
void {{../name}}::{{name}}(const {{input_type_cpp}}& input, std::function<void(const bts::api::Result<{{output_type_cpp}}>)> callback, uint32_t timeout_ms) {
_pchannel->send({{@index}}, input, callback);
}
bts::api::Result<{{output_type_cpp}}> {{../name}}::{{name}}(const {{input_type_cpp}}& input, uint32_t timeout_ms) {
if (_pchannel->is_sync_call_ok()) {
std::promise<bts::api::Result<{{output_type_cpp}}>> p;
auto future = p.get_future();
{{name}}(input, [&](bts::api::Result<{{output_type_cpp}}> res) {
p.set_value(res);
}, timeout_ms);
future.wait();
return future.get();
}
else {
throw bts::api::ApiException("API blocking call cannot be made on this thread. Please use {{name}}_async instead.");
}
}
{{/if}}
{{/each}}
{{/each}}
{{ns-close package}}
{{/if}}