Chromium Code Reviews| Index: remoting/base/dispatch_win.h |
| diff --git a/remoting/base/dispatch_win.h b/remoting/base/dispatch_win.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4c82fa8faf108df7073c464248ea8829c447080b |
| --- /dev/null |
| +++ b/remoting/base/dispatch_win.h |
| @@ -0,0 +1,585 @@ |
| +// This file was GENERATED by command: |
| +// pump.py dispatch_win.h.pump |
| +// DO NOT EDIT BY HAND!!! |
|
Wez
2012/06/13 00:34:36
I'm going to assume you haven't edited by hand, an
|
| + |
| +// 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. |
| + |
| +#ifndef REMOTING_BASE_IDISPATCH_DRIVER_WIN_H_ |
| +#define REMOTING_BASE_IDISPATCH_DRIVER_WIN_H_ |
| + |
| +#include <oaidl.h> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/template_util.h" |
| +#include "base/win/scoped_variant.h" |
| + |
| +namespace remoting { |
| + |
| +namespace dispatch { |
| + |
| +namespace internal { |
| + |
| +// |is_param| is used to test whether the passed parameters are either constant |
| +// references to |VARIANT| structures (input parameters) or pointers to |
| +// |VARIANT| structures (output parameters). |
| +template <typename T> struct is_param : base::false_type {}; |
| +template <> struct is_param<VARIANT> : base::true_type {}; |
| +template <> struct is_param<base::win::ScopedVariant> : base::true_type {}; |
| +template <> struct is_param<VARIANT*> : base::true_type {}; |
| + |
| +// |ScopedVariantArg| is used to cleanup local copies of |VARIANT| parameters |
| +// in case of an error. It should be possible to cast a pointer to a vector of |
| +// |ScopedVariantArg| to a pointer to a vector of |VARIANTARG| strcutures. |
| +class ScopedVariantArg : public VARIANTARG { |
| + public: |
| + ScopedVariantArg() { |
| + vt = VT_EMPTY; |
| + } |
| + |
| + ~ScopedVariantArg() { |
| + VariantClear(this); |
| + } |
| + |
| + // Marshall() routines copy an input parameter to a VARIANTARG structure so |
| + // that it can be passed to IDispatch::Invoke. |
| + template <typename T> |
| + HRESULT Marshall(const T& param) { |
| + CHECK(false); |
| + return E_FAIL; |
| + } |
| + |
| + template <> |
| + HRESULT Marshall<VARIANT>(const VARIANT& param) { |
| + return VariantCopy(this, ¶m); |
| + } |
| + |
| + template <> |
| + HRESULT Marshall<base::win::ScopedVariant>( |
| + const base::win::ScopedVariant& param) { |
| + return VariantCopy(this, ¶m); |
| + } |
| + |
| + template <> |
| + HRESULT Marshall<VARIANT*>(VARIANT* const & param) { |
| + return S_OK; |
| + } |
| + |
| + // Unmarshall() routines moves an output parameter from a VARIANTARG structure |
| + // to the location specified by the caller. |
| + template <typename T> |
| + void Unmarshall(const T& param_out) { |
| + CHECK(false); |
| + } |
| + |
| + template <> |
| + void Unmarshall<VARIANT>(const VARIANT& param_out) { |
| + } |
| + |
| + template <> |
| + void Unmarshall<base::win::ScopedVariant>( |
| + const base::win::ScopedVariant& param_out) { |
| + } |
| + |
| + template <> |
| + void Unmarshall<VARIANT*>(VARIANT* const & param_out) { |
| + *param_out = *this; |
| + vt = VT_EMPTY; |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ScopedVariantArg); |
| +}; |
| + |
| +// Make sure the layout of |VARIANTARG| and |ScopedVariantArg| is identical. |
| +COMPILE_ASSERT(sizeof(ScopedVariantArg) == sizeof(VARIANTARG), |
| + scoped_variant_arg_should_not_add_data_members); |
| + |
| +} // namespace internal |
| + |
| +// Invoke() is a convenience wrapper for IDispatch::Invoke. It takes care of |
| +// calling the desired method by its ID and implements logic for passing |
| +// a variable number of in/out parameters to the called method. |
| +// |
| +// Current limitations: |
| +// - in_out parameters are not supported. |
| +// - more than 7 parameters are not supported. |
| +// - the method ID cannot be cached and reused. |
| +// - VARIANT is the only supported parameter type at the moment. |
| + |
| +HRESULT Invoke(IDispatch* object, |
| + LPOLESTR name, |
| + WORD flags, |
| + VARIANT* const & result_out) { |
| + |
| + // Retrieve the ID of the method to be called. |
| + DISPID disp_id; |
| + HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, |
| + &disp_id); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Request the return value if asked by the caller. |
| + internal::ScopedVariantArg result; |
| + VARIANT* disp_result = NULL; |
| + if (result_out != NULL) |
| + disp_result = &result; |
| + |
| + |
| + // Invoke the method. |
| + DISPPARAMS disp_params = { NULL, NULL, 0, 0 }; |
| + hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags, |
| + &disp_params, disp_result, NULL, NULL); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + |
| + // Unmarshall the return value. |
| + if (result_out != NULL) |
| + result.Unmarshall(result_out); |
| + |
| + return S_OK; |
| +} |
| + |
| +template <typename P1> |
| +HRESULT Invoke(IDispatch* object, |
| + LPOLESTR name, |
| + WORD flags, |
| + const P1& p1, |
| + VARIANT* const & result_out) { |
| + COMPILE_ASSERT(internal::is_param<P1>::value, parameters_must_be_variants); |
| + |
| + // Retrieve the ID of the method to be called. |
| + DISPID disp_id; |
| + HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, |
| + &disp_id); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Request the return value if asked by the caller. |
| + internal::ScopedVariantArg result; |
| + VARIANT* disp_result = NULL; |
| + if (result_out != NULL) |
| + disp_result = &result; |
| + |
| + // Marshal the parameters into an array of VARIANT structures. |
| + internal::ScopedVariantArg disp_args[1]; |
| + hr = disp_args[1 - 1].Marshall(p1); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Invoke the method. |
| + DISPPARAMS disp_params = { disp_args, NULL, 1, 0 }; |
| + hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags, |
| + &disp_params, disp_result, NULL, NULL); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Unmarshall the parameters. |
| + disp_args[1 - 1].Unmarshall(p1); |
| + |
| + // Unmarshall the return value. |
| + if (result_out != NULL) |
| + result.Unmarshall(result_out); |
| + |
| + return S_OK; |
| +} |
| + |
| +template <typename P1, typename P2> |
| +HRESULT Invoke(IDispatch* object, |
| + LPOLESTR name, |
| + WORD flags, |
| + const P1& p1, |
| + const P2& p2, |
| + VARIANT* const & result_out) { |
| + COMPILE_ASSERT(internal::is_param<P1>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P2>::value, parameters_must_be_variants); |
| + |
| + // Retrieve the ID of the method to be called. |
| + DISPID disp_id; |
| + HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, |
| + &disp_id); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Request the return value if asked by the caller. |
| + internal::ScopedVariantArg result; |
| + VARIANT* disp_result = NULL; |
| + if (result_out != NULL) |
| + disp_result = &result; |
| + |
| + // Marshal the parameters into an array of VARIANT structures. |
| + internal::ScopedVariantArg disp_args[2]; |
| + hr = disp_args[2 - 1].Marshall(p1); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[2 - 2].Marshall(p2); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Invoke the method. |
| + DISPPARAMS disp_params = { disp_args, NULL, 2, 0 }; |
| + hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags, |
| + &disp_params, disp_result, NULL, NULL); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Unmarshall the parameters. |
| + disp_args[2 - 1].Unmarshall(p1); |
| + disp_args[2 - 2].Unmarshall(p2); |
| + |
| + // Unmarshall the return value. |
| + if (result_out != NULL) |
| + result.Unmarshall(result_out); |
| + |
| + return S_OK; |
| +} |
| + |
| +template <typename P1, typename P2, typename P3> |
| +HRESULT Invoke(IDispatch* object, |
| + LPOLESTR name, |
| + WORD flags, |
| + const P1& p1, |
| + const P2& p2, |
| + const P3& p3, |
| + VARIANT* const & result_out) { |
| + COMPILE_ASSERT(internal::is_param<P1>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P2>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P3>::value, parameters_must_be_variants); |
| + |
| + // Retrieve the ID of the method to be called. |
| + DISPID disp_id; |
| + HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, |
| + &disp_id); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Request the return value if asked by the caller. |
| + internal::ScopedVariantArg result; |
| + VARIANT* disp_result = NULL; |
| + if (result_out != NULL) |
| + disp_result = &result; |
| + |
| + // Marshal the parameters into an array of VARIANT structures. |
| + internal::ScopedVariantArg disp_args[3]; |
| + hr = disp_args[3 - 1].Marshall(p1); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[3 - 2].Marshall(p2); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[3 - 3].Marshall(p3); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Invoke the method. |
| + DISPPARAMS disp_params = { disp_args, NULL, 3, 0 }; |
| + hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags, |
| + &disp_params, disp_result, NULL, NULL); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Unmarshall the parameters. |
| + disp_args[3 - 1].Unmarshall(p1); |
| + disp_args[3 - 2].Unmarshall(p2); |
| + disp_args[3 - 3].Unmarshall(p3); |
| + |
| + // Unmarshall the return value. |
| + if (result_out != NULL) |
| + result.Unmarshall(result_out); |
| + |
| + return S_OK; |
| +} |
| + |
| +template <typename P1, typename P2, typename P3, typename P4> |
| +HRESULT Invoke(IDispatch* object, |
| + LPOLESTR name, |
| + WORD flags, |
| + const P1& p1, |
| + const P2& p2, |
| + const P3& p3, |
| + const P4& p4, |
| + VARIANT* const & result_out) { |
| + COMPILE_ASSERT(internal::is_param<P1>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P2>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P3>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P4>::value, parameters_must_be_variants); |
| + |
| + // Retrieve the ID of the method to be called. |
| + DISPID disp_id; |
| + HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, |
| + &disp_id); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Request the return value if asked by the caller. |
| + internal::ScopedVariantArg result; |
| + VARIANT* disp_result = NULL; |
| + if (result_out != NULL) |
| + disp_result = &result; |
| + |
| + // Marshal the parameters into an array of VARIANT structures. |
| + internal::ScopedVariantArg disp_args[4]; |
| + hr = disp_args[4 - 1].Marshall(p1); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[4 - 2].Marshall(p2); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[4 - 3].Marshall(p3); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[4 - 4].Marshall(p4); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Invoke the method. |
| + DISPPARAMS disp_params = { disp_args, NULL, 4, 0 }; |
| + hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags, |
| + &disp_params, disp_result, NULL, NULL); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Unmarshall the parameters. |
| + disp_args[4 - 1].Unmarshall(p1); |
| + disp_args[4 - 2].Unmarshall(p2); |
| + disp_args[4 - 3].Unmarshall(p3); |
| + disp_args[4 - 4].Unmarshall(p4); |
| + |
| + // Unmarshall the return value. |
| + if (result_out != NULL) |
| + result.Unmarshall(result_out); |
| + |
| + return S_OK; |
| +} |
| + |
| +template <typename P1, typename P2, typename P3, typename P4, typename P5> |
| +HRESULT Invoke(IDispatch* object, |
| + LPOLESTR name, |
| + WORD flags, |
| + const P1& p1, |
| + const P2& p2, |
| + const P3& p3, |
| + const P4& p4, |
| + const P5& p5, |
| + VARIANT* const & result_out) { |
| + COMPILE_ASSERT(internal::is_param<P1>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P2>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P3>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P4>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P5>::value, parameters_must_be_variants); |
| + |
| + // Retrieve the ID of the method to be called. |
| + DISPID disp_id; |
| + HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, |
| + &disp_id); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Request the return value if asked by the caller. |
| + internal::ScopedVariantArg result; |
| + VARIANT* disp_result = NULL; |
| + if (result_out != NULL) |
| + disp_result = &result; |
| + |
| + // Marshal the parameters into an array of VARIANT structures. |
| + internal::ScopedVariantArg disp_args[5]; |
| + hr = disp_args[5 - 1].Marshall(p1); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[5 - 2].Marshall(p2); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[5 - 3].Marshall(p3); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[5 - 4].Marshall(p4); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[5 - 5].Marshall(p5); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Invoke the method. |
| + DISPPARAMS disp_params = { disp_args, NULL, 5, 0 }; |
| + hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags, |
| + &disp_params, disp_result, NULL, NULL); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Unmarshall the parameters. |
| + disp_args[5 - 1].Unmarshall(p1); |
| + disp_args[5 - 2].Unmarshall(p2); |
| + disp_args[5 - 3].Unmarshall(p3); |
| + disp_args[5 - 4].Unmarshall(p4); |
| + disp_args[5 - 5].Unmarshall(p5); |
| + |
| + // Unmarshall the return value. |
| + if (result_out != NULL) |
| + result.Unmarshall(result_out); |
| + |
| + return S_OK; |
| +} |
| + |
| +template <typename P1, typename P2, typename P3, typename P4, typename P5, |
| + typename P6> |
| +HRESULT Invoke(IDispatch* object, |
| + LPOLESTR name, |
| + WORD flags, |
| + const P1& p1, |
| + const P2& p2, |
| + const P3& p3, |
| + const P4& p4, |
| + const P5& p5, |
| + const P6& p6, |
| + VARIANT* const & result_out) { |
| + COMPILE_ASSERT(internal::is_param<P1>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P2>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P3>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P4>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P5>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P6>::value, parameters_must_be_variants); |
| + |
| + // Retrieve the ID of the method to be called. |
| + DISPID disp_id; |
| + HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, |
| + &disp_id); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Request the return value if asked by the caller. |
| + internal::ScopedVariantArg result; |
| + VARIANT* disp_result = NULL; |
| + if (result_out != NULL) |
| + disp_result = &result; |
| + |
| + // Marshal the parameters into an array of VARIANT structures. |
| + internal::ScopedVariantArg disp_args[6]; |
| + hr = disp_args[6 - 1].Marshall(p1); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[6 - 2].Marshall(p2); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[6 - 3].Marshall(p3); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[6 - 4].Marshall(p4); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[6 - 5].Marshall(p5); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[6 - 6].Marshall(p6); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Invoke the method. |
| + DISPPARAMS disp_params = { disp_args, NULL, 6, 0 }; |
| + hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags, |
| + &disp_params, disp_result, NULL, NULL); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Unmarshall the parameters. |
| + disp_args[6 - 1].Unmarshall(p1); |
| + disp_args[6 - 2].Unmarshall(p2); |
| + disp_args[6 - 3].Unmarshall(p3); |
| + disp_args[6 - 4].Unmarshall(p4); |
| + disp_args[6 - 5].Unmarshall(p5); |
| + disp_args[6 - 6].Unmarshall(p6); |
| + |
| + // Unmarshall the return value. |
| + if (result_out != NULL) |
| + result.Unmarshall(result_out); |
| + |
| + return S_OK; |
| +} |
| + |
| +template <typename P1, typename P2, typename P3, typename P4, typename P5, |
| + typename P6, typename P7> |
| +HRESULT Invoke(IDispatch* object, |
| + LPOLESTR name, |
| + WORD flags, |
| + const P1& p1, |
| + const P2& p2, |
| + const P3& p3, |
| + const P4& p4, |
| + const P5& p5, |
| + const P6& p6, |
| + const P7& p7, |
| + VARIANT* const & result_out) { |
| + COMPILE_ASSERT(internal::is_param<P1>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P2>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P3>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P4>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P5>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P6>::value, parameters_must_be_variants); |
| + COMPILE_ASSERT(internal::is_param<P7>::value, parameters_must_be_variants); |
| + |
| + // Retrieve the ID of the method to be called. |
| + DISPID disp_id; |
| + HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, |
| + &disp_id); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Request the return value if asked by the caller. |
| + internal::ScopedVariantArg result; |
| + VARIANT* disp_result = NULL; |
| + if (result_out != NULL) |
| + disp_result = &result; |
| + |
| + // Marshal the parameters into an array of VARIANT structures. |
| + internal::ScopedVariantArg disp_args[7]; |
| + hr = disp_args[7 - 1].Marshall(p1); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[7 - 2].Marshall(p2); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[7 - 3].Marshall(p3); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[7 - 4].Marshall(p4); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[7 - 5].Marshall(p5); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[7 - 6].Marshall(p6); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = disp_args[7 - 7].Marshall(p7); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Invoke the method. |
| + DISPPARAMS disp_params = { disp_args, NULL, 7, 0 }; |
| + hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags, |
| + &disp_params, disp_result, NULL, NULL); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + // Unmarshall the parameters. |
| + disp_args[7 - 1].Unmarshall(p1); |
| + disp_args[7 - 2].Unmarshall(p2); |
| + disp_args[7 - 3].Unmarshall(p3); |
| + disp_args[7 - 4].Unmarshall(p4); |
| + disp_args[7 - 5].Unmarshall(p5); |
| + disp_args[7 - 6].Unmarshall(p6); |
| + disp_args[7 - 7].Unmarshall(p7); |
| + |
| + // Unmarshall the return value. |
| + if (result_out != NULL) |
| + result.Unmarshall(result_out); |
| + |
| + return S_OK; |
| +} |
| + |
| +} // namespace dispatch |
| + |
| +} // namespace remoting |
| + |
| +#endif // REMOTING_BASE_IDISPATCH_DRIVER_WIN_H_ |