From ec7a4df5ee9ec1188665df0215e30128503fd9b9 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Mon, 30 Apr 2018 15:55:28 -0400 Subject: [PATCH] Remove underscore restiction on qualifier in ApiServerInterop --- src/lib/api/core/ApiServerInterop.cpp | 166 +++++++++++++------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/src/lib/api/core/ApiServerInterop.cpp b/src/lib/api/core/ApiServerInterop.cpp index 547d31ef5..fa00bdef9 100644 --- a/src/lib/api/core/ApiServerInterop.cpp +++ b/src/lib/api/core/ApiServerInterop.cpp @@ -1,83 +1,83 @@ -#include "ApiServerInterop.h" -#include "lib/quickbus/quickbus.h" -#include "lib/logging/logging.h" -#include "lib/utils/bts_assert.h" - -namespace bts { -namespace api { - -// defined in ApiClientInterop.h -std::string base_topic(const char* type_name, const char* service_qualifier); -bts::qbus::RPCServiceName rpc_topic(const std::string& base_topic); -bts::qbus::Topic stream_topic(const std::string& base_topic, const char* method_and_qualifier); - -struct ApiServerCore { - ApiServerCore(Quickbus& qbus, const std::string topic, const qbus::OnRPCRequest& handler) : - qbus(qbus), - topic(topic), - rpc(qbus, rpc_topic(topic), handler) - {} - - Quickbus& qbus; - std::string topic; - qbus::RPCServer rpc; -}; - -CAPI ApiServerCore* api_server_create(Quickbus* pbus, const char* type_name, const char* service_qualifier, raw_rpc_request_callback cb, void* extra) { - bts_assert(pbus); - // Invalid characters in qualifier: + - for (auto ch : { '+', '_' }) { - bts_assert(strchr(service_qualifier, ch) == nullptr); - } - auto service_name = base_topic(type_name, service_qualifier); - LOG(Api,Info,"Create server: {}",service_name); - return new ApiServerCore(*pbus, service_name, [=](qbus::RPCRequestPtr const& req, qbus::ReplyHandler const& reply) { - // Extend the lifetime of the ReplyHandler by moving it to the heap - qbus::ReplyHandler* phandler = new qbus::ReplyHandler(std::move(reply)); - LOG(Api,Diag,"Received rpc request: {}",reinterpret_cast(phandler)); - cb((uint8_t*)(req->value().c_str()), req->value().size(), reinterpret_cast(phandler), extra); - }); -} - -CAPI void api_server_call_callback(ReplyHandler** ppvhandler, const uint8_t* buffer, int length) { - bts_assert(ppvhandler); - bts_assert(*ppvhandler); - //LOG(Api,Diag,"Send rpc reply: {}",reinterpret_cast(*ppvhandler)); - qbus::ReplyHandler** pphandler = reinterpret_cast(ppvhandler); - std::string reply_buffer((const char*)buffer, (size_t)length); - qbus::RPCReplyPtr replyptr = std::make_shared(move(reply_buffer)); - (**pphandler)(replyptr); - delete (*pphandler); - *pphandler = nullptr; -} - -CAPI TableHandle api_server_create_table(ApiServerCore* pserver, const char* method_and_qualifier) { - bts_assert(pserver); - auto topic = stream_topic(pserver->topic, method_and_qualifier); - LOG(Api,Info,"Create table: {}",topic.value()); - return new qbus::TablePublisher(pserver->qbus, topic); -} - -CAPI void api_server_update_table(TableHandle htable, StreamUpdate* raw_changes, int change_count) { - if (change_count > 0) { - bts_assert(htable); - qbus::TablePublisher* ptable = reinterpret_cast(htable); - std::vector changes(change_count); - for (int x = 0; x < change_count; ++x) { - StreamUpdate& ch = raw_changes[x]; - std::string buffer(ch.buffer, ch.buffer_len); - qbus::RecordPtr record = std::make_shared(std::move(buffer)); - changes[x] = qbus::Change((qbus::Change::Type)ch.type, qbus::RecordKey(ch.key), record); - } - ptable->publish(std::move(changes)); - } -} - -CAPI void api_server_destroy_table(qbus::TablePublisher* ptable) { - if (ptable) { - ptable->disconnect(); - delete ptable; - } -} - -} }//namespace +#include "ApiServerInterop.h" +#include "lib/quickbus/quickbus.h" +#include "lib/logging/logging.h" +#include "lib/utils/bts_assert.h" + +namespace bts { +namespace api { + +// defined in ApiClientInterop.h +std::string base_topic(const char* type_name, const char* service_qualifier); +bts::qbus::RPCServiceName rpc_topic(const std::string& base_topic); +bts::qbus::Topic stream_topic(const std::string& base_topic, const char* method_and_qualifier); + +struct ApiServerCore { + ApiServerCore(Quickbus& qbus, const std::string topic, const qbus::OnRPCRequest& handler) : + qbus(qbus), + topic(topic), + rpc(qbus, rpc_topic(topic), handler) + {} + + Quickbus& qbus; + std::string topic; + qbus::RPCServer rpc; +}; + +CAPI ApiServerCore* api_server_create(Quickbus* pbus, const char* type_name, const char* service_qualifier, raw_rpc_request_callback cb, void* extra) { + bts_assert(pbus); + // Invalid characters in qualifier: + + for (auto ch : { '+' }) { + bts_assert(strchr(service_qualifier, ch) == nullptr); + } + auto service_name = base_topic(type_name, service_qualifier); + LOG(Api,Info,"Create server: {}",service_name); + return new ApiServerCore(*pbus, service_name, [=](qbus::RPCRequestPtr const& req, qbus::ReplyHandler const& reply) { + // Extend the lifetime of the ReplyHandler by moving it to the heap + qbus::ReplyHandler* phandler = new qbus::ReplyHandler(std::move(reply)); + LOG(Api,Diag,"Received rpc request: {}",reinterpret_cast(phandler)); + cb((uint8_t*)(req->value().c_str()), req->value().size(), reinterpret_cast(phandler), extra); + }); +} + +CAPI void api_server_call_callback(ReplyHandler** ppvhandler, const uint8_t* buffer, int length) { + bts_assert(ppvhandler); + bts_assert(*ppvhandler); + //LOG(Api,Diag,"Send rpc reply: {}",reinterpret_cast(*ppvhandler)); + qbus::ReplyHandler** pphandler = reinterpret_cast(ppvhandler); + std::string reply_buffer((const char*)buffer, (size_t)length); + qbus::RPCReplyPtr replyptr = std::make_shared(move(reply_buffer)); + (**pphandler)(replyptr); + delete (*pphandler); + *pphandler = nullptr; +} + +CAPI TableHandle api_server_create_table(ApiServerCore* pserver, const char* method_and_qualifier) { + bts_assert(pserver); + auto topic = stream_topic(pserver->topic, method_and_qualifier); + LOG(Api,Info,"Create table: {}",topic.value()); + return new qbus::TablePublisher(pserver->qbus, topic); +} + +CAPI void api_server_update_table(TableHandle htable, StreamUpdate* raw_changes, int change_count) { + if (change_count > 0) { + bts_assert(htable); + qbus::TablePublisher* ptable = reinterpret_cast(htable); + std::vector changes(change_count); + for (int x = 0; x < change_count; ++x) { + StreamUpdate& ch = raw_changes[x]; + std::string buffer(ch.buffer, ch.buffer_len); + qbus::RecordPtr record = std::make_shared(std::move(buffer)); + changes[x] = qbus::Change((qbus::Change::Type)ch.type, qbus::RecordKey(ch.key), record); + } + ptable->publish(std::move(changes)); + } +} + +CAPI void api_server_destroy_table(qbus::TablePublisher* ptable) { + if (ptable) { + ptable->disconnect(); + delete ptable; + } +} + +} }//namespace