for (const auto& i : decls) {
if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
continue;
-
- GenDeclaration(stream, iface, *i);
- GenBrace(stream, 0, [&]() {
- GenInvocation(stream, *i);
- }, false);
- stream << NLine(1);
+ GenInvocation(stream, iface, *i);
}
}
void CppProxyBodyGen::GenInvocation(std::ofstream& stream,
- const Declaration& decl) {
- stream << CB_INVOCATION_PRE;
-
- // Serialize
- stream << Tab(1)
- << "rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::"
- << decl.GetID() << "));" << NLine(1);
- std::string m;
- std::string l;
- for (const auto& i : decl.GetParameters()) {
- auto& pt = i->GetParameterType();
- if (pt.GetDirection() == ParameterType::Direction::OUT)
- continue;
- m += GenPrivateSharingRequest(pt.GetBaseType(), i->GetID());
- m += ConvertTypeToSerializer(pt.GetBaseType(), i->GetID(), "p");
- if (IsDelegateType(pt.GetBaseType())) {
- l += "delegate_list_.emplace_back(" + i->GetID() + ".release());\n";
- }
- }
- stream << AddIndent(TAB_SIZE, m) << NLine(1);
-
- stream << Tab(1) << "std::lock_guard<std::recursive_mutex> lock(mutex_);"
- << NLine(1);
-
- if (!l.empty())
- stream << AddIndent(TAB_SIZE, l);
-
- stream << CB_INVOCATION_MID;
-
- // Deserialize
- if (decl.GetMethodType() == Declaration::MethodType::ASYNC) {
- stream << Tab(1) << "rpc_port_parcel_destroy(p);"
- << NLine(1);
- return;
- }
+ const Interface& iface, const Declaration& decl) {
+ ReplaceAll(CB_INVOCATION)
+ .Select("<ASYNC_OR_SYNC>",
+ { CB_INVOCATION_ASYNC, CB_INVOCATION_SYNC }, [&]() {
+ if (decl.GetMethodType() == Declaration::MethodType::ASYNC)
+ return 0;
+ return 1;
+ })
+ .Change("<RET_TYPE>", ConvertTypeToString(decl.GetType()))
+ .Change("<IFACE>", iface.GetID())
+ .Change("<METHOD>", decl.GetID())
+ .Change("<PARAMS>", GetParameters(decl.GetParameters()))
+ .Change("<SERIALIZE>", [&]() {
+ std::string m;
+ std::string l;
+ std::string ret;
+ for (const auto& i : decl.GetParameters()) {
+ auto& pt = i->GetParameterType();
+ if (pt.GetDirection() == ParameterType::Direction::OUT)
+ continue;
+ m += GenPrivateSharingRequest(pt.GetBaseType(), i->GetID());
+ m += ConvertTypeToSerializer(pt.GetBaseType(), i->GetID(), "p");
+ if (IsDelegateType(pt.GetBaseType())) {
+ l += "delegate_list_.emplace_back(" + i->GetID() + ".release());\n";
+ }
+ }
- stream << NLine(1);
- stream << Tab(1) << ConvertTypeToString(decl.GetType()) << " ret;";
+ ret = AddIndent(TAB_SIZE, m) + NLine(1);
+ ret += Tab(1) + "std::lock_guard<std::recursive_mutex> lock(mutex_);"
+ + NLine(1);
- auto parcel_read = [&]() -> std::string {
+ if (!l.empty())
+ ret += AddIndent(TAB_SIZE, l);
+ return ret;
+ })
+ .Change("<DESERIALIZE>", [&]() {
std::string code;
for (const auto& i : decl.GetParameters()) {
if (i->GetParameterType().GetDirection() ==
}
return code;
- };
- stream << ReplaceAll(CB_INVOCATION_RECEIVE, "[PARCEL_READ]", parcel_read());
-
- stream << CB_INVOCATION_END;
+ })
+ .Out(stream);
}
} // namespace tidl
}
)__cpp_cb";
-const char CB_INVOCATION_PRE[] =
-R"__cpp_cb( if (port_ == nullptr) {
+const char CB_INVOCATION[] =
+R"__cpp_cb(
+<RET_TYPE> <IFACE>::<METHOD>(<PARAMS>) {
+ if (port_ == nullptr) {
_E("Not connected");
throw NotConnectedSocketException();
}
int seq_num_ = -1;
rpc_port_parcel_header_get_seq_num(header_, &seq_num_);
_W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_);
-)__cpp_cb";
-
-const char CB_INVOCATION_MID[] =
-R"__cpp_cb(
+ rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::<METHOD>));
+<SERIALIZE>
// Send
int r = rpc_port_parcel_send(p, port_);
if (r != RPC_PORT_ERROR_NONE) {
rpc_port_parcel_destroy(p);
throw InvalidIOException();
}
+<ASYNC_OR_SYNC>
+}
)__cpp_cb";
-/**
- * [PARCEL_READ] The implementation to read the data from the parcel.
- */
-const char CB_INVOCATION_RECEIVE[] =
+const char CB_INVOCATION_ASYNC[] =
R"__cpp_cb(
+ rpc_port_parcel_destroy(p);
+)__cpp_cb";
+
+const char CB_INVOCATION_SYNC[] =
+R"__cpp_cb(
+ <RET_TYPE> ret;
bool done_ = false;
do {
rpc_port_parcel_h parcel_received = nullptr;
}
done_ = true;
-[PARCEL_READ]
+<DESERIALIZE>
rpc_port_parcel_destroy(parcel_received);
} while (!done_);
-)__cpp_cb";
-const char CB_INVOCATION_END[] =
-R"__cpp_cb(
rpc_port_parcel_destroy(p);
return ret;