| Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017, 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 ANDROID_STATS_LOG_API_GEN_COLLATION_H |
| 18 | #define ANDROID_STATS_LOG_API_GEN_COLLATION_H |
| 19 | |
| 20 | |
| 21 | #include <google/protobuf/descriptor.h> |
| 22 | |
| 23 | #include <set> |
| 24 | #include <vector> |
| Stefan Lafon | 9478f35 | 2017-10-30 21:20:20 -0700 | [diff] [blame] | 25 | #include <map> |
| Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | namespace stats_log_api_gen { |
| 29 | |
| Stefan Lafon | 9478f35 | 2017-10-30 21:20:20 -0700 | [diff] [blame] | 30 | using std::map; |
| Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 31 | using std::set; |
| 32 | using std::string; |
| 33 | using std::vector; |
| 34 | using google::protobuf::Descriptor; |
| Yangster-mac | ba5b9e4 | 2018-01-10 21:31:59 -0800 | [diff] [blame] | 35 | using google::protobuf::FieldDescriptor; |
| Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * The types for atom parameters. |
| 39 | */ |
| 40 | typedef enum { |
| Yangster-mac | 7604aea | 2017-12-11 22:55:49 -0800 | [diff] [blame] | 41 | JAVA_TYPE_UNKNOWN = 0, |
| Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 42 | |
| Yangster-mac | 7604aea | 2017-12-11 22:55:49 -0800 | [diff] [blame] | 43 | JAVA_TYPE_ATTRIBUTION_CHAIN = 1, |
| 44 | JAVA_TYPE_BOOLEAN = 2, |
| 45 | JAVA_TYPE_INT = 3, |
| 46 | JAVA_TYPE_LONG = 4, |
| 47 | JAVA_TYPE_FLOAT = 5, |
| 48 | JAVA_TYPE_DOUBLE = 6, |
| 49 | JAVA_TYPE_STRING = 7, |
| 50 | JAVA_TYPE_ENUM = 8, |
| Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 51 | |
| Yangster-mac | 7604aea | 2017-12-11 22:55:49 -0800 | [diff] [blame] | 52 | JAVA_TYPE_OBJECT = -1, |
| 53 | JAVA_TYPE_BYTE_ARRAY = -2, |
| Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 54 | } java_type_t; |
| 55 | |
| Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 56 | /** |
| 57 | * The name and type for an atom field. |
| 58 | */ |
| 59 | struct AtomField { |
| 60 | string name; |
| 61 | java_type_t javaType; |
| 62 | |
| Stefan Lafon | 9478f35 | 2017-10-30 21:20:20 -0700 | [diff] [blame] | 63 | // If the field is of type enum, the following map contains the list of enum values. |
| 64 | map<int /* numeric value */, string /* value name */> enumValues; |
| 65 | |
| Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 66 | inline AtomField() :name(), javaType(JAVA_TYPE_UNKNOWN) {} |
| Stefan Lafon | 9478f35 | 2017-10-30 21:20:20 -0700 | [diff] [blame] | 67 | inline AtomField(const AtomField& that) :name(that.name), |
| 68 | javaType(that.javaType), |
| 69 | enumValues(that.enumValues) {} |
| Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 70 | inline AtomField(string n, java_type_t jt) :name(n), javaType(jt) {} |
| 71 | inline ~AtomField() {} |
| 72 | }; |
| 73 | |
| 74 | /** |
| 75 | * The name and code for an atom. |
| 76 | */ |
| 77 | struct AtomDecl { |
| 78 | int code; |
| 79 | string name; |
| 80 | |
| 81 | string message; |
| 82 | vector<AtomField> fields; |
| 83 | |
| Yao Chen | 9c1debe | 2018-02-19 14:39:19 -0800 | [diff] [blame] | 84 | vector<int> primaryFields; |
| 85 | int exclusiveField = 0; |
| 86 | |
| Yao Chen | c40a19d | 2018-03-15 16:48:25 -0700 | [diff] [blame] | 87 | int uidField = 0; |
| 88 | |
| Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 89 | AtomDecl(); |
| 90 | AtomDecl(const AtomDecl& that); |
| 91 | AtomDecl(int code, const string& name, const string& message); |
| 92 | ~AtomDecl(); |
| 93 | |
| 94 | inline bool operator<(const AtomDecl& that) const { |
| 95 | return (code == that.code) ? (name < that.name) : (code < that.code); |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | struct Atoms { |
| 100 | set<vector<java_type_t>> signatures; |
| 101 | set<AtomDecl> decls; |
| Yangster-mac | ba5b9e4 | 2018-01-10 21:31:59 -0800 | [diff] [blame] | 102 | set<AtomDecl> non_chained_decls; |
| 103 | set<vector<java_type_t>> non_chained_signatures; |
| Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | /** |
| 107 | * Gather the information about the atoms. Returns the number of errors. |
| 108 | */ |
| 109 | int collate_atoms(const Descriptor* descriptor, Atoms* atoms); |
| Yangster-mac | ba5b9e4 | 2018-01-10 21:31:59 -0800 | [diff] [blame] | 110 | int collate_atom(const Descriptor *atom, AtomDecl *atomDecl, vector<java_type_t> *signature); |
| Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 111 | |
| 112 | } // namespace stats_log_api_gen |
| 113 | } // namespace android |
| 114 | |
| 115 | |
| Yangster-mac | 7604aea | 2017-12-11 22:55:49 -0800 | [diff] [blame] | 116 | #endif // ANDROID_STATS_LOG_API_GEN_COLLATION_H |