Пример #1
0
        public static IntPtr OverridenMethod(IntPtr instance, string method)
        {
            Type klass = ((GCHandle)instance).Target.GetType();

            if (method == "metaObject() const")
            {
#if DEBUG
                return((IntPtr)DebugGCHandle.Alloc(metaObjectMethod));
#else
                return((IntPtr)GCHandle.Alloc(metaObjectMethod));
#endif
            }

            Dictionary <string, MemberInfo> methods;
            if (!overridenMethods.TryGetValue(klass, out methods))
            {
                return((IntPtr)0);
            }

            MemberInfo methodInfo;
            if (!methods.TryGetValue(method, out methodInfo))
            {
                return((IntPtr)0);
            }

#if DEBUG
            return((IntPtr)DebugGCHandle.Alloc(methodInfo));
#else
            return((IntPtr)GCHandle.Alloc(methodInfo));
#endif
        }
Пример #2
0
        public override int GetHashCode()
        {
#if DEBUG
            return(QyotoHash((IntPtr)DebugGCHandle.Alloc(instance)));
#else
            return(QyotoHash((IntPtr)GCHandle.Alloc(instance)));
#endif
        }
Пример #3
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);
                }
            }
        }
Пример #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);
                    }
                }
            }
        }
Пример #5
0
        public static QMetaObject MakeMetaObject(Type t)
        {
            if (t == null)
            {
                return(null);
            }

            QMetaObject parentMeta      = null;
            string      parentClassName = null;

            if (!SmokeMarshallers.IsSmokeClass(t.BaseType) &&
                !metaObjects.TryGetValue(t.BaseType, out parentMeta))
            {
                // create QMetaObject
                parentMeta = MakeMetaObject(t.BaseType);
            }
            else
            {
                parentClassName = SmokeMarshallers.SmokeClassName(t.BaseType);
            }

            ICollection <CPPMethod> slots;

            // build slot table
            slots = GetSlotSignatures(t).Values;

            PropertyInfo pi = t.GetProperty("Emit", BindingFlags.Instance
                                            | BindingFlags.NonPublic
                                            | BindingFlags.DeclaredOnly);
            ICollection <CPPMethod> signals = null;

            if (pi == null)
            {
                signals = new List <CPPMethod>();
            }
            else
            {
                emitInterfaceCache[t] = pi.PropertyType;
                signals = GetSignalSignatures(pi.PropertyType).Values;
            }

            ICollection <CPPProperty> properties = GetProperties(t).Values;
            QyotoMetaData             metaData   = new QyotoMetaData(t.Name, signals, slots, GetClassInfos(t), properties);

            IntPtr metaObject;
            IntPtr parentMetaPtr = (IntPtr)0;

            unsafe
            {
                fixed(byte *stringdata = metaData.StringData)
                fixed(uint *data = metaData.Data)
                {
                    if (parentMeta != null)
                    {
#if DEBUG
                        parentMetaPtr = (IntPtr)DebugGCHandle.Alloc(parentMeta);
#else
                        parentMetaPtr = (IntPtr)GCHandle.Alloc(parentMeta);
#endif
                    }
                    metaObject = qyoto_make_metaObject(parentClassName,
                                                       parentMetaPtr,
                                                       (IntPtr)stringdata, metaData.StringData.Length,
                                                       (IntPtr)data, metaData.Data.Length);
                }
            }

            QMetaObject res = (QMetaObject)((GCHandle)metaObject).Target;
#if DEBUG
            DebugGCHandle.Free((GCHandle)metaObject);
#else
            ((GCHandle)metaObject).Free();
#endif
            metaObjects.Add(t, res);
            return(res);
        }