|
1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ |
|
2 /* vim: set ts=2 et sw=2 tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef mozilla_dom_bluetooth_bluetoothreplyrunnable_h__ |
|
8 #define mozilla_dom_bluetooth_bluetoothreplyrunnable_h__ |
|
9 |
|
10 #include "mozilla/Attributes.h" |
|
11 #include "BluetoothCommon.h" |
|
12 #include "nsThreadUtils.h" |
|
13 #include "js/Value.h" |
|
14 |
|
15 class nsIDOMDOMRequest; |
|
16 |
|
17 BEGIN_BLUETOOTH_NAMESPACE |
|
18 |
|
19 class BluetoothReply; |
|
20 |
|
21 class BluetoothReplyRunnable : public nsRunnable |
|
22 { |
|
23 public: |
|
24 NS_DECL_NSIRUNNABLE |
|
25 |
|
26 BluetoothReplyRunnable(nsIDOMDOMRequest* aReq); |
|
27 |
|
28 void SetReply(BluetoothReply* aReply); |
|
29 |
|
30 void SetError(const nsAString& aError) |
|
31 { |
|
32 mErrorString = aError; |
|
33 } |
|
34 |
|
35 virtual void ReleaseMembers(); |
|
36 |
|
37 protected: |
|
38 virtual ~BluetoothReplyRunnable(); |
|
39 |
|
40 virtual bool ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue) = 0; |
|
41 |
|
42 // This is an autoptr so we don't have to bring the ipdl include into the |
|
43 // header. We assume we'll only be running this once and it should die on |
|
44 // scope out of Run() anyways. |
|
45 nsAutoPtr<BluetoothReply> mReply; |
|
46 |
|
47 private: |
|
48 nsresult FireReply(JS::Handle<JS::Value> aVal); |
|
49 nsresult FireErrorString(); |
|
50 |
|
51 nsCOMPtr<nsIDOMDOMRequest> mDOMRequest; |
|
52 nsString mErrorString; |
|
53 }; |
|
54 |
|
55 class BluetoothVoidReplyRunnable : public BluetoothReplyRunnable |
|
56 { |
|
57 public: |
|
58 BluetoothVoidReplyRunnable(nsIDOMDOMRequest* aReq); |
|
59 ~BluetoothVoidReplyRunnable(); |
|
60 |
|
61 protected: |
|
62 virtual bool ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue) MOZ_OVERRIDE |
|
63 { |
|
64 aValue.setUndefined(); |
|
65 return true; |
|
66 } |
|
67 }; |
|
68 |
|
69 END_BLUETOOTH_NAMESPACE |
|
70 |
|
71 #endif |