blob: 87d4d5db0cee5d151c001cc9eeb24b89d99adaab [file] [log] [blame]
Yao Chend54f9dd2017-10-17 17:37:48 +00001/*
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 Lafon9478f352017-10-30 21:20:20 -070025#include <map>
Yao Chend54f9dd2017-10-17 17:37:48 +000026
27namespace android {
28namespace stats_log_api_gen {
29
Stefan Lafon9478f352017-10-30 21:20:20 -070030using std::map;
Yao Chend54f9dd2017-10-17 17:37:48 +000031using std::set;
32using std::string;
33using std::vector;
34using google::protobuf::Descriptor;
Yangster-macba5b9e42018-01-10 21:31:59 -080035using google::protobuf::FieldDescriptor;
Yao Chend54f9dd2017-10-17 17:37:48 +000036
Chenjie Yu159e4f82018-08-29 11:49:11 -070037const int PULL_ATOM_START_ID = 10000;
38
tsaichristineed615642020-01-02 12:53:41 -080039const int FIRST_UID_IN_CHAIN_ID = 0;
40
Yao Chend54f9dd2017-10-17 17:37:48 +000041/**
42 * The types for atom parameters.
43 */
44typedef enum {
Yangster-mac7604aea2017-12-11 22:55:49 -080045 JAVA_TYPE_UNKNOWN = 0,
Yao Chend54f9dd2017-10-17 17:37:48 +000046
Yangster-mac7604aea2017-12-11 22:55:49 -080047 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-mac48b3d622018-08-18 12:38:11 -070055 JAVA_TYPE_KEY_VALUE_PAIR = 9,
Yao Chend54f9dd2017-10-17 17:37:48 +000056
Yangster-mac7604aea2017-12-11 22:55:49 -080057 JAVA_TYPE_OBJECT = -1,
58 JAVA_TYPE_BYTE_ARRAY = -2,
Yao Chend54f9dd2017-10-17 17:37:48 +000059} java_type_t;
60
Yao Chend54f9dd2017-10-17 17:37:48 +000061/**
62 * The name and type for an atom field.
63 */
64struct AtomField {
65 string name;
66 java_type_t javaType;
67
Stefan Lafon9478f352017-10-30 21:20:20 -070068 // 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 Chend54f9dd2017-10-17 17:37:48 +000071 inline AtomField() :name(), javaType(JAVA_TYPE_UNKNOWN) {}
Stefan Lafon9478f352017-10-30 21:20:20 -070072 inline AtomField(const AtomField& that) :name(that.name),
73 javaType(that.javaType),
74 enumValues(that.enumValues) {}
Yao Chend54f9dd2017-10-17 17:37:48 +000075 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 */
82struct AtomDecl {
83 int code;
84 string name;
85
86 string message;
87 vector<AtomField> fields;
88
Yao Chen9c1debe2018-02-19 14:39:19 -080089 vector<int> primaryFields;
90 int exclusiveField = 0;
91
Yao Chenc40a19d2018-03-15 16:48:25 -070092 int uidField = 0;
93
Andrei Oneada01ea52019-01-30 15:28:36 +000094 bool whitelisted = false;
95
Yao Chenbbdd67d2018-10-24 12:15:56 -070096 vector<int> binaryFields;
97
Tej Singh810eeb32019-03-07 19:08:52 -080098 bool hasModule = false;
99 string moduleName;
100
Yao Chend54f9dd2017-10-17 17:37:48 +0000101 AtomDecl();
102 AtomDecl(const AtomDecl& that);
103 AtomDecl(int code, const string& name, const string& message);
104 ~AtomDecl();
105
106 inline bool operator<(const AtomDecl& that) const {
107 return (code == that.code) ? (name < that.name) : (code < that.code);
108 }
109};
110
111struct Atoms {
Tej Singh810eeb32019-03-07 19:08:52 -0800112 map<vector<java_type_t>, set<string>> signatures_to_modules;
Yao Chend54f9dd2017-10-17 17:37:48 +0000113 set<AtomDecl> decls;
Yangster-macba5b9e42018-01-10 21:31:59 -0800114 set<AtomDecl> non_chained_decls;
Tej Singh810eeb32019-03-07 19:08:52 -0800115 map<vector<java_type_t>, set<string>> non_chained_signatures_to_modules;
Muhammad Qureshic8e22662019-11-20 17:18:03 -0800116 int maxPushedAtomId;
Yao Chend54f9dd2017-10-17 17:37:48 +0000117};
118
119/**
120 * Gather the information about the atoms. Returns the number of errors.
121 */
122int collate_atoms(const Descriptor* descriptor, Atoms* atoms);
Yangster-macba5b9e42018-01-10 21:31:59 -0800123int collate_atom(const Descriptor *atom, AtomDecl *atomDecl, vector<java_type_t> *signature);
Yao Chend54f9dd2017-10-17 17:37:48 +0000124
125} // namespace stats_log_api_gen
126} // namespace android
127
128
Muhammad Qureshic8e22662019-11-20 17:18:03 -0800129#endif // ANDROID_STATS_LOG_API_GEN_COLLATION_H