Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions
Mozilla.XPCOM.Invoker Class Reference

List of all members.

Public Member Functions

static IntPtr WrapCLRObject (IntPtr obj, Guid id)

Static Public Member Functions

static int XPTC_InvokeByIndexSafe (IntPtr that, Int32 index, UInt32 argCount, IntPtr args)
static object Invoke (IntPtr that, string iface, string method, params object[] args)
static object Invoke (IntPtr that, string iface, int method, params object[] args)
static object Invoke (IntPtr that, MethodDescriptor desc, params object[] args)

Private Member Functions

static IntPtr typeinfo_WrapUnicode (IntPtr str, UInt32 length)
static void typeinfo_FreeWrappedUnicode (IntPtr str)
static int XPTC_InvokeByIndex (IntPtr that, Int32 methodIndex, UInt32 argCount, IntPtr args)

Static Private Member Functions

static void MarshalOneArg (ParamDescriptor param, object arg, IntPtr buffer)
static IntPtr MarshalArgs (MethodDescriptor desc, object[] args)
static void FreeOneMarshalledArg (ParamDescriptor param, IntPtr buffer)
static void DemarshalArgs (MethodDescriptor desc, IntPtr argbuf)

Detailed Description

Definition at line 66 of file xptinvoke.cs.


Member Function Documentation

static void Mozilla.XPCOM.Invoker.DemarshalArgs ( MethodDescriptor  desc,
IntPtr  argbuf 
) [inline, static, private]

Definition at line 209 of file xptinvoke.cs.

    {
        int variantsz = Marshal.SizeOf(typeof(XPTCVariant));
        for (int i = 0; i < desc.args.Length; i++) {
            ParamDescriptor param = desc.args[i];
            IntPtr current = (IntPtr)(argbuf.ToInt32() + variantsz * i);
            FreeOneMarshalledArg(param, current);
        }
        Marshal.FreeCoTaskMem(argbuf);
    }
static void Mozilla.XPCOM.Invoker.FreeOneMarshalledArg ( ParamDescriptor  param,
IntPtr  buffer 
) [inline, static, private]

Definition at line 205 of file xptinvoke.cs.

    {
    }
static object Mozilla.XPCOM.Invoker.Invoke ( IntPtr  that,
string  iface,
string  method,
params object[]  args 
) [inline, static]

Definition at line 234 of file xptinvoke.cs.

    {
        return Invoke(that, TypeInfo.GetMethodData(iface, method), args);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static object Mozilla.XPCOM.Invoker.Invoke ( IntPtr  that,
string  iface,
int  method,
params object[]  args 
) [inline, static]

Definition at line 240 of file xptinvoke.cs.

    {
        return Invoke(that, TypeInfo.GetMethodData(iface, method), args);
    }

Here is the call graph for this function:

static object Mozilla.XPCOM.Invoker.Invoke ( IntPtr  that,
MethodDescriptor  desc,
params object[]  args 
) [inline, static]

Definition at line 246 of file xptinvoke.cs.

    {
        IntPtr argbuf = MarshalArgs(desc, args);
        int res = XPTC_InvokeByIndex(that, desc.index,
                                     (UInt32)args.Length, argbuf);
        DemarshalArgs(desc, argbuf);
        if (res != 0) {
            throw new Exception(String.Format("XPCOM Error: {0:X2}",
                                              res));
        }
        return null;
    }

Here is the call graph for this function:

static IntPtr Mozilla.XPCOM.Invoker.MarshalArgs ( MethodDescriptor  desc,
object[]  args 
) [inline, static, private]

Definition at line 181 of file xptinvoke.cs.

    {
        if (args.Length != desc.args.Length) {
            string msg = String.Format("{0} needs {1} args, {2} passed",
                                       desc.name, desc.args.Length, 
                                       args.Length);
            throw new Exception(msg);
        }

        int variantsz = 16; /* sizeof(nsXPTCVariant) */
        int size = variantsz * args.Length;
        IntPtr argbuf = Marshal.AllocCoTaskMem(size);

        for (int i = 0; i < args.Length; i++) {
            ParamDescriptor param = desc.args[i];
            IntPtr current = (IntPtr)(argbuf.ToInt32() + variantsz * i);
            object arg = args[i];

            MarshalOneArg(param, arg, current);
        }

        return argbuf;
    }

Here is the call graph for this function:

static void Mozilla.XPCOM.Invoker.MarshalOneArg ( ParamDescriptor  param,
object  arg,
IntPtr  buffer 
) [inline, static, private]

Definition at line 68 of file xptinvoke.cs.

    {
        string msg;
        if (param.flags != TypeInfo.ParamFlags.In) {
            msg = String.Format("{0} is {1} (only In " +
                              "supported)", param.Name(),
                              param.flags.ToString());
            throw new Exception(msg);
        }

        TypeInfo.TypeDescriptor type = param.type;
        
        if ((type.flags & TypeFlags.Reference) != 0) {
            if ((type.flags & TypeFlags.Pointer) == 0) {
                throw new Exception("TD is Reference but " +
                                    "not Pointer?! (" +
                                    param.ToString() + ")");
            }
            
            if (arg == null) {
                throw new Exception(param.Name() +
                                    ": null passed as arg for " + 
                                    "Reference param");
            }
        }

        if (type.IsScalar()) {
            
            XPTCVariant variant = new XPTCVariant();
            variant.type = type;
            variant.flags = 0;
            variant.ptr = IntPtr.Zero;
            Marshal.StructureToPtr(variant, buffer, false);

            IntPtr p;
            switch (type.tag) {

            case TypeTag.Int8:
            case TypeTag.Int16:
            case TypeTag.Int32:
            case TypeTag.UInt8:
            case TypeTag.UInt16:
            case TypeTag.UInt32:
            case TypeTag.Char:
            case TypeTag.WChar:
                Marshal.WriteInt32(buffer, (Int32)arg);
                break;

            case TypeTag.UInt64:
            case TypeTag.Int64:
                Marshal.WriteInt64(buffer, (Int64)arg);
                break;

            case TypeTag.Bool:
                bool b = (bool)arg;
                Marshal.WriteInt32(buffer, b ? 1 : 0);
                break;

            case TypeTag.Float:
                float[] f = new float[] { (float)arg };
                Marshal.Copy(f, 0, buffer, 1);
                break;
            case TypeTag.Double:
                double[] d = new double[] { (double)arg };
                Marshal.Copy(d, 0, buffer, 1);
                break;

            case TypeTag.String:
                Marshal.WriteIntPtr(buffer, 
                            Marshal.StringToCoTaskMemAnsi((string)arg));
                break;
            case TypeTag.WString:
                Marshal.WriteIntPtr(buffer, 
                            Marshal.StringToCoTaskMemUni((string)arg));
                break;

            default:
                msg = String.Format("{0}: type {1} not supported",
                                    param.Name(), type.tag.ToString());
                throw new Exception(msg);
            }

            Console.WriteLine("{0} @ {1:X2}", param.Name(),
                              buffer.ToInt32());
            return;
        }

        if (type.tag == TypeTag.Interface) {
            Guid iid = param.GetIID();
            Console.WriteLine("{0} is interface {1}",
                              param.Name(), iid);
            Marshal.WriteIntPtr(buffer, CLRWrapper.Wrap(arg, ref iid));
            Console.WriteLine("{0} @ {1:X2}", param.Name(),
                              buffer.ToInt32());
            return;
        }

        msg = String.Format("{0} type {1} not yet supported ",
                            param.Name(), type.tag.ToString());
        throw new Exception(msg);
    }

Here is the call graph for this function:

static void Mozilla.XPCOM.Invoker.typeinfo_FreeWrappedUnicode ( IntPtr  str) [private]
static IntPtr Mozilla.XPCOM.Invoker.typeinfo_WrapUnicode ( IntPtr  str,
UInt32  length 
) [private]
static IntPtr Mozilla.XPCOM.Invoker.WrapCLRObject ( IntPtr  obj,
Guid  id 
)
static int Mozilla.XPCOM.Invoker.XPTC_InvokeByIndex ( IntPtr  that,
Int32  methodIndex,
UInt32  argCount,
IntPtr  args 
) [private]
static int Mozilla.XPCOM.Invoker.XPTC_InvokeByIndexSafe ( IntPtr  that,
Int32  index,
UInt32  argCount,
IntPtr  args 
) [inline, static]

Definition at line 221 of file xptinvoke.cs.

    {
        Console.WriteLine("XPTC_IBI: {0:X2}:{1}({2}:{3:X2})",
                          that.ToInt32(), index, argCount, args.ToInt32());
        return XPTC_InvokeByIndex(that, index, argCount, args);
    }

Here is the call graph for this function:


The documentation for this class was generated from the following file: