" 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" \
" 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()
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) {