2017-10-17 17:37:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017, The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ANDROID_STATS_LOG_API_GEN_COLLATION_H
|
|
|
|
#define ANDROID_STATS_LOG_API_GEN_COLLATION_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <google/protobuf/descriptor.h>
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
2017-10-30 21:20:20 -07:00
|
|
|
#include <map>
|
2017-10-17 17:37:48 +00:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace stats_log_api_gen {
|
|
|
|
|
2017-10-30 21:20:20 -07:00
|
|
|
using std::map;
|
2017-10-17 17:37:48 +00:00
|
|
|
using std::set;
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
using google::protobuf::Descriptor;
|
2018-01-10 21:31:59 -08:00
|
|
|
using google::protobuf::FieldDescriptor;
|
2017-10-17 17:37:48 +00:00
|
|
|
|
2018-08-29 11:49:11 -07:00
|
|
|
const int PULL_ATOM_START_ID = 10000;
|
|
|
|
|
2017-10-17 17:37:48 +00:00
|
|
|
/**
|
|
|
|
* The types for atom parameters.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
2017-12-11 22:55:49 -08:00
|
|
|
JAVA_TYPE_UNKNOWN = 0,
|
|
|
|
|
|
|
|
JAVA_TYPE_ATTRIBUTION_CHAIN = 1,
|
|
|
|
JAVA_TYPE_BOOLEAN = 2,
|
|
|
|
JAVA_TYPE_INT = 3,
|
|
|
|
JAVA_TYPE_LONG = 4,
|
|
|
|
JAVA_TYPE_FLOAT = 5,
|
|
|
|
JAVA_TYPE_DOUBLE = 6,
|
|
|
|
JAVA_TYPE_STRING = 7,
|
|
|
|
JAVA_TYPE_ENUM = 8,
|
2018-08-18 12:38:11 -07:00
|
|
|
JAVA_TYPE_KEY_VALUE_PAIR = 9,
|
2017-12-11 22:55:49 -08:00
|
|
|
|
|
|
|
JAVA_TYPE_OBJECT = -1,
|
|
|
|
JAVA_TYPE_BYTE_ARRAY = -2,
|
2017-10-17 17:37:48 +00:00
|
|
|
} java_type_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The name and type for an atom field.
|
|
|
|
*/
|
|
|
|
struct AtomField {
|
|
|
|
string name;
|
|
|
|
java_type_t javaType;
|
|
|
|
|
2017-10-30 21:20:20 -07:00
|
|
|
// If the field is of type enum, the following map contains the list of enum values.
|
|
|
|
map<int /* numeric value */, string /* value name */> enumValues;
|
|
|
|
|
2017-10-17 17:37:48 +00:00
|
|
|
inline AtomField() :name(), javaType(JAVA_TYPE_UNKNOWN) {}
|
2017-10-30 21:20:20 -07:00
|
|
|
inline AtomField(const AtomField& that) :name(that.name),
|
|
|
|
javaType(that.javaType),
|
|
|
|
enumValues(that.enumValues) {}
|
2017-10-17 17:37:48 +00:00
|
|
|
inline AtomField(string n, java_type_t jt) :name(n), javaType(jt) {}
|
|
|
|
inline ~AtomField() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The name and code for an atom.
|
|
|
|
*/
|
|
|
|
struct AtomDecl {
|
|
|
|
int code;
|
|
|
|
string name;
|
|
|
|
|
|
|
|
string message;
|
|
|
|
vector<AtomField> fields;
|
|
|
|
|
2018-02-19 14:39:19 -08:00
|
|
|
vector<int> primaryFields;
|
|
|
|
int exclusiveField = 0;
|
|
|
|
|
2018-03-15 16:48:25 -07:00
|
|
|
int uidField = 0;
|
|
|
|
|
2019-01-30 15:28:36 +00:00
|
|
|
bool whitelisted = false;
|
|
|
|
|
2018-10-24 12:15:56 -07:00
|
|
|
vector<int> binaryFields;
|
|
|
|
|
2019-03-07 19:08:52 -08:00
|
|
|
bool hasModule = false;
|
|
|
|
string moduleName;
|
|
|
|
|
2017-10-17 17:37:48 +00:00
|
|
|
AtomDecl();
|
|
|
|
AtomDecl(const AtomDecl& that);
|
|
|
|
AtomDecl(int code, const string& name, const string& message);
|
|
|
|
~AtomDecl();
|
|
|
|
|
|
|
|
inline bool operator<(const AtomDecl& that) const {
|
|
|
|
return (code == that.code) ? (name < that.name) : (code < that.code);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Atoms {
|
2019-03-07 19:08:52 -08:00
|
|
|
map<vector<java_type_t>, set<string>> signatures_to_modules;
|
2017-10-17 17:37:48 +00:00
|
|
|
set<AtomDecl> decls;
|
2018-01-10 21:31:59 -08:00
|
|
|
set<AtomDecl> non_chained_decls;
|
2019-03-07 19:08:52 -08:00
|
|
|
map<vector<java_type_t>, set<string>> non_chained_signatures_to_modules;
|
2017-10-17 17:37:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gather the information about the atoms. Returns the number of errors.
|
|
|
|
*/
|
|
|
|
int collate_atoms(const Descriptor* descriptor, Atoms* atoms);
|
2018-01-10 21:31:59 -08:00
|
|
|
int collate_atom(const Descriptor *atom, AtomDecl *atomDecl, vector<java_type_t> *signature);
|
2017-10-17 17:37:48 +00:00
|
|
|
|
|
|
|
} // namespace stats_log_api_gen
|
|
|
|
} // namespace android
|
|
|
|
|
|
|
|
|
2017-12-11 22:55:49 -08:00
|
|
|
#endif // ANDROID_STATS_LOG_API_GEN_COLLATION_H
|