From 4107312478ad5160eeeeb9b14d3ec464a76796b3 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Wed, 17 Jan 2018 17:41:00 +0900 Subject: [PATCH] Handle returned data When the proxy app is sending some request to the stub app, the stub app may try to send callback data at the same time. This path will make it possible to handle callback events to get the result data. Change-Id: Idb11a6efe630e055efbfef5aeaecd178a70e6da1 Signed-off-by: Junghoon Park --- idlc/cs_gen/cs_proxy_gen.cc | 66 +++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/idlc/cs_gen/cs_proxy_gen.cc b/idlc/cs_gen/cs_proxy_gen.cc index 4e03844..77e64bd 100644 --- a/idlc/cs_gen/cs_proxy_gen.cc +++ b/idlc/cs_gen/cs_proxy_gen.cc @@ -96,6 +96,21 @@ void CsProxyGen::GenInterface(std::ofstream& stream, const Interface& iface) { " Rejected?.Invoke(this, null);\n" \ "}\n" \ "\n" \ + "private void ProcessReceivedEvent(IntPtr parcel)\n" \ + "{\n" \ + " Interop.LibRPCPort.Parcel.ReadInt32(parcel, out int id);\n" \ + " Interop.LibRPCPort.Parcel.ReadInt32(parcel, out int seqId);\n" \ + "\n" \ + " foreach (var i in _delegateList)\n" \ + " {\n" \ + " if ((int)i.Id == id && i.SeqId == seqId)\n" \ + " {\n" \ + " i.OnReceivedEvent(parcel);\n" \ + " break;\n" \ + " }\n" \ + " }\n" \ + "}\n" \ + "\n" \ "private void OnReceivedEvent(string endPoint, string port_name, IntPtr data)\n" \ "{\n" \ " if (Interop.LibRPCPort.Parcel.CreateFromPort(out IntPtr parcel_received, _port) != 0)\n" \ @@ -105,23 +120,33 @@ void CsProxyGen::GenInterface(std::ofstream& stream, const Interface& iface) { " if (cmd != (int)MethodId.Callback)\n" \ " {\n" \ " Interop.LibRPCPort.Parcel.Destroy(parcel_received);\n" \ - " //TODO\n" \ - " return;\n" \ + " throw new InvalidOperationException(\"Invalid protocol\");\n" \ " }\n" \ "\n" \ - " Interop.LibRPCPort.Parcel.ReadInt32(parcel_received, out int id);\n" \ - " Interop.LibRPCPort.Parcel.ReadInt32(parcel_received, out int seqId);\n" \ + " ProcessReceivedEvent(parcel_received);\n" \ + " Interop.LibRPCPort.Parcel.Destroy(parcel_received);\n" \ + "}\n" \ "\n" \ - " foreach (var i in _delegateList)\n" \ + "private void ConsumeCommand(out IntPtr parcel, IntPtr port)\n" \ + "{\n" \ + " do\n" \ " {\n" \ - " if ((int)i.Id == id && i.SeqId == seqId)\n" \ - " {\n" \ - " i.OnReceivedEvent(parcel_received);\n" \ + " int ret = Interop.LibRPCPort.Parcel.CreateFromPort(out IntPtr p, port);\n" \ + "\n" \ + " if (ret != 0)\n" \ " break;\n" \ + " Interop.LibRPCPort.Parcel.ReadInt32(p, out int cmd);\n" \ + " if (cmd == (int)MethodId.Result)\n" \ + " {\n" \ + " parcel = p;\n" \ + " return;\n" \ " }\n" \ - " }\n" \ "\n" \ - " Interop.LibRPCPort.Parcel.Destroy(parcel_received);\n" \ + " ProcessReceivedEvent(p);\n" \ + " Interop.LibRPCPort.Parcel.Destroy(p);\n" \ + " parcel = IntPtr.Zero;\n" \ + " } while (true);\n" \ + " parcel = IntPtr.Zero;\n" \ "}\n"; stream << Tab(2) << "public class " << iface.GetID() @@ -229,19 +254,14 @@ void CsProxyGen::GenInvocation(std::ofstream& stream, const Declaration& decl) { if (decl.GetMethodType() == Declaration::MethodType::ASYNC) return; - stream << Tab(4) << "// Receive" << NLine(1); - stream << Tab(4) - << "Interop.LibRPCPort.Parcel.CreateFromPort(out IntPtr parcel_received, _port);" - << NLine(1); - stream << Tab(4) - << "Interop.LibRPCPort.Parcel.ReadInt32(parcel_received, out int cmd);" - << NLine(1); - stream << Tab(4) - << "if (cmd != (int)MethodId.Result)" << NLine(1); - GenBrace(stream, TAB_SIZE * 4, [&]() { - //TODO - }); - stream << NLine(1); + const char* receive_block = + "// Receive\n" \ + "ConsumeCommand(out IntPtr parcel_received, _port);\n" \ + "if (parcel_received == IntPtr.Zero)\n" \ + "{\n" \ + " throw new InvalidOperationException(\"Can't receive data\");\n" \ + "}\n"; + stream << AddIndent(TAB_SIZE * 4, receive_block) << NLine(1); for (auto& i : decl.GetParameters().GetParams()) { if (i->GetParameterType().GetDirection() == ParameterType::Direction::IN) { -- 2.7.4