aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2020-05-14 10:15:22 +0200
committerShauren <shauren.trinity@gmail.com>2020-05-14 10:15:22 +0200
commitd3e1e4be229d7b3a4b8aa9d2a43b7ae3a5d72d39 (patch)
tree3ea9b964fcbb33e5286a31cd0a475fbeb70de58f
parentd3782c2d095546d1e5bf56133c58677418b49d1e (diff)
Misc: Update protobuf code generator plugin for 4c85198ed6135b42f9dfe0ad16901f7d741b64c6
-rw-r--r--contrib/protoc-bnet/BnetServiceGenerator.cpp81
-rw-r--r--contrib/protoc-bnet/CMakeLists.txt25
2 files changed, 71 insertions, 35 deletions
diff --git a/contrib/protoc-bnet/BnetServiceGenerator.cpp b/contrib/protoc-bnet/BnetServiceGenerator.cpp
index 41088fbf5c2..149eee8fd7c 100644
--- a/contrib/protoc-bnet/BnetServiceGenerator.cpp
+++ b/contrib/protoc-bnet/BnetServiceGenerator.cpp
@@ -22,10 +22,12 @@ BnetServiceGenerator::BnetServiceGenerator(pb::ServiceDescriptor const* descript
if (descriptor_->options().HasExtension(Battlenet::service_options))
vars_["original_hash"] = " typedef std::integral_constant<uint32, 0x" + pb::ToUpper(pb::ToHex(HashServiceName(descriptor_->options().GetExtension(Battlenet::service_options).descriptor_name()))) + "u> OriginalHash;\n";
+ else
+ vars_["original_hash"] = "";
vars_["name_hash"] = " typedef std::integral_constant<uint32, 0x" + pb::ToUpper(pb::ToHex(HashServiceName(descriptor_->full_name()))) + "u> NameHash;\n";
}
-BnetServiceGenerator::~BnetServiceGenerator() { }
+BnetServiceGenerator::~BnetServiceGenerator() = default;
void BnetServiceGenerator::GenerateDeclarations(pb::io::Printer* printer)
{
@@ -50,25 +52,34 @@ void BnetServiceGenerator::GenerateInterface(pb::io::Printer* printer)
printer->Print(vars_,
"\n"
"static google::protobuf::ServiceDescriptor const* descriptor();\n"
- "\n"
- "// client methods --------------------------------------------------\n"
"\n");
- GenerateClientMethodSignatures(printer);
+ if (!descriptor_->options().HasExtension(Battlenet::sdk_service_options) || descriptor_->options().GetExtension(Battlenet::sdk_service_options).inbound())
+ {
+ printer->Print(vars_,
+ "// client methods --------------------------------------------------\n");
- printer->Print(
- "// server methods --------------------------------------------------\n"
- "\n"
- "void CallServerMethod(uint32 token, uint32 methodId, MessageBuffer buffer) override final;\n"
- "\n");
+ GenerateClientMethodSignatures(printer);
- printer->Outdent();
+ printer->Print(vars_, "\n");
+ }
- printer->Print(" protected:\n ");
+ printer->Print("void CallServerMethod(uint32 token, uint32 methodId, MessageBuffer buffer) final;\n");
- printer->Indent();
+ if (!descriptor_->options().HasExtension(Battlenet::sdk_service_options) || descriptor_->options().GetExtension(Battlenet::sdk_service_options).outbound())
+ {
+ printer->Outdent();
+
+ printer->Print(
+ "\n"
+ " protected:\n ");
- GenerateServerMethodSignatures(printer);
+ printer->Indent();
+
+ printer->Print("// server methods --------------------------------------------------\n");
+
+ GenerateServerMethodSignatures(printer);
+ }
printer->Outdent();
@@ -98,9 +109,9 @@ void BnetServiceGenerator::GenerateClientMethodSignatures(pb::io::Printer* print
sub_vars["input_type_name"] = method->input_type()->full_name();
if (method->output_type()->name() != "NO_RESPONSE")
- printer->Print(sub_vars, "void $name$($input_type$ const* request, std::function<void($output_type$ const*)> responseCallback);\n");
+ printer->Print(sub_vars, "void $name$($input_type$ const* request, std::function<void($output_type$ const*)> responseCallback, bool client = false, bool server = false);\n");
else
- printer->Print(sub_vars, "void $name$($input_type$ const* request);\n");
+ printer->Print(sub_vars, "void $name$($input_type$ const* request, bool client = false, bool server = false);\n");
}
}
@@ -152,9 +163,23 @@ void BnetServiceGenerator::GenerateImplementation(pb::io::Printer* printer)
"}\n"
"\n");
- GenerateClientMethodImplementations(printer);
- GenerateServerCallMethod(printer);
- GenerateServerImplementations(printer);
+ if (!descriptor_->options().HasExtension(Battlenet::sdk_service_options) || descriptor_->options().GetExtension(Battlenet::sdk_service_options).inbound())
+ GenerateClientMethodImplementations(printer);
+
+ if (!descriptor_->options().HasExtension(Battlenet::sdk_service_options) || descriptor_->options().GetExtension(Battlenet::sdk_service_options).outbound())
+ {
+ GenerateServerCallMethod(printer);
+ GenerateServerImplementations(printer);
+ }
+ else
+ {
+ printer->Print(vars_,
+ "void $classname$::CallServerMethod(uint32 token, uint32 methodId, MessageBuffer /*buffer*/) {\n"
+ " TC_LOG_ERROR(\"service.protobuf\", \"%s Server tried to call server method %u\",\n"
+ " GetCallerInfo().c_str(), methodId);\n"
+ "}\n"
+ "\n");
+ }
}
void BnetServiceGenerator::GenerateClientMethodImplementations(pb::io::Printer* printer)
@@ -177,7 +202,7 @@ void BnetServiceGenerator::GenerateClientMethodImplementations(pb::io::Printer*
if (method->output_type()->name() != "NO_RESPONSE")
{
printer->Print(sub_vars,
- "void $classname$::$name$($input_type$ const* request, std::function<void($output_type$ const*)> responseCallback) {\n"
+ "void $classname$::$name$($input_type$ const* request, std::function<void($output_type$ const*)> responseCallback, bool client /*= false*/, bool server /*= false*/) {\n"
" TC_LOG_DEBUG(\"service.protobuf\", \"%s Server called client method $full_name$($input_type_name${ %s })\",\n"
" GetCallerInfo().c_str(), request->ShortDebugString().c_str());\n"
" std::function<void(MessageBuffer)> callback = [responseCallback](MessageBuffer buffer) -> void {\n"
@@ -185,17 +210,17 @@ void BnetServiceGenerator::GenerateClientMethodImplementations(pb::io::Printer*
" if (response.ParseFromArray(buffer.GetReadPointer(), buffer.GetActiveSize()))\n"
" responseCallback(&response);\n"
" };\n"
- " SendRequest(service_hash_, $method_id$, request, std::move(callback));\n"
+ " SendRequest(service_hash_, $method_id$ | (client ? 0x40000000 : 0) | (server ? 0x80000000 : 0), request, std::move(callback));\n"
"}\n"
"\n");
}
else
{
printer->Print(sub_vars,
- "void $classname$::$name$($input_type$ const* request) {\n"
+ "void $classname$::$name$($input_type$ const* request, bool client /*= false*/, bool server /*= false*/) {\n"
" TC_LOG_DEBUG(\"service.protobuf\", \"%s Server called client method $full_name$($input_type_name${ %s })\",\n"
" GetCallerInfo().c_str(), request->ShortDebugString().c_str());\n"
- " SendRequest(service_hash_, $method_id$, request);\n"
+ " SendRequest(service_hash_, $method_id$ | (client ? 0x40000000 : 0) | (server ? 0x80000000 : 0), request);\n"
"}\n"
"\n");
}
@@ -206,7 +231,7 @@ void BnetServiceGenerator::GenerateServerCallMethod(pb::io::Printer* printer)
{
printer->Print(vars_,
"void $classname$::CallServerMethod(uint32 token, uint32 methodId, MessageBuffer buffer) {\n"
- " switch(methodId) {\n");
+ " switch(methodId & 0x3FFFFFFF) {\n");
for (int i = 0; i < descriptor_->method_count(); i++)
{
@@ -229,7 +254,7 @@ void BnetServiceGenerator::GenerateServerCallMethod(pb::io::Printer* printer)
" $input_type$ request;\n"
" if (!request.ParseFromArray(buffer.GetReadPointer(), buffer.GetActiveSize())) {\n"
" TC_LOG_DEBUG(\"service.protobuf\", \"%s Failed to parse request for $full_name$ server method call.\", GetCallerInfo().c_str());\n"
- " SendResponse(service_hash_, $method_id$, token, ERROR_RPC_MALFORMED_REQUEST);\n"
+ " SendResponse(service_hash_, methodId, token, ERROR_RPC_MALFORMED_REQUEST);\n"
" return;\n"
" }\n"
);
@@ -239,16 +264,16 @@ void BnetServiceGenerator::GenerateServerCallMethod(pb::io::Printer* printer)
printer->Print(sub_vars,
" TC_LOG_DEBUG(\"service.protobuf\", \"%s Client called server method $full_name$($input_type_name${ %s }).\",\n"
" GetCallerInfo().c_str(), request.ShortDebugString().c_str());\n"
- " std::function<void(ServiceBase*, uint32, ::google::protobuf::Message const*)> continuation = [token](ServiceBase* service, uint32 status, ::google::protobuf::Message const* response)\n"
+ " std::function<void(ServiceBase*, uint32, ::google::protobuf::Message const*)> continuation = [token, methodId](ServiceBase* service, uint32 status, ::google::protobuf::Message const* response)\n"
" {\n"
" ASSERT(response->GetDescriptor() == $output_type$::descriptor());\n"
" $classname$* self = static_cast<$classname$*>(service);\n"
" TC_LOG_DEBUG(\"service.protobuf\", \"%s Client called server method $full_name$() returned $output_type_name${ %s } status %u.\",\n"
" self->GetCallerInfo().c_str(), response->ShortDebugString().c_str(), status);\n"
" if (!status)\n"
- " self->SendResponse(self->service_hash_, $method_id$, token, response);\n"
+ " self->SendResponse(self->service_hash_, methodId, token, response);\n"
" else\n"
- " self->SendResponse(self->service_hash_, $method_id$, token, status);\n"
+ " self->SendResponse(self->service_hash_, methodId, token, status);\n"
" };\n"
" $output_type$ response;\n"
" uint32 status = Handle$name$(&request, &response, continuation);\n"
@@ -263,7 +288,7 @@ void BnetServiceGenerator::GenerateServerCallMethod(pb::io::Printer* printer)
" TC_LOG_DEBUG(\"service.protobuf\", \"%s Client called server method $full_name$($input_type_name${ %s }) status %u.\",\n"
" GetCallerInfo().c_str(), request.ShortDebugString().c_str(), status);\n"
" if (status)\n"
- " SendResponse(service_hash_, $method_id$, token, status);\n");
+ " SendResponse(service_hash_, methodId, token, status);\n");
}
printer->Print(sub_vars,
diff --git a/contrib/protoc-bnet/CMakeLists.txt b/contrib/protoc-bnet/CMakeLists.txt
index 77cecaecdb0..1e07a00d140 100644
--- a/contrib/protoc-bnet/CMakeLists.txt
+++ b/contrib/protoc-bnet/CMakeLists.txt
@@ -1,7 +1,7 @@
-cmake_minimum_required(VERSION 3.0)
+cmake_minimum_required(VERSION 3.8)
project(protoc_bnet)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+set(CXX_EXTENSIONS OFF)
find_package(Protobuf REQUIRED)
@@ -19,14 +19,25 @@ set(SOURCE_FILES
include_directories(${CMAKE_SOURCE_DIR} ${PROTOBUF_INCLUDE_DIRS})
add_executable(protoc-gen-bnet ${SOURCE_FILES})
+target_compile_features(protoc-gen-bnet
+ PUBLIC
+ cxx_std_17
+ cxx_alias_templates
+ cxx_auto_type
+ cxx_constexpr
+ cxx_decltype
+ cxx_decltype_auto
+ cxx_final
+ cxx_lambdas
+ cxx_generic_lambdas
+ cxx_variadic_templates
+ cxx_defaulted_functions
+ cxx_nullptr
+ cxx_trailing_return_types
+ cxx_return_type_deduction)
target_link_libraries(protoc-gen-bnet ${PROTOBUF_PROTOC_LIBRARIES} ${PROTOBUF_LIBRARIES})
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR})
-add_custom_target(install_plugin
- make install
- DEPENDS protoc-gen-bnet
- COMMENT "Installing protoc_bnet")
-
install(TARGETS protoc-gen-bnet DESTINATION bin)