PECengine/StorageManager2/ClientSrc/CPEngStoreEntry.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Store entry abstract class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <e32std.h>
       
    22 #include    "CPEngStoreEntry.h"
       
    23 #include	"MPEngStorageManagerWatcher.h"
       
    24 #include	"MPEngStorageManager.h"
       
    25 #include	"PEngStorageGlobals.h"
       
    26 
       
    27 //	Debug prints
       
    28 #include	"PresenceDebugPrint.h"
       
    29 
       
    30 
       
    31 // ============================= LOCAL CLASS DEFINITION ======================
       
    32 
       
    33 // CLASS DEFINITION
       
    34 NONSHARABLE_CLASS( TPEngSIdsDesWraper ):
       
    35         public MDesCArray
       
    36     {
       
    37 public:
       
    38     inline TPEngSIdsDesWraper( const TDesC& aSid )
       
    39             : iSid( aSid )
       
    40         {
       
    41         }
       
    42 public: // from MDesC16Array
       
    43     inline TInt MdcaCount() const
       
    44         {
       
    45         // we have only one Sid
       
    46         return 1;
       
    47         }
       
    48 
       
    49     inline TPtrC16 MdcaPoint( TInt aIndex ) const
       
    50         {
       
    51         // panic is index is out of 0
       
    52         __ASSERT_DEBUG( aIndex == 0, User::Panic(
       
    53                             KPEngSMPanic,
       
    54                             EPEngSM_StoreManNotDefined ) );
       
    55         ( void ) aIndex; // Prevent compilation warning about unused variable
       
    56         return iSid;
       
    57         }
       
    58 
       
    59 private: // data
       
    60     const TDesC& 			iSid;
       
    61     };
       
    62 
       
    63 // ============================ MEMBER FUNCTIONS ===============================
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CPEngStoreEntry::CPEngStoreEntry
       
    67 // C++ default constructor can NOT contain any code, that might leave.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 EXPORT_C CPEngStoreEntry::CPEngStoreEntry(
       
    71     TPEngStorageType aStorageType )
       
    72         : iStorageType( aStorageType )
       
    73     {
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CPEngStoreEntry::BaseConstructL
       
    78 // Symbian 2nd phase Base constructor can leave.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 EXPORT_C void CPEngStoreEntry::BaseConstructL()
       
    82     {
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CPEngStoreEntry::BaseConstructL
       
    87 // Symbian 2nd phase Base constructor can leave.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 EXPORT_C void CPEngStoreEntry::BaseConstructL(
       
    91     MPEngStorageManager& aStorageManager,
       
    92     TBool aRegister /* = ETrue */ )
       
    93     {
       
    94     iStorageManager = &aStorageManager;
       
    95     iStorageManager->Open();                        // CSI: 65 #
       
    96 
       
    97     if ( aRegister )
       
    98         {
       
    99         TPEngSIdsDesWraper sidWrap( this->StorageId() );
       
   100         iStorageManager->StorageManagerWatcher().RegisterListenSIDsObserverL(
       
   101             sidWrap,
       
   102             *this,
       
   103             MPEngStorageManagerWatcher::EPEngObserverInternal );
       
   104         }
       
   105     }
       
   106 
       
   107 
       
   108 // Destructor
       
   109 EXPORT_C CPEngStoreEntry::~CPEngStoreEntry()
       
   110     {
       
   111     if ( iStorageManager )
       
   112         {
       
   113         iStorageManager->StorageManagerWatcher(
       
   114         ).UnregisterListenSIDsObserver( *this );
       
   115         iStorageManager->Close();
       
   116         }
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // ==== Default implementation of functions from main class ====================
       
   121 // -----------------------------------------------------------------------------
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CPEngStoreEntry::Release
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 EXPORT_C void CPEngStoreEntry::Release()
       
   128     {
       
   129     __ASSERT_DEBUG( iStorageManager, User::Panic(
       
   130                         KPEngSMPanic,
       
   131                         EPEngSM_StoreManNotDefined ) );
       
   132     // do not check, let client crash,
       
   133     // since this should be always valid pointer
       
   134     iStorageManager->Unlock( *this );
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CPEngStoreEntry::LockLC()
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 EXPORT_C TInt CPEngStoreEntry::LockLC()
       
   142     {
       
   143     __ASSERT_DEBUG( iStorageManager, User::Panic(
       
   144                         KPEngSMPanic,
       
   145                         EPEngSM_StoreManNotDefined ) );
       
   146     TInt err( Lock() );
       
   147     CleanupReleasePushL( *this );
       
   148     return err;
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CPEngStoreEntry::Lock
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 EXPORT_C TInt CPEngStoreEntry::Lock(
       
   156     TPengStorageLockPriority aPriority
       
   157     /* EStorageLockLevelBasic */,
       
   158     TBool aCreateEntry /* = ETrue */ ) const
       
   159     {
       
   160     __ASSERT_DEBUG( iStorageManager, User::Panic(
       
   161                         KPEngSMPanic,
       
   162                         EPEngSM_StoreManNotDefined ) );
       
   163 
       
   164     // do not check, let client crash,
       
   165     // since this should be always valid pointer
       
   166     return iStorageManager->Lock( *this, aPriority, aCreateEntry );
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CPEngStoreEntry::Unlock
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 EXPORT_C TInt CPEngStoreEntry::Unlock() const
       
   174     {
       
   175     __ASSERT_DEBUG( iStorageManager, User::Panic(
       
   176                         KPEngSMPanic,
       
   177                         EPEngSM_StoreManNotDefined ) );
       
   178     // do not check, let client crash, since this should be always valid pointer
       
   179     return iStorageManager->Unlock( *this );
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CPEngStoreEntry::BufferServerSideNotifications
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 EXPORT_C TInt CPEngStoreEntry::BufferServerSideNotifications()
       
   187     {
       
   188     __ASSERT_DEBUG( iStorageManager, User::Panic(
       
   189                         KPEngSMPanic,
       
   190                         EPEngSM_StoreManNotDefined ) );
       
   191     return iStorageManager->BufferServerSideNotifications();
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CPEngStoreEntry::ReleaseServerSideBuffering
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 EXPORT_C TInt CPEngStoreEntry::ReleaseServerSideBuffering()
       
   199     {
       
   200     __ASSERT_DEBUG( iStorageManager, User::Panic(
       
   201                         KPEngSMPanic,
       
   202                         EPEngSM_StoreManNotDefined ) );
       
   203 
       
   204     return iStorageManager->ReleaseServerSideBuffering();
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CPEngStoreEntry::StoreL
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 EXPORT_C void CPEngStoreEntry::StoreL()
       
   212     {
       
   213     __ASSERT_DEBUG( iStorageManager, User::Panic(
       
   214                         KPEngSMPanic,
       
   215                         EPEngSM_StoreManNotDefined ) );
       
   216     iStorageManager->StoreL( *this );
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // ===================== Storage type support ==================================
       
   221 // -----------------------------------------------------------------------------
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CPEngStoreEntry::StorageType
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 EXPORT_C TPEngStorageType CPEngStoreEntry::StorageType() const
       
   228     {
       
   229     return iStorageType;
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CPEngStoreEntry::ChangeStorageTypeL
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 EXPORT_C void CPEngStoreEntry::ChangeStorageTypeL( TPEngStorageType aNewType )
       
   237     {
       
   238     __ASSERT_DEBUG( iStorageManager, User::Panic(
       
   239                         KPEngSMPanic,
       
   240                         EPEngSM_StoreManNotDefined ) );
       
   241     if ( iStorageType == aNewType )
       
   242         {
       
   243         return;
       
   244         }
       
   245     TInt err( iStorageManager->Delete( *this ) );
       
   246     err = err == KErrNotFound ? KErrNone : err;
       
   247     User::LeaveIfError( err );
       
   248     iStorageType = aNewType;
       
   249     // reset version counter to zero
       
   250     iEntryVersion = 0;
       
   251     iStorageManager->StoreL( *this );
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // ====  New functions of MPEngSIDChangeObserver with default implementation ===
       
   256 // -----------------------------------------------------------------------------
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CPEngStoreEntry::HandleSIDsChangeL
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 EXPORT_C void CPEngStoreEntry::HandleSIDsChangeL(
       
   263     CPtrCArray& /* aChangedSIDs */ )
       
   264     {
       
   265     // does nothing
       
   266     }
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CPEngStoreEntry::HandleSIDNotifyError
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 EXPORT_C void CPEngStoreEntry::HandleSIDNotifyError(
       
   273     TInt /* aError */ )
       
   274     {
       
   275     // does nothing
       
   276     }
       
   277 
       
   278 //  End of File
       
   279 
       
   280 
       
   281 
       
   282