realtimenetprots/sipfw/SampleApp/socketengine/Src/SIPExSocketReader.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 #include    "SIPExSocketReader.h"
       
    20 #include    "SIPEXReaderNotifier.h"
       
    21 #include    <in_sock.h>
       
    22 #include    <e32svr.h>
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // CSIPExSocketReader::NewL
       
    26 // Static constructor
       
    27 // -----------------------------------------------------------------------------
       
    28 //
       
    29 CSIPExSocketReader* CSIPExSocketReader::NewL( 
       
    30     RSocket& aSocket, 
       
    31     MSIPExReaderNotifier& aNotifier )
       
    32     {
       
    33     CSIPExSocketReader* self = NewLC( aSocket, aNotifier );
       
    34     CleanupStack::Pop(self);
       
    35     return self;
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CSIPExSocketReader::NewLC
       
    40 // Static constructor
       
    41 // -----------------------------------------------------------------------------
       
    42 //    
       
    43 CSIPExSocketReader* CSIPExSocketReader::NewLC( 
       
    44     RSocket& aSocket, 
       
    45     MSIPExReaderNotifier& aNotifier )
       
    46     {
       
    47     CSIPExSocketReader* self = new (ELeave) CSIPExSocketReader( aSocket, aNotifier );
       
    48     CleanupStack::PushL(self);
       
    49     self->ConstructL();
       
    50     return self;
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CSIPExSocketReader::CSIPExSocketReader
       
    55 // Constructor
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CSIPExSocketReader::CSIPExSocketReader( 
       
    59     RSocket& aSocket, 
       
    60     MSIPExReaderNotifier& aNotifier )
       
    61     : CActive(CActive::EPriorityStandard), 
       
    62       iNotifier( aNotifier ), 
       
    63       iSocket( aSocket )
       
    64     {
       
    65     CActiveScheduler::Add(this);
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CSIPExSocketReader::~CSIPExSocketReader
       
    70 // Destructor
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CSIPExSocketReader::~CSIPExSocketReader()
       
    74     {
       
    75     Cancel();
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CSIPExSocketReader::ConstructL
       
    80 // 2nd phase constructor
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CSIPExSocketReader::ConstructL()
       
    84     {
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CSIPExSocketReader::DoCancel
       
    89 // Cancels outstanding request.
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CSIPExSocketReader::DoCancel()
       
    93     {
       
    94     iSocket.CancelRead();
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CSIPExSocketReader::RunL
       
    99 // Buffers the characters read from socket and notifies the observer when buffer
       
   100 // if full. If error notifies the observer.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CSIPExSocketReader::RunL()
       
   104     {
       
   105     if( iStatus.Int() == KErrNone )
       
   106         {
       
   107         iMessage.Append( iBuffer );
       
   108         iBuffer.Zero();
       
   109         if( iMessage.Length() == 4 )
       
   110             {
       
   111             iNotifier.MessageReceived( iMessage );
       
   112             iMessage.Zero();
       
   113             }
       
   114         Read();
       
   115         }
       
   116     else
       
   117         {
       
   118         iMessage.FillZ();
       
   119         iMessage.Zero();
       
   120         iNotifier.ErrorInReading( iStatus.Int() );
       
   121         }
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CSIPExSocketReader::Read
       
   126 // Asynchronous
       
   127 // Starts the asynchoronous reading if not already active.
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CSIPExSocketReader::Read()
       
   131     {
       
   132     if( !IsActive() )
       
   133         {
       
   134         iSocket.Read( iBuffer, iStatus );
       
   135         SetActive();
       
   136         }
       
   137     }
       
   138 
       
   139 // End of file