blob: 8e4cb9f44029514735cf87d39fc7a8be0b48a993 [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
37/**
38 * The types for atom parameters.
39 */
40typedef enum {
Yangster-mac7604aea2017-12-11 22:55:49 -080041 JAVA_TYPE_UNKNOWN = 0,
Yao Chend54f9dd2017-10-17 17:37:48 +000042
Yangster-mac7604aea2017-12-11 22:55:49 -080043 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,
Tej Singh37b97422019-04-18 11:31:52 +080051 JAVA_TYPE_KEY_VALUE_PAIR = 9,
Yao Chend54f9dd2017-10-17 17:37:48 +000052
Yangster-mac7604aea2017-12-11 22:55:49 -080053 JAVA_TYPE_OBJECT = -1,
54 JAVA_TYPE_BYTE_ARRAY = -2,
Yao Chend54f9dd2017-10-17 17:37:48 +000055} java_type_t;
56
Yao Chend54f9dd2017-10-17 17:37:48 +000057/**
58 * The name and type for an atom field.
59 */
60struct AtomField {
61 string name;
62 java_type_t javaType;
63
Stefan Lafon9478f352017-10-30 21:20:20 -070064 // If the field is of type enum, the following map contains the list of enum values.
65 map<int /* numeric value */, string /* value name */> enumValues;
66
Yao Chend54f9dd2017-10-17 17:37:48 +000067 inline AtomField() :name(), javaType(JAVA_TYPE_UNKNOWN) {}
Stefan Lafon9478f352017-10-30 21:20:20 -070068 inline AtomField(const AtomField& that) :name(that.name),
69 javaType(that.javaType),
70 enumValues(that.enumValues) {}
Yao Chend54f9dd2017-10-17 17:37:48 +000071 inline AtomField(string n, java_type_t jt) :name(n), javaType(jt) {}
72 inline ~AtomField() {}
73};
74
75/**
76 * The name and code for an atom.
77 */
78struct AtomDecl {
79 int code;
80 string name;
81
82 string message;
83 vector<AtomField> fields;
84
Yao Chen9c1debe2018-02-19 14:39:19 -080085 vector<int> primaryFields;
86 int exclusiveField = 0;
87
Yao Chenc40a19d2018-03-15 16:48:25 -070088 int uidField = 0;
89
Yao Chen8b71c742018-10-24 12:15:56 -070090 vector<int> binaryFields;
91
Tej Singh1f431f32019-03-07 19:08:52 -080092 bool hasModule = false;
93 string moduleName;
94
Yao Chend54f9dd2017-10-17 17:37:48 +000095 AtomDecl();
96 AtomDecl(const AtomDecl& that);
97 AtomDecl(int code, const string& name, const string& message);
98 ~AtomDecl();
99
100 inline bool operator<(const AtomDecl& that) const {
101 return (code == that.code) ? (name < that.name) : (code < that.code);
102 }
103};
104
105struct Atoms {
Tej Singh1f431f32019-03-07 19:08:52 -0800106 map<vector<java_type_t>, set<string>> signatures_to_modules;
Yao Chend54f9dd2017-10-17 17:37:48 +0000107 set<AtomDecl> decls;
Yangster-macba5b9e42018-01-10 21:31:59 -0800108 set<AtomDecl> non_chained_decls;
Tej Singh1f431f32019-03-07 19:08:52 -0800109 map<vector<java_type_t>, set<string>> non_chained_signatures_to_modules;
Yao Chend54f9dd2017-10-17 17:37:48 +0000110};
111
112/**
113 * Gather the information about the atoms. Returns the number of errors.
114 */
115int collate_atoms(const Descriptor* descriptor, Atoms* atoms);
Yangster-macba5b9e42018-01-10 21:31:59 -0800116int collate_atom(const Descriptor *atom, AtomDecl *atomDecl, vector<java_type_t> *signature);
Yao Chend54f9dd2017-10-17 17:37:48 +0000117
118} // namespace stats_log_api_gen
119} // namespace android
120
121
Tej Singh37b97422019-04-18 11:31:52 +0800122#endif // ANDROID_STATS_LOG_API_GEN_COLLATION_H