|
1 /* |
|
2 * Copyright (c) 2004 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: Presence attribute constructor container. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CPEngAttrConstructorCon.h" |
|
20 #include "CPEngSessionSlotObject.h" |
|
21 #include "CPEngPresenceAttrConstructor.h" |
|
22 #include "MPEngPresenceAttrConstructorTypeImp.h" |
|
23 |
|
24 #include <E32Std.h> |
|
25 |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS =============================== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CPEngAttrConstructorCon::NewL() |
|
31 // Two-phased constructor. |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CPEngAttrConstructorCon* CPEngAttrConstructorCon::NewL( CPEngSessionSlotObject& aOwner ) |
|
35 { |
|
36 CPEngAttrConstructorCon* self = new( ELeave ) CPEngAttrConstructorCon( aOwner ); |
|
37 return self; |
|
38 } |
|
39 |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CPEngAttrConstructorCon::CPEngAttrConstructorCon |
|
43 // C++ default constructor can NOT contain any code, that |
|
44 // might leave. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CPEngAttrConstructorCon::CPEngAttrConstructorCon( CPEngSessionSlotObject& aOwner ) |
|
48 : iOwner( aOwner ) |
|
49 { |
|
50 } |
|
51 |
|
52 |
|
53 // Destructor |
|
54 CPEngAttrConstructorCon::~CPEngAttrConstructorCon() |
|
55 { |
|
56 iConstructors.ResetAndDestroy(); |
|
57 } |
|
58 |
|
59 |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CPEngAttrConstructorCon::AddConstructorL() |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void CPEngAttrConstructorCon::AddConstructorL( |
|
66 MPEngPresenceAttrConstructorTypeImp* aTypeConstructor, |
|
67 TUint32 aType, |
|
68 TPEngAttributeOriginator aOrigin ) |
|
69 { |
|
70 CPEngPresenceAttrConstructor* constructor = NULL; |
|
71 |
|
72 TRAPD( err, |
|
73 constructor = CPEngPresenceAttrConstructor::NewL( *this, |
|
74 *aTypeConstructor, |
|
75 aType, |
|
76 aOrigin ) ); |
|
77 if ( err != KErrNone ) |
|
78 { |
|
79 delete aTypeConstructor; |
|
80 User::Leave( err ); |
|
81 } |
|
82 |
|
83 |
|
84 CleanupStack::PushL( constructor ); |
|
85 __AssertConstructorValidL( *constructor ); |
|
86 iConstructors.AppendL( constructor ); |
|
87 |
|
88 CleanupStack::Pop( constructor ); |
|
89 } |
|
90 |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CPEngAttrConstructorCon::FindByType() |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 CPEngPresenceAttrConstructor* CPEngAttrConstructorCon::FindByType( TUint32 aType ) |
|
97 { |
|
98 const TInt count = iConstructors.Count(); |
|
99 for ( TInt ii( 0 ); ii < count ; ii++ ) |
|
100 { |
|
101 CPEngPresenceAttrConstructor* constructor = iConstructors[ ii ]; |
|
102 if ( constructor->iType == aType ) |
|
103 { |
|
104 return constructor; |
|
105 } |
|
106 } |
|
107 |
|
108 return NULL; |
|
109 } |
|
110 |
|
111 |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CPEngAttrConstructorCon::FindByTypeL() |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 CPEngPresenceAttrConstructor& CPEngAttrConstructorCon::FindByTypeL( TUint32 aType ) |
|
118 { |
|
119 CPEngPresenceAttrConstructor* constructor = FindByType( aType ); |
|
120 if ( !constructor ) |
|
121 { |
|
122 User::Leave( KErrUnknown ); |
|
123 } |
|
124 |
|
125 return *constructor; |
|
126 } |
|
127 |
|
128 |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CPEngAttrConstructorCon::TypeArray() |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 TArray<TUint32> CPEngAttrConstructorCon::TypeArray() const |
|
135 { |
|
136 return TArray<TUint32>( GetTypeCount, GetTypePtr, ( const CBase* ) this ); |
|
137 } |
|
138 |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CPEngAttrConstructorCon::OpenRef() |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 void CPEngAttrConstructorCon::OpenRef() |
|
145 { |
|
146 //Simply forward the open and close requests to owner |
|
147 |
|
148 iOwner.Open(); // CSI: 15,65 # |
|
149 } |
|
150 |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CPEngAttrConstructorCon::CloseRef() |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 void CPEngAttrConstructorCon::CloseRef() |
|
157 { |
|
158 //Simply forward the open and close requests to owner |
|
159 |
|
160 iOwner.Close(); |
|
161 } |
|
162 |
|
163 |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CPEngAttrConstructorCon::__AssertConstructorValidL() |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 void CPEngAttrConstructorCon::__AssertConstructorValidL( |
|
170 const CPEngPresenceAttrConstructor& aConstructor ) |
|
171 { |
|
172 //Check that each model type ID is unique |
|
173 __ASSERT_ALWAYS( !FindByType( aConstructor.iType ), |
|
174 aConstructor.__DbgPanicL( EPEngAttributeTypeIDNotUnique, |
|
175 KErrAlreadyExists ) ); |
|
176 |
|
177 |
|
178 //Check attribute XML properties |
|
179 TPtrC8 name( NULL, 0 ); |
|
180 TPtrC8 nameSpace( NULL, 0 ); |
|
181 TInt err = aConstructor.GetCurrentXmlNames( name, nameSpace ); |
|
182 |
|
183 if ( aConstructor.Originator() == EPEngLocalAttribute ) |
|
184 { |
|
185 __ASSERT_ALWAYS( ( name.Length() == 0 ) && ( nameSpace.Length() == 0 ), |
|
186 aConstructor.__DbgPanicL( EPEngLocalAttributeTypeProperties, |
|
187 KErrGeneral ) ); |
|
188 __ASSERT_ALWAYS( ( err == KErrArgument ), |
|
189 aConstructor.__DbgPanicL( EPEngLocalAttributeTypeProperties, |
|
190 KErrGeneral ) ); |
|
191 |
|
192 } |
|
193 else |
|
194 { |
|
195 User::LeaveIfError( err ); |
|
196 |
|
197 __ASSERT_ALWAYS( ( name.Length() > 0 ) && ( nameSpace.Length() > 0 ), |
|
198 aConstructor.__DbgPanicL( EPEngNetworAttributeTypeProperties, |
|
199 KErrGeneral ) ); |
|
200 } |
|
201 } |
|
202 |
|
203 |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CPEngAttrConstructorCon::GetTypeCount() |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 TInt CPEngAttrConstructorCon::GetTypeCount( const CBase* aPtr ) |
|
210 { |
|
211 const CPEngAttrConstructorCon* self = static_cast<const CPEngAttrConstructorCon*>( aPtr ); |
|
212 return self->iConstructors.Count(); |
|
213 } |
|
214 |
|
215 |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CPEngAttrConstructorCon::GetTypePtr() |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 const TAny* CPEngAttrConstructorCon::GetTypePtr( const CBase* aPtr, TInt aIndex ) |
|
222 { |
|
223 const CPEngAttrConstructorCon* self = static_cast<const CPEngAttrConstructorCon*>( aPtr ); |
|
224 return &( ( self->iConstructors )[ aIndex ]->iType ); |
|
225 } |
|
226 |
|
227 |
|
228 |
|
229 // End of File |