dom/bluetooth/ipc/BluetoothChild.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "base/basictypes.h"
michael@0 8
michael@0 9 #include "BluetoothChild.h"
michael@0 10
michael@0 11 #include "mozilla/Assertions.h"
michael@0 12 #include "nsDebug.h"
michael@0 13 #include "nsISupportsImpl.h"
michael@0 14 #include "nsThreadUtils.h"
michael@0 15
michael@0 16 #include "BluetoothReplyRunnable.h"
michael@0 17 #include "BluetoothService.h"
michael@0 18 #include "BluetoothServiceChildProcess.h"
michael@0 19
michael@0 20 USING_BLUETOOTH_NAMESPACE
michael@0 21
michael@0 22 namespace {
michael@0 23
michael@0 24 BluetoothServiceChildProcess* sBluetoothService;
michael@0 25
michael@0 26 } // anonymous namespace
michael@0 27
michael@0 28 /*******************************************************************************
michael@0 29 * BluetoothChild
michael@0 30 ******************************************************************************/
michael@0 31
michael@0 32 BluetoothChild::BluetoothChild(BluetoothServiceChildProcess* aBluetoothService)
michael@0 33 : mShutdownState(Running)
michael@0 34 {
michael@0 35 MOZ_COUNT_CTOR(BluetoothChild);
michael@0 36 MOZ_ASSERT(!sBluetoothService);
michael@0 37 MOZ_ASSERT(aBluetoothService);
michael@0 38
michael@0 39 sBluetoothService = aBluetoothService;
michael@0 40 }
michael@0 41
michael@0 42 BluetoothChild::~BluetoothChild()
michael@0 43 {
michael@0 44 MOZ_COUNT_DTOR(BluetoothChild);
michael@0 45 MOZ_ASSERT(sBluetoothService);
michael@0 46 MOZ_ASSERT(mShutdownState == Dead);
michael@0 47
michael@0 48 sBluetoothService = nullptr;
michael@0 49 }
michael@0 50
michael@0 51 void
michael@0 52 BluetoothChild::BeginShutdown()
michael@0 53 {
michael@0 54 // Only do something here if we haven't yet begun the shutdown sequence.
michael@0 55 if (mShutdownState == Running) {
michael@0 56 SendStopNotifying();
michael@0 57 mShutdownState = SentStopNotifying;
michael@0 58 }
michael@0 59 }
michael@0 60
michael@0 61 void
michael@0 62 BluetoothChild::ActorDestroy(ActorDestroyReason aWhy)
michael@0 63 {
michael@0 64 MOZ_ASSERT(sBluetoothService);
michael@0 65
michael@0 66 sBluetoothService->NoteDeadActor();
michael@0 67
michael@0 68 #ifdef DEBUG
michael@0 69 mShutdownState = Dead;
michael@0 70 #endif
michael@0 71 }
michael@0 72
michael@0 73 bool
michael@0 74 BluetoothChild::RecvNotify(const BluetoothSignal& aSignal)
michael@0 75 {
michael@0 76 MOZ_ASSERT(sBluetoothService);
michael@0 77
michael@0 78 sBluetoothService->DistributeSignal(aSignal);
michael@0 79 return true;
michael@0 80 }
michael@0 81
michael@0 82 bool
michael@0 83 BluetoothChild::RecvEnabled(const bool& aEnabled)
michael@0 84 {
michael@0 85 MOZ_ASSERT(sBluetoothService);
michael@0 86
michael@0 87 sBluetoothService->SetEnabled(aEnabled);
michael@0 88 return true;
michael@0 89 }
michael@0 90
michael@0 91 bool
michael@0 92 BluetoothChild::RecvBeginShutdown()
michael@0 93 {
michael@0 94 if (mShutdownState != Running && mShutdownState != SentStopNotifying) {
michael@0 95 MOZ_ASSERT(false, "Bad state!");
michael@0 96 return false;
michael@0 97 }
michael@0 98
michael@0 99 SendStopNotifying();
michael@0 100 mShutdownState = SentStopNotifying;
michael@0 101
michael@0 102 return true;
michael@0 103 }
michael@0 104
michael@0 105 bool
michael@0 106 BluetoothChild::RecvNotificationsStopped()
michael@0 107 {
michael@0 108 if (mShutdownState != SentStopNotifying) {
michael@0 109 MOZ_ASSERT(false, "Bad state!");
michael@0 110 return false;
michael@0 111 }
michael@0 112
michael@0 113 Send__delete__(this);
michael@0 114 return true;
michael@0 115 }
michael@0 116
michael@0 117 PBluetoothRequestChild*
michael@0 118 BluetoothChild::AllocPBluetoothRequestChild(const Request& aRequest)
michael@0 119 {
michael@0 120 MOZ_CRASH("Caller is supposed to manually construct a request!");
michael@0 121 }
michael@0 122
michael@0 123 bool
michael@0 124 BluetoothChild::DeallocPBluetoothRequestChild(PBluetoothRequestChild* aActor)
michael@0 125 {
michael@0 126 delete aActor;
michael@0 127 return true;
michael@0 128 }
michael@0 129
michael@0 130 /*******************************************************************************
michael@0 131 * BluetoothRequestChild
michael@0 132 ******************************************************************************/
michael@0 133
michael@0 134 BluetoothRequestChild::BluetoothRequestChild(
michael@0 135 BluetoothReplyRunnable* aReplyRunnable)
michael@0 136 : mReplyRunnable(aReplyRunnable)
michael@0 137 {
michael@0 138 MOZ_COUNT_CTOR(BluetoothRequestChild);
michael@0 139 MOZ_ASSERT(aReplyRunnable);
michael@0 140 }
michael@0 141
michael@0 142 BluetoothRequestChild::~BluetoothRequestChild()
michael@0 143 {
michael@0 144 MOZ_COUNT_DTOR(BluetoothRequestChild);
michael@0 145 }
michael@0 146
michael@0 147 void
michael@0 148 BluetoothRequestChild::ActorDestroy(ActorDestroyReason aWhy)
michael@0 149 {
michael@0 150 // Nothing needed here.
michael@0 151 }
michael@0 152
michael@0 153 bool
michael@0 154 BluetoothRequestChild::Recv__delete__(const BluetoothReply& aReply)
michael@0 155 {
michael@0 156 MOZ_ASSERT(NS_IsMainThread());
michael@0 157 MOZ_ASSERT(mReplyRunnable);
michael@0 158
michael@0 159 nsRefPtr<BluetoothReplyRunnable> replyRunnable;
michael@0 160 mReplyRunnable.swap(replyRunnable);
michael@0 161
michael@0 162 if (replyRunnable) {
michael@0 163 // XXXbent Need to fix this, it copies unnecessarily.
michael@0 164 replyRunnable->SetReply(new BluetoothReply(aReply));
michael@0 165 return NS_SUCCEEDED(NS_DispatchToCurrentThread(replyRunnable));
michael@0 166 }
michael@0 167
michael@0 168 return true;
michael@0 169 }

mercurial