Msrp/MsrpServer/src/CMSRPParser.cpp
branchMSRP_FrameWork
changeset 25 505ad3f0ce5c
equal deleted inserted replaced
22:f1578314b8da 25:505ad3f0ce5c
       
     1 /*
       
     2 * Copyright (c) 2009-2010 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 * Initial Contributors:
       
     9 * Nokia Corporation - initial contribution.
       
    10 * Contributors:
       
    11 *
       
    12 * Description:
       
    13 * MSRP Implementation
       
    14 *
       
    15 */
       
    16 
       
    17 // INCLUDES
       
    18 
       
    19 // CLASS HEADER
       
    20 #include "CMSRPParser.h"
       
    21 #include "MSRPCommon.h"
       
    22 
       
    23 // -----------------------------------------------------------------------------
       
    24 // CMSRPParser::NewL
       
    25 // Static constructor
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 /*static*/MMSRPParser* CMSRPParser::NewL(MMSRPParserObserver& aConnection)
       
    29     {
       
    30     MSRPLOG( "CMSRPParser::NewL enter" )
       
    31     CMSRPParser* self = new (ELeave) CMSRPParser(aConnection);
       
    32     CleanupStack::PushL(self);
       
    33     self->ConstructL(aConnection);
       
    34     CleanupStack::Pop(self);
       
    35     MSRPLOG( "CMSRPParser::NewL exit" )
       
    36     return self;
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CMSRPParser::CMSRPParser
       
    41 // Constructor
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CMSRPParser::CMSRPParser(MMSRPParserObserver& aConnection)        
       
    45     : CActive(CActive::EPriorityStandard), iConnection( aConnection )
       
    46     {  
       
    47     CActiveScheduler::Add(this);
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CMSRPParser::~CMSRPParser
       
    52 // Destructor
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CMSRPParser::~CMSRPParser()
       
    56     {
       
    57     MSRPLOG( "CMSRPParser::~CMSRPParser enter" )
       
    58     Cancel();    
       
    59     delete iParser;
       
    60     MSRPLOG( "CMSRPParser::~CMSRPParser exit" )
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CMSRPParser::ConstructL
       
    65 // 2nd phase constructor
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 void CMSRPParser::ConstructL(MMSRPParserObserver& aConnection)
       
    69     {
       
    70     //iState = EIdle;
       
    71     iParser = CMSRPMsgParser::NewL(aConnection);
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CMSRPParser::DoCancel
       
    76 // Cancels outstanding request.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CMSRPParser::DoCancel()
       
    80     {
       
    81     MSRPLOG( "CMSRPParser::DoCancel enter" )
       
    82     //TRequestStatus* status = &iStatus;
       
    83     //User::RequestComplete( status, KErrCancel );
       
    84     MSRPLOG( "CMSRPParser::DoCancel exit" )
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CMSRPParser::Parse
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CMSRPParser::ParseL(RMsrpBuf& aBuf)
       
    92     { 
       
    93     MSRPLOG( "CMSRPParser::ParseL enter" )
       
    94     
       
    95     if(!IsActive())
       
    96         {
       
    97         TRequestStatus* status = &iStatus;
       
    98         SetActive();
       
    99         User::RequestComplete( status, KErrNone );
       
   100         }
       
   101     
       
   102     //collate with last element in array, else claim ownership
       
   103     if(iParser->iParseBuffers.Count())
       
   104         {
       
   105         if(iParser->iParseBuffers[iParser->iParseBuffers.Count()-1]->Collate(aBuf))
       
   106             return;
       
   107         }
       
   108         
       
   109     RMsrpBuf* buf = new (ELeave) RMsrpBuf(aBuf);
       
   110     CleanupDeletePushL(buf);
       
   111     iParser->iParseBuffers.AppendL(buf);
       
   112     CleanupStack::Pop( );
       
   113     MSRPLOG( "CMSRPParser::ParseL exit" )
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CMSRPParser::CancelReceiving
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 /*void CMSRPParser::CancelReceiving()
       
   121     {
       
   122     Cancel();
       
   123     }*/
       
   124 
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CMSRPParser::RunL
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CMSRPParser::RunL()
       
   131     {     
       
   132     MSRPLOG( "CMSRPParser::RunL enter" )
       
   133           
       
   134     TBool reschedule = iParser->ParseL();
       
   135     
       
   136     //count could be > 0 but data could be insufficient to parse
       
   137     if(reschedule && iParser->iParseBuffers.Count())
       
   138        {
       
   139        TRequestStatus* status = &iStatus;
       
   140        SetActive();
       
   141        User::RequestComplete( status, KErrNone );
       
   142        }
       
   143     MSRPLOG( "CMSRPParser::RunL exit" )
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CMSRPParser::RunError
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 TInt CMSRPParser::RunError(TInt /*aError*/)
       
   151     {
       
   152     MSRPLOG( "CMSRPParser::RunError enter" )    
       
   153     //aError = KErrNone;
       
   154     //ParseError//non leaving introduce
       
   155     TRAPD(err,iConnection.ParseStatusL(NULL, KErrCorrupt));
       
   156     MSRPLOG( "CMSRPParser::RunError exit" )
       
   157     return err;
       
   158     }
       
   159     
       
   160 
       
   161 // End of File
       
   162