Bug 786468 - Support alternate nsIRadioInterfaceLayer implementations. r=philikon,mrbkap

This commit is contained in:
Michael Vines 2012-08-31 10:59:27 -07:00
parent 4716a41074
commit 14df4431a5
3 changed files with 41 additions and 28 deletions

View File

@ -13,7 +13,18 @@
# limitations under the License.
# RadioInterfaceLayer.js
#
# IMPORTANT:
# Users of nsIRadioInterfaceLayer should invoke
# nsIInterfaceRequestor::GetInterface() as implemented by
# "@mozilla.org/telephony/system-worker-manager;1" to
# obtain the instance.
#
# DO NOT use do_CreateInstance()/do_GetService() to directly
# instantiate "@mozilla.org/ril;1".
#
component {2d831c8d-6017-435b-a80c-e5d422810cea} RadioInterfaceLayer.js
contract @mozilla.org/ril;1 {2d831c8d-6017-435b-a80c-e5d422810cea}
# RILContentHelper.js
component {472816e1-1fd6-4405-996c-806f9ea68174} RILContentHelper.js

View File

@ -19,7 +19,6 @@
#include "nsIObserverService.h"
#include "nsIJSContextStack.h"
#include "nsIRadioInterfaceLayer.h"
#include "nsINetworkManager.h"
#include "nsIWifi.h"
#include "nsIWorkerHolder.h"
@ -52,7 +51,6 @@ using namespace mozilla::system;
namespace {
NS_DEFINE_CID(kRadioInterfaceLayerCID, NS_RADIOINTERFACELAYER_CID);
NS_DEFINE_CID(kWifiWorkerCID, NS_WIFIWORKER_CID);
NS_DEFINE_CID(kNetworkManagerCID, NS_NETWORKMANAGER_CID);
@ -414,7 +412,7 @@ SystemWorkerManager::Shutdown()
StopRil();
mRILWorker = nullptr;
mRIL = nullptr;
#ifdef MOZ_WIDGET_GONK
StopNetd();
@ -469,8 +467,8 @@ SystemWorkerManager::GetInterface(const nsIID &aIID, void **aResult)
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
if (aIID.Equals(NS_GET_IID(nsIRadioInterfaceLayer))) {
return CallQueryInterface(mRILWorker,
reinterpret_cast<nsIRadioInterfaceLayer**>(aResult));
NS_IF_ADDREF(*reinterpret_cast<nsIRadioInterfaceLayer**>(aResult) = mRIL);
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIWifi))) {
@ -495,34 +493,37 @@ SystemWorkerManager::InitRIL(JSContext *cx)
// We're keeping as much of this implementation as possible in JS, so the real
// worker lives in RadioInterfaceLayer.js. All we do here is hold it alive and
// hook it up to the RIL thread.
nsCOMPtr<nsIWorkerHolder> worker = do_CreateInstance(kRadioInterfaceLayerCID);
NS_ENSURE_TRUE(worker, NS_ERROR_FAILURE);
nsCOMPtr<nsIRadioInterfaceLayer> ril = do_CreateInstance("@mozilla.org/ril;1");
NS_ENSURE_TRUE(ril, NS_ERROR_FAILURE);
jsval workerval;
nsresult rv = worker->GetWorker(&workerval);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIWorkerHolder> worker = do_QueryInterface(ril);
if (worker) {
jsval workerval;
nsresult rv = worker->GetWorker(&workerval);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(!JSVAL_IS_PRIMITIVE(workerval), NS_ERROR_UNEXPECTED);
NS_ENSURE_TRUE(!JSVAL_IS_PRIMITIVE(workerval), NS_ERROR_UNEXPECTED);
JSAutoRequest ar(cx);
JSAutoCompartment ac(cx, JSVAL_TO_OBJECT(workerval));
JSAutoRequest ar(cx);
JSAutoCompartment ac(cx, JSVAL_TO_OBJECT(workerval));
WorkerCrossThreadDispatcher *wctd =
GetWorkerCrossThreadDispatcher(cx, workerval);
if (!wctd) {
return NS_ERROR_FAILURE;
WorkerCrossThreadDispatcher *wctd =
GetWorkerCrossThreadDispatcher(cx, workerval);
if (!wctd) {
return NS_ERROR_FAILURE;
}
nsRefPtr<ConnectWorkerToRIL> connection = new ConnectWorkerToRIL();
if (!wctd->PostTask(connection)) {
return NS_ERROR_UNEXPECTED;
}
// Now that we're set up, connect ourselves to the RIL thread.
mozilla::RefPtr<RILReceiver> receiver = new RILReceiver(wctd);
StartRil(receiver);
}
nsRefPtr<ConnectWorkerToRIL> connection = new ConnectWorkerToRIL();
if (!wctd->PostTask(connection)) {
return NS_ERROR_UNEXPECTED;
}
// Now that we're set up, connect ourselves to the RIL thread.
mozilla::RefPtr<RILReceiver> receiver = new RILReceiver(wctd);
StartRil(receiver);
mRILWorker = worker;
mRIL = ril;
return NS_OK;
}

View File

@ -19,6 +19,7 @@
#define mozilla_dom_system_b2g_systemworkermanager_h__
#include "nsIInterfaceRequestor.h"
#include "nsIRadioInterfaceLayer.h"
#include "nsIObserver.h"
#include "nsAutoPtr.h"
#include "nsCOMPtr.h"
@ -60,7 +61,7 @@ private:
#endif
nsresult InitWifi(JSContext *cx);
nsCOMPtr<nsIWorkerHolder> mRILWorker;
nsCOMPtr<nsIRadioInterfaceLayer> mRIL;
#ifdef MOZ_WIDGET_GONK
nsCOMPtr<nsIWorkerHolder> mNetdWorker;
#endif