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 | |
Chenjie Yu | 159e4f8 | 2018-08-29 11:49:11 -0700 | [diff] [blame] | 37 | const int PULL_ATOM_START_ID = 10000; |
| 38 | |
tsaichristine | ed61564 | 2020-01-02 12:53:41 -0800 | [diff] [blame] | 39 | const int FIRST_UID_IN_CHAIN_ID = 0; |
| 40 | |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 41 | /** |
| 42 | * The types for atom parameters. |
| 43 | */ |
| 44 | typedef enum { |
Yangster-mac | 7604aea | 2017-12-11 22:55:49 -0800 | [diff] [blame] | 45 | JAVA_TYPE_UNKNOWN = 0, |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 46 | |
Yangster-mac | 7604aea | 2017-12-11 22:55:49 -0800 | [diff] [blame] | 47 | JAVA_TYPE_ATTRIBUTION_CHAIN = 1, |
| 48 | JAVA_TYPE_BOOLEAN = 2, |
| 49 | JAVA_TYPE_INT = 3, |
| 50 | JAVA_TYPE_LONG = 4, |
| 51 | JAVA_TYPE_FLOAT = 5, |
| 52 | JAVA_TYPE_DOUBLE = 6, |
| 53 | JAVA_TYPE_STRING = 7, |
| 54 | JAVA_TYPE_ENUM = 8, |
Yangster-mac | 48b3d62 | 2018-08-18 12:38:11 -0700 | [diff] [blame] | 55 | JAVA_TYPE_KEY_VALUE_PAIR = 9, |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 56 | |
Yangster-mac | 7604aea | 2017-12-11 22:55:49 -0800 | [diff] [blame] | 57 | JAVA_TYPE_OBJECT = -1, |
| 58 | JAVA_TYPE_BYTE_ARRAY = -2, |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 59 | } java_type_t; |
| 60 | |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 61 | /** |
| 62 | * The name and type for an atom field. |
| 63 | */ |
| 64 | struct AtomField { |
| 65 | string name; |
| 66 | java_type_t javaType; |
| 67 | |
Stefan Lafon | 9478f35 | 2017-10-30 21:20:20 -0700 | [diff] [blame] | 68 | // If the field is of type enum, the following map contains the list of enum values. |
| 69 | map<int /* numeric value */, string /* value name */> enumValues; |
| 70 | |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 71 | inline AtomField() :name(), javaType(JAVA_TYPE_UNKNOWN) {} |
Stefan Lafon | 9478f35 | 2017-10-30 21:20:20 -0700 | [diff] [blame] | 72 | inline AtomField(const AtomField& that) :name(that.name), |
| 73 | javaType(that.javaType), |
| 74 | enumValues(that.enumValues) {} |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 75 | inline AtomField(string n, java_type_t jt) :name(n), javaType(jt) {} |
| 76 | inline ~AtomField() {} |
| 77 | }; |
| 78 | |
| 79 | /** |
| 80 | * The name and code for an atom. |
| 81 | */ |
| 82 | struct AtomDecl { |
| 83 | int code; |
| 84 | string name; |
| 85 | |
| 86 | string message; |
| 87 | vector<AtomField> fields; |
| 88 | |
Yao Chen | 9c1debe | 2018-02-19 14:39:19 -0800 | [diff] [blame] | 89 | vector<int> primaryFields; |
| 90 | int exclusiveField = 0; |
tsaichristine | 5adc7e0 | 2020-01-14 17:07:39 -0800 | [diff] [blame^] | 91 | int defaultState = INT_MAX; |
| 92 | int resetState = INT_MAX; |
| 93 | bool nested; |
Yao Chen | 9c1debe | 2018-02-19 14:39:19 -0800 | [diff] [blame] | 94 | |
Yao Chen | c40a19d | 2018-03-15 16:48:25 -0700 | [diff] [blame] | 95 | int uidField = 0; |
| 96 | |
Andrei Onea | da01ea5 | 2019-01-30 15:28:36 +0000 | [diff] [blame] | 97 | bool whitelisted = false; |
| 98 | |
Yao Chen | bbdd67d | 2018-10-24 12:15:56 -0700 | [diff] [blame] | 99 | vector<int> binaryFields; |
| 100 | |
Tej Singh | 810eeb3 | 2019-03-07 19:08:52 -0800 | [diff] [blame] | 101 | bool hasModule = false; |
| 102 | string moduleName; |
| 103 | |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 104 | AtomDecl(); |
| 105 | AtomDecl(const AtomDecl& that); |
| 106 | AtomDecl(int code, const string& name, const string& message); |
| 107 | ~AtomDecl(); |
| 108 | |
| 109 | inline bool operator<(const AtomDecl& that) const { |
| 110 | return (code == that.code) ? (name < that.name) : (code < that.code); |
| 111 | } |
| 112 | }; |
| 113 | |
| 114 | struct Atoms { |
Tej Singh | 810eeb3 | 2019-03-07 19:08:52 -0800 | [diff] [blame] | 115 | map<vector<java_type_t>, set<string>> signatures_to_modules; |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 116 | set<AtomDecl> decls; |
Yangster-mac | ba5b9e4 | 2018-01-10 21:31:59 -0800 | [diff] [blame] | 117 | set<AtomDecl> non_chained_decls; |
Tej Singh | 810eeb3 | 2019-03-07 19:08:52 -0800 | [diff] [blame] | 118 | map<vector<java_type_t>, set<string>> non_chained_signatures_to_modules; |
Muhammad Qureshi | c8e2266 | 2019-11-20 17:18:03 -0800 | [diff] [blame] | 119 | int maxPushedAtomId; |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | /** |
| 123 | * Gather the information about the atoms. Returns the number of errors. |
| 124 | */ |
| 125 | int collate_atoms(const Descriptor* descriptor, Atoms* atoms); |
Yangster-mac | ba5b9e4 | 2018-01-10 21:31:59 -0800 | [diff] [blame] | 126 | 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] | 127 | |
| 128 | } // namespace stats_log_api_gen |
| 129 | } // namespace android |
| 130 | |
| 131 | |
Muhammad Qureshi | c8e2266 | 2019-11-20 17:18:03 -0800 | [diff] [blame] | 132 | #endif // ANDROID_STATS_LOG_API_GEN_COLLATION_H |