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_UTILS_H_ 18 #define VTS_COMPILATION_TOOLS_VTSC_CODE_UTILS_H_ 19 20 #include <string> 21 22 #include <hidl-util/FQName.h> 23 24 #include "test/vts/proto/ComponentSpecificationMessage.pb.h" 25 26 using namespace std; 27 28 namespace android { 29 namespace vts { 30 31 // Returns the component class name as a string 32 extern string ComponentClassToString(int component_class); 33 34 // Returns the component type name as a string 35 extern string ComponentTypeToString(int component_type); 36 37 // Returns the C/C++ variable type name of a given data type. 38 extern string GetCppVariableType(const string primitive_type_string); 39 40 // Returns the C/C++ basic variable type name of a given argument. 41 string GetCppVariableType(const VariableSpecificationMessage& arg, 42 bool generate_const = false); 43 44 // Get the C/C++ instance type name of an argument. 45 extern string GetCppInstanceType( 46 const VariableSpecificationMessage& arg, 47 const string& msg = string(), 48 const ComponentSpecificationMessage* message = NULL); 49 50 // Returns the name of a function which can convert the given arg to a protobuf. 51 extern string GetConversionToProtobufFunctionName( 52 VariableSpecificationMessage arg); 53 54 // fs_mkdirs for VTS. 55 extern int vts_fs_mkdirs(char* file_path, mode_t mode); 56 57 // Replace the name space access symbol "::" in the string to "__" to prevent 58 // mis-interpretation in generated cpp code. 59 string ClearStringWithNameSpaceAccess(const string& str); 60 61 // Returns a string which joins the given dir_path and file_name. 62 string PathJoin(const char* dir_path, const char* file_name); 63 64 // Returns a string which remove given base_path from file_path if included. 65 string RemoveBaseDir(const string& file_path, const string& base_path); 66 67 // Get the package name from the message if set. e.g. android.hardware.foo 68 string GetPackageName(const ComponentSpecificationMessage& message); 69 70 // Get the path of package from the message. e.g. android/hardware/for 71 string GetPackagePath(const ComponentSpecificationMessage& message); 72 73 // Get the namespace token of package from the message. 74 // e.g. android::hardware::foo 75 string GetPackageNamespaceToken(const ComponentSpecificationMessage& message); 76 77 // Get component version string from the message. e.g. 1.0 78 // If for_macro = true, return the version string with format like V1_0. 79 std::string GetVersion(const ComponentSpecificationMessage& message, 80 bool for_macro = false); 81 82 // Get component major version from the message. e.g. 1.0 -> 1 83 int GetMajorVersion(const ComponentSpecificationMessage& message); 84 85 // Get component minor version from the message. e.g. 1.0 -> 0 86 int GetMinorVersion(const ComponentSpecificationMessage& message); 87 88 // Get the base name of component from the message. e.g. typs, Foo. 89 std::string GetComponentBaseName(const ComponentSpecificationMessage& message); 90 91 // Get the component name from message,e.g. IFoo, IFooCallback, types etc. 92 string GetComponentName(const ComponentSpecificationMessage& message); 93 94 // Generate the FQName of the given message.. 95 FQName GetFQName(const ComponentSpecificationMessage& message); 96 97 // Generate a plain string from the name of given variable, replace any special 98 // character (non alphabat or digital) with '_' 99 // e.g. msg.test --> msg_test, msg[test] --> msg_test_ 100 string GetVarString(const string& var_name); 101 102 } // namespace vts 103 } // namespace android 104 105 #endif // VTS_COMPILATION_TOOLS_VTSC_CODE_UTILS_H_ 106