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

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: 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') | remoting/base/dispatch_win.h.pump » ('J')
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!!!
Wez 2012/06/13 00:34:36 I'm going to assume you haven't edited by hand, an
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 // |is_param| is used to test whether the passed parameters are either constant
25 // references to |VARIANT| structures (input parameters) or pointers to
26 // |VARIANT| structures (output parameters).
27 template <typename T> struct is_param : base::false_type {};
28 template <> struct is_param<VARIANT> : base::true_type {};
29 template <> struct is_param<base::win::ScopedVariant> : base::true_type {};
30 template <> struct is_param<VARIANT*> : base::true_type {};
31
32 // |ScopedVariantArg| is used to cleanup local copies of |VARIANT| parameters
33 // in case of an error. It should be possible to cast a pointer to a vector of
34 // |ScopedVariantArg| to a pointer to a vector of |VARIANTARG| strcutures.
35 class ScopedVariantArg : public VARIANTARG {
36 public:
37 ScopedVariantArg() {
38 vt = VT_EMPTY;
39 }
40
41 ~ScopedVariantArg() {
42 VariantClear(this);
43 }
44
45 // Marshall() routines copy an input parameter to a VARIANTARG structure so
46 // that it can be passed to IDispatch::Invoke.
47 template <typename T>
48 HRESULT Marshall(const T& param) {
49 CHECK(false);
50 return E_FAIL;
51 }
52
53 template <>
54 HRESULT Marshall<VARIANT>(const VARIANT& param) {
55 return VariantCopy(this, &param);
56 }
57
58 template <>
59 HRESULT Marshall<base::win::ScopedVariant>(
60 const base::win::ScopedVariant& param) {
61 return VariantCopy(this, &param);
62 }
63
64 template <>
65 HRESULT Marshall<VARIANT*>(VARIANT* const & param) {
66 return S_OK;
67 }
68
69 // Unmarshall() routines moves an output parameter from a VARIANTARG structure
70 // to the location specified by the caller.
71 template <typename T>
72 void Unmarshall(const T& param_out) {
73 CHECK(false);
74 }
75
76 template <>
77 void Unmarshall<VARIANT>(const VARIANT& param_out) {
78 }
79
80 template <>
81 void Unmarshall<base::win::ScopedVariant>(
82 const base::win::ScopedVariant& param_out) {
83 }
84
85 template <>
86 void Unmarshall<VARIANT*>(VARIANT* const & param_out) {
87 *param_out = *this;
88 vt = VT_EMPTY;
89 }
90
91 private:
92 DISALLOW_COPY_AND_ASSIGN(ScopedVariantArg);
93 };
94
95 // Make sure the layout of |VARIANTARG| and |ScopedVariantArg| is identical.
96 COMPILE_ASSERT(sizeof(ScopedVariantArg) == sizeof(VARIANTARG),
97 scoped_variant_arg_should_not_add_data_members);
98
99 } // namespace internal
100
101 // Invoke() is a convenience wrapper for IDispatch::Invoke. It takes care of
102 // calling the desired method by its ID and implements logic for passing
103 // a variable number of in/out parameters to the called method.
104 //
105 // Current limitations:
106 // - in_out parameters are not supported.
107 // - more than 7 parameters are not supported.
108 // - the method ID cannot be cached and reused.
109 // - VARIANT is the only supported parameter type at the moment.
110
111 HRESULT Invoke(IDispatch* object,
112 LPOLESTR name,
113 WORD flags,
114 VARIANT* const & result_out) {
115
116 // Retrieve the ID of the method to be called.
117 DISPID disp_id;
118 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
119 &disp_id);
120 if (FAILED(hr))
121 return hr;
122
123 // Request the return value if asked by the caller.
124 internal::ScopedVariantArg result;
125 VARIANT* disp_result = NULL;
126 if (result_out != NULL)
127 disp_result = &result;
128
129
130 // Invoke the method.
131 DISPPARAMS disp_params = { NULL, NULL, 0, 0 };
132 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
133 &disp_params, disp_result, NULL, NULL);
134 if (FAILED(hr))
135 return hr;
136
137
138 // Unmarshall the return value.
139 if (result_out != NULL)
140 result.Unmarshall(result_out);
141
142 return S_OK;
143 }
144
145 template <typename P1>
146 HRESULT Invoke(IDispatch* object,
147 LPOLESTR name,
148 WORD flags,
149 const P1& p1,
150 VARIANT* const & result_out) {
151 COMPILE_ASSERT(internal::is_param<P1>::value, parameters_must_be_variants);
152
153 // Retrieve the ID of the method to be called.
154 DISPID disp_id;
155 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
156 &disp_id);
157 if (FAILED(hr))
158 return hr;
159
160 // Request the return value if asked by the caller.
161 internal::ScopedVariantArg result;
162 VARIANT* disp_result = NULL;
163 if (result_out != NULL)
164 disp_result = &result;
165
166 // Marshal the parameters into an array of VARIANT structures.
167 internal::ScopedVariantArg disp_args[1];
168 hr = disp_args[1 - 1].Marshall(p1);
169 if (FAILED(hr))
170 return hr;
171
172 // Invoke the method.
173 DISPPARAMS disp_params = { disp_args, NULL, 1, 0 };
174 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
175 &disp_params, disp_result, NULL, NULL);
176 if (FAILED(hr))
177 return hr;
178
179 // Unmarshall the parameters.
180 disp_args[1 - 1].Unmarshall(p1);
181
182 // Unmarshall the return value.
183 if (result_out != NULL)
184 result.Unmarshall(result_out);
185
186 return S_OK;
187 }
188
189 template <typename P1, typename P2>
190 HRESULT Invoke(IDispatch* object,
191 LPOLESTR name,
192 WORD flags,
193 const P1& p1,
194 const P2& p2,
195 VARIANT* const & result_out) {
196 COMPILE_ASSERT(internal::is_param<P1>::value, parameters_must_be_variants);
197 COMPILE_ASSERT(internal::is_param<P2>::value, parameters_must_be_variants);
198
199 // Retrieve the ID of the method to be called.
200 DISPID disp_id;
201 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
202 &disp_id);
203 if (FAILED(hr))
204 return hr;
205
206 // Request the return value if asked by the caller.
207 internal::ScopedVariantArg result;
208 VARIANT* disp_result = NULL;
209 if (result_out != NULL)
210 disp_result = &result;
211
212 // Marshal the parameters into an array of VARIANT structures.
213 internal::ScopedVariantArg disp_args[2];
214 hr = disp_args[2 - 1].Marshall(p1);
215 if (FAILED(hr))
216 return hr;
217 hr = disp_args[2 - 2].Marshall(p2);
218 if (FAILED(hr))
219 return hr;
220
221 // Invoke the method.
222 DISPPARAMS disp_params = { disp_args, NULL, 2, 0 };
223 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
224 &disp_params, disp_result, NULL, NULL);
225 if (FAILED(hr))
226 return hr;
227
228 // Unmarshall the parameters.
229 disp_args[2 - 1].Unmarshall(p1);
230 disp_args[2 - 2].Unmarshall(p2);
231
232 // Unmarshall the return value.
233 if (result_out != NULL)
234 result.Unmarshall(result_out);
235
236 return S_OK;
237 }
238
239 template <typename P1, typename P2, typename P3>
240 HRESULT Invoke(IDispatch* object,
241 LPOLESTR name,
242 WORD flags,
243 const P1& p1,
244 const P2& p2,
245 const P3& p3,
246 VARIANT* const & result_out) {
247 COMPILE_ASSERT(internal::is_param<P1>::value, parameters_must_be_variants);
248 COMPILE_ASSERT(internal::is_param<P2>::value, parameters_must_be_variants);
249 COMPILE_ASSERT(internal::is_param<P3>::value, parameters_must_be_variants);
250
251 // Retrieve the ID of the method to be called.
252 DISPID disp_id;
253 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
254 &disp_id);
255 if (FAILED(hr))
256 return hr;
257
258 // Request the return value if asked by the caller.
259 internal::ScopedVariantArg result;
260 VARIANT* disp_result = NULL;
261 if (result_out != NULL)
262 disp_result = &result;
263
264 // Marshal the parameters into an array of VARIANT structures.
265 internal::ScopedVariantArg disp_args[3];
266 hr = disp_args[3 - 1].Marshall(p1);
267 if (FAILED(hr))
268 return hr;
269 hr = disp_args[3 - 2].Marshall(p2);
270 if (FAILED(hr))
271 return hr;
272 hr = disp_args[3 - 3].Marshall(p3);
273 if (FAILED(hr))
274 return hr;
275
276 // Invoke the method.
277 DISPPARAMS disp_params = { disp_args, NULL, 3, 0 };
278 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
279 &disp_params, disp_result, NULL, NULL);
280 if (FAILED(hr))
281 return hr;
282
283 // Unmarshall the parameters.
284 disp_args[3 - 1].Unmarshall(p1);
285 disp_args[3 - 2].Unmarshall(p2);
286 disp_args[3 - 3].Unmarshall(p3);
287
288 // Unmarshall the return value.
289 if (result_out != NULL)
290 result.Unmarshall(result_out);
291
292 return S_OK;
293 }
294
295 template <typename P1, typename P2, typename P3, typename P4>
296 HRESULT Invoke(IDispatch* object,
297 LPOLESTR name,
298 WORD flags,
299 const P1& p1,
300 const P2& p2,
301 const P3& p3,
302 const P4& p4,
303 VARIANT* const & result_out) {
304 COMPILE_ASSERT(internal::is_param<P1>::value, parameters_must_be_variants);
305 COMPILE_ASSERT(internal::is_param<P2>::value, parameters_must_be_variants);
306 COMPILE_ASSERT(internal::is_param<P3>::value, parameters_must_be_variants);
307 COMPILE_ASSERT(internal::is_param<P4>::value, parameters_must_be_variants);
308
309 // Retrieve the ID of the method to be called.
310 DISPID disp_id;
311 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
312 &disp_id);
313 if (FAILED(hr))
314 return hr;
315
316 // Request the return value if asked by the caller.
317 internal::ScopedVariantArg result;
318 VARIANT* disp_result = NULL;
319 if (result_out != NULL)
320 disp_result = &result;
321
322 // Marshal the parameters into an array of VARIANT structures.
323 internal::ScopedVariantArg disp_args[4];
324 hr = disp_args[4 - 1].Marshall(p1);
325 if (FAILED(hr))
326 return hr;
327 hr = disp_args[4 - 2].Marshall(p2);
328 if (FAILED(hr))
329 return hr;
330 hr = disp_args[4 - 3].Marshall(p3);
331 if (FAILED(hr))
332 return hr;
333 hr = disp_args[4 - 4].Marshall(p4);
334 if (FAILED(hr))
335 return hr;
336
337 // Invoke the method.
338 DISPPARAMS disp_params = { disp_args, NULL, 4, 0 };
339 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
340 &disp_params, disp_result, NULL, NULL);
341 if (FAILED(hr))
342 return hr;
343
344 // Unmarshall the parameters.
345 disp_args[4 - 1].Unmarshall(p1);
346 disp_args[4 - 2].Unmarshall(p2);
347 disp_args[4 - 3].Unmarshall(p3);
348 disp_args[4 - 4].Unmarshall(p4);
349
350 // Unmarshall the return value.
351 if (result_out != NULL)
352 result.Unmarshall(result_out);
353
354 return S_OK;
355 }
356
357 template <typename P1, typename P2, typename P3, typename P4, typename P5>
358 HRESULT Invoke(IDispatch* object,
359 LPOLESTR name,
360 WORD flags,
361 const P1& p1,
362 const P2& p2,
363 const P3& p3,
364 const P4& p4,
365 const P5& p5,
366 VARIANT* const & result_out) {
367 COMPILE_ASSERT(internal::is_param<P1>::value, parameters_must_be_variants);
368 COMPILE_ASSERT(internal::is_param<P2>::value, parameters_must_be_variants);
369 COMPILE_ASSERT(internal::is_param<P3>::value, parameters_must_be_variants);
370 COMPILE_ASSERT(internal::is_param<P4>::value, parameters_must_be_variants);
371 COMPILE_ASSERT(internal::is_param<P5>::value, parameters_must_be_variants);
372
373 // Retrieve the ID of the method to be called.
374 DISPID disp_id;
375 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
376 &disp_id);
377 if (FAILED(hr))
378 return hr;
379
380 // Request the return value if asked by the caller.
381 internal::ScopedVariantArg result;
382 VARIANT* disp_result = NULL;
383 if (result_out != NULL)
384 disp_result = &result;
385
386 // Marshal the parameters into an array of VARIANT structures.
387 internal::ScopedVariantArg disp_args[5];
388 hr = disp_args[5 - 1].Marshall(p1);
389 if (FAILED(hr))
390 return hr;
391 hr = disp_args[5 - 2].Marshall(p2);
392 if (FAILED(hr))
393 return hr;
394 hr = disp_args[5 - 3].Marshall(p3);
395 if (FAILED(hr))
396 return hr;
397 hr = disp_args[5 - 4].Marshall(p4);
398 if (FAILED(hr))
399 return hr;
400 hr = disp_args[5 - 5].Marshall(p5);
401 if (FAILED(hr))
402 return hr;
403
404 // Invoke the method.
405 DISPPARAMS disp_params = { disp_args, NULL, 5, 0 };
406 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
407 &disp_params, disp_result, NULL, NULL);
408 if (FAILED(hr))
409 return hr;
410
411 // Unmarshall the parameters.
412 disp_args[5 - 1].Unmarshall(p1);
413 disp_args[5 - 2].Unmarshall(p2);
414 disp_args[5 - 3].Unmarshall(p3);
415 disp_args[5 - 4].Unmarshall(p4);
416 disp_args[5 - 5].Unmarshall(p5);
417
418 // Unmarshall the return value.
419 if (result_out != NULL)
420 result.Unmarshall(result_out);
421
422 return S_OK;
423 }
424
425 template <typename P1, typename P2, typename P3, typename P4, typename P5,
426 typename P6>
427 HRESULT Invoke(IDispatch* object,
428 LPOLESTR name,
429 WORD flags,
430 const P1& p1,
431 const P2& p2,
432 const P3& p3,
433 const P4& p4,
434 const P5& p5,
435 const P6& p6,
436 VARIANT* const & result_out) {
437 COMPILE_ASSERT(internal::is_param<P1>::value, parameters_must_be_variants);
438 COMPILE_ASSERT(internal::is_param<P2>::value, parameters_must_be_variants);
439 COMPILE_ASSERT(internal::is_param<P3>::value, parameters_must_be_variants);
440 COMPILE_ASSERT(internal::is_param<P4>::value, parameters_must_be_variants);
441 COMPILE_ASSERT(internal::is_param<P5>::value, parameters_must_be_variants);
442 COMPILE_ASSERT(internal::is_param<P6>::value, parameters_must_be_variants);
443
444 // Retrieve the ID of the method to be called.
445 DISPID disp_id;
446 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
447 &disp_id);
448 if (FAILED(hr))
449 return hr;
450
451 // Request the return value if asked by the caller.
452 internal::ScopedVariantArg result;
453 VARIANT* disp_result = NULL;
454 if (result_out != NULL)
455 disp_result = &result;
456
457 // Marshal the parameters into an array of VARIANT structures.
458 internal::ScopedVariantArg disp_args[6];
459 hr = disp_args[6 - 1].Marshall(p1);
460 if (FAILED(hr))
461 return hr;
462 hr = disp_args[6 - 2].Marshall(p2);
463 if (FAILED(hr))
464 return hr;
465 hr = disp_args[6 - 3].Marshall(p3);
466 if (FAILED(hr))
467 return hr;
468 hr = disp_args[6 - 4].Marshall(p4);
469 if (FAILED(hr))
470 return hr;
471 hr = disp_args[6 - 5].Marshall(p5);
472 if (FAILED(hr))
473 return hr;
474 hr = disp_args[6 - 6].Marshall(p6);
475 if (FAILED(hr))
476 return hr;
477
478 // Invoke the method.
479 DISPPARAMS disp_params = { disp_args, NULL, 6, 0 };
480 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
481 &disp_params, disp_result, NULL, NULL);
482 if (FAILED(hr))
483 return hr;
484
485 // Unmarshall the parameters.
486 disp_args[6 - 1].Unmarshall(p1);
487 disp_args[6 - 2].Unmarshall(p2);
488 disp_args[6 - 3].Unmarshall(p3);
489 disp_args[6 - 4].Unmarshall(p4);
490 disp_args[6 - 5].Unmarshall(p5);
491 disp_args[6 - 6].Unmarshall(p6);
492
493 // Unmarshall the return value.
494 if (result_out != NULL)
495 result.Unmarshall(result_out);
496
497 return S_OK;
498 }
499
500 template <typename P1, typename P2, typename P3, typename P4, typename P5,
501 typename P6, typename P7>
502 HRESULT Invoke(IDispatch* object,
503 LPOLESTR name,
504 WORD flags,
505 const P1& p1,
506 const P2& p2,
507 const P3& p3,
508 const P4& p4,
509 const P5& p5,
510 const P6& p6,
511 const P7& p7,
512 VARIANT* const & result_out) {
513 COMPILE_ASSERT(internal::is_param<P1>::value, parameters_must_be_variants);
514 COMPILE_ASSERT(internal::is_param<P2>::value, parameters_must_be_variants);
515 COMPILE_ASSERT(internal::is_param<P3>::value, parameters_must_be_variants);
516 COMPILE_ASSERT(internal::is_param<P4>::value, parameters_must_be_variants);
517 COMPILE_ASSERT(internal::is_param<P5>::value, parameters_must_be_variants);
518 COMPILE_ASSERT(internal::is_param<P6>::value, parameters_must_be_variants);
519 COMPILE_ASSERT(internal::is_param<P7>::value, parameters_must_be_variants);
520
521 // Retrieve the ID of the method to be called.
522 DISPID disp_id;
523 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
524 &disp_id);
525 if (FAILED(hr))
526 return hr;
527
528 // Request the return value if asked by the caller.
529 internal::ScopedVariantArg result;
530 VARIANT* disp_result = NULL;
531 if (result_out != NULL)
532 disp_result = &result;
533
534 // Marshal the parameters into an array of VARIANT structures.
535 internal::ScopedVariantArg disp_args[7];
536 hr = disp_args[7 - 1].Marshall(p1);
537 if (FAILED(hr))
538 return hr;
539 hr = disp_args[7 - 2].Marshall(p2);
540 if (FAILED(hr))
541 return hr;
542 hr = disp_args[7 - 3].Marshall(p3);
543 if (FAILED(hr))
544 return hr;
545 hr = disp_args[7 - 4].Marshall(p4);
546 if (FAILED(hr))
547 return hr;
548 hr = disp_args[7 - 5].Marshall(p5);
549 if (FAILED(hr))
550 return hr;
551 hr = disp_args[7 - 6].Marshall(p6);
552 if (FAILED(hr))
553 return hr;
554 hr = disp_args[7 - 7].Marshall(p7);
555 if (FAILED(hr))
556 return hr;
557
558 // Invoke the method.
559 DISPPARAMS disp_params = { disp_args, NULL, 7, 0 };
560 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags,
561 &disp_params, disp_result, NULL, NULL);
562 if (FAILED(hr))
563 return hr;
564
565 // Unmarshall the parameters.
566 disp_args[7 - 1].Unmarshall(p1);
567 disp_args[7 - 2].Unmarshall(p2);
568 disp_args[7 - 3].Unmarshall(p3);
569 disp_args[7 - 4].Unmarshall(p4);
570 disp_args[7 - 5].Unmarshall(p5);
571 disp_args[7 - 6].Unmarshall(p6);
572 disp_args[7 - 7].Unmarshall(p7);
573
574 // Unmarshall the return value.
575 if (result_out != NULL)
576 result.Unmarshall(result_out);
577
578 return S_OK;
579 }
580
581 } // namespace dispatch
582
583 } // namespace remoting
584
585 #endif // REMOTING_BASE_IDISPATCH_DRIVER_WIN_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/base/dispatch_win.h.pump » ('j') | remoting/base/dispatch_win.h.pump » ('J')

Powered by Google App Engine
This is Rietveld 408576698