|
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 CEmailExtension::CEmailExtension( const TUid& aUid ) : |
|
41 iUid( TUid::Uid(aUid.iUid ) ) |
|
42 { |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CEmailExtension::~CEmailExtension() |
|
50 { |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 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 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 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 //<qmail> |
|
116 // --------------------------------------------------------------------------- |
|
117 // Constructor is required for sbs2 to generate the same .defs for urel/udeb |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 CExtendableEmail::CExtendableEmail() |
|
121 { |
|
122 FUNC_LOG; |
|
123 } |
|
124 //</qmail> |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // destructor |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 TEmailExtensions::~TEmailExtensions() |
|
131 { |
|
132 iExtensions.Close(); |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // c++ constructor |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 TEmailExtensions::TEmailExtensions() : iExtensions( 1 ) |
|
140 { |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // returns index of extension in extension array |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 TInt TEmailExtensions::FindExtension( const TUid& aUid ) const |
|
148 { |
|
149 TInt index = KErrNotFound; |
|
150 for ( TInt i = 0; i < iExtensions.Count(); i++ ) |
|
151 { |
|
152 const CEmailExtension* tested = iExtensions[i]; |
|
153 if ( aUid == tested->Uid() ) |
|
154 { |
|
155 index = i; |
|
156 break; |
|
157 } |
|
158 } |
|
159 return index; |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // Returns extension by index. Panics if index is out of range. |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 CEmailExtension* TEmailExtensions::Extension( const TInt aIndex ) const |
|
167 { |
|
168 __ASSERT_ALWAYS( aIndex>=0 && aIndex < iExtensions.Count(), |
|
169 Panic( EEmailExtensionIndexOutOfRange ) ); |
|
170 return iExtensions[aIndex]; |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 void TEmailExtensions::AddL( CEmailExtension* aExtension ) |
|
178 { |
|
179 FUNC_LOG; |
|
180 if ( !aExtension ) |
|
181 { |
|
182 User::Leave( KErrArgument ); |
|
183 } |
|
184 CleanupStack::PushL( aExtension ); |
|
185 iExtensions.AppendL( aExtension ); |
|
186 CleanupStack::Pop(); |
|
187 aExtension->IncRef(); |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // Removes extension from array |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 void TEmailExtensions::Remove( |
|
195 const CEmailExtension* aExtension ) |
|
196 { |
|
197 FUNC_LOG; |
|
198 const TInt index( FindExtension( aExtension->Uid() ) ); |
|
199 if ( index != KErrNotFound ) |
|
200 { |
|
201 iExtensions.Remove( index ); |
|
202 } |
|
203 } |
|
204 |
|
205 // End of file |