email/imap4mtm/imaputils/src/cimaputils.cpp
changeset 31 ebfee66fde93
parent 0 72b543305e3a
equal deleted inserted replaced
30:6a20128ce557 31:ebfee66fde93
       
     1 // Copyright (c) 2006-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 //
       
    15 
       
    16 #include "cimaputils.h"
       
    17 #include "cimaplogger.h"
       
    18 #include "cimapcharconv.h"
       
    19 
       
    20 /**
       
    21 Create the IMAP utilities class.
       
    22 There is only one instance of this class at any one time. If more than one
       
    23 server MTM instance exists at any time, then they share this class.
       
    24 This is a static function.
       
    25 */
       
    26 EXPORT_C void CImapUtils::CreateL()
       
    27 	{
       
    28 	CImapUtils* self = NULL;
       
    29 
       
    30 	TAny* tls = Dll::Tls();
       
    31 	if (tls)
       
    32 		{
       
    33 		self = static_cast<CImapUtils*>(tls);
       
    34 		++self->iRefCount;
       
    35 		}
       
    36 	else
       
    37 		{
       
    38 		self = new (ELeave) CImapUtils();
       
    39 		CleanupStack::PushL(self);
       
    40 		self->ConstructL();
       
    41 		CleanupStack::Pop();
       
    42 		Dll::SetTls(self);
       
    43 		self->iRefCount = 1;
       
    44 		}
       
    45 	}
       
    46 
       
    47 /**
       
    48 Delete the IMAP utilities class.
       
    49 The class uses a reference count to ensure that there is only ever one instance
       
    50 of the class at any time. Once the reference count hits 0, the class is destroyed.
       
    51 This is a static function.
       
    52 */
       
    53 EXPORT_C void CImapUtils::Delete()
       
    54 	{
       
    55 	TAny* tls = Dll::Tls();
       
    56 
       
    57 	if (tls)
       
    58 		{
       
    59 		CImapUtils* self = static_cast<CImapUtils*>(tls);
       
    60 		--self->iRefCount;
       
    61 		if (self->iRefCount == 0)
       
    62 			{
       
    63 			delete self;
       
    64 			Dll::SetTls(NULL);
       
    65 			}
       
    66 		}
       
    67 	}
       
    68 
       
    69 /**
       
    70 Get a reference to the IMAP utilities class.
       
    71 This is a static function.
       
    72 
       
    73 @return Reference to IMAP utilities class.
       
    74 */
       
    75 EXPORT_C CImapUtils& CImapUtils::GetRef()
       
    76 	{
       
    77 	TAny* tls = Dll::Tls();	
       
    78 
       
    79 	__ASSERT_DEBUG(tls != NULL, User::Invariant());
       
    80 
       
    81 	CImapUtils* utils = static_cast<CImapUtils*>(tls);
       
    82 	return *utils;
       
    83 	}
       
    84 
       
    85 CImapUtils::CImapUtils()
       
    86 	{
       
    87 	}
       
    88 
       
    89 void CImapUtils::ConstructL()
       
    90 	{
       
    91 	User::LeaveIfError(iFs.Connect());
       
    92 	iLogger = CImapLogger::NewL();
       
    93 	iCharconv = CImapCharconv::NewL(iFs);
       
    94 	}
       
    95 
       
    96 CImapUtils::~CImapUtils()
       
    97 	{
       
    98 	delete iLogger;
       
    99 	delete iCharconv;
       
   100 	iFs.Close();
       
   101 	}
       
   102 
       
   103 /**
       
   104 Gets a connected file system object.
       
   105 
       
   106 @return a connected file system object.
       
   107 */
       
   108 EXPORT_C RFs& CImapUtils::Fs()
       
   109 	{
       
   110 	return iFs;
       
   111 	}
       
   112 
       
   113 /**
       
   114 Gets a reference to the logger utility class.
       
   115 
       
   116 @return Reference to the logger utility class.
       
   117 */
       
   118 EXPORT_C CImapLogger& CImapUtils::Logger()
       
   119 	{
       
   120 	return *iLogger;
       
   121 	}
       
   122 
       
   123 /**
       
   124 Gets a reference to the character converter utility class.
       
   125 
       
   126 @return reference to the character converter utility class.
       
   127 */
       
   128 EXPORT_C CImapCharconv& CImapUtils::Charconv()
       
   129 	{
       
   130 	return *iCharconv;
       
   131 	}
       
   132 
       
   133 /**
       
   134 The panic function for the imapserver.
       
   135 @param aPanic The panic code.
       
   136 */
       
   137 EXPORT_C void TImapServerPanic::ImapPanic(TImpsPanic aPanic)
       
   138 	{
       
   139 	_LIT(KImapServerPanic, "IMAPServer");
       
   140 	User::Panic(KImapServerPanic(), aPanic);
       
   141 	}