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

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: Style Fixed 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 using System;
6 using System.Collections.Generic;
7 using System.Linq;
8 using System.Text;
9 using EnvDTE;
10 using EnvDTE80;
11 using System.Runtime.InteropServices;
12
13 namespace UnitTests
14 {
15 /// <summary>
16 /// This class receives messages from the COM calls to Visual Studio
17 /// and auto-retries them if they fail because VS is busy
18 /// </summary>
19 public class ComMessageFilter : IOleMessageFilter
20 {
21 /// <summary>
22 /// Note this registers the filter only for the current thread.
23 /// </summary>
24 public static void Register()
25 {
26 IOleMessageFilter oldFilter = null;
27 CoRegisterMessageFilter(new ComMessageFilter(), out oldFilter);
28 }
29
30 /// <summary>
31 /// Note this only closes the filter for the current thread.
32 /// </summary>
33 public static void Revoke()
34 {
35 IOleMessageFilter oldFilter = null;
36 CoRegisterMessageFilter(null, out oldFilter);
37 }
38
39 /// <summary>
40 /// Handles calls for the thread
41 /// </summary>
42 /// <param name="dwCallType">Unused</param>
43 /// <param name="hTaskCaller">Unused</param>
44 /// <param name="dwTickCount">Unused</param>
45 /// <param name="lpInterfaceInfo">Unused</param>
46 /// <returns>Code indicating message was handled</returns>
47 int IOleMessageFilter.HandleInComingCall(int dwCallType, System.IntPtr hTask Caller,
48 int dwTickCount, System.IntPtr lpInterfaceInfo)
49 {
50 return 0; // SERVERCALL_ISHANDLED.
51 }
52
53 /// <summary>
54 /// Automatically retries the failed call
55 /// </summary>
56 /// <param name="hTaskCallee">Unused</param>
57 /// <param name="dwTickCount">Unused</param>
58 /// <param name="dwRejectType">Unused</param>
59 /// <returns>Code indicating call should be retried</returns>
60 int IOleMessageFilter.RetryRejectedCall(System.IntPtr hTaskCallee,
61 int dwTickCount, int dwRejectType)
62 {
63 if (dwRejectType == 2) // SERVERCALL_RETRYLATER
64 {
65 // Immediate retry
66 return 99;
67 }
68 // Cancel call
69 return -1;
70 }
71
72 /// <summary>
73 /// Handles an incoming message by indicating it should be dispatched always
74 /// </summary>
75 /// <param name="hTaskCallee">Unused</param>
76 /// <param name="dwTickCount">Unused</param>
77 /// <param name="dwPendingType"><Unused/param>
78 /// <returns>Code indicating message should be dispatched</returns>
79 int IOleMessageFilter.MessagePending(System.IntPtr hTaskCallee,
80 int dwTickCount, int dwPendingType)
81 {
82 return 2; // PENDINGMSG_WAITDEFPROCESS
83 }
84
85 // Implement the IOleMessageFilter interface.
86 [DllImport("Ole32.dll")]
87 private static extern int CoRegisterMessageFilter(
88 IOleMessageFilter newFilter, out IOleMessageFilter oldFilter);
89 }
90
91 /// <summary>
92 /// Interface for IOleMessageFilter
93 /// </summary>
94 [ComImport(), Guid("00000016-0000-0000-C000-000000000046"),
95 InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
96 interface IOleMessageFilter
97 {
98 [PreserveSig]
99 int HandleInComingCall(int dwCallType, IntPtr hTaskCaller,
100 int dwTickCount, IntPtr lpInterfaceInfo);
101
102 [PreserveSig]
103 int RetryRejectedCall(IntPtr hTaskCallee, int dwTickCount, int dwRejectType) ;
104
105 [PreserveSig]
106 int MessagePending(IntPtr hTaskCallee, int dwTickCount, int dwPendingType);
107 }
108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698