PECengine/AttributeLibrary2/Src/CPEngAttrLibObjectHolder.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Attribute library object holder.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include    "CPEngAttrLibObjectHolder.h"
       
    20 #include    "CPEngSessionSlotObject.h"
       
    21 #include    "CPEngSessionSlotObjectCon.h"
       
    22 
       
    23 #include    "CPEngPresenceAttrManager.h"
       
    24 #include    "CPEngPresenceAttrTransactionEnv.h"
       
    25 #include    "CPEngAttributeTransactionFactory.h"
       
    26 
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CPEngAttrLibObjectHolder::InstanceLC()
       
    32 // Singleton retrieve method.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CPEngAttrLibObjectHolder* CPEngAttrLibObjectHolder::InstanceLC()
       
    36     {
       
    37     CPEngAttrLibObjectHolder* holder = NULL;
       
    38 
       
    39     holder = ( CPEngAttrLibObjectHolder* ) Dll::Tls();
       
    40     if ( !holder )
       
    41         {
       
    42         holder = CPEngAttrLibObjectHolder::NewLC();
       
    43         User::LeaveIfError( Dll::SetTls( holder ) );
       
    44         }
       
    45     else
       
    46         {
       
    47         TInt val = holder->Open();                 // CSI: 65 #
       
    48         CleanupClosePushL( *holder );
       
    49         }
       
    50 
       
    51     return holder;
       
    52     }
       
    53 
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CPEngAttrLibObjectHolder::HandleThreadDetach()
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 void CPEngAttrLibObjectHolder::HandleThreadDetach()
       
    60     {
       
    61     CPEngAttrLibObjectHolder* holder;
       
    62     holder = ( CPEngAttrLibObjectHolder* ) Dll::Tls();
       
    63     delete holder;
       
    64     }
       
    65 
       
    66 
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CPEngAttrLibObjectHolder::NewLC()
       
    70 // Two-phased constructor.
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CPEngAttrLibObjectHolder* CPEngAttrLibObjectHolder::NewLC()
       
    74     {
       
    75     CPEngAttrLibObjectHolder* self = new( ELeave ) CPEngAttrLibObjectHolder;
       
    76     CleanupClosePushL( *self );
       
    77     self->ConstructL();
       
    78     return self;
       
    79     }
       
    80 
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CPEngAttrLibObjectHolder::CPEngAttrLibObjectHolder
       
    84 // C++ default constructor can NOT contain any code, that
       
    85 // might leave.
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 CPEngAttrLibObjectHolder::CPEngAttrLibObjectHolder()
       
    89     {
       
    90     }
       
    91 
       
    92 
       
    93 // Destructor
       
    94 CPEngAttrLibObjectHolder::~CPEngAttrLibObjectHolder()
       
    95     {
       
    96     delete iAttributeManagers;
       
    97     delete iAttributeTransEnvs;
       
    98     delete iAttributeTransFacts;
       
    99     Dll::SetTls( NULL );
       
   100 
       
   101 #if _BullseyeCoverage
       
   102     cov_write();
       
   103 #endif
       
   104     }
       
   105 
       
   106 
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CPEngAttrLibObjectHolder::ConstructL()
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CPEngAttrLibObjectHolder::ConstructL()
       
   113     {
       
   114     iAttributeManagers = CPEngSessionSlotObjectCon::NewL();
       
   115     iAttributeTransEnvs = CPEngSessionSlotObjectCon::NewL();
       
   116     iAttributeTransFacts = CPEngSessionSlotObjectCon::NewL();
       
   117     }
       
   118 
       
   119 
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CPEngAttrLibObjectHolder::AttributeManagerInstanceL()
       
   123 //
       
   124 // NOTE!! Method increases returned object reference count by one before
       
   125 // returning it.
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 MPEngPresenceAttrManager* CPEngAttrLibObjectHolder::AttributeManagerInstanceL(
       
   129     const CPEngSessionSlotId& aSlotId )
       
   130     {
       
   131     CPEngPresenceAttrManager* attrManager =
       
   132         ( CPEngPresenceAttrManager* ) iAttributeManagers->FindById( aSlotId );
       
   133     if ( !attrManager )
       
   134         {
       
   135         attrManager = CPEngPresenceAttrManager::NewLC( aSlotId );
       
   136         attrManager->SetOwner( *this );
       
   137         iAttributeManagers->AddL( attrManager );
       
   138         CleanupStack::Pop(); //Leave reference open to MPEngPresenceAttrManager
       
   139         }
       
   140     else {
       
   141         attrManager->Open();    // CSI: 65 #
       
   142         }
       
   143 
       
   144     return attrManager;
       
   145     }
       
   146 
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CPEngAttrLibObjectHolder::AttributeTransEnvInstanceL()
       
   150 //
       
   151 // NOTE!! Method increases returned object reference count by one before
       
   152 // returning it.
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 MPEngPresenceAttrTransactionEnv* CPEngAttrLibObjectHolder::AttributeTransEnvInstanceL(
       
   156     const CPEngSessionSlotId& aSlotId )
       
   157     {
       
   158     CPEngPresenceAttrTransactionEnv* transEnv =
       
   159         ( CPEngPresenceAttrTransactionEnv* ) iAttributeTransEnvs->FindById( aSlotId );
       
   160     if ( !transEnv )
       
   161         {
       
   162         MPEngPresenceAttrManager* attrMan = AttributeManagerInstanceL( aSlotId );
       
   163         CleanupClosePushL( *attrMan );
       
   164         transEnv = CPEngPresenceAttrTransactionEnv::NewL( aSlotId, *attrMan );
       
   165         CleanupStack::Pop(); //Leave reference open to MPEngPresenceAttrManager
       
   166         //transEnv took its ownership
       
   167 
       
   168 
       
   169         CleanupStack::PushL( transEnv );
       
   170         transEnv->SetOwner( *this );
       
   171         iAttributeTransEnvs->AddL( transEnv );
       
   172         CleanupStack::Pop(); //Leave initial reference open to CPEngPresenceAttrTransactionEnv
       
   173         }
       
   174     else {
       
   175         transEnv->Open();       // CSI: 65 #
       
   176         }
       
   177 
       
   178     return transEnv;
       
   179     }
       
   180 
       
   181 
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CPEngAttrLibObjectHolder::AttributeTransFactInstanceL()
       
   185 //
       
   186 // NOTE!! Method increases returned object reference count by one before
       
   187 // returning it.
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 MPEngTransactionFactory* CPEngAttrLibObjectHolder::AttributeTransFactInstanceL(
       
   191     const CPEngSessionSlotId& aSlotId )
       
   192     {
       
   193     CPEngAttributeTransactionFactory* transFact =
       
   194         ( CPEngAttributeTransactionFactory* ) iAttributeTransFacts->FindById( aSlotId );
       
   195     if ( !transFact )
       
   196         {
       
   197         MPEngPresenceAttrManager* attrMan = AttributeManagerInstanceL( aSlotId );
       
   198         CleanupClosePushL( *attrMan );
       
   199 
       
   200         MPEngPresenceAttrTransactionEnv* attrEnv = AttributeTransEnvInstanceL( aSlotId );
       
   201         CleanupClosePushL( *attrEnv );
       
   202 
       
   203         transFact = CPEngAttributeTransactionFactory::NewL( aSlotId, *attrEnv, *attrMan );
       
   204         CleanupStack::Pop( 2 ); //CPEngAttributeTransactionFactory took ownership of
       
   205         //attrMan and attrEnv
       
   206 
       
   207         CleanupClosePushL( *transFact );
       
   208         transFact->SetOwner( *this );
       
   209         iAttributeTransFacts->AddL( transFact );
       
   210         CleanupStack::Pop(); //Leave initial CPEngAttributeTransactionFactory reference open
       
   211         }
       
   212 
       
   213     else {
       
   214         transFact->Open();      // CSI: 65 #
       
   215         }
       
   216 
       
   217     return transFact;
       
   218     }
       
   219 
       
   220 
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CPEngAttrLibObjectHolder::__DbgInstanceOrNull()
       
   224 // Debug helper.
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 #ifdef _DEBUG
       
   228 CPEngAttrLibObjectHolder* CPEngAttrLibObjectHolder::__DbgInstanceOrNull()
       
   229     {
       
   230     return ( CPEngAttrLibObjectHolder* ) Dll::Tls();
       
   231     }
       
   232 #endif // _DEBUG
       
   233 
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // CPEngAttrLibObjectHolder::__DbgObjectCounts()
       
   237 // Debug helper.
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 #ifdef _DEBUG
       
   241 void CPEngAttrLibObjectHolder::__DbgObjectCounts( TInt& aHolder,
       
   242                                                   TInt& aAttrMan,
       
   243                                                   TInt& aTransEnv,
       
   244                                                   TInt& aTransFact ) const
       
   245     {
       
   246     aHolder = 1;
       
   247     aAttrMan = iAttributeManagers->Count();
       
   248     aTransEnv = iAttributeTransEnvs->Count();
       
   249     aTransFact = iAttributeTransFacts->Count();
       
   250     }
       
   251 #endif // _DEBUG
       
   252 
       
   253 
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // __DoGetRefCount()
       
   257 // Debug helper.
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 #ifdef _DEBUG
       
   261 void __DoGetRefCount( const CPEngSessionSlotObjectCon& aCon,
       
   262                       const CPEngSessionSlotId& aSlotId,
       
   263                       TInt& aRefCount )
       
   264     {
       
   265 
       
   266     const CPEngSessionSlotObject* obj = aCon.FindById( aSlotId );
       
   267     if ( obj )
       
   268         {
       
   269         aRefCount = obj->RefCount();
       
   270         }
       
   271     else
       
   272         {
       
   273         aRefCount = KErrNotFound;
       
   274         }
       
   275     }
       
   276 #endif // _DEBUG
       
   277 
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // CPEngAttrLibObjectHolder::__DbgAttrManRefCount()
       
   281 // Debug helper.
       
   282 // -----------------------------------------------------------------------------
       
   283 //
       
   284 #ifdef _DEBUG
       
   285 void CPEngAttrLibObjectHolder::__DbgAttrManRefCount( const CPEngSessionSlotId& aSlotId,
       
   286                                                      TInt& aRefCount ) const
       
   287     {
       
   288     __DoGetRefCount( *iAttributeManagers, aSlotId, aRefCount );
       
   289     }
       
   290 #endif // _DEBUG
       
   291 
       
   292 
       
   293 // -----------------------------------------------------------------------------
       
   294 // CPEngAttrLibObjectHolder::__DbgTransEnvRefCount()
       
   295 // Debug helper.
       
   296 // -----------------------------------------------------------------------------
       
   297 //
       
   298 #ifdef _DEBUG
       
   299 void CPEngAttrLibObjectHolder::__DbgTransEnvRefCount( const CPEngSessionSlotId& aSlotId,
       
   300                                                       TInt& aRefCount ) const
       
   301     {
       
   302     __DoGetRefCount( *iAttributeTransEnvs, aSlotId, aRefCount );
       
   303     }
       
   304 #endif // _DEBUG
       
   305 
       
   306 
       
   307 // -----------------------------------------------------------------------------
       
   308 // CPEngAttrLibObjectHolder::__DbgTransFactRefCount()
       
   309 // Debug helper.
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 #ifdef _DEBUG
       
   313 void CPEngAttrLibObjectHolder::__DbgTransFactRefCount( const CPEngSessionSlotId& aSlotId,
       
   314                                                        TInt& aRefCount ) const
       
   315     {
       
   316     __DoGetRefCount( *iAttributeTransFacts, aSlotId, aRefCount );
       
   317     }
       
   318 #endif // _DEBUG
       
   319 
       
   320 
       
   321 //  End of File