dom/bluetooth/BluetoothReplyRunnable.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/bluetooth/BluetoothReplyRunnable.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,71 @@
     1.4 +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_dom_bluetooth_bluetoothreplyrunnable_h__
    1.11 +#define mozilla_dom_bluetooth_bluetoothreplyrunnable_h__
    1.12 +
    1.13 +#include "mozilla/Attributes.h"
    1.14 +#include "BluetoothCommon.h"
    1.15 +#include "nsThreadUtils.h"
    1.16 +#include "js/Value.h"
    1.17 +
    1.18 +class nsIDOMDOMRequest;
    1.19 +
    1.20 +BEGIN_BLUETOOTH_NAMESPACE
    1.21 +
    1.22 +class BluetoothReply;
    1.23 +
    1.24 +class BluetoothReplyRunnable : public nsRunnable
    1.25 +{
    1.26 +public:
    1.27 +  NS_DECL_NSIRUNNABLE
    1.28 +
    1.29 +  BluetoothReplyRunnable(nsIDOMDOMRequest* aReq);
    1.30 +
    1.31 +  void SetReply(BluetoothReply* aReply);
    1.32 +
    1.33 +  void SetError(const nsAString& aError)
    1.34 +  {
    1.35 +    mErrorString = aError;
    1.36 +  }
    1.37 +
    1.38 +  virtual void ReleaseMembers();
    1.39 +
    1.40 +protected:
    1.41 +  virtual ~BluetoothReplyRunnable();
    1.42 +
    1.43 +  virtual bool ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue) = 0;
    1.44 +
    1.45 +  // This is an autoptr so we don't have to bring the ipdl include into the
    1.46 +  // header. We assume we'll only be running this once and it should die on
    1.47 +  // scope out of Run() anyways.
    1.48 +  nsAutoPtr<BluetoothReply> mReply;
    1.49 +
    1.50 +private:
    1.51 +  nsresult FireReply(JS::Handle<JS::Value> aVal);
    1.52 +  nsresult FireErrorString();
    1.53 +
    1.54 +  nsCOMPtr<nsIDOMDOMRequest> mDOMRequest;
    1.55 +  nsString mErrorString;
    1.56 +};
    1.57 +
    1.58 +class BluetoothVoidReplyRunnable : public BluetoothReplyRunnable
    1.59 +{
    1.60 +public:
    1.61 +  BluetoothVoidReplyRunnable(nsIDOMDOMRequest* aReq);
    1.62 + ~BluetoothVoidReplyRunnable();
    1.63 +
    1.64 +protected:
    1.65 +  virtual bool ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue) MOZ_OVERRIDE
    1.66 +  {
    1.67 +    aValue.setUndefined();
    1.68 +    return true;
    1.69 +  }
    1.70 +};
    1.71 +
    1.72 +END_BLUETOOTH_NAMESPACE
    1.73 +
    1.74 +#endif

mercurial