realtimenetprots/sipfw/SampleApp/socketengine/Src/SIPExSocketWriter.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 
       
     2 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 // All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 //
       
     9 // Initial Contributors:
       
    10 // Nokia Corporation - initial contribution.
       
    11 //
       
    12 // Contributors:
       
    13 //
       
    14 // Description:
       
    15 //
       
    16 
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include    "SIPExSocketWriter.h"
       
    21 #include    "SIPExWriterNotifier.h"
       
    22 #include    <in_sock.h>
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // CSIPExSocketWriter::NewL
       
    26 // Static constructor
       
    27 // -----------------------------------------------------------------------------
       
    28 //
       
    29 CSIPExSocketWriter* CSIPExSocketWriter::NewL( 
       
    30     RSocket& aSocket, 
       
    31     MSIPExWriterNotifier& aNotifier )
       
    32     {
       
    33     CSIPExSocketWriter* self = NewLC( aSocket, aNotifier );
       
    34     CleanupStack::Pop(self);
       
    35     return self;
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CSIPExSocketWriter::NewLC
       
    40 // Static constructor
       
    41 // -----------------------------------------------------------------------------
       
    42 //    
       
    43 CSIPExSocketWriter* CSIPExSocketWriter::NewLC( 
       
    44     RSocket& aSocket, 
       
    45     MSIPExWriterNotifier& aNotifier )
       
    46     {
       
    47     CSIPExSocketWriter* self = new (ELeave) CSIPExSocketWriter( aSocket, aNotifier );
       
    48     CleanupStack::PushL(self);
       
    49     self->ConstructL();
       
    50     return self;
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CSIPExSocketWriter::CSIPExSocketWriter
       
    55 // Constructor
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CSIPExSocketWriter::CSIPExSocketWriter( 
       
    59     RSocket& aSocket, 
       
    60     MSIPExWriterNotifier& aNotifier )
       
    61     : CActive(CActive::EPriorityStandard), 
       
    62       iNotifier( aNotifier ), 
       
    63       iSocket( aSocket )
       
    64     {
       
    65     CActiveScheduler::Add(this);
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CSIPExSocketWriter::~CSIPExSocketWriter
       
    70 // Destructor
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CSIPExSocketWriter::~CSIPExSocketWriter()
       
    74     {
       
    75     Cancel();
       
    76     delete iBuffer;
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CSIPExSocketWriter::ConstructL
       
    81 // 2nd phase constructor
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CSIPExSocketWriter::ConstructL()
       
    85     {
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CSIPExSocketWriter::DoCancel
       
    90 // From CActive
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CSIPExSocketWriter::DoCancel()
       
    94     {
       
    95     iSocket.CancelWrite();
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CSIPExSocketWriter::RunL
       
   100 // From CActive
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CSIPExSocketWriter::RunL()
       
   104     {
       
   105     if( iBuffer )
       
   106         {
       
   107         delete iBuffer;
       
   108         iBuffer = NULL;
       
   109         }
       
   110 
       
   111     if( iStatus.Int() == KErrNone )
       
   112         {
       
   113         iNotifier.WriteDone();
       
   114         }
       
   115     else
       
   116         {
       
   117         iNotifier.ErrorInWriting( iStatus.Int() );
       
   118         }
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CSIPExSocketWriter::Write
       
   123 // Asynchronous
       
   124 // Copy the parameter to the member variable and start asynchronous writing.
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CSIPExSocketWriter::Write( const TDesC8& aBuffer )
       
   128     {
       
   129     if( iBuffer )
       
   130         {
       
   131         delete iBuffer;
       
   132         iBuffer = NULL;
       
   133         }
       
   134 
       
   135     TRAPD( err, iBuffer = aBuffer.AllocL() );
       
   136 
       
   137     if( !IsActive() && err == KErrNone )
       
   138         {
       
   139         iSocket.Write( *iBuffer, iStatus );
       
   140         SetActive();
       
   141         }
       
   142     }
       
   143 
       
   144 // End of file