This commit is contained in:
Pedro Pinto committed 2017-08-07 17:21:12 -04:00
commit 950e7b7e2d
350 files changed
+38599

No files matched your search

@@ -0,0 +1,48 @@
#include "QuickbusClientChannel.h"
#include "QuickbusClientChannel.h"
#include "ClientChannel.h"
namespace bts {
namespace api {
QuickbusClientChannel::QuickbusClientChannel(Quickbus& bus, const char* type_name, const char* service_qualifier) :
_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 std::string & method_and_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_and_qualifier.c_str(), 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