Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(772)

Side by Side Diff: visual_studio/NativeClientVSAddIn/UnitTests/ComMessageFilter.cs

Issue 10758009: Native Client Visual Studio Add-in (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using EnvDTE;
6 using EnvDTE80;
7 using System.Runtime.InteropServices;
8
9 namespace UnitTests
10 {
11 /// <summary>
12 /// This class receives messages from the COM calls to Visual Studio
13 /// and auto-retries them if they fail because VS is busy
14 /// </summary>
15 public class ComMessageFilter : IOleMessageFilter
16 {
17 // Start the filter.
18 // Note that this registers the filter only for the current thread
19 public static void Register()
20 {
21 IOleMessageFilter newFilter = new ComMessageFilter();
22 IOleMessageFilter oldFilter = null;
23 CoRegisterMessageFilter(newFilter, out oldFilter);
24 }
25
26 // Done with the filter, close it.
27 // Note that this revokes the filter only for the current thread
28 public static void Revoke()
29 {
30 IOleMessageFilter oldFilter = null;
31 CoRegisterMessageFilter(null, out oldFilter);
32 }
33
34 // Handle incoming thread requests.
35 int IOleMessageFilter.HandleInComingCall(int dwCallType,
36 System.IntPtr hTaskCaller, int dwTickCount, System.IntPtr
37 lpInterfaceInfo)
38 {
39 //Return the flag SERVERCALL_ISHANDLED.
40 return 0;
41 }
42
43 // Thread call was rejected, so try again.
44 int IOleMessageFilter.RetryRejectedCall(System.IntPtr
45 hTaskCallee, int dwTickCount, int dwRejectType)
46 {
47 if (dwRejectType == 2)
48 // flag = SERVERCALL_RETRYLATER.
49 {
50 // Retry the thread call immediately if return >=0 &
51 // <100.
52 return 99;
53 }
54 // Too busy; cancel call.
55 return -1;
56 }
57
58 int IOleMessageFilter.MessagePending(System.IntPtr hTaskCallee,
59 int dwTickCount, int dwPendingType)
60 {
61 //Return the flag PENDINGMSG_WAITDEFPROCESS.
62 return 2;
63 }
64
65 // Implement the IOleMessageFilter interface.
66 [DllImport("Ole32.dll")]
67 private static extern int
68 CoRegisterMessageFilter(IOleMessageFilter newFilter, out
69 IOleMessageFilter oldFilter);
70 }
71
72 [ComImport(), Guid("00000016-0000-0000-C000-000000000046"),
73 InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
74 interface IOleMessageFilter
75 {
76 [PreserveSig]
77 int HandleInComingCall(
78 int dwCallType,
79 IntPtr hTaskCaller,
80 int dwTickCount,
81 IntPtr lpInterfaceInfo);
82
83 [PreserveSig]
84 int RetryRejectedCall(
85 IntPtr hTaskCallee,
86 int dwTickCount,
87 int dwRejectType);
88
89 [PreserveSig]
90 int MessagePending(
91 IntPtr hTaskCallee,
92 int dwTickCount,
93 int dwPendingType);
94 }
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698