|
1 /* |
|
2 * Copyright (c) 2009 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: email internal extension base class |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cemailextensionbase.h" |
|
19 #include "emailtrace.h" |
|
20 |
|
21 /** |
|
22 * |
|
23 */ |
|
24 enum TEmailFwPanic { |
|
25 EEmailExtensionIndexOutOfRange |
|
26 }; |
|
27 |
|
28 _LIT( KEmailExtensionPanic, "EmailFw" ); |
|
29 |
|
30 void Panic( TEmailFwPanic aPanic ) |
|
31 { |
|
32 FUNC_LOG; |
|
33 User::Panic( KEmailExtensionPanic, aPanic ); |
|
34 } |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // c++ constructor |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 EXPORT_C CEmailExtension::CEmailExtension( const TUid& aUid ) : |
|
41 iUid( TUid::Uid(aUid.iUid ) ) |
|
42 { |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 EXPORT_C CEmailExtension::~CEmailExtension() |
|
50 { |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 EXPORT_C TUid CEmailExtension::Uid() const |
|
58 { |
|
59 return iUid; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 TUint CEmailExtension::DecRef() |
|
67 { |
|
68 if ( iRefCount ) |
|
69 { |
|
70 iRefCount--; |
|
71 } |
|
72 return iRefCount; |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 void CEmailExtension::IncRef() |
|
80 { |
|
81 ++iRefCount; |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // deletes extension and removes it from extension array |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 EXPORT_C void CExtendableEmail::ReleaseExtension( CEmailExtension* aExtension ) |
|
89 { |
|
90 FUNC_LOG; |
|
91 if ( !aExtension->DecRef() ) |
|
92 { |
|
93 iExtensions.Remove( aExtension ); |
|
94 delete aExtension; |
|
95 } |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // Finds and returns extension |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 EXPORT_C CEmailExtension* CExtendableEmail::ExtensionL( const TUid& aInterfaceUid ) |
|
103 { |
|
104 FUNC_LOG; |
|
105 TInt index = iExtensions.FindExtension( aInterfaceUid ); |
|
106 CEmailExtension* ext = NULL; |
|
107 if ( index != KErrNotFound ) |
|
108 { |
|
109 ext = iExtensions.Extension( index ); |
|
110 ext->IncRef(); |
|
111 } |
|
112 return ext; |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // destructor |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 EXPORT_C TEmailExtensions::~TEmailExtensions() |
|
120 { |
|
121 iExtensions.Close(); |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // c++ constructor |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 EXPORT_C TEmailExtensions::TEmailExtensions() : iExtensions( 1 ) |
|
129 { |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // returns index of extension in extension array |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 EXPORT_C TInt TEmailExtensions::FindExtension( const TUid& aUid ) const |
|
137 { |
|
138 TInt index = KErrNotFound; |
|
139 for ( TInt i = 0; i < iExtensions.Count(); i++ ) |
|
140 { |
|
141 const CEmailExtension* tested = iExtensions[i]; |
|
142 if ( aUid == tested->Uid() ) |
|
143 { |
|
144 index = i; |
|
145 break; |
|
146 } |
|
147 } |
|
148 return index; |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // Returns extension by index. Panics if index is out of range. |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 EXPORT_C CEmailExtension* TEmailExtensions::Extension( const TInt aIndex ) const |
|
156 { |
|
157 __ASSERT_ALWAYS( aIndex>=0 && aIndex < iExtensions.Count(), |
|
158 Panic( EEmailExtensionIndexOutOfRange ) ); |
|
159 return iExtensions[aIndex]; |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 EXPORT_C void TEmailExtensions::AddL( CEmailExtension* aExtension ) |
|
167 { |
|
168 FUNC_LOG; |
|
169 if ( !aExtension ) |
|
170 { |
|
171 User::Leave( KErrArgument ); |
|
172 } |
|
173 CleanupStack::PushL( aExtension ); |
|
174 iExtensions.AppendL( aExtension ); |
|
175 CleanupStack::Pop(); |
|
176 aExtension->IncRef(); |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------------------------- |
|
180 // Removes extension from array |
|
181 // --------------------------------------------------------------------------- |
|
182 // |
|
183 EXPORT_C void TEmailExtensions::Remove( |
|
184 const CEmailExtension* aExtension ) |
|
185 { |
|
186 FUNC_LOG; |
|
187 const TInt index( FindExtension( aExtension->Uid() ) ); |
|
188 if ( index != KErrNotFound ) |
|
189 { |
|
190 iExtensions.Remove( index ); |
|
191 } |
|
192 } |
|
193 |
|
194 // End of file |