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

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

Issue 10532099: Switching to IDispatch::Invoke when calling Omaha interfaces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR feedback. 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
« no previous file with comments | « no previous file | remoting/base/dispatch_win.h.pump » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // This file was GENERATED by command:
2 // pump.py dispatch_win.h.pump
3 // DO NOT EDIT BY HAND!!!
4
5 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style license that can be
7 // found in the LICENSE file.
8
9 #ifndef REMOTING_BASE_IDISPATCH_DRIVER_WIN_H_
10 #define REMOTING_BASE_IDISPATCH_DRIVER_WIN_H_
11
12 #include <oaidl.h>
13
14 #include "base/basictypes.h"
15 #include "base/template_util.h"
16 #include "base/win/scoped_variant.h"
17
18 namespace remoting {
19
20 namespace dispatch {
21
22 namespace internal {
23
24 // A helper wrapper for |VARIANTARG| that is used to pass parameters to and from
25 // IDispatch::Invoke(). The latter accepts parameters as an array of
26 // |VARIANTARG| structures. The calling convention is:
27 // - [in] parameters are initialized and freed if needed by the caller.
28 // - [out] parameters are initialized by IDispatch::Invoke(). It if up to
Wez 2012/06/13 17:55:16 typo: if -> is
alexeypa (please no reviews) 2012/06/13 18:45:11 Done.
29 // the caller to free leakable variants (such as VT_DISPATCH).
Wez 2012/06/13 17:55:16 It's also the case that any value in the VARIANT o
alexeypa (please no reviews) 2012/06/13 18:45:11 No, it is not. One should be able to pass a pointe
Wez 2012/06/13 21:02:16 In which case it's important that the supplied VAR
alexeypa (please no reviews) 2012/06/14 16:27:20 The same rule applies to any other C++ function ta
30 // - [in] [out] parameters are combination of both: the caller initializes
31 // them before the call and the callee assigns new values correctly
32 // freeing leakable variants.
33 //
34 // Using |ScopedVariantArg| instead of naked |VARIANTARG| ensures that
35 // the resources allocated during the call will be properly freed. It also
36 // provides marshaling methods that convert between C++ types and VARIANTs.
Wez 2012/06/13 17:55:16 nit: This implies that you could pass e.g. an int
alexeypa (please no reviews) 2012/06/13 18:45:11 With proper support (i.e. Marshal/Unmarshal method
Wez 2012/06/13 21:02:16 OK; consider adding a line to clarify that current
alexeypa (please no reviews) 2012/06/14 16:27:20 Will do.
37 // The current convention is:
38 // - constant references are considered input parameters.
39 // - pointers to non-constant objects are considered output parameters.
40 // - [in] [out] parameters are not supported.
41 //
42 // It should be possible to cast a pointer to an array of |ScopedVariantArg| to
Wez 2012/06/13 17:55:16 nit: should -> must?
alexeypa (please no reviews) 2012/06/13 18:45:11 Done.
43 // a pointer to an array of |VARIANTARG| structures.
44 class ScopedVariantArg : public VARIANTARG {
45 public:
46 ScopedVariantArg() {
47 vt = VT_EMPTY;
48 }
49
50 ~ScopedVariantArg() {
51 VariantClear(this);
52 }
53
54 // Marshal() routines pack the input parameters into VARIANTARG structures so
55 // that they can be passed to IDispatch::Invoke.
56 HRESULT Marshal(const VARIANT& param) {
Wez 2012/06/13 17:55:16 nit: I would recommend CopyFrom rather than Marsha
alexeypa (please no reviews) 2012/06/13 18:45:11 CopyFrom sounds confusing to me. It also does not
Wez 2012/06/13 21:02:16 CopyFrom() describes the actual action that the ca
alexeypa (please no reviews) 2012/06/14 16:27:20 I still think CopyFrom() is one level too verbose
57 return VariantCopy(this, &param);
58 }
59
60 HRESULT Marshal(VARIANT* const & param) {
61 // Do nothing for an [out] parameter.
62 return S_OK;
63 }
64
65 // Unmarshal() routines unpack the output parameter from VARIANTARG structures
66 // to the locations specified by the caller.
67 void Unmarshal(const VARIANT& param_out) {
Wez 2012/06/13 17:55:16 nit: Similarly, I'd recommend MoveTo rather then U
68 // Do nothing for an [in] parameter.
69 }
70
71 void Unmarshal(VARIANT* const & param_out) {
72 *param_out = *this;
Wez 2012/06/13 17:55:16 Do you need to VariantClear() param_out before rep
alexeypa (please no reviews) 2012/06/13 18:45:11 No, *param_out is not initialized at this point.
73 vt = VT_EMPTY;
74 }
75
76 private:
77 DISALLOW_COPY_AND_ASSIGN(ScopedVariantArg);
78 };
79
80 // Make sure the layouts of |VARIANTARG| and |ScopedVariantArg| are identical.
81 COMPILE_ASSERT(sizeof(ScopedVariantArg) == sizeof(VARIANTARG),
82 scoped_variant_arg_should_not_add_data_members);
83
84 } // namespace internal
85
86 // Invoke() is a convenience wrapper for IDispatch::Invoke. It takes care of
87 // calling the desired method by its ID and implements logic for passing
88 // a variable number of in/out parameters to the called method.
89 //
90 // Current limitations:
91 // - in_out parameters are not supported.
92 // - more than 7 parameters are not supported.
93 // - the method ID cannot be cached and reused.
94 // - VARIANT is the only supported parameter type at the moment.
95
96 HRESULT Invoke(IDispatch* object,
97 LPOLESTR name,
98 WORD flags,
99 VARIANT* const & result_out) {
100 // Retrieve the ID of the method to be called.
101 DISPID disp_id;
102 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
103 &disp_id);
104 if (FAILED(hr))
105 return hr;
106
107 // Request the return value if asked by the caller.
108 internal::ScopedVariantArg result;
109 VARIANT* disp_result = NULL;
110 if (result_out != NULL)
111 disp_result = &result;
112
113
114 // Invoke the method.
115 DISPPARAMS disp_params = { NULL, NULL, 0, 0 };
116 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
117 &disp_params, disp_result, NULL, NULL);
118 if (FAILED(hr))
119 return hr;
120
121
122 // Unmarshal the return value.
123 if (result_out != NULL)
124 result.Unmarshal(result_out);
125
126 return S_OK;
127 }
128
129 template <typename P1>
130 HRESULT Invoke(IDispatch* object,
131 LPOLESTR name,
132 WORD flags,
133 const P1& p1,
134 VARIANT* const & result_out) {
135 // Retrieve the ID of the method to be called.
136 DISPID disp_id;
137 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
138 &disp_id);
139 if (FAILED(hr))
140 return hr;
141
142 // Request the return value if asked by the caller.
143 internal::ScopedVariantArg result;
144 VARIANT* disp_result = NULL;
145 if (result_out != NULL)
146 disp_result = &result;
147
148 // Marshal the parameters into an array of VARIANT structures.
149 internal::ScopedVariantArg disp_args[1];
150 hr = disp_args[1 - 1].Marshal(p1);
151 if (FAILED(hr))
152 return hr;
153
154 // Invoke the method.
155 DISPPARAMS disp_params = { disp_args, NULL, 1, 0 };
156 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
157 &disp_params, disp_result, NULL, NULL);
158 if (FAILED(hr))
159 return hr;
160
161 // Unmarshal the parameters.
162 disp_args[1 - 1].Unmarshal(p1);
163
164 // Unmarshal the return value.
165 if (result_out != NULL)
166 result.Unmarshal(result_out);
167
168 return S_OK;
169 }
170
171 template <typename P1, typename P2>
172 HRESULT Invoke(IDispatch* object,
173 LPOLESTR name,
174 WORD flags,
175 const P1& p1,
176 const P2& p2,
177 VARIANT* const & result_out) {
178 // Retrieve the ID of the method to be called.
179 DISPID disp_id;
180 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
181 &disp_id);
182 if (FAILED(hr))
183 return hr;
184
185 // Request the return value if asked by the caller.
186 internal::ScopedVariantArg result;
187 VARIANT* disp_result = NULL;
188 if (result_out != NULL)
189 disp_result = &result;
190
191 // Marshal the parameters into an array of VARIANT structures.
192 internal::ScopedVariantArg disp_args[2];
193 hr = disp_args[2 - 1].Marshal(p1);
194 if (FAILED(hr))
195 return hr;
196 hr = disp_args[2 - 2].Marshal(p2);
197 if (FAILED(hr))
198 return hr;
199
200 // Invoke the method.
201 DISPPARAMS disp_params = { disp_args, NULL, 2, 0 };
202 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
203 &disp_params, disp_result, NULL, NULL);
204 if (FAILED(hr))
205 return hr;
206
207 // Unmarshal the parameters.
208 disp_args[2 - 1].Unmarshal(p1);
209 disp_args[2 - 2].Unmarshal(p2);
210
211 // Unmarshal the return value.
212 if (result_out != NULL)
213 result.Unmarshal(result_out);
214
215 return S_OK;
216 }
217
218 template <typename P1, typename P2, typename P3>
219 HRESULT Invoke(IDispatch* object,
220 LPOLESTR name,
221 WORD flags,
222 const P1& p1,
223 const P2& p2,
224 const P3& p3,
225 VARIANT* const & result_out) {
226 // Retrieve the ID of the method to be called.
227 DISPID disp_id;
228 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
229 &disp_id);
230 if (FAILED(hr))
231 return hr;
232
233 // Request the return value if asked by the caller.
234 internal::ScopedVariantArg result;
235 VARIANT* disp_result = NULL;
236 if (result_out != NULL)
237 disp_result = &result;
238
239 // Marshal the parameters into an array of VARIANT structures.
240 internal::ScopedVariantArg disp_args[3];
241 hr = disp_args[3 - 1].Marshal(p1);
242 if (FAILED(hr))
243 return hr;
244 hr = disp_args[3 - 2].Marshal(p2);
245 if (FAILED(hr))
246 return hr;
247 hr = disp_args[3 - 3].Marshal(p3);
248 if (FAILED(hr))
249 return hr;
250
251 // Invoke the method.
252 DISPPARAMS disp_params = { disp_args, NULL, 3, 0 };
253 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
254 &disp_params, disp_result, NULL, NULL);
255 if (FAILED(hr))
256 return hr;
257
258 // Unmarshal the parameters.
259 disp_args[3 - 1].Unmarshal(p1);
260 disp_args[3 - 2].Unmarshal(p2);
261 disp_args[3 - 3].Unmarshal(p3);
262
263 // Unmarshal the return value.
264 if (result_out != NULL)
265 result.Unmarshal(result_out);
266
267 return S_OK;
268 }
269
270 template <typename P1, typename P2, typename P3, typename P4>
271 HRESULT Invoke(IDispatch* object,
272 LPOLESTR name,
273 WORD flags,
274 const P1& p1,
275 const P2& p2,
276 const P3& p3,
277 const P4& p4,
278 VARIANT* const & result_out) {
279 // Retrieve the ID of the method to be called.
280 DISPID disp_id;
281 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
282 &disp_id);
283 if (FAILED(hr))
284 return hr;
285
286 // Request the return value if asked by the caller.
287 internal::ScopedVariantArg result;
288 VARIANT* disp_result = NULL;
289 if (result_out != NULL)
290 disp_result = &result;
291
292 // Marshal the parameters into an array of VARIANT structures.
293 internal::ScopedVariantArg disp_args[4];
294 hr = disp_args[4 - 1].Marshal(p1);
295 if (FAILED(hr))
296 return hr;
297 hr = disp_args[4 - 2].Marshal(p2);
298 if (FAILED(hr))
299 return hr;
300 hr = disp_args[4 - 3].Marshal(p3);
301 if (FAILED(hr))
302 return hr;
303 hr = disp_args[4 - 4].Marshal(p4);
304 if (FAILED(hr))
305 return hr;
306
307 // Invoke the method.
308 DISPPARAMS disp_params = { disp_args, NULL, 4, 0 };
309 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
310 &disp_params, disp_result, NULL, NULL);
311 if (FAILED(hr))
312 return hr;
313
314 // Unmarshal the parameters.
315 disp_args[4 - 1].Unmarshal(p1);
316 disp_args[4 - 2].Unmarshal(p2);
317 disp_args[4 - 3].Unmarshal(p3);
318 disp_args[4 - 4].Unmarshal(p4);
319
320 // Unmarshal the return value.
321 if (result_out != NULL)
322 result.Unmarshal(result_out);
323
324 return S_OK;
325 }
326
327 template <typename P1, typename P2, typename P3, typename P4, typename P5>
328 HRESULT Invoke(IDispatch* object,
329 LPOLESTR name,
330 WORD flags,
331 const P1& p1,
332 const P2& p2,
333 const P3& p3,
334 const P4& p4,
335 const P5& p5,
336 VARIANT* const & result_out) {
337 // Retrieve the ID of the method to be called.
338 DISPID disp_id;
339 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
340 &disp_id);
341 if (FAILED(hr))
342 return hr;
343
344 // Request the return value if asked by the caller.
345 internal::ScopedVariantArg result;
346 VARIANT* disp_result = NULL;
347 if (result_out != NULL)
348 disp_result = &result;
349
350 // Marshal the parameters into an array of VARIANT structures.
351 internal::ScopedVariantArg disp_args[5];
352 hr = disp_args[5 - 1].Marshal(p1);
353 if (FAILED(hr))
354 return hr;
355 hr = disp_args[5 - 2].Marshal(p2);
356 if (FAILED(hr))
357 return hr;
358 hr = disp_args[5 - 3].Marshal(p3);
359 if (FAILED(hr))
360 return hr;
361 hr = disp_args[5 - 4].Marshal(p4);
362 if (FAILED(hr))
363 return hr;
364 hr = disp_args[5 - 5].Marshal(p5);
365 if (FAILED(hr))
366 return hr;
367
368 // Invoke the method.
369 DISPPARAMS disp_params = { disp_args, NULL, 5, 0 };
370 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
371 &disp_params, disp_result, NULL, NULL);
372 if (FAILED(hr))
373 return hr;
374
375 // Unmarshal the parameters.
376 disp_args[5 - 1].Unmarshal(p1);
377 disp_args[5 - 2].Unmarshal(p2);
378 disp_args[5 - 3].Unmarshal(p3);
379 disp_args[5 - 4].Unmarshal(p4);
380 disp_args[5 - 5].Unmarshal(p5);
381
382 // Unmarshal the return value.
383 if (result_out != NULL)
384 result.Unmarshal(result_out);
385
386 return S_OK;
387 }
388
389 template <typename P1, typename P2, typename P3, typename P4, typename P5,
390 typename P6>
391 HRESULT Invoke(IDispatch* object,
392 LPOLESTR name,
393 WORD flags,
394 const P1& p1,
395 const P2& p2,
396 const P3& p3,
397 const P4& p4,
398 const P5& p5,
399 const P6& p6,
400 VARIANT* const & result_out) {
401 // Retrieve the ID of the method to be called.
402 DISPID disp_id;
403 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
404 &disp_id);
405 if (FAILED(hr))
406 return hr;
407
408 // Request the return value if asked by the caller.
409 internal::ScopedVariantArg result;
410 VARIANT* disp_result = NULL;
411 if (result_out != NULL)
412 disp_result = &result;
413
414 // Marshal the parameters into an array of VARIANT structures.
415 internal::ScopedVariantArg disp_args[6];
416 hr = disp_args[6 - 1].Marshal(p1);
417 if (FAILED(hr))
418 return hr;
419 hr = disp_args[6 - 2].Marshal(p2);
420 if (FAILED(hr))
421 return hr;
422 hr = disp_args[6 - 3].Marshal(p3);
423 if (FAILED(hr))
424 return hr;
425 hr = disp_args[6 - 4].Marshal(p4);
426 if (FAILED(hr))
427 return hr;
428 hr = disp_args[6 - 5].Marshal(p5);
429 if (FAILED(hr))
430 return hr;
431 hr = disp_args[6 - 6].Marshal(p6);
432 if (FAILED(hr))
433 return hr;
434
435 // Invoke the method.
436 DISPPARAMS disp_params = { disp_args, NULL, 6, 0 };
437 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
438 &disp_params, disp_result, NULL, NULL);
439 if (FAILED(hr))
440 return hr;
441
442 // Unmarshal the parameters.
443 disp_args[6 - 1].Unmarshal(p1);
444 disp_args[6 - 2].Unmarshal(p2);
445 disp_args[6 - 3].Unmarshal(p3);
446 disp_args[6 - 4].Unmarshal(p4);
447 disp_args[6 - 5].Unmarshal(p5);
448 disp_args[6 - 6].Unmarshal(p6);
449
450 // Unmarshal the return value.
451 if (result_out != NULL)
452 result.Unmarshal(result_out);
453
454 return S_OK;
455 }
456
457 template <typename P1, typename P2, typename P3, typename P4, typename P5,
458 typename P6, typename P7>
459 HRESULT Invoke(IDispatch* object,
460 LPOLESTR name,
461 WORD flags,
462 const P1& p1,
463 const P2& p2,
464 const P3& p3,
465 const P4& p4,
466 const P5& p5,
467 const P6& p6,
468 const P7& p7,
469 VARIANT* const & result_out) {
470 // Retrieve the ID of the method to be called.
471 DISPID disp_id;
472 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
473 &disp_id);
474 if (FAILED(hr))
475 return hr;
476
477 // Request the return value if asked by the caller.
478 internal::ScopedVariantArg result;
479 VARIANT* disp_result = NULL;
480 if (result_out != NULL)
481 disp_result = &result;
482
483 // Marshal the parameters into an array of VARIANT structures.
484 internal::ScopedVariantArg disp_args[7];
485 hr = disp_args[7 - 1].Marshal(p1);
486 if (FAILED(hr))
487 return hr;
488 hr = disp_args[7 - 2].Marshal(p2);
489 if (FAILED(hr))
490 return hr;
491 hr = disp_args[7 - 3].Marshal(p3);
492 if (FAILED(hr))
493 return hr;
494 hr = disp_args[7 - 4].Marshal(p4);
495 if (FAILED(hr))
496 return hr;
497 hr = disp_args[7 - 5].Marshal(p5);
498 if (FAILED(hr))
499 return hr;
500 hr = disp_args[7 - 6].Marshal(p6);
501 if (FAILED(hr))
502 return hr;
503 hr = disp_args[7 - 7].Marshal(p7);
504 if (FAILED(hr))
505 return hr;
506
507 // Invoke the method.
508 DISPPARAMS disp_params = { disp_args, NULL, 7, 0 };
509 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
510 &disp_params, disp_result, NULL, NULL);
511 if (FAILED(hr))
512 return hr;
513
514 // Unmarshal the parameters.
515 disp_args[7 - 1].Unmarshal(p1);
516 disp_args[7 - 2].Unmarshal(p2);
517 disp_args[7 - 3].Unmarshal(p3);
518 disp_args[7 - 4].Unmarshal(p4);
519 disp_args[7 - 5].Unmarshal(p5);
520 disp_args[7 - 6].Unmarshal(p6);
521 disp_args[7 - 7].Unmarshal(p7);
522
523 // Unmarshal the return value.
524 if (result_out != NULL)
525 result.Unmarshal(result_out);
526
527 return S_OK;
528 }
529
530 } // namespace dispatch
531
532 } // namespace remoting
533
534 #endif // REMOTING_BASE_IDISPATCH_DRIVER_WIN_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/base/dispatch_win.h.pump » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698