michael@0: /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_bluetooth_bluetoothreplyrunnable_h__ michael@0: #define mozilla_dom_bluetooth_bluetoothreplyrunnable_h__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "BluetoothCommon.h" michael@0: #include "nsThreadUtils.h" michael@0: #include "js/Value.h" michael@0: michael@0: class nsIDOMDOMRequest; michael@0: michael@0: BEGIN_BLUETOOTH_NAMESPACE michael@0: michael@0: class BluetoothReply; michael@0: michael@0: class BluetoothReplyRunnable : public nsRunnable michael@0: { michael@0: public: michael@0: NS_DECL_NSIRUNNABLE michael@0: michael@0: BluetoothReplyRunnable(nsIDOMDOMRequest* aReq); michael@0: michael@0: void SetReply(BluetoothReply* aReply); michael@0: michael@0: void SetError(const nsAString& aError) michael@0: { michael@0: mErrorString = aError; michael@0: } michael@0: michael@0: virtual void ReleaseMembers(); michael@0: michael@0: protected: michael@0: virtual ~BluetoothReplyRunnable(); michael@0: michael@0: virtual bool ParseSuccessfulReply(JS::MutableHandle aValue) = 0; michael@0: michael@0: // This is an autoptr so we don't have to bring the ipdl include into the michael@0: // header. We assume we'll only be running this once and it should die on michael@0: // scope out of Run() anyways. michael@0: nsAutoPtr mReply; michael@0: michael@0: private: michael@0: nsresult FireReply(JS::Handle aVal); michael@0: nsresult FireErrorString(); michael@0: michael@0: nsCOMPtr mDOMRequest; michael@0: nsString mErrorString; michael@0: }; michael@0: michael@0: class BluetoothVoidReplyRunnable : public BluetoothReplyRunnable michael@0: { michael@0: public: michael@0: BluetoothVoidReplyRunnable(nsIDOMDOMRequest* aReq); michael@0: ~BluetoothVoidReplyRunnable(); michael@0: michael@0: protected: michael@0: virtual bool ParseSuccessfulReply(JS::MutableHandle aValue) MOZ_OVERRIDE michael@0: { michael@0: aValue.setUndefined(); michael@0: return true; michael@0: } michael@0: }; michael@0: michael@0: END_BLUETOOTH_NAMESPACE michael@0: michael@0: #endif