61 lines
2.0 KiB
C++
61 lines
2.0 KiB
C++
#include "QuickbusClientChannel.h"
|
|
#include "ClientChannel.h"
|
|
#include "QuickbusClientChannel.h"
|
|
namespace bts {
|
|
namespace api {
|
|
|
|
QuickbusClientChannel::QuickbusClientChannel(
|
|
Quickbus &bus,
|
|
const ServiceContext &context,
|
|
const char *type_name,
|
|
const char *service_qualifier)
|
|
: ClientChannel(context),
|
|
_pclient(api_client_create(&bus, type_name, service_qualifier)) {}
|
|
|
|
QuickbusClientChannel::~QuickbusClientChannel() {
|
|
if (_pclient != nullptr) {
|
|
api_client_destroy(_pclient);
|
|
_pclient = nullptr;
|
|
}
|
|
}
|
|
|
|
void QuickbusClientChannel::send_core(
|
|
const std::string &request_envalope, OnReply on_response) {
|
|
raw_response_callback trampoline = [](const char *buffer, size_t length,
|
|
void *extraptr) {
|
|
OnReply *on_response = static_cast<OnReply *>(extraptr);
|
|
assert(on_response != nullptr);
|
|
(*on_response)(buffer, length);
|
|
delete on_response;
|
|
};
|
|
OnReply *heap_on_response = new OnReply(move(on_response));
|
|
api_client_send(
|
|
_pclient, request_envalope.c_str(), request_envalope.size(), trampoline,
|
|
heap_on_response);
|
|
}
|
|
|
|
ClientChannel::Unsubscribe QuickbusClientChannel::subscribe_core(
|
|
const char *method, const char *qualifier, OnSubscriptionCB cb) {
|
|
raw_subscription_callback trampoline = [](EventType event_type,
|
|
const StreamUpdate *changes,
|
|
int count, void *extra) {
|
|
OnSubscriptionCB *heap_cb = static_cast<OnSubscriptionCB *>(extra);
|
|
assert(heap_cb != nullptr);
|
|
(*heap_cb)(event_type, changes, count);
|
|
};
|
|
OnSubscriptionCB *heap_cb = new OnSubscriptionCB(cb);
|
|
auto subscription =
|
|
api_client_subscribe(_pclient, method, qualifier, trampoline, heap_cb);
|
|
return [this, subscription, heap_cb]() {
|
|
api_client_unsubscribe(_pclient, subscription);
|
|
delete heap_cb;
|
|
};
|
|
}
|
|
|
|
bool QuickbusClientChannel::is_sync_call_ok() {
|
|
return !api_client_is_on_qb_thread(_pclient);
|
|
}
|
|
|
|
} // namespace api
|
|
} // namespace bts
|