FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
CrossThreadCall.cpp
1 /**********************************************************\
2 Original Author: Richard Bateman (taxilian)
3 
4 Created: Oct 2, 2010
5 License: Dual license model; choose one of two:
6  New BSD License
7  http://www.opensource.org/licenses/bsd-license.php
8  - or -
9  GNU Lesser General Public License, version 2.1
10  http://www.gnu.org/licenses/lgpl-2.1.html
11 
12 Copyright 2010 Richard Bateman, Firebreath development team
13 \**********************************************************/
14 
15 #include "precompiled_headers.h" // On windows, everything above this line in PCH
16 #include "CrossThreadCall.h"
17 
18 using namespace FB;
19 
20 void CrossThreadCall::syncCallbackFunctor(void *userData)
21 {
22  std::auto_ptr<CrossThreadCallWeakPtr> callWeak(static_cast<CrossThreadCallWeakPtr*>(userData));
23  if (CrossThreadCallPtr call = callWeak->lock()) {
24  try
25  {
26  call->funct->call();
27  }
28  catch(const FB::script_error& e)
29  {
30  call->m_result = variant(boost::make_shared<FB::script_error>(e.what()), true);
31  }
32  // Make sure the lock goes out of scope before we finish
33  boost::lock_guard<boost::mutex> lock(call->m_mutex);
34  call->m_returned = true;
35  call->m_cond.notify_one();
36  }
37 }
38 
39 void CrossThreadCall::asyncCallbackFunctor(void *userData)
40 {
41  std::auto_ptr<CrossThreadCall> call(static_cast<CrossThreadCall *>(userData));
42 
43  try {
44  call->funct->call();
45  } catch (const FB::script_error& ex) {
46  // we can't sensibly handle it here
47  FB_UNUSED_VARIABLE(ex);
48  } catch (const FB::bad_variant_cast& ex) {
49  // we can't sensibly handle it here
50  FB_UNUSED_VARIABLE(ex);
51  }
52 }
53 
Accepts any datatype, used in all interactions with javascript. Provides tools for getting back out t...
Definition: variant.h:198
Thrown when variant::cast<type> or variant::convert_cast<type> fails because the type of the value st...
Definition: variant.h:133
Exception type; when thrown in a JSAPI method, a javascript exception will be thrown.
Definition: JSExceptions.h:28