pimappservices/calendar/server/src/agspermanentdata.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // CAgnPermanentData is a container to hold the handles/references 
       
    15 // to data which is pre-created during server start-up when
       
    16 // the Agenda server is started in non-transient mode.
       
    17 // 
       
    18 //
       
    19 
       
    20 #include "agspermanentdata.h"
       
    21 
       
    22 #include "agsfilemanager.h"
       
    23 #include "calcommonimpl.h"
       
    24 
       
    25 
       
    26 CAgnPermanentData* CAgnPermanentData::NewL(CAgnServer& aServer, CAgnServFileMgr& aFileMgr)
       
    27 	{
       
    28 	CAgnPermanentData* self = new (ELeave) CAgnPermanentData(aServer, aFileMgr);
       
    29 	return self;
       
    30 	}
       
    31 
       
    32 CAgnPermanentData::CAgnPermanentData(CAgnServer& aServer, CAgnServFileMgr& aFileMgr)
       
    33  : iServer(aServer), iFileMgr(aFileMgr)
       
    34 	{
       
    35 	}
       
    36 
       
    37 CAgnPermanentData::~CAgnPermanentData()
       
    38 	{
       
    39 	Close();
       
    40 	}
       
    41 
       
    42 void CAgnPermanentData::Close()
       
    43 	{
       
    44 	if (iFile)
       
    45 		{
       
    46 		iFileMgr.CloseAgenda(*iFile, ETrue);
       
    47 		iFile = NULL;
       
    48 		}
       
    49 	}
       
    50 
       
    51 /*
       
    52   Starts the creation of the pre-created data. In this case this means opening
       
    53   the default Agenda file and starting the index building process. Building
       
    54   the indices is asynchronously handled within the CAgnServFile object (iFile).
       
    55 */
       
    56 void CAgnPermanentData::StartDataCreationL()
       
    57 	{
       
    58 	if (!iFile)
       
    59 		{		
       
    60 		CalCommon::TCalFileVersionSupport dummyStatus;
       
    61 		iFile = &iFileMgr.OpenAgendaL(KDefaultSecureAgendaFileName(), iServer, dummyStatus);		
       
    62 		iFile->DoStartBuildIndex();
       
    63 		}
       
    64 	}
       
    65 
       
    66 /*
       
    67   Releases the file if it is being held open by this object.
       
    68   
       
    69 @param Filename of Agenda file
       
    70 */
       
    71 void CAgnPermanentData::ReleaseFileL(const TDesC& aFilename)
       
    72 	{
       
    73 	if (iFile && (aFilename.CompareF(iFile->FileName()) == 0))
       
    74 		{
       
    75 		Close();
       
    76 		}
       
    77 	}
       
    78 
       
    79 /*
       
    80   Checks whether this object is the only one that is currently using
       
    81   aFilename.
       
    82   
       
    83 @return ETrue if this is the only object referencing aFilename, EFalse otherwise.
       
    84 */
       
    85 TBool CAgnPermanentData::IsOnlyClientOfFile(const TDesC& aFilename)
       
    86 	{
       
    87 	if (iFile)
       
    88 		{
       
    89 		if ((aFilename.CompareF(iFile->FileName()) == 0) && iFile->ReferenceCount() == 1)
       
    90 			{
       
    91 			return ETrue;
       
    92 			}
       
    93 		}
       
    94 	return EFalse;
       
    95 	}
       
    96