Bug 801507 - Listen to ObjectPush service socket. r=qdot, a=blocking-basecamp
authorEric Chou <echou@mozilla.com>
Mon, 15 Oct 2012 14:16:41 +0800
changeset 113413 7b2a0dc30b53f4ea1a79b2832bcc9a928c65659c
parent 113412 6f1d02bdf889aa0b32f19654d5f0567ca53b93c2
child 113414 c4a76f8e8d69ccdc8818a2345525c0e4cbe71764
push id2342
push userryanvm@gmail.com
push dateWed, 17 Oct 2012 00:45:56 +0000
treeherdermozilla-aurora@cbfef8616b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot, blocking-basecamp
bugs801507
milestone18.0a2
Bug 801507 - Listen to ObjectPush service socket. r=qdot, a=blocking-basecamp
dom/bluetooth/BluetoothOppManager.cpp
dom/bluetooth/BluetoothOppManager.h
dom/bluetooth/linux/BluetoothDBusService.cpp
--- a/dom/bluetooth/BluetoothOppManager.cpp
+++ b/dom/bluetooth/BluetoothOppManager.cpp
@@ -154,16 +154,37 @@ BluetoothOppManager::Connect(const nsASt
 
 void
 BluetoothOppManager::Disconnect()
 {
   CloseSocket();
 }
 
 bool
+BluetoothOppManager::Listen()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  CloseSocket();
+
+  BluetoothService* bs = BluetoothService::Get();
+  if (!bs) {
+    NS_WARNING("BluetoothService not available!");
+    return false;
+  }
+
+  nsresult rv = bs->ListenSocketViaService(BluetoothReservedChannels::OPUSH,
+                                           BluetoothSocketType::RFCOMM,
+                                           true,
+                                           false,
+                                           this);
+  return NS_FAILED(rv) ? false : true;
+}
+
+bool
 BluetoothOppManager::SendFile(BlobParent* aActor,
                               BluetoothReplyRunnable* aRunnable)
 {
   if (mBlob) {
     // Means there's a sending process. Reply error.
     return false;
   }
 
--- a/dom/bluetooth/BluetoothOppManager.h
+++ b/dom/bluetooth/BluetoothOppManager.h
@@ -41,16 +41,17 @@ public:
    * percentage of file. At the end, the application will get another
    * system message indicating that te process is complete, then it can
    * either call Disconnect() to close RFCOMM connection or start another
    * file-sending thread via calling SendFile() again.
    */
   bool Connect(const nsAString& aDeviceObjectPath,
                BluetoothReplyRunnable* aRunnable);
   void Disconnect();
+  bool Listen();
 
   bool SendFile(BlobParent* aBlob,
                 BluetoothReplyRunnable* aRunnable);
   bool StopSendingFile(BluetoothReplyRunnable* aRunnable);
 
   void SendConnectRequest();
   void SendPutHeaderRequest(const nsAString& aFileName, int aFileSize);
   void SendPutRequest(uint8_t* aFileBody, int aFileBodyLength,
--- a/dom/bluetooth/linux/BluetoothDBusService.cpp
+++ b/dom/bluetooth/linux/BluetoothDBusService.cpp
@@ -752,30 +752,42 @@ class PrepareProfileManagersRunnable : p
 public:
   NS_IMETHOD
   Run()
   {
     BluetoothHfpManager* h = BluetoothHfpManager::Get();
     if (h) {
       h->Listen();
     }
+
+    BluetoothOppManager* opp = BluetoothOppManager::Get();
+    if (opp) {
+      opp->Listen();
+    }
+
     return NS_OK;
   }
 };
 
 class ShutdownProfileManagersRunnable : public nsRunnable
 {
 public:
   NS_IMETHOD
   Run()
   {
     BluetoothHfpManager* h = BluetoothHfpManager::Get();
     if (h) {
       h->CloseSocket();
     }
+
+    BluetoothOppManager* opp = BluetoothOppManager::Get();
+    if (opp) {
+      opp->CloseSocket();
+    }
+
     return NS_OK;
   }
 };
 
 class PrepareAdapterRunnable : public nsRunnable
 {
 public:
   PrepareAdapterRunnable(const nsAString& aPath) :
@@ -788,16 +800,17 @@ public:
   Run()
   {
     MOZ_ASSERT(!NS_IsMainThread());
 
     nsTArray<uint32_t> uuids;
 
     uuids.AppendElement((uint32_t)(BluetoothServiceUuid::HandsfreeAG >> 32));
     uuids.AppendElement((uint32_t)(BluetoothServiceUuid::HeadsetAG >> 32));
+    uuids.AppendElement((uint32_t)(BluetoothServiceUuid::ObjectPush >> 32));
 
     // TODO/qdot: This needs to be held for the life of the bluetooth connection
     // so we could clean it up. For right now though, we can throw it away.
     nsTArray<uint32_t> handles;
 
     if (!BluetoothDBusService::AddReservedServicesInternal(mPath, uuids, handles)) {
       NS_WARNING("Failed to add reserved services");
 #ifdef MOZ_WIDGET_GONK