Bug 1123651: Fix coding style in Nfc.cpp, r=allstars.chh
authorThomas Zimmermann <tdz@users.sourceforge.net>
Wed, 21 Jan 2015 10:59:21 +0100
changeset 251994 84c24df5a06056e428750a797d1aae6e5b5965ca
parent 251993 ad50ef7a29e549c5aa454f6642952dd8e10e301d
child 251995 7c33110665cda474da5023e19d1d77df36b72bc2
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersallstars
bugs1123651
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1123651: Fix coding style in Nfc.cpp, r=allstars.chh
ipc/nfc/Nfc.cpp
--- a/ipc/nfc/Nfc.cpp
+++ b/ipc/nfc/Nfc.cpp
@@ -1,10 +1,10 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* vim: set sw=4 ts=8 et ft=cpp: */
+/* vim: set sw=2 ts=8 et ft=cpp: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Copyright © 2013, Deutsche Telekom, Inc. */
 
 #include "mozilla/ipc/Nfc.h"
 
@@ -32,205 +32,206 @@ const char* NFC_SOCKET_NAME = "/dev/sock
 
 // Network port to connect to for adb forwarded sockets when doing
 // desktop development.
 const uint32_t NFC_TEST_PORT = 6400;
 
 class SendNfcSocketDataTask : public nsRunnable
 {
 public:
-    SendNfcSocketDataTask(NfcConsumer* aConsumer, UnixSocketRawData* aRawData)
-        : mConsumer(aConsumer), mRawData(aRawData)
-    { }
-
-    NS_IMETHOD Run()
-    {
-        MOZ_ASSERT(NS_IsMainThread());
+  SendNfcSocketDataTask(NfcConsumer* aConsumer, UnixSocketRawData* aRawData)
+    : mConsumer(aConsumer)
+    , mRawData(aRawData)
+  { }
 
-        if (!mConsumer ||
-            mConsumer->GetConnectionStatus() != SOCKET_CONNECTED) {
-            // Probably shuting down.
-            delete mRawData;
-            return NS_OK;
-        }
+  NS_IMETHOD Run()
+  {
+    MOZ_ASSERT(NS_IsMainThread());
 
-        mConsumer->SendSocketData(mRawData);
-        return NS_OK;
+    if (!mConsumer ||
+      mConsumer->GetConnectionStatus() != SOCKET_CONNECTED) {
+      // Probably shuting down.
+      delete mRawData;
+      return NS_OK;
     }
 
+    mConsumer->SendSocketData(mRawData);
+    return NS_OK;
+  }
+
 private:
-    NfcConsumer* mConsumer;
-    UnixSocketRawData* mRawData;
+  NfcConsumer* mConsumer;
+  UnixSocketRawData* mRawData;
 };
 
 class NfcConnector : public mozilla::ipc::UnixSocketConnector
 {
 public:
-    NfcConnector()
-    {}
+  NfcConnector()
+  { }
 
-    virtual ~NfcConnector()
-    {}
+  virtual ~NfcConnector()
+  { }
 
-    virtual int Create();
-    virtual bool CreateAddr(bool aIsServer,
-                            socklen_t& aAddrSize,
-                            sockaddr_any& aAddr,
-                            const char* aAddress);
-    virtual bool SetUp(int aFd);
-    virtual bool SetUpListenSocket(int aFd);
-    virtual void GetSocketAddr(const sockaddr_any& aAddr,
-                               nsAString& aAddrStr);
+  virtual int Create();
+  virtual bool CreateAddr(bool aIsServer,
+                          socklen_t& aAddrSize,
+                          sockaddr_any& aAddr,
+                          const char* aAddress);
+  virtual bool SetUp(int aFd);
+  virtual bool SetUpListenSocket(int aFd);
+  virtual void GetSocketAddr(const sockaddr_any& aAddr,
+                             nsAString& aAddrStr);
 };
 
 int
 NfcConnector::Create()
 {
-    MOZ_ASSERT(!NS_IsMainThread());
+  MOZ_ASSERT(!NS_IsMainThread());
 
-    int fd = -1;
+  int fd = -1;
 
 #if defined(MOZ_WIDGET_GONK)
-    fd = socket(AF_LOCAL, SOCK_STREAM, 0);
+  fd = socket(AF_LOCAL, SOCK_STREAM, 0);
 #else
-    // If we can't hit a local loopback, fail later in connect.
-    fd = socket(AF_INET, SOCK_STREAM, 0);
+  // If we can't hit a local loopback, fail later in connect.
+  fd = socket(AF_INET, SOCK_STREAM, 0);
 #endif
 
-    if (fd < 0) {
-        NS_WARNING("Could not open nfc socket!");
-        return -1;
-    }
+  if (fd < 0) {
+    NS_WARNING("Could not open nfc socket!");
+    return -1;
+  }
 
-    if (!SetUp(fd)) {
-        NS_WARNING("Could not set up socket!");
-    }
-    return fd;
+  if (!SetUp(fd)) {
+    NS_WARNING("Could not set up socket!");
+  }
+  return fd;
 }
 
 bool
 NfcConnector::CreateAddr(bool aIsServer,
                          socklen_t& aAddrSize,
                          sockaddr_any& aAddr,
                          const char* aAddress)
 {
-    // We never open nfc socket as server.
-    MOZ_ASSERT(!aIsServer);
-    uint32_t af;
+  // We never open nfc socket as server.
+  MOZ_ASSERT(!aIsServer);
+  uint32_t af;
 #if defined(MOZ_WIDGET_GONK)
-    af = AF_LOCAL;
+  af = AF_LOCAL;
 #else
-    af = AF_INET;
+  af = AF_INET;
 #endif
-    switch (af) {
-    case AF_LOCAL:
-        aAddr.un.sun_family = af;
-        if(strlen(aAddress) > sizeof(aAddr.un.sun_path)) {
-            NS_WARNING("Address too long for socket struct!");
-            return false;
-        }
-        strcpy((char*)&aAddr.un.sun_path, aAddress);
-        aAddrSize = strlen(aAddress) + offsetof(struct sockaddr_un, sun_path) + 1;
-        break;
-    case AF_INET:
-        aAddr.in.sin_family = af;
-        aAddr.in.sin_port = htons(NFC_TEST_PORT);
-        aAddr.in.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-        aAddrSize = sizeof(sockaddr_in);
-        break;
-    default:
-        NS_WARNING("Socket type not handled by connector!");
-        return false;
+  switch (af) {
+  case AF_LOCAL:
+    aAddr.un.sun_family = af;
+    if(strlen(aAddress) > sizeof(aAddr.un.sun_path)) {
+      NS_WARNING("Address too long for socket struct!");
+      return false;
     }
-    return true;
+    strcpy((char*)&aAddr.un.sun_path, aAddress);
+    aAddrSize = strlen(aAddress) + offsetof(struct sockaddr_un, sun_path) + 1;
+    break;
+  case AF_INET:
+    aAddr.in.sin_family = af;
+    aAddr.in.sin_port = htons(NFC_TEST_PORT);
+    aAddr.in.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+    aAddrSize = sizeof(sockaddr_in);
+    break;
+  default:
+    NS_WARNING("Socket type not handled by connector!");
+    return false;
+  }
+  return true;
 }
 
 bool
 NfcConnector::SetUp(int aFd)
 {
-    // Nothing to do here.
-    return true;
+  // Nothing to do here.
+  return true;
 }
 
 bool
 NfcConnector::SetUpListenSocket(int aFd)
 {
-    // Nothing to do here.
-    return true;
+  // Nothing to do here.
+  return true;
 }
 
 void
 NfcConnector::GetSocketAddr(const sockaddr_any& aAddr,
                             nsAString& aAddrStr)
 {
-    MOZ_CRASH("This should never be called!");
+  MOZ_CRASH("This should never be called!");
 }
 
 } // anonymous namespace
 
 namespace mozilla {
 namespace ipc {
 
 NfcConsumer::NfcConsumer(NfcSocketListener* aListener)
-    : mListener(aListener)
-    , mShutdown(false)
+  : mListener(aListener)
+  , mShutdown(false)
 {
-    mAddress = NFC_SOCKET_NAME;
+  mAddress = NFC_SOCKET_NAME;
 
-    ConnectSocket(new NfcConnector(), mAddress.get());
+  ConnectSocket(new NfcConnector(), mAddress.get());
 }
 
 void
 NfcConsumer::Shutdown()
 {
-    MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(NS_IsMainThread());
 
-    mShutdown = true;
-    CloseSocket();
+  mShutdown = true;
+  CloseSocket();
 }
 
 bool
 NfcConsumer::PostToNfcDaemon(const uint8_t* aData, size_t aSize)
 {
-    MOZ_ASSERT(!NS_IsMainThread());
+  MOZ_ASSERT(!NS_IsMainThread());
 
-    UnixSocketRawData* raw = new UnixSocketRawData(aData, aSize);
-    nsRefPtr<SendNfcSocketDataTask> task = new SendNfcSocketDataTask(this, raw);
-    NS_DispatchToMainThread(task);
-    return true;
+  UnixSocketRawData* raw = new UnixSocketRawData(aData, aSize);
+  nsRefPtr<SendNfcSocketDataTask> task = new SendNfcSocketDataTask(this, raw);
+  NS_DispatchToMainThread(task);
+  return true;
 }
 
 void
 NfcConsumer::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aData)
 {
-    MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(NS_IsMainThread());
 
-    if (mListener) {
-        mListener->ReceiveSocketData(aData);
-    }
+  if (mListener) {
+    mListener->ReceiveSocketData(aData);
+  }
 }
 
 void
 NfcConsumer::OnConnectSuccess()
 {
-    // Nothing to do here.
-    CHROMIUM_LOG("NFC: %s\n", __FUNCTION__);
+  // Nothing to do here.
+  CHROMIUM_LOG("NFC: %s\n", __FUNCTION__);
 }
 
 void
 NfcConsumer::OnConnectError()
 {
-    CHROMIUM_LOG("NFC: %s\n", __FUNCTION__);
-    CloseSocket();
+  CHROMIUM_LOG("NFC: %s\n", __FUNCTION__);
+  CloseSocket();
 }
 
 void
 NfcConsumer::OnDisconnect()
 {
-    CHROMIUM_LOG("NFC: %s\n", __FUNCTION__);
-    if (!mShutdown) {
-        ConnectSocket(new NfcConnector(), mAddress.get(),
-                      GetSuggestedConnectDelayMs());
-    }
+  CHROMIUM_LOG("NFC: %s\n", __FUNCTION__);
+  if (!mShutdown) {
+    ConnectSocket(new NfcConnector(), mAddress.get(),
+                  GetSuggestedConnectDelayMs());
+  }
 }
 
 } // namespace ipc
 } // namespace mozilla