public override IMessage Invoke(IMessage message) { IMethodCallMessage callMessage = (IMethodCallMessage)message; object defaultRetVal = GetDefaultReturn(callMessage.MethodBase, callMessage.InArgs); if (defaultRetVal != null) { MethodReturnMessageWrapper defaultReturnMessage = new MethodReturnMessageWrapper((IMethodReturnMessage)message); defaultReturnMessage.ReturnValue = defaultRetVal; return(defaultReturnMessage); } object[] outArgs; object retVal; Exception exception; busObject.Invoke(callMessage.MethodBase, callMessage.MethodName, callMessage.InArgs, out outArgs, out retVal, out exception); MethodReturnMessageWrapper returnMessage = new MethodReturnMessageWrapper((IMethodReturnMessage)message); returnMessage.Exception = exception; returnMessage.ReturnValue = retVal; return(returnMessage); }
public override IMessage Invoke(IMessage message) { IMethodCallMessage callMessage = (IMethodCallMessage)message; StackItem[] stack = new StackItem[callMessage.ArgCount + 1]; #if DEBUG if ((QDebug.DebugChannel() & QtDebugChannel.QTDB_TRANSPARENT_PROXY) != 0) { Console.WriteLine("ENTER SignalInvocation.Invoke() MethodName: {0}.{1} Type: {2} ArgCount: {3}", instance, callMessage.MethodName, callMessage.TypeName, callMessage.ArgCount.ToString()); } #endif unsafe { fixed(StackItem *stackPtr = stack) { for (int i = 0; i < callMessage.ArgCount; i++) { SmokeMarshallers.UnboxToStackItem(callMessage.Args[i], stackPtr + i + 1); } IMethodReturnMessage returnMessage = new ReturnMessage(null, callMessage); /*(IMethodReturnMessage) message;*/ MethodReturnMessageWrapper returnValue = new MethodReturnMessageWrapper((IMethodReturnMessage)returnMessage); #if DEBUG GCHandle instanceHandle = DebugGCHandle.Alloc(instance); #else GCHandle instanceHandle = GCHandle.Alloc(instance); #endif Qyoto.CPPMethod signalEntry = Qyoto.GetSignalSignature(signalsInterface, (MethodInfo)callMessage.MethodBase); Type returnType = ((MethodInfo)returnMessage.MethodBase).ReturnType; SignalEmit(signalEntry.signature, signalEntry.type, (IntPtr)instanceHandle, (IntPtr)stackPtr, callMessage.ArgCount); if (returnType != typeof(void)) { returnValue.ReturnValue = SmokeMarshallers.BoxFromStackItem(returnType, 0, stackPtr); } returnMessage = returnValue; return(returnMessage); } } }
public virtual IMessage SyncProcessMessage(object o, IMessageSink sink, IMessage msg) { Begin(o, msg); IMethodReturnMessage returnedMessage = (IMethodReturnMessage)sink.SyncProcessMessage(msg); if (returnedMessage.Exception != null) { if (Error(returnedMessage.Exception, o, msg)) { returnedMessage = new MethodReturnMessageWrapper(returnedMessage) { Exception = null }; } } End(o, msg); return(returnedMessage); }
public override IMessage Invoke(IMessage message) { IMethodCallMessage callMessage = (IMethodCallMessage)message; StackItem[] stack = new StackItem[callMessage.ArgCount + 1]; #if DEBUG if ((QDebug.DebugChannel() & QtDebugChannel.QTDB_TRANSPARENT_PROXY) != 0) { Console.WriteLine("ENTER SignalInvocation.Invoke() MethodName: {0}.{1} Type: {2} ArgCount: {3}", instance, callMessage.MethodName, callMessage.TypeName, callMessage.ArgCount.ToString()); } #endif if (callMessage.MethodSignature != null) { Type[] types = (Type[])callMessage.MethodSignature; for (int i = 0; i < callMessage.ArgCount; i++) { if (callMessage.Args[i] == null) { unsafe { stack[i + 1].s_class = (IntPtr)0; } } else if (types[i] == typeof(bool)) { stack[i + 1].s_bool = (bool)callMessage.Args[i]; } else if (types[i] == typeof(sbyte)) { stack[i + 1].s_char = (sbyte)callMessage.Args[i]; } else if (types[i] == typeof(byte)) { stack[i + 1].s_uchar = (byte)callMessage.Args[i]; } else if (types[i] == typeof(char)) { stack[i + 1].s_uchar = (byte)(char)callMessage.Args[i]; } else if (types[i] == typeof(short)) { stack[i + 1].s_short = (short)callMessage.Args[i]; } else if (types[i] == typeof(ushort)) { stack[i + 1].s_ushort = (ushort)callMessage.Args[i]; } else if (types[i] == typeof(int) || types[i].IsEnum) { stack[i + 1].s_int = (int)callMessage.Args[i]; } else if (types[i] == typeof(uint)) { stack[i + 1].s_uint = (uint)callMessage.Args[i]; } else if (types[i] == typeof(long)) { stack[i + 1].s_long = (long)callMessage.Args[i]; } else if (types[i] == typeof(ulong)) { stack[i + 1].s_ulong = (ulong)callMessage.Args[i]; } else if (types[i] == typeof(float)) { stack[i + 1].s_float = (float)callMessage.Args[i]; } else if (types[i] == typeof(double)) { stack[i + 1].s_double = (double)callMessage.Args[i]; } else if (types[i] == typeof(string)) { #if DEBUG stack[i + 1].s_class = (IntPtr)DebugGCHandle.Alloc(callMessage.Args[i]); #else stack[i + 1].s_class = (IntPtr)GCHandle.Alloc(callMessage.Args[i]); #endif } else { #if DEBUG stack[i + 1].s_class = (IntPtr)DebugGCHandle.Alloc(callMessage.Args[i]); #else stack[i + 1].s_class = (IntPtr)GCHandle.Alloc(callMessage.Args[i]); #endif } } } IMethodReturnMessage returnMessage = new ReturnMessage(null, callMessage); /*(IMethodReturnMessage) message;*/ MethodReturnMessageWrapper returnValue = new MethodReturnMessageWrapper((IMethodReturnMessage)returnMessage); #if DEBUG GCHandle instanceHandle = DebugGCHandle.Alloc(instance); #else GCHandle instanceHandle = GCHandle.Alloc(instance); #endif Qyoto.CPPMethod signalEntry = Qyoto.GetSignalSignature(signalsInterface, (MethodInfo)callMessage.MethodBase); unsafe { fixed(StackItem *stackPtr = stack) { Type returnType = ((MethodInfo)returnMessage.MethodBase).ReturnType; SignalEmit(signalEntry.signature, signalEntry.type, (IntPtr)instanceHandle, (IntPtr)stackPtr, callMessage.ArgCount); if (returnType == typeof(void)) { ; } else if (returnType == typeof(bool)) { returnValue.ReturnValue = stack[0].s_bool; } else if (returnType == typeof(sbyte)) { returnValue.ReturnValue = stack[0].s_char; } else if (returnType == typeof(byte)) { returnValue.ReturnValue = stack[0].s_uchar; } else if (returnType == typeof(char)) { returnValue.ReturnValue = (char)stack[0].s_uchar; } else if (returnType == typeof(short)) { returnValue.ReturnValue = stack[0].s_short; } else if (returnType == typeof(ushort)) { returnValue.ReturnValue = stack[0].s_ushort; } else if (returnType.IsEnum) { returnValue.ReturnValue = Enum.ToObject(returnType, stack[0].s_int); } else if (returnType == typeof(int)) { returnValue.ReturnValue = stack[0].s_int; } else if (returnType == typeof(uint)) { returnValue.ReturnValue = stack[0].s_uint; } else if (returnType == typeof(long)) { // s_long will contain the wrong value on 32 bit platforms // (i.e. where a native C++ 'long' isn't at least 64 bit) returnValue.ReturnValue = (SmokeMarshallers.SizeOfNativeLong < sizeof(long))? stack[0].s_int : stack[0].s_long; } else if (returnType == typeof(ulong)) { returnValue.ReturnValue = (SmokeMarshallers.SizeOfNativeLong < sizeof(long))? stack[0].s_uint : stack[0].s_ulong; } else if (returnType == typeof(float)) { returnValue.ReturnValue = stack[0].s_float; } else if (returnType == typeof(double)) { returnValue.ReturnValue = stack[0].s_double; } else if (returnType == typeof(string)) { if (stack[0].s_class != IntPtr.Zero) { returnValue.ReturnValue = ((GCHandle)stack[0].s_class).Target; #if DEBUG DebugGCHandle.Free((GCHandle)stack[0].s_class); #else ((GCHandle)stack[0].s_class).SynchronizedFree(); #endif } } else { if (stack[0].s_class != IntPtr.Zero) { returnValue.ReturnValue = ((GCHandle)stack[0].s_class).Target; #if DEBUG DebugGCHandle.Free((GCHandle)stack[0].s_class); #else ((GCHandle)stack[0].s_class).SynchronizedFree(); #endif } } } } returnMessage = returnValue; return(returnMessage); }