PECengine/AttributeLibrary2/SrcAttributeBase/CPEngPresenceAttrModelStorageProxy.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2005 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:  Presence attribute store proxy.
       
    15 *
       
    16 */
       
    17 
       
    18 //  INCLUDES
       
    19 #include "CPEngPresenceAttrModelStorageProxy.h"
       
    20 #include "CPEngPresenceAttrModel.h"
       
    21 #include "CPEngModelStoreEntryAdapter.h"
       
    22 #include "MPEngStorageManager.h"
       
    23 #include "PEngAttributeStoreIDCodec.h"
       
    24 #include "PEngWVPresenceAttributes2.h"
       
    25 #include <E32Base.h>
       
    26 
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CPEngPresenceAttrModelStorageProxy::NewL()
       
    32 // Two-phased constructor.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CPEngPresenceAttrModelStorageProxy* CPEngPresenceAttrModelStorageProxy::NewL(
       
    36     CPEngPresenceAttrModel& aAttributeModel )
       
    37     {
       
    38     CPEngPresenceAttrModelStorageProxy* self = new ( ELeave ) CPEngPresenceAttrModelStorageProxy(
       
    39         aAttributeModel );
       
    40     return self;
       
    41     }
       
    42 
       
    43 
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CPEngPresenceAttrModelStorageProxy::ConnectStorageL()
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 void CPEngPresenceAttrModelStorageProxy::ConnectStorageL( TBool aUserModel,
       
    50                                                           HBufC* aStoreId,
       
    51                                                           MPEngStorageManager& aStorageManager )
       
    52 
       
    53     {
       
    54     __ASSERT_ALWAYS( !iStoreEntry, User::Leave( KErrAlreadyExists ) );
       
    55 
       
    56 
       
    57     TPEngStorageType storageType = EPEngStorageBasicCached;
       
    58     if ( aUserModel )
       
    59         {
       
    60         storageType = EPEngStorageBasicPermanent;
       
    61         }
       
    62 
       
    63 
       
    64     iStoreEntry = CPEngModelStoreEntryAdapter::NewL( aStoreId,
       
    65                                                      aStorageManager,
       
    66                                                      storageType,
       
    67                                                      iAttributeModel );
       
    68     }
       
    69 
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CPEngPresenceAttrModelStorageProxy::CPEngPresenceAttrModelStorageProxy()
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CPEngPresenceAttrModelStorageProxy::CPEngPresenceAttrModelStorageProxy(
       
    76     CPEngPresenceAttrModel& aAttributeModel )
       
    77         : iAttributeModel( aAttributeModel ),
       
    78         iEditLockOwned( EFalse ),
       
    79         iForceNotifySidChange( ETrue )
       
    80     {
       
    81     }
       
    82 
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CPEngPresenceAttrModelStorageProxy::~CPEngPresenceAttrModelStorageProxy()
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 CPEngPresenceAttrModelStorageProxy::~CPEngPresenceAttrModelStorageProxy()
       
    89     {
       
    90     StopEditSupport();
       
    91     }
       
    92 
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CPEngPresenceAttrModelStorageProxy::RetrieveFromStorageL()
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 TInt CPEngPresenceAttrModelStorageProxy::RetrieveFromStorageL()
       
    99     {
       
   100     //KErrArgument is used here because client is trying
       
   101     //perform storage operation for wrong kind of attribute model
       
   102     __ASSERT_ALWAYS( iStoreEntry, User::Leave( KErrArgument ) );
       
   103 
       
   104     return iStoreEntry->StorageManager().RetrieveL( *iStoreEntry );
       
   105     }
       
   106 
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CPEngPresenceAttrModelStorageProxy::StoreToStorageL()
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CPEngPresenceAttrModelStorageProxy::StoreToStorageL( TBool aForceStore ) const
       
   113     {
       
   114     __ASSERT_ALWAYS( iStoreEntry, User::Leave( KErrArgument ) );
       
   115 
       
   116     MPEngStorageManager& sm = iStoreEntry->StorageManager();
       
   117     if ( aForceStore )
       
   118         {
       
   119         //Updating the force notify flag from const storage method
       
   120         //is ok, because the value is internal storage advice,
       
   121         //and thus the data isn't directly visible to attribute clients
       
   122         CPEngPresenceAttrModelStorageProxy* nonConstSelf =
       
   123             const_cast<CPEngPresenceAttrModelStorageProxy*> ( this );
       
   124 
       
   125         //Force notification from SID change is sent if the storing fails
       
   126         //If storing succeds, no need to send SID change event "manually"
       
   127         nonConstSelf->iForceNotifySidChange = ETrue;
       
   128         sm.StoreExclusiveL( *iStoreEntry );
       
   129         nonConstSelf->iForceNotifySidChange = EFalse;
       
   130         }
       
   131     else
       
   132         {
       
   133         sm.StoreL( *iStoreEntry );
       
   134         }
       
   135 
       
   136     ForceSendAttrEventIfNeededL();
       
   137     }
       
   138 
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CPEngPresenceAttrModelStorageProxy::RemoveFromStorageL()
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CPEngPresenceAttrModelStorageProxy::RemoveFromStorageL()
       
   145     {
       
   146     __ASSERT_ALWAYS( iStoreEntry, User::Leave( KErrArgument ) );
       
   147 
       
   148     User::LeaveIfError( iStoreEntry->StorageManager().Delete( *iStoreEntry ) );
       
   149     }
       
   150 
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CPEngPresenceAttrModelStorageProxy::IsFromThisStorage()
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 TBool CPEngPresenceAttrModelStorageProxy::IsFromThisStorage(
       
   157     const MPEngStorageManager& aStorageManager ) const
       
   158     {
       
   159     if ( iStoreEntry &&
       
   160          ( &iStoreEntry->StorageManager() == &aStorageManager ) )
       
   161         {
       
   162         return ETrue;
       
   163         }
       
   164 
       
   165 
       
   166     return EFalse;
       
   167     }
       
   168 
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CPEngPresenceAttrModelStorageProxy::GainEditLockL()
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 void CPEngPresenceAttrModelStorageProxy::GainEditLockL( TBool aCreationAllowed )
       
   175     {
       
   176     __ASSERT_ALWAYS( iStoreEntry, User::Leave( KErrArgument ) );
       
   177     __ASSERT_ALWAYS( !iEditLockOwned, User::Leave( KErrLocked ) );
       
   178 
       
   179     if ( iStoreEntry->StorageManager().LockedL( *iStoreEntry ) )
       
   180         {
       
   181         User::Leave( KErrLocked );
       
   182         }
       
   183 
       
   184     User::LeaveIfError( iStoreEntry->Lock( EStorageLockLevelBasic,
       
   185                                            aCreationAllowed ) );
       
   186     iEditLockOwned = ETrue;
       
   187     }
       
   188 
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CPEngPresenceAttrModelStorageProxy::StopEditSupport()
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 TInt CPEngPresenceAttrModelStorageProxy::StopEditSupport()
       
   195     {
       
   196     TInt err = KErrNone;
       
   197 
       
   198     if ( iStoreEntry && iEditLockOwned )
       
   199         {
       
   200         iStoreEntry->Release();
       
   201         iEditLockOwned = EFalse;
       
   202 
       
   203         TRAP( err, ForceSendAttrEventIfNeededL() );
       
   204         }
       
   205 
       
   206     delete iStoreEntry;
       
   207     iStoreEntry = NULL;
       
   208 
       
   209     return err;
       
   210     }
       
   211 
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CPEngPresenceAttrModelStorageProxy::IsEditLocked()
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 TBool CPEngPresenceAttrModelStorageProxy::IsEditLocked() const
       
   218     {
       
   219     return iEditLockOwned;
       
   220     }
       
   221 
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CPEngPresenceAttrModelStorageProxy::ForceSendAttrEventIfNeededL()
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 void CPEngPresenceAttrModelStorageProxy::ForceSendAttrEventIfNeededL() const
       
   228     {
       
   229     if ( iForceNotifySidChange &&
       
   230          ( iAttributeModel.Type() != KUidPrAttrOnlineStatus ) )
       
   231         {
       
   232         HBufC* sid = PEngAttributeStoreIDCodec::GenerateStoreIdL( KUidPrAttrOnlineStatus,
       
   233                                                                   iAttributeModel.PresenceID() );
       
   234         CleanupStack::PushL( sid );
       
   235         MPEngStorageManager& m = iStoreEntry->StorageManager();
       
   236         User::LeaveIfError( m.NotifyChangedSId( *sid, iStoreEntry->StorageType() ) );
       
   237         CleanupStack::PopAndDestroy( sid );
       
   238         }
       
   239     }
       
   240 
       
   241 
       
   242 // End of File