Merge "Add a struct wrapper for bytes fields in stats_log cpp APIs."
This commit is contained in:
@@ -69,7 +69,7 @@ cpp_type_name(java_type_t type)
|
||||
case JAVA_TYPE_STRING:
|
||||
return "char const*";
|
||||
case JAVA_TYPE_BYTE_ARRAY:
|
||||
return "char const*";
|
||||
return "const BytesField&";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
@@ -272,9 +272,6 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms,
|
||||
chainField.name.c_str(), chainField.name.c_str());
|
||||
}
|
||||
}
|
||||
} else if (*arg == JAVA_TYPE_BYTE_ARRAY) {
|
||||
fprintf(out, ", %s arg%d, size_t arg%d_length",
|
||||
cpp_type_name(*arg), argIndex, argIndex);
|
||||
} else {
|
||||
fprintf(out, ", %s arg%d", cpp_type_name(*arg), argIndex);
|
||||
}
|
||||
@@ -319,7 +316,8 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms,
|
||||
fprintf(out, " event.end();\n\n");
|
||||
} else if (*arg == JAVA_TYPE_BYTE_ARRAY) {
|
||||
fprintf(out,
|
||||
" event.AppendCharArray(arg%d, arg%d_length);\n",
|
||||
" event.AppendCharArray(arg%d.arg, "
|
||||
"arg%d.arg_length);\n",
|
||||
argIndex, argIndex);
|
||||
} else {
|
||||
if (*arg == JAVA_TYPE_STRING) {
|
||||
@@ -361,9 +359,6 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms,
|
||||
chainField.name.c_str(), chainField.name.c_str());
|
||||
}
|
||||
}
|
||||
} else if (*arg == JAVA_TYPE_BYTE_ARRAY) {
|
||||
fprintf(out, ", %s arg%d, size_t arg%d_length",
|
||||
cpp_type_name(*arg), argIndex, argIndex);
|
||||
} else {
|
||||
fprintf(out, ", %s arg%d", cpp_type_name(*arg), argIndex);
|
||||
}
|
||||
@@ -390,8 +385,6 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms,
|
||||
chainField.name.c_str(), chainField.name.c_str());
|
||||
}
|
||||
}
|
||||
} else if (*arg == JAVA_TYPE_BYTE_ARRAY) {
|
||||
fprintf(out, ", arg%d, arg%d_length", argIndex, argIndex);
|
||||
} else {
|
||||
fprintf(out, ", arg%d", argIndex);
|
||||
}
|
||||
@@ -445,7 +438,14 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms,
|
||||
fprintf(out, " arg%d = \"\";\n", argIndex);
|
||||
fprintf(out, " }\n");
|
||||
}
|
||||
fprintf(out, " event << arg%d;\n", argIndex);
|
||||
if (*arg == JAVA_TYPE_BYTE_ARRAY) {
|
||||
fprintf(out,
|
||||
" event.AppendCharArray(arg%d.arg, "
|
||||
"arg%d.arg_length);",
|
||||
argIndex, argIndex);
|
||||
} else {
|
||||
fprintf(out, " event << arg%d;\n", argIndex);
|
||||
}
|
||||
if (argIndex == 2) {
|
||||
fprintf(out, " event.end();\n\n");
|
||||
fprintf(out, " event.end();\n\n");
|
||||
@@ -525,7 +525,9 @@ void build_non_chained_decl_map(const Atoms& atoms,
|
||||
static void write_cpp_usage(
|
||||
FILE* out, const string& method_name, const string& atom_code_name,
|
||||
const AtomDecl& atom, const AtomDecl &attributionDecl) {
|
||||
fprintf(out, " * Usage: %s(StatsLog.%s", method_name.c_str(), atom_code_name.c_str());
|
||||
fprintf(out, " * Usage: %s(StatsLog.%s", method_name.c_str(),
|
||||
atom_code_name.c_str());
|
||||
|
||||
for (vector<AtomField>::const_iterator field = atom.fields.begin();
|
||||
field != atom.fields.end(); field++) {
|
||||
if (field->javaType == JAVA_TYPE_ATTRIBUTION_CHAIN) {
|
||||
@@ -540,10 +542,6 @@ static void write_cpp_usage(
|
||||
chainField.name.c_str(), chainField.name.c_str());
|
||||
}
|
||||
}
|
||||
} else if (field->javaType == JAVA_TYPE_BYTE_ARRAY) {
|
||||
fprintf(out, ", %s %s, size_t %s_length",
|
||||
cpp_type_name(field->javaType), field->name.c_str(),
|
||||
field->name.c_str());
|
||||
} else {
|
||||
fprintf(out, ", %s %s", cpp_type_name(field->javaType), field->name.c_str());
|
||||
}
|
||||
@@ -571,9 +569,6 @@ static void write_cpp_method_header(
|
||||
chainField.name.c_str(), chainField.name.c_str());
|
||||
}
|
||||
}
|
||||
} else if (*arg == JAVA_TYPE_BYTE_ARRAY) {
|
||||
fprintf(out, ", %s arg%d, size_t arg%d_length",
|
||||
cpp_type_name(*arg), argIndex, argIndex);
|
||||
} else {
|
||||
fprintf(out, ", %s arg%d", cpp_type_name(*arg), argIndex);
|
||||
}
|
||||
@@ -640,6 +635,15 @@ write_stats_log_header(FILE* out, const Atoms& atoms, const AtomDecl &attributio
|
||||
fprintf(out, "};\n");
|
||||
fprintf(out, "\n");
|
||||
|
||||
fprintf(out, "struct BytesField {\n");
|
||||
fprintf(out,
|
||||
" BytesField(char const* array, size_t len) : arg(array), "
|
||||
"arg_length(len) {}\n");
|
||||
fprintf(out, " char const* arg;\n");
|
||||
fprintf(out, " size_t arg_length;\n");
|
||||
fprintf(out, "};\n");
|
||||
fprintf(out, "\n");
|
||||
|
||||
fprintf(out, "struct StateAtomFieldOptions {\n");
|
||||
fprintf(out, " std::vector<int> primaryFields;\n");
|
||||
fprintf(out, " int exclusiveField;\n");
|
||||
@@ -1058,6 +1062,11 @@ write_stats_log_jni(FILE* out, const string& java_method_name, const string& cpp
|
||||
fprintf(out, " str%d = NULL;\n", argIndex);
|
||||
fprintf(out, " }\n");
|
||||
|
||||
fprintf(out,
|
||||
" android::util::BytesField bytesField%d(str%d, "
|
||||
"str%d_length);",
|
||||
argIndex, argIndex, argIndex);
|
||||
|
||||
} else if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) {
|
||||
hadStringOrChain = true;
|
||||
for (auto chainField : attributionDecl.fields) {
|
||||
@@ -1110,7 +1119,8 @@ write_stats_log_jni(FILE* out, const string& java_method_name, const string& cpp
|
||||
|
||||
// stats_write call
|
||||
argIndex = 1;
|
||||
fprintf(out, " int ret = android::util::%s(code", cpp_method_name.c_str());
|
||||
fprintf(out, "\n int ret = android::util::%s(code",
|
||||
cpp_method_name.c_str());
|
||||
for (vector<java_type_t>::const_iterator arg = signature->begin();
|
||||
arg != signature->end(); arg++) {
|
||||
if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) {
|
||||
@@ -1123,16 +1133,12 @@ write_stats_log_jni(FILE* out, const string& java_method_name, const string& cpp
|
||||
fprintf(out, ", %s_vec", chainField.name.c_str());
|
||||
}
|
||||
}
|
||||
} else if (*arg == JAVA_TYPE_BYTE_ARRAY) {
|
||||
fprintf(out, ", bytesField%d", argIndex);
|
||||
} else {
|
||||
const char* argName = (*arg == JAVA_TYPE_STRING ||
|
||||
*arg == JAVA_TYPE_BYTE_ARRAY)
|
||||
? "str"
|
||||
: "arg";
|
||||
const char* argName =
|
||||
(*arg == JAVA_TYPE_STRING) ? "str" : "arg";
|
||||
fprintf(out, ", (%s)%s%d", cpp_type_name(*arg), argName, argIndex);
|
||||
|
||||
if (*arg == JAVA_TYPE_BYTE_ARRAY) {
|
||||
fprintf(out, ", %s%d_length", argName, argIndex);
|
||||
}
|
||||
}
|
||||
argIndex++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user