Bug 826977 - Part 2/4: SystemWorkerManager & RadionInterfaceLayer changes. r=qDot

This commit is contained in:
Vicamo Yang 2013-01-24 14:42:07 +08:00
parent d48c5f2464
commit 71fcc9bac6
5 changed files with 36 additions and 64 deletions

View File

@ -45,6 +45,7 @@ XPIDLSRCS = \
nsIWorkerHolder.idl \
nsIAudioChannelManager.idl \
nsINavigatorAudioChannelManager.idl \
nsISystemWorkerManager.idl \
$(NULL)
LOCAL_INCLUDES = \

View File

@ -135,6 +135,10 @@ XPCOMUtils.defineLazyServiceGetter(this, "gTimeService",
"@mozilla.org/time/timeservice;1",
"nsITimeService");
XPCOMUtils.defineLazyServiceGetter(this, "gSystemWorkerManager",
"@mozilla.org/telephony/system-worker-manager;1",
"nsISystemWorkerManager");
XPCOMUtils.defineLazyGetter(this, "WAP", function () {
let WAP = {};
Cu.import("resource://gre/modules/WapPushManager.js", WAP);
@ -316,17 +320,17 @@ function RadioInterfaceLayer() {
// pass debug pref to ril_worker
this.worker.postMessage({rilMessageType: "setDebugEnabled",
enabled: debugPref});
gSystemWorkerManager.registerRilWorker(this.worker);
}
RadioInterfaceLayer.prototype = {
classID: RADIOINTERFACELAYER_CID,
classInfo: XPCOMUtils.generateCI({classID: RADIOINTERFACELAYER_CID,
classDescription: "RadioInterfaceLayer",
interfaces: [Ci.nsIWorkerHolder,
Ci.nsIRadioInterfaceLayer]}),
interfaces: [Ci.nsIRadioInterfaceLayer]}),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWorkerHolder,
Ci.nsIRadioInterfaceLayer,
QueryInterface: XPCOMUtils.generateQI([Ci.nsIRadioInterfaceLayer,
Ci.nsIObserver,
Ci.nsISettingsServiceCallback]),

View File

@ -13,18 +13,9 @@
# 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}
category profile-after-change RadioInterfaceLayer @mozilla.org/ril;1
# RILContentHelper.js
component {472816e1-1fd6-4405-996c-806f9ea68174} RILContentHelper.js

View File

@ -366,13 +366,7 @@ SystemWorkerManager::Init()
return NS_ERROR_FAILURE;
}
nsresult rv = InitRIL(cx);
if (NS_FAILED(rv)) {
NS_WARNING("Failed to initialize RIL/Telephony!");
return rv;
}
rv = InitWifi(cx);
nsresult rv = InitWifi(cx);
if (NS_FAILED(rv)) {
NS_WARNING("Failed to initialize WiFi Networking!");
return rv;
@ -414,8 +408,6 @@ SystemWorkerManager::Shutdown()
StopRil();
mRIL = nullptr;
#ifdef MOZ_WIDGET_GONK
StopNetd();
mNetdWorker = nullptr;
@ -468,11 +460,6 @@ SystemWorkerManager::GetInterface(const nsIID &aIID, void **aResult)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
if (aIID.Equals(NS_GET_IID(nsIRadioInterfaceLayer))) {
NS_IF_ADDREF(*reinterpret_cast<nsIRadioInterfaceLayer**>(aResult) = mRIL);
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIWifi))) {
return CallQueryInterface(mWifiWorker,
reinterpret_cast<nsIWifi**>(aResult));
@ -490,42 +477,28 @@ SystemWorkerManager::GetInterface(const nsIID &aIID, void **aResult)
}
nsresult
SystemWorkerManager::InitRIL(JSContext *cx)
SystemWorkerManager::RegisterRilWorker(const JS::Value& aWorker,
JSContext *aCx)
{
// 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<nsIRadioInterfaceLayer> ril = do_CreateInstance("@mozilla.org/ril;1");
NS_ENSURE_TRUE(ril, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(!JSVAL_IS_PRIMITIVE(aWorker), NS_ERROR_UNEXPECTED);
nsCOMPtr<nsIWorkerHolder> worker = do_QueryInterface(ril);
if (worker) {
jsval workerval;
nsresult rv = worker->GetWorker(&workerval);
NS_ENSURE_SUCCESS(rv, rv);
JSAutoRequest ar(aCx);
JSAutoCompartment ac(aCx, JSVAL_TO_OBJECT(aWorker));
NS_ENSURE_TRUE(!JSVAL_IS_PRIMITIVE(workerval), NS_ERROR_UNEXPECTED);
JSAutoRequest ar(cx);
JSAutoCompartment ac(cx, JSVAL_TO_OBJECT(workerval));
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);
WorkerCrossThreadDispatcher *wctd =
GetWorkerCrossThreadDispatcher(aCx, aWorker);
if (!wctd) {
return NS_ERROR_FAILURE;
}
mRIL = ril;
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);
return NS_OK;
}
@ -575,7 +548,10 @@ SystemWorkerManager::InitWifi(JSContext *cx)
return NS_OK;
}
NS_IMPL_ISUPPORTS2(SystemWorkerManager, nsIObserver, nsIInterfaceRequestor)
NS_IMPL_ISUPPORTS3(SystemWorkerManager,
nsIObserver,
nsIInterfaceRequestor,
nsISystemWorkerManager)
NS_IMETHODIMP
SystemWorkerManager::Observe(nsISupports *aSubject, const char *aTopic,

View File

@ -19,7 +19,7 @@
#define mozilla_dom_system_b2g_systemworkermanager_h__
#include "nsIInterfaceRequestor.h"
#include "nsIRadioInterfaceLayer.h"
#include "nsISystemWorkerManager.h"
#include "nsIObserver.h"
#include "nsAutoPtr.h"
#include "nsCOMPtr.h"
@ -35,12 +35,14 @@ namespace dom {
namespace gonk {
class SystemWorkerManager : public nsIObserver,
public nsIInterfaceRequestor
public nsIInterfaceRequestor,
public nsISystemWorkerManager
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSISYSTEMWORKERMANAGER
nsresult Init();
void Shutdown();
@ -55,13 +57,11 @@ private:
SystemWorkerManager();
~SystemWorkerManager();
nsresult InitRIL(JSContext *cx);
#ifdef MOZ_WIDGET_GONK
nsresult InitNetd(JSContext *cx);
#endif
nsresult InitWifi(JSContext *cx);
nsCOMPtr<nsIRadioInterfaceLayer> mRIL;
#ifdef MOZ_WIDGET_GONK
nsCOMPtr<nsIWorkerHolder> mNetdWorker;
#endif