annotate VBoxFrontend/VBoxEventListener.cs @ 7:a7650e26195f tip

Added support for generating Com Callable Wrappers
author Ivo Smits
date Fri, 06 May 2011 08:12:43 +0200
parents e1ec7bf71313
children
rev   line source
0
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
1 ???using System;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
2 using System.Runtime.InteropServices;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
3 using System.Runtime.CompilerServices;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
4 using VirtualBox;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
5
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
6 namespace ConsoleApplication1 {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
7 public class VBoxEventArgs : EventArgs {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
8 public IEvent Event { get; private set; }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
9 public VBoxEventArgs(IEvent e) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
10 Event = e;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
11 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
12 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
13
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
14 [ClassInterface(ClassInterfaceType.None)]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
15 [TypeLibType(TypeLibTypeFlags.FCanCreate)]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
16 [ComVisible(true)]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
17 public class VBoxEventListener : IEventListener {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
18 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
19 [Guid("9b6e1aee-35f3-4f4d-b5bb-ed0ecefd8538")]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
20 [ComImport()]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
21 interface IEventSourceXPCOM {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
22 [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
23 [return: MarshalAs(UnmanagedType.Interface)]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
24 IEventListener CreateListener();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
25 [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
26 [return: MarshalAs(UnmanagedType.Interface)]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
27 IEventSource CreateAggregator([MarshalAs(UnmanagedType.SafeArray)] ref System.Array psubordinates);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
28 [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
29 void RegisterListener([MarshalAs(UnmanagedType.Interface)] IEventListener plistener, UInt32 pinterestinglen, IntPtr pinteresting, Int32 pactive);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
30 //void RegisterListener([MarshalAs(UnmanagedType.Interface)] IEventListener plistener, UInt32 pinterestinglen, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=1)] VBoxEventType[] pinteresting, Int32 pactive);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
31
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
32 [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
33 void UnregisterListener([MarshalAs(UnmanagedType.Interface)] IEventListener plistener);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
34 [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
35 Int32 FireEvent([MarshalAs(UnmanagedType.Interface)] IEvent pevent, Int32 ptimeout);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
36 [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
37 [return: MarshalAs(UnmanagedType.Interface)]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
38 IEvent GetEvent([MarshalAs(UnmanagedType.Interface)] IEventListener plistener, Int32 ptimeout);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
39 [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
40 void EventProcessed([MarshalAs(UnmanagedType.Interface)] IEventListener plistener, [MarshalAs(UnmanagedType.Interface)] IEvent pevent);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
41 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
42
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
43 public EventHandler<VBoxEventArgs> HandleEvent;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
44 void IEventListener.HandleEvent(IEvent aEvent) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
45 Console.WriteLine("Event: {0}", aEvent.Type);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
46 if (HandleEvent != null) HandleEvent(this, new VBoxEventArgs(aEvent));
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
47 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
48
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
49 public void RegisterSource(IEventSource src, params VBoxEventType[] events) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
50 if (Environment.OSVersion.Platform == PlatformID.Win32NT || Environment.OSVersion.Platform == PlatformID.WinCE) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
51 Array eventTypesArray = (Array)events;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
52 src.RegisterListener(this, ref eventTypesArray, 1);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
53 } else {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
54 unsafe {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
55 fixed (VBoxEventType* ptr = events) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
56 ((IEventSourceXPCOM)src).RegisterListener(this, (uint)events.Length, (IntPtr)ptr, 1);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
57 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
58 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
59 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
60 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
61
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
62 public void UnregisterSource(IEventSource src) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
63 src.UnregisterListener(this);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
64 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
65 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
66 }