Back to index

lightning-sunbird  0.9+nobinonly
test-invoke.cs
Go to the documentation of this file.
00001 using System;
00002 using System.Runtime.InteropServices;
00003 using Mozilla.XPCOM;
00004 using MethodDescriptor = Mozilla.XPCOM.TypeInfo.MethodDescriptor;
00005 
00006 public class Test
00007 {
00008     [DllImport("xpcom-dotnet.so")]
00009     static extern int StartXPCOM(out IntPtr srvmgr);
00010     
00011     static IntPtr srvmgr;
00012 
00013     [DllImport("test.so", EntryPoint="GetImpl")]
00014     public static extern IntPtr GetTestImpl();
00015 
00016     public static int xptinfo_test(string[] args)
00017     {
00018         int index = Int32.Parse(args[2]);
00019         MethodDescriptor meth = TypeInfo.GetMethodData(args[1], index);
00020         Console.WriteLine("{0}#{1}: {2}", args[1], index, meth.ToString());
00021         return 0;
00022     }
00023 
00024     public static int xptinvoke_test_cb()
00025     {
00026         object o = new object();
00027 
00028         IntPtr impl = GetTestImpl();
00029         Invoker.Invoke(impl, "test", "callback", o);
00030         return 0;
00031     }
00032 
00033     public static int xptinvoke_test_add(string[] args)
00034     {
00035         int a = Int32.Parse(args[1]);
00036         int b = Int32.Parse(args[2]);
00037 
00038         IntPtr impl = GetTestImpl();
00039         Invoker.Invoke(impl, "test", "add", a, b);
00040         return 0;
00041     }
00042 
00043     public static int Main(string[] args)
00044     {
00045         int res = StartXPCOM(out srvmgr);
00046 
00047         if (res != 0) {
00048             Console.WriteLine("StartXPCOM failed: {0:X2}", res);
00049             return 1;
00050         }
00051 
00052         if (args[0] == "add")
00053             return xptinvoke_test_add(args);
00054         if (args[0] == "xptinfo")
00055             return xptinfo_test(args);
00056         if (args[0] == "cb")
00057             return xptinvoke_test_cb();
00058         Console.WriteLine("Unknown test mode: {0}", args[0]);
00059         return 1;
00060     }
00061 }