PECengine/AttributeLibrary2/Src/CPEngPresenceAttrManager.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:  Concrete MPEngPresenceAttrManager implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 #include "CPEngPresenceAttrManager.h"
       
    21 #include "CPEngAttrConstructorCon.h"
       
    22 #include "CPEngPresenceAttrModelStorageProxy.h"
       
    23 #include "CPEngPresenceAttrConstructor.h"
       
    24 #include "PEngAttributeStoreIDCodec.h"
       
    25 #include "PEngAttributeRequestCodec.h"
       
    26 
       
    27 
       
    28 #include "PEngStorageManager.h"
       
    29 #include "MPEngStorageManager.h"
       
    30 #include "PEngWVAttributeConstructorFactory.h"
       
    31 #include "PresenceDebugPrint.h"
       
    32 
       
    33 
       
    34 #include <E32Base.h>
       
    35 
       
    36 
       
    37 
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CPEngPresenceAttrManager::NewLC()
       
    43 // Two-phased constructor.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CPEngPresenceAttrManager* CPEngPresenceAttrManager::NewLC(
       
    47     const CPEngSessionSlotId& aSlotId )
       
    48     {
       
    49     CPEngPresenceAttrManager* self = new ( ELeave ) CPEngPresenceAttrManager;
       
    50 
       
    51     CleanupClosePushL( *self );
       
    52     self->ConstructL( aSlotId );
       
    53 
       
    54     return self;
       
    55     }
       
    56 
       
    57 
       
    58 // Destructor
       
    59 CPEngPresenceAttrManager::~CPEngPresenceAttrManager()
       
    60     {
       
    61     delete iTypeConstructors;
       
    62     if ( iStorageManager )
       
    63         {
       
    64         iStorageManager->Close();
       
    65         }
       
    66     }
       
    67 
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CPEngPresenceAttrManager::CPEngPresenceAttrManager
       
    71 // C++ default constructor can NOT contain any code, that
       
    72 // might leave.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CPEngPresenceAttrManager::CPEngPresenceAttrManager()
       
    76     {
       
    77     }
       
    78 
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CPEngPresenceAttrManager::ConstructL
       
    82 // Symbian 2nd phase constructor can leave.
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CPEngPresenceAttrManager::ConstructL( const CPEngSessionSlotId& aSlotId )
       
    86     {
       
    87     CPEngSessionSlotObject::ConstructL( aSlotId );
       
    88     iStorageManager = PEngStorageManager::GetStorageManagerL( aSlotId );
       
    89 
       
    90     iTypeConstructors  = CPEngAttrConstructorCon::NewL( *this );
       
    91     PEngWVAttributeConstructorFactory::CreateConstructorsL( *iTypeConstructors );
       
    92     }
       
    93 
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CPEngPresenceAttrManager::Close()
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CPEngPresenceAttrManager::Close()
       
   100     {
       
   101     CPEngSessionSlotObject::Close();
       
   102     }
       
   103 
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CPEngPresenceAttrManager::InstantiateAttributeLC()
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CPEngPresenceAttrManager::InstantiateAttributeLC(
       
   110     MPEngPresenceAttrModel2*& aModel,
       
   111     const TDesC& aPresenceID,
       
   112     TUint32 aType,
       
   113     TInt aInstanceOptions )
       
   114 
       
   115     {
       
   116     aModel = NULL;
       
   117     TBool userModel = ( aInstanceOptions & EPEngUserAttribute );
       
   118 
       
   119     CPEngPresenceAttrConstructor& constructor =
       
   120         iTypeConstructors->FindByTypeL( aType );
       
   121 
       
   122     //Attribute object holds a reference to attribute manager instance
       
   123     //==> method can't be const
       
   124     MPEngPresenceAdvancedAttrModel2* model = constructor.NewAttributeInstanceLC(
       
   125                                                  userModel,
       
   126                                                  aPresenceID );
       
   127 
       
   128 
       
   129     if ( ( aInstanceOptions & EPEngStorableModel ) )
       
   130         {
       
   131         HBufC* storeId = PEngAttributeStoreIDCodec::GenerateStoreIdL( aType, aPresenceID );
       
   132         model->Storage().ConnectStorageL( userModel, storeId, *iStorageManager );
       
   133         }
       
   134 
       
   135     if ( aInstanceOptions & EPEngEditLockedModel )
       
   136         {
       
   137         if ( aInstanceOptions & EPEngCreationNotAllowed )
       
   138             {
       
   139             model->Storage().GainEditLockL( EFalse );
       
   140             }
       
   141         else
       
   142             {
       
   143             model->Storage().GainEditLockL( ETrue );
       
   144             }
       
   145         }
       
   146 
       
   147 
       
   148     aModel = model;
       
   149     }
       
   150 
       
   151 
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CPEngPresenceAttrManager::LoadAttributeLC()
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TInt CPEngPresenceAttrManager::LoadAttributeLC(
       
   158     MPEngPresenceAttrModel2*& aModel,
       
   159     const TDesC& aPresenceID,
       
   160     TUint32 aType,
       
   161     TInt aInstanceOptions )
       
   162 
       
   163     {
       
   164     aModel = NULL;
       
   165     MPEngPresenceAttrModel2* model = NULL;
       
   166     InstantiateAttributeLC( model, aPresenceID, aType, aInstanceOptions );
       
   167 
       
   168 
       
   169     TInt loadStatus = KErrNone;
       
   170     if ( aInstanceOptions & EPEngStorableModel )
       
   171         {
       
   172         loadStatus = model->Advanced()->Storage().RetrieveFromStorageL();
       
   173         }
       
   174 
       
   175 
       
   176     aModel = model;
       
   177     return loadStatus;
       
   178     }
       
   179 
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CPEngPresenceAttrManager::StoreEditLockedAttributeL()
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CPEngPresenceAttrManager::StoreEditLockedAttributeL( const MPEngPresenceAttrModel2& aModel )
       
   186     {
       
   187     ModelEditLockedFromThisSlotL( aModel );
       
   188 
       
   189     const CPEngPresenceAttrModelStorageProxy& storage = aModel.Advanced()->Storage();
       
   190     storage.StoreToStorageL();
       
   191     }
       
   192 
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CPEngPresenceAttrManager::StopEditSupport()
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 TInt CPEngPresenceAttrManager::StopEditSupport( MPEngPresenceAttrModel2& aModel ) const
       
   199     {
       
   200     CPEngPresenceAttrModelStorageProxy& storage = aModel.Advanced()->Storage();
       
   201     if ( !storage.IsFromThisStorage( *iStorageManager ) )
       
   202         {
       
   203         return KErrArgument;
       
   204         }
       
   205 
       
   206     return storage.StopEditSupport();
       
   207     }
       
   208 
       
   209 
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CPEngPresenceAttrManager::ModelEditLockedFromThisSlotL()
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 void CPEngPresenceAttrManager::ModelEditLockedFromThisSlotL(
       
   216     const MPEngPresenceAttrModel2& aModel ) const
       
   217     {
       
   218     const CPEngPresenceAttrModelStorageProxy& storage = aModel.Advanced()->Storage();
       
   219 
       
   220     //If the assert below fails, the model in question has been loaded from
       
   221     //another NWSessionSlot than where it is now tried to store or publish
       
   222     __ASSERT_ALWAYS( storage.IsFromThisStorage( *iStorageManager ),
       
   223                      User::Leave( KErrArgument ) );
       
   224 
       
   225     //If the assert below fails, the model in question has been
       
   226     //loaded without edit lock, and thus it can't be stored or published
       
   227     __ASSERT_ALWAYS( storage.IsEditLocked(),
       
   228                      User::Leave( KErrArgument ) );
       
   229     }
       
   230 
       
   231 
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CPEngPresenceAttrManager::ValidNetworkAttribute()
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 TBool CPEngPresenceAttrManager::ValidNetworkAttribute( TUint32 aType ) const
       
   238     {
       
   239     const CPEngPresenceAttrConstructor* constructor = iTypeConstructors->FindByType( aType );
       
   240     if ( constructor )
       
   241         {
       
   242         TPEngAttributeOriginator attribOriginator = constructor->Originator();
       
   243 
       
   244         if ( ( attribOriginator == EPEngClientOriginated ) ||
       
   245              ( attribOriginator == EPEngServerOriginated ) ||
       
   246              ( attribOriginator == EPEngClientServerOriginated ) )
       
   247             {
       
   248             //attribute type is a valid network attribute
       
   249             return KErrNone;
       
   250             }
       
   251 
       
   252         else
       
   253             {
       
   254             //attribute has some other originator
       
   255             //==> it is not a valid network attribute
       
   256             return KErrNotSupported;
       
   257             }
       
   258         }
       
   259 
       
   260     //Unknown attribute type
       
   261     return KErrUnknown;
       
   262     }
       
   263 
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CPEngPresenceAttrManager::KnownAttributeTypes()
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 TArray<TUint32> CPEngPresenceAttrManager::KnownAttributeTypes() const
       
   270     {
       
   271     return iTypeConstructors->TypeArray();
       
   272     }
       
   273 
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // CPEngPresenceAttrManager::GetAttributeXmlNameAndNameSpace()
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 TInt CPEngPresenceAttrManager::GetAttributeXmlNameAndNameSpace(
       
   280     TUint32 aType,
       
   281     TPtrC8& aAttributeName,
       
   282     TPtrC8& aAttributeNameSpace ) const
       
   283     {
       
   284     const CPEngPresenceAttrConstructor* constructor =
       
   285         iTypeConstructors->FindByType( aType );
       
   286     TInt err = KErrUnknown;
       
   287     if ( constructor )
       
   288         {
       
   289         err = constructor->GetCurrentXmlNames( aAttributeName,
       
   290                                                aAttributeNameSpace );
       
   291         }
       
   292 
       
   293     if ( err != KErrNone )
       
   294         {
       
   295         aAttributeName.Set( NULL, 0 );
       
   296         aAttributeNameSpace.Set( NULL, 0 );
       
   297         }
       
   298 
       
   299     return err;
       
   300     }
       
   301 
       
   302 
       
   303 
       
   304 
       
   305 
       
   306 // -----------------------------------------------------------------------------
       
   307 // CPEngPresenceAttrManager::PackModelArrayL()
       
   308 // -----------------------------------------------------------------------------
       
   309 //
       
   310 HBufC16* CPEngPresenceAttrManager::PackModelArrayL(
       
   311     const RPointerArray<MPEngPresenceAttrModel2>& aModels ) const
       
   312     {
       
   313     return PEngAttributeRequestCodec::PackModelArrayL( aModels );
       
   314     }
       
   315 
       
   316 
       
   317 
       
   318 // -----------------------------------------------------------------------------
       
   319 // CPEngPresenceAttrManager::UnpackModelArrayL()
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 void CPEngPresenceAttrManager::UnpackModelArrayL(
       
   323     const TDesC16& aModelPkg,
       
   324     TInt aInstanceOptions,
       
   325     RPointerArray<MPEngPresenceAttrModel2>& aModels  )
       
   326     {
       
   327     PEngAttributeRequestCodec::UnpackModelArrayL( aModelPkg,
       
   328                                                   aInstanceOptions,
       
   329                                                   aModels,
       
   330                                                   *this );
       
   331     }
       
   332 
       
   333 
       
   334 // -----------------------------------------------------------------------------
       
   335 // CPEngPresenceAttrManager::PackFetchRequestL()
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 HBufC16* CPEngPresenceAttrManager::PackFetchRequestL(
       
   339     const MDesCArray& aPresenceIDs,
       
   340     const TArray<TUint32>& aTypes ) const
       
   341     {
       
   342     return PEngAttributeRequestCodec::PackFetchRequestL( aPresenceIDs,
       
   343                                                          aTypes );
       
   344     }
       
   345 
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 // CPEngPresenceAttrManager::UnpackFetchRequestL()
       
   349 // -----------------------------------------------------------------------------
       
   350 //
       
   351 void CPEngPresenceAttrManager::UnpackFetchRequestL( const TDesC16& aFetchRequestPkg,
       
   352                                                     CDesCArray& aPresenceIDs,
       
   353                                                     RArray<TUint32>& aTypes ) const
       
   354     {
       
   355     PEngAttributeRequestCodec::UnpackFetchRequestL( aFetchRequestPkg,
       
   356                                                     aPresenceIDs,
       
   357                                                     aTypes );
       
   358     }
       
   359 
       
   360 
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 // CPEngPresenceAttrManager::GenerateStoreIdL()
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 HBufC* CPEngPresenceAttrManager::GenerateStoreIdL( TUint32 aAttributeType,
       
   367                                                    const TDesC& aPresenceId ) const
       
   368     {
       
   369     return PEngAttributeStoreIDCodec::GenerateStoreIdL( aAttributeType, aPresenceId );
       
   370     }
       
   371 
       
   372 
       
   373 // -----------------------------------------------------------------------------
       
   374 // CPEngPresenceAttrManager::ResolveStoreId()
       
   375 // -----------------------------------------------------------------------------
       
   376 //
       
   377 TInt CPEngPresenceAttrManager::ResolveStoreId( const TDesC& aStoreId,
       
   378                                                TUint32& aAttributeType,
       
   379                                                TPtrC& aPresenceId ) const
       
   380 
       
   381     {
       
   382     return PEngAttributeStoreIDCodec::ResolveStoreId( aStoreId,
       
   383                                                       aAttributeType,
       
   384                                                       aPresenceId );
       
   385     }
       
   386 
       
   387 
       
   388 
       
   389 // -----------------------------------------------------------------------------
       
   390 // CPEngPresenceAttrManager::ForceStoreBatchL()
       
   391 // -----------------------------------------------------------------------------
       
   392 //
       
   393 void CPEngPresenceAttrManager::ForceStoreBatchL(
       
   394     const RPointerArray<MPEngPresenceAttrModel2> aModels )
       
   395     {
       
   396     if ( aModels.Count() > 0 )
       
   397         {
       
   398         User::LeaveIfError( iStorageManager->BufferServerSideNotifications() );
       
   399         TRAPD( err,
       
   400             {
       
   401             const TInt count = aModels.Count();
       
   402             for ( TInt ii = count - 1 ; ii >= 0 ; --ii )
       
   403                 {
       
   404                 const CPEngPresenceAttrModelStorageProxy& storage =
       
   405                     aModels[ ii ]->Advanced()->Storage();
       
   406                 storage.StoreToStorageL( ETrue );   //Force store
       
   407                 }
       
   408             } );
       
   409 
       
   410         User::LeaveIfError( iStorageManager->ReleaseServerSideBuffering() );
       
   411         User::LeaveIfError( err );
       
   412         }
       
   413     }
       
   414 
       
   415 
       
   416 // -----------------------------------------------------------------------------
       
   417 // CPEngPresenceAttrManager::ForceRemoveFromStoreBatchL()
       
   418 // -----------------------------------------------------------------------------
       
   419 //
       
   420 void CPEngPresenceAttrManager::ForceRemoveFromStoreBatchL(
       
   421     RPointerArray<MPEngPresenceAttrModel2> aModels )
       
   422     {
       
   423     User::LeaveIfError( iStorageManager->BufferServerSideNotifications() );
       
   424     TRAPD( err,
       
   425         {
       
   426         const TInt count = aModels.Count();
       
   427         for ( TInt ii = count - 1 ; ii >= 0 ; --ii )
       
   428             {
       
   429             CPEngPresenceAttrModelStorageProxy& storage =
       
   430                 aModels[ ii ]->Advanced()->Storage();
       
   431             storage.RemoveFromStorageL();
       
   432             }
       
   433         } );
       
   434 
       
   435     User::LeaveIfError( iStorageManager->ReleaseServerSideBuffering() );
       
   436     User::LeaveIfError( err );
       
   437     }
       
   438 
       
   439 
       
   440 //  End of File
       
   441 
       
   442