messagingappbase/msgavkon/muiu_internal/servicesinternal/src/MuiuLock.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2007 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:   The global lock class for messaging components
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <centralrepository.h>    // CRepository
       
    21 #include "MuiuLock.h"             // Own header file
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // CMuiuLock::NewL
       
    25 // Runs the first and second phase constructors
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 EXPORT_C CMuiuLock* CMuiuLock::NewL( TUid aLockId )
       
    29     {
       
    30     CMuiuLock* self = new (ELeave) CMuiuLock;
       
    31     CleanupStack::PushL( self );
       
    32     self->ConstructL( aLockId );
       
    33     CleanupStack::Pop( self );
       
    34     return self;
       
    35     }
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CMuiuLock::~CMuiuLock
       
    39 // Destructor. Releases the lock if needed.
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CMuiuLock::~CMuiuLock()
       
    43     {
       
    44     if ( iLocked )
       
    45         {
       
    46         Release();
       
    47         }
       
    48     delete iRepository;
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CMuiuLock::Reserve
       
    53 // Reserves the lock for the client by opening the read/write transaction to
       
    54 // the central repository
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 EXPORT_C TInt CMuiuLock::Reserve()
       
    58     {
       
    59     TInt status( KErrNone );
       
    60     
       
    61     if ( !iLocked )
       
    62         {
       
    63         status = iRepository->StartTransaction( 
       
    64             CRepository::EReadWriteTransaction );
       
    65             
       
    66         if ( status == KErrNone )
       
    67             {
       
    68             iLocked = ETrue;
       
    69             }
       
    70         }
       
    71     else
       
    72         {
       
    73         status = KErrGeneral;
       
    74         }
       
    75         
       
    76     return status;
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CMuiuLock::Release
       
    81 // Releases the lock by cancelling the transaction opened by Reserve()
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 EXPORT_C void CMuiuLock::Release()
       
    85     {
       
    86     if ( iLocked )
       
    87         {
       
    88         iRepository->CancelTransaction();
       
    89         iLocked = EFalse;
       
    90         }
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CMuiuLock::CMuiuLock
       
    95 // First phase constructor. Just initialises the data members.
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 CMuiuLock::CMuiuLock() :
       
    99     iRepository ( NULL ),
       
   100     iLocked ( EFalse )
       
   101     {
       
   102     // none
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CMuiuLock::ConstructL
       
   107 // Second phase constructor. Creates the central repository handle.
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void CMuiuLock::ConstructL( TUid aLockId )
       
   111     {
       
   112     iRepository = CRepository::NewL( aLockId );
       
   113     }