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

Side by Side Diff: remoting/base/dispatch_win.h.pump

Issue 10532099: Switching to IDispatch::Invoke when calling Omaha interfaces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 $$ This is a pump file for generating file templates. Pump is a python
2 $$ script that is part of the Google Test suite of utilities. Description
3 $$ can be found here:
4 $$
5 $$ http://code.google.com/p/googletest/wiki/PumpManual
6
7 $$ MAX_ARITY controls the number of arguments that dispatch::Invoke() supports.
8 $$ It is choosend to match the number of arguments base::Bind() supports.
Wez 2012/06/13 00:34:36 choosend -> chosen
alexeypa (please no reviews) 2012/06/13 16:39:47 Done.
9 $var MAX_ARITY = 7
10 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
11 // Use of this source code is governed by a BSD-style license that can be
12 // found in the LICENSE file.
13
14 #ifndef REMOTING_BASE_IDISPATCH_DRIVER_WIN_H_
15 #define REMOTING_BASE_IDISPATCH_DRIVER_WIN_H_
16
17 #include <oaidl.h>
18
19 #include "base/basictypes.h"
20 #include "base/template_util.h"
21 #include "base/win/scoped_variant.h"
22
23 namespace remoting {
24
25 namespace dispatch {
26
27 namespace internal {
28
29 // |is_param| is used to test whether the passed parameters are either constant
30 // references to |VARIANT| structures (input parameters) or pointers to
31 // |VARIANT| structures (output parameters).
Wez 2012/06/13 00:34:36 Why do you need that? If Marshal() were simply an
alexeypa (please no reviews) 2012/06/13 16:39:47 It wasn't really needed. Overloaded methods work m
32 template <typename T> struct is_param : base::false_type {};
33 template <> struct is_param<VARIANT> : base::true_type {};
34 template <> struct is_param<base::win::ScopedVariant> : base::true_type {};
35 template <> struct is_param<VARIANT*> : base::true_type {};
36
37 // |ScopedVariantArg| is used to cleanup local copies of |VARIANT| parameters
38 // in case of an error. It should be possible to cast a pointer to a vector of
39 // |ScopedVariantArg| to a pointer to a vector of |VARIANTARG| strcutures.
Wez 2012/06/13 00:34:36 strcutures -> structures
Wez 2012/06/13 00:34:36 For this to make sense the reader needs two bits o
alexeypa (please no reviews) 2012/06/13 16:39:47 Done.
alexeypa (please no reviews) 2012/06/13 16:39:47 Done.
40 class ScopedVariantArg : public VARIANTARG {
Wez 2012/06/13 00:34:36 Would it make sense to derived from base::win::Sco
alexeypa (please no reviews) 2012/06/13 16:39:47 I don't think so. base::win::ScopedVariant seems t
Wez 2012/06/13 17:55:15 Actually I'd missed that this derives from VARIANT
alexeypa (please no reviews) 2012/06/13 18:45:11 VARIANT and VARIANTARG is the same thing.
41 public:
42 ScopedVariantArg() {
43 vt = VT_EMPTY;
44 }
45
46 ~ScopedVariantArg() {
47 VariantClear(this);
48 }
49
50 // Marshall() routines copy an input parameter to a VARIANTARG structure so
51 // that it can be passed to IDispatch::Invoke.
52 template <typename T>
53 HRESULT Marshall(const T& param) {
Wez 2012/06/13 00:34:36 Marshall -> Marshal
alexeypa (please no reviews) 2012/06/13 16:39:47 Done.
54 CHECK(false);
55 return E_FAIL;
56 }
57
58 template <>
59 HRESULT Marshall<VARIANT>(const VARIANT& param) {
60 return VariantCopy(this, &param);
61 }
62
63 template <>
64 HRESULT Marshall<base::win::ScopedVariant>(
65 const base::win::ScopedVariant& param) {
Wez 2012/06/13 00:34:36 Do you need this? ScopedVariant has an implicit co
alexeypa (please no reviews) 2012/06/13 16:39:47 The implicit conversion works if it is an overload
66 return VariantCopy(this, &param);
67 }
68
69 template <>
70 HRESULT Marshall<VARIANT*>(VARIANT* const & param) {
Wez 2012/06/13 00:34:36 Add a comment to clarify that this is the out-para
alexeypa (please no reviews) 2012/06/13 16:39:47 Done.
71 return S_OK;
72 }
73
74 // Unmarshall() routines moves an output parameter from a VARIANTARG structure
75 // to the location specified by the caller.
76 template <typename T>
77 void Unmarshall(const T& param_out) {
Wez 2012/06/13 00:34:36 Unmarshall -> Unmarshal
alexeypa (please no reviews) 2012/06/13 16:39:47 Done.
78 CHECK(false);
79 }
80
81 template <>
82 void Unmarshall<VARIANT>(const VARIANT& param_out) {
83 }
84
85 template <>
86 void Unmarshall<base::win::ScopedVariant>(
87 const base::win::ScopedVariant& param_out) {
88 }
89
90 template <>
91 void Unmarshall<VARIANT*>(VARIANT* const & param_out) {
92 *param_out = *this;
93 vt = VT_EMPTY;
94 }
95
96 private:
97 DISALLOW_COPY_AND_ASSIGN(ScopedVariantArg);
98 };
99
100 // Make sure the layout of |VARIANTARG| and |ScopedVariantArg| is identical.
101 COMPILE_ASSERT(sizeof(ScopedVariantArg) == sizeof(VARIANTARG),
102 scoped_variant_arg_should_not_add_data_members);
103
104 } // namespace internal
105
106 // Invoke() is a convenience wrapper for IDispatch::Invoke. It takes care of
107 // calling the desired method by its ID and implements logic for passing
108 // a variable number of in/out parameters to the called method.
109 //
110 // Current limitations:
111 // - in_out parameters are not supported.
112 // - more than $(MAX_ARITY) parameters are not supported.
113 // - the method ID cannot be cached and reused.
114 // - VARIANT is the only supported parameter type at the moment.
115 $range ARITY 0..MAX_ARITY
116 $for ARITY [[
117 $range ARG 1..ARITY
118
119
120 $if ARITY > 0 [[template <$for ARG , [[typename P$(ARG)]]>]]
121
122 HRESULT Invoke(IDispatch* object,
123 LPOLESTR name,
124 WORD flags,
125 $for ARG [[
126
127 const P$(ARG)& p$(ARG),
128 ]]
129
130 VARIANT* const & result_out) {
131 $for ARG [[
132
133 COMPILE_ASSERT(internal::is_param<P$(ARG)>::value, parameters_must_be_variants );
Wez 2012/06/13 00:34:36 nit: Line too long?
alexeypa (please no reviews) 2012/06/13 16:39:47 This line was removed.
134 ]]
135
136
137 // Retrieve the ID of the method to be called.
138 DISPID disp_id;
139 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
140 &disp_id);
141 if (FAILED(hr))
142 return hr;
143
144 // Request the return value if asked by the caller.
145 internal::ScopedVariantArg result;
146 VARIANT* disp_result = NULL;
147 if (result_out != NULL)
148 disp_result = &result;
149
150 $if ARITY > 0 [[
151
152 // Marshal the parameters into an array of VARIANT structures.
153 internal::ScopedVariantArg disp_args[$(ARITY)];
154 $for ARG [[
155
156 hr = disp_args[$(ARITY) - $(ARG)].Marshall(p$(ARG));
157 if (FAILED(hr))
158 return hr;
159 ]]
160 ]]
161
162
163 // Invoke the method.
164 DISPPARAMS disp_params = { $if ARITY > 0 [[disp_args]] $else [[NULL]], NULL, $ (ARITY), 0 };
Wez 2012/06/13 00:34:36 nit: Line too long?
alexeypa (please no reviews) 2012/06/13 16:39:47 Only the one in .pump. I changed it so that the li
165 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
166 &disp_params, disp_result, NULL, NULL);
167 if (FAILED(hr))
168 return hr;
169
170 $if ARITY > 0 [[
171
172 // Unmarshall the parameters.
173 $for ARG [[
174
175 disp_args[$(ARITY) - $(ARG)].Unmarshall(p$(ARG));
176 ]]
177 ]]
178
179
180 // Unmarshall the return value.
181 if (result_out != NULL)
182 result.Unmarshall(result_out);
183
184 return S_OK;
185 }
186
187 ]]
188
189 } // namespace dispatch
190
191 } // namespace remoting
192
193 #endif // REMOTING_BASE_IDISPATCH_DRIVER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698