dom/bluetooth/ipc/BluetoothServiceChildProcess.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

     1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
     2 /* vim: set ts=2 et sw=2 tw=80: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #include "base/basictypes.h"
     9 #include "BluetoothServiceChildProcess.h"
    11 #include "mozilla/Assertions.h"
    12 #include "mozilla/dom/ContentChild.h"
    14 #include "BluetoothChild.h"
    15 #include "MainThreadUtils.h"
    17 USING_BLUETOOTH_NAMESPACE
    19 namespace {
    21 BluetoothChild* sBluetoothChild;
    23 inline
    24 void
    25 SendRequest(BluetoothReplyRunnable* aRunnable, const Request& aRequest)
    26 {
    27   MOZ_ASSERT(NS_IsMainThread());
    28   MOZ_ASSERT(aRunnable);
    30   NS_WARN_IF_FALSE(sBluetoothChild,
    31                    "Calling methods on BluetoothServiceChildProcess during "
    32                    "shutdown!");
    34   if (sBluetoothChild) {
    35     BluetoothRequestChild* actor = new BluetoothRequestChild(aRunnable);
    36     sBluetoothChild->SendPBluetoothRequestConstructor(actor, aRequest);
    37   }
    38 }
    40 } // anonymous namespace
    42 // static
    43 BluetoothServiceChildProcess*
    44 BluetoothServiceChildProcess::Create()
    45 {
    46   MOZ_ASSERT(!sBluetoothChild);
    48   mozilla::dom::ContentChild* contentChild =
    49     mozilla::dom::ContentChild::GetSingleton();
    50   MOZ_ASSERT(contentChild);
    52   BluetoothServiceChildProcess* btService = new BluetoothServiceChildProcess();
    54   sBluetoothChild = new BluetoothChild(btService);
    55   contentChild->SendPBluetoothConstructor(sBluetoothChild);
    57   return btService;
    58 }
    60 BluetoothServiceChildProcess::BluetoothServiceChildProcess()
    61 {
    62 }
    64 BluetoothServiceChildProcess::~BluetoothServiceChildProcess()
    65 {
    66   sBluetoothChild = nullptr;
    67 }
    69 void
    70 BluetoothServiceChildProcess::NoteDeadActor()
    71 {
    72   MOZ_ASSERT(sBluetoothChild);
    73   sBluetoothChild = nullptr;
    74 }
    76 void
    77 BluetoothServiceChildProcess::RegisterBluetoothSignalHandler(
    78                                               const nsAString& aNodeName,
    79                                               BluetoothSignalObserver* aHandler)
    80 {
    81   if (sBluetoothChild && !IsSignalRegistered(aNodeName)) {
    82     sBluetoothChild->SendRegisterSignalHandler(nsString(aNodeName));
    83   }
    84   BluetoothService::RegisterBluetoothSignalHandler(aNodeName, aHandler);
    85 }
    87 void
    88 BluetoothServiceChildProcess::UnregisterBluetoothSignalHandler(
    89                                               const nsAString& aNodeName,
    90                                               BluetoothSignalObserver* aHandler)
    91 {
    92   BluetoothService::UnregisterBluetoothSignalHandler(aNodeName, aHandler);
    93   if (sBluetoothChild && !IsSignalRegistered(aNodeName)) {
    94     sBluetoothChild->SendUnregisterSignalHandler(nsString(aNodeName));
    95   }
    96 }
    98 nsresult
    99 BluetoothServiceChildProcess::GetDefaultAdapterPathInternal(
   100                                               BluetoothReplyRunnable* aRunnable)
   101 {
   102   SendRequest(aRunnable, DefaultAdapterPathRequest());
   103   return NS_OK;
   104 }
   106 nsresult
   107 BluetoothServiceChildProcess::GetConnectedDevicePropertiesInternal(
   108                                               uint16_t aServiceUuid,
   109                                               BluetoothReplyRunnable* aRunnable)
   110 {
   111   SendRequest(aRunnable, ConnectedDevicePropertiesRequest(aServiceUuid));
   112   return NS_OK;
   113 }
   114 nsresult
   115 BluetoothServiceChildProcess::GetPairedDevicePropertiesInternal(
   116                                      const nsTArray<nsString>& aDeviceAddresses,
   117                                      BluetoothReplyRunnable* aRunnable)
   118 {
   119   PairedDevicePropertiesRequest request;
   120   request.addresses().AppendElements(aDeviceAddresses);
   122   SendRequest(aRunnable, request);
   123   return NS_OK;
   124 }
   126 nsresult
   127 BluetoothServiceChildProcess::StopDiscoveryInternal(
   128                                               BluetoothReplyRunnable* aRunnable)
   129 {
   130   SendRequest(aRunnable, StopDiscoveryRequest());
   131   return NS_OK;
   132 }
   134 nsresult
   135 BluetoothServiceChildProcess::StartDiscoveryInternal(
   136                                               BluetoothReplyRunnable* aRunnable)
   137 {
   138   SendRequest(aRunnable, StartDiscoveryRequest());
   139   return NS_OK;
   140 }
   142 nsresult
   143 BluetoothServiceChildProcess::SetProperty(BluetoothObjectType aType,
   144                                           const BluetoothNamedValue& aValue,
   145                                           BluetoothReplyRunnable* aRunnable)
   146 {
   147   SendRequest(aRunnable, SetPropertyRequest(aType, aValue));
   148   return NS_OK;
   149 }
   151 nsresult
   152 BluetoothServiceChildProcess::CreatePairedDeviceInternal(
   153                                               const nsAString& aAddress,
   154                                               int aTimeout,
   155                                               BluetoothReplyRunnable* aRunnable)
   156 {
   157   SendRequest(aRunnable,
   158               PairRequest(nsString(aAddress), aTimeout));
   159   return NS_OK;
   160 }
   162 nsresult
   163 BluetoothServiceChildProcess::RemoveDeviceInternal(
   164                                               const nsAString& aObjectPath,
   165                                               BluetoothReplyRunnable* aRunnable)
   166 {
   167   SendRequest(aRunnable,
   168               UnpairRequest(nsString(aObjectPath)));
   169   return NS_OK;
   170 }
   172 nsresult
   173 BluetoothServiceChildProcess::GetServiceChannel(const nsAString& aDeviceAddress,
   174                                                 const nsAString& aServiceUuid,
   175                                                 BluetoothProfileManagerBase* aManager)
   176 {
   177   MOZ_CRASH("This should never be called!");
   178 }
   180 bool
   181 BluetoothServiceChildProcess::UpdateSdpRecords(const nsAString& aDeviceAddress,
   182                                                BluetoothProfileManagerBase* aManager)
   183 {
   184   MOZ_CRASH("This should never be called!");
   185 }
   187 bool
   188 BluetoothServiceChildProcess::SetPinCodeInternal(
   189                                                 const nsAString& aDeviceAddress,
   190                                                 const nsAString& aPinCode,
   191                                                 BluetoothReplyRunnable* aRunnable)
   192 {
   193   SendRequest(aRunnable,
   194               SetPinCodeRequest(nsString(aDeviceAddress), nsString(aPinCode)));
   195   return true;
   196 }
   198 bool
   199 BluetoothServiceChildProcess::SetPasskeyInternal(
   200                                                 const nsAString& aDeviceAddress,
   201                                                 uint32_t aPasskey,
   202                                                 BluetoothReplyRunnable* aRunnable)
   203 {
   204   SendRequest(aRunnable,
   205               SetPasskeyRequest(nsString(aDeviceAddress), aPasskey));
   206   return true;
   207 }
   209 bool
   210 BluetoothServiceChildProcess::SetPairingConfirmationInternal(
   211                                                 const nsAString& aDeviceAddress,
   212                                                 bool aConfirm,
   213                                                 BluetoothReplyRunnable* aRunnable)
   214 {
   215   if(aConfirm) {
   216     SendRequest(aRunnable,
   217                 ConfirmPairingConfirmationRequest(nsString(aDeviceAddress)));
   218   } else {
   219     SendRequest(aRunnable,
   220                 DenyPairingConfirmationRequest(nsString(aDeviceAddress)));
   221   }
   222   return true;
   223 }
   225 void
   226 BluetoothServiceChildProcess::Connect(
   227   const nsAString& aDeviceAddress,
   228   uint32_t aCod,
   229   uint16_t aServiceUuid,
   230   BluetoothReplyRunnable* aRunnable)
   231 {
   232   SendRequest(aRunnable,
   233               ConnectRequest(nsString(aDeviceAddress),
   234                              aCod,
   235                              aServiceUuid));
   236 }
   238 void
   239 BluetoothServiceChildProcess::Disconnect(
   240   const nsAString& aDeviceAddress,
   241   uint16_t aServiceUuid,
   242   BluetoothReplyRunnable* aRunnable)
   243 {
   244   SendRequest(aRunnable,
   245               DisconnectRequest(nsString(aDeviceAddress), aServiceUuid));
   246 }
   248 void
   249 BluetoothServiceChildProcess::SendFile(
   250   const nsAString& aDeviceAddress,
   251   BlobParent* aBlobParent,
   252   BlobChild* aBlobChild,
   253   BluetoothReplyRunnable* aRunnable)
   254 {
   255   SendRequest(aRunnable,
   256               SendFileRequest(nsString(aDeviceAddress), nullptr, aBlobChild));
   257 }
   259 void
   260 BluetoothServiceChildProcess::SendFile(
   261   const nsAString& aDeviceAddress,
   262   nsIDOMBlob* aBlobChild,
   263   BluetoothReplyRunnable* aRunnable)
   264 {
   265   // Parent-process-only method
   266   MOZ_CRASH("This should never be called!");
   267 }
   269 void
   270 BluetoothServiceChildProcess::StopSendingFile(
   271   const nsAString& aDeviceAddress,
   272   BluetoothReplyRunnable* aRunnable)
   273 {
   274   SendRequest(aRunnable,
   275               StopSendingFileRequest(nsString(aDeviceAddress)));
   276 }
   278 void
   279 BluetoothServiceChildProcess::ConfirmReceivingFile(
   280   const nsAString& aDeviceAddress,
   281   bool aConfirm,
   282   BluetoothReplyRunnable* aRunnable)
   283 {
   284   if(aConfirm) {
   285     SendRequest(aRunnable,
   286                 ConfirmReceivingFileRequest(nsString(aDeviceAddress)));
   287     return;
   288   }
   290   SendRequest(aRunnable,
   291               DenyReceivingFileRequest(nsString(aDeviceAddress)));
   292 }
   294 void
   295 BluetoothServiceChildProcess::ConnectSco(BluetoothReplyRunnable* aRunnable)
   296 {
   297   SendRequest(aRunnable, ConnectScoRequest());
   298 }
   300 void
   301 BluetoothServiceChildProcess::DisconnectSco(BluetoothReplyRunnable* aRunnable)
   302 {
   303   SendRequest(aRunnable, DisconnectScoRequest());
   304 }
   306 void
   307 BluetoothServiceChildProcess::IsScoConnected(BluetoothReplyRunnable* aRunnable)
   308 {
   309   SendRequest(aRunnable, IsScoConnectedRequest());
   310 }
   312 #ifdef MOZ_B2G_RIL
   313 void
   314 BluetoothServiceChildProcess::AnswerWaitingCall(
   315   BluetoothReplyRunnable* aRunnable)
   316 {
   317   SendRequest(aRunnable, AnswerWaitingCallRequest());
   318 }
   320 void
   321 BluetoothServiceChildProcess::IgnoreWaitingCall(
   322   BluetoothReplyRunnable* aRunnable)
   323 {
   324   SendRequest(aRunnable, IgnoreWaitingCallRequest());
   325 }
   327 void
   328 BluetoothServiceChildProcess::ToggleCalls(
   329   BluetoothReplyRunnable* aRunnable)
   330 {
   331   SendRequest(aRunnable, ToggleCallsRequest());
   332 }
   333 #endif // MOZ_B2G_RIL
   335 void
   336 BluetoothServiceChildProcess::SendMetaData(const nsAString& aTitle,
   337                                            const nsAString& aArtist,
   338                                            const nsAString& aAlbum,
   339                                            int64_t aMediaNumber,
   340                                            int64_t aTotalMediaCount,
   341                                            int64_t aDuration,
   342                                            BluetoothReplyRunnable* aRunnable)
   343 {
   344   SendRequest(aRunnable,
   345               SendMetaDataRequest(nsString(aTitle), nsString(aArtist),
   346                                   nsString(aAlbum), aMediaNumber,
   347                                   aTotalMediaCount, aDuration));
   348 }
   350 void
   351 BluetoothServiceChildProcess::SendPlayStatus(int64_t aDuration,
   352                                              int64_t aPosition,
   353                                              const nsAString& aPlayStatus,
   354                                              BluetoothReplyRunnable* aRunnable)
   355 {
   356   SendRequest(aRunnable,
   357               SendPlayStatusRequest(aDuration, aPosition,
   358                                     nsString(aPlayStatus)));
   359 }
   361 nsresult
   362 BluetoothServiceChildProcess::HandleStartup()
   363 {
   364   // Don't need to do anything here for startup since our Create function takes
   365   // care of the actor machinery.
   366   return NS_OK;
   367 }
   369 nsresult
   370 BluetoothServiceChildProcess::HandleShutdown()
   371 {
   372   // If this process is shutting down then we need to disconnect ourselves from
   373   // the parent.
   374   if (sBluetoothChild) {
   375     sBluetoothChild->BeginShutdown();
   376   }
   377   return NS_OK;
   378 }
   380 nsresult
   381 BluetoothServiceChildProcess::StartInternal()
   382 {
   383   MOZ_CRASH("This should never be called!");
   384 }
   386 nsresult
   387 BluetoothServiceChildProcess::StopInternal()
   388 {
   389   MOZ_CRASH("This should never be called!");
   390 }
   392 bool
   393 BluetoothServiceChildProcess::IsConnected(uint16_t aServiceUuid)
   394 {
   395   MOZ_CRASH("This should never be called!");
   396 }
   398 nsresult
   399 BluetoothServiceChildProcess::SendSinkMessage(const nsAString& aDeviceAddresses,
   400                                               const nsAString& aMessage)
   401 {
   402   MOZ_CRASH("This should never be called!");
   403 }
   405 nsresult
   406 BluetoothServiceChildProcess::SendInputMessage(const nsAString& aDeviceAddresses,
   407                                                const nsAString& aMessage)
   408 {
   409   MOZ_CRASH("This should never be called!");
   410 }
   412 void
   413 BluetoothServiceChildProcess::UpdatePlayStatus(uint32_t aDuration,
   414                                                uint32_t aPosition,
   415                                                ControlPlayStatus aPlayStatus)
   416 {
   417   MOZ_CRASH("This should never be called!");
   418 }

mercurial