Ejemplo n.º 1
0
        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);
                }
            }
        }