| OLD | NEW |
| (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 is up to |
| 29 // the caller to free leakable variants (such as VT_DISPATCH). |
| 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 wraping methods that convert between C++ types and VARIANTs. |
| 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 must be possible to cast a pointer to an array of |ScopedVariantArg| to |
| 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 // Wrap() routines pack the input parameters into VARIANTARG structures so |
| 55 // that they can be passed to IDispatch::Invoke. |
| 56 |
| 57 HRESULT Wrap(const VARIANT& param) { |
| 58 return VariantCopy(this, ¶m); |
| 59 } |
| 60 |
| 61 HRESULT Wrap(VARIANT* const & param) { |
| 62 // Do nothing for an [out] parameter. |
| 63 return S_OK; |
| 64 } |
| 65 |
| 66 // Unwrap() routines unpack the output parameters from VARIANTARG structures |
| 67 // to the locations specified by the caller. |
| 68 |
| 69 void Unwrap(const VARIANT& param_out) { |
| 70 // Do nothing for an [in] parameter. |
| 71 } |
| 72 |
| 73 void Unwrap(VARIANT* const & param_out) { |
| 74 *param_out = *this; |
| 75 vt = VT_EMPTY; |
| 76 } |
| 77 |
| 78 private: |
| 79 DISALLOW_COPY_AND_ASSIGN(ScopedVariantArg); |
| 80 }; |
| 81 |
| 82 // Make sure the layouts of |VARIANTARG| and |ScopedVariantArg| are identical. |
| 83 COMPILE_ASSERT(sizeof(ScopedVariantArg) == sizeof(VARIANTARG), |
| 84 scoped_variant_arg_should_not_add_data_members); |
| 85 |
| 86 } // namespace internal |
| 87 |
| 88 // Invoke() is a convenience wrapper for IDispatch::Invoke. It takes care of |
| 89 // calling the desired method by its ID and implements logic for passing |
| 90 // a variable number of in/out parameters to the called method. |
| 91 // |
| 92 // Current limitations: |
| 93 // - in_out parameters are not supported. |
| 94 // - more than 7 parameters are not supported. |
| 95 // - the method ID cannot be cached and reused. |
| 96 // - VARIANT is the only supported parameter type at the moment. |
| 97 |
| 98 HRESULT Invoke(IDispatch* object, |
| 99 LPOLESTR name, |
| 100 WORD flags, |
| 101 VARIANT* const & result_out) { |
| 102 // Retrieve the ID of the method to be called. |
| 103 DISPID disp_id; |
| 104 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, |
| 105 &disp_id); |
| 106 if (FAILED(hr)) |
| 107 return hr; |
| 108 |
| 109 // Request the return value if asked by the caller. |
| 110 internal::ScopedVariantArg result; |
| 111 VARIANT* disp_result = NULL; |
| 112 if (result_out != NULL) |
| 113 disp_result = &result; |
| 114 |
| 115 |
| 116 // Invoke the method. |
| 117 DISPPARAMS disp_params = { NULL, NULL, 0, 0 }; |
| 118 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags, |
| 119 &disp_params, disp_result, NULL, NULL); |
| 120 if (FAILED(hr)) |
| 121 return hr; |
| 122 |
| 123 |
| 124 // Unwrap the return value. |
| 125 if (result_out != NULL) |
| 126 result.Unwrap(result_out); |
| 127 |
| 128 return S_OK; |
| 129 } |
| 130 |
| 131 template <typename P1> |
| 132 HRESULT Invoke(IDispatch* object, |
| 133 LPOLESTR name, |
| 134 WORD flags, |
| 135 const P1& p1, |
| 136 VARIANT* const & result_out) { |
| 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 // Wrap the parameters into an array of VARIANT structures. |
| 151 internal::ScopedVariantArg disp_args[1]; |
| 152 hr = disp_args[1 - 1].Wrap(p1); |
| 153 if (FAILED(hr)) |
| 154 return hr; |
| 155 |
| 156 // Invoke the method. |
| 157 DISPPARAMS disp_params = { disp_args, NULL, 1, 0 }; |
| 158 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags, |
| 159 &disp_params, disp_result, NULL, NULL); |
| 160 if (FAILED(hr)) |
| 161 return hr; |
| 162 |
| 163 // Unwrap the parameters. |
| 164 disp_args[1 - 1].Unwrap(p1); |
| 165 |
| 166 // Unwrap the return value. |
| 167 if (result_out != NULL) |
| 168 result.Unwrap(result_out); |
| 169 |
| 170 return S_OK; |
| 171 } |
| 172 |
| 173 template <typename P1, typename P2> |
| 174 HRESULT Invoke(IDispatch* object, |
| 175 LPOLESTR name, |
| 176 WORD flags, |
| 177 const P1& p1, |
| 178 const P2& p2, |
| 179 VARIANT* const & result_out) { |
| 180 // Retrieve the ID of the method to be called. |
| 181 DISPID disp_id; |
| 182 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, |
| 183 &disp_id); |
| 184 if (FAILED(hr)) |
| 185 return hr; |
| 186 |
| 187 // Request the return value if asked by the caller. |
| 188 internal::ScopedVariantArg result; |
| 189 VARIANT* disp_result = NULL; |
| 190 if (result_out != NULL) |
| 191 disp_result = &result; |
| 192 |
| 193 // Wrap the parameters into an array of VARIANT structures. |
| 194 internal::ScopedVariantArg disp_args[2]; |
| 195 hr = disp_args[2 - 1].Wrap(p1); |
| 196 if (FAILED(hr)) |
| 197 return hr; |
| 198 hr = disp_args[2 - 2].Wrap(p2); |
| 199 if (FAILED(hr)) |
| 200 return hr; |
| 201 |
| 202 // Invoke the method. |
| 203 DISPPARAMS disp_params = { disp_args, NULL, 2, 0 }; |
| 204 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags, |
| 205 &disp_params, disp_result, NULL, NULL); |
| 206 if (FAILED(hr)) |
| 207 return hr; |
| 208 |
| 209 // Unwrap the parameters. |
| 210 disp_args[2 - 1].Unwrap(p1); |
| 211 disp_args[2 - 2].Unwrap(p2); |
| 212 |
| 213 // Unwrap the return value. |
| 214 if (result_out != NULL) |
| 215 result.Unwrap(result_out); |
| 216 |
| 217 return S_OK; |
| 218 } |
| 219 |
| 220 template <typename P1, typename P2, typename P3> |
| 221 HRESULT Invoke(IDispatch* object, |
| 222 LPOLESTR name, |
| 223 WORD flags, |
| 224 const P1& p1, |
| 225 const P2& p2, |
| 226 const P3& p3, |
| 227 VARIANT* const & result_out) { |
| 228 // Retrieve the ID of the method to be called. |
| 229 DISPID disp_id; |
| 230 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, |
| 231 &disp_id); |
| 232 if (FAILED(hr)) |
| 233 return hr; |
| 234 |
| 235 // Request the return value if asked by the caller. |
| 236 internal::ScopedVariantArg result; |
| 237 VARIANT* disp_result = NULL; |
| 238 if (result_out != NULL) |
| 239 disp_result = &result; |
| 240 |
| 241 // Wrap the parameters into an array of VARIANT structures. |
| 242 internal::ScopedVariantArg disp_args[3]; |
| 243 hr = disp_args[3 - 1].Wrap(p1); |
| 244 if (FAILED(hr)) |
| 245 return hr; |
| 246 hr = disp_args[3 - 2].Wrap(p2); |
| 247 if (FAILED(hr)) |
| 248 return hr; |
| 249 hr = disp_args[3 - 3].Wrap(p3); |
| 250 if (FAILED(hr)) |
| 251 return hr; |
| 252 |
| 253 // Invoke the method. |
| 254 DISPPARAMS disp_params = { disp_args, NULL, 3, 0 }; |
| 255 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags, |
| 256 &disp_params, disp_result, NULL, NULL); |
| 257 if (FAILED(hr)) |
| 258 return hr; |
| 259 |
| 260 // Unwrap the parameters. |
| 261 disp_args[3 - 1].Unwrap(p1); |
| 262 disp_args[3 - 2].Unwrap(p2); |
| 263 disp_args[3 - 3].Unwrap(p3); |
| 264 |
| 265 // Unwrap the return value. |
| 266 if (result_out != NULL) |
| 267 result.Unwrap(result_out); |
| 268 |
| 269 return S_OK; |
| 270 } |
| 271 |
| 272 template <typename P1, typename P2, typename P3, typename P4> |
| 273 HRESULT Invoke(IDispatch* object, |
| 274 LPOLESTR name, |
| 275 WORD flags, |
| 276 const P1& p1, |
| 277 const P2& p2, |
| 278 const P3& p3, |
| 279 const P4& p4, |
| 280 VARIANT* const & result_out) { |
| 281 // Retrieve the ID of the method to be called. |
| 282 DISPID disp_id; |
| 283 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, |
| 284 &disp_id); |
| 285 if (FAILED(hr)) |
| 286 return hr; |
| 287 |
| 288 // Request the return value if asked by the caller. |
| 289 internal::ScopedVariantArg result; |
| 290 VARIANT* disp_result = NULL; |
| 291 if (result_out != NULL) |
| 292 disp_result = &result; |
| 293 |
| 294 // Wrap the parameters into an array of VARIANT structures. |
| 295 internal::ScopedVariantArg disp_args[4]; |
| 296 hr = disp_args[4 - 1].Wrap(p1); |
| 297 if (FAILED(hr)) |
| 298 return hr; |
| 299 hr = disp_args[4 - 2].Wrap(p2); |
| 300 if (FAILED(hr)) |
| 301 return hr; |
| 302 hr = disp_args[4 - 3].Wrap(p3); |
| 303 if (FAILED(hr)) |
| 304 return hr; |
| 305 hr = disp_args[4 - 4].Wrap(p4); |
| 306 if (FAILED(hr)) |
| 307 return hr; |
| 308 |
| 309 // Invoke the method. |
| 310 DISPPARAMS disp_params = { disp_args, NULL, 4, 0 }; |
| 311 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags, |
| 312 &disp_params, disp_result, NULL, NULL); |
| 313 if (FAILED(hr)) |
| 314 return hr; |
| 315 |
| 316 // Unwrap the parameters. |
| 317 disp_args[4 - 1].Unwrap(p1); |
| 318 disp_args[4 - 2].Unwrap(p2); |
| 319 disp_args[4 - 3].Unwrap(p3); |
| 320 disp_args[4 - 4].Unwrap(p4); |
| 321 |
| 322 // Unwrap the return value. |
| 323 if (result_out != NULL) |
| 324 result.Unwrap(result_out); |
| 325 |
| 326 return S_OK; |
| 327 } |
| 328 |
| 329 template <typename P1, typename P2, typename P3, typename P4, typename P5> |
| 330 HRESULT Invoke(IDispatch* object, |
| 331 LPOLESTR name, |
| 332 WORD flags, |
| 333 const P1& p1, |
| 334 const P2& p2, |
| 335 const P3& p3, |
| 336 const P4& p4, |
| 337 const P5& p5, |
| 338 VARIANT* const & result_out) { |
| 339 // Retrieve the ID of the method to be called. |
| 340 DISPID disp_id; |
| 341 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, |
| 342 &disp_id); |
| 343 if (FAILED(hr)) |
| 344 return hr; |
| 345 |
| 346 // Request the return value if asked by the caller. |
| 347 internal::ScopedVariantArg result; |
| 348 VARIANT* disp_result = NULL; |
| 349 if (result_out != NULL) |
| 350 disp_result = &result; |
| 351 |
| 352 // Wrap the parameters into an array of VARIANT structures. |
| 353 internal::ScopedVariantArg disp_args[5]; |
| 354 hr = disp_args[5 - 1].Wrap(p1); |
| 355 if (FAILED(hr)) |
| 356 return hr; |
| 357 hr = disp_args[5 - 2].Wrap(p2); |
| 358 if (FAILED(hr)) |
| 359 return hr; |
| 360 hr = disp_args[5 - 3].Wrap(p3); |
| 361 if (FAILED(hr)) |
| 362 return hr; |
| 363 hr = disp_args[5 - 4].Wrap(p4); |
| 364 if (FAILED(hr)) |
| 365 return hr; |
| 366 hr = disp_args[5 - 5].Wrap(p5); |
| 367 if (FAILED(hr)) |
| 368 return hr; |
| 369 |
| 370 // Invoke the method. |
| 371 DISPPARAMS disp_params = { disp_args, NULL, 5, 0 }; |
| 372 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags, |
| 373 &disp_params, disp_result, NULL, NULL); |
| 374 if (FAILED(hr)) |
| 375 return hr; |
| 376 |
| 377 // Unwrap the parameters. |
| 378 disp_args[5 - 1].Unwrap(p1); |
| 379 disp_args[5 - 2].Unwrap(p2); |
| 380 disp_args[5 - 3].Unwrap(p3); |
| 381 disp_args[5 - 4].Unwrap(p4); |
| 382 disp_args[5 - 5].Unwrap(p5); |
| 383 |
| 384 // Unwrap the return value. |
| 385 if (result_out != NULL) |
| 386 result.Unwrap(result_out); |
| 387 |
| 388 return S_OK; |
| 389 } |
| 390 |
| 391 template <typename P1, typename P2, typename P3, typename P4, typename P5, |
| 392 typename P6> |
| 393 HRESULT Invoke(IDispatch* object, |
| 394 LPOLESTR name, |
| 395 WORD flags, |
| 396 const P1& p1, |
| 397 const P2& p2, |
| 398 const P3& p3, |
| 399 const P4& p4, |
| 400 const P5& p5, |
| 401 const P6& p6, |
| 402 VARIANT* const & result_out) { |
| 403 // Retrieve the ID of the method to be called. |
| 404 DISPID disp_id; |
| 405 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, |
| 406 &disp_id); |
| 407 if (FAILED(hr)) |
| 408 return hr; |
| 409 |
| 410 // Request the return value if asked by the caller. |
| 411 internal::ScopedVariantArg result; |
| 412 VARIANT* disp_result = NULL; |
| 413 if (result_out != NULL) |
| 414 disp_result = &result; |
| 415 |
| 416 // Wrap the parameters into an array of VARIANT structures. |
| 417 internal::ScopedVariantArg disp_args[6]; |
| 418 hr = disp_args[6 - 1].Wrap(p1); |
| 419 if (FAILED(hr)) |
| 420 return hr; |
| 421 hr = disp_args[6 - 2].Wrap(p2); |
| 422 if (FAILED(hr)) |
| 423 return hr; |
| 424 hr = disp_args[6 - 3].Wrap(p3); |
| 425 if (FAILED(hr)) |
| 426 return hr; |
| 427 hr = disp_args[6 - 4].Wrap(p4); |
| 428 if (FAILED(hr)) |
| 429 return hr; |
| 430 hr = disp_args[6 - 5].Wrap(p5); |
| 431 if (FAILED(hr)) |
| 432 return hr; |
| 433 hr = disp_args[6 - 6].Wrap(p6); |
| 434 if (FAILED(hr)) |
| 435 return hr; |
| 436 |
| 437 // Invoke the method. |
| 438 DISPPARAMS disp_params = { disp_args, NULL, 6, 0 }; |
| 439 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags, |
| 440 &disp_params, disp_result, NULL, NULL); |
| 441 if (FAILED(hr)) |
| 442 return hr; |
| 443 |
| 444 // Unwrap the parameters. |
| 445 disp_args[6 - 1].Unwrap(p1); |
| 446 disp_args[6 - 2].Unwrap(p2); |
| 447 disp_args[6 - 3].Unwrap(p3); |
| 448 disp_args[6 - 4].Unwrap(p4); |
| 449 disp_args[6 - 5].Unwrap(p5); |
| 450 disp_args[6 - 6].Unwrap(p6); |
| 451 |
| 452 // Unwrap the return value. |
| 453 if (result_out != NULL) |
| 454 result.Unwrap(result_out); |
| 455 |
| 456 return S_OK; |
| 457 } |
| 458 |
| 459 template <typename P1, typename P2, typename P3, typename P4, typename P5, |
| 460 typename P6, typename P7> |
| 461 HRESULT Invoke(IDispatch* object, |
| 462 LPOLESTR name, |
| 463 WORD flags, |
| 464 const P1& p1, |
| 465 const P2& p2, |
| 466 const P3& p3, |
| 467 const P4& p4, |
| 468 const P5& p5, |
| 469 const P6& p6, |
| 470 const P7& p7, |
| 471 VARIANT* const & result_out) { |
| 472 // Retrieve the ID of the method to be called. |
| 473 DISPID disp_id; |
| 474 HRESULT hr = object->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, |
| 475 &disp_id); |
| 476 if (FAILED(hr)) |
| 477 return hr; |
| 478 |
| 479 // Request the return value if asked by the caller. |
| 480 internal::ScopedVariantArg result; |
| 481 VARIANT* disp_result = NULL; |
| 482 if (result_out != NULL) |
| 483 disp_result = &result; |
| 484 |
| 485 // Wrap the parameters into an array of VARIANT structures. |
| 486 internal::ScopedVariantArg disp_args[7]; |
| 487 hr = disp_args[7 - 1].Wrap(p1); |
| 488 if (FAILED(hr)) |
| 489 return hr; |
| 490 hr = disp_args[7 - 2].Wrap(p2); |
| 491 if (FAILED(hr)) |
| 492 return hr; |
| 493 hr = disp_args[7 - 3].Wrap(p3); |
| 494 if (FAILED(hr)) |
| 495 return hr; |
| 496 hr = disp_args[7 - 4].Wrap(p4); |
| 497 if (FAILED(hr)) |
| 498 return hr; |
| 499 hr = disp_args[7 - 5].Wrap(p5); |
| 500 if (FAILED(hr)) |
| 501 return hr; |
| 502 hr = disp_args[7 - 6].Wrap(p6); |
| 503 if (FAILED(hr)) |
| 504 return hr; |
| 505 hr = disp_args[7 - 7].Wrap(p7); |
| 506 if (FAILED(hr)) |
| 507 return hr; |
| 508 |
| 509 // Invoke the method. |
| 510 DISPPARAMS disp_params = { disp_args, NULL, 7, 0 }; |
| 511 hr = object->Invoke(disp_id, IID_NULL, LOCALE_USER_DEFAULT, flags, |
| 512 &disp_params, disp_result, NULL, NULL); |
| 513 if (FAILED(hr)) |
| 514 return hr; |
| 515 |
| 516 // Unwrap the parameters. |
| 517 disp_args[7 - 1].Unwrap(p1); |
| 518 disp_args[7 - 2].Unwrap(p2); |
| 519 disp_args[7 - 3].Unwrap(p3); |
| 520 disp_args[7 - 4].Unwrap(p4); |
| 521 disp_args[7 - 5].Unwrap(p5); |
| 522 disp_args[7 - 6].Unwrap(p6); |
| 523 disp_args[7 - 7].Unwrap(p7); |
| 524 |
| 525 // Unwrap the return value. |
| 526 if (result_out != NULL) |
| 527 result.Unwrap(result_out); |
| 528 |
| 529 return S_OK; |
| 530 } |
| 531 |
| 532 } // namespace dispatch |
| 533 |
| 534 } // namespace remoting |
| 535 |
| 536 #endif // REMOTING_BASE_IDISPATCH_DRIVER_WIN_H_ |
| OLD | NEW |