dom/bluetooth/ipc/BluetoothChild.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/bluetooth/ipc/BluetoothChild.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,169 @@
     1.4 +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "base/basictypes.h"
    1.11 +
    1.12 +#include "BluetoothChild.h"
    1.13 +
    1.14 +#include "mozilla/Assertions.h"
    1.15 +#include "nsDebug.h"
    1.16 +#include "nsISupportsImpl.h"
    1.17 +#include "nsThreadUtils.h"
    1.18 +
    1.19 +#include "BluetoothReplyRunnable.h"
    1.20 +#include "BluetoothService.h"
    1.21 +#include "BluetoothServiceChildProcess.h"
    1.22 +
    1.23 +USING_BLUETOOTH_NAMESPACE
    1.24 +
    1.25 +namespace {
    1.26 +
    1.27 +BluetoothServiceChildProcess* sBluetoothService;
    1.28 +
    1.29 +} // anonymous namespace
    1.30 +
    1.31 +/*******************************************************************************
    1.32 + * BluetoothChild
    1.33 + ******************************************************************************/
    1.34 +
    1.35 +BluetoothChild::BluetoothChild(BluetoothServiceChildProcess* aBluetoothService)
    1.36 +: mShutdownState(Running)
    1.37 +{
    1.38 +  MOZ_COUNT_CTOR(BluetoothChild);
    1.39 +  MOZ_ASSERT(!sBluetoothService);
    1.40 +  MOZ_ASSERT(aBluetoothService);
    1.41 +
    1.42 +  sBluetoothService = aBluetoothService;
    1.43 +}
    1.44 +
    1.45 +BluetoothChild::~BluetoothChild()
    1.46 +{
    1.47 +  MOZ_COUNT_DTOR(BluetoothChild);
    1.48 +  MOZ_ASSERT(sBluetoothService);
    1.49 +  MOZ_ASSERT(mShutdownState == Dead);
    1.50 +
    1.51 +  sBluetoothService = nullptr;
    1.52 +}
    1.53 +
    1.54 +void
    1.55 +BluetoothChild::BeginShutdown()
    1.56 +{
    1.57 +  // Only do something here if we haven't yet begun the shutdown sequence.
    1.58 +  if (mShutdownState == Running) {
    1.59 +    SendStopNotifying();
    1.60 +    mShutdownState = SentStopNotifying;
    1.61 +  }
    1.62 +}
    1.63 +
    1.64 +void
    1.65 +BluetoothChild::ActorDestroy(ActorDestroyReason aWhy)
    1.66 +{
    1.67 +  MOZ_ASSERT(sBluetoothService);
    1.68 +
    1.69 +  sBluetoothService->NoteDeadActor();
    1.70 +
    1.71 +#ifdef DEBUG
    1.72 +  mShutdownState = Dead;
    1.73 +#endif
    1.74 +}
    1.75 +
    1.76 +bool
    1.77 +BluetoothChild::RecvNotify(const BluetoothSignal& aSignal)
    1.78 +{
    1.79 +  MOZ_ASSERT(sBluetoothService);
    1.80 +
    1.81 +  sBluetoothService->DistributeSignal(aSignal);
    1.82 +  return true;
    1.83 +}
    1.84 +
    1.85 +bool
    1.86 +BluetoothChild::RecvEnabled(const bool& aEnabled)
    1.87 +{
    1.88 +  MOZ_ASSERT(sBluetoothService);
    1.89 +
    1.90 +  sBluetoothService->SetEnabled(aEnabled);
    1.91 +  return true;
    1.92 +}
    1.93 +
    1.94 +bool
    1.95 +BluetoothChild::RecvBeginShutdown()
    1.96 +{
    1.97 +  if (mShutdownState != Running && mShutdownState != SentStopNotifying) {
    1.98 +    MOZ_ASSERT(false, "Bad state!");
    1.99 +    return false;
   1.100 +  }
   1.101 +
   1.102 +  SendStopNotifying();
   1.103 +  mShutdownState = SentStopNotifying;
   1.104 +
   1.105 +  return true;
   1.106 +}
   1.107 +
   1.108 +bool
   1.109 +BluetoothChild::RecvNotificationsStopped()
   1.110 +{
   1.111 +  if (mShutdownState != SentStopNotifying) {
   1.112 +    MOZ_ASSERT(false, "Bad state!");
   1.113 +    return false;
   1.114 +  }
   1.115 +
   1.116 +  Send__delete__(this);
   1.117 +  return true;
   1.118 +}
   1.119 +
   1.120 +PBluetoothRequestChild*
   1.121 +BluetoothChild::AllocPBluetoothRequestChild(const Request& aRequest)
   1.122 +{
   1.123 +  MOZ_CRASH("Caller is supposed to manually construct a request!");
   1.124 +}
   1.125 +
   1.126 +bool
   1.127 +BluetoothChild::DeallocPBluetoothRequestChild(PBluetoothRequestChild* aActor)
   1.128 +{
   1.129 +  delete aActor;
   1.130 +  return true;
   1.131 +}
   1.132 +
   1.133 +/*******************************************************************************
   1.134 + * BluetoothRequestChild
   1.135 + ******************************************************************************/
   1.136 +
   1.137 +BluetoothRequestChild::BluetoothRequestChild(
   1.138 +                                         BluetoothReplyRunnable* aReplyRunnable)
   1.139 +: mReplyRunnable(aReplyRunnable)
   1.140 +{
   1.141 +  MOZ_COUNT_CTOR(BluetoothRequestChild);
   1.142 +  MOZ_ASSERT(aReplyRunnable);
   1.143 +}
   1.144 +
   1.145 +BluetoothRequestChild::~BluetoothRequestChild()
   1.146 +{
   1.147 +  MOZ_COUNT_DTOR(BluetoothRequestChild);
   1.148 +}
   1.149 +
   1.150 +void
   1.151 +BluetoothRequestChild::ActorDestroy(ActorDestroyReason aWhy)
   1.152 +{
   1.153 +  // Nothing needed here.
   1.154 +}
   1.155 +
   1.156 +bool
   1.157 +BluetoothRequestChild::Recv__delete__(const BluetoothReply& aReply)
   1.158 +{
   1.159 +  MOZ_ASSERT(NS_IsMainThread());
   1.160 +  MOZ_ASSERT(mReplyRunnable);
   1.161 +
   1.162 +  nsRefPtr<BluetoothReplyRunnable> replyRunnable;
   1.163 +  mReplyRunnable.swap(replyRunnable);
   1.164 +
   1.165 +  if (replyRunnable) {
   1.166 +    // XXXbent Need to fix this, it copies unnecessarily.
   1.167 +    replyRunnable->SetReply(new BluetoothReply(aReply));
   1.168 +    return NS_SUCCEEDED(NS_DispatchToCurrentThread(replyRunnable));
   1.169 +  }
   1.170 +
   1.171 +  return true;
   1.172 +}

mercurial