1 // Copyright (c) 2011 Google Inc. All rights reserved. 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google Inc. nor the name Chromium Embedded 14 // Framework nor the names of its contributors may be used to endorse 15 // or promote products derived from this software without specific prior 16 // written permission. 17 // 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 30 // Do not include this header file directly. Use base/cef_bind.h instead. 31 32 // Specializations of RunnableAdapter<> for Windows specific calling 33 // conventions. Please see base/bind_internal.h for more info. 34 35 #ifndef CEF_INCLUDE_BASE_INTERNAL_CEF_BIND_INTERNAL_WIN_H_ 36 #define CEF_INCLUDE_BASE_INTERNAL_CEF_BIND_INTERNAL_WIN_H_ 37 38 // In the x64 architecture in Windows, __fastcall, __stdcall, etc, are all 39 // the same as __cdecl which would turn the following specializations into 40 // multiple definitions. 41 #if defined(ARCH_CPU_X86_FAMILY) 42 #if defined(ARCH_CPU_32_BITS) 43 44 namespace base { 45 namespace cef_internal { 46 47 template <typename Functor> 48 class RunnableAdapter; 49 50 // __stdcall Function: Arity 0. 51 template <typename R> 52 class RunnableAdapter<R(__stdcall*)()> { 53 public: 54 typedef R(RunType)(); 55 RunnableAdapter(R (__stdcall * function)())56 explicit RunnableAdapter(R(__stdcall* function)()) : function_(function) {} 57 Run()58 R Run() { return function_(); } 59 60 private: 61 R(__stdcall* function_)(); 62 }; 63 64 // __fastcall Function: Arity 0. 65 template <typename R> 66 class RunnableAdapter<R(__fastcall*)()> { 67 public: 68 typedef R(RunType)(); 69 RunnableAdapter(R (__fastcall * function)())70 explicit RunnableAdapter(R(__fastcall* function)()) : function_(function) {} 71 Run()72 R Run() { return function_(); } 73 74 private: 75 R(__fastcall* function_)(); 76 }; 77 78 // __stdcall Function: Arity 1. 79 template <typename R, typename A1> 80 class RunnableAdapter<R(__stdcall*)(A1)> { 81 public: 82 typedef R(RunType)(A1); 83 RunnableAdapter(R (__stdcall * function)(A1))84 explicit RunnableAdapter(R(__stdcall* function)(A1)) : function_(function) {} 85 Run(typename CallbackParamTraits<A1>::ForwardType a1)86 R Run(typename CallbackParamTraits<A1>::ForwardType a1) { 87 return function_(a1); 88 } 89 90 private: 91 R(__stdcall* function_)(A1); 92 }; 93 94 // __fastcall Function: Arity 1. 95 template <typename R, typename A1> 96 class RunnableAdapter<R(__fastcall*)(A1)> { 97 public: 98 typedef R(RunType)(A1); 99 RunnableAdapter(R (__fastcall * function)(A1))100 explicit RunnableAdapter(R(__fastcall* function)(A1)) : function_(function) {} 101 Run(typename CallbackParamTraits<A1>::ForwardType a1)102 R Run(typename CallbackParamTraits<A1>::ForwardType a1) { 103 return function_(a1); 104 } 105 106 private: 107 R(__fastcall* function_)(A1); 108 }; 109 110 // __stdcall Function: Arity 2. 111 template <typename R, typename A1, typename A2> 112 class RunnableAdapter<R(__stdcall*)(A1, A2)> { 113 public: 114 typedef R(RunType)(A1, A2); 115 RunnableAdapter(R (__stdcall * function)(A1,A2))116 explicit RunnableAdapter(R(__stdcall* function)(A1, A2)) 117 : function_(function) {} 118 Run(typename CallbackParamTraits<A1>::ForwardType a1,typename CallbackParamTraits<A2>::ForwardType a2)119 R Run(typename CallbackParamTraits<A1>::ForwardType a1, 120 typename CallbackParamTraits<A2>::ForwardType a2) { 121 return function_(a1, a2); 122 } 123 124 private: 125 R(__stdcall* function_)(A1, A2); 126 }; 127 128 // __fastcall Function: Arity 2. 129 template <typename R, typename A1, typename A2> 130 class RunnableAdapter<R(__fastcall*)(A1, A2)> { 131 public: 132 typedef R(RunType)(A1, A2); 133 RunnableAdapter(R (__fastcall * function)(A1,A2))134 explicit RunnableAdapter(R(__fastcall* function)(A1, A2)) 135 : function_(function) {} 136 Run(typename CallbackParamTraits<A1>::ForwardType a1,typename CallbackParamTraits<A2>::ForwardType a2)137 R Run(typename CallbackParamTraits<A1>::ForwardType a1, 138 typename CallbackParamTraits<A2>::ForwardType a2) { 139 return function_(a1, a2); 140 } 141 142 private: 143 R(__fastcall* function_)(A1, A2); 144 }; 145 146 // __stdcall Function: Arity 3. 147 template <typename R, typename A1, typename A2, typename A3> 148 class RunnableAdapter<R(__stdcall*)(A1, A2, A3)> { 149 public: 150 typedef R(RunType)(A1, A2, A3); 151 RunnableAdapter(R (__stdcall * function)(A1,A2,A3))152 explicit RunnableAdapter(R(__stdcall* function)(A1, A2, A3)) 153 : function_(function) {} 154 Run(typename CallbackParamTraits<A1>::ForwardType a1,typename CallbackParamTraits<A2>::ForwardType a2,typename CallbackParamTraits<A3>::ForwardType a3)155 R Run(typename CallbackParamTraits<A1>::ForwardType a1, 156 typename CallbackParamTraits<A2>::ForwardType a2, 157 typename CallbackParamTraits<A3>::ForwardType a3) { 158 return function_(a1, a2, a3); 159 } 160 161 private: 162 R(__stdcall* function_)(A1, A2, A3); 163 }; 164 165 // __fastcall Function: Arity 3. 166 template <typename R, typename A1, typename A2, typename A3> 167 class RunnableAdapter<R(__fastcall*)(A1, A2, A3)> { 168 public: 169 typedef R(RunType)(A1, A2, A3); 170 RunnableAdapter(R (__fastcall * function)(A1,A2,A3))171 explicit RunnableAdapter(R(__fastcall* function)(A1, A2, A3)) 172 : function_(function) {} 173 Run(typename CallbackParamTraits<A1>::ForwardType a1,typename CallbackParamTraits<A2>::ForwardType a2,typename CallbackParamTraits<A3>::ForwardType a3)174 R Run(typename CallbackParamTraits<A1>::ForwardType a1, 175 typename CallbackParamTraits<A2>::ForwardType a2, 176 typename CallbackParamTraits<A3>::ForwardType a3) { 177 return function_(a1, a2, a3); 178 } 179 180 private: 181 R(__fastcall* function_)(A1, A2, A3); 182 }; 183 184 // __stdcall Function: Arity 4. 185 template <typename R, typename A1, typename A2, typename A3, typename A4> 186 class RunnableAdapter<R(__stdcall*)(A1, A2, A3, A4)> { 187 public: 188 typedef R(RunType)(A1, A2, A3, A4); 189 RunnableAdapter(R (__stdcall * function)(A1,A2,A3,A4))190 explicit RunnableAdapter(R(__stdcall* function)(A1, A2, A3, A4)) 191 : function_(function) {} 192 Run(typename CallbackParamTraits<A1>::ForwardType a1,typename CallbackParamTraits<A2>::ForwardType a2,typename CallbackParamTraits<A3>::ForwardType a3,typename CallbackParamTraits<A4>::ForwardType a4)193 R Run(typename CallbackParamTraits<A1>::ForwardType a1, 194 typename CallbackParamTraits<A2>::ForwardType a2, 195 typename CallbackParamTraits<A3>::ForwardType a3, 196 typename CallbackParamTraits<A4>::ForwardType a4) { 197 return function_(a1, a2, a3, a4); 198 } 199 200 private: 201 R(__stdcall* function_)(A1, A2, A3, A4); 202 }; 203 204 // __fastcall Function: Arity 4. 205 template <typename R, typename A1, typename A2, typename A3, typename A4> 206 class RunnableAdapter<R(__fastcall*)(A1, A2, A3, A4)> { 207 public: 208 typedef R(RunType)(A1, A2, A3, A4); 209 RunnableAdapter(R (__fastcall * function)(A1,A2,A3,A4))210 explicit RunnableAdapter(R(__fastcall* function)(A1, A2, A3, A4)) 211 : function_(function) {} 212 Run(typename CallbackParamTraits<A1>::ForwardType a1,typename CallbackParamTraits<A2>::ForwardType a2,typename CallbackParamTraits<A3>::ForwardType a3,typename CallbackParamTraits<A4>::ForwardType a4)213 R Run(typename CallbackParamTraits<A1>::ForwardType a1, 214 typename CallbackParamTraits<A2>::ForwardType a2, 215 typename CallbackParamTraits<A3>::ForwardType a3, 216 typename CallbackParamTraits<A4>::ForwardType a4) { 217 return function_(a1, a2, a3, a4); 218 } 219 220 private: 221 R(__fastcall* function_)(A1, A2, A3, A4); 222 }; 223 224 // __stdcall Function: Arity 5. 225 template <typename R, 226 typename A1, 227 typename A2, 228 typename A3, 229 typename A4, 230 typename A5> 231 class RunnableAdapter<R(__stdcall*)(A1, A2, A3, A4, A5)> { 232 public: 233 typedef R(RunType)(A1, A2, A3, A4, A5); 234 RunnableAdapter(R (__stdcall * function)(A1,A2,A3,A4,A5))235 explicit RunnableAdapter(R(__stdcall* function)(A1, A2, A3, A4, A5)) 236 : function_(function) {} 237 Run(typename CallbackParamTraits<A1>::ForwardType a1,typename CallbackParamTraits<A2>::ForwardType a2,typename CallbackParamTraits<A3>::ForwardType a3,typename CallbackParamTraits<A4>::ForwardType a4,typename CallbackParamTraits<A5>::ForwardType a5)238 R Run(typename CallbackParamTraits<A1>::ForwardType a1, 239 typename CallbackParamTraits<A2>::ForwardType a2, 240 typename CallbackParamTraits<A3>::ForwardType a3, 241 typename CallbackParamTraits<A4>::ForwardType a4, 242 typename CallbackParamTraits<A5>::ForwardType a5) { 243 return function_(a1, a2, a3, a4, a5); 244 } 245 246 private: 247 R(__stdcall* function_)(A1, A2, A3, A4, A5); 248 }; 249 250 // __fastcall Function: Arity 5. 251 template <typename R, 252 typename A1, 253 typename A2, 254 typename A3, 255 typename A4, 256 typename A5> 257 class RunnableAdapter<R(__fastcall*)(A1, A2, A3, A4, A5)> { 258 public: 259 typedef R(RunType)(A1, A2, A3, A4, A5); 260 RunnableAdapter(R (__fastcall * function)(A1,A2,A3,A4,A5))261 explicit RunnableAdapter(R(__fastcall* function)(A1, A2, A3, A4, A5)) 262 : function_(function) {} 263 Run(typename CallbackParamTraits<A1>::ForwardType a1,typename CallbackParamTraits<A2>::ForwardType a2,typename CallbackParamTraits<A3>::ForwardType a3,typename CallbackParamTraits<A4>::ForwardType a4,typename CallbackParamTraits<A5>::ForwardType a5)264 R Run(typename CallbackParamTraits<A1>::ForwardType a1, 265 typename CallbackParamTraits<A2>::ForwardType a2, 266 typename CallbackParamTraits<A3>::ForwardType a3, 267 typename CallbackParamTraits<A4>::ForwardType a4, 268 typename CallbackParamTraits<A5>::ForwardType a5) { 269 return function_(a1, a2, a3, a4, a5); 270 } 271 272 private: 273 R(__fastcall* function_)(A1, A2, A3, A4, A5); 274 }; 275 276 // __stdcall Function: Arity 6. 277 template <typename R, 278 typename A1, 279 typename A2, 280 typename A3, 281 typename A4, 282 typename A5, 283 typename A6> 284 class RunnableAdapter<R(__stdcall*)(A1, A2, A3, A4, A5, A6)> { 285 public: 286 typedef R(RunType)(A1, A2, A3, A4, A5, A6); 287 RunnableAdapter(R (__stdcall * function)(A1,A2,A3,A4,A5,A6))288 explicit RunnableAdapter(R(__stdcall* function)(A1, A2, A3, A4, A5, A6)) 289 : function_(function) {} 290 Run(typename CallbackParamTraits<A1>::ForwardType a1,typename CallbackParamTraits<A2>::ForwardType a2,typename CallbackParamTraits<A3>::ForwardType a3,typename CallbackParamTraits<A4>::ForwardType a4,typename CallbackParamTraits<A5>::ForwardType a5,typename CallbackParamTraits<A6>::ForwardType a6)291 R Run(typename CallbackParamTraits<A1>::ForwardType a1, 292 typename CallbackParamTraits<A2>::ForwardType a2, 293 typename CallbackParamTraits<A3>::ForwardType a3, 294 typename CallbackParamTraits<A4>::ForwardType a4, 295 typename CallbackParamTraits<A5>::ForwardType a5, 296 typename CallbackParamTraits<A6>::ForwardType a6) { 297 return function_(a1, a2, a3, a4, a5, a6); 298 } 299 300 private: 301 R(__stdcall* function_)(A1, A2, A3, A4, A5, A6); 302 }; 303 304 // __fastcall Function: Arity 6. 305 template <typename R, 306 typename A1, 307 typename A2, 308 typename A3, 309 typename A4, 310 typename A5, 311 typename A6> 312 class RunnableAdapter<R(__fastcall*)(A1, A2, A3, A4, A5, A6)> { 313 public: 314 typedef R(RunType)(A1, A2, A3, A4, A5, A6); 315 RunnableAdapter(R (__fastcall * function)(A1,A2,A3,A4,A5,A6))316 explicit RunnableAdapter(R(__fastcall* function)(A1, A2, A3, A4, A5, A6)) 317 : function_(function) {} 318 Run(typename CallbackParamTraits<A1>::ForwardType a1,typename CallbackParamTraits<A2>::ForwardType a2,typename CallbackParamTraits<A3>::ForwardType a3,typename CallbackParamTraits<A4>::ForwardType a4,typename CallbackParamTraits<A5>::ForwardType a5,typename CallbackParamTraits<A6>::ForwardType a6)319 R Run(typename CallbackParamTraits<A1>::ForwardType a1, 320 typename CallbackParamTraits<A2>::ForwardType a2, 321 typename CallbackParamTraits<A3>::ForwardType a3, 322 typename CallbackParamTraits<A4>::ForwardType a4, 323 typename CallbackParamTraits<A5>::ForwardType a5, 324 typename CallbackParamTraits<A6>::ForwardType a6) { 325 return function_(a1, a2, a3, a4, a5, a6); 326 } 327 328 private: 329 R(__fastcall* function_)(A1, A2, A3, A4, A5, A6); 330 }; 331 332 // __stdcall Function: Arity 7. 333 template <typename R, 334 typename A1, 335 typename A2, 336 typename A3, 337 typename A4, 338 typename A5, 339 typename A6, 340 typename A7> 341 class RunnableAdapter<R(__stdcall*)(A1, A2, A3, A4, A5, A6, A7)> { 342 public: 343 typedef R(RunType)(A1, A2, A3, A4, A5, A6, A7); 344 RunnableAdapter(R (__stdcall * function)(A1,A2,A3,A4,A5,A6,A7))345 explicit RunnableAdapter(R(__stdcall* function)(A1, A2, A3, A4, A5, A6, A7)) 346 : function_(function) {} 347 Run(typename CallbackParamTraits<A1>::ForwardType a1,typename CallbackParamTraits<A2>::ForwardType a2,typename CallbackParamTraits<A3>::ForwardType a3,typename CallbackParamTraits<A4>::ForwardType a4,typename CallbackParamTraits<A5>::ForwardType a5,typename CallbackParamTraits<A6>::ForwardType a6,typename CallbackParamTraits<A7>::ForwardType a7)348 R Run(typename CallbackParamTraits<A1>::ForwardType a1, 349 typename CallbackParamTraits<A2>::ForwardType a2, 350 typename CallbackParamTraits<A3>::ForwardType a3, 351 typename CallbackParamTraits<A4>::ForwardType a4, 352 typename CallbackParamTraits<A5>::ForwardType a5, 353 typename CallbackParamTraits<A6>::ForwardType a6, 354 typename CallbackParamTraits<A7>::ForwardType a7) { 355 return function_(a1, a2, a3, a4, a5, a6, a7); 356 } 357 358 private: 359 R(__stdcall* function_)(A1, A2, A3, A4, A5, A6, A7); 360 }; 361 362 // __fastcall Function: Arity 7. 363 template <typename R, 364 typename A1, 365 typename A2, 366 typename A3, 367 typename A4, 368 typename A5, 369 typename A6, 370 typename A7> 371 class RunnableAdapter<R(__fastcall*)(A1, A2, A3, A4, A5, A6, A7)> { 372 public: 373 typedef R(RunType)(A1, A2, A3, A4, A5, A6, A7); 374 RunnableAdapter(R (__fastcall * function)(A1,A2,A3,A4,A5,A6,A7))375 explicit RunnableAdapter(R(__fastcall* function)(A1, A2, A3, A4, A5, A6, A7)) 376 : function_(function) {} 377 Run(typename CallbackParamTraits<A1>::ForwardType a1,typename CallbackParamTraits<A2>::ForwardType a2,typename CallbackParamTraits<A3>::ForwardType a3,typename CallbackParamTraits<A4>::ForwardType a4,typename CallbackParamTraits<A5>::ForwardType a5,typename CallbackParamTraits<A6>::ForwardType a6,typename CallbackParamTraits<A7>::ForwardType a7)378 R Run(typename CallbackParamTraits<A1>::ForwardType a1, 379 typename CallbackParamTraits<A2>::ForwardType a2, 380 typename CallbackParamTraits<A3>::ForwardType a3, 381 typename CallbackParamTraits<A4>::ForwardType a4, 382 typename CallbackParamTraits<A5>::ForwardType a5, 383 typename CallbackParamTraits<A6>::ForwardType a6, 384 typename CallbackParamTraits<A7>::ForwardType a7) { 385 return function_(a1, a2, a3, a4, a5, a6, a7); 386 } 387 388 private: 389 R(__fastcall* function_)(A1, A2, A3, A4, A5, A6, A7); 390 }; 391 392 } // namespace cef_internal 393 } // namespace base 394 395 #endif // defined(ARCH_CPU_32_BITS) 396 #endif // defined(ARCH_CPU_X86_FAMILY) 397 398 #endif // CEF_INCLUDE_BASE_INTERNAL_CEF_BIND_INTERNAL_WIN_H_ 399