1 /* 2 * 3 * Copyright 2015, Google Inc. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * * Redistributions in binary form must reproduce the above 13 * copyright notice, this list of conditions and the following disclaimer 14 * in the documentation and/or other materials provided with the 15 * distribution. 16 * * Neither the name of Google Inc. nor the names of its 17 * contributors may be used to endorse or promote products derived from 18 * this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * 32 */ 33 34 #ifndef GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H 35 #define GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H 36 37 #include <map> 38 #include <memory> 39 #include <vector> 40 41 #ifndef GRPC_CUSTOM_STRING 42 #include <string> 43 #define GRPC_CUSTOM_STRING std::string 44 #endif 45 46 namespace grpc { 47 48 typedef GRPC_CUSTOM_STRING string; 49 50 } // namespace grpc 51 52 namespace grpc_generator { 53 54 // An abstract interface representing a method. 55 struct Method { ~MethodMethod56 virtual ~Method() {} 57 58 virtual grpc::string name() const = 0; 59 60 virtual grpc::string input_type_name() const = 0; 61 virtual grpc::string output_type_name() const = 0; 62 virtual grpc::string input_name() const = 0; 63 virtual grpc::string output_name() const = 0; 64 65 virtual bool NoStreaming() const = 0; 66 virtual bool ClientOnlyStreaming() const = 0; 67 virtual bool ServerOnlyStreaming() const = 0; 68 virtual bool BidiStreaming() const = 0; 69 }; 70 71 // An abstract interface representing a service. 72 struct Service { ~ServiceService73 virtual ~Service() {} 74 75 virtual grpc::string name() const = 0; 76 77 virtual int method_count() const = 0; 78 virtual std::unique_ptr<const Method> method(int i) const = 0; 79 }; 80 81 struct Printer { ~PrinterPrinter82 virtual ~Printer() {} 83 84 virtual void Print(const std::map<grpc::string, grpc::string> &vars, 85 const char *template_string) = 0; 86 virtual void Print(const char *string) = 0; 87 virtual void Indent() = 0; 88 virtual void Outdent() = 0; 89 }; 90 91 // An interface that allows the source generated to be output using various 92 // libraries/idls/serializers. 93 struct File { ~FileFile94 virtual ~File() {} 95 96 virtual grpc::string filename() const = 0; 97 virtual grpc::string filename_without_ext() const = 0; 98 virtual grpc::string message_header_ext() const = 0; 99 virtual grpc::string service_header_ext() const = 0; 100 virtual grpc::string package() const = 0; 101 virtual std::vector<grpc::string> package_parts() const = 0; 102 virtual grpc::string additional_headers() const = 0; 103 virtual grpc::string additional_imports() const = 0; 104 105 virtual int service_count() const = 0; 106 virtual std::unique_ptr<const Service> service(int i) const = 0; 107 108 virtual std::unique_ptr<Printer> CreatePrinter(grpc::string *str) const = 0; 109 }; 110 } // namespace grpc_generator 111 112 #endif // GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H 113