blob: 2f840d7f446941136248da7f7569709020169168 [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;
35
36/**
37 * The types for atom parameters.
38 */
39typedef enum {
40 JAVA_TYPE_UNKNOWN = 0,
41
42 JAVA_TYPE_WORK_SOURCE = 1,
43 JAVA_TYPE_BOOLEAN = 2,
44 JAVA_TYPE_INT = 3,
45 JAVA_TYPE_LONG = 4,
46 JAVA_TYPE_FLOAT = 5,
47 JAVA_TYPE_DOUBLE = 6,
48 JAVA_TYPE_STRING = 7,
Stefan Lafon9478f352017-10-30 21:20:20 -070049 JAVA_TYPE_ENUM = 8,
Yao Chend54f9dd2017-10-17 17:37:48 +000050
51 JAVA_TYPE_OBJECT = -1,
52 JAVA_TYPE_BYTE_ARRAY = -2,
53} java_type_t;
54
55
56/**
57 * The name and type for an atom field.
58 */
59struct AtomField {
60 string name;
61 java_type_t javaType;
62
Stefan Lafon9478f352017-10-30 21:20:20 -070063 // 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 Chend54f9dd2017-10-17 17:37:48 +000066 inline AtomField() :name(), javaType(JAVA_TYPE_UNKNOWN) {}
Stefan Lafon9478f352017-10-30 21:20:20 -070067 inline AtomField(const AtomField& that) :name(that.name),
68 javaType(that.javaType),
69 enumValues(that.enumValues) {}
Yao Chend54f9dd2017-10-17 17:37:48 +000070 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 */
77struct AtomDecl {
78 int code;
79 string name;
80
81 string message;
82 vector<AtomField> fields;
83
84 AtomDecl();
85 AtomDecl(const AtomDecl& that);
86 AtomDecl(int code, const string& name, const string& message);
87 ~AtomDecl();
88
89 inline bool operator<(const AtomDecl& that) const {
90 return (code == that.code) ? (name < that.name) : (code < that.code);
91 }
92};
93
94struct Atoms {
95 set<vector<java_type_t>> signatures;
96 set<AtomDecl> decls;
97};
98
99/**
100 * Gather the information about the atoms. Returns the number of errors.
101 */
102int collate_atoms(const Descriptor* descriptor, Atoms* atoms);
103
104} // namespace stats_log_api_gen
105} // namespace android
106
107
108#endif // ANDROID_STATS_LOG_API_GEN_COLLATION_H