2012-07-18 03:41:54 +00:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-08-21 03:21:24 +00:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-07-18 03:41:54 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
#include "BluetoothReplyRunnable.h"
|
2013-01-29 06:52:48 +00:00
|
|
|
#include "DOMRequest.h"
|
2012-09-13 16:37:14 +00:00
|
|
|
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
2013-09-10 20:56:05 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2012-07-18 03:41:54 +00:00
|
|
|
|
|
|
|
USING_BLUETOOTH_NAMESPACE
|
|
|
|
|
2012-08-25 16:33:51 +00:00
|
|
|
BluetoothReplyRunnable::BluetoothReplyRunnable(nsIDOMDOMRequest* aReq)
|
|
|
|
: mDOMRequest(aReq)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothReplyRunnable::SetReply(BluetoothReply* aReply)
|
|
|
|
{
|
|
|
|
mReply = aReply;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothReplyRunnable::ReleaseMembers()
|
|
|
|
{
|
|
|
|
mDOMRequest = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
BluetoothReplyRunnable::~BluetoothReplyRunnable()
|
|
|
|
{}
|
|
|
|
|
2012-07-18 03:41:54 +00:00
|
|
|
nsresult
|
2013-10-16 17:44:50 +00:00
|
|
|
BluetoothReplyRunnable::FireReply(JS::Handle<JS::Value> aVal)
|
2012-07-18 03:41:54 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMRequestService> rs =
|
2013-01-29 06:52:48 +00:00
|
|
|
do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
|
|
|
|
|
2012-07-18 03:41:54 +00:00
|
|
|
return mReply->type() == BluetoothReply::TBluetoothReplySuccess ?
|
2012-10-11 05:49:11 +00:00
|
|
|
rs->FireSuccessAsync(mDOMRequest, aVal) :
|
|
|
|
rs->FireErrorAsync(mDOMRequest, mReply->get_BluetoothReplyError().error());
|
2012-07-18 03:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
BluetoothReplyRunnable::FireErrorString()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMRequestService> rs =
|
|
|
|
do_GetService("@mozilla.org/dom/dom-request-service;1");
|
2013-01-29 06:52:48 +00:00
|
|
|
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
|
|
|
|
|
2012-10-11 05:49:11 +00:00
|
|
|
return rs->FireErrorAsync(mDOMRequest, mErrorString);
|
2012-07-18 03:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BluetoothReplyRunnable::Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-09-25 20:13:15 +00:00
|
|
|
MOZ_ASSERT(mDOMRequest);
|
|
|
|
MOZ_ASSERT(mReply);
|
2012-07-18 03:41:54 +00:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
2013-10-16 17:44:50 +00:00
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JS::Rooted<JS::Value> v(cx, JSVAL_VOID);
|
|
|
|
|
2012-07-18 03:41:54 +00:00
|
|
|
if (mReply->type() != BluetoothReply::TBluetoothReplySuccess) {
|
2013-10-16 17:44:50 +00:00
|
|
|
rv = FireReply(v);
|
2012-07-18 03:41:54 +00:00
|
|
|
} else {
|
|
|
|
if (!ParseSuccessfulReply(&v)) {
|
|
|
|
rv = FireErrorString();
|
|
|
|
} else {
|
|
|
|
rv = FireReply(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("Could not fire DOMRequest!");
|
2012-07-18 03:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseMembers();
|
2012-09-13 16:37:14 +00:00
|
|
|
MOZ_ASSERT(!mDOMRequest,
|
|
|
|
"mDOMRequest still alive! Deriving class should call "
|
|
|
|
"BluetoothReplyRunnable::ReleaseMembers()!");
|
2012-07-18 03:41:54 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2012-08-25 16:33:51 +00:00
|
|
|
|
|
|
|
BluetoothVoidReplyRunnable::BluetoothVoidReplyRunnable(nsIDOMDOMRequest* aReq)
|
|
|
|
: BluetoothReplyRunnable(aReq)
|
|
|
|
{}
|
|
|
|
|
|
|
|
BluetoothVoidReplyRunnable::~BluetoothVoidReplyRunnable()
|
|
|
|
{}
|
|
|
|
|