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> |
| 25 | |
| 26 | namespace android { |
| 27 | namespace stats_log_api_gen { |
| 28 | |
| 29 | using std::set; |
| 30 | using std::string; |
| 31 | using std::vector; |
| 32 | using google::protobuf::Descriptor; |
| 33 | |
| 34 | /** |
| 35 | * The types for atom parameters. |
| 36 | */ |
| 37 | typedef enum { |
| 38 | JAVA_TYPE_UNKNOWN = 0, |
| 39 | |
| 40 | JAVA_TYPE_WORK_SOURCE = 1, |
| 41 | JAVA_TYPE_BOOLEAN = 2, |
| 42 | JAVA_TYPE_INT = 3, |
| 43 | JAVA_TYPE_LONG = 4, |
| 44 | JAVA_TYPE_FLOAT = 5, |
| 45 | JAVA_TYPE_DOUBLE = 6, |
| 46 | JAVA_TYPE_STRING = 7, |
| 47 | |
| 48 | JAVA_TYPE_OBJECT = -1, |
| 49 | JAVA_TYPE_BYTE_ARRAY = -2, |
| 50 | } java_type_t; |
| 51 | |
| 52 | |
| 53 | /** |
| 54 | * The name and type for an atom field. |
| 55 | */ |
| 56 | struct AtomField { |
| 57 | string name; |
| 58 | java_type_t javaType; |
| 59 | |
| 60 | inline AtomField() :name(), javaType(JAVA_TYPE_UNKNOWN) {} |
| 61 | inline AtomField(const AtomField& that) :name(that.name), javaType(that.javaType) {} |
| 62 | inline AtomField(string n, java_type_t jt) :name(n), javaType(jt) {} |
| 63 | inline ~AtomField() {} |
| 64 | }; |
| 65 | |
| 66 | /** |
| 67 | * The name and code for an atom. |
| 68 | */ |
| 69 | struct AtomDecl { |
| 70 | int code; |
| 71 | string name; |
| 72 | |
| 73 | string message; |
| 74 | vector<AtomField> fields; |
| 75 | |
| 76 | AtomDecl(); |
| 77 | AtomDecl(const AtomDecl& that); |
| 78 | AtomDecl(int code, const string& name, const string& message); |
| 79 | ~AtomDecl(); |
| 80 | |
| 81 | inline bool operator<(const AtomDecl& that) const { |
| 82 | return (code == that.code) ? (name < that.name) : (code < that.code); |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | struct Atoms { |
| 87 | set<vector<java_type_t>> signatures; |
| 88 | set<AtomDecl> decls; |
| 89 | }; |
| 90 | |
| 91 | /** |
| 92 | * Gather the information about the atoms. Returns the number of errors. |
| 93 | */ |
| 94 | int collate_atoms(const Descriptor* descriptor, Atoms* atoms); |
| 95 | |
| 96 | } // namespace stats_log_api_gen |
| 97 | } // namespace android |
| 98 | |
| 99 | |
| 100 | #endif // ANDROID_STATS_LOG_API_GEN_COLLATION_H |