• 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_PROFILER_PROFILERCODEGENBASE_H_
18 #define VTS_COMPILATION_TOOLS_VTSC_CODE_GEN_PROFILER_PROFILERCODEGENBASE_H_
19 
20 #include <hidl-util/Formatter.h>
21 #include <hidl-util/FQName.h>
22 #include <iostream>
23 #include <string>
24 
25 #include "test/vts/proto/ComponentSpecificationMessage.pb.h"
26 
27 namespace android {
28 namespace vts {
29 /**
30  * Base class that generates the profiler code for HAL interfaces.
31  * It takes the input of a vts proto (i.e. ComponentSpecificationMessage) and
32  * generates the header and source file of the corresponding profiler.
33  *
34  * All the profiler generator for a particular HAL type (e.g. Hidl Hal,
35  * Legacy Hal etc.) should derive from this class.
36  */
37 class ProfilerCodeGenBase {
38  public:
39   ProfilerCodeGenBase(const std::string& input_vts_file_path);
40 
41   virtual ~ProfilerCodeGenBase();
42 
43   // Generates both the header and source file for profiler.
44   void GenerateAll(Formatter& header_out, Formatter& source_out,
45     const ComponentSpecificationMessage& message);
46 
47   // Generates the header file for profiler.
48   virtual void GenerateHeaderFile(Formatter &out,
49     const ComponentSpecificationMessage &message);
50 
51   // Generates the source file for profiler.
52   virtual void GenerateSourceFile(Formatter &out,
53     const ComponentSpecificationMessage &message);
54 
55  protected:
56   // Generates the profiler code for scalar type.
57   virtual void GenerateProfilerForScalarVariable(Formatter& out,
58     const VariableSpecificationMessage& val, const std::string& arg_name,
59     const std::string& arg_value) = 0;
60 
61   // Generates the profiler code for string type.
62   virtual void GenerateProfilerForStringVariable(Formatter& out,
63     const VariableSpecificationMessage& val, const std::string& arg_name,
64     const std::string& arg_value) = 0;
65 
66   // Generates the profiler code for enum type.
67   virtual void GenerateProfilerForEnumVariable(Formatter& out,
68     const VariableSpecificationMessage& val, const std::string& arg_name,
69     const std::string& arg_value) = 0;
70 
71   // Generates the profiler code for vector type.
72   virtual void GenerateProfilerForVectorVariable(Formatter& out,
73     const VariableSpecificationMessage& val, const std::string& arg_name,
74     const std::string& arg_value) = 0;
75 
76   // Generates the profiler code for array type.
77   virtual void GenerateProfilerForArrayVariable(Formatter& out,
78     const VariableSpecificationMessage& val, const std::string& arg_name,
79     const std::string& arg_value) = 0;
80 
81   // Generates the profiler code for struct type.
82   virtual void GenerateProfilerForStructVariable(Formatter& out,
83     const VariableSpecificationMessage& val, const std::string& arg_name,
84     const std::string& arg_value) = 0;
85 
86   // Generates the profiler code for union type.
87   virtual void GenerateProfilerForUnionVariable(Formatter& out,
88     const VariableSpecificationMessage& val, const std::string& arg_name,
89     const std::string& arg_value) = 0;
90 
91   // Generates the profiler code for hidl callback type.
92   virtual void GenerateProfilerForHidlCallbackVariable(Formatter& out,
93       const VariableSpecificationMessage& val, const std::string& arg_name,
94       const std::string& arg_value) = 0;
95 
96   // Generates the profiler code for hidl interface type.
97   virtual void GenerateProfilerForHidlInterfaceVariable(Formatter& out,
98       const VariableSpecificationMessage& val, const std::string& arg_name,
99       const std::string& arg_value) = 0;
100 
101   // Generates the profiler code for mask type.
102     virtual void GenerateProfilerForMaskVariable(Formatter& out,
103         const VariableSpecificationMessage& val, const std::string& arg_name,
104         const std::string& arg_value) = 0;
105 
106   // Generates the profiler code for hidl memory type.
107   virtual void GenerateProfilerForHidlMemoryVariable(Formatter& out,
108       const VariableSpecificationMessage& val, const std::string& arg_name,
109       const std::string& arg_value) = 0;
110 
111   // Generates the profiler code for pointer type.
112   virtual void GenerateProfilerForPointerVariable(Formatter& out,
113       const VariableSpecificationMessage& val, const std::string& arg_name,
114       const std::string& arg_value) = 0;
115 
116   // Generates the profiler code for fmq sync type.
117   virtual void GenerateProfilerForFMQSyncVariable(Formatter& out,
118       const VariableSpecificationMessage& val, const std::string& arg_name,
119       const std::string& arg_value) = 0;
120 
121   // Generates the profiler code for fmq unsync type.
122   virtual void GenerateProfilerForFMQUnsyncVariable(Formatter& out,
123       const VariableSpecificationMessage& val, const std::string& arg_name,
124       const std::string& arg_value) = 0;
125 
126   // Generates the profiler code for method.
127   virtual void GenerateProfilerForMethod(Formatter& out,
128     const FunctionSpecificationMessage& method) = 0;
129 
130   // Generates the necessary "#include" code for header file of profiler.
131   virtual void GenerateHeaderIncludeFiles(Formatter& out,
132     const ComponentSpecificationMessage& message) = 0;
133   // Generates the necessary "#include" code for source file of profiler.
134   virtual void GenerateSourceIncludeFiles(Formatter& out,
135     const ComponentSpecificationMessage& message) = 0;
136   // Generates the necessary "using" code for profiler.
137   virtual void GenerateUsingDeclaration(Formatter& out,
138     const ComponentSpecificationMessage& message) = 0;
139   // Generates the necessary "#define" code for profiler.
GenerateMacros(Formatter &,const ComponentSpecificationMessage &)140   virtual void GenerateMacros(Formatter&,
141       const ComponentSpecificationMessage&) {};
142   // Generates sanity check for profiler. These codes will be generated at the
143   // beginning of the main profiler function.
GenerateProfierSanityCheck(Formatter &,const ComponentSpecificationMessage &)144   virtual void GenerateProfierSanityCheck(Formatter&,
145     const ComponentSpecificationMessage&) {};
146   // Generate local variable definition. These codes will be generated after
147   // the sanity check code.
GenerateLocalVariableDefinition(Formatter &,const ComponentSpecificationMessage &)148   virtual void GenerateLocalVariableDefinition(Formatter&,
149     const ComponentSpecificationMessage&) {};
150 
151   // Generates the profiler code for a typed variable.
152   virtual void GenerateProfilerForTypedVariable(Formatter& out,
153     const VariableSpecificationMessage& val, const std::string& arg_name,
154     const std::string& arg_value);
155 
156   // Generates the profiler method declaration for a user defined type.
157   // (e.g. attributes within an interface).
158   // The method signature is:
159   // void profile__UDTName(VariableSpecificationMessage* arg_name,
160   //                       UDTName arg_val_name);
161   virtual void GenerateProfilerMethodDeclForAttribute(Formatter& out,
162     const VariableSpecificationMessage& attribute);
163 
164   // Generates the profiler method implementation for a user defined type.
165   virtual void GenerateProfilerMethodImplForAttribute(Formatter& out,
166     const VariableSpecificationMessage& attribute);
167 
168   //**********   Utility functions   *****************
169   virtual void GenerateOpenNameSpaces(Formatter& out,
170       const ComponentSpecificationMessage& message);
171   virtual void GenerateCloseNameSpaces(Formatter& out,
172       const ComponentSpecificationMessage& message);
173   std::string GetPackage(const ComponentSpecificationMessage& message);
174   std::string GetPackageVersion(const ComponentSpecificationMessage& message);
175   std::string GetComponentName(const ComponentSpecificationMessage& message);
176 
177   std::string input_vts_file_path_;
178   DISALLOW_COPY_AND_ASSIGN (ProfilerCodeGenBase);
179 };
180 
181 }  // namespace vts
182 }  // namespace android
183 
184 #endif  // VTS_COMPILATION_TOOLS_VTSC_CODE_GEN_PROFILER_PROFILERCODEGENBASE_H_
185