private void IssueErrorReply(MessageContainer method_call, Exception raisedException, MethodInfo mi = null) { Message replyMsg; // BusException allows precisely formatted Error messages. BusException busException = raisedException as BusException; if (busException != null) { replyMsg = method_call.CreateError(busException.ErrorName, busException.ErrorMessage); } else if (raisedException is ArgumentException && mi != null && mi != null && raisedException.TargetSite.Name == mi.Name) { // Name match trick above is a hack since we don't have the resolved MethodInfo. ArgumentException argException = (ArgumentException)raisedException; using (System.IO.StringReader sr = new System.IO.StringReader(argException.Message)) { replyMsg = method_call.CreateError("org.freedesktop.DBus.Error.InvalidArgs", sr.ReadLine()); } } else { replyMsg = method_call.CreateError(Mapper.GetInterfaceName(raisedException.GetType()), raisedException.Message); } conn.Send(replyMsg); }
private void IssueReply(MessageContainer method_call, Signature outSig, MessageWriter retWriter, MethodInfo mi, Exception raisedException) { Message msg = method_call.Message; if (!msg.ReplyExpected) { return; } Message replyMsg; if (raisedException == null) { MessageContainer method_return = new MessageContainer { Type = MessageType.MethodReturn, Destination = method_call.Sender, ReplySerial = msg.Header.Serial }; replyMsg = method_return.Message; replyMsg.AttachBodyTo(retWriter); replyMsg.Signature = outSig; } else { // BusException allows precisely formatted Error messages. BusException busException = raisedException as BusException; if (busException != null) { replyMsg = method_call.CreateError(busException.ErrorName, busException.ErrorMessage); } else if (raisedException is ArgumentException && raisedException.TargetSite.Name == mi.Name) { // Name match trick above is a hack since we don't have the resolved MethodInfo. ArgumentException argException = (ArgumentException)raisedException; using (System.IO.StringReader sr = new System.IO.StringReader(argException.Message)) { replyMsg = method_call.CreateError("org.freedesktop.DBus.Error.InvalidArgs", sr.ReadLine()); } } else { replyMsg = method_call.CreateError(Mapper.GetInterfaceName(raisedException.GetType()), raisedException.Message); } } conn.Send(replyMsg); }
public virtual void HandleMethodCall(MessageContainer method_call) { MethodInfo mi; if (!methodInfoCache.TryGetValue(method_call.Member, out mi)) { methodInfoCache[method_call.Member] = mi = Mapper.GetMethod(Object.GetType(), method_call); } if (mi == null) { conn.MaybeSendUnknownMethodError(method_call); return; } MethodCaller mCaller; if (!mCallers.TryGetValue(mi, out mCaller)) { mCaller = TypeImplementer.GenCaller(mi); mCallers[mi] = mCaller; } Signature inSig, outSig; TypeImplementer.SigsForMethod(mi, out inSig, out outSig); Message msg = method_call.Message; MessageReader msgReader = new MessageReader(msg); MessageWriter retWriter = new MessageWriter(); Exception raisedException = null; try { mCaller(Object, msgReader, msg, retWriter); } catch (Exception e) { raisedException = e; } if (!msg.ReplyExpected) { return; } Message replyMsg; if (raisedException == null) { MessageContainer method_return = new MessageContainer { Type = MessageType.MethodReturn, ReplySerial = msg.Header.Serial }; replyMsg = method_return.Message; replyMsg.AttachBodyTo(retWriter); replyMsg.Signature = outSig; } else { // BusException allows precisely formatted Error messages. BusException busException = raisedException as BusException; if (busException != null) { replyMsg = method_call.CreateError(busException.ErrorName, busException.ErrorMessage); } else if (raisedException is ArgumentException && raisedException.TargetSite.Name == mi.Name) { // Name match trick above is a hack since we don't have the resolved MethodInfo. ArgumentException argException = (ArgumentException)raisedException; using (System.IO.StringReader sr = new System.IO.StringReader(argException.Message)) { replyMsg = method_call.CreateError("org.freedesktop.DBus.Error.InvalidArgs", sr.ReadLine()); } } else { replyMsg = method_call.CreateError(Mapper.GetInterfaceName(raisedException.GetType()), raisedException.Message); } } if (method_call.Sender != null) { replyMsg.Header[FieldCode.Destination] = method_call.Sender; } conn.Send(replyMsg); }
public virtual void HandleMethodCall(MethodCall method_call) { Type type = obj.GetType(); //object retObj = type.InvokeMember (msg.Member, BindingFlags.InvokeMethod, null, obj, MessageHelper.GetDynamicValues (msg)); //TODO: there is no member name mapping for properties etc. yet // FIXME: Inefficient to do this on every call MethodInfo mi = Mapper.GetMethod(type, method_call); if (mi == null) { conn.MaybeSendUnknownMethodError(method_call); return; } MethodCaller2 mCaller; if (!mCallers.TryGetValue(mi, out mCaller)) { //mCaller = TypeImplementer.GenCaller (mi, obj); mCaller = TypeImplementer.GenCaller2(mi); mCallers[mi] = mCaller; } Signature inSig, outSig; TypeImplementer.SigsForMethod(mi, out inSig, out outSig); Message msg = method_call.message; MessageReader msgReader = new MessageReader(method_call.message); MessageWriter retWriter = new MessageWriter(); /* * MessageWriter retWriter = null; * if (msg.ReplyExpected) * retWriter = new MessageWriter (); */ Exception raisedException = null; try { //mCaller (msgReader, method_call.message, retWriter); mCaller(obj, msgReader, method_call.message, retWriter); } catch (Exception e) { raisedException = e; } if (!msg.ReplyExpected) { return; } Message replyMsg; if (raisedException == null) { MethodReturn method_return = new MethodReturn(msg.Header.Serial); replyMsg = method_return.message; replyMsg.Body = retWriter.ToArray(); replyMsg.Signature = outSig; } else { Error error; // BusException allows precisely formatted Error messages. BusException busException = raisedException as BusException; if (busException != null) { error = method_call.CreateError(busException.ErrorName, busException.ErrorMessage); } else if (raisedException is ArgumentException && raisedException.TargetSite.Name == mi.Name) { // Name match trick above is a hack since we don't have the resolved MethodInfo. ArgumentException argException = (ArgumentException)raisedException; using (System.IO.StringReader sr = new System.IO.StringReader(argException.Message)) { error = method_call.CreateError("org.freedesktop.DBus.Error.InvalidArgs", sr.ReadLine()); } } else { error = method_call.CreateError(Mapper.GetInterfaceName(raisedException.GetType()), raisedException.Message); } replyMsg = error.message; } if (method_call.Sender != null) { replyMsg.Header[FieldCode.Destination] = method_call.Sender; } conn.Send(replyMsg); }