2012-07-18 07:41:54 +04:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-08-21 07:21:24 +04:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-07-18 07:41:54 +04: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 10:52:48 +04:00
|
|
|
#include "DOMRequest.h"
|
2012-09-13 20:37:14 +04:00
|
|
|
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
2013-09-11 00:56:05 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2012-07-18 07:41:54 +04:00
|
|
|
|
|
|
|
USING_BLUETOOTH_NAMESPACE
|
|
|
|
|
2012-08-25 20:33:51 +04:00
|
|
|
BluetoothReplyRunnable::BluetoothReplyRunnable(nsIDOMDOMRequest* aReq)
|
|
|
|
: mDOMRequest(aReq)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothReplyRunnable::SetReply(BluetoothReply* aReply)
|
|
|
|
{
|
|
|
|
mReply = aReply;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothReplyRunnable::ReleaseMembers()
|
|
|
|
{
|
|
|
|
mDOMRequest = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
BluetoothReplyRunnable::~BluetoothReplyRunnable()
|
|
|
|
{}
|
|
|
|
|
2012-07-18 07:41:54 +04:00
|
|
|
nsresult
|
2013-10-16 21:44:50 +04:00
|
|
|
BluetoothReplyRunnable::FireReply(JS::Handle<JS::Value> aVal)
|
2012-07-18 07:41:54 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMRequestService> rs =
|
2013-01-29 10:52:48 +04:00
|
|
|
do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
|
|
|
|
|
2012-07-18 07:41:54 +04:00
|
|
|
return mReply->type() == BluetoothReply::TBluetoothReplySuccess ?
|
2012-10-11 09:49:11 +04:00
|
|
|
rs->FireSuccessAsync(mDOMRequest, aVal) :
|
|
|
|
rs->FireErrorAsync(mDOMRequest, mReply->get_BluetoothReplyError().error());
|
2012-07-18 07:41:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
BluetoothReplyRunnable::FireErrorString()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMRequestService> rs =
|
|
|
|
do_GetService("@mozilla.org/dom/dom-request-service;1");
|
2013-01-29 10:52:48 +04:00
|
|
|
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
|
|
|
|
|
2012-10-11 09:49:11 +04:00
|
|
|
return rs->FireErrorAsync(mDOMRequest, mErrorString);
|
2012-07-18 07:41:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BluetoothReplyRunnable::Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-09-26 00:13:15 +04:00
|
|
|
MOZ_ASSERT(mDOMRequest);
|
|
|
|
MOZ_ASSERT(mReply);
|
2012-07-18 07:41:54 +04:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
2013-10-16 21:44:50 +04:00
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JS::Rooted<JS::Value> v(cx, JSVAL_VOID);
|
|
|
|
|
2012-07-18 07:41:54 +04:00
|
|
|
if (mReply->type() != BluetoothReply::TBluetoothReplySuccess) {
|
2013-10-16 21:44:50 +04:00
|
|
|
rv = FireReply(v);
|
2012-07-18 07:41:54 +04:00
|
|
|
} else {
|
|
|
|
if (!ParseSuccessfulReply(&v)) {
|
|
|
|
rv = FireErrorString();
|
|
|
|
} else {
|
|
|
|
rv = FireReply(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-09-14 02:51:00 +04:00
|
|
|
BT_WARNING("Could not fire DOMRequest!");
|
2012-07-18 07:41:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseMembers();
|
2012-09-13 20:37:14 +04:00
|
|
|
MOZ_ASSERT(!mDOMRequest,
|
|
|
|
"mDOMRequest still alive! Deriving class should call "
|
|
|
|
"BluetoothReplyRunnable::ReleaseMembers()!");
|
2012-07-18 07:41:54 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2012-08-25 20:33:51 +04:00
|
|
|
|
|
|
|
BluetoothVoidReplyRunnable::BluetoothVoidReplyRunnable(nsIDOMDOMRequest* aReq)
|
|
|
|
: BluetoothReplyRunnable(aReq)
|
|
|
|
{}
|
|
|
|
|
|
|
|
BluetoothVoidReplyRunnable::~BluetoothVoidReplyRunnable()
|
|
|
|
{}
|
|
|
|
|