• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef NET_GRPC_COMPILER_JAVA_GENERATOR_H_
2 #define NET_GRPC_COMPILER_JAVA_GENERATOR_H_
3 
4 #include <stdlib.h>  // for abort()
5 #include <iostream>
6 #include <string>
7 
8 #include <google/protobuf/io/zero_copy_stream.h>
9 #include <google/protobuf/descriptor.h>
10 
11 class LogHelper {
12   std::ostream* os;
13 
14  public:
LogHelper(std::ostream * os)15   LogHelper(std::ostream* os) : os(os) {}
~LogHelper()16   ~LogHelper() {
17     *os << std::endl;
18     ::abort();
19   }
get_os()20   std::ostream& get_os() {
21     return *os;
22   }
23 };
24 
25 // Abort the program after logging the mesage if the given condition is not
26 // true. Otherwise, do nothing.
27 #define GRPC_CODEGEN_CHECK(x) !(x) && LogHelper(&std::cerr).get_os() \
28                              << "CHECK FAILED: " << __FILE__ << ":" \
29                              << __LINE__ << ": "
30 
31 // Abort the program after logging the mesage.
32 #define GRPC_CODEGEN_FAIL GRPC_CODEGEN_CHECK(false)
33 
34 using namespace std;
35 
36 namespace java_grpc_generator {
37 
38 enum ProtoFlavor {
39   NORMAL, LITE, NANO
40 };
41 
42 // Returns the package name of the gRPC services defined in the given file.
43 string ServiceJavaPackage(const google::protobuf::FileDescriptor* file, bool nano);
44 
45 // Returns the name of the outer class that wraps in all the generated code for
46 // the given service.
47 string ServiceClassName(const google::protobuf::ServiceDescriptor* service);
48 
49 // Writes the generated service interface into the given ZeroCopyOutputStream
50 void GenerateService(const google::protobuf::ServiceDescriptor* service,
51                      google::protobuf::io::ZeroCopyOutputStream* out,
52                      ProtoFlavor flavor,
53                      bool disable_version);
54 
55 }  // namespace java_grpc_generator
56 
57 #endif  // NET_GRPC_COMPILER_JAVA_GENERATOR_H_
58