Tizen 2.0 Release
[framework/web/wrt-commons.git] / modules / core / src / named_output_pipe.cpp
index 5dd7215..2a9a1fa 100644 (file)
@@ -19,6 +19,7 @@
  * @version     1.0
  * @brief       This file is the implementation file of named output pipe
  */
+#include <stddef.h>
 #include <dpl/named_output_pipe.h>
 #include <dpl/binary_queue.h>
 #include <dpl/scoped_free.h>
 #include <fcntl.h>
 #include <errno.h>
 
-namespace DPL
-{
-NamedOutputPipe::NamedOutputPipe()
-    : m_fifo(-1)
-{
-}
+namespace DPL {
+NamedOutputPipe::NamedOutputPipe() :
+    m_fifo(-1)
+{}
 
 NamedOutputPipe::~NamedOutputPipe()
 {
@@ -45,19 +44,22 @@ void NamedOutputPipe::Open(const std::string& pipeName)
     // Then open it for reading or writing
     int fifo = TEMP_FAILURE_RETRY(open(pipeName.c_str(), O_WRONLY | O_NONBLOCK));
 
-    if (fifo == -1)
+    if (fifo == -1) {
         ThrowMsg(Exception::OpenFailed, pipeName);
+    }
 
     m_fifo = fifo;
 }
 
 void NamedOutputPipe::Close()
 {
-    if (m_fifo == -1)
+    if (m_fifo == -1) {
         return;
+    }
 
-    if (TEMP_FAILURE_RETRY(close(m_fifo)) == -1)
+    if (TEMP_FAILURE_RETRY(close(m_fifo)) == -1) {
         Throw(Exception::CloseFailed);
+    }
 
     m_fifo = -1;
 }
@@ -65,8 +67,9 @@ void NamedOutputPipe::Close()
 size_t NamedOutputPipe::Write(const BinaryQueue &buffer, size_t bufferSize)
 {
     // Adjust write size
-    if (bufferSize > buffer.Size())
+    if (bufferSize > buffer.Size()) {
         bufferSize = buffer.Size();
+    }
 
     // FIXME: User write visitor to write !
     // WriteVisitor visitor
@@ -74,20 +77,17 @@ size_t NamedOutputPipe::Write(const BinaryQueue &buffer, size_t bufferSize)
     ScopedFree<void> flattened(malloc(bufferSize));
     buffer.Flatten(flattened.Get(), bufferSize);
 
-    ssize_t result = TEMP_FAILURE_RETRY(write(m_fifo, flattened.Get(), bufferSize));
+    ssize_t result =
+        TEMP_FAILURE_RETRY(write(m_fifo, flattened.Get(), bufferSize));
 
-    if (result > 0)
-    {
+    if (result > 0) {
         // Successfuly written some bytes
         return static_cast<size_t>(result);
-    }
-    else if (result == 0)
-    {
+    } else if (result == 0) {
         // This is abnormal result
-        ThrowMsg(CommonException::InternalError, "Invalid socket write result, 0 bytes written");
-    }
-    else
-    {
+        ThrowMsg(CommonException::InternalError,
+                 "Invalid socket write result, 0 bytes written");
+    } else {
         // Interpret error result
         // FIXME: Handle errno
         Throw(AbstractOutput::Exception::WriteFailed);