contentstorage/srvsrc/casrvmmchistory.cpp
author hgs
Mon, 18 Oct 2010 10:44:15 +0300
changeset 127 7b66bc3c6dc9
parent 94 dbb8300717f7
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
85
7feec50967db 201003_02
hgs
parents:
diff changeset
     1
/*
7feec50967db 201003_02
hgs
parents:
diff changeset
     2
 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
7feec50967db 201003_02
hgs
parents:
diff changeset
     3
 * All rights reserved.
7feec50967db 201003_02
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
7feec50967db 201003_02
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
7feec50967db 201003_02
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
7feec50967db 201003_02
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
7feec50967db 201003_02
hgs
parents:
diff changeset
     8
 *
7feec50967db 201003_02
hgs
parents:
diff changeset
     9
 * Initial Contributors:
7feec50967db 201003_02
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
7feec50967db 201003_02
hgs
parents:
diff changeset
    11
 *
7feec50967db 201003_02
hgs
parents:
diff changeset
    12
 * Contributors:
7feec50967db 201003_02
hgs
parents:
diff changeset
    13
 *
7feec50967db 201003_02
hgs
parents:
diff changeset
    14
 * Description:  ?Description
7feec50967db 201003_02
hgs
parents:
diff changeset
    15
 *
7feec50967db 201003_02
hgs
parents:
diff changeset
    16
 */
7feec50967db 201003_02
hgs
parents:
diff changeset
    17
7feec50967db 201003_02
hgs
parents:
diff changeset
    18
// INCLUDE FILES
7feec50967db 201003_02
hgs
parents:
diff changeset
    19
#include <f32file.h>
7feec50967db 201003_02
hgs
parents:
diff changeset
    20
#include <s32file.h>
7feec50967db 201003_02
hgs
parents:
diff changeset
    21
#include <sysutil.h>
7feec50967db 201003_02
hgs
parents:
diff changeset
    22
#include "casrvmmchistory.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    23
// CONSTANTS
7feec50967db 201003_02
hgs
parents:
diff changeset
    24
LOCAL_D const TInt KCaMmcHistoryLength = 2;
7feec50967db 201003_02
hgs
parents:
diff changeset
    25
7feec50967db 201003_02
hgs
parents:
diff changeset
    26
// ==================== MEMBER FUNCTIONS ====================
7feec50967db 201003_02
hgs
parents:
diff changeset
    27
7feec50967db 201003_02
hgs
parents:
diff changeset
    28
// ---------------------------------------------------------
94
hgs
parents: 85
diff changeset
    29
//
hgs
parents: 85
diff changeset
    30
// ---------------------------------------------------------
hgs
parents: 85
diff changeset
    31
//
hgs
parents: 85
diff changeset
    32
CCaSrvMmcHistory::CCaSrvMmcHistory()
hgs
parents: 85
diff changeset
    33
	{
hgs
parents: 85
diff changeset
    34
	}
hgs
parents: 85
diff changeset
    35
hgs
parents: 85
diff changeset
    36
// ---------------------------------------------------------
hgs
parents: 85
diff changeset
    37
//
hgs
parents: 85
diff changeset
    38
// ---------------------------------------------------------
hgs
parents: 85
diff changeset
    39
//
hgs
parents: 85
diff changeset
    40
void CCaSrvMmcHistory::ConstructL()
hgs
parents: 85
diff changeset
    41
	{
hgs
parents: 85
diff changeset
    42
	}
hgs
parents: 85
diff changeset
    43
hgs
parents: 85
diff changeset
    44
// ---------------------------------------------------------
hgs
parents: 85
diff changeset
    45
//
hgs
parents: 85
diff changeset
    46
// ---------------------------------------------------------
hgs
parents: 85
diff changeset
    47
//
hgs
parents: 85
diff changeset
    48
EXPORT_C CCaSrvMmcHistory* CCaSrvMmcHistory::NewL()
hgs
parents: 85
diff changeset
    49
     {
hgs
parents: 85
diff changeset
    50
     CCaSrvMmcHistory* self = new (ELeave) CCaSrvMmcHistory();
hgs
parents: 85
diff changeset
    51
     CleanupStack::PushL( self );
hgs
parents: 85
diff changeset
    52
     self->ConstructL();
hgs
parents: 85
diff changeset
    53
     CleanupStack::Pop( self );
hgs
parents: 85
diff changeset
    54
     return self;
hgs
parents: 85
diff changeset
    55
     }
hgs
parents: 85
diff changeset
    56
hgs
parents: 85
diff changeset
    57
// ---------------------------------------------------------
hgs
parents: 85
diff changeset
    58
//
hgs
parents: 85
diff changeset
    59
// ---------------------------------------------------------
hgs
parents: 85
diff changeset
    60
//
hgs
parents: 85
diff changeset
    61
CCaSrvMmcHistory::~CCaSrvMmcHistory()
hgs
parents: 85
diff changeset
    62
    {
hgs
parents: 85
diff changeset
    63
    iMmcList.Close();
hgs
parents: 85
diff changeset
    64
    }
hgs
parents: 85
diff changeset
    65
hgs
parents: 85
diff changeset
    66
// ---------------------------------------------------------
hgs
parents: 85
diff changeset
    67
//
85
7feec50967db 201003_02
hgs
parents:
diff changeset
    68
// ---------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
    69
//
7feec50967db 201003_02
hgs
parents:
diff changeset
    70
EXPORT_C void CCaSrvMmcHistory::LoadL( RFs& aFs, const TDesC& aFname )
7feec50967db 201003_02
hgs
parents:
diff changeset
    71
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
    72
    iMmcList.Reset();
7feec50967db 201003_02
hgs
parents:
diff changeset
    73
    TUint att;
7feec50967db 201003_02
hgs
parents:
diff changeset
    74
    if( KErrNotFound != aFs.Att( aFname, att ) )
7feec50967db 201003_02
hgs
parents:
diff changeset
    75
        {
7feec50967db 201003_02
hgs
parents:
diff changeset
    76
        RFileReadStream stream;
7feec50967db 201003_02
hgs
parents:
diff changeset
    77
        CleanupClosePushL( stream );
7feec50967db 201003_02
hgs
parents:
diff changeset
    78
        User::LeaveIfError( stream.Open( aFs, aFname, EFileStream
7feec50967db 201003_02
hgs
parents:
diff changeset
    79
                | EFileShareReadersOnly ) );
7feec50967db 201003_02
hgs
parents:
diff changeset
    80
        TInt len = Min( KCaMmcHistoryLength, stream.ReadInt32L() );
7feec50967db 201003_02
hgs
parents:
diff changeset
    81
        while( len-- )
7feec50967db 201003_02
hgs
parents:
diff changeset
    82
            {
7feec50967db 201003_02
hgs
parents:
diff changeset
    83
            iMmcList.AppendL( stream.ReadUint32L() );
7feec50967db 201003_02
hgs
parents:
diff changeset
    84
            }
7feec50967db 201003_02
hgs
parents:
diff changeset
    85
        CleanupStack::PopAndDestroy( &stream );
7feec50967db 201003_02
hgs
parents:
diff changeset
    86
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
    87
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
    88
7feec50967db 201003_02
hgs
parents:
diff changeset
    89
// ---------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
    90
// CMenuSrvMmcHistory::SaveL
7feec50967db 201003_02
hgs
parents:
diff changeset
    91
// Method do not work if there is no free space on C drive.
7feec50967db 201003_02
hgs
parents:
diff changeset
    92
// ---------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
    93
//
7feec50967db 201003_02
hgs
parents:
diff changeset
    94
EXPORT_C void CCaSrvMmcHistory::SaveL( RFs& aFs, const TDesC& aFname )
7feec50967db 201003_02
hgs
parents:
diff changeset
    95
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
    96
    if( SysUtil::DiskSpaceBelowCriticalLevelL( &aFs, 0, EDriveC ) )
7feec50967db 201003_02
hgs
parents:
diff changeset
    97
        {
7feec50967db 201003_02
hgs
parents:
diff changeset
    98
        return;
7feec50967db 201003_02
hgs
parents:
diff changeset
    99
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
   100
7feec50967db 201003_02
hgs
parents:
diff changeset
   101
    RFileWriteStream stream;
7feec50967db 201003_02
hgs
parents:
diff changeset
   102
    CleanupClosePushL( stream );
7feec50967db 201003_02
hgs
parents:
diff changeset
   103
    User::LeaveIfError( stream.Replace( aFs, aFname, EFileStream
7feec50967db 201003_02
hgs
parents:
diff changeset
   104
            | EFileShareExclusive ) );
7feec50967db 201003_02
hgs
parents:
diff changeset
   105
    stream.WriteInt32L( iMmcList.Count() );
7feec50967db 201003_02
hgs
parents:
diff changeset
   106
    for( TInt i = 0; i < iMmcList.Count(); i++ )
7feec50967db 201003_02
hgs
parents:
diff changeset
   107
        {
7feec50967db 201003_02
hgs
parents:
diff changeset
   108
        stream.WriteUint32L( iMmcList[i] );
7feec50967db 201003_02
hgs
parents:
diff changeset
   109
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
   110
    CleanupStack::PopAndDestroy( &stream );
7feec50967db 201003_02
hgs
parents:
diff changeset
   111
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   112
7feec50967db 201003_02
hgs
parents:
diff changeset
   113
// ---------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   114
// CMenuSrvMmcHistory::InsertL
7feec50967db 201003_02
hgs
parents:
diff changeset
   115
// ---------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   116
//
7feec50967db 201003_02
hgs
parents:
diff changeset
   117
EXPORT_C void CCaSrvMmcHistory::InsertL( TUint aMmc )
7feec50967db 201003_02
hgs
parents:
diff changeset
   118
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
   119
    TInt i = iMmcList.Find( aMmc );
7feec50967db 201003_02
hgs
parents:
diff changeset
   120
    switch( i )
7feec50967db 201003_02
hgs
parents:
diff changeset
   121
        {
7feec50967db 201003_02
hgs
parents:
diff changeset
   122
        case 0:
7feec50967db 201003_02
hgs
parents:
diff changeset
   123
            {
7feec50967db 201003_02
hgs
parents:
diff changeset
   124
            // aMmc is already first, do nothing.
7feec50967db 201003_02
hgs
parents:
diff changeset
   125
            break;
7feec50967db 201003_02
hgs
parents:
diff changeset
   126
            }
7feec50967db 201003_02
hgs
parents:
diff changeset
   127
7feec50967db 201003_02
hgs
parents:
diff changeset
   128
        case KErrNotFound:
7feec50967db 201003_02
hgs
parents:
diff changeset
   129
            {
7feec50967db 201003_02
hgs
parents:
diff changeset
   130
            // aMmc is not in the list. Insert as first.
7feec50967db 201003_02
hgs
parents:
diff changeset
   131
            if( iMmcList.Count() == KCaMmcHistoryLength )
7feec50967db 201003_02
hgs
parents:
diff changeset
   132
                {
7feec50967db 201003_02
hgs
parents:
diff changeset
   133
                // List already full - remove last item to make space.
7feec50967db 201003_02
hgs
parents:
diff changeset
   134
                iMmcList.Remove( KCaMmcHistoryLength - 1 );
7feec50967db 201003_02
hgs
parents:
diff changeset
   135
                }
7feec50967db 201003_02
hgs
parents:
diff changeset
   136
            iMmcList.InsertL( aMmc, 0 );
7feec50967db 201003_02
hgs
parents:
diff changeset
   137
            break;
7feec50967db 201003_02
hgs
parents:
diff changeset
   138
            }
7feec50967db 201003_02
hgs
parents:
diff changeset
   139
7feec50967db 201003_02
hgs
parents:
diff changeset
   140
        default:
7feec50967db 201003_02
hgs
parents:
diff changeset
   141
            {
7feec50967db 201003_02
hgs
parents:
diff changeset
   142
            // aMmc is in the list, but not first. Move to first place.
7feec50967db 201003_02
hgs
parents:
diff changeset
   143
            iMmcList.Remove( i );
7feec50967db 201003_02
hgs
parents:
diff changeset
   144
            iMmcList.InsertL( aMmc, 0 );
7feec50967db 201003_02
hgs
parents:
diff changeset
   145
            break;
7feec50967db 201003_02
hgs
parents:
diff changeset
   146
            }
7feec50967db 201003_02
hgs
parents:
diff changeset
   147
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
   148
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   149
7feec50967db 201003_02
hgs
parents:
diff changeset
   150
// ---------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   151
// CMenuSrvMmcHistory::Find
7feec50967db 201003_02
hgs
parents:
diff changeset
   152
// ---------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   153
//
7feec50967db 201003_02
hgs
parents:
diff changeset
   154
EXPORT_C TInt CCaSrvMmcHistory::Find( TUint aMmc )
7feec50967db 201003_02
hgs
parents:
diff changeset
   155
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
   156
    return iMmcList.Find( aMmc );
7feec50967db 201003_02
hgs
parents:
diff changeset
   157
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   158
7feec50967db 201003_02
hgs
parents:
diff changeset
   159
//  End of File