1 /* 2 * Copyright (C) 2019, 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 #pragma once 18 19 #include <stdio.h> 20 #include <string.h> 21 22 #include <map> 23 #include <set> 24 #include <vector> 25 26 #include "Collation.h" 27 28 namespace android { 29 namespace stats_log_api_gen { 30 31 using namespace std; 32 33 const string DEFAULT_CPP_NAMESPACE = "android,util"; 34 const string DEFAULT_CPP_HEADER_IMPORT = "statslog.h"; 35 36 const int JAVA_MODULE_REQUIRES_FLOAT = 0x01; 37 const int JAVA_MODULE_REQUIRES_ATTRIBUTION = 0x02; 38 const int JAVA_MODULE_REQUIRES_KEY_VALUE_PAIRS = 0x04; 39 40 const map<AnnotationId, string> ANNOTATION_ID_CONSTANTS = { 41 {ANNOTATION_ID_IS_UID, "ANNOTATION_ID_IS_UID"}, 42 {ANNOTATION_ID_TRUNCATE_TIMESTAMP, "ANNOTATION_ID_TRUNCATE_TIMESTAMP"}, 43 {ANNOTATION_ID_PRIMARY_FIELD, "ANNOTATION_ID_PRIMARY_FIELD"}, 44 {ANNOTATION_ID_PRIMARY_FIELD_FIRST_UID, "ANNOTATION_ID_PRIMARY_FIELD_FIRST_UID"}, 45 {ANNOTATION_ID_EXCLUSIVE_STATE, "ANNOTATION_ID_EXCLUSIVE_STATE"}, 46 {ANNOTATION_ID_TRIGGER_STATE_RESET, "ANNOTATION_ID_TRIGGER_STATE_RESET"}, 47 {ANNOTATION_ID_STATE_NESTED, "ANNOTATION_ID_STATE_NESTED"}}; 48 49 string make_constant_name(const string& str); 50 51 const char* cpp_type_name(java_type_t type); 52 53 const char* java_type_name(java_type_t type); 54 55 // Common Native helpers 56 void write_namespace(FILE* out, const string& cppNamespaces); 57 58 void write_closing_namespace(FILE* out, const string& cppNamespaces); 59 60 void write_native_atom_constants(FILE* out, const Atoms& atoms, const AtomDecl& attributionDecl); 61 62 void write_native_method_signature(FILE* out, const string& methodName, 63 const vector<java_type_t>& signature, 64 const AtomDecl& attributionDecl, const string& closer); 65 66 void write_native_method_call(FILE* out, const string& methodName, 67 const vector<java_type_t>& signature, const AtomDecl& attributionDecl, 68 int argIndex = 1); 69 70 // Common Java helpers. 71 void write_java_atom_codes(FILE* out, const Atoms& atoms); 72 73 void write_java_enum_values(FILE* out, const Atoms& atoms); 74 75 void write_java_usage(FILE* out, const string& method_name, const string& atom_code_name, 76 const AtomDecl& atom); 77 78 int write_java_non_chained_methods(FILE* out, const SignatureInfoMap& signatureInfoMap); 79 80 int write_java_work_source_methods(FILE* out, const SignatureInfoMap& signatureInfoMap); 81 82 } // namespace stats_log_api_gen 83 } // namespace android 84