emailservices/emailclientapi/src/emailapiutils.cpp
author hgs
Thu, 14 Oct 2010 17:33:43 +0300
changeset 76 38bf5461e270
parent 62 a8c646b56683
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description: This file implements class CEmailApiUtils.
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include <e32std.h>
62
hgs
parents: 47
diff changeset
    19
#include "CFSMailPlugin.h"
47
hgs
parents:
diff changeset
    20
#include "emailapidefs.h"
hgs
parents:
diff changeset
    21
#include "emailclientapiimpldefs.h"
hgs
parents:
diff changeset
    22
#include "emailapiutils.h"
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    25
// 
hgs
parents:
diff changeset
    26
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    27
CPluginData::CPluginData( TUid aUid ) :
hgs
parents:
diff changeset
    28
    iData( aUid ),
hgs
parents:
diff changeset
    29
    iPluginLoadError( KErrNotReady )
hgs
parents:
diff changeset
    30
    { 
hgs
parents:
diff changeset
    31
    }
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    34
// 
hgs
parents:
diff changeset
    35
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    36
CPluginData::~CPluginData()
hgs
parents:
diff changeset
    37
    {
hgs
parents:
diff changeset
    38
    // panic if a user of plugin has not called ReleaseInstance after ClaimInstance
hgs
parents:
diff changeset
    39
    __ASSERT_ALWAYS( iOwned || !iRefCount, Panic( EMailPanicPluginNotReleased ) );
hgs
parents:
diff changeset
    40
    }
hgs
parents:
diff changeset
    41
hgs
parents:
diff changeset
    42
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    43
// 
hgs
parents:
diff changeset
    44
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    45
CFSMailPlugin* CPluginData::ClaimInstance()
hgs
parents:
diff changeset
    46
    {
hgs
parents:
diff changeset
    47
    if ( !iData.iPlugin )
hgs
parents:
diff changeset
    48
        {
hgs
parents:
diff changeset
    49
        TRAP( iPluginLoadError, iData.iPlugin = CFSMailPlugin::NewL( iData.iUid ) );
hgs
parents:
diff changeset
    50
        }
hgs
parents:
diff changeset
    51
    if ( !iPluginLoadError )
hgs
parents:
diff changeset
    52
        {
hgs
parents:
diff changeset
    53
        iRefCount++;
hgs
parents:
diff changeset
    54
        }
hgs
parents:
diff changeset
    55
    return iData.iPlugin;
hgs
parents:
diff changeset
    56
    }
hgs
parents:
diff changeset
    57
hgs
parents:
diff changeset
    58
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    59
// 
hgs
parents:
diff changeset
    60
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    61
CFSMailPlugin* CPluginData::ClaimInstanceL()
hgs
parents:
diff changeset
    62
    {
hgs
parents:
diff changeset
    63
    ClaimInstance();
hgs
parents:
diff changeset
    64
    User::LeaveIfError( iPluginLoadError );
hgs
parents:
diff changeset
    65
    return iData.iPlugin;
hgs
parents:
diff changeset
    66
    }
hgs
parents:
diff changeset
    67
hgs
parents:
diff changeset
    68
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    69
// 
hgs
parents:
diff changeset
    70
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    71
void CPluginData::ReleaseInstance()
hgs
parents:
diff changeset
    72
    {
hgs
parents:
diff changeset
    73
    if ( iData.iPlugin )
hgs
parents:
diff changeset
    74
        {
hgs
parents:
diff changeset
    75
        iRefCount--;
hgs
parents:
diff changeset
    76
        if ( !iRefCount )
hgs
parents:
diff changeset
    77
            {
hgs
parents:
diff changeset
    78
            delete iData.iPlugin;
hgs
parents:
diff changeset
    79
            iData.iPlugin = NULL;
hgs
parents:
diff changeset
    80
            }
hgs
parents:
diff changeset
    81
        }
hgs
parents:
diff changeset
    82
    }
hgs
parents:
diff changeset
    83
hgs
parents:
diff changeset
    84
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    85
// 
hgs
parents:
diff changeset
    86
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    87
void CPluginData::ReleasePushL()
hgs
parents:
diff changeset
    88
    {
hgs
parents:
diff changeset
    89
    TCleanupItem item( &CPluginData::CleanupOperation, this );
hgs
parents:
diff changeset
    90
    CleanupStack::PushL( item );
hgs
parents:
diff changeset
    91
    }
hgs
parents:
diff changeset
    92
hgs
parents:
diff changeset
    93
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    94
// 
hgs
parents:
diff changeset
    95
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    96
void CPluginData::CleanupOperation( TAny* aAny )
hgs
parents:
diff changeset
    97
    {
hgs
parents:
diff changeset
    98
    CPluginData* pdata = reinterpret_cast<CPluginData*>( aAny );
hgs
parents:
diff changeset
    99
    pdata->ReleaseInstance();
hgs
parents:
diff changeset
   100
    }
hgs
parents:
diff changeset
   101
hgs
parents:
diff changeset
   102
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   103
// 
hgs
parents:
diff changeset
   104
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   105
TUid CPluginData::Uid() const
hgs
parents:
diff changeset
   106
    {
hgs
parents:
diff changeset
   107
    return iData.iUid;
hgs
parents:
diff changeset
   108
    }
hgs
parents:
diff changeset
   109
hgs
parents:
diff changeset
   110
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   111
// 
hgs
parents:
diff changeset
   112
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   113
TInt CPluginData::LoadResult() const
hgs
parents:
diff changeset
   114
    {
hgs
parents:
diff changeset
   115
    return iPluginLoadError;
hgs
parents:
diff changeset
   116
    }
hgs
parents:
diff changeset
   117
hgs
parents:
diff changeset
   118
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   119
// 
hgs
parents:
diff changeset
   120
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   121
TFSMailMsgId FsMsgId( const CPluginData& aPluginData, const EmailInterface::TBaseId& aId )
hgs
parents:
diff changeset
   122
    {
hgs
parents:
diff changeset
   123
    TFSMailMsgId id( aPluginData.Uid(), aId.iId );
hgs
parents:
diff changeset
   124
    return id;
hgs
parents:
diff changeset
   125
    }
hgs
parents:
diff changeset
   126
hgs
parents:
diff changeset
   127
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   128
// 
hgs
parents:
diff changeset
   129
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   130
void CleanupReleasePush::PushL( EmailInterface::MEmailInterface& aItem )
hgs
parents:
diff changeset
   131
    {
hgs
parents:
diff changeset
   132
    TCleanupItem item( &CleanupReleasePush::Release, &aItem );
hgs
parents:
diff changeset
   133
    CleanupStack::PushL( item );
hgs
parents:
diff changeset
   134
    }
hgs
parents:
diff changeset
   135
hgs
parents:
diff changeset
   136
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   137
// 
hgs
parents:
diff changeset
   138
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   139
void CleanupReleasePush::Release( TAny *aPtr )
hgs
parents:
diff changeset
   140
    {
hgs
parents:
diff changeset
   141
    reinterpret_cast<EmailInterface::MEmailInterface*>( aPtr )->Release();
hgs
parents:
diff changeset
   142
    }
hgs
parents:
diff changeset
   143
hgs
parents:
diff changeset
   144
// End of file