Exemplo n.º 1
0
        public static new int Exec()
        {
            int result = (int)staticInterceptor.Invoke("exec", "exec()", typeof(int));

            Qyoto.Cleanup();
            return(result);
        }
Exemplo n.º 2
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));
            }
        }
Exemplo n.º 3
0
 public virtual QMetaObject MetaObject()
 {
     if (SmokeMarshallers.IsSmokeClass(GetType()))
     {
         return((QMetaObject)interceptor.Invoke("metaObject", "metaObject()", typeof(QMetaObject)));
     }
     else
     {
         return(Qyoto.GetMetaObject(this));
     }
 }
Exemplo n.º 4
0
 protected QObject(Type dummy)
 {
     try {
         Type             proxyInterface = Qyoto.GetSignalsInterface(GetType());
         SignalInvocation realProxy      = new SignalInvocation(proxyInterface, this);
         Q_EMIT = realProxy.GetTransparentProxy();
     }
     catch (Exception e) {
         Console.WriteLine("Could not retrieve signal interface: {0}", e);
     }
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
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);
        }
Exemplo 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

            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);
        }
Exemplo n.º 8
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++)
                {
                    if (parameters[i].ParameterType == typeof(bool))
                    {
                        args[i] = stackPtr[i].s_bool;
                    }
                    else if (parameters[i].ParameterType == typeof(sbyte))
                    {
                        args[i] = stackPtr[i].s_char;
                    }
                    else if (parameters[i].ParameterType == typeof(byte))
                    {
                        args[i] = stackPtr[i].s_uchar;
                    }
                    else if (parameters[i].ParameterType == typeof(char))
                    {
                        args[i] = (char)stackPtr[i].s_uchar;
                    }
                    else if (parameters[i].ParameterType == typeof(short))
                    {
                        args[i] = stackPtr[i].s_short;
                    }
                    else if (parameters[i].ParameterType == typeof(ushort))
                    {
                        args[i] = stackPtr[i].s_ushort;
                    }
                    else if (parameters[i].ParameterType == typeof(int) ||
                             parameters[i].ParameterType.IsEnum)
                    {
                        args[i] = stackPtr[i].s_int;
                    }
                    else if (parameters[i].ParameterType == typeof(uint))
                    {
                        args[i] = stackPtr[i].s_uint;
                    }
                    else if (parameters[i].ParameterType == 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)
                        args[i] = (SmokeMarshallers.SizeOfNativeLong < sizeof(long))? stackPtr[i + 1].s_int : stackPtr[i + 1].s_long;
                    }
                    else if (parameters[i].ParameterType == typeof(ulong))
                    {
                        args[i] = (SmokeMarshallers.SizeOfNativeLong < sizeof(long))? stackPtr[i + 1].s_uint : stackPtr[i + 1].s_ulong;
                    }
                    else if (parameters[i].ParameterType == typeof(float))
                    {
                        args[i] = stackPtr[i].s_float;
                    }
                    else if (parameters[i].ParameterType == typeof(double))
                    {
                        args[i] = stackPtr[i].s_double;
                    }
                    else if (parameters[i].ParameterType == typeof(string))
                    {
                        if (stackPtr[i].s_class != IntPtr.Zero)
                        {
                            args[i] = (string)((GCHandle)stackPtr[i].s_class).Target;
#if DEBUG
                            DebugGCHandle.Free((GCHandle)stackPtr[i].s_class);
#else
                            ((GCHandle)stackPtr[i].s_class).SynchronizedFree();
#endif
                        }
                    }
                    else
                    {
                        if (stackPtr[i].s_class != IntPtr.Zero)
                        {
                            args[i] = ((GCHandle)stackPtr[i].s_class).Target;
#if DEBUG
                            DebugGCHandle.Free((GCHandle)stackPtr[i].s_class);
#else
                            ((GCHandle)stackPtr[i].s_class).SynchronizedFree();
#endif
                        }
                    }
                }
            }

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

            unsafe {
                StackItem *retval = (StackItem *)ret;
                if (returnType == typeof(void))
                {
                    ;
                }
                else if (returnType == typeof(bool))
                {
                    retval[0].s_bool = (bool)returnValue;
                }
                else if (returnType == typeof(sbyte))
                {
                    retval[0].s_char = (sbyte)returnValue;
                }
                else if (returnType == typeof(byte))
                {
                    retval[0].s_uchar = (byte)returnValue;
                }
                else if (returnType == typeof(short))
                {
                    retval[0].s_short = (short)returnValue;
                }
                else if (returnType == typeof(ushort))
                {
                    retval[0].s_ushort = (ushort)returnValue;
                }
                else if (returnType == typeof(int) || returnType.IsEnum)
                {
                    retval[0].s_int = (int)returnValue;
                }
                else if (returnType == typeof(uint))
                {
                    retval[0].s_uint = (uint)returnValue;
                }
                else if (returnType == typeof(long))
                {
                    retval[0].s_long = (long)returnValue;
                }
                else if (returnType == typeof(ulong))
                {
                    retval[0].s_ulong = (ulong)returnValue;
                }
                else if (returnType == typeof(float))
                {
                    retval[0].s_float = (float)returnValue;
                }
                else if (returnType == typeof(double))
                {
                    retval[0].s_double = (double)returnValue;
                }
                else if (returnType == typeof(string))
                {
#if DEBUG
                    retval[0].s_class = (IntPtr)DebugGCHandle.Alloc(returnValue);
#else
                    retval[0].s_class = (IntPtr)GCHandle.Alloc(returnValue);
#endif
                }
                else if (returnValue == null)
                {
                    retval[0].s_class = IntPtr.Zero;
                }
                else
                {
#if DEBUG
                    retval[0].s_class = (IntPtr)DebugGCHandle.Alloc(returnValue);
#else
                    retval[0].s_class = (IntPtr)GCHandle.Alloc(returnValue);
#endif
                }
            }
        }