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