Msrp/MsrpServer/src/CMSRPWriter.cpp
branchMSRP_FrameWork
changeset 25 505ad3f0ce5c
child 58 cdb720e67852
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 "CMSRPWriter.h"
       
    21 #include "MSRPCommon.h"
       
    22 
       
    23 // -----------------------------------------------------------------------------
       
    24 // CMSRPParser::NewL
       
    25 // Static constructor
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 /*static*/MMSRPWriter* CMSRPWriter::NewL(RSocket& aSocket, MMSRPWriterErrorObserver& aConnection)
       
    29     {
       
    30     MSRPLOG( "CMSRPWriter::NewL enter" )
       
    31     CMSRPWriter* self = new (ELeave) CMSRPWriter( aSocket, aConnection );
       
    32     CleanupStack::PushL(self);
       
    33     //self->ConstructL();
       
    34     CleanupStack::Pop(self);
       
    35     MSRPLOG( "CMSRPWriter::NewL exit" )
       
    36     return self;
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CMSRPWriter::CMSRPWriter
       
    41 // Constructor
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CMSRPWriter::CMSRPWriter(RSocket& aSocket, MMSRPWriterErrorObserver& aConnection)        
       
    45     : CActive(CActive::EPriorityStandard), iConnection( aConnection ), iSocket(aSocket)
       
    46     {  
       
    47     CActiveScheduler::Add(this);
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CMSRPWriter::~CMSRPWriter
       
    52 // Destructor
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CMSRPWriter::~CMSRPWriter()
       
    56     {
       
    57     MSRPLOG( "CMSRPWriter::~CMSRPWriter enter" )
       
    58     Cancel();    
       
    59     iSendQueue.Reset();
       
    60     iSendQueue.Close();
       
    61     MSRPLOG( "CMSRPWriter::~CMSRPWriter exit" )
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CMSRPWriter::ConstructL
       
    66 // 2nd phase constructor
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 /*
       
    70 void CMSRPWriter::ConstructL()
       
    71     {
       
    72     //iWriteIssued = FALSE;
       
    73     //iState = EIdle;
       
    74     }
       
    75 */
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CMSRPWriter::DoCancel
       
    79 // Cancels outstanding request.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CMSRPWriter::DoCancel()
       
    83     {
       
    84     MSRPLOG( "CMSRPWriter::DoCancel enter" )
       
    85     
       
    86     if(iWriteIssued)
       
    87         {
       
    88         MSRPLOG( "CMSRPWriter::write issued cancelled" )
       
    89         iSocket.CancelWrite();      
       
    90         }
       
    91     else
       
    92         {
       
    93         //MSRPLOG( "CMSRPWriter::self complete cancelled" )
       
    94         //TRequestStatus* status = &iStatus;
       
    95         //User::RequestComplete( status, KErrCancel );
       
    96         }
       
    97     MSRPLOG( "CMSRPWriter::DoCancel exit" )
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CMSRPWriter::Parse
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void CMSRPWriter::RequestSendL(MMSRPWriterObserver& aMsg)
       
   105     { 
       
   106     MSRPLOG( "CMSRPWriter::RequestSendL enter" )
       
   107     iSendQueue.AppendL(&aMsg);
       
   108     if(!IsActive())
       
   109         {
       
   110         /*avoid invoking send in other active object context*/
       
   111         //SendL
       
   112         TRequestStatus* status = &iStatus;
       
   113         SetActive();
       
   114         User::RequestComplete( status, KErrNone );
       
   115         }
       
   116     MSRPLOG( "CMSRPWriter::RequestSendL exit" )
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CMSRPWriter::CancelReceiving
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 /*void CMSRPWriter::CancelReceiving()
       
   124     {
       
   125     Cancel();
       
   126     }*/
       
   127 
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CMSRPWriter::RunL
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void CMSRPWriter::RunL()
       
   134     { 
       
   135     MSRPLOG( "CMSRPWriter::RunL enter" )    
       
   136         
       
   137     TInt status = iStatus.Int();
       
   138         
       
   139     if(status != KErrNone)
       
   140         {
       
   141         //socket error
       
   142         iConnection.WriteSocketError(status);
       
   143         return;
       
   144         }
       
   145     
       
   146     if(iWriteIssued)
       
   147         {
       
   148         iWriteIssued = FALSE;
       
   149         MMSRPWriterObserver::TMsgStatus msgState = MMSRPWriterObserver::EComplete;
       
   150         msgState = iSendQueue[0]->WriteDoneL(status); 
       
   151         
       
   152         if(msgState != MMSRPWriterObserver::EPending)
       
   153             {
       
   154             MMSRPWriterObserver* obs = iSendQueue[0];
       
   155             iSendQueue.Remove(0);
       
   156             if(msgState == MMSRPWriterObserver::EInterrupted)
       
   157                 iSendQueue.AppendL(obs);              
       
   158             }
       
   159         }
       
   160         
       
   161     SendL();
       
   162                     
       
   163     MSRPLOG( "CMSRPWriter::RunL exit" )
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CMSRPWriter::RunError
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 TInt CMSRPWriter::RunError(TInt aError)
       
   171     {
       
   172     MSRPLOG( "CMSRPWriter::RunError enter" )
       
   173     MSRPLOG( "CMSRPWriter::RunError exit" )
       
   174     /*get send buffer errors shud b handled in SendL 
       
   175      * by deleting msg obs from writer queue, if part of msg written to conn is 0 or complete
       
   176      * send failed msg error to client  in msghandler b4 getsend returns*/
       
   177     iConnection.WriteSocketError(aError);
       
   178     return KErrNone;    
       
   179     }
       
   180     
       
   181 // -----------------------------------------------------------------------------
       
   182 // CMSRPWriter::SendL
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CMSRPWriter::SendL()
       
   186     {
       
   187     TBool interruptSend = FALSE;
       
   188 
       
   189     //while(iSendQueue.Count())
       
   190     if(iSendQueue.Count())        
       
   191         {
       
   192         MMSRPWriterObserver::TWriteStatus ret = MMSRPWriterObserver::EMsrpSocketWrite;
       
   193         TPtrC8 data(NULL,0);
       
   194         
       
   195         if(iSendQueue.Count()>1)
       
   196             interruptSend = TRUE;
       
   197         
       
   198         ret = iSendQueue[0]->GetSendBufferL(data, interruptSend);
       
   199         
       
   200         Deque();
       
   201         CActiveScheduler::Add(this);
       
   202         SetActive();
       
   203 
       
   204         if( ret == MMSRPWriterObserver::EMsrpSocketWrite ) //KErrNone == 0
       
   205            {
       
   206            iSocket.Write( data, iStatus );
       
   207            iWriteIssued = TRUE;           
       
   208            }   
       
   209         else if (ret == MMSRPWriterObserver::EMsrpAvoidSocketWrite)//EAvoidSocketWrite
       
   210             {
       
   211             TRequestStatus* status = &iStatus;                       
       
   212             User::RequestComplete( status, KErrNone );
       
   213             iWriteIssued = FALSE;        
       
   214             }
       
   215         
       
   216 
       
   217          /* check in run_error: getsendbufferl leaves are recoverable
       
   218           * if msg state equivalent to nothing written to connection
       
   219           * ,remove observer and try to recover
       
   220           * if writedone leaves, then we can be sure that msg state will reflect socket write issued
       
   221           * and so no attempt will be made to recover
       
   222           */
       
   223         
       
   224         //iSendQueue.Remove(0);
       
   225         
       
   226         }            
       
   227     }
       
   228 
       
   229 
       
   230 // End of File
       
   231