aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2019-04-08 14:50:29 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-04-08 14:50:29 +0000
commit545f44dc4c6ec299b4745e74d6589ab9e7e2eec4 (patch)
tree952fb0bfdbd762d02bfb18c19c4d370ecc598731
parentf06bc62b24bc2c88032fd196941132eef60a98dc (diff)
parent71d1f3833613772af89558fbc1c315987c71eefd (diff)
downloadaidl-545f44dc4c6ec299b4745e74d6589ab9e7e2eec4.tar.gz
Merge "Change parameters in log data to array of pairs" into qt-dev
-rw-r--r--aidl_to_cpp.cpp21
-rw-r--r--aidl_to_cpp.h2
-rw-r--r--generate_cpp.cpp52
3 files changed, 48 insertions, 27 deletions
diff --git a/aidl_to_cpp.cpp b/aidl_to_cpp.cpp
index 9dba75a8..d5a9f025 100644
--- a/aidl_to_cpp.cpp
+++ b/aidl_to_cpp.cpp
@@ -105,7 +105,7 @@ const static std::unordered_map<std::string, TypeInfo> kTypeInfoMap = {
// missing List, Map, ParcelFileDescriptor, IBinder
};
-TypeInfo GetTypeInfo(const AidlTypenames&, const AidlTypeSpecifier& aidl) {
+TypeInfo GetTypeInfo(const AidlTypeSpecifier& aidl) {
CHECK(aidl.IsResolved()) << aidl.ToString();
const string& aidl_name = aidl.GetName();
@@ -120,21 +120,28 @@ TypeInfo GetTypeInfo(const AidlTypenames&, const AidlTypeSpecifier& aidl) {
return info;
}
+inline bool CanWriteLog(const TypeInfo& t) {
+ return t.cpp_name != "";
+}
+
+bool CanWriteLog(const AidlTypeSpecifier& aidl) {
+ return CanWriteLog(GetTypeInfo(aidl));
+}
+
void WriteLogFor(const CodeGeneratorContext& c) {
- const TypeInfo info = GetTypeInfo(c.types, c.type);
- if (info.cpp_name == "") {
+ const TypeInfo info = GetTypeInfo(c.type);
+ if (!CanWriteLog(info)) {
return;
}
const string var_object_expr = ((c.isPointer ? "*" : "")) + c.name;
if (c.type.IsArray()) {
- c.writer << c.log << "[\"" << c.name << "\"] = Json::Value(Json::arrayValue);\n";
- c.writer << "for (const auto& v: " << var_object_expr << ") " << c.log << "[\"" << c.name
- << "\"].append(";
+ c.writer << c.log << " = Json::Value(Json::arrayValue);\n";
+ c.writer << "for (const auto& v: " << var_object_expr << ") " << c.log << ".append(";
info.toJsonValueExpr(c, "v");
c.writer << ");";
} else {
- c.writer << c.log << "[\"" << c.name << "\"] = ";
+ c.writer << c.log << " = ";
info.toJsonValueExpr(c, var_object_expr);
c.writer << ";";
}
diff --git a/aidl_to_cpp.h b/aidl_to_cpp.h
index 8aff3719..ca5a6cd0 100644
--- a/aidl_to_cpp.h
+++ b/aidl_to_cpp.h
@@ -38,7 +38,7 @@ struct CodeGeneratorContext {
// Emits code that writes name and value of an argument or the return value to
// the Json object
void WriteLogFor(const CodeGeneratorContext& c);
-
+bool CanWriteLog(const AidlTypeSpecifier& aidl);
std::string GetTransactionIdFor(const AidlMethod& method);
} // namespace cpp
} // namespace aidl
diff --git a/generate_cpp.cpp b/generate_cpp.cpp
index 544a68f6..ca7d7d69 100644
--- a/generate_cpp.cpp
+++ b/generate_cpp.cpp
@@ -225,21 +225,38 @@ string BuildHeaderGuard(const AidlDefinedType& defined_type, ClassNames header_t
return ret;
}
+void WriteLogForArguments(CodeWriterPtr& writer, const AidlArgument& a, const TypeNamespace& types,
+ bool isServer, string logVarName) {
+ if (!CanWriteLog(a.GetType())) {
+ return;
+ }
+ string logElementVarName = "_log_arg_element";
+ (*writer) << "{\n";
+ (*writer).Indent();
+ (*writer) << "Json::Value " << logElementVarName << "(Json::objectValue);\n";
+ string varName = isServer ? BuildVarName(a) : a.GetName();
+ (*writer) << logElementVarName << "[\"name\"] = \"" << varName << "\";\n";
+
+ bool isPointer = a.IsOut() && !isServer;
+ WriteLogFor({*(writer.get()), types.typenames_, a.GetType(), varName, isPointer,
+ logElementVarName + "[\"value\"]"});
+ (*writer) << logVarName << ".append(" << logElementVarName << ");\n";
+ (*writer) << "}\n";
+ (*writer).Dedent();
+}
+
const string GenLogBeforeExecute(const string className, const AidlMethod& method,
const TypeNamespace& types, bool isServer) {
string code;
CodeWriterPtr writer = CodeWriter::ForString(&code);
- (*writer) << "Json::Value _log_input_args(Json::objectValue);\n";
+ (*writer) << "Json::Value _log_input_args(Json::arrayValue);\n";
(*writer) << "if (" << className << "::logFunc != nullptr) {\n";
(*writer).Indent();
for (const auto& a : method.GetArguments()) {
if (a->IsIn()) {
- string varName = isServer ? BuildVarName(*a) : a->GetName();
- bool isPointer = a->IsOut() && !isServer;
- WriteLogFor(
- {*(writer.get()), types.typenames_, a->GetType(), varName, isPointer, "_log_input_args"});
+ WriteLogForArguments(writer, *a, types, isServer, "_log_input_args");
}
}
@@ -277,14 +294,14 @@ const string GenLogAfterExecute(const string className, const AidlInterface& int
// interface_name: "foo.bar.IFoo",
// method_name: "TestMethod",
// (proxy|stub)_address: "0x12345678",
- // input_args: {
- // arg1: 30,
- // arg2: ["apple", "grape"],
- // },
- // output_args: {
- // arg2: ["mango", "banana"],
- // arg3: "10.5",
- // },
+ // input_args: [
+ // {name: "arg1", value: 30,},
+ // {name: "arg2", value: ["apple", "grape"],},
+ // ],
+ // output_args: [
+ // {name: "arg2", value: ["mango", "banana"],},
+ // {name: "arg3", value: "10.5",},
+ // ],
// _aidl_return: "ok",
// binder_status: {
// exception_code: -8,
@@ -306,7 +323,7 @@ const string GenLogAfterExecute(const string className, const AidlInterface& int
(*writer) << "_log_transaction[\"" << (isServer ? "stub_address" : "proxy_address") << "\"] = "
<< "Json::Value(android::base::StringPrintf(\"0x%%p\", this));\n";
(*writer) << "_log_transaction[\"input_args\"] = _log_input_args;\n";
- (*writer) << "Json::Value _log_output_args(Json::objectValue);\n";
+ (*writer) << "Json::Value _log_output_args(Json::arrayValue);\n";
(*writer) << "Json::Value _log_status(Json::objectValue);\n";
(*writer) << "_log_status[\"exception_code\"] = Json::Value(" << statusVarName
@@ -321,17 +338,14 @@ const string GenLogAfterExecute(const string className, const AidlInterface& int
(*writer) << "_log_transaction[\"binder_status\"] = _log_status;\n";
for (const auto& a : method.GetOutArguments()) {
- string varName = isServer ? BuildVarName(*a) : a->GetName();
- bool isPointer = !isServer;
- WriteLogFor(
- {*(writer.get()), types.typenames_, a->GetType(), varName, isPointer, "_log_output_args"});
+ WriteLogForArguments(writer, *a, types, isServer, "_log_output_args");
}
(*writer) << "_log_transaction[\"output_args\"] = _log_output_args;\n";
if (method.GetType().GetName() != "void") {
WriteLogFor({*(writer.get()), types.typenames_, method.GetType(), returnVarName, !isServer,
- "_log_transaction"});
+ "_log_transaction[\"" + returnVarName + "\"]"});
}
// call the user-provided function with the Json object for the entire