Beispiel #1
0
        static void MarshalCallback(IntPtr raw_closure, IntPtr return_val, uint n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data)
        {
            string message = String.Empty;

            try {
                SignalClosure closure = closures [raw_closure] as SignalClosure;
                message = "Marshaling " + closure.name + " signal";
                Value       objval = (Value)Marshal.PtrToStructure(param_values, typeof(Value));
                GLib.Object __obj  = objval.Val as GLib.Object;
                if (__obj == null)
                {
                    return;
                }

                if (closure.args_type == typeof(EventArgs))
                {
                    closure.Invoke(new ClosureInvokedArgs(__obj, EventArgs.Empty));
                    return;
                }

                SignalArgs args = Activator.CreateInstance(closure.args_type, new object [0]) as SignalArgs;
                args.Args = new object [n_param_vals - 1];
                GLib.Value[] vals = new GLib.Value [n_param_vals - 1];
                for (int i = 1; i < n_param_vals; i++)
                {
                    IntPtr ptr = new IntPtr(param_values.ToInt64() + i * Marshal.SizeOf(typeof(Value)));
                    vals [i - 1]      = (Value)Marshal.PtrToStructure(ptr, typeof(Value));
                    args.Args [i - 1] = vals [i - 1].Val;
                }
                ClosureInvokedArgs ci_args = new ClosureInvokedArgs(__obj, args);
                closure.Invoke(ci_args);
                for (int i = 1; i < n_param_vals; i++)
                {
                    vals [i - 1].Update(args.Args [i - 1]);
                    IntPtr ptr = new IntPtr(param_values.ToInt64() + i * Marshal.SizeOf(typeof(Value)));
                    Marshal.StructureToPtr(vals [i - 1], ptr, false);
                }
                if (return_val == IntPtr.Zero || args.RetVal == null)
                {
                    return;
                }

                Value ret = (Value)Marshal.PtrToStructure(return_val, typeof(Value));
                ret.Val = args.RetVal;
                Marshal.StructureToPtr(ret, return_val, false);
            } catch (Exception e) {
                Console.WriteLine(message);
                ExceptionManager.RaiseUnhandledException(e, false);
            }
        }
            unsafe static void MarshalCallback(IntPtr raw_closure, Value *return_val, uint n_param_vals, Value *param_values, IntPtr invocation_hint, IntPtr marshal_data)
            {
                SignalClosure closure = null;

                try {
                    closure = closures [raw_closure] as SignalClosure;
                    GLib.Object __obj = param_values [0].Val as GLib.Object;
                    if (__obj == null)
                    {
                        return;
                    }

                    if (closure.signal.args_type == typeof(EventArgs))
                    {
                        closure.Invoke(new ClosureInvokedArgs(__obj, EventArgs.Empty));
                        return;
                    }

                    SignalArgs args = FastActivator.CreateSignalArgs(closure.signal.args_type);
                    args.Args = new object [n_param_vals - 1];
                    for (int i = 1; i < n_param_vals; i++)
                    {
                        args.Args [i - 1] = param_values [i].Val;
                    }
                    ClosureInvokedArgs ci_args = new ClosureInvokedArgs(__obj, args);
                    closure.Invoke(ci_args);
                    for (int i = 1; i < n_param_vals; i++)
                    {
                        param_values [i].Update(args.Args [i - 1]);
                    }
                    if (return_val == null || args.RetVal == null)
                    {
                        return;
                    }

                    return_val->Val = args.RetVal;
                } catch (Exception e) {
                    if (closure != null)
                    {
                        Console.WriteLine("Marshaling {0} signal", closure.signal.name);
                    }
                    ExceptionManager.RaiseUnhandledException(e, false);
                }
            }