brandingserver/tools/bsimport/src/cbsimportstoragemanager.cpp
changeset 0 e6b17d312c8b
child 21 cfd5c2994f10
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     1 /*
       
     2 * Copyright (c) 2006-2006 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 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Stores element data and writes it to stream
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <s32strm.h>
       
    20 #include <s32file.h>
       
    21 #include <f32file.h>
       
    22 #include <bautils.h>
       
    23 #include <cbsfactory.h>
       
    24 #include <mbsupdater.h>
       
    25 
       
    26 #include "cbsimportstoragemanager.h"
       
    27 #include "cbsimportstorage.h"
       
    28 #include "importlogwriter.h"
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // CBSImportStorageManager::NewL
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CBSImportStorageManager* CBSImportStorageManager::NewL()
       
    37     {
       
    38     CBSImportStorageManager* self = NewLC();
       
    39     CleanupStack::Pop();
       
    40     return self;
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CBSImportStorageManager::NewLC
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CBSImportStorageManager* CBSImportStorageManager::NewLC()
       
    48     {
       
    49     CBSImportStorageManager* self = 
       
    50         new (ELeave) CBSImportStorageManager();
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     return self;
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CBSImportStorageManager::ConstructL
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 void CBSImportStorageManager::ConstructL()
       
    61     {
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CBSImportStorageManager::CBSImportStorageManager
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CBSImportStorageManager::CBSImportStorageManager() : 
       
    69     iCurrent( KErrNotFound )
       
    70     {
       
    71     }
       
    72     
       
    73 // ---------------------------------------------------------------------------
       
    74 // CBSImportStorageManager::~CBSImportStorageManager
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CBSImportStorageManager::~CBSImportStorageManager()
       
    78     {
       
    79     iStorages.ResetAndDestroy();
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CBSImportStorageManager::CreateStorageL
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CBSImportStorageManager::CreateStorageL()
       
    87     {
       
    88     CBSImportStorage* tmp = CBSImportStorage::NewL();
       
    89     iStorages.Append( tmp );
       
    90     iCurrent = iStorages.Find( tmp );
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CBSImportStorageManager::StorageCount
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 TInt CBSImportStorageManager::StorageCount()
       
    98     {
       
    99     return iStorages.Count();
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CBSImportStorageManager::Storage
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 CBSImportStorage* CBSImportStorageManager::Storage( TInt aIndex )
       
   107     {
       
   108     return iStorages[ aIndex ];
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CBSImportStorageManager::Storage
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 CBSImportStorage* CBSImportStorageManager::Storage()
       
   116     {
       
   117     return iStorages[ iCurrent ];
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CBSImportStorageManager::WriteDataToServerL
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 void CBSImportStorageManager::WriteDataToServerL()
       
   125     {
       
   126     // Merge storages
       
   127     MergeStorages();
       
   128     
       
   129     // Flush each storage
       
   130     TInt count = iStorages.Count();
       
   131     for( TInt i = 0; i < count; i++ )
       
   132         {
       
   133         iStorages[i]->FlushToServerL();
       
   134         }
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // CBSImportStorageManager::MergeStoragesL
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CBSImportStorageManager::MergeStorages()
       
   142     {
       
   143     for( TInt i = 0; i < iStorages.Count(); i++ )
       
   144         {
       
   145         for( TInt j = i + 1; j < iStorages.Count(); j++ )
       
   146             {
       
   147             if( iStorages[i]->Compare( iStorages[j] ) )
       
   148                 {
       
   149                 // they have same header data -> merge them
       
   150                 iStorages[i]->TakeElements( iStorages[j] );
       
   151                 delete iStorages[j];
       
   152                 iStorages.Remove( j );
       
   153                 j--; // correct index
       
   154                 }
       
   155             }
       
   156         }
       
   157     }
       
   158 
       
   159 // End of file