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

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 // 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 namespace UnitTests
6 {
7 using System;
8 using System.Runtime.InteropServices;
9
10 /// <summary>
11 /// Interface for IOleMessageFilter.
12 /// </summary>
13 [ComImport, Guid("00000016-0000-0000-C000-000000000046"),
14 InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
15 public interface IOleMessageFilter
16 {
17 /// <summary>
18 /// Handles calls for the thread.
19 /// </summary>
20 /// <param name="dwCallType">The parameter is not used.</param>
21 /// <param name="hTaskCaller">The parameter is not used.</param>
22 /// <param name="dwTickCount">The parameter is not used.</param>
23 /// <param name="lpInterfaceInfo">The parameter is not used.</param>
24 /// <returns>Code indicating message was handled.</returns>
25 [System.Diagnostics.CodeAnalysis.SuppressMessage(
26 "Microsoft.StyleCop.CSharp.NamingRules",
27 "SA1305:FieldNamesMustNotUseHungarianNotation",
28 Justification = "Matching variable name to COM interface")]
29 [PreserveSig]
30 int HandleInComingCall(
31 int dwCallType,
32 IntPtr hTaskCaller,
33 int dwTickCount,
34 IntPtr lpInterfaceInfo);
35
36 /// <summary>
37 /// Automatically retries the failed call.
38 /// </summary>
39 /// <param name="hTaskCallee">The parameter is not used.</param>
40 /// <param name="dwTickCount">The parameter is not used.</param>
41 /// <param name="dwRejectType">The parameter is not used.</param>
42 /// <returns>Code indicating call should be retried.</returns>
43 [System.Diagnostics.CodeAnalysis.SuppressMessage(
44 "Microsoft.StyleCop.CSharp.NamingRules",
45 "SA1305:FieldNamesMustNotUseHungarianNotation",
46 Justification = "Matching variable name to COM interface")]
47 [PreserveSig]
48 int RetryRejectedCall(IntPtr hTaskCallee, int dwTickCount, int dwRejectType) ;
49
50 /// <summary>
51 /// Handles an incoming message by indicating it should be dispatched always .
52 /// </summary>
53 /// <param name="hTaskCallee">The parameter is not used.</param>
54 /// <param name="dwTickCount">The parameter is not used.</param>
55 /// <param name="dwPendingType">The parameter is not used.</param>
56 /// <returns>Code indicating message should be dispatched.</returns>
57 [System.Diagnostics.CodeAnalysis.SuppressMessage(
58 "Microsoft.StyleCop.CSharp.NamingRules",
59 "SA1305:FieldNamesMustNotUseHungarianNotation",
60 Justification = "Matching variable name to COM interface")]
61 [PreserveSig]
62 int MessagePending(IntPtr hTaskCallee, int dwTickCount, int dwPendingType);
63 }
64
65 /// <summary>
66 /// This class receives messages from the COM calls to Visual Studio
67 /// and auto-retries them if they fail because VS is busy.
68 /// </summary>
69 public class ComMessageFilter : IOleMessageFilter
70 {
71 /// <summary>
72 /// Note this registers the filter only for the current thread.
73 /// </summary>
74 public static void Register()
75 {
76 IOleMessageFilter oldFilter = null;
77 CoRegisterMessageFilter(new ComMessageFilter(), out oldFilter);
78 }
79
80 /// <summary>
81 /// Note this only closes the filter for the current thread.
82 /// </summary>
83 public static void Revoke()
84 {
85 IOleMessageFilter oldFilter = null;
86 CoRegisterMessageFilter(null, out oldFilter);
87 }
88
89 /// <summary>
90 /// Handles calls for the thread.
91 /// </summary>
92 /// <param name="dwCallType">The parameter is not used.</param>
93 /// <param name="hTaskCaller">The parameter is not used.</param>
94 /// <param name="dwTickCount">The parameter is not used.</param>
95 /// <param name="lpInterfaceInfo">The parameter is not used.</param>
96 /// <returns>Code indicating message was handled.</returns>
97 [System.Diagnostics.CodeAnalysis.SuppressMessage(
98 "Microsoft.StyleCop.CSharp.NamingRules",
99 "SA1305:FieldNamesMustNotUseHungarianNotation",
100 Justification = "Matching variable name to COM interface")]
101 int IOleMessageFilter.HandleInComingCall(
102 int dwCallType,
103 System.IntPtr hTaskCaller,
104 int dwTickCount,
105 System.IntPtr lpInterfaceInfo)
106 {
107 return 0; // SERVERCALL_ISHANDLED.
108 }
109
110 /// <summary>
111 /// Automatically retries the failed call.
112 /// </summary>
113 /// <param name="hTaskCallee">The parameter is not used.</param>
114 /// <param name="dwTickCount">The parameter is not used.</param>
115 /// <param name="dwRejectType">The parameter is not used.</param>
116 /// <returns>Code indicating call should be retried.</returns>
117 [System.Diagnostics.CodeAnalysis.SuppressMessage(
118 "Microsoft.StyleCop.CSharp.NamingRules",
119 "SA1305:FieldNamesMustNotUseHungarianNotation",
120 Justification = "Matching variable name to COM interface")]
121 int IOleMessageFilter.RetryRejectedCall(
122 System.IntPtr hTaskCallee,
123 int dwTickCount,
124 int dwRejectType)
125 {
126 // If reject type is SERVERCALL_RETRYLATER.
127 if (dwRejectType == 2)
128 {
129 // Immediate retry.
130 return 99;
131 }
132
133 // Cancel call.
134 return -1;
135 }
136
137 /// <summary>
138 /// Handles an incoming message by indicating it should be dispatched always .
139 /// </summary>
140 /// <param name="hTaskCallee">The parameter is not used.</param>
141 /// <param name="dwTickCount">The parameter is not used.</param>
142 /// <param name="dwPendingType">The parameter is not used.</param>
143 /// <returns>Code indicating message should be dispatched.</returns>
144 [System.Diagnostics.CodeAnalysis.SuppressMessage(
145 "Microsoft.StyleCop.CSharp.NamingRules",
146 "SA1305:FieldNamesMustNotUseHungarianNotation",
147 Justification = "Matching variable name to COM interface")]
148 int IOleMessageFilter.MessagePending(
149 System.IntPtr hTaskCallee,
150 int dwTickCount,
151 int dwPendingType)
152 {
153 return 2; // PENDINGMSG_WAITDEFPROCESS.
154 }
155
156 // Implement the IOleMessageFilter interface.
157 [DllImport("Ole32.dll")]
158 private static extern int CoRegisterMessageFilter(
159 IOleMessageFilter newFilter, out IOleMessageFilter oldFilter);
160 }
161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698