mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1171994: Separate RIL I/O interfaces, r=htsai
This patch separates the current interface of |RilConsumer| into two distinct classes. |RilWorker| provides the public interface and |RilConsumer| provides the internal implementation. Running |RilConsumer| on a worker thread will be easier this way.
This commit is contained in:
parent
892060a564
commit
09dca3ba49
@ -119,7 +119,7 @@ SystemWorkerManager::Shutdown()
|
||||
ShutdownAutoMounter();
|
||||
|
||||
#ifdef MOZ_B2G_RIL
|
||||
RilConsumer::Shutdown();
|
||||
RilWorker::Shutdown();
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIWifi> wifi(do_QueryInterface(mWifiWorker));
|
||||
@ -201,7 +201,7 @@ SystemWorkerManager::RegisterRilWorker(unsigned int aClientId,
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return RilConsumer::Register(aClientId, wctd);
|
||||
return RilWorker::Register(aClientId, wctd);
|
||||
#endif // MOZ_B2G_RIL
|
||||
}
|
||||
|
||||
|
147
ipc/ril/Ril.cpp
147
ipc/ril/Ril.cpp
@ -10,8 +10,19 @@
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <netdb.h> // For gethostbyname.
|
||||
#include "jsfriendapi.h"
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/dom/workers/Workers.h"
|
||||
#include "mozilla/ipc/StreamSocket.h"
|
||||
#include "mozilla/ipc/StreamSocketConsumer.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsThreadUtils.h" // For NS_IsMainThread.
|
||||
#include "RilConnector.h"
|
||||
|
||||
#ifdef CHROMIUM_LOG
|
||||
#undef CHROMIUM_LOG
|
||||
#endif
|
||||
|
||||
#if defined(MOZ_WIDGET_GONK)
|
||||
#include <android/log.h>
|
||||
#define CHROMIUM_LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk", args)
|
||||
@ -19,20 +30,47 @@
|
||||
#define CHROMIUM_LOG(args...) printf(args);
|
||||
#endif
|
||||
|
||||
#include "jsfriendapi.h"
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsThreadUtils.h" // For NS_IsMainThread.
|
||||
#include "RilConnector.h"
|
||||
|
||||
USING_WORKERS_NAMESPACE
|
||||
using namespace mozilla::ipc;
|
||||
|
||||
namespace {
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
class RilConsumer;
|
||||
|
||||
static const char RIL_SOCKET_NAME[] = "/dev/socket/rilproxy";
|
||||
|
||||
static nsTArray<nsAutoPtr<mozilla::ipc::RilConsumer>> sRilConsumers;
|
||||
static nsTArray<nsAutoPtr<RilConsumer>> sRilConsumers;
|
||||
|
||||
//
|
||||
// RilConsumer
|
||||
//
|
||||
|
||||
class RilConsumer final : public StreamSocketConsumer
|
||||
{
|
||||
public:
|
||||
friend class RilWorker;
|
||||
|
||||
RilConsumer(unsigned long aClientId,
|
||||
WorkerCrossThreadDispatcher* aDispatcher);
|
||||
|
||||
void Send(UnixSocketRawData* aRawData);
|
||||
void Close();
|
||||
|
||||
// Methods for |StreamSocketConsumer|
|
||||
//
|
||||
|
||||
void ReceiveSocketData(int aIndex,
|
||||
nsAutoPtr<UnixSocketBuffer>& aBuffer) override;
|
||||
void OnConnectSuccess(int aIndex) override;
|
||||
void OnConnectError(int aIndex) override;
|
||||
void OnDisconnect(int aIndex) override;
|
||||
|
||||
private:
|
||||
nsRefPtr<StreamSocket> mSocket;
|
||||
nsRefPtr<mozilla::dom::workers::WorkerCrossThreadDispatcher> mDispatcher;
|
||||
nsCString mAddress;
|
||||
bool mShutdown;
|
||||
};
|
||||
|
||||
class ConnectWorkerToRIL final : public WorkerTask
|
||||
{
|
||||
@ -193,11 +231,6 @@ DispatchRILEvent::RunTask(JSContext* aCx)
|
||||
return JS_CallFunctionName(aCx, obj, "onRILMessage", args, &rval);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
RilConsumer::RilConsumer(unsigned long aClientId,
|
||||
WorkerCrossThreadDispatcher* aDispatcher)
|
||||
: mDispatcher(aDispatcher)
|
||||
@ -218,47 +251,6 @@ RilConsumer::RilConsumer(unsigned long aClientId,
|
||||
mSocket->Connect(new RilConnector(mAddress, aClientId));
|
||||
}
|
||||
|
||||
nsresult
|
||||
RilConsumer::Register(unsigned int aClientId,
|
||||
WorkerCrossThreadDispatcher* aDispatcher)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
sRilConsumers.EnsureLengthAtLeast(aClientId + 1);
|
||||
|
||||
if (sRilConsumers[aClientId]) {
|
||||
NS_WARNING("RilConsumer already registered");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsRefPtr<ConnectWorkerToRIL> connection = new ConnectWorkerToRIL();
|
||||
if (!aDispatcher->PostTask(connection)) {
|
||||
NS_WARNING("Failed to connect worker to ril");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
// Now that we're set up, connect ourselves to the RIL thread.
|
||||
sRilConsumers[aClientId] = new RilConsumer(aClientId, aDispatcher);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
RilConsumer::Shutdown()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
for (unsigned long i = 0; i < sRilConsumers.Length(); i++) {
|
||||
nsAutoPtr<RilConsumer> instance(sRilConsumers[i]);
|
||||
if (!instance) {
|
||||
continue;
|
||||
}
|
||||
|
||||
instance->mShutdown = true;
|
||||
instance->Close();
|
||||
instance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RilConsumer::Send(UnixSocketRawData* aRawData)
|
||||
{
|
||||
@ -316,5 +308,50 @@ RilConsumer::OnDisconnect(int aIndex)
|
||||
mSocket->GetSuggestedConnectDelayMs());
|
||||
}
|
||||
|
||||
//
|
||||
// RilWorker
|
||||
//
|
||||
|
||||
nsresult
|
||||
RilWorker::Register(unsigned int aClientId,
|
||||
WorkerCrossThreadDispatcher* aDispatcher)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
sRilConsumers.EnsureLengthAtLeast(aClientId + 1);
|
||||
|
||||
if (sRilConsumers[aClientId]) {
|
||||
NS_WARNING("RilConsumer already registered");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsRefPtr<ConnectWorkerToRIL> connection = new ConnectWorkerToRIL();
|
||||
if (!aDispatcher->PostTask(connection)) {
|
||||
NS_WARNING("Failed to connect worker to ril");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
// Now that we're set up, connect ourselves to the RIL thread.
|
||||
sRilConsumers[aClientId] = new RilConsumer(aClientId, aDispatcher);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
RilWorker::Shutdown()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
for (unsigned long i = 0; i < sRilConsumers.Length(); i++) {
|
||||
nsAutoPtr<RilConsumer> instance(sRilConsumers[i]);
|
||||
if (!instance) {
|
||||
continue;
|
||||
}
|
||||
|
||||
instance->mShutdown = true;
|
||||
instance->Close();
|
||||
instance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ipc
|
||||
} // namespace mozilla
|
||||
|
@ -7,42 +7,28 @@
|
||||
#ifndef mozilla_ipc_Ril_h
|
||||
#define mozilla_ipc_Ril_h 1
|
||||
|
||||
#include <mozilla/dom/workers/Workers.h>
|
||||
#include <mozilla/ipc/StreamSocket.h>
|
||||
#include <mozilla/ipc/StreamSocketConsumer.h>
|
||||
#include "nsError.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace dom {
|
||||
namespace workers {
|
||||
|
||||
class WorkerCrossThreadDispatcher;
|
||||
|
||||
} // namespace workers
|
||||
} // namespace dom
|
||||
|
||||
namespace ipc {
|
||||
|
||||
class RilConsumer final : public StreamSocketConsumer
|
||||
class RilWorker final
|
||||
{
|
||||
public:
|
||||
static nsresult Register(
|
||||
unsigned int aClientId,
|
||||
mozilla::dom::workers::WorkerCrossThreadDispatcher* aDispatcher);
|
||||
|
||||
static void Shutdown();
|
||||
|
||||
void Send(UnixSocketRawData* aRawData);
|
||||
|
||||
private:
|
||||
RilConsumer(unsigned long aClientId,
|
||||
mozilla::dom::workers::WorkerCrossThreadDispatcher* aDispatcher);
|
||||
|
||||
void Close();
|
||||
|
||||
// Methods for |StreamSocketConsumer|
|
||||
//
|
||||
|
||||
void ReceiveSocketData(int aIndex,
|
||||
nsAutoPtr<UnixSocketBuffer>& aBuffer) override;
|
||||
void OnConnectSuccess(int aIndex) override;
|
||||
void OnConnectError(int aIndex) override;
|
||||
void OnDisconnect(int aIndex) override;
|
||||
|
||||
nsRefPtr<StreamSocket> mSocket;
|
||||
nsRefPtr<mozilla::dom::workers::WorkerCrossThreadDispatcher> mDispatcher;
|
||||
nsCString mAddress;
|
||||
bool mShutdown;
|
||||
};
|
||||
|
||||
} // namespace ipc
|
||||
|
Loading…
Reference in New Issue
Block a user