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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: visual_studio/NativeClientVSAddIn/UnitTests/ComMessageFilter.cs
diff --git a/visual_studio/NativeClientVSAddIn/UnitTests/ComMessageFilter.cs b/visual_studio/NativeClientVSAddIn/UnitTests/ComMessageFilter.cs
new file mode 100644
index 0000000000000000000000000000000000000000..ae616c35690cf97e89c66e919ef754c46155b1e6
--- /dev/null
+++ b/visual_studio/NativeClientVSAddIn/UnitTests/ComMessageFilter.cs
@@ -0,0 +1,161 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+namespace UnitTests
+{
+ using System;
+ using System.Runtime.InteropServices;
+
+ /// <summary>
+ /// Interface for IOleMessageFilter.
+ /// </summary>
+ [ComImport, Guid("00000016-0000-0000-C000-000000000046"),
+ InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IOleMessageFilter
+ {
+ /// <summary>
+ /// Handles calls for the thread.
+ /// </summary>
+ /// <param name="dwCallType">The parameter is not used.</param>
+ /// <param name="hTaskCaller">The parameter is not used.</param>
+ /// <param name="dwTickCount">The parameter is not used.</param>
+ /// <param name="lpInterfaceInfo">The parameter is not used.</param>
+ /// <returns>Code indicating message was handled.</returns>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage(
+ "Microsoft.StyleCop.CSharp.NamingRules",
+ "SA1305:FieldNamesMustNotUseHungarianNotation",
+ Justification = "Matching variable name to COM interface")]
+ [PreserveSig]
+ int HandleInComingCall(
+ int dwCallType,
+ IntPtr hTaskCaller,
+ int dwTickCount,
+ IntPtr lpInterfaceInfo);
+
+ /// <summary>
+ /// Automatically retries the failed call.
+ /// </summary>
+ /// <param name="hTaskCallee">The parameter is not used.</param>
+ /// <param name="dwTickCount">The parameter is not used.</param>
+ /// <param name="dwRejectType">The parameter is not used.</param>
+ /// <returns>Code indicating call should be retried.</returns>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage(
+ "Microsoft.StyleCop.CSharp.NamingRules",
+ "SA1305:FieldNamesMustNotUseHungarianNotation",
+ Justification = "Matching variable name to COM interface")]
+ [PreserveSig]
+ int RetryRejectedCall(IntPtr hTaskCallee, int dwTickCount, int dwRejectType);
+
+ /// <summary>
+ /// Handles an incoming message by indicating it should be dispatched always.
+ /// </summary>
+ /// <param name="hTaskCallee">The parameter is not used.</param>
+ /// <param name="dwTickCount">The parameter is not used.</param>
+ /// <param name="dwPendingType">The parameter is not used.</param>
+ /// <returns>Code indicating message should be dispatched.</returns>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage(
+ "Microsoft.StyleCop.CSharp.NamingRules",
+ "SA1305:FieldNamesMustNotUseHungarianNotation",
+ Justification = "Matching variable name to COM interface")]
+ [PreserveSig]
+ int MessagePending(IntPtr hTaskCallee, int dwTickCount, int dwPendingType);
+ }
+
+ /// <summary>
+ /// This class receives messages from the COM calls to Visual Studio
+ /// and auto-retries them if they fail because VS is busy.
+ /// </summary>
+ public class ComMessageFilter : IOleMessageFilter
+ {
+ /// <summary>
+ /// Note this registers the filter only for the current thread.
+ /// </summary>
+ public static void Register()
+ {
+ IOleMessageFilter oldFilter = null;
+ CoRegisterMessageFilter(new ComMessageFilter(), out oldFilter);
+ }
+
+ /// <summary>
+ /// Note this only closes the filter for the current thread.
+ /// </summary>
+ public static void Revoke()
+ {
+ IOleMessageFilter oldFilter = null;
+ CoRegisterMessageFilter(null, out oldFilter);
+ }
+
+ /// <summary>
+ /// Handles calls for the thread.
+ /// </summary>
+ /// <param name="dwCallType">The parameter is not used.</param>
+ /// <param name="hTaskCaller">The parameter is not used.</param>
+ /// <param name="dwTickCount">The parameter is not used.</param>
+ /// <param name="lpInterfaceInfo">The parameter is not used.</param>
+ /// <returns>Code indicating message was handled.</returns>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage(
+ "Microsoft.StyleCop.CSharp.NamingRules",
+ "SA1305:FieldNamesMustNotUseHungarianNotation",
+ Justification = "Matching variable name to COM interface")]
+ int IOleMessageFilter.HandleInComingCall(
+ int dwCallType,
+ System.IntPtr hTaskCaller,
+ int dwTickCount,
+ System.IntPtr lpInterfaceInfo)
+ {
+ return 0; // SERVERCALL_ISHANDLED.
+ }
+
+ /// <summary>
+ /// Automatically retries the failed call.
+ /// </summary>
+ /// <param name="hTaskCallee">The parameter is not used.</param>
+ /// <param name="dwTickCount">The parameter is not used.</param>
+ /// <param name="dwRejectType">The parameter is not used.</param>
+ /// <returns>Code indicating call should be retried.</returns>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage(
+ "Microsoft.StyleCop.CSharp.NamingRules",
+ "SA1305:FieldNamesMustNotUseHungarianNotation",
+ Justification = "Matching variable name to COM interface")]
+ int IOleMessageFilter.RetryRejectedCall(
+ System.IntPtr hTaskCallee,
+ int dwTickCount,
+ int dwRejectType)
+ {
+ // If reject type is SERVERCALL_RETRYLATER.
+ if (dwRejectType == 2)
+ {
+ // Immediate retry.
+ return 99;
+ }
+
+ // Cancel call.
+ return -1;
+ }
+
+ /// <summary>
+ /// Handles an incoming message by indicating it should be dispatched always.
+ /// </summary>
+ /// <param name="hTaskCallee">The parameter is not used.</param>
+ /// <param name="dwTickCount">The parameter is not used.</param>
+ /// <param name="dwPendingType">The parameter is not used.</param>
+ /// <returns>Code indicating message should be dispatched.</returns>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage(
+ "Microsoft.StyleCop.CSharp.NamingRules",
+ "SA1305:FieldNamesMustNotUseHungarianNotation",
+ Justification = "Matching variable name to COM interface")]
+ int IOleMessageFilter.MessagePending(
+ System.IntPtr hTaskCallee,
+ int dwTickCount,
+ int dwPendingType)
+ {
+ return 2; // PENDINGMSG_WAITDEFPROCESS.
+ }
+
+ // Implement the IOleMessageFilter interface.
+ [DllImport("Ole32.dll")]
+ private static extern int CoRegisterMessageFilter(
+ IOleMessageFilter newFilter, out IOleMessageFilter oldFilter);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698