Example #1
0
        static public void InvokeCustomSlot(IntPtr obj, string slotname, IntPtr stack, IntPtr ret)
        {
            QObject qobj = (QObject)((GCHandle)obj).Target;

#if DEBUG
            if ((QDebug.DebugChannel() & QtDebugChannel.QTDB_TRANSPARENT_PROXY) != 0)
            {
                Console.WriteLine("ENTER InvokeCustomSlot() {0}.{1}",
                                  qobj,
                                  slotname);
            }
#endif

            MethodInfo      slot       = Qyoto.GetSlotMethodInfo(qobj.GetType(), slotname);
            ParameterInfo[] parameters = slot.GetParameters();
            object[]        args       = new object[parameters.Length];

            unsafe {
                StackItem *stackPtr = (StackItem *)stack;
                for (int i = 0; i < args.Length; i++)
                {
                    args[i] = SmokeMarshallers.BoxFromStackItem(parameters[i].ParameterType, 0, stackPtr + i);
                }

                object returnValue = slot.Invoke(qobj, args);

                StackItem *retval = (StackItem *)ret;

                if (slot.ReturnType != typeof(void))
                {
                    SmokeMarshallers.UnboxToStackItem(returnValue, retval);
                }
            }
        }
Example #2
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);
                }
            }
        }
Example #3
0
        public static void InvokeMethod(IntPtr instanceHandle, IntPtr methodHandle, IntPtr stack, IntPtr typeIDs)
        {
            object     instance = ((GCHandle)instanceHandle).Target;
            MethodInfo method   = (MethodInfo)((GCHandle)methodHandle).Target;

#if DEBUG
            if ((QDebug.DebugChannel() & QtDebugChannel.QTDB_TRANSPARENT_PROXY) != 0 &&
                (QDebug.DebugChannel() & QtDebugChannel.QTDB_VIRTUAL) != 0)
            {
                Console.WriteLine("ENTER InvokeMethod() {0}.{1}",
                                  instance,
                                  method.Name);
            }
#endif
            unsafe {
                StackItem *     stackPtr   = (StackItem *)stack;
                ParameterInfo[] parameters = method.GetParameters();
                object[]        args       = new object[parameters.Length];
                TypeId *        typeIDsPtr = (TypeId *)typeIDs;

                for (int i = 0; i < args.Length; i++)
                {
                    args[i] = SmokeMarshallers.BoxFromStackItem(parameters[i].ParameterType, (int)typeIDsPtr[i + 1], stackPtr + i + 1);
                }
                object returnValue = method.Invoke(instance, args);
                *      typeIDsPtr  = SmokeMarshallers.GetTypeId(returnValue == null ? typeof(object) : returnValue.GetType());

                //TODO: should this always be unboxing something?
                if (method.ReturnType != typeof(void))
                {
                    SmokeMarshallers.UnboxToStackItem(returnValue, stackPtr);
                }
            }

            return;
        }
Example #4
0
        public object Invoke(string mungedName, string signature, Type returnType, bool refArgs, params object[] args)
        {
#if DEBUG
            if ((QDebug.DebugChannel() & QtDebugChannel.QTDB_TRANSPARENT_PROXY) != 0)
            {
                Console.WriteLine("ENTER SmokeInvocation.Invoke() MethodName: {0}.{1} Type: {2} ArgCount: {3}",
                                  className,
                                  signature,
                                  returnType,
                                  args.Length / 2);
            }
#endif

            if (signature.StartsWith("operator=="))
            {
                if (args[1] == null && args[3] == null)
                {
                    return(true);
                }
                else if (args[1] == null || args[3] == null)
                {
                    return(false);
                }
            }
            ModuleIndex methodId;
            methodId.smoke = IntPtr.Zero;
            methodId.index = -1;
            if (!methodIdCache.TryGetValue(signature, out methodId))
            {
                methodId = FindMethodId(className, mungedName, signature);

                if (methodId.index == -1)
                {
                    Console.Error.WriteLine("LEAVE Invoke() ** Missing method ** {0}.{1}",
                                            className,
                                            signature);
                    return(null);
                }

                methodIdCache[signature] = methodId;
            }

            StackItem[] stack   = new StackItem[(args.Length / 2) + 1];
            TypeId[]    typeIDs = new TypeId[(args.Length / 2) + 1];

            unsafe
            {
                fixed(StackItem *stackPtr = stack)
                {
                    fixed(TypeId *typeIDsPtr = typeIDs)
                    {
                        typeIDs[0] = 0;
                        for (int i = 1, k = 1; i < args.Length; i += 2, k++)
                        {
                            typeIDs[k] = SmokeMarshallers.UnboxToStackItem(args[i], stackPtr + k);
                        }

                        object returnValue = null;

                        if (instance == null)
                        {
                            CallSmokeMethod(methodId.smoke, (int)methodId.index, (IntPtr)0, (IntPtr)stackPtr, args.Length / 2, (IntPtr)typeIDsPtr);
                        }
                        else
                        {
#if DEBUG
                            GCHandle instanceHandle = DebugGCHandle.Alloc(instance);
#else
                            GCHandle instanceHandle = GCHandle.Alloc(instance);
#endif
                            CallSmokeMethod(methodId.smoke, methodId.index, (IntPtr)instanceHandle, (IntPtr)stackPtr, args.Length / 2, (IntPtr)typeIDsPtr);
#if DEBUG
                            DebugGCHandle.Free(instanceHandle);
#else
                            instanceHandle.Free();
#endif
                        }

                        if (returnType != typeof(void))
                        {
                            returnValue = SmokeMarshallers.BoxFromStackItem(returnType, (int)typeIDs[0], stackPtr);
                        }

                        if (refArgs)
                        {
                            for (int i = 1, k = 1; i < args.Length; i += 2, k++)
                            {
                                Type t = args[i].GetType();
                                if (t.IsPrimitive || t == typeof(NativeLong) || t == typeof(NativeULong))
                                {
                                    args[i] = SmokeMarshallers.BoxFromStackItem(args[i].GetType(), (int)typeIDs[k], stackPtr + k);
                                }
                            }
                        }

                        return(returnValue);
                    }
                }
            }
        }