| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216 | 
							- /*
 
-  *
 
-  * Copyright 2015, Google Inc.
 
-  * All rights reserved.
 
-  *
 
-  * Redistribution and use in source and binary forms, with or without
 
-  * modification, are permitted provided that the following conditions are
 
-  * met:
 
-  *
 
-  *     * Redistributions of source code must retain the above copyright
 
-  * notice, this list of conditions and the following disclaimer.
 
-  *     * Redistributions in binary form must reproduce the above
 
-  * copyright notice, this list of conditions and the following disclaimer
 
-  * in the documentation and/or other materials provided with the
 
-  * distribution.
 
-  *     * Neither the name of Google Inc. nor the names of its
 
-  * contributors may be used to endorse or promote products derived from
 
-  * this software without specific prior written permission.
 
-  *
 
-  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
-  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
-  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
-  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
-  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
-  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
-  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
-  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
-  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
-  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
-  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-  *
 
-  */
 
- #include <map>
 
- #include "src/compiler/cpp_generator.h"
 
- #include <sstream>
 
- namespace grpc_cpp_generator {
 
- namespace {
 
- template <class T>
 
- grpc::string as_string(T x) {
 
-   std::ostringstream out;
 
-   out << x;
 
-   return out.str();
 
- }
 
- grpc::string FilenameIdentifier(const grpc::string &filename) {
 
-   grpc::string result;
 
-   for (unsigned i = 0; i < filename.size(); i++) {
 
-     char c = filename[i];
 
-     if (isalnum(c)) {
 
-       result.push_back(c);
 
-     } else {
 
-       static char hex[] = "0123456789abcdef";
 
-       result.push_back('_');
 
-       result.push_back(hex[(c >> 4) & 0xf]);
 
-       result.push_back(hex[c & 0xf]);
 
-     }
 
-   }
 
-   return result;
 
- }
 
- }  // namespace
 
- template<class T, size_t N>
 
- T *array_end(T (&array)[N]) { return array + N; }
 
- void PrintIncludes(Printer *printer, const std::vector<grpc::string>& headers, const Parameters ¶ms) {
 
-   std::map<grpc::string, grpc::string> vars;
 
-   vars["l"] = params.use_system_headers ? '<' : '"';
 
-   vars["r"] = params.use_system_headers ? '>' : '"';
 
-   if (!params.grpc_search_path.empty()) {
 
-     vars["l"] += params.grpc_search_path;
 
-     if (params.grpc_search_path.back() != '/') {
 
-       vars["l"] += '/';
 
-     }
 
-   }
 
-   for (auto i = headers.begin(); i != headers.end(); i++) {
 
-     vars["h"] = *i;
 
-     printer->Print(vars, "#include $l$$h$$r$\n");
 
-   }
 
- }
 
- grpc::string GetHeaderPrologue(File *file, const Parameters & /*params*/) {
 
-   grpc::string output;
 
-   {
 
-     // Scope the output stream so it closes and finalizes output to the string.
 
-     auto printer = file->CreatePrinter(&output);
 
-     std::map<grpc::string, grpc::string> vars;
 
-     vars["filename"] = file->filename();
 
-     vars["filename_identifier"] = FilenameIdentifier(file->filename());
 
-     vars["filename_base"] = file->filename_without_ext();
 
-     vars["message_header_ext"] = file->message_header_ext();
 
-     printer->Print(vars, "// Generated by the gRPC protobuf plugin.\n");
 
-     printer->Print(vars,
 
-                   "// If you make any local change, they will be lost.\n");
 
-     printer->Print(vars, "// source: $filename$\n");
 
-     grpc::string leading_comments = file->GetLeadingComments();
 
-     if (!leading_comments.empty()) {
 
-       printer->Print(vars, "// Original file comments:\n");
 
-       printer->Print(leading_comments.c_str());
 
-     }
 
-     printer->Print(vars, "#ifndef GRPC_$filename_identifier$__INCLUDED\n");
 
-     printer->Print(vars, "#define GRPC_$filename_identifier$__INCLUDED\n");
 
-     printer->Print(vars, "\n");
 
-     printer->Print(vars, "#include \"$filename_base$$message_header_ext$\"\n");
 
-     printer->Print(vars, "\n");
 
-   }
 
-   return output;
 
- }
 
- grpc::string GetHeaderIncludes(File *file,
 
-                                const Parameters ¶ms) {
 
-   grpc::string output;
 
-   {
 
-     // Scope the output stream so it closes and finalizes output to the string.
 
-     auto printer = file->CreatePrinter(&output);
 
-     std::map<grpc::string, grpc::string> vars;
 
-     static const char *headers_strs[] = {
 
-       "grpc++/impl/codegen/async_stream.h",
 
-       "grpc++/impl/codegen/async_unary_call.h",
 
-       "grpc++/impl/codegen/proto_utils.h",
 
-       "grpc++/impl/codegen/rpc_method.h",
 
-       "grpc++/impl/codegen/service_type.h",
 
-       "grpc++/impl/codegen/status.h",
 
-       "grpc++/impl/codegen/stub_options.h",
 
-       "grpc++/impl/codegen/sync_stream.h"
 
-     };
 
-     std::vector<grpc::string> headers(headers_strs, array_end(headers_strs));
 
-     PrintIncludes(printer.get(), headers, params);
 
-     printer->Print(vars, "\n");
 
-     printer->Print(vars, "namespace grpc {\n");
 
-     printer->Print(vars, "class CompletionQueue;\n");
 
-     printer->Print(vars, "class Channel;\n");
 
-     printer->Print(vars, "class RpcService;\n");
 
-     printer->Print(vars, "class ServerCompletionQueue;\n");
 
-     printer->Print(vars, "class ServerContext;\n");
 
-     printer->Print(vars, "}  // namespace grpc\n\n");
 
-     if (!file->package().empty()) {
 
-       std::vector<grpc::string> parts = file->package_parts();
 
-       for (auto part = parts.begin(); part != parts.end(); part++) {
 
-         vars["part"] = *part;
 
-         printer->Print(vars, "namespace $part$ {\n");
 
-       }
 
-       printer->Print(vars, "\n");
 
-     }
 
-   }
 
-   return output;
 
- }
 
- void PrintHeaderClientMethodInterfaces(
 
-     Printer *printer, const Method *method,
 
-     std::map<grpc::string, grpc::string> *vars, bool is_public) {
 
-   (*vars)["Method"] = method->name();
 
-   (*vars)["Request"] = method->input_type_name();
 
-   (*vars)["Response"] = method->output_type_name();
 
-   if (is_public) {
 
-     if (method->NoStreaming()) {
 
-       printer->Print(
 
-           *vars,
 
-           "virtual ::grpc::Status $Method$(::grpc::ClientContext* context, "
 
-           "const $Request$& request, $Response$* response) = 0;\n");
 
-       printer->Print(*vars,
 
-                      "std::unique_ptr< "
 
-                      "::grpc::ClientAsyncResponseReaderInterface< $Response$>> "
 
-                      "Async$Method$(::grpc::ClientContext* context, "
 
-                      "const $Request$& request, "
 
-                      "::grpc::CompletionQueue* cq) {\n");
 
-       printer->Indent();
 
-       printer->Print(*vars,
 
-                      "return std::unique_ptr< "
 
-                      "::grpc::ClientAsyncResponseReaderInterface< $Response$>>("
 
-                      "Async$Method$Raw(context, request, cq));\n");
 
-       printer->Outdent();
 
-       printer->Print("}\n");
 
-     } else if (method->ClientOnlyStreaming()) {
 
-       printer->Print(
 
-           *vars,
 
-           "std::unique_ptr< ::grpc::ClientWriterInterface< $Request$>>"
 
-           " $Method$("
 
-           "::grpc::ClientContext* context, $Response$* response) {\n");
 
-       printer->Indent();
 
-       printer->Print(
 
-           *vars,
 
-           "return std::unique_ptr< ::grpc::ClientWriterInterface< $Request$>>"
 
-           "($Method$Raw(context, response));\n");
 
-       printer->Outdent();
 
-       printer->Print("}\n");
 
-       printer->Print(
 
-           *vars,
 
-           "std::unique_ptr< ::grpc::ClientAsyncWriterInterface< $Request$>>"
 
-           " Async$Method$(::grpc::ClientContext* context, $Response$* "
 
-           "response, "
 
-           "::grpc::CompletionQueue* cq, void* tag) {\n");
 
-       printer->Indent();
 
-       printer->Print(*vars,
 
-                      "return std::unique_ptr< "
 
-                      "::grpc::ClientAsyncWriterInterface< $Request$>>("
 
-                      "Async$Method$Raw(context, response, cq, tag));\n");
 
-       printer->Outdent();
 
-       printer->Print("}\n");
 
-     } else if (method->ServerOnlyStreaming()) {
 
-       printer->Print(
 
-           *vars,
 
-           "std::unique_ptr< ::grpc::ClientReaderInterface< $Response$>>"
 
-           " $Method$(::grpc::ClientContext* context, const $Request$& request)"
 
-           " {\n");
 
-       printer->Indent();
 
-       printer->Print(
 
-           *vars,
 
-           "return std::unique_ptr< ::grpc::ClientReaderInterface< $Response$>>"
 
-           "($Method$Raw(context, request));\n");
 
-       printer->Outdent();
 
-       printer->Print("}\n");
 
-       printer->Print(
 
-           *vars,
 
-           "std::unique_ptr< ::grpc::ClientAsyncReaderInterface< $Response$>> "
 
-           "Async$Method$("
 
-           "::grpc::ClientContext* context, const $Request$& request, "
 
-           "::grpc::CompletionQueue* cq, void* tag) {\n");
 
-       printer->Indent();
 
-       printer->Print(*vars,
 
-                      "return std::unique_ptr< "
 
-                      "::grpc::ClientAsyncReaderInterface< $Response$>>("
 
-                      "Async$Method$Raw(context, request, cq, tag));\n");
 
-       printer->Outdent();
 
-       printer->Print("}\n");
 
-     } else if (method->BidiStreaming()) {
 
-       printer->Print(*vars,
 
-                      "std::unique_ptr< ::grpc::ClientReaderWriterInterface< "
 
-                      "$Request$, $Response$>> "
 
-                      "$Method$(::grpc::ClientContext* context) {\n");
 
-       printer->Indent();
 
-       printer->Print(
 
-           *vars,
 
-           "return std::unique_ptr< "
 
-           "::grpc::ClientReaderWriterInterface< $Request$, $Response$>>("
 
-           "$Method$Raw(context));\n");
 
-       printer->Outdent();
 
-       printer->Print("}\n");
 
-       printer->Print(
 
-           *vars,
 
-           "std::unique_ptr< "
 
-           "::grpc::ClientAsyncReaderWriterInterface< $Request$, $Response$>> "
 
-           "Async$Method$(::grpc::ClientContext* context, "
 
-           "::grpc::CompletionQueue* cq, void* tag) {\n");
 
-       printer->Indent();
 
-       printer->Print(
 
-           *vars,
 
-           "return std::unique_ptr< "
 
-           "::grpc::ClientAsyncReaderWriterInterface< $Request$, $Response$>>("
 
-           "Async$Method$Raw(context, cq, tag));\n");
 
-       printer->Outdent();
 
-       printer->Print("}\n");
 
-     }
 
-   } else {
 
-     if (method->NoStreaming()) {
 
-       printer->Print(
 
-           *vars,
 
-           "virtual ::grpc::ClientAsyncResponseReaderInterface< $Response$>* "
 
-           "Async$Method$Raw(::grpc::ClientContext* context, "
 
-           "const $Request$& request, "
 
-           "::grpc::CompletionQueue* cq) = 0;\n");
 
-     } else if (method->ClientOnlyStreaming()) {
 
-       printer->Print(
 
-           *vars,
 
-           "virtual ::grpc::ClientWriterInterface< $Request$>*"
 
-           " $Method$Raw("
 
-           "::grpc::ClientContext* context, $Response$* response) = 0;\n");
 
-       printer->Print(*vars,
 
-                      "virtual ::grpc::ClientAsyncWriterInterface< $Request$>*"
 
-                      " Async$Method$Raw(::grpc::ClientContext* context, "
 
-                      "$Response$* response, "
 
-                      "::grpc::CompletionQueue* cq, void* tag) = 0;\n");
 
-     } else if (method->ServerOnlyStreaming()) {
 
-       printer->Print(
 
-           *vars,
 
-           "virtual ::grpc::ClientReaderInterface< $Response$>* $Method$Raw("
 
-           "::grpc::ClientContext* context, const $Request$& request) = 0;\n");
 
-       printer->Print(
 
-           *vars,
 
-           "virtual ::grpc::ClientAsyncReaderInterface< $Response$>* "
 
-           "Async$Method$Raw("
 
-           "::grpc::ClientContext* context, const $Request$& request, "
 
-           "::grpc::CompletionQueue* cq, void* tag) = 0;\n");
 
-     } else if (method->BidiStreaming()) {
 
-       printer->Print(*vars,
 
-                      "virtual ::grpc::ClientReaderWriterInterface< $Request$, "
 
-                      "$Response$>* "
 
-                      "$Method$Raw(::grpc::ClientContext* context) = 0;\n");
 
-       printer->Print(*vars,
 
-                      "virtual ::grpc::ClientAsyncReaderWriterInterface< "
 
-                      "$Request$, $Response$>* "
 
-                      "Async$Method$Raw(::grpc::ClientContext* context, "
 
-                      "::grpc::CompletionQueue* cq, void* tag) = 0;\n");
 
-     }
 
-   }
 
- }
 
- void PrintHeaderClientMethod(Printer *printer,
 
-                              const Method *method,
 
-                              std::map<grpc::string, grpc::string> *vars,
 
-                              bool is_public) {
 
-   (*vars)["Method"] = method->name();
 
-   (*vars)["Request"] = method->input_type_name();
 
-   (*vars)["Response"] = method->output_type_name();
 
-   if (is_public) {
 
-     if (method->NoStreaming()) {
 
-       printer->Print(
 
-           *vars,
 
-           "::grpc::Status $Method$(::grpc::ClientContext* context, "
 
-           "const $Request$& request, $Response$* response) GRPC_OVERRIDE;\n");
 
-       printer->Print(
 
-           *vars,
 
-           "std::unique_ptr< ::grpc::ClientAsyncResponseReader< $Response$>> "
 
-           "Async$Method$(::grpc::ClientContext* context, "
 
-           "const $Request$& request, "
 
-           "::grpc::CompletionQueue* cq) {\n");
 
-       printer->Indent();
 
-       printer->Print(*vars,
 
-                      "return std::unique_ptr< "
 
-                      "::grpc::ClientAsyncResponseReader< $Response$>>("
 
-                      "Async$Method$Raw(context, request, cq));\n");
 
-       printer->Outdent();
 
-       printer->Print("}\n");
 
-     } else if (method->ClientOnlyStreaming()) {
 
-       printer->Print(
 
-           *vars,
 
-           "std::unique_ptr< ::grpc::ClientWriter< $Request$>>"
 
-           " $Method$("
 
-           "::grpc::ClientContext* context, $Response$* response) {\n");
 
-       printer->Indent();
 
-       printer->Print(*vars,
 
-                      "return std::unique_ptr< ::grpc::ClientWriter< $Request$>>"
 
-                      "($Method$Raw(context, response));\n");
 
-       printer->Outdent();
 
-       printer->Print("}\n");
 
-       printer->Print(*vars,
 
-                      "std::unique_ptr< ::grpc::ClientAsyncWriter< $Request$>>"
 
-                      " Async$Method$(::grpc::ClientContext* context, "
 
-                      "$Response$* response, "
 
-                      "::grpc::CompletionQueue* cq, void* tag) {\n");
 
-       printer->Indent();
 
-       printer->Print(
 
-           *vars,
 
-           "return std::unique_ptr< ::grpc::ClientAsyncWriter< $Request$>>("
 
-           "Async$Method$Raw(context, response, cq, tag));\n");
 
-       printer->Outdent();
 
-       printer->Print("}\n");
 
-     } else if (method->ServerOnlyStreaming()) {
 
-       printer->Print(
 
-           *vars,
 
-           "std::unique_ptr< ::grpc::ClientReader< $Response$>>"
 
-           " $Method$(::grpc::ClientContext* context, const $Request$& request)"
 
-           " {\n");
 
-       printer->Indent();
 
-       printer->Print(
 
-           *vars,
 
-           "return std::unique_ptr< ::grpc::ClientReader< $Response$>>"
 
-           "($Method$Raw(context, request));\n");
 
-       printer->Outdent();
 
-       printer->Print("}\n");
 
-       printer->Print(
 
-           *vars,
 
-           "std::unique_ptr< ::grpc::ClientAsyncReader< $Response$>> "
 
-           "Async$Method$("
 
-           "::grpc::ClientContext* context, const $Request$& request, "
 
-           "::grpc::CompletionQueue* cq, void* tag) {\n");
 
-       printer->Indent();
 
-       printer->Print(
 
-           *vars,
 
-           "return std::unique_ptr< ::grpc::ClientAsyncReader< $Response$>>("
 
-           "Async$Method$Raw(context, request, cq, tag));\n");
 
-       printer->Outdent();
 
-       printer->Print("}\n");
 
-     } else if (method->BidiStreaming()) {
 
-       printer->Print(
 
-           *vars,
 
-           "std::unique_ptr< ::grpc::ClientReaderWriter< $Request$, $Response$>>"
 
-           " $Method$(::grpc::ClientContext* context) {\n");
 
-       printer->Indent();
 
-       printer->Print(*vars,
 
-                      "return std::unique_ptr< "
 
-                      "::grpc::ClientReaderWriter< $Request$, $Response$>>("
 
-                      "$Method$Raw(context));\n");
 
-       printer->Outdent();
 
-       printer->Print("}\n");
 
-       printer->Print(*vars,
 
-                      "std::unique_ptr<  ::grpc::ClientAsyncReaderWriter< "
 
-                      "$Request$, $Response$>> "
 
-                      "Async$Method$(::grpc::ClientContext* context, "
 
-                      "::grpc::CompletionQueue* cq, void* tag) {\n");
 
-       printer->Indent();
 
-       printer->Print(*vars,
 
-                      "return std::unique_ptr< "
 
-                      "::grpc::ClientAsyncReaderWriter< $Request$, $Response$>>("
 
-                      "Async$Method$Raw(context, cq, tag));\n");
 
-       printer->Outdent();
 
-       printer->Print("}\n");
 
-     }
 
-   } else {
 
-     if (method->NoStreaming()) {
 
-       printer->Print(*vars,
 
-                      "::grpc::ClientAsyncResponseReader< $Response$>* "
 
-                      "Async$Method$Raw(::grpc::ClientContext* context, "
 
-                      "const $Request$& request, "
 
-                      "::grpc::CompletionQueue* cq) GRPC_OVERRIDE;\n");
 
-     } else if (method->ClientOnlyStreaming()) {
 
-       printer->Print(*vars,
 
-                      "::grpc::ClientWriter< $Request$>* $Method$Raw("
 
-                      "::grpc::ClientContext* context, $Response$* response) "
 
-                      "GRPC_OVERRIDE;\n");
 
-       printer->Print(
 
-           *vars,
 
-           "::grpc::ClientAsyncWriter< $Request$>* Async$Method$Raw("
 
-           "::grpc::ClientContext* context, $Response$* response, "
 
-           "::grpc::CompletionQueue* cq, void* tag) GRPC_OVERRIDE;\n");
 
-     } else if (method->ServerOnlyStreaming()) {
 
-       printer->Print(*vars,
 
-                      "::grpc::ClientReader< $Response$>* $Method$Raw("
 
-                      "::grpc::ClientContext* context, const $Request$& request)"
 
-                      " GRPC_OVERRIDE;\n");
 
-       printer->Print(
 
-           *vars,
 
-           "::grpc::ClientAsyncReader< $Response$>* Async$Method$Raw("
 
-           "::grpc::ClientContext* context, const $Request$& request, "
 
-           "::grpc::CompletionQueue* cq, void* tag) GRPC_OVERRIDE;\n");
 
-     } else if (method->BidiStreaming()) {
 
-       printer->Print(
 
-           *vars,
 
-           "::grpc::ClientReaderWriter< $Request$, $Response$>* "
 
-           "$Method$Raw(::grpc::ClientContext* context) GRPC_OVERRIDE;\n");
 
-       printer->Print(
 
-           *vars,
 
-           "::grpc::ClientAsyncReaderWriter< $Request$, $Response$>* "
 
-           "Async$Method$Raw(::grpc::ClientContext* context, "
 
-           "::grpc::CompletionQueue* cq, void* tag) GRPC_OVERRIDE;\n");
 
-     }
 
-   }
 
- }
 
- void PrintHeaderClientMethodData(Printer *printer, const Method *method,
 
-                                  std::map<grpc::string, grpc::string> *vars) {
 
-   (*vars)["Method"] = method->name();
 
-   printer->Print(*vars, "const ::grpc::RpcMethod rpcmethod_$Method$_;\n");
 
- }
 
- void PrintHeaderServerMethodSync(Printer *printer, const Method *method,
 
-                                  std::map<grpc::string, grpc::string> *vars) {
 
-   (*vars)["Method"] = method->name();
 
-   (*vars)["Request"] = method->input_type_name();
 
-   (*vars)["Response"] = method->output_type_name();
 
-   printer->Print(method->GetLeadingComments().c_str());
 
-   if (method->NoStreaming()) {
 
-     printer->Print(*vars,
 
-                    "virtual ::grpc::Status $Method$("
 
-                    "::grpc::ServerContext* context, const $Request$* request, "
 
-                    "$Response$* response);\n");
 
-   } else if (method->ClientOnlyStreaming()) {
 
-     printer->Print(*vars,
 
-                    "virtual ::grpc::Status $Method$("
 
-                    "::grpc::ServerContext* context, "
 
-                    "::grpc::ServerReader< $Request$>* reader, "
 
-                    "$Response$* response);\n");
 
-   } else if (method->ServerOnlyStreaming()) {
 
-     printer->Print(*vars,
 
-                    "virtual ::grpc::Status $Method$("
 
-                    "::grpc::ServerContext* context, const $Request$* request, "
 
-                    "::grpc::ServerWriter< $Response$>* writer);\n");
 
-   } else if (method->BidiStreaming()) {
 
-     printer->Print(
 
-         *vars,
 
-         "virtual ::grpc::Status $Method$("
 
-         "::grpc::ServerContext* context, "
 
-         "::grpc::ServerReaderWriter< $Response$, $Request$>* stream);"
 
-         "\n");
 
-   }
 
-   printer->Print(method->GetTrailingComments().c_str());
 
- }
 
- void PrintHeaderServerMethodAsync(
 
-     Printer *printer,
 
-     const Method *method,
 
-     std::map<grpc::string, grpc::string> *vars) {
 
-   (*vars)["Method"] = method->name();
 
-   (*vars)["Request"] = method->input_type_name();
 
-   (*vars)["Response"] = method->output_type_name();
 
-   printer->Print(*vars, "template <class BaseClass>\n");
 
-   printer->Print(*vars,
 
-                  "class WithAsyncMethod_$Method$ : public BaseClass {\n");
 
-   printer->Print(
 
-       " private:\n"
 
-       "  void BaseClassMustBeDerivedFromService(const Service *service) {}\n");
 
-   printer->Print(" public:\n");
 
-   printer->Indent();
 
-   printer->Print(*vars,
 
-                  "WithAsyncMethod_$Method$() {\n"
 
-                  "  ::grpc::Service::MarkMethodAsync($Idx$);\n"
 
-                  "}\n");
 
-   printer->Print(*vars,
 
-                  "~WithAsyncMethod_$Method$() GRPC_OVERRIDE {\n"
 
-                  "  BaseClassMustBeDerivedFromService(this);\n"
 
-                  "}\n");
 
-   if (method->NoStreaming()) {
 
-     printer->Print(
 
-         *vars,
 
-         "// disable synchronous version of this method\n"
 
-         "::grpc::Status $Method$("
 
-         "::grpc::ServerContext* context, const $Request$* request, "
 
-         "$Response$* response) GRPC_FINAL GRPC_OVERRIDE {\n"
 
-         "  abort();\n"
 
-         "  return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
 
-         "}\n");
 
-     printer->Print(
 
-         *vars,
 
-         "void Request$Method$("
 
-         "::grpc::ServerContext* context, $Request$* request, "
 
-         "::grpc::ServerAsyncResponseWriter< $Response$>* response, "
 
-         "::grpc::CompletionQueue* new_call_cq, "
 
-         "::grpc::ServerCompletionQueue* notification_cq, void *tag) {\n");
 
-     printer->Print(*vars,
 
-                    "  ::grpc::Service::RequestAsyncUnary($Idx$, context, "
 
-                    "request, response, new_call_cq, notification_cq, tag);\n");
 
-     printer->Print("}\n");
 
-   } else if (method->ClientOnlyStreaming()) {
 
-     printer->Print(
 
-         *vars,
 
-         "// disable synchronous version of this method\n"
 
-         "::grpc::Status $Method$("
 
-         "::grpc::ServerContext* context, "
 
-         "::grpc::ServerReader< $Request$>* reader, "
 
-         "$Response$* response) GRPC_FINAL GRPC_OVERRIDE {\n"
 
-         "  abort();\n"
 
-         "  return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
 
-         "}\n");
 
-     printer->Print(
 
-         *vars,
 
-         "void Request$Method$("
 
-         "::grpc::ServerContext* context, "
 
-         "::grpc::ServerAsyncReader< $Response$, $Request$>* reader, "
 
-         "::grpc::CompletionQueue* new_call_cq, "
 
-         "::grpc::ServerCompletionQueue* notification_cq, void *tag) {\n");
 
-     printer->Print(*vars,
 
-                    "  ::grpc::Service::RequestAsyncClientStreaming($Idx$, "
 
-                    "context, reader, new_call_cq, notification_cq, tag);\n");
 
-     printer->Print("}\n");
 
-   } else if (method->ServerOnlyStreaming()) {
 
-     printer->Print(
 
-         *vars,
 
-         "// disable synchronous version of this method\n"
 
-         "::grpc::Status $Method$("
 
-         "::grpc::ServerContext* context, const $Request$* request, "
 
-         "::grpc::ServerWriter< $Response$>* writer) GRPC_FINAL GRPC_OVERRIDE "
 
-         "{\n"
 
-         "  abort();\n"
 
-         "  return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
 
-         "}\n");
 
-     printer->Print(
 
-         *vars,
 
-         "void Request$Method$("
 
-         "::grpc::ServerContext* context, $Request$* request, "
 
-         "::grpc::ServerAsyncWriter< $Response$>* writer, "
 
-         "::grpc::CompletionQueue* new_call_cq, "
 
-         "::grpc::ServerCompletionQueue* notification_cq, void *tag) {\n");
 
-     printer->Print(
 
-         *vars,
 
-         "  ::grpc::Service::RequestAsyncServerStreaming($Idx$, "
 
-         "context, request, writer, new_call_cq, notification_cq, tag);\n");
 
-     printer->Print("}\n");
 
-   } else if (method->BidiStreaming()) {
 
-     printer->Print(
 
-         *vars,
 
-         "// disable synchronous version of this method\n"
 
-         "::grpc::Status $Method$("
 
-         "::grpc::ServerContext* context, "
 
-         "::grpc::ServerReaderWriter< $Response$, $Request$>* stream) "
 
-         "GRPC_FINAL GRPC_OVERRIDE {\n"
 
-         "  abort();\n"
 
-         "  return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
 
-         "}\n");
 
-     printer->Print(
 
-         *vars,
 
-         "void Request$Method$("
 
-         "::grpc::ServerContext* context, "
 
-         "::grpc::ServerAsyncReaderWriter< $Response$, $Request$>* stream, "
 
-         "::grpc::CompletionQueue* new_call_cq, "
 
-         "::grpc::ServerCompletionQueue* notification_cq, void *tag) {\n");
 
-     printer->Print(*vars,
 
-                    "  ::grpc::Service::RequestAsyncBidiStreaming($Idx$, "
 
-                    "context, stream, new_call_cq, notification_cq, tag);\n");
 
-     printer->Print("}\n");
 
-   }
 
-   printer->Outdent();
 
-   printer->Print(*vars, "};\n");
 
- }
 
- void PrintHeaderServerMethodGeneric(
 
-     Printer *printer,
 
-     const Method *method,
 
-     std::map<grpc::string, grpc::string> *vars) {
 
-   (*vars)["Method"] = method->name();
 
-   (*vars)["Request"] = method->input_type_name();
 
-   (*vars)["Response"] = method->output_type_name();
 
-   printer->Print(*vars, "template <class BaseClass>\n");
 
-   printer->Print(*vars,
 
-                  "class WithGenericMethod_$Method$ : public BaseClass {\n");
 
-   printer->Print(
 
-       " private:\n"
 
-       "  void BaseClassMustBeDerivedFromService(const Service *service) {}\n");
 
-   printer->Print(" public:\n");
 
-   printer->Indent();
 
-   printer->Print(*vars,
 
-                  "WithGenericMethod_$Method$() {\n"
 
-                  "  ::grpc::Service::MarkMethodGeneric($Idx$);\n"
 
-                  "}\n");
 
-   printer->Print(*vars,
 
-                  "~WithGenericMethod_$Method$() GRPC_OVERRIDE {\n"
 
-                  "  BaseClassMustBeDerivedFromService(this);\n"
 
-                  "}\n");
 
-   if (method->NoStreaming()) {
 
-     printer->Print(
 
-         *vars,
 
-         "// disable synchronous version of this method\n"
 
-         "::grpc::Status $Method$("
 
-         "::grpc::ServerContext* context, const $Request$* request, "
 
-         "$Response$* response) GRPC_FINAL GRPC_OVERRIDE {\n"
 
-         "  abort();\n"
 
-         "  return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
 
-         "}\n");
 
-   } else if (method->ClientOnlyStreaming()) {
 
-     printer->Print(
 
-         *vars,
 
-         "// disable synchronous version of this method\n"
 
-         "::grpc::Status $Method$("
 
-         "::grpc::ServerContext* context, "
 
-         "::grpc::ServerReader< $Request$>* reader, "
 
-         "$Response$* response) GRPC_FINAL GRPC_OVERRIDE {\n"
 
-         "  abort();\n"
 
-         "  return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
 
-         "}\n");
 
-   } else if (method->ServerOnlyStreaming()) {
 
-     printer->Print(
 
-         *vars,
 
-         "// disable synchronous version of this method\n"
 
-         "::grpc::Status $Method$("
 
-         "::grpc::ServerContext* context, const $Request$* request, "
 
-         "::grpc::ServerWriter< $Response$>* writer) GRPC_FINAL GRPC_OVERRIDE "
 
-         "{\n"
 
-         "  abort();\n"
 
-         "  return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
 
-         "}\n");
 
-   } else if (method->BidiStreaming()) {
 
-     printer->Print(
 
-         *vars,
 
-         "// disable synchronous version of this method\n"
 
-         "::grpc::Status $Method$("
 
-         "::grpc::ServerContext* context, "
 
-         "::grpc::ServerReaderWriter< $Response$, $Request$>* stream) "
 
-         "GRPC_FINAL GRPC_OVERRIDE {\n"
 
-         "  abort();\n"
 
-         "  return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
 
-         "}\n");
 
-   }
 
-   printer->Outdent();
 
-   printer->Print(*vars, "};\n");
 
- }
 
- void PrintHeaderService(Printer *printer,
 
-                         const Service *service,
 
-                         std::map<grpc::string, grpc::string> *vars) {
 
-   (*vars)["Service"] = service->name();
 
-   printer->Print(service->GetLeadingComments().c_str());
 
-   printer->Print(*vars,
 
-                  "class $Service$ GRPC_FINAL {\n"
 
-                  " public:\n");
 
-   printer->Indent();
 
-   // Client side
 
-   printer->Print(
 
-       "class StubInterface {\n"
 
-       " public:\n");
 
-   printer->Indent();
 
-   printer->Print("virtual ~StubInterface() {}\n");
 
-   for (int i = 0; i < service->method_count(); ++i) {
 
-     printer->Print(service->method(i)->GetLeadingComments().c_str());
 
-     PrintHeaderClientMethodInterfaces(printer, service->method(i).get(), vars, true);
 
-     printer->Print(service->method(i)->GetTrailingComments().c_str());
 
-   }
 
-   printer->Outdent();
 
-   printer->Print("private:\n");
 
-   printer->Indent();
 
-   for (int i = 0; i < service->method_count(); ++i) {
 
-     PrintHeaderClientMethodInterfaces(printer, service->method(i).get(), vars, false);
 
-   }
 
-   printer->Outdent();
 
-   printer->Print("};\n");
 
-   printer->Print(
 
-       "class Stub GRPC_FINAL : public StubInterface"
 
-       " {\n public:\n");
 
-   printer->Indent();
 
-   printer->Print("Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel);\n");
 
-   for (int i = 0; i < service->method_count(); ++i) {
 
-     PrintHeaderClientMethod(printer, service->method(i).get(), vars, true);
 
-   }
 
-   printer->Outdent();
 
-   printer->Print("\n private:\n");
 
-   printer->Indent();
 
-   printer->Print("std::shared_ptr< ::grpc::ChannelInterface> channel_;\n");
 
-   for (int i = 0; i < service->method_count(); ++i) {
 
-     PrintHeaderClientMethod(printer, service->method(i).get(), vars, false);
 
-   }
 
-   for (int i = 0; i < service->method_count(); ++i) {
 
-     PrintHeaderClientMethodData(printer, service->method(i).get(), vars);
 
-   }
 
-   printer->Outdent();
 
-   printer->Print("};\n");
 
-   printer->Print(
 
-       "static std::unique_ptr<Stub> NewStub(const std::shared_ptr< "
 
-       "::grpc::ChannelInterface>& channel, "
 
-       "const ::grpc::StubOptions& options = ::grpc::StubOptions());\n");
 
-   printer->Print("\n");
 
-   // Server side - base
 
-   printer->Print(
 
-       "class Service : public ::grpc::Service {\n"
 
-       " public:\n");
 
-   printer->Indent();
 
-   printer->Print("Service();\n");
 
-   printer->Print("virtual ~Service();\n");
 
-   for (int i = 0; i < service->method_count(); ++i) {
 
-     PrintHeaderServerMethodSync(printer, service->method(i).get(), vars);
 
-   }
 
-   printer->Outdent();
 
-   printer->Print("};\n");
 
-   // Server side - Asynchronous
 
-   for (int i = 0; i < service->method_count(); ++i) {
 
-     (*vars)["Idx"] = as_string(i);
 
-     PrintHeaderServerMethodAsync(printer, service->method(i).get(), vars);
 
-   }
 
-   printer->Print("typedef ");
 
-   for (int i = 0; i < service->method_count(); ++i) {
 
-     (*vars)["method_name"] = service->method(i).get()->name();
 
-     printer->Print(*vars, "WithAsyncMethod_$method_name$<");
 
-   }
 
-   printer->Print("Service");
 
-   for (int i = 0; i < service->method_count(); ++i) {
 
-     printer->Print(" >");
 
-   }
 
-   printer->Print(" AsyncService;\n");
 
-   // Server side - Generic
 
-   for (int i = 0; i < service->method_count(); ++i) {
 
-     (*vars)["Idx"] = as_string(i);
 
-     PrintHeaderServerMethodGeneric(printer, service->method(i).get(), vars);
 
-   }
 
-   printer->Outdent();
 
-   printer->Print("};\n");
 
-   printer->Print(service->GetTrailingComments().c_str());
 
- }
 
- grpc::string GetHeaderServices(File *file,
 
-                                const Parameters ¶ms) {
 
-   grpc::string output;
 
-   {
 
-     // Scope the output stream so it closes and finalizes output to the string.
 
-     auto printer = file->CreatePrinter(&output);
 
-     std::map<grpc::string, grpc::string> vars;
 
-     // Package string is empty or ends with a dot. It is used to fully qualify
 
-     // method names.
 
-     vars["Package"] = file->package();
 
-     if (!file->package().empty()) {
 
-       vars["Package"].append(".");
 
-     }
 
-     if (!params.services_namespace.empty()) {
 
-       vars["services_namespace"] = params.services_namespace;
 
-       printer->Print(vars, "\nnamespace $services_namespace$ {\n\n");
 
-     }
 
-     for (int i = 0; i < file->service_count(); ++i) {
 
-       PrintHeaderService(printer.get(), file->service(i).get(), &vars);
 
-       printer->Print("\n");
 
-     }
 
-     if (!params.services_namespace.empty()) {
 
-       printer->Print(vars, "}  // namespace $services_namespace$\n\n");
 
-     }
 
-   }
 
-   return output;
 
- }
 
- grpc::string GetHeaderEpilogue(File *file, const Parameters & /*params*/) {
 
-   grpc::string output;
 
-   {
 
-     // Scope the output stream so it closes and finalizes output to the string.
 
-     auto printer = file->CreatePrinter(&output);
 
-     std::map<grpc::string, grpc::string> vars;
 
-     vars["filename"] = file->filename();
 
-     vars["filename_identifier"] = FilenameIdentifier(file->filename());
 
-     if (!file->package().empty()) {
 
-       std::vector<grpc::string> parts = file->package_parts();
 
-       for (auto part = parts.rbegin(); part != parts.rend(); part++) {
 
-         vars["part"] = *part;
 
-         printer->Print(vars, "}  // namespace $part$\n");
 
-       }
 
-       printer->Print(vars, "\n");
 
-     }
 
-     printer->Print(vars, "\n");
 
-     printer->Print(vars, "#endif  // GRPC_$filename_identifier$__INCLUDED\n");
 
-     printer->Print(file->GetTrailingComments().c_str());
 
-   }
 
-   return output;
 
- }
 
- grpc::string GetSourcePrologue(File *file, const Parameters & /*params*/) {
 
-   grpc::string output;
 
-   {
 
-     // Scope the output stream so it closes and finalizes output to the string.
 
-     auto printer = file->CreatePrinter(&output);
 
-     std::map<grpc::string, grpc::string> vars;
 
-     vars["filename"] = file->filename();
 
-     vars["filename_base"] = file->filename_without_ext();
 
-     vars["message_header_ext"] = file->message_header_ext();
 
-     vars["service_header_ext"] = file->service_header_ext();
 
-     printer->Print(vars, "// Generated by the gRPC protobuf plugin.\n");
 
-     printer->Print(vars,
 
-                   "// If you make any local change, they will be lost.\n");
 
-     printer->Print(vars, "// source: $filename$\n\n");
 
-     printer->Print(vars, "#include \"$filename_base$$message_header_ext$\"\n");
 
-     printer->Print(vars, "#include \"$filename_base$$service_header_ext$\"\n");
 
-     printer->Print(vars, file->additional_headers().c_str());
 
-     printer->Print(vars, "\n");
 
-   }
 
-   return output;
 
- }
 
- grpc::string GetSourceIncludes(File *file,
 
-                                const Parameters ¶ms) {
 
-   grpc::string output;
 
-   {
 
-     // Scope the output stream so it closes and finalizes output to the string.
 
-     auto printer = file->CreatePrinter(&output);
 
-     std::map<grpc::string, grpc::string> vars;
 
-     static const char *headers_strs[] = {
 
-       "grpc++/impl/codegen/async_stream.h",
 
-       "grpc++/impl/codegen/async_unary_call.h",
 
-       "grpc++/impl/codegen/channel_interface.h",
 
-       "grpc++/impl/codegen/client_unary_call.h",
 
-       "grpc++/impl/codegen/method_handler_impl.h",
 
-       "grpc++/impl/codegen/rpc_service_method.h",
 
-       "grpc++/impl/codegen/service_type.h",
 
-       "grpc++/impl/codegen/sync_stream.h"
 
-     };
 
-     std::vector<grpc::string> headers(headers_strs, array_end(headers_strs));
 
-     PrintIncludes(printer.get(), headers, params);
 
-     if (!file->package().empty()) {
 
-       std::vector<grpc::string> parts = file->package_parts();
 
-       for (auto part = parts.begin(); part != parts.end(); part++) {
 
-         vars["part"] = *part;
 
-         printer->Print(vars, "namespace $part$ {\n");
 
-       }
 
-     }
 
-     printer->Print(vars, "\n");
 
-   }
 
-   return output;
 
- }
 
- void PrintSourceClientMethod(Printer *printer,
 
-                              const Method *method,
 
-                              std::map<grpc::string, grpc::string> *vars) {
 
-   (*vars)["Method"] = method->name();
 
-   (*vars)["Request"] = method->input_type_name();
 
-   (*vars)["Response"] = method->output_type_name();
 
-   if (method->NoStreaming()) {
 
-     printer->Print(*vars,
 
-                    "::grpc::Status $ns$$Service$::Stub::$Method$("
 
-                    "::grpc::ClientContext* context, "
 
-                    "const $Request$& request, $Response$* response) {\n");
 
-     printer->Print(*vars,
 
-                    "  return ::grpc::BlockingUnaryCall(channel_.get(), "
 
-                    "rpcmethod_$Method$_, "
 
-                    "context, request, response);\n"
 
-                    "}\n\n");
 
-     printer->Print(
 
-         *vars,
 
-         "::grpc::ClientAsyncResponseReader< $Response$>* "
 
-         "$ns$$Service$::Stub::Async$Method$Raw(::grpc::ClientContext* context, "
 
-         "const $Request$& request, "
 
-         "::grpc::CompletionQueue* cq) {\n");
 
-     printer->Print(*vars,
 
-                    "  return new "
 
-                    "::grpc::ClientAsyncResponseReader< $Response$>("
 
-                    "channel_.get(), cq, "
 
-                    "rpcmethod_$Method$_, "
 
-                    "context, request);\n"
 
-                    "}\n\n");
 
-   } else if (method->ClientOnlyStreaming()) {
 
-     printer->Print(*vars,
 
-                    "::grpc::ClientWriter< $Request$>* "
 
-                    "$ns$$Service$::Stub::$Method$Raw("
 
-                    "::grpc::ClientContext* context, $Response$* response) {\n");
 
-     printer->Print(*vars,
 
-                    "  return new ::grpc::ClientWriter< $Request$>("
 
-                    "channel_.get(), "
 
-                    "rpcmethod_$Method$_, "
 
-                    "context, response);\n"
 
-                    "}\n\n");
 
-     printer->Print(*vars,
 
-                    "::grpc::ClientAsyncWriter< $Request$>* "
 
-                    "$ns$$Service$::Stub::Async$Method$Raw("
 
-                    "::grpc::ClientContext* context, $Response$* response, "
 
-                    "::grpc::CompletionQueue* cq, void* tag) {\n");
 
-     printer->Print(*vars,
 
-                    "  return new ::grpc::ClientAsyncWriter< $Request$>("
 
-                    "channel_.get(), cq, "
 
-                    "rpcmethod_$Method$_, "
 
-                    "context, response, tag);\n"
 
-                    "}\n\n");
 
-   } else if (method->ServerOnlyStreaming()) {
 
-     printer->Print(
 
-         *vars,
 
-         "::grpc::ClientReader< $Response$>* "
 
-         "$ns$$Service$::Stub::$Method$Raw("
 
-         "::grpc::ClientContext* context, const $Request$& request) {\n");
 
-     printer->Print(*vars,
 
-                    "  return new ::grpc::ClientReader< $Response$>("
 
-                    "channel_.get(), "
 
-                    "rpcmethod_$Method$_, "
 
-                    "context, request);\n"
 
-                    "}\n\n");
 
-     printer->Print(*vars,
 
-                    "::grpc::ClientAsyncReader< $Response$>* "
 
-                    "$ns$$Service$::Stub::Async$Method$Raw("
 
-                    "::grpc::ClientContext* context, const $Request$& request, "
 
-                    "::grpc::CompletionQueue* cq, void* tag) {\n");
 
-     printer->Print(*vars,
 
-                    "  return new ::grpc::ClientAsyncReader< $Response$>("
 
-                    "channel_.get(), cq, "
 
-                    "rpcmethod_$Method$_, "
 
-                    "context, request, tag);\n"
 
-                    "}\n\n");
 
-   } else if (method->BidiStreaming()) {
 
-     printer->Print(
 
-         *vars,
 
-         "::grpc::ClientReaderWriter< $Request$, $Response$>* "
 
-         "$ns$$Service$::Stub::$Method$Raw(::grpc::ClientContext* context) {\n");
 
-     printer->Print(*vars,
 
-                    "  return new ::grpc::ClientReaderWriter< "
 
-                    "$Request$, $Response$>("
 
-                    "channel_.get(), "
 
-                    "rpcmethod_$Method$_, "
 
-                    "context);\n"
 
-                    "}\n\n");
 
-     printer->Print(
 
-         *vars,
 
-         "::grpc::ClientAsyncReaderWriter< $Request$, $Response$>* "
 
-         "$ns$$Service$::Stub::Async$Method$Raw(::grpc::ClientContext* context, "
 
-         "::grpc::CompletionQueue* cq, void* tag) {\n");
 
-     printer->Print(*vars,
 
-                    "  return new "
 
-                    "::grpc::ClientAsyncReaderWriter< $Request$, $Response$>("
 
-                    "channel_.get(), cq, "
 
-                    "rpcmethod_$Method$_, "
 
-                    "context, tag);\n"
 
-                    "}\n\n");
 
-   }
 
- }
 
- void PrintSourceServerMethod(Printer *printer,
 
-                              const Method *method,
 
-                              std::map<grpc::string, grpc::string> *vars) {
 
-   (*vars)["Method"] = method->name();
 
-   (*vars)["Request"] = method->input_type_name();
 
-   (*vars)["Response"] = method->output_type_name();
 
-   if (method->NoStreaming()) {
 
-     printer->Print(*vars,
 
-                    "::grpc::Status $ns$$Service$::Service::$Method$("
 
-                    "::grpc::ServerContext* context, "
 
-                    "const $Request$* request, $Response$* response) {\n");
 
-     printer->Print("  (void) context;\n");
 
-     printer->Print("  (void) request;\n");
 
-     printer->Print("  (void) response;\n");
 
-     printer->Print(
 
-         "  return ::grpc::Status("
 
-         "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n");
 
-     printer->Print("}\n\n");
 
-   } else if (method->ClientOnlyStreaming()) {
 
-     printer->Print(*vars,
 
-                    "::grpc::Status $ns$$Service$::Service::$Method$("
 
-                    "::grpc::ServerContext* context, "
 
-                    "::grpc::ServerReader< $Request$>* reader, "
 
-                    "$Response$* response) {\n");
 
-     printer->Print("  (void) context;\n");
 
-     printer->Print("  (void) reader;\n");
 
-     printer->Print("  (void) response;\n");
 
-     printer->Print(
 
-         "  return ::grpc::Status("
 
-         "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n");
 
-     printer->Print("}\n\n");
 
-   } else if (method->ServerOnlyStreaming()) {
 
-     printer->Print(*vars,
 
-                    "::grpc::Status $ns$$Service$::Service::$Method$("
 
-                    "::grpc::ServerContext* context, "
 
-                    "const $Request$* request, "
 
-                    "::grpc::ServerWriter< $Response$>* writer) {\n");
 
-     printer->Print("  (void) context;\n");
 
-     printer->Print("  (void) request;\n");
 
-     printer->Print("  (void) writer;\n");
 
-     printer->Print(
 
-         "  return ::grpc::Status("
 
-         "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n");
 
-     printer->Print("}\n\n");
 
-   } else if (method->BidiStreaming()) {
 
-     printer->Print(*vars,
 
-                    "::grpc::Status $ns$$Service$::Service::$Method$("
 
-                    "::grpc::ServerContext* context, "
 
-                    "::grpc::ServerReaderWriter< $Response$, $Request$>* "
 
-                    "stream) {\n");
 
-     printer->Print("  (void) context;\n");
 
-     printer->Print("  (void) stream;\n");
 
-     printer->Print(
 
-         "  return ::grpc::Status("
 
-         "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n");
 
-     printer->Print("}\n\n");
 
-   }
 
- }
 
- void PrintSourceService(Printer *printer,
 
-                         const Service *service,
 
-                         std::map<grpc::string, grpc::string> *vars) {
 
-   (*vars)["Service"] = service->name();
 
-   printer->Print(*vars,
 
-                  "static const char* $prefix$$Service$_method_names[] = {\n");
 
-   for (int i = 0; i < service->method_count(); ++i) {
 
-     (*vars)["Method"] = service->method(i).get()->name();
 
-     printer->Print(*vars, "  \"/$Package$$Service$/$Method$\",\n");
 
-   }
 
-   printer->Print(*vars, "};\n\n");
 
-   printer->Print(*vars,
 
-                  "std::unique_ptr< $ns$$Service$::Stub> $ns$$Service$::NewStub("
 
-                  "const std::shared_ptr< ::grpc::ChannelInterface>& channel, "
 
-                  "const ::grpc::StubOptions& options) {\n"
 
-                  "  std::unique_ptr< $ns$$Service$::Stub> stub(new "
 
-                  "$ns$$Service$::Stub(channel));\n"
 
-                  "  return stub;\n"
 
-                  "}\n\n");
 
-   printer->Print(*vars,
 
-                  "$ns$$Service$::Stub::Stub(const std::shared_ptr< "
 
-                  "::grpc::ChannelInterface>& channel)\n");
 
-   printer->Indent();
 
-   printer->Print(": channel_(channel)");
 
-   for (int i = 0; i < service->method_count(); ++i) {
 
-     auto method = service->method(i);
 
-     (*vars)["Method"] = method->name();
 
-     (*vars)["Idx"] = as_string(i);
 
-     if (method->NoStreaming()) {
 
-       (*vars)["StreamingType"] = "NORMAL_RPC";
 
-     } else if (method->ClientOnlyStreaming()) {
 
-       (*vars)["StreamingType"] = "CLIENT_STREAMING";
 
-     } else if (method->ServerOnlyStreaming()) {
 
-       (*vars)["StreamingType"] = "SERVER_STREAMING";
 
-     } else {
 
-       (*vars)["StreamingType"] = "BIDI_STREAMING";
 
-     }
 
-     printer->Print(*vars,
 
-                    ", rpcmethod_$Method$_("
 
-                    "$prefix$$Service$_method_names[$Idx$], "
 
-                    "::grpc::RpcMethod::$StreamingType$, "
 
-                    "channel"
 
-                    ")\n");
 
-   }
 
-   printer->Print("{}\n\n");
 
-   printer->Outdent();
 
-   for (int i = 0; i < service->method_count(); ++i) {
 
-     (*vars)["Idx"] = as_string(i);
 
-     PrintSourceClientMethod(printer, service->method(i).get(), vars);
 
-   }
 
-   printer->Print(*vars, "$ns$$Service$::Service::Service() {\n");
 
-   printer->Indent();
 
-   printer->Print(*vars, "(void)$prefix$$Service$_method_names;\n");
 
-   for (int i = 0; i < service->method_count(); ++i) {
 
-     auto method = service->method(i);
 
-     (*vars)["Idx"] = as_string(i);
 
-     (*vars)["Method"] = method->name();
 
-     (*vars)["Request"] = method->input_type_name();
 
-     (*vars)["Response"] = method->output_type_name();
 
-     if (method->NoStreaming()) {
 
-       printer->Print(
 
-           *vars,
 
-           "AddMethod(new ::grpc::RpcServiceMethod(\n"
 
-           "    $prefix$$Service$_method_names[$Idx$],\n"
 
-           "    ::grpc::RpcMethod::NORMAL_RPC,\n"
 
-           "    new ::grpc::RpcMethodHandler< $ns$$Service$::Service, "
 
-           "$Request$, "
 
-           "$Response$>(\n"
 
-           "        std::mem_fn(&$ns$$Service$::Service::$Method$), this)));\n");
 
-     } else if (method->ClientOnlyStreaming()) {
 
-       printer->Print(
 
-           *vars,
 
-           "AddMethod(new ::grpc::RpcServiceMethod(\n"
 
-           "    $prefix$$Service$_method_names[$Idx$],\n"
 
-           "    ::grpc::RpcMethod::CLIENT_STREAMING,\n"
 
-           "    new ::grpc::ClientStreamingHandler< "
 
-           "$ns$$Service$::Service, $Request$, $Response$>(\n"
 
-           "        std::mem_fn(&$ns$$Service$::Service::$Method$), this)));\n");
 
-     } else if (method->ServerOnlyStreaming()) {
 
-       printer->Print(
 
-           *vars,
 
-           "AddMethod(new ::grpc::RpcServiceMethod(\n"
 
-           "    $prefix$$Service$_method_names[$Idx$],\n"
 
-           "    ::grpc::RpcMethod::SERVER_STREAMING,\n"
 
-           "    new ::grpc::ServerStreamingHandler< "
 
-           "$ns$$Service$::Service, $Request$, $Response$>(\n"
 
-           "        std::mem_fn(&$ns$$Service$::Service::$Method$), this)));\n");
 
-     } else if (method->BidiStreaming()) {
 
-       printer->Print(
 
-           *vars,
 
-           "AddMethod(new ::grpc::RpcServiceMethod(\n"
 
-           "    $prefix$$Service$_method_names[$Idx$],\n"
 
-           "    ::grpc::RpcMethod::BIDI_STREAMING,\n"
 
-           "    new ::grpc::BidiStreamingHandler< "
 
-           "$ns$$Service$::Service, $Request$, $Response$>(\n"
 
-           "        std::mem_fn(&$ns$$Service$::Service::$Method$), this)));\n");
 
-     }
 
-   }
 
-   printer->Outdent();
 
-   printer->Print(*vars, "}\n\n");
 
-   printer->Print(*vars,
 
-                  "$ns$$Service$::Service::~Service() {\n"
 
-                  "}\n\n");
 
-   for (int i = 0; i < service->method_count(); ++i) {
 
-     (*vars)["Idx"] = as_string(i);
 
-     PrintSourceServerMethod(printer, service->method(i).get(), vars);
 
-   }
 
- }
 
- grpc::string GetSourceServices(File *file,
 
-                                const Parameters ¶ms) {
 
-   grpc::string output;
 
-   {
 
-     // Scope the output stream so it closes and finalizes output to the string.
 
-     auto printer = file->CreatePrinter(&output);
 
-     std::map<grpc::string, grpc::string> vars;
 
-     // Package string is empty or ends with a dot. It is used to fully qualify
 
-     // method names.
 
-     vars["Package"] = file->package();
 
-     if (!file->package().empty()) {
 
-       vars["Package"].append(".");
 
-     }
 
-     if (!params.services_namespace.empty()) {
 
-       vars["ns"] = params.services_namespace + "::";
 
-       vars["prefix"] = params.services_namespace;
 
-     } else {
 
-       vars["ns"] = "";
 
-       vars["prefix"] = "";
 
-     }
 
-     for (int i = 0; i < file->service_count(); ++i) {
 
-       PrintSourceService(printer.get(), file->service(i).get(), &vars);
 
-       printer->Print("\n");
 
-     }
 
-   }
 
-   return output;
 
- }
 
- grpc::string GetSourceEpilogue(File *file, const Parameters & /*params*/) {
 
-   grpc::string temp;
 
-   if (!file->package().empty()) {
 
-     std::vector<grpc::string> parts = file->package_parts();
 
-     for (auto part = parts.begin(); part != parts.end(); part++) {
 
-       temp.append("}  // namespace ");
 
-       temp.append(*part);
 
-       temp.append("\n");
 
-     }
 
-     temp.append("\n");
 
-   }
 
-   return temp;
 
- }
 
- }  // namespace grpc_cpp_generator
 
 
  |