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