47
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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: This file implements class CEmailApiUtils.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <e32std.h>
|
62
|
19 |
#include "CFSMailPlugin.h"
|
47
|
20 |
#include "emailapidefs.h"
|
|
21 |
#include "emailclientapiimpldefs.h"
|
|
22 |
#include "emailapiutils.h"
|
|
23 |
|
|
24 |
// ---------------------------------------------------------------------------
|
|
25 |
//
|
|
26 |
// ---------------------------------------------------------------------------
|
|
27 |
CPluginData::CPluginData( TUid aUid ) :
|
|
28 |
iData( aUid ),
|
|
29 |
iPluginLoadError( KErrNotReady )
|
|
30 |
{
|
|
31 |
}
|
|
32 |
|
|
33 |
// ---------------------------------------------------------------------------
|
|
34 |
//
|
|
35 |
// ---------------------------------------------------------------------------
|
|
36 |
CPluginData::~CPluginData()
|
|
37 |
{
|
|
38 |
// panic if a user of plugin has not called ReleaseInstance after ClaimInstance
|
|
39 |
__ASSERT_ALWAYS( iOwned || !iRefCount, Panic( EMailPanicPluginNotReleased ) );
|
|
40 |
}
|
|
41 |
|
|
42 |
// ---------------------------------------------------------------------------
|
|
43 |
//
|
|
44 |
// ---------------------------------------------------------------------------
|
|
45 |
CFSMailPlugin* CPluginData::ClaimInstance()
|
|
46 |
{
|
|
47 |
if ( !iData.iPlugin )
|
|
48 |
{
|
|
49 |
TRAP( iPluginLoadError, iData.iPlugin = CFSMailPlugin::NewL( iData.iUid ) );
|
|
50 |
}
|
|
51 |
if ( !iPluginLoadError )
|
|
52 |
{
|
|
53 |
iRefCount++;
|
|
54 |
}
|
|
55 |
return iData.iPlugin;
|
|
56 |
}
|
|
57 |
|
|
58 |
// ---------------------------------------------------------------------------
|
|
59 |
//
|
|
60 |
// ---------------------------------------------------------------------------
|
|
61 |
CFSMailPlugin* CPluginData::ClaimInstanceL()
|
|
62 |
{
|
|
63 |
ClaimInstance();
|
|
64 |
User::LeaveIfError( iPluginLoadError );
|
|
65 |
return iData.iPlugin;
|
|
66 |
}
|
|
67 |
|
|
68 |
// ---------------------------------------------------------------------------
|
|
69 |
//
|
|
70 |
// ---------------------------------------------------------------------------
|
|
71 |
void CPluginData::ReleaseInstance()
|
|
72 |
{
|
|
73 |
if ( iData.iPlugin )
|
|
74 |
{
|
|
75 |
iRefCount--;
|
|
76 |
if ( !iRefCount )
|
|
77 |
{
|
|
78 |
delete iData.iPlugin;
|
|
79 |
iData.iPlugin = NULL;
|
|
80 |
}
|
|
81 |
}
|
|
82 |
}
|
|
83 |
|
|
84 |
// ---------------------------------------------------------------------------
|
|
85 |
//
|
|
86 |
// ---------------------------------------------------------------------------
|
|
87 |
void CPluginData::ReleasePushL()
|
|
88 |
{
|
|
89 |
TCleanupItem item( &CPluginData::CleanupOperation, this );
|
|
90 |
CleanupStack::PushL( item );
|
|
91 |
}
|
|
92 |
|
|
93 |
// ---------------------------------------------------------------------------
|
|
94 |
//
|
|
95 |
// ---------------------------------------------------------------------------
|
|
96 |
void CPluginData::CleanupOperation( TAny* aAny )
|
|
97 |
{
|
|
98 |
CPluginData* pdata = reinterpret_cast<CPluginData*>( aAny );
|
|
99 |
pdata->ReleaseInstance();
|
|
100 |
}
|
|
101 |
|
|
102 |
// ---------------------------------------------------------------------------
|
|
103 |
//
|
|
104 |
// ---------------------------------------------------------------------------
|
|
105 |
TUid CPluginData::Uid() const
|
|
106 |
{
|
|
107 |
return iData.iUid;
|
|
108 |
}
|
|
109 |
|
|
110 |
// ---------------------------------------------------------------------------
|
|
111 |
//
|
|
112 |
// ---------------------------------------------------------------------------
|
|
113 |
TInt CPluginData::LoadResult() const
|
|
114 |
{
|
|
115 |
return iPluginLoadError;
|
|
116 |
}
|
|
117 |
|
|
118 |
// ---------------------------------------------------------------------------
|
|
119 |
//
|
|
120 |
// ---------------------------------------------------------------------------
|
|
121 |
TFSMailMsgId FsMsgId( const CPluginData& aPluginData, const EmailInterface::TBaseId& aId )
|
|
122 |
{
|
|
123 |
TFSMailMsgId id( aPluginData.Uid(), aId.iId );
|
|
124 |
return id;
|
|
125 |
}
|
|
126 |
|
|
127 |
// ---------------------------------------------------------------------------
|
|
128 |
//
|
|
129 |
// ---------------------------------------------------------------------------
|
|
130 |
void CleanupReleasePush::PushL( EmailInterface::MEmailInterface& aItem )
|
|
131 |
{
|
|
132 |
TCleanupItem item( &CleanupReleasePush::Release, &aItem );
|
|
133 |
CleanupStack::PushL( item );
|
|
134 |
}
|
|
135 |
|
|
136 |
// ---------------------------------------------------------------------------
|
|
137 |
//
|
|
138 |
// ---------------------------------------------------------------------------
|
|
139 |
void CleanupReleasePush::Release( TAny *aPtr )
|
|
140 |
{
|
|
141 |
reinterpret_cast<EmailInterface::MEmailInterface*>( aPtr )->Release();
|
|
142 |
}
|
|
143 |
|
|
144 |
// End of file
|