• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef VTS_COMPILATION_TOOLS_VTSC_CODE_GEN_CODEGENBASE_H_
18 #define VTS_COMPILATION_TOOLS_VTSC_CODE_GEN_CODEGENBASE_H_
19 
20 #include <hidl-util/Formatter.h>
21 #include <iostream>
22 #include <sstream>
23 #include <string>
24 
25 #include "test/vts/proto/ComponentSpecificationMessage.pb.h"
26 
27 using namespace std;
28 
29 namespace android {
30 namespace vts {
31 
32 enum VtsCompileMode {
33   kDriver = 0,
34   kProfiler,
35   kFuzzer
36 };
37 
38 // Specifies what kinds of files to generate.
39 enum VtsCompileFileType {
40   kBoth = 0,
41   kHeader,
42   kSource,
43 };
44 
45 class CodeGenBase {
46  public:
47   explicit CodeGenBase(const char* input_vts_file_path);
48   virtual ~CodeGenBase();
49 
50   // Generate both a C/C++ file and its header file.
51   virtual void GenerateAll(Formatter& header_out, Formatter& source_out,
52                            const ComponentSpecificationMessage& message) = 0;
53 
54   // Generates source file.
55   virtual void GenerateSourceFile(
56       Formatter& out, const ComponentSpecificationMessage& message) = 0;
57 
58   // Generates header file.
59   virtual void GenerateHeaderFile(
60       Formatter& out, const ComponentSpecificationMessage& message) = 0;
61 
input_vts_file_path()62   const char* input_vts_file_path() const {
63     return input_vts_file_path_;
64   }
65 
66  protected:
67   const char* input_vts_file_path_;
68 };
69 
70 // TODO(zhuoyao): move these methods to util files.
71 // Translates the VTS proto file to C/C++ code and header files.
72 void Translate(VtsCompileMode mode,
73                const char* input_vts_file_path,
74                const char* output_header_dir_path,
75                const char* output_cpp_file_path);
76 
77 
78 // Translates the VTS proto file to a C/C++ source or header file.
79 void TranslateToFile(VtsCompileMode mode,
80                      const char* input_vts_file_path,
81                      const char* output_file_path,
82                      VtsCompileFileType file_type);
83 
84 }  // namespace vts
85 }  // namespace android
86 
87 #endif  // VTS_COMPILATION_TOOLS_VTSC_CODE_GEN_CODEGENBASE_H_
88