1/*
2 *
3 * Copyright 2015 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19#ifndef GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
20#define GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
21
22// cpp_generator.h/.cc do not directly depend on GRPC/ProtoBuf, such that they
23// can be used to generate code for other serialization systems, such as
24// FlatBuffers.
25
26#include <memory>
27#include <vector>
28
29#include "src/compiler/config.h"
30#include "src/compiler/schema_interface.h"
31
32#ifndef GRPC_CUSTOM_STRING
33#include <string>
34#define GRPC_CUSTOM_STRING std::string
35#endif
36
37namespace grpc {
38
39typedef GRPC_CUSTOM_STRING string;
40
41} // namespace grpc
42
43namespace grpc_cpp_generator {
44
45// Contains all the parameters that are parsed from the command line.
46struct Parameters {
47 // Puts the service into a namespace
48 grpc::string services_namespace;
49 // Use system includes (<>) or local includes ("")
50 bool use_system_headers;
51 // Prefix to any grpc include
52 grpc::string grpc_search_path;
53 // Generate Google Mock code to facilitate unit testing.
54 bool generate_mock_code;
55 // Google Mock search path, when non-empty, local includes will be used.
56 grpc::string gmock_search_path;
57 // *EXPERIMENTAL* Additional include files in grpc.pb.h
58 std::vector<grpc::string> additional_header_includes;
59 // By default, use "pb.h"
60 grpc::string message_header_extension;
61 // Whether to include headers corresponding to imports in source file.
62 bool include_import_headers;
63};
64
65// Return the prologue of the generated header file.
66grpc::string GetHeaderPrologue(grpc_generator::File* file,
67 const Parameters& params);
68
69// Return the includes needed for generated header file.
70grpc::string GetHeaderIncludes(grpc_generator::File* file,
71 const Parameters& params);
72
73// Return the includes needed for generated source file.
74grpc::string GetSourceIncludes(grpc_generator::File* file,
75 const Parameters& params);
76
77// Return the epilogue of the generated header file.
78grpc::string GetHeaderEpilogue(grpc_generator::File* file,
79 const Parameters& params);
80
81// Return the prologue of the generated source file.
82grpc::string GetSourcePrologue(grpc_generator::File* file,
83 const Parameters& params);
84
85// Return the services for generated header file.
86grpc::string GetHeaderServices(grpc_generator::File* file,
87 const Parameters& params);
88
89// Return the services for generated source file.
90grpc::string GetSourceServices(grpc_generator::File* file,
91 const Parameters& params);
92
93// Return the epilogue of the generated source file.
94grpc::string GetSourceEpilogue(grpc_generator::File* file,
95 const Parameters& params);
96
97// Return the prologue of the generated mock file.
98grpc::string GetMockPrologue(grpc_generator::File* file,
99 const Parameters& params);
100
101// Return the includes needed for generated mock file.
102grpc::string GetMockIncludes(grpc_generator::File* file,
103 const Parameters& params);
104
105// Return the services for generated mock file.
106grpc::string GetMockServices(grpc_generator::File* file,
107 const Parameters& params);
108
109// Return the epilogue of generated mock file.
110grpc::string GetMockEpilogue(grpc_generator::File* file,
111 const Parameters& params);
112
113// Return the prologue of the generated mock file.
114grpc::string GetMockPrologue(grpc_generator::File* file,
115 const Parameters& params);
116
117// Return the includes needed for generated mock file.
118grpc::string GetMockIncludes(grpc_generator::File* file,
119 const Parameters& params);
120
121// Return the services for generated mock file.
122grpc::string GetMockServices(grpc_generator::File* file,
123 const Parameters& params);
124
125// Return the epilogue of generated mock file.
126grpc::string GetMockEpilogue(grpc_generator::File* file,
127 const Parameters& params);
128
129} // namespace grpc_cpp_generator
130
131#endif // GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
132