2014-07-01 10:37:32 +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 "MobileConnectionIPCService.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/StaticPtr.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
using namespace mozilla::dom::mobileconnection;
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(MobileConnectionIPCService, nsIMobileConnectionService)
|
|
|
|
|
|
|
|
MobileConnectionIPCService::MobileConnectionIPCService()
|
|
|
|
{
|
|
|
|
int32_t numRil = Preferences::GetInt("ril.numRadioInterfaces", 1);
|
2014-09-21 07:24:43 +00:00
|
|
|
mItems.SetLength(numRil);
|
2014-07-01 10:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MobileConnectionIPCService::~MobileConnectionIPCService()
|
|
|
|
{
|
2014-09-21 07:24:43 +00:00
|
|
|
uint32_t count = mItems.Length();
|
2014-07-01 10:37:32 +00:00
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2014-09-21 07:24:43 +00:00
|
|
|
if (mItems[i]) {
|
|
|
|
mItems[i]->Shutdown();
|
|
|
|
}
|
2014-07-01 10:37:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIMobileConnectionService
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-09-21 07:24:43 +00:00
|
|
|
MobileConnectionIPCService::GetNumItems(uint32_t* aNumItems)
|
2014-07-01 10:37:32 +00:00
|
|
|
{
|
2014-09-21 07:24:43 +00:00
|
|
|
*aNumItems = mItems.Length();
|
2014-07-01 10:37:32 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-09-21 07:24:43 +00:00
|
|
|
MobileConnectionIPCService::GetItemByServiceId(uint32_t aServiceId,
|
|
|
|
nsIMobileConnection** aItem)
|
2014-07-01 10:37:32 +00:00
|
|
|
{
|
2014-09-21 07:24:43 +00:00
|
|
|
NS_ENSURE_TRUE(aServiceId < mItems.Length(), NS_ERROR_INVALID_ARG);
|
2014-07-01 10:37:32 +00:00
|
|
|
|
2014-09-21 07:24:43 +00:00
|
|
|
if (!mItems[aServiceId]) {
|
|
|
|
nsRefPtr<MobileConnectionChild> child = new MobileConnectionChild(aServiceId);
|
2014-07-01 10:37:32 +00:00
|
|
|
|
2014-09-21 07:24:43 +00:00
|
|
|
// |SendPMobileConnectionConstructor| adds another reference to the child
|
|
|
|
// actor and removes in |DeallocPMobileConnectionChild|.
|
|
|
|
ContentChild::GetSingleton()->SendPMobileConnectionConstructor(child,
|
|
|
|
aServiceId);
|
|
|
|
child->Init();
|
2014-07-01 10:37:32 +00:00
|
|
|
|
2014-09-21 07:24:43 +00:00
|
|
|
mItems[aServiceId] = child;
|
2014-07-01 10:37:32 +00:00
|
|
|
}
|
|
|
|
|
2014-09-21 07:24:43 +00:00
|
|
|
nsRefPtr<nsIMobileConnection> item(mItems[aServiceId]);
|
|
|
|
item.forget(aItem);
|
2014-07-01 10:37:32 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|