applicationmanagement/server/src/amstorage.cpp
author hgs
Fri, 17 Sep 2010 19:58:05 +0530
changeset 62 03849bd79877
parent 47 d316aecb87fd
child 67 fdbfe0a95492
permissions -rw-r--r--
201037
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47
d316aecb87fd 201025_02
hgs
parents:
diff changeset
     1
/*
d316aecb87fd 201025_02
hgs
parents:
diff changeset
     2
 * Copyright (c) 2000 Nokia Corporation and/or its subsidiary(-ies). 
d316aecb87fd 201025_02
hgs
parents:
diff changeset
     3
 * All rights reserved.
d316aecb87fd 201025_02
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
d316aecb87fd 201025_02
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
d316aecb87fd 201025_02
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
d316aecb87fd 201025_02
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
d316aecb87fd 201025_02
hgs
parents:
diff changeset
     8
 *
d316aecb87fd 201025_02
hgs
parents:
diff changeset
     9
 * Initial Contributors:
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    11
 *
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    12
 * Contributors:
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    13
 *
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    14
 * Description: Implementation of applicationmanagement components
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    15
 *
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    16
 */
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    17
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    18
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    19
#include <centralrepository.h>
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    20
#include <s32mem.h>
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    21
#include <s32file.h>
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    22
#include <e32des8.h>
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    23
#ifndef __SERIES60_30__
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    24
#include "AMAppHideUtil.h"
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    25
#endif
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    26
#include "debug.h"
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    27
#include "amprivateCRKeys.h"
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    28
#include "amstorage.h"
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    29
#include "AMDeploymentComponent.h"
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    30
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    31
using namespace NApplicationManagement;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    32
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    33
// CONSTANTS
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    34
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    35
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    36
/***************************************************
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    37
 // RComponentIdArray
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    38
 ***************************************************/
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    39
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    40
void RComponentIdArray::SetListL(const TDesC8& aChilds)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    41
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    42
#ifdef _DEBUG
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    43
    HBufC *b = HBufC::NewLC(aChilds.Length() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    44
    TPtr p(b->Des() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    45
    p.Copy(aChilds);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    46
    RDEBUG_2( "RComponentIdArray::SetListL: Setting list from: '%S'", &p);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    47
    CleanupStack::PopAndDestroy(b);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    48
#endif
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    49
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    50
    RDesReadStream buf(aChilds);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    51
    //TInt size( buf.Source()->TellL( MStreamBuf::ERead ).SizeL() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    52
    TInt left(aChilds.Length() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    53
    const TInt KSize(sizeof(TUint32));
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    54
    while (left > 0)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    55
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    56
        TUint32 val(buf.ReadUint32L() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    57
#ifdef _DEBUG
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    58
        RDEBUG_2( "RComponentIdArray::SetListL: Appending id: '%d'", val);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    59
#endif
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    60
        Append(val);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    61
        left -= KSize;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    62
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    63
    buf.Close();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    64
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    65
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    66
void RComponentIdArray::RemoveByValue(TUint32 aValue)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    67
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    68
    TInt ind(Find(aValue) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    69
    Remove(ind);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    70
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    71
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    72
void RComponentIdArray::GetListLC(HBufC8 *&aChilds, TInt &aLength)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    73
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    74
    ASSERT( aChilds == NULL );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    75
    TInt c(Count() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    76
    if (c > 0)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    77
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    78
        aLength = c * sizeof(TUint32);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    79
        aChilds = HBufC8::NewLC(aLength);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    80
        TPtr8 p(aChilds->Des() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    81
        RDesWriteStream stream(p);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    82
        CleanupClosePushL(stream);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    83
        TInt i( 0);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    84
        do
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    85
            {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    86
            stream.WriteUint32L(operator[](i) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    87
            }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    88
        while ( ++i < c);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    89
        stream.CommitL();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    90
        CleanupStack::PopAndDestroy( &stream);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    91
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    92
    else
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    93
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    94
        aChilds = KNullDesC8().AllocLC();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    95
        aLength = 0;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    96
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    97
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    98
d316aecb87fd 201025_02
hgs
parents:
diff changeset
    99
/*	
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   100
 void TCertInfoPckg::ExternalizeL(RWriteStream& aStream) const
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   101
 {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   102
 aStream << iId;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   103
 TPckgBuf<TCertInfo>::ExternalizeL( aStream );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   104
 }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   105
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   106
 void TCertInfoPckg::InternalizeL(RReadStream& aStream)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   107
 {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   108
 
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   109
 }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   110
 */
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   111
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   112
void RCertArray::ExternalizeL(RWriteStream& aStream) const
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   113
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   114
    TInt c(Count() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   115
    aStream.WriteInt32L(c);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   116
    for (TInt i( 0); i < c; i++)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   117
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   118
        aStream.WriteInt32L(i);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   119
        aStream << (*(operator[](i)));
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   120
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   121
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   122
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   123
void RCertArray::InternalizeL(RReadStream& aStream)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   124
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   125
    TInt c(aStream.ReadInt32L() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   126
    for (TInt i( 0); i < c; i++)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   127
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   128
        TCertInfoPckg *pkg = new ( ELeave ) TCertInfoPckg;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   129
        RDEBUG_2( "RCertArray::InternalizeL - allocated TCertInfoPckg 0x%X", reinterpret_cast<TUint>( pkg ) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   130
        CleanupStack::PushL(pkg);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   131
        TInt idx(aStream.ReadInt32L() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   132
        aStream >> (*pkg);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   133
        Append(pkg);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   134
        CleanupStack::Pop(pkg);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   135
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   136
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   137
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   138
TInt RCertArray::FindByValue(const TCertInfoPckg &aPckg)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   139
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   140
    TInt c(Count() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   141
    for (TInt i( 0); i < c; i++)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   142
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   143
        if (operator[](i)->Compare(aPckg) == 0)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   144
            {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   145
            return i;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   146
            }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   147
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   148
    return KErrNotFound;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   149
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   150
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   151
/***************************************************
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   152
 // CDeliveryComponentStorage
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   153
 ***************************************************/
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   154
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   155
CDeliveryComponentStorage::CDeliveryComponentStorage()
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   156
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   157
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   158
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   159
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   160
void CDeliveryComponentStorage::ConstructL()
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   161
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   162
#ifndef __SERIES60_30__
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   163
    iHidder = CAMAppHideUtil::NewL();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   164
#endif
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   165
    LoadCertsL();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   166
    TRAPD( erx, iRepository = CRepository::NewL ( KCRUidPrivateApplicationManagementKeys ) )
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   167
    ;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   168
    if (erx != KErrNone)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   169
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   170
        RDEBUG_2( "CDeliveryComponentStorage::ConstructL() ERROR CentRep not initialized: Check deployment! %d", erx );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   171
        User::Leave(erx);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   172
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   173
    TInt err(iRepository->Get(KNextIdKey, iNextId) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   174
    if (err == KErrNotFound)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   175
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   176
        iNextId = KMinIdValue;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   177
        User::LeaveIfError(iRepository->Create(KNextIdKey, iNextId) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   178
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   179
    else
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   180
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   181
        User::LeaveIfError(err);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   182
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   183
    LoadComponentsL();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   184
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   185
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   186
void CDeliveryComponentStorage::LoadCertsL()
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   187
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   188
    RFs fs;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   189
    User::LeaveIfError(fs.Connect() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   190
    CleanupClosePushL(fs);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   191
    TInt e(fs.CreatePrivatePath(KDefaultDrive) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   192
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   193
    User::LeaveIfError(e);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   194
    TBuf<64> privatePath;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   195
    User::LeaveIfError(fs.PrivatePath(privatePath) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   196
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   197
    TInt privPathLength(privatePath.Length() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   198
    _LIT( KCertFile, "amcerts.dat");
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   199
    HBufC *afile = HBufC::NewLC(privPathLength + KCertFile().Length());
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   200
    *afile = privatePath;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   201
    afile->Des().Append(KCertFile);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   202
    RFileReadStream certFile;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   203
    TInt err(certFile.Open(fs, *afile, EFileRead) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   204
    if (err == KErrNone)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   205
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   206
        CleanupClosePushL(certFile);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   207
        iCertificates.InternalizeL(certFile);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   208
        CleanupStack::PopAndDestroy( &certFile);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   209
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   210
    else
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   211
        if (err == KErrNotFound)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   212
            {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   213
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   214
            }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   215
        else
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   216
            {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   217
            User::Leave(err);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   218
            }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   219
    CleanupStack::PopAndDestroy(afile);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   220
    CleanupStack::PopAndDestroy( &fs);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   221
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   222
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   223
CDeliveryComponentStorage* CDeliveryComponentStorage::NewLC()
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   224
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   225
    CDeliveryComponentStorage *self = new ( ELeave ) CDeliveryComponentStorage( );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   226
    CleanupStack::PushL(self) ;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   227
    self->ConstructL() ;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   228
    return self;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   229
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   230
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   231
CDeliveryComponentStorage* CDeliveryComponentStorage::NewL()
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   232
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   233
    CDeliveryComponentStorage *self = NewLC();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   234
    CleanupStack::Pop(self) ;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   235
    return self;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   236
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   237
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   238
TInt CDeliveryComponentStorage::NextKey()
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   239
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   240
    TInt oldNext(iNextId++);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   241
    iRepository->Set(KNextIdKey, iNextId);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   242
    return oldNext;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   243
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   244
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   245
CDeliveryComponentStorage::~CDeliveryComponentStorage()
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   246
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   247
    RDEBUG_3( "CDeliveryComponentStorage::~CDeliveryComponentStorage 0x%X - 0x%X", reinterpret_cast<TUint>(this),
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   248
            reinterpret_cast<TUint>(this)+sizeof( CDeliveryComponentStorage ) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   249
    delete iRepository;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   250
    iRepository = NULL;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   251
    iComponents.ResetAndDestroy();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   252
    iComponentIds.Close();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   253
    TRAPD( err,CloseCertificatesL() )
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   254
    ;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   255
    if (err != KErrNone)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   256
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   257
        RDEBUG_2( "CDeliveryComponentStorage::~CDeliveryComponentStorage: ERROR Failed to close certificate storage properly: %d", err);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   258
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   259
#ifndef __SERIES60_30__
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   260
    delete iHidder;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   261
    iHidder = NULL;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   262
#endif
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   263
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   264
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   265
void CDeliveryComponentStorage::CloseCertificatesL()
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   266
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   267
    RFs fs;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   268
    User::LeaveIfError(fs.Connect() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   269
    CleanupClosePushL(fs);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   270
    TInt e(fs.CreatePrivatePath(KDefaultDrive) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   271
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   272
    User::LeaveIfError(e);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   273
    TBuf<64> privatePath;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   274
    User::LeaveIfError(fs.PrivatePath(privatePath) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   275
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   276
    TInt privPathLength(privatePath.Length() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   277
    _LIT( KCertFile, "amcerts.dat");
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   278
    HBufC *afile = HBufC::NewLC(privPathLength + KCertFile().Length());
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   279
    *afile = privatePath;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   280
    afile->Des().Append(KCertFile);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   281
    RFileWriteStream certFile;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   282
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   283
    TInt err(certFile.Replace(fs, *afile, EFileWrite) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   284
    if (err == KErrNone)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   285
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   286
        CleanupClosePushL(certFile);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   287
        iCertificates.ExternalizeL(certFile);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   288
        CleanupStack::PopAndDestroy( &certFile);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   289
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   290
    else
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   291
        if (err == KErrNotFound)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   292
            {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   293
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   294
            }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   295
        else
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   296
            {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   297
            User::Leave(err);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   298
            }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   299
    CleanupStack::PopAndDestroy(afile);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   300
    CleanupStack::PopAndDestroy( &fs);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   301
    iCertificates.ResetAndDestroy();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   302
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   303
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   304
const RComponentIdArray &CDeliveryComponentStorage::GetComponentIds() const
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   305
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   306
    return iComponentIds;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   307
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   308
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   309
void CDeliveryComponentStorage::GetStateChangeComponentIdsL(
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   310
        RComponentIdArray &aArray)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   311
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   312
    RDEBUG_2( "CDeliveryComponentStorage::GetStateChangeComponentIdsL %d dcs", iComponentIds.Count());
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   313
    aArray.Reset();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   314
    TInt c(iComponentIds.Count() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   315
    for (TInt i( 0); i < c; i++)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   316
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   317
        CDeploymentComponent &compo = ComponentL(iComponentIds[i]);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   318
        if (compo.OldState() != EDCSNone)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   319
            {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   320
            aArray.Append(iComponentIds[i]);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   321
            }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   322
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   323
    RDEBUG( "CDeliveryComponentStorage::GetStateChangeComponentIdsL end");
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   324
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   325
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   326
void CDeliveryComponentStorage::StateChangedL(TUint32 aInternalId)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   327
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   328
    RDEBUG_2( "CDeliveryComponentStorage::StateChangedL id %d", aInternalId);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   329
    CDeploymentComponent &compo = ComponentL(aInternalId);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   330
    compo.StateChangeComplete();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   331
    UpdateL(compo);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   332
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   333
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   334
void CDeliveryComponentStorage::LoadComponentsL()
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   335
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   336
    TInt length( 0);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   337
    TInt err(iRepository->Get(KIdListLengthKey, length) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   338
    if (err == KErrNotFound)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   339
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   340
        length = 0;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   341
        User::LeaveIfError(iRepository->Create(KIdListLengthKey, length) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   342
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   343
    else
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   344
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   345
        User::LeaveIfError(err);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   346
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   347
    HBufC8 *listbuf = HBufC8::NewLC(length) ;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   348
    TPtr8 ptr(listbuf->Des() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   349
    err = iRepository->Get(KIdListKey, ptr) ;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   350
    if (err == KErrNotFound)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   351
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   352
        err = iRepository->Create(KIdListKey, KNullDesC8);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   353
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   354
    else
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   355
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   356
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   357
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   358
    User::LeaveIfError(err);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   359
    TRAPD(code, iComponentIds.SetListL( ptr ))
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   360
    ;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   361
    if (code != KErrEof)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   362
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   363
        User::LeaveIfError(code);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   364
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   365
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   366
    CleanupStack::PopAndDestroy(listbuf);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   367
#ifndef __SERIES60_30__
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   368
    TInt i(iComponentIds.Count() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   369
    //iHidder->Reset();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   370
    while ( --i >= 0)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   371
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   372
        CDeploymentComponent &comp = ComponentL(iComponentIds[i]);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   373
        if (comp.State() == EDCSInactive)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   374
            {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   375
            iHidder->AddUidL(comp.Uid());
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   376
            }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   377
        else
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   378
            if (comp.State() == EDCSActive)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   379
                {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   380
                iHidder->RemoveUidL(comp.Uid() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   381
                }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   382
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   383
    iHidder->PersistUidsL();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   384
#endif
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   385
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   386
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   387
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   388
CDeploymentComponent *CDeliveryComponentStorage::NewComponentL(
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   389
        const TDeploymentComponentState &aState, const TDCUserId &aUserId,
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   390
        const TCertInfo *aCertInfo/* = NULL */)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   391
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   392
    CDeploymentComponent *newc = CDeploymentComponent::NewLC(NextKey(),
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   393
            aUserId);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   394
    if (aCertInfo != NULL)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   395
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   396
        TCertInfoPckg *p = new( ELeave ) TCertInfoPckg(*aCertInfo);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   397
        RDEBUG_2( "CDeliveryComponentStorage::NewComponentL - allocated TCertInfoPckg 0x%X", reinterpret_cast<TUint>( p ) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   398
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   399
        TInt idx(iCertificates.FindByValue(*p) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   400
        if (idx == KErrNotFound)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   401
            {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   402
            RDEBUG_2( "CDeliveryComponentStorage::NewComponentL - TCertInfoPckg NOT found 0x%X", reinterpret_cast<TUint>( p ) );
62
hgs
parents: 47
diff changeset
   403
            TRAPD(err,iCertificates.AppendL(p));
hgs
parents: 47
diff changeset
   404
            if(err != KErrNone)
hgs
parents: 47
diff changeset
   405
                {
hgs
parents: 47
diff changeset
   406
                delete p;
hgs
parents: 47
diff changeset
   407
                p = NULL;
hgs
parents: 47
diff changeset
   408
				User::Leave( err );
hgs
parents: 47
diff changeset
   409
                }
hgs
parents: 47
diff changeset
   410
            else
hgs
parents: 47
diff changeset
   411
                {
hgs
parents: 47
diff changeset
   412
                idx = iCertificates.Count() - 1;
hgs
parents: 47
diff changeset
   413
                }
47
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   414
            }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   415
        else
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   416
            {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   417
            RDEBUG_2( "CDeliveryComponentStorage::NewComponentL - TCertInfoPckg found at %d, deleting temporary", idx );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   418
            delete p;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   419
            p = NULL;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   420
            }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   421
        if (idx >= 0)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   422
            {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   423
            RDEBUG_2( "CDeliveryComponentStorage::NewComponentL - TCertInfoPckg found 0x%X", reinterpret_cast<TUint>( p ) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   424
            newc->SetOwner(idx);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   425
            }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   426
        else
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   427
            {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   428
            RDEBUG_3( "CDeliveryComponentStorage::NewComponentL - WARNING Could not add certificate 0x%X: %d", reinterpret_cast<TUint>( p ), idx );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   429
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   430
            }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   431
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   432
    newc->SetState(aState);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   433
    newc->SetStatusNode(EIdle);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   434
    UpdateL( *newc);
62
hgs
parents: 47
diff changeset
   435
    iComponents.AppendL(newc);
hgs
parents: 47
diff changeset
   436
    iComponentIds.AppendL(newc->InternalId() );
47
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   437
RDEBUG_2( "CDeliveryComponentStorage::NewComponentL -Internal ID is  %d, ", newc->InternalId() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   438
    PersistStateL();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   439
    CleanupStack::Pop(newc);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   440
    return newc;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   441
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   442
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   443
void CDeliveryComponentStorage::UpdateL(
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   444
        const CDeploymentComponent &aComponent)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   445
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   446
    aComponent.PersistL( *iRepository) ;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   447
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   448
#ifndef __SERIES60_30__
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   449
    if (aComponent.State() == EDCSInactive)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   450
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   451
        iHidder->AddUidL(aComponent.Uid(), ETrue);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   452
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   453
    else
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   454
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   455
        iHidder->RemoveUidL(aComponent.Uid(), ETrue);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   456
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   457
#endif
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   458
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   459
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   460
void CDeliveryComponentStorage::PersistStateL()
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   461
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   462
    TInt length( 0);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   463
    HBufC8 *buf= NULL;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   464
    iComponentIds.GetListLC(buf, length);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   465
    User::LeaveIfError(iRepository->Set(KIdListLengthKey, length) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   466
    User::LeaveIfError(iRepository->Set(KIdListKey, *buf) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   467
    CleanupStack::PopAndDestroy(buf);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   468
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   469
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   470
void CDeliveryComponentStorage::RemoveL(TUint32 aInternalId)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   471
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   472
    RDEBUG_2("CDeliveryComponentStorage::RemoveL - Remove id: (%d)", aInternalId );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   473
    TInt count(iComponents.Count() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   474
    for (TInt i( 0); i < count; i++)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   475
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   476
        CDeploymentComponent *el = iComponents[i];
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   477
        if (aInternalId == el->iInternalId)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   478
            {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   479
#ifndef __SERIES60_30__
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   480
            iHidder->RemoveUidL(el->Uid(), ETrue);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   481
#endif
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   482
            iComponents.Remove(i);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   483
            iComponentIds.RemoveByValue(aInternalId);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   484
            el->DestroyL( *iRepository);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   485
            delete el;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   486
            RDEBUG_2("CDeliveryComponentStorage::RemoveL - Removed id: (%d)", aInternalId );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   487
            PersistStateL();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   488
            break;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   489
            }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   490
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   491
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   492
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   493
CDeploymentComponent &CDeliveryComponentStorage::ComponentL(
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   494
        TUint32 aInternalId)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   495
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   496
    CDeploymentComponent *resp= NULL;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   497
    TInt count(iComponents.Count() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   498
    for (TInt i( 0); i < count; i++)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   499
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   500
        CDeploymentComponent *el = iComponents[i];
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   501
        if (aInternalId == el->iInternalId)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   502
            {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   503
            resp = el;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   504
            break;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   505
            }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   506
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   507
    if (resp == NULL)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   508
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   509
        TBuf8< NCentralRepositoryConstants::KMaxBinaryLength> buf;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   510
        TInt err(iRepository->Get(aInternalId, buf) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   511
        User::LeaveIfError(err) ;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   512
        resp = LoadComponentL(aInternalId, buf) ;
62
hgs
parents: 47
diff changeset
   513
        iComponents.AppendL(resp);
47
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   514
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   515
    if (resp == NULL)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   516
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   517
        User::Leave(KErrNotFound);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   518
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   519
    return *resp;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   520
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   521
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   522
CDeploymentComponent *CDeliveryComponentStorage::LoadComponentL(
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   523
        TInt aInternalId, const TDesC8 &aBuffer) const
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   524
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   525
    CDeploymentComponent *res = CDeploymentComponent::LoadL(aInternalId,
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   526
            aBuffer);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   527
#ifdef _DEBUG
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   528
    if (res)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   529
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   530
        RDEBUG8_4( "CDeliveryComponentStorage::LoadComponentL - loaded component state %d, internalid %d, and userid: %S", res->State(), res->InternalId(),&res->UserId() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   531
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   532
    else
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   533
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   534
        RDEBUG( "CDeliveryComponentStorage::LoadComponentL - WARNING failed to load component" );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   535
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   536
#endif
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   537
    return res;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   538
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   539
void CDeliveryComponentStorage::CheckForDuplicateNodesInDeployedL(
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   540
        CDeploymentComponent &aComponent)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   541
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   542
    TInt CompIdsCount(iComponentIds.Count() );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   543
    RDEBUG8_2("CheckForDuplicateNodesInDeployedL: CompIdsCount-> (%d)", CompIdsCount );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   544
    RDEBUG8_2("CheckForDuplicateNodesInDeployedL: aComponent UserID is %S", &(aComponent.UserId()));
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   545
    for (TInt i( 0); i < CompIdsCount; i++)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   546
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   547
        CDeploymentComponent &compo = ComponentL(iComponentIds[i]);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   548
        RDEBUG8_2("CheckForDuplicateNodesInDeployedL: compo UserID is %S", &(compo.UserId()));
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   549
        if (&aComponent != &compo)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   550
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   551
        if (((compo.State()== EDCSActive) || (compo.State()== EDCSInactive))
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   552
                &&(compo.UserId() == aComponent.UserId()))
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   553
            {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   554
            (aComponent.iUserId).Append(*IntToDes8LC(aComponent.iInternalId));
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   555
            CleanupStack::PopAndDestroy();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   556
            break;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   557
            }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   558
          }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   559
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   560
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   561
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   562
HBufC8* CDeliveryComponentStorage::IntToDes8LC(const TInt aLuid)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   563
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   564
    HBufC8* buf = HBufC8::NewLC( 10); //10 = max length of 32bit integer
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   565
    TPtr8 ptrBuf = buf->Des();
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   566
    ptrBuf.Num(aLuid);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   567
    return buf;
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   568
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   569
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   570
void CDeliveryComponentStorage::InstalledL(CDeploymentComponent &aComponent)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   571
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   572
    CheckForDuplicateNodesInDeployedL(aComponent);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   573
    aComponent.SetState(EDCSActive);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   574
    // set state to IDLE 
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   575
    aComponent.SetStatusNode(EIdle);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   576
    UpdateL(aComponent);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   577
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   578
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   579
void CDeliveryComponentStorage::DeactivateL(CDeploymentComponent &aComponent)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   580
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   581
    /* :
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   582
     * set state to InActivate in progress
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   583
     * use TRAP instead of leaving.
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   584
     */
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   585
    aComponent.SetStatusNode(EDeployed_DeactivateProgress);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   586
    //User::LeaveIfError(aComponent.SetState(EDCSInactive) );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   587
    TInt err = aComponent.SetState(EDCSInactive);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   588
    if (err == KErrNone)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   589
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   590
        TRAP(err,UpdateL(aComponent));
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   591
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   592
    //UpdateL(aComponent);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   593
    /*:
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   594
     * if error set state to InActivate failed or else set to Idle
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   595
     * call userleaveiferror()
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   596
     */
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   597
    if (err == KErrNone)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   598
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   599
        aComponent.SetStatusNode(EIdle);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   600
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   601
    else
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   602
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   603
        aComponent.SetStatusNode(EDeployed_DeactivateFailed);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   604
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   605
    User::LeaveIfError(err);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   606
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   607
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   608
void CDeliveryComponentStorage::SetDeploymentComponentState(CDeploymentComponent &aComponent,TDeploymentComponentState aState)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   609
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   610
    aComponent.SetState( aState );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   611
    TRAP_IGNORE(UpdateL( aComponent ));    
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   612
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   613
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   614
void CDeliveryComponentStorage::ActivateL(CDeploymentComponent &aComponent)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   615
    {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   616
    /* :
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   617
     * set state to Activate in progress
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   618
     * use TRAP instead of leaving.
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   619
     */
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   620
    aComponent.SetStatusNode(EDeployed_ActivateProgress);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   621
    TInt err = aComponent.SetState(EDCSActive);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   622
    //UpdateL( aComponent );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   623
    if (err == KErrNone)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   624
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   625
        TRAP(err,UpdateL(aComponent));
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   626
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   627
    /*:
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   628
     * if error set state to InActivate failed or else set to Idle
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   629
     * call userleaveiferror()
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   630
     */
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   631
    if (err == KErrNone)
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   632
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   633
        aComponent.SetStatusNode(EIdle);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   634
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   635
    else
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   636
        {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   637
        aComponent.SetStatusNode(EDeployed_ActivateFailed);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   638
        }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   639
    User::LeaveIfError(err);
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   640
    }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   641
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   642
/*void CDeliveryComponentStorage::UninstalledL( CDeploymentComponent &aComponent )
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   643
 {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   644
 aComponent.SetState( EDCSInactive );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   645
 UpdateL( aComponent );
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   646
 }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   647
 
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   648
 void CDeliveryComponentStorage::ResetL()
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   649
 {
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   650
 }
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   651
 */
d316aecb87fd 201025_02
hgs
parents:
diff changeset
   652
//  End of File