tizen 2.4 release
[framework/web/wrt-commons.git] / modules / socket / src / waitable_input_output_execution_context_support.cpp
@@ -22,9 +22,8 @@
  */
 #include <stddef.h>
 #include <dpl/socket/waitable_input_output_execution_context_support.h>
-#include <dpl/scoped_array.h>
 #include <dpl/socket/abstract_socket.h> // FIXME: Remove !!!
-#include <dpl/log/log.h>
+#include <dpl/log/wrt_log.h>
 #include <dpl/assert.h>
 
 namespace DPL {
@@ -56,7 +55,7 @@ void WaitableInputOutputExecutionContextSupport::Open(
         Throw(Exception::AlreadyOpened);
     }
 
-    LogPedantic("Opening waitable input-output execution context support...");
+    WrtLogD("Opening waitable input-output execution context support...");
 
     // Save IO handle
     m_waitableInputOutput = inputOutput;
@@ -70,7 +69,7 @@ void WaitableInputOutputExecutionContextSupport::Open(
     // Done
     m_opened = true;
 
-    LogPedantic("Waitable input-output execution context support opened");
+    WrtLogD("Waitable input-output execution context support opened");
 }
 
 void WaitableInputOutputExecutionContextSupport::Close()
@@ -79,7 +78,7 @@ void WaitableInputOutputExecutionContextSupport::Close()
         return;
     }
 
-    LogPedantic("Closing waitable input-output execution context support...");
+    WrtLogD("Closing waitable input-output execution context support...");
 
     // Remove read and write watches
     CheckedRemoveReadWriteWatch();
@@ -87,43 +86,51 @@ void WaitableInputOutputExecutionContextSupport::Close()
     // Set proper state
     m_opened = false;
 
-    LogPedantic("Waitable input-output execution context support closed");
+    WrtLogD("Waitable input-output execution context support closed");
 }
 
 void WaitableInputOutputExecutionContextSupport::AddReadWatch()
 {
-    WaitableHandleWatchSupport::InheritedContext()->AddWaitableHandleWatch(
-        this,
-        m_waitableInputOutput
-            ->WaitableReadHandle(),
-        WaitMode
-            ::Read);
+    WaitableHandleWatchSupport* ctx =
+        WaitableHandleWatchSupport::InheritedContext();
+    if(ctx)
+        ctx->AddWaitableHandleWatch(
+            this,
+            m_waitableInputOutput->WaitableReadHandle(),
+            WaitMode::Read);
 }
 
 void WaitableInputOutputExecutionContextSupport::RemoveReadWatch()
 {
-    WaitableHandleWatchSupport::InheritedContext()->RemoveWaitableHandleWatch(
-        this,
-        m_waitableInputOutput->WaitableReadHandle(),
-        WaitMode::Read);
+    WaitableHandleWatchSupport* ctx =
+        WaitableHandleWatchSupport::InheritedContext();
+    if(ctx)
+        ctx->RemoveWaitableHandleWatch(
+            this,
+            m_waitableInputOutput->WaitableReadHandle(),
+            WaitMode::Read);
 }
 
 void WaitableInputOutputExecutionContextSupport::AddWriteWatch()
 {
-    WaitableHandleWatchSupport::InheritedContext()->AddWaitableHandleWatch(
-        this,
-        m_waitableInputOutput
-            ->WaitableWriteHandle(),
-        WaitMode
-            ::Write);
+    WaitableHandleWatchSupport* ctx =
+        WaitableHandleWatchSupport::InheritedContext();
+    if(ctx)
+        ctx->AddWaitableHandleWatch(
+            this,
+            m_waitableInputOutput->WaitableWriteHandle(),
+            WaitMode::Write);
 }
 
 void WaitableInputOutputExecutionContextSupport::RemoveWriteWatch()
 {
-    WaitableHandleWatchSupport::InheritedContext()->RemoveWaitableHandleWatch(
-        this,
-        m_waitableInputOutput->WaitableWriteHandle(),
-        WaitMode::Write);
+    WaitableHandleWatchSupport* ctx =
+        WaitableHandleWatchSupport::InheritedContext();
+    if(ctx)
+        ctx->RemoveWaitableHandleWatch(
+            this,
+            m_waitableInputOutput->WaitableWriteHandle(),
+            WaitMode::Write);
 }
 
 void WaitableInputOutputExecutionContextSupport::CheckedRemoveReadWatch()
@@ -163,7 +170,7 @@ void WaitableInputOutputExecutionContextSupport::OnWaitableHandleEvent(
 
     switch (mode) {
     case WaitMode::Read:
-        LogPedantic("Read event occurred");
+        WrtLogD("Read event occurred");
 
         // Read and parse bytes
         ReadInput();
@@ -172,7 +179,7 @@ void WaitableInputOutputExecutionContextSupport::OnWaitableHandleEvent(
         break;
 
     case WaitMode::Write:
-        LogPedantic("Write event occurred");
+        WrtLogD("Write event occurred");
 
         // Push bytes and unregister from write event
         FeedOutput();
@@ -194,7 +201,7 @@ void WaitableInputOutputExecutionContextSupport::OnWaitableHandleEvent(
 
 void WaitableInputOutputExecutionContextSupport::ReadInput()
 {
-    LogPedantic("Reading input bytes");
+    WrtLogD("Reading input bytes");
 
     Try
     {
@@ -203,7 +210,7 @@ void WaitableInputOutputExecutionContextSupport::ReadInput()
 
         if (inputBuffer.get() == NULL) {
             // No data, should not occur
-            LogPedantic("WARNING: Spontaneous ReadSocket occurred");
+            WrtLogD("WARNING: Spontaneous ReadSocket occurred");
             return;
         }
 
@@ -222,7 +229,7 @@ void WaitableInputOutputExecutionContextSupport::ReadInput()
             return;
         }
 
-        LogPedantic("Read " << inputBuffer->Size() << " input bytes");
+        WrtLogD("Read %i input bytes", inputBuffer->Size());
 
         // Append all read data
         m_inputStream.AppendMoveFrom(*inputBuffer);
@@ -232,7 +239,7 @@ void WaitableInputOutputExecutionContextSupport::ReadInput()
         //FIXME: Inproper exception abstraction!!!
         // Some errors occurred while feeding abstract IO
         // Interpret connection broken errors, and pass futher other ones
-        LogPedantic("Abstract IO connection was broken during read");
+        WrtLogD("Abstract IO connection was broken during read");
 
         // Signal broken connection
         OnInputStreamBroken();
@@ -264,7 +271,7 @@ void WaitableInputOutputExecutionContextSupport::FeedOutput()
     }
 
     // OK to feed output
-    LogPedantic("Feeding output");
+    WrtLogD("Feeding output");
 
     Try
     {
@@ -279,7 +286,7 @@ void WaitableInputOutputExecutionContextSupport::FeedOutput()
                 AddWriteWatch();
                 m_hasWriteWatch = true;
 
-                LogPedantic("Started exhaustive output feeding");
+                WrtLogD("Started exhaustive output feeding");
             }
         }
 
@@ -292,7 +299,7 @@ void WaitableInputOutputExecutionContextSupport::FeedOutput()
     {
         // Some errors occurred while feeding abstract IO
         // Interpret connection broken errors, and pass futher other ones
-        LogPedantic("Abstract IO connection was broken during write");
+        WrtLogD("Abstract IO connection was broken during write");
 
         // Signal broken connection
         OnInputStreamBroken();