From ef97b447b06eff74de0563b2444096239d3f16b0 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Wed, 27 Sep 2017 17:03:03 -0400 Subject: [PATCH] callback parameter to service rpc server should be const ref isntead of copy --- src/lib/api/service_compiler/plugin.py | 5 +++++ .../api/service_compiler/templates/cpp/server.pb.h | 2 +- src/lib/api/test/ApiTests.cpp | 12 ++++++------ src/lib/api/test/HelloServiceServer.cpp | 6 +++--- src/lib/api/test/HelloServiceServer.h | 6 +++--- src/lib/md/relay/QueryServer.cpp | 2 +- .../sparkd/orderman/service/OrderServiceServer.h | 6 +++--- .../sparkd/persistence/PersistenceServiceServer.cpp | 10 +++++----- .../sparkd/persistence/PersistenceServiceServer.h | 10 +++++----- src/server/sparkd/user/UserServiceServer.cpp | 4 ++-- src/server/sparkd/user/UserServiceServer.h | 4 ++-- 11 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/lib/api/service_compiler/plugin.py b/src/lib/api/service_compiler/plugin.py index f8c59d3cc..41d6078fc 100755 --- a/src/lib/api/service_compiler/plugin.py +++ b/src/lib/api/service_compiler/plugin.py @@ -229,6 +229,11 @@ def generate_code(request, response): 'type': lambda this,item: item.split('.')[-1:][0], 'camel': lambda _,f: camel_case(f), } + # for proto_file in request.proto_file: + # todo: for all files on the input + # get a list of their messages and Key fields + # pass this as a dictionary into transform_file + # pass for proto_file in request.proto_file: if proto_file.name in request.file_to_generate: proto_file = transform_file(proto_file) diff --git a/src/lib/api/service_compiler/templates/cpp/server.pb.h b/src/lib/api/service_compiler/templates/cpp/server.pb.h index 3675ad8da..bf871d788 100644 --- a/src/lib/api/service_compiler/templates/cpp/server.pb.h +++ b/src/lib/api/service_compiler/templates/cpp/server.pb.h @@ -36,7 +36,7 @@ protected: {{cap name}}Publisher make_{{name}}_publisher(const {{input_type}}& qualifier) const; {{else}} // {{comment}} - virtual void {{name}}(const {{input_type}}& request, std::function reply) = 0; + virtual void {{name}}(const {{input_type}}& request, const std::function& reply) = 0; {{/if}} {{/each}} diff --git a/src/lib/api/test/ApiTests.cpp b/src/lib/api/test/ApiTests.cpp index 8a9f1fdd9..ed2c1ab37 100644 --- a/src/lib/api/test/ApiTests.cpp +++ b/src/lib/api/test/ApiTests.cpp @@ -26,7 +26,7 @@ namespace test { _shout() {} // Inherited via ApiTestServiceBase - virtual void format_qualifier(const QualifierArgument & request, function reply) override { + virtual void format_qualifier(const QualifierArgument & request, const std::function& reply) override { TestResult result; switch (request.qualifier_case()) { case QualifierArgument::kSimple: @@ -45,24 +45,24 @@ namespace test { } // Inherited via ApiTestServiceBase - virtual void test_empty_reply(const EmptyRequest&, std::function reply) override { + virtual void test_empty_reply(const EmptyRequest&, const std::function& reply) override { TestResult result; reply(result); } - virtual void run_hello_service(const EmptyRequest&, std::function reply) override { + virtual void run_hello_service(const EmptyRequest&, const std::function& reply) override { _hello.reset(new HelloServiceServer(_ctx)); reply(TestResult()); } - virtual void stop_hello_service(const EmptyRequest&, std::function reply) override { + virtual void stop_hello_service(const EmptyRequest&, const std::function& reply) override { _hello.reset(); reply(TestResult()); } - virtual void run_shout_service(const EmptyRequest&, std::function reply) override { + virtual void run_shout_service(const EmptyRequest&, const std::function& reply) override { _shout.reset(new ShoutServiceServer(_ctx)); reply(TestResult()); } - virtual void stop_shout_service(const EmptyRequest&, std::function reply) override { + virtual void stop_shout_service(const EmptyRequest&, const std::function& reply) override { _shout.reset(); reply(TestResult()); } diff --git a/src/lib/api/test/HelloServiceServer.cpp b/src/lib/api/test/HelloServiceServer.cpp index 67653e2fd..dab250104 100644 --- a/src/lib/api/test/HelloServiceServer.cpp +++ b/src/lib/api/test/HelloServiceServer.cpp @@ -29,14 +29,14 @@ void HelloServiceServer::publish(const std::string& msg, int* to_remove) { _gpub(&added, nullptr, &removed); } -void HelloServiceServer::say_hello(const HelloRequest & request, std::function reply) { +void HelloServiceServer::say_hello(const HelloRequest & request, const std::function& reply) { HelloResponse response; response.set_message("hello " + request.name()); publish(response.message()); reply(response); } -void HelloServiceServer::yell_hello(const HelloRequest & request, std::function reply) { +void HelloServiceServer::yell_hello(const HelloRequest & request, const std::function& reply) { HelloResponse response; ShoutRequest sr; @@ -56,7 +56,7 @@ void HelloServiceServer::yell_hello(const HelloRequest & request, std::function< ShoutServiceServer::ShoutServiceServer(bts::api::ServiceContext & context) : ShoutServiceBase(context) { } -void test::ShoutServiceServer::upper(const ShoutRequest & request, std::function on_result) { +void test::ShoutServiceServer::upper(const ShoutRequest & request, const std::function& on_result) { ShoutResponse response; response.set_msg( boost::to_upper_copy(request.msg())); diff --git a/src/lib/api/test/HelloServiceServer.h b/src/lib/api/test/HelloServiceServer.h index c419d31a3..2aae38a07 100644 --- a/src/lib/api/test/HelloServiceServer.h +++ b/src/lib/api/test/HelloServiceServer.h @@ -24,15 +24,15 @@ private: void publish(const std::string& msg, int * to_remove=nullptr); // Inherited via HelloServiceBase - virtual void say_hello(const HelloRequest & request, std::function on_result) override; - virtual void yell_hello(const HelloRequest & request, std::function on_result) override; + virtual void say_hello(const HelloRequest & request, const std::function& on_result) override; + virtual void yell_hello(const HelloRequest & request, const std::function& on_result) override; }; struct BTS_EXPORT ShoutServiceServer : public ShoutServiceBase { ShoutServiceServer(bts::api::ServiceContext& context); // Inherited via ShoutServiceBase - virtual void upper(const ShoutRequest & request, std::function on_result) override; + virtual void upper(const ShoutRequest & request, const std::function& on_result) override; }; }}}//namespace diff --git a/src/lib/md/relay/QueryServer.cpp b/src/lib/md/relay/QueryServer.cpp index 958b70ce1..86f5fe3a6 100644 --- a/src/lib/md/relay/QueryServer.cpp +++ b/src/lib/md/relay/QueryServer.cpp @@ -344,7 +344,7 @@ struct MDRelayServer : bts::co2::MarketDataRelayBase { _db(db), _threadpool(threadpool) { } - virtual void requestmd(const MDRequest & request, std::function reply) override { + virtual void requestmd(const MDRequest & request, const std::function& reply) override { _threadpool.post([=]() { google::protobuf::Arena arena; MDReply* preply = google::protobuf::Arena::CreateMessage(&arena); diff --git a/src/server/sparkd/orderman/service/OrderServiceServer.h b/src/server/sparkd/orderman/service/OrderServiceServer.h index c93d16005..034e2db99 100644 --- a/src/server/sparkd/orderman/service/OrderServiceServer.h +++ b/src/server/sparkd/orderman/service/OrderServiceServer.h @@ -13,15 +13,15 @@ public: ~OrderServiceServer(); void create_order(const api::orderman::CreateOrderRequest& , - std::function ) override; + const std::function& ) override; void cancel_order(const api::orderman::CancelOrderRequest& , - std::function ) override; + const std::function& ) override; void update_order(const api::orderman::UpdateOrderRequest& , - std::function ) override; + const std::function& ) override; private: enum class VenueState; diff --git a/src/server/sparkd/persistence/PersistenceServiceServer.cpp b/src/server/sparkd/persistence/PersistenceServiceServer.cpp index 40ef06c29..60aec6dd5 100644 --- a/src/server/sparkd/persistence/PersistenceServiceServer.cpp +++ b/src/server/sparkd/persistence/PersistenceServiceServer.cpp @@ -73,7 +73,7 @@ PersistenceServiceServer::PersistenceServiceServer(bts::api::ServiceContext & co PersistenceServiceServer::~PersistenceServiceServer() {} void PersistenceServiceServer::retrieve(const RetrieveRequest& request, - std::function reply) + const std::function& reply) { LOG(Persistence,Diag, "Retrieving {} rows from {}/{}", request.key().size(), me->db,request.ns()); RetrieveResponse response; @@ -126,7 +126,7 @@ void PersistenceServiceServer::retrieve(const RetrieveRequest& request, } void PersistenceServiceServer::retrieve_all(const RetrieveAllRequest& request, - std::function reply) + const std::function& reply) { LOG(Persistence,Diag, "Retrieving all rows from {}/{}", me->db,request.ns()); RetrieveResponse response; @@ -156,7 +156,7 @@ void PersistenceServiceServer::retrieve_all(const RetrieveAllRequest& request, } void PersistenceServiceServer::remove(const RemoveRequest& request, - std::function reply) + const std::function& reply) { LOG(Persistence,Diag, "Removing {} rows from {}/{}", request.key().size(), me->db,request.ns()); @@ -227,7 +227,7 @@ void PersistenceServiceServer::remove(const RemoveRequest& request, } void PersistenceServiceServer::remove_all(const RemoveAllRequest& request, - std::function reply) + const std::function& reply) { LOG(Persistence,Diag, "Removing all rows from {}/{}", me->db,request.ns()); @@ -270,7 +270,7 @@ void PersistenceServiceServer::remove_all(const RemoveAllRequest& request, } void PersistenceServiceServer::store(const StoreRequest& request, - std::function reply) + const std::function& reply) { LOG(Persistence,Diag, "Storing {} rows in {}/{}", request.record().size(), me->db,request.ns()); StoreResponse response; diff --git a/src/server/sparkd/persistence/PersistenceServiceServer.h b/src/server/sparkd/persistence/PersistenceServiceServer.h index e804ec3a4..4a092792d 100644 --- a/src/server/sparkd/persistence/PersistenceServiceServer.h +++ b/src/server/sparkd/persistence/PersistenceServiceServer.h @@ -13,17 +13,17 @@ public: ~PersistenceServiceServer(); void retrieve(const api::persistence::RetrieveRequest& request, - std::function reply)override; + const std::function& reply)override; void retrieve_all(const api::persistence::RetrieveAllRequest& request, - std::function reply)override; + const std::function& reply)override; void remove(const api::persistence::RemoveRequest& request, - std::function reply)override; + const std::function& reply)override; void remove_all(const api::persistence::RemoveAllRequest& request, - std::function reply)override; + const std::function& reply)override; void store(const api::persistence::StoreRequest& request, - std::function reply)override; + const std::function& reply)override; private: typedef PersistenceServiceServer::NsPublisher Publisher; struct PImpl; diff --git a/src/server/sparkd/user/UserServiceServer.cpp b/src/server/sparkd/user/UserServiceServer.cpp index 7e6fe15f4..9b79607ea 100644 --- a/src/server/sparkd/user/UserServiceServer.cpp +++ b/src/server/sparkd/user/UserServiceServer.cpp @@ -14,7 +14,7 @@ UserServiceServer::UserServiceServer (bts::api::ServiceContext& context) : UserS UserServiceServer::~UserServiceServer () {} void UserServiceServer::get_logins(const api::user::GetLoginsRequest& , - std::function r ) + const std::function& r ) { api::user::GetLoginsRespose resp; auto users = config::get(); @@ -24,7 +24,7 @@ void UserServiceServer::get_logins(const api::user::GetLoginsRequest& , } void UserServiceServer::authenticate_login(const api::user::AuthenticateLoginRequest& r, - std::function respond) + const std::function& respond) { api::user::AuthenticateLoginResponse resp; resp.set_is_valid(false); diff --git a/src/server/sparkd/user/UserServiceServer.h b/src/server/sparkd/user/UserServiceServer.h index 07432ce11..34efffd26 100644 --- a/src/server/sparkd/user/UserServiceServer.h +++ b/src/server/sparkd/user/UserServiceServer.h @@ -12,9 +12,9 @@ public: UserServiceServer (bts::api::ServiceContext& context); ~UserServiceServer(); void get_logins(const api::user::GetLoginsRequest& , - std::function ) override; + const std::function& ) override; void authenticate_login(const api::user::AuthenticateLoginRequest& , - std::function ) override; + const std::function& ) override; }; }}