browserutilities/favouritesengine/ClientServer/src/FavouritesFile.cpp
changeset 0 dd21522fd290
child 25 0ed94ceaa377
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 RFavouritesFile
       
    16 *       
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "FavouritesFile.h"
       
    24 #include "FavouritesMsg.h"
       
    25 #include "FavouritesPanic.h"
       
    26 #include "FavouritesDb.h"
       
    27 #include <f32file.h>
       
    28 
       
    29 // CLASS DECLARATION
       
    30 
       
    31 /**
       
    32 * Favourites file implementation.
       
    33 */
       
    34 NONSHARABLE_CLASS(CFavouritesFileImpl): public CBase
       
    35     {
       
    36     public:     // Destructor
       
    37 
       
    38         /**
       
    39         * Destructor.
       
    40         */
       
    41         virtual inline ~CFavouritesFileImpl();
       
    42 
       
    43     public:     // data
       
    44 
       
    45         RFile iFile;    ///< The file.
       
    46 
       
    47     };
       
    48 
       
    49 // ---------------------------------------------------------
       
    50 // CFavouritesFileImpl::~CFavouritesFileImpl
       
    51 // ---------------------------------------------------------
       
    52 //
       
    53 CFavouritesFileImpl::~CFavouritesFileImpl()
       
    54     {
       
    55     iFile.Close();
       
    56     }
       
    57 
       
    58 // ================= MEMBER FUNCTIONS =======================
       
    59 
       
    60 // ---------------------------------------------------------
       
    61 // RFavouritesFile::Close
       
    62 // ---------------------------------------------------------
       
    63 //
       
    64 EXPORT_C void RFavouritesFile::Close()
       
    65     {
       
    66     delete iImpl;
       
    67     iImpl = NULL;
       
    68     RFavouritesHandle::Close();
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------
       
    72 // RFavouritesFile::Open
       
    73 // ---------------------------------------------------------
       
    74 //
       
    75 EXPORT_C TInt RFavouritesFile::Open( RFavouritesDb& aDb, TInt aUid )
       
    76     {
       
    77     return DoOpen( aDb, aUid, EFavengFileOpenRead );
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // RFavouritesFile::Replace
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 EXPORT_C TInt RFavouritesFile::Replace( RFavouritesDb& aDb, TInt aUid )
       
    85     {
       
    86     return DoOpen( aDb, aUid, EFavengFileOpenWrite );
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------
       
    90 // RFavouritesFile::Read
       
    91 // ---------------------------------------------------------
       
    92 //
       
    93 EXPORT_C TInt RFavouritesFile::Read( TDes8& aDes ) const
       
    94     {
       
    95     __ASSERT_DEBUG( iImpl, FavouritesPanic( EFavouritesNotReady ) );
       
    96     return iImpl->iFile.Read( aDes );
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------
       
   100 // RFavouritesFile::Write
       
   101 // ---------------------------------------------------------
       
   102 //
       
   103 EXPORT_C TInt RFavouritesFile::Write( const TDesC8& aDes )
       
   104     {
       
   105     __ASSERT_DEBUG( iImpl, FavouritesPanic( EFavouritesNotReady ) );
       
   106     return iImpl->iFile.Write( aDes );
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------
       
   110 // RFavouritesFile::Size
       
   111 // ---------------------------------------------------------
       
   112 //
       
   113 EXPORT_C TInt RFavouritesFile::Size(TInt &aSize) const
       
   114 	{
       
   115 	__ASSERT_DEBUG( iImpl, FavouritesPanic( EFavouritesNotReady ) );
       
   116     return iImpl->iFile.Size( aSize );
       
   117 	}
       
   118 	
       
   119 // ---------------------------------------------------------
       
   120 // RFavouritesFile::DoOpen
       
   121 // ---------------------------------------------------------
       
   122 //
       
   123 TInt RFavouritesFile::DoOpen( RFavouritesDb& aDb, TInt aUid, TInt aFunction )
       
   124     {
       
   125     __ASSERT_DEBUG( !iImpl, FavouritesPanic( EFavouritesAlreadyOpen ) );
       
   126     TInt err;
       
   127     iImpl = new CFavouritesFileImpl();
       
   128     if ( iImpl )
       
   129         {
       
   130         err = RFavouritesHandle::Open
       
   131             ( aDb, EFavengFileOpen, TIpcArgs( aUid ) );
       
   132 
       
   133         if ( !err )
       
   134             {
       
   135             TPckgBuf<TInt> file;
       
   136             
       
   137             TInt rfsHandler = RFavouritesHandle::SendReceive( 
       
   138             	aFunction, TIpcArgs( aUid, &file ));
       
   139             
       
   140         	if(rfsHandler >= 0)
       
   141         		{
       
   142             	err = iImpl->iFile.AdoptFromServer( rfsHandler, file() );
       
   143         		}
       
   144         	else
       
   145         		{
       
   146         		err = rfsHandler;
       
   147         		}
       
   148             }
       
   149         }
       
   150     else
       
   151         {
       
   152         err = KErrNoMemory;
       
   153         }
       
   154     if ( err )
       
   155         {
       
   156         Close();    // Deletes and NULL-s iImpl.
       
   157         }
       
   158     return err;
       
   159     }
       
   160 
       
   161 // End of file