• 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_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                           const ComponentSpecificationMessage* message = NULL,
43                           bool generate_const = false,
44                           int var_depth = 0);
45 
46 // Get the C/C++ instance type name of an argument.
47 extern string GetCppInstanceType(
48     const VariableSpecificationMessage& arg,
49     const string& msg = string(),
50     const ComponentSpecificationMessage* message = NULL);
51 
52 // Returns the name of a function which can convert the given arg to a protobuf.
53 extern string GetConversionToProtobufFunctionName(
54     VariableSpecificationMessage arg);
55 
56 // fs_mkdirs for VTS.
57 extern int vts_fs_mkdirs(char* file_path, mode_t mode);
58 
59 // Replace the name space access symbol "::" in the string to "__" to prevent
60 // mis-interpretation in generated cpp code.
61 string ClearStringWithNameSpaceAccess(const string& str);
62 
63 // Returns a string which joins the given dir_path and file_name.
64 string PathJoin(const char* dir_path, const char* file_name);
65 
66 // Returns a string which remove given base_path from file_path if included.
67 string RemoveBaseDir(const string& file_path, const string& base_path);
68 
69 // Get the package name from the message if set. e.g. android.hardware.foo
70 string GetPackageName(const ComponentSpecificationMessage& message);
71 
72 // Get the path of package from the message. e.g. android/hardware/for
73 string GetPackagePath(const ComponentSpecificationMessage& message);
74 
75 // Get the namespace token of package from the message.
76 // e.g. android::hardware::foo
77 string GetPackageNamespaceToken(const ComponentSpecificationMessage& message);
78 
79 // Get component version string from the message. e.g. 1.0
80 // If for_macro = true, return the version string with format like V1_0.
81 std::string GetVersion(const ComponentSpecificationMessage& message,
82                        bool for_macro = false);
83 
84 // Get the base name of component from the message. e.g. typs, Foo.
85 std::string GetComponentBaseName(const ComponentSpecificationMessage& message);
86 
87 // Get the component name from message,e.g. IFoo, IFooCallback, types etc.
88 string GetComponentName(const ComponentSpecificationMessage& message);
89 
90 // Generate the FQName of the given message..
91 FQName GetFQName(const ComponentSpecificationMessage& message);
92 
93 }  // namespace vts
94 }  // namespace android
95 
96 #endif  // VTS_COMPILATION_TOOLS_VTSC_CODE_UTILS_H_
97