PECengine/AttributeLibrary2/Src/CPEngSessionSlotObject.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:  Base class for session slot, reference counted objects.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <E32Std.h>
       
    20 #include "CPEngSessionSlotObject.h"
       
    21 #include "CPEngSessionSlotObjectCon.h"
       
    22 #include "CPEngSessionSlotId.h"
       
    23 
       
    24 
       
    25 //LOCAL constants
       
    26 namespace
       
    27     {
       
    28     _LIT( KPEngSlotObjectPanic, "AttrSlotObj" );
       
    29     enum TPEngSlotObjectPanicReasons
       
    30         {
       
    31         ESlotObjAccessCountNegative,
       
    32         ESlotObjHasAlreadyOwner,
       
    33         };
       
    34 
       
    35     void PanicSlotObj( TPEngSlotObjectPanicReasons aPanicReason )
       
    36         {
       
    37         User::Panic( KPEngSlotObjectPanic, aPanicReason );
       
    38         }
       
    39     }
       
    40 
       
    41 
       
    42 
       
    43 
       
    44 // ============================ MEMBER FUNCTIONS ===============================
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CPEngSessionSlotObject::CPEngSessionSlotObject
       
    48 // C++ default constructor can NOT contain any code, that
       
    49 // might leave.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CPEngSessionSlotObject::CPEngSessionSlotObject()
       
    53         : iAccessCount( 1 )
       
    54     {
       
    55     }
       
    56 
       
    57 
       
    58 // Destructor
       
    59 CPEngSessionSlotObject::~CPEngSessionSlotObject()
       
    60     {
       
    61     delete iSlotId;
       
    62 
       
    63     if ( iContainer )
       
    64         {
       
    65         iContainer->Remove( this );
       
    66         }
       
    67 
       
    68     if ( iOwner )
       
    69         {
       
    70         iOwner->Close();
       
    71         }
       
    72     }
       
    73 
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CPEngSessionSlotObject::Open()
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CPEngSessionSlotObject::Open()
       
    80     {
       
    81     iAccessCount++;
       
    82     }
       
    83 
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CPEngSessionSlotObject::Close()
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CPEngSessionSlotObject::Close()
       
    90     {
       
    91     __ASSERT_DEBUG( ( iAccessCount >= 1 ), PanicSlotObj( ESlotObjAccessCountNegative ) );
       
    92 
       
    93     iAccessCount--;
       
    94 
       
    95     if ( iAccessCount == 0 )
       
    96         {
       
    97         delete this;
       
    98         }
       
    99     }
       
   100 
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CPEngSessionSlotObject::ConstructL()
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CPEngSessionSlotObject::ConstructL( const CPEngSessionSlotId& aSlotId )
       
   107     {
       
   108     iSlotId = aSlotId.CloneL();
       
   109     }
       
   110 
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CPEngSessionSlotObject::SlotId()
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 const CPEngSessionSlotId& CPEngSessionSlotObject::SlotId() const
       
   117     {
       
   118     return *iSlotId;
       
   119     }
       
   120 
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CPEngSessionSlotObject::SetOwner()
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CPEngSessionSlotObject::SetOwner( CObject& aOwner )
       
   127     {
       
   128     __ASSERT_ALWAYS( !iOwner, PanicSlotObj( ESlotObjHasAlreadyOwner ) );
       
   129 
       
   130     iOwner = &aOwner;
       
   131     TInt val = iOwner->Open();     // CSI: 65 #
       
   132     }
       
   133 
       
   134 
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CPEngSessionSlotObject::RefCount()
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 TInt CPEngSessionSlotObject::RefCount() const
       
   141     {
       
   142     return iAccessCount;
       
   143     }
       
   144 
       
   145 
       
   146 
       
   147 
       
   148 //  End of File