browserutilities/favouritesengine/ClientServer/src/FavouritesBuf.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2004 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 the License "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 *      Implementation of class RFavouritesBuf
       
    16 *      
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "FavouritesBuf.h"
       
    24 #include "FavouritesMsg.h"
       
    25 #include "FavouritesPanic.h"
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 // ---------------------------------------------------------
       
    30 // RFavouritesBuf::Open
       
    31 // ---------------------------------------------------------
       
    32 //
       
    33 TInt RFavouritesBuf::Open( RFavouritesSession& aSess )
       
    34     {
       
    35 	SetBuf( ERead | EWrite, iBuf.iData, iBuf.iData );   // Empty.
       
    36     return RFavouritesHandle::Open( aSess, EFavengOpenStream, TIpcArgs() );
       
    37     }
       
    38 
       
    39 // ---------------------------------------------------------
       
    40 // RFavouritesBuf::Open
       
    41 // ---------------------------------------------------------
       
    42 //
       
    43 TInt RFavouritesBuf::Open
       
    44 ( RFavouritesHandle& aHandle, TInt aFunction, TIpcArgs& aArgs )
       
    45     {
       
    46     iBuf.iLen = 0;
       
    47 	SetBuf( ERead | EWrite, iBuf.iData, iBuf.iData );   // Initially empty.
       
    48     TPckg<TFavouritesBuf> buf( iBuf );
       
    49     aArgs.Set( 3, &buf );
       
    50     TInt err = RFavouritesHandle::Open( aHandle, aFunction, aArgs );
       
    51     if ( !err && iBuf.iLen > 0 )
       
    52         {
       
    53         // If aFunction provided data, it is already here.
       
    54         SetEnd( ERead, iBuf.iData + iBuf.iLen );
       
    55         }
       
    56     return err;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------
       
    60 // RFavouritesBuf::Close()
       
    61 // ---------------------------------------------------------
       
    62 //
       
    63 void RFavouritesBuf::Close()
       
    64     {
       
    65     // Resolve RFavouritesHandle::Close() vs. TStreamBuf::Close() ambiguity.
       
    66     // Mind the order: TStreamBuf::Close calls SynchL -> needs an open buf.
       
    67     TStreamBuf::Close();
       
    68     RFavouritesHandle::Close();
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------
       
    72 // RFavouritesBuf::UnderflowL()
       
    73 // ---------------------------------------------------------
       
    74 //
       
    75 TInt RFavouritesBuf::UnderflowL( TInt /*aMaxLength*/ )
       
    76     {
       
    77     __ASSERT_DEBUG( Avail( ERead ) == 0, \
       
    78         FavouritesPanic( EFavouritesInternal ) );
       
    79     return IpcReadL();
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------
       
    83 // RFavouritesBuf::OverflowL()
       
    84 // ---------------------------------------------------------
       
    85 //
       
    86 void RFavouritesBuf::OverflowL()
       
    87     {
       
    88     __ASSERT_DEBUG( Avail( EWrite ) == 0, \
       
    89         FavouritesPanic( EFavouritesInternal ) );
       
    90     IpcWriteL();
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------
       
    94 // RFavouritesBuf::DoSynchL()
       
    95 // ---------------------------------------------------------
       
    96 //
       
    97 void RFavouritesBuf::DoSynchL()
       
    98     {
       
    99     if ( Lag( ERead ) )
       
   100         {
       
   101         // Read lag unexpected, we do not support seeking.
       
   102         User::Leave( KErrNotSupported );
       
   103         }
       
   104     IpcWriteL();    // Flush write lag.
       
   105 	SetBuf( ERead | EWrite, iBuf.iData, iBuf.iData );
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------
       
   109 // RFavouritesBuf::IpcReadL()
       
   110 // ---------------------------------------------------------
       
   111 //
       
   112 TInt RFavouritesBuf::IpcReadL()
       
   113     {
       
   114 	TPtr8 des( iBuf.iData, KFavouritesStreamBufSize );
       
   115     TInt len = User::LeaveIfError
       
   116         ( SendReceive( EFavengStreamRead, TIpcArgs( &des ) ) );
       
   117     SetBuf( EWrite, iBuf.iData, iBuf.iData );
       
   118     SetBuf( ERead, iBuf.iData, iBuf.iData + len );
       
   119     return len;
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------
       
   123 // RFavouritesBuf::IpcWriteL()
       
   124 // ---------------------------------------------------------
       
   125 //
       
   126 void RFavouritesBuf::IpcWriteL()
       
   127     {
       
   128     if ( Lag( EWrite ) )
       
   129         {
       
   130         TPtrC8 ptr( iBuf.iData, Lag( EWrite ) );
       
   131         User::LeaveIfError
       
   132             ( SendReceive( EFavengStreamWrite, TIpcArgs( &ptr ) ) );
       
   133         }
       
   134     SetBuf( ERead, iBuf.iData, iBuf.iData );
       
   135     SetBuf( EWrite, iBuf.iData, iBuf.iData + KFavouritesStreamBufSize );
       
   136     }
       
   137 
       
   138 //  End of File