Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 2
0
        public static int RegisterType <T>()
        {
            string      className;
            Destructor  dtorHandler;
            Constructor ctorHandler;

            if (SmokeMarshallers.IsSmokeClass(typeof(T)))
            {
                className   = SmokeMarshallers.SmokeClassName(typeof(T));
                dtorHandler = delegate(IntPtr obj) { DestroyObject(className, obj); };
                ctorHandler = delegate(IntPtr copy) { return(CreateObject(className, copy)); };
            }
            else
            {
                className   = typeof(T).ToString();
                dtorHandler = delegate(IntPtr obj) { ((GCHandle)obj).Free(); };
                ctorHandler = delegate(IntPtr copy) {
                    if (copy != IntPtr.Zero)
                    {
                        object o = (T)((GCHandle)copy).Target;    // create a copy if this is a valuetype
                        return((IntPtr)GCHandle.Alloc(o));
                    }
                    return((IntPtr)GCHandle.Alloc(default(T)));
                };
            }
            GCHandle.Alloc(className); // prevent collection
            GCHandle.Alloc(dtorHandler);
            GCHandle.Alloc(ctorHandler);
            return(QMetaTypeRegisterType(className, dtorHandler, ctorHandler));
        }
Ejemplo n.º 3
0
        public static T qobject_cast <T>(QObject obj) where T : class
        {
            if (obj == null)
            {
                return(null);
            }

            // direct cast possible?
            try {
                return((T)(object)obj);
            } catch {}

            Type t = typeof(T);

            if (!SmokeMarshallers.IsSmokeClass(t))
            {
                return(null);
            }
            string className = SmokeMarshallers.SmokeClassName(t);

            IntPtr ret = qyoto_qt_metacast((IntPtr)GCHandle.Alloc(obj),className);

            if (ret == IntPtr.Zero)
            {
                return(null);
            }
            else
            {
                GCHandle handle = (GCHandle)ret;
                object   target = handle.Target;
                handle.Free();
                return((T)target);
            }
        }
Ejemplo n.º 4
0
        public T FindChild <T>(string name)
        {
            string childClassName = null;
            IntPtr metaObject     = IntPtr.Zero;

            if (SmokeMarshallers.IsSmokeClass(typeof(T)))
            {
                childClassName = SmokeMarshallers.SmokeClassName(typeof(T));
            }
            else
            {
                metaObject = (IntPtr)GCHandle.Alloc(Qyoto.GetMetaObject(typeof(T)));
            }

            IntPtr child = FindQObjectChild((IntPtr)GCHandle.Alloc(this), childClassName, metaObject, name);

            if (child != IntPtr.Zero)
            {
                try {
                    return((T)((GCHandle)child).Target);
                } catch (Exception e) {
                    Console.WriteLine("Found child, but an error has occurred: {0}", e.Message);
                    return(default(T));
                }
            }
            else
            {
                return(default(T));
            }
        }
Ejemplo n.º 5
0
 public virtual QMetaObject MetaObject()
 {
     if (SmokeMarshallers.IsSmokeClass(GetType()))
     {
         return((QMetaObject)interceptor.Invoke("metaObject", "metaObject()", typeof(QMetaObject), false));
     }
     else
     {
         return(Qyoto.GetMetaObject(this));
     }
 }
Ejemplo n.º 6
0
        public static unsafe void InvokeDelegate(Delegate d, IntPtr stack)
        {
            MethodInfo mi = d.Method;

            ParameterInfo[] parameters = mi.GetParameters();
            object[]        args       = new object[parameters.Length];
            StackItem *     stackPtr   = (StackItem *)stack;

            for (int i = 0; i < args.Length; i++)
            {
                args[i] = SmokeMarshallers.BoxFromStackItem(parameters[i].ParameterType, 0, stackPtr + i);
            }
            d.DynamicInvoke(args);
        }
Ejemplo n.º 7
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);
                }
            }
        }
Ejemplo n.º 8
0
 public static void InitRuntime()
 {
     if (runtimeInitialized)
     {
         return;
     }
     Qyoto.Init_qyoto();
     SmokeMarshallers.SetUp();
     // not set when mono is embedded
     if (AppDomain.CurrentDomain.SetupInformation.ConfigurationFile == null)
     {
         PropertyInfo   pi    = typeof(AppDomain).GetProperty("SetupInformationNoCopy", BindingFlags.NonPublic | BindingFlags.Instance);
         AppDomainSetup setup = (AppDomainSetup)pi.GetValue(AppDomain.CurrentDomain, null);
         setup.ConfigurationFile = Assembly.GetExecutingAssembly().Location + ".config";
     }
     runtimeInitialized = true;
 }
Ejemplo n.º 9
0
        public SmokeInvocation(Type klass, Object obj)
        {
            classToProxy = klass;
            instance     = obj;
            className    = SmokeMarshallers.SmokeClassName(klass);

            TryInitialize(klass.Assembly);

            if (!globalMethodIdCache.TryGetValue(classToProxy, out methodIdCache))
            {
                methodIdCache = new Dictionary <string, ModuleIndex>();
                globalMethodIdCache[classToProxy] = methodIdCache;
            }

            if (instance != null)
            {
                AddOverridenMethods(instance.GetType());
            }
        }
Ejemplo n.º 10
0
        public static MethodInfo GetSlotMethodInfo(Type klass, string slotname)
        {
            Dictionary <string, CPPMethod> slotTable;
            CPPMethod result;

            do
            {
                slotTable = GetSlotSignatures(klass);

                if (slotTable.TryGetValue(slotname, out result))
                {
                    return(result.mi);
                }

                klass = klass.BaseType;
            } while (!SmokeMarshallers.IsSmokeClass(klass));

            return(null);
        }
Ejemplo n.º 11
0
        public List <T> FindChildren <T>(QRegExp regExp)
        {
            List <T>    list  = new List <T>();
            AddToListFn addFn = delegate(IntPtr obj) {
                T o = (T)((System.Runtime.InteropServices.GCHandle)obj).Target;
                list.Add(o);
            };

            string childClassName = null;
            IntPtr metaObject     = IntPtr.Zero;

            if (SmokeMarshallers.IsSmokeClass(typeof(T)))
            {
                childClassName = SmokeMarshallers.SmokeClassName(typeof(T));
            }
            else
            {
                metaObject = (IntPtr)GCHandle.Alloc(Qyoto.GetMetaObject(typeof(T)));
            }
            FindQObjectChildren((IntPtr)GCHandle.Alloc(this), childClassName, metaObject, (IntPtr)GCHandle.Alloc(regExp), string.Empty, addFn);
            return(list);
        }
Ejemplo n.º 12
0
        public T Create <T>(QWidget parentWidget, QObject parent, string keyword, List <QVariant> args) where T : class
        {
            Type type = typeof(T);

            if (!SmokeMarshallers.IsSmokeClass(type))
            {
                throw new Exception("The generic type must be included in the bindings");
            }

            QObject o = Create(SmokeMarshallers.SmokeClassName(type), parentWidget, parent, args, keyword);

            if (o == null)
            {
                return(null);
            }
            T t = qobject_cast <T>(o);

            if (t == null)
            {
                o.Dispose();
            }
            return(t);
        }
Ejemplo n.º 13
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;
        }
Ejemplo n.º 14
0
        public static Dictionary <PropertyInfo, CPPProperty> GetProperties(Type t)
        {
            Dictionary <PropertyInfo, CPPProperty> props = new Dictionary <PropertyInfo, CPPProperty>();

            foreach (PropertyInfo pi in t.GetProperties())
            {
                if (SmokeMarshallers.IsSmokeClass(pi.DeclaringType))
                {
                    continue;
                }
                object[] attrs = pi.GetCustomAttributes(typeof(Q_PROPERTY), false);
                if (attrs.Length != 0)
                {
                    Q_PROPERTY  attr = (Q_PROPERTY)attrs[0];
                    CPPProperty prop = new CPPProperty();
                    if (attr.Type == "" || attr.Name == "")
                    {
                        prop.type = GetPrimitiveString(pi.PropertyType);
                        prop.name = pi.Name;
                    }
                    else
                    {
                        prop.type = attr.Type;
                        prop.name = attr.Name;
                    }
                    prop.pi = pi;
                    if (pi.GetCustomAttributes(typeof(Q_SCRIPTABLE), false).Length != 0)
                    {
                        prop.scriptable = true;
                    }
                    props.Add(pi, prop);
                }
            }

            return(props);
        }
Ejemplo n.º 15
0
        public static string GetPrimitiveString(Type type)
        {
            string typeString = type.ToString();

            switch (typeString)
            {
            case "System.Void":
                return("");

            case "System.Boolean":
                return("bool");

            case "System.Int32":
                return("int");

            case "System.Int64":
                return("long");

            case "System.UInt32":
                return("uint");

            case "System.UInt64":
                return("ulong");

            case "System.Int16":
                return("short");

            case "System.UInt16":
                return("ushort");

            case "System.Byte":
                return("uchar");

            case "System.SByte":
                return("sbyte");

            case "System.String":
                return("QString");

            case "System.Double":
                return("double");

            case "System.Single":
                return("float");

            case "System.Char":
                return("char");
            }

            if (type.IsGenericType)
            {
                Type[] args = type.GetGenericArguments();
                if (type.FullName.StartsWith("System.Collections.Generic.List`1"))
                {
                    return("QList<" + GetPrimitiveString(args[0]) + ">");
                }
                else if (type.FullName.StartsWith("System.Collections.Generic.Dictionary`2"))
                {
                    return("QMap<" + GetPrimitiveString(args[0]) + ", " + GetPrimitiveString(args[1]) + ">");
                }
            }

            if (SmokeMarshallers.IsSmokeClass(type))
            {
                typeString = SmokeMarshallers.SmokeClassName(type);
            }

            List <string> nonQObjectClasses = new List <string>
            {
                // paint devices
                "QCustomRasterPaintDevice", "QGLFramebufferObject", "QGLPixelBuffer", "QImage", "QPicture", "QPixmap", "QPrinter", "QSvgGenerator",
                // painters
                "QStylePainter", "Q3Painter", "QPainter",
                // model items
                "QListWidgetItem", "QTreeWidgetItem", "QTableWidgetItem", "QStandardItem"
            };

            // pointer types
            if (type.IsSubclassOf(typeof(QObject)) || nonQObjectClasses.Contains(typeString))
            {
                typeString += "*";
            }

            return(typeString);
        }
Ejemplo n.º 16
0
        static public QVariant FromValue(object value, System.Type valueType)
        {
            if (valueType == typeof(bool))
            {
                return(new QVariant((bool)value));
            }
            else if (valueType == typeof(double))
            {
                return(new QVariant((double)value));
            }
            else if (valueType == typeof(QBitArray))
            {
                return(new QVariant((QBitArray)value));
            }
            else if (valueType == typeof(QByteArray))
            {
                return(new QVariant((QByteArray)value));
            }
            else if (valueType == typeof(char))
            {
                return(new QVariant(new QChar((char)value)));
            }
            else if (valueType == typeof(QDate))
            {
                return(new QVariant((QDate)value));
            }
            else if (valueType == typeof(QDateTime))
            {
                return(new QVariant((QDateTime)value));
            }
            else if (valueType == typeof(int))
            {
                return(new QVariant((int)value));
            }
            else if (valueType == typeof(QLine))
            {
                return(new QVariant((QLine)value));
            }
            else if (valueType == typeof(QLineF))
            {
                return(new QVariant((QLineF)value));
            }
            else if (valueType == typeof(QLocale))
            {
                return(new QVariant((QLocale)value));
            }
            else if (valueType == typeof(QPoint))
            {
                return(new QVariant((QPoint)value));
            }
            else if (valueType == typeof(QPointF))
            {
                return(new QVariant((QPointF)value));
            }
            else if (valueType == typeof(QRect))
            {
                return(new QVariant((QRect)value));
            }
            else if (valueType == typeof(QRectF))
            {
                return(new QVariant((QRectF)value));
            }
            else if (valueType == typeof(QRegExp))
            {
                return(new QVariant((QRegExp)value));
            }
            else if (valueType == typeof(QSize))
            {
                return(new QVariant((QSize)value));
            }
            else if (valueType == typeof(QSizeF))
            {
                return(new QVariant((QSizeF)value));
            }
            else if (valueType == typeof(string))
            {
                return(new QVariant((string)value));
            }
            else if (valueType == typeof(List <string>))
            {
                return(new QVariant((List <string>)value));
            }
            else if (valueType == typeof(List <QVariant>))
            {
                return(new QVariant((List <QVariant>)value));
            }
            else if (valueType == typeof(Dictionary <string, QVariant>))
            {
                return(new QVariant((Dictionary <string, QVariant>)value));
            }
            else if (valueType == typeof(QTime))
            {
                return(new QVariant((QTime)value));
            }
            else if (valueType == typeof(uint))
            {
                return(new QVariant((uint)value));
            }
            else if (valueType == typeof(QUrl))
            {
                return(new QVariant((QUrl)value));
            }
            else if (valueType == typeof(QVariant))
            {
                return(new QVariant((QVariant)value));
            }
            else if (valueType.IsEnum)
            {
                return(new QVariant((int)value));
            }
            else
            {
                string typeName;
                if (SmokeMarshallers.IsSmokeClass(valueType))
                {
                    typeName = SmokeMarshallers.SmokeClassName(valueType);
                }
                else
                {
                    typeName = valueType.ToString();
                }
                Type type = NameToType(typeName);
                if (type == Type.Invalid)
                {
                    return(FromValue <object>(value));
                }
                else if (type > Type.LastCoreType)
                {
                    IntPtr valueHandle = IntPtr.Zero;
                    if (value != null)
                    {
                        valueHandle = (IntPtr)GCHandle.Alloc(value);
                    }
                    GCHandle handle = (GCHandle)QVariantFromValue(QMetaType.type(typeName), valueHandle);
                    QVariant v      = (QVariant)handle.Target;
                    handle.Free();
                    return(v);
                }

                return(new QVariant());
            }
        }
Ejemplo n.º 17
0
        public object Value(System.Type valueType)
        {
            if (valueType == typeof(bool))
            {
                return(ToBool());
            }
            else if (valueType == typeof(double))
            {
                return(ToDouble());
            }
            else if (valueType == typeof(QBitArray))
            {
                return(ToBitArray());
            }
            else if (valueType == typeof(QByteArray))
            {
                return(ToByteArray());
            }
            else if (valueType == typeof(char))
            {
                return(ToChar());
            }
            else if (valueType == typeof(QDate))
            {
                return(ToDate());
            }
            else if (valueType == typeof(QDateTime))
            {
                return(ToDateTime());
            }
            else if (valueType == typeof(int))
            {
                return(ToInt());
            }
            else if (valueType == typeof(QLine))
            {
                return(ToLine());
            }
            else if (valueType == typeof(QLineF))
            {
                return(ToLineF());
            }
            else if (valueType == typeof(QLocale))
            {
                return(ToLocale());
            }
            else if (valueType == typeof(QPoint))
            {
                return(ToPoint());
            }
            else if (valueType == typeof(QPointF))
            {
                return(ToPointF());
            }
            else if (valueType == typeof(QRect))
            {
                return(ToRect());
            }
            else if (valueType == typeof(QRectF))
            {
                return(ToRectF());
            }
            else if (valueType == typeof(QRegExp))
            {
                return(ToRegExp());
            }
            else if (valueType == typeof(QSize))
            {
                return(ToSize());
            }
            else if (valueType == typeof(QSizeF))
            {
                return(ToSizeF());
            }
            else if (valueType == typeof(string))
            {
                return(ToString());
            }
            else if (valueType == typeof(List <string>))
            {
                return(ToStringList());
            }
            else if (valueType == typeof(List <QVariant>))
            {
                return(ToList());
            }
            else if (valueType == typeof(Dictionary <string, QVariant>))
            {
                object o = ToMap();
                if (o == null)
                {
                    o = ToHash();
                }
                return(o);
            }
            else if (valueType == typeof(QTime))
            {
                return(ToTime());
            }
            else if (valueType == typeof(uint))
            {
                return(ToUInt());
            }
            else if (valueType == typeof(QUrl))
            {
                return(ToUrl());
            }
            else if (valueType == typeof(QVariant))
            {
                return(this);
            }
            else if (valueType.IsEnum)
            {
                return(Enum.ToObject(valueType, ToLongLong()));
            }
            else
            {
                string typeName;
                if (SmokeMarshallers.IsSmokeClass(valueType))
                {
                    typeName = SmokeMarshallers.SmokeClassName(valueType);
                }
                else
                {
                    typeName = valueType.ToString();
                }
                Type type = NameToType(typeName);
                if (type > Type.LastCoreType)
                {
                    IntPtr instancePtr = QVariantValue(typeName, (IntPtr)GCHandle.Alloc(this));
                    return(((GCHandle)instancePtr).Target);
                }
                else if (type == Type.Invalid)
                {
                    Console.WriteLine("QVariant.Value(): invalid type: {0}", valueType);
                }

                return(null);
            }
        }
Ejemplo n.º 18
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);
                    }
                }
            }
        }
Ejemplo n.º 19
0
 public static void Cleanup()
 {
     SmokeMarshallers.ConvertRefs();
     SetApplicationTerminated();
 }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        static void AddOverridenMethods(Type klass)
        {
            if (SmokeMarshallers.IsSmokeClass(klass))
            {
                return;
            }

            if (overridenMethods.ContainsKey(klass))
            {
                return;
            }

            Dictionary <string, MemberInfo> methodsHash = new Dictionary <string, MemberInfo>();

            overridenMethods.Add(klass, methodsHash);

            do
            {
                MemberInfo[] methods = klass.FindMembers(MemberTypes.Method,
                                                         BindingFlags.Public
                                                         | BindingFlags.NonPublic
                                                         | BindingFlags.Instance
                                                         | BindingFlags.DeclaredOnly,
                                                         Type.FilterName,
                                                         "*");
                foreach (MemberInfo method in methods)
                {
                    Type   parent    = klass.BaseType;
                    string signature = null;
                    while (signature == null && parent != null && parent != typeof(Qt))
                    {
                        MemberInfo[] parentMethods = parent.FindMembers(MemberTypes.Method,
                                                                        BindingFlags.Public
                                                                        | BindingFlags.NonPublic
                                                                        | BindingFlags.Instance
                                                                        | BindingFlags.DeclaredOnly,
                                                                        Type.FilterName,
                                                                        method.Name);
                        foreach (MemberInfo parentMethod in parentMethods)
                        {
                            if (method.ToString() == parentMethod.ToString())
                            {
                                object[] smokeMethod = parentMethod.GetCustomAttributes(typeof(SmokeMethod), false);
                                if (smokeMethod.Length > 0)
                                {
                                    signature = ((SmokeMethod)smokeMethod[0]).Signature;
                                }
                            }
                        }

                        parent = parent.BaseType;
                    }

                    if (signature != null && !methodsHash.ContainsKey(signature))
                    {
                        methodsHash.Add(signature, method);
                    }
                }

                klass = klass.BaseType;
            } while (!SmokeMarshallers.IsSmokeClass(klass));
        }
Ejemplo n.º 22
0
        public static string GetPrimitiveString(Type type)
        {
            string typeString = type.ToString();

            switch (typeString)
            {
            case "System.Void":
                return("");

            case "System.Boolean":
                return("bool");

            case "System.Int32":
                return("int");

            case "System.Int64":
                return("long");

            case "System.UInt32":
                return("uint");

            case "System.UInt64":
                return("ulong");

            case "System.Int16":
                return("short");

            case "System.UInt16":
                return("ushort");

            case "System.Byte":
                return("uchar");

            case "System.SByte":
                return("sbyte");

            case "System.String":
                return("QString");

            case "System.Double":
                return("double");

            case "System.Single":
                return("float");

            case "System.Char":
                return("char");
            }

            if (type.IsGenericType)
            {
                Type[] args = type.GetGenericArguments();
                if (type.FullName.StartsWith("System.Collections.Generic.List`1"))
                {
                    return("QList<" + GetPrimitiveString(args[0]) + ">");
                }
                else if (type.FullName.StartsWith("System.Collections.Generic.Dictionary`2"))
                {
                    return("QMap<" + GetPrimitiveString(args[0]) + ", " + GetPrimitiveString(args[1]) + ">");
                }
            }

            if (SmokeMarshallers.IsSmokeClass(type))
            {
                typeString = SmokeMarshallers.SmokeClassName(type);
            }

            // pointer types
            if (type.IsSubclassOf(typeof(QObject)) ||
                typeString == "QListWidgetItem" ||
                typeString == "QTreeWidgetItem" ||
                typeString == "QTableWidgetItem" ||
                typeString == "QStandardItem")
            {
                typeString += "*";
            }

            return(typeString);
        }