// MessageToProtocolRequest // // Converts a IMessage representing a method call (IMethodCallMessage) // into the Ice protocol representation, and writes it to stream outStream. public static void MessageToProtocolRequest(Stream outStream, IMessage msg) { IMethodCallMessage mcall = msg as IMethodCallMessage; Ice.ProtocolWriter pw = new Ice.ProtocolWriter(outStream); // extract message bits from mcall Ice.Identity id = (Ice.Identity)mcall.LogicalCallContext.GetData("__iceIdentity"); string[] facetPath = (string[])mcall.LogicalCallContext.GetData("__iceFacetPath"); Ice.OperationMode opMode = (Ice.OperationMode)mcall.LogicalCallContext.GetData("__iceOperationMode"); Ice.Context ctx = (Ice.Context)mcall.LogicalCallContext.GetData("__iceContext"); bool oneWay = (bool)mcall.LogicalCallContext.GetData("__iceOneWay"); int thisRequestId = 0; if (!oneWay) { thisRequestId = IceChannelUtils.NextRequestId; } mcall.LogicalCallContext.SetData("__iceRequestId", thisRequestId); ParameterInfo[] paramInfos = mcall.MethodBase.GetParameters(); // Create an Ice protocol message pw.BeginMessage(Ice.MessageType.Request); pw.WriteRequestMessageHeader(thisRequestId, id, facetPath, mcall.MethodName, Ice.OperationMode.Normal, ctx); // now write the args pw.BeginEncapsulation(); for (int i = 0; i < mcall.ArgCount; i++) { if (!paramInfos[i].IsOut) { if (Attribute.GetCustomAttribute(paramInfos[i], typeof(Ice.AsProxy)) != null) { pw.WriteProxy(mcall.Args[i], paramInfos[i].ParameterType); } else { pw.WriteObject(mcall.Args[i], paramInfos[i].ParameterType); } } } pw.WriteClassInstances(); pw.EndEncapsulation(); pw.EndMessage(); }
// MessageToProtocolRequest // // Converts a IMessage representing a method call (IMethodCallMessage) // into the Ice protocol representation, and writes it to stream outStream. public static void MessageToProtocolRequest (Stream outStream, IMessage msg) { IMethodCallMessage mcall = msg as IMethodCallMessage; Ice.ProtocolWriter pw = new Ice.ProtocolWriter(outStream); // extract message bits from mcall Ice.Identity id = (Ice.Identity) mcall.LogicalCallContext.GetData("__iceIdentity"); string[] facetPath = (string[]) mcall.LogicalCallContext.GetData("__iceFacetPath"); Ice.OperationMode opMode = (Ice.OperationMode) mcall.LogicalCallContext.GetData("__iceOperationMode"); Ice.Context ctx = (Ice.Context) mcall.LogicalCallContext.GetData("__iceContext"); bool oneWay = (bool) mcall.LogicalCallContext.GetData("__iceOneWay"); int thisRequestId = 0; if (!oneWay) thisRequestId = IceChannelUtils.NextRequestId; mcall.LogicalCallContext.SetData("__iceRequestId", thisRequestId); ParameterInfo[] paramInfos = mcall.MethodBase.GetParameters(); // Create an Ice protocol message pw.BeginMessage (Ice.MessageType.Request); pw.WriteRequestMessageHeader (thisRequestId, id, facetPath, mcall.MethodName, Ice.OperationMode.Normal, ctx); // now write the args pw.BeginEncapsulation(); for (int i = 0; i < mcall.ArgCount; i++) { if (!paramInfos[i].IsOut) { if (Attribute.GetCustomAttribute (paramInfos[i], typeof(Ice.AsProxy)) != null) pw.WriteProxy (mcall.Args[i], paramInfos[i].ParameterType); else pw.WriteObject (mcall.Args[i], paramInfos[i].ParameterType); } } pw.WriteClassInstances(); pw.EndEncapsulation(); pw.EndMessage(); }
private void ListenerThread() { if (_e is Ice.TcpEndpoint) { // loop and accept socket connections, then convert them // into Endpoints, and instantiate a ReceiverDispatcher for // them. while (true) { Socket clientSocket = _listener.AcceptSocket(); Ice.Endpoint ne = (Ice.Endpoint)_e.Clone(); Ice.TcpEndpoint tcpep = ne as Ice.TcpEndpoint; if (tcpep == null) { throw new NotSupportedException("Only TCP endpoints are supported"); } tcpep.Socket = clientSocket; if (tcpep.HasConnection) { // validate the connection MemoryStream ms = new MemoryStream(); Ice.ProtocolWriter pw = new Ice.ProtocolWriter(ms); pw.BeginMessage(MessageType.ValidateConnection); pw.EndMessage(); ms.WriteTo(tcpep.Stream); } tcpep.ReceiverDispatcher = new Ice.ReceiverDispatcher(tcpep, new MessageRequestDelegate(MessageRequestHandler)); } } else { throw new NotImplementedException("ListenerThread managed to get a non-Tcp Ice.Endpoint"); } }
private void ListenerThread () { if (_e is Ice.TcpEndpoint) { // loop and accept socket connections, then convert them // into Endpoints, and instantiate a ReceiverDispatcher for // them. while (true) { Socket clientSocket = _listener.AcceptSocket(); Ice.Endpoint ne = (Ice.Endpoint) _e.Clone(); Ice.TcpEndpoint tcpep = ne as Ice.TcpEndpoint; if (tcpep == null) { throw new NotSupportedException ("Only TCP endpoints are supported"); } tcpep.Socket = clientSocket; if (tcpep.HasConnection) { // validate the connection MemoryStream ms = new MemoryStream(); Ice.ProtocolWriter pw = new Ice.ProtocolWriter(ms); pw.BeginMessage (MessageType.ValidateConnection); pw.EndMessage (); ms.WriteTo (tcpep.Stream); } tcpep.ReceiverDispatcher = new Ice.ReceiverDispatcher (tcpep, new MessageRequestDelegate (MessageRequestHandler)); } } else { throw new NotImplementedException("ListenerThread managed to get a non-Tcp Ice.Endpoint"); } }
// MessageToProtocolReply // // Given a IMethodReturnMessage replyMsg, which originated from the // original IMethodMessage callMsg, serialize the reply using the // Ice protocol to outStream public static void MessageToProtocolReply(IMessage callMsg, IMessage replyMsg, Stream outStream) { IMethodMessage cmsg = callMsg as IMethodMessage; IMethodReturnMessage retmsg = replyMsg as IMethodReturnMessage; if (cmsg == null || retmsg == null) { throw new InvalidOperationException("no IMethodReturnMessage????"); } if (retmsg.Exception != null) { Trace.WriteLine("retmsg.Exception != null, don't know what to do"); Console.WriteLine(retmsg.Exception); return; } int requestId = (int)callMsg.Properties["__iceRequestId"]; Ice.ProtocolWriter pw = new Ice.ProtocolWriter(outStream); pw.BeginMessage(Ice.MessageType.Reply); pw.WriteReplyMessageHeader(MessageReplyType.Success, requestId); pw.BeginEncapsulation(); // first write the out params object[] outArgs = retmsg.OutArgs; int curOutArg = 0; MethodInfo mi = cmsg.MethodBase as MethodInfo; ParameterInfo[] paramInfos = mi.GetParameters(); foreach (ParameterInfo pinfo in paramInfos) { if (pinfo.IsOut) { if (Attribute.GetCustomAttribute(pinfo, typeof(Ice.AsProxy)) != null) { pw.WriteProxy(outArgs[curOutArg++], pinfo.ParameterType); } else { pw.WriteObject(outArgs[curOutArg++], pinfo.ParameterType); } } } Type rtype = mi.ReturnType; if (rtype != null && rtype != typeof(void)) { if (mi.ReturnTypeCustomAttributes.IsDefined(typeof(Ice.AsProxy), true)) { pw.WriteProxy(retmsg.ReturnValue, rtype); } else { pw.WriteObject(retmsg.ReturnValue, rtype); } } pw.WriteClassInstances(); pw.EndEncapsulation(); pw.EndMessage(); }
// MessageToProtocolReply // // Given a IMethodReturnMessage replyMsg, which originated from the // original IMethodMessage callMsg, serialize the reply using the // Ice protocol to outStream public static void MessageToProtocolReply (IMessage callMsg, IMessage replyMsg, Stream outStream) { IMethodMessage cmsg = callMsg as IMethodMessage; IMethodReturnMessage retmsg = replyMsg as IMethodReturnMessage; if (cmsg == null || retmsg == null) throw new InvalidOperationException ("no IMethodReturnMessage????"); if (retmsg.Exception != null) { Trace.WriteLine ("retmsg.Exception != null, don't know what to do"); Console.WriteLine (retmsg.Exception); return; } int requestId = (int) callMsg.Properties["__iceRequestId"]; Ice.ProtocolWriter pw = new Ice.ProtocolWriter (outStream); pw.BeginMessage (Ice.MessageType.Reply); pw.WriteReplyMessageHeader (MessageReplyType.Success, requestId); pw.BeginEncapsulation(); // first write the out params object[] outArgs = retmsg.OutArgs; int curOutArg = 0; MethodInfo mi = cmsg.MethodBase as MethodInfo; ParameterInfo[] paramInfos = mi.GetParameters(); foreach (ParameterInfo pinfo in paramInfos) { if (pinfo.IsOut) { if (Attribute.GetCustomAttribute (pinfo, typeof(Ice.AsProxy)) != null) pw.WriteProxy (outArgs[curOutArg++], pinfo.ParameterType); else pw.WriteObject (outArgs[curOutArg++], pinfo.ParameterType); } } Type rtype = mi.ReturnType; if (rtype != null && rtype != typeof(void)) { if (mi.ReturnTypeCustomAttributes.IsDefined (typeof(Ice.AsProxy), true)) pw.WriteProxy (retmsg.ReturnValue, rtype); else pw.WriteObject (retmsg.ReturnValue, rtype); } pw.WriteClassInstances(); pw.EndEncapsulation(); pw.EndMessage (); }