|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : sipplugindirector |
|
15 // Part of : sip agent server |
|
16 // implementation |
|
17 // Version : 1.0 |
|
18 // |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include "sipplugindirector.h" |
|
25 #include "sipprofileagent.h" |
|
26 #include "sipprofileagentinitparams.h" |
|
27 #include "SipProfileLog.h" |
|
28 #include <sipprofileagentextensionparams.h> |
|
29 |
|
30 const TInt KPluginMicroSecInSec = 1; |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS =============================== |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CSIPPluginDirector::CSIPPluginDirector |
|
36 // C++ default constructor can NOT contain any code, that |
|
37 // might leave. |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CSIPPluginDirector::CSIPPluginDirector(MSIPProfileAgentObserver& aObserver) |
|
41 : iProfileAgentObserver(aObserver), |
|
42 iDeltaTimerCallBack(CleanupTimerExpired, this) |
|
43 { |
|
44 TUid KSIPProfileServerUid = {0x0}; |
|
45 iServerId = KSIPProfileServerUid; |
|
46 iDeltaTimerEntry.Set(iDeltaTimerCallBack); |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CSIPPluginDirector::ConstructL |
|
51 // Symbian 2nd phase constructor can leave. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 void CSIPPluginDirector::ConstructL() |
|
55 { |
|
56 iDeltaTimer = CDeltaTimer::NewL(CActive::EPriorityStandard); |
|
57 iConfigExtension = CSipProfileAgentConfigExtension::NewL(); |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CSIPPluginDirector::NewLC |
|
62 // Two-phased constructor. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CSIPPluginDirector* CSIPPluginDirector::NewLC( |
|
66 MSIPProfileAgentObserver& aObserver) |
|
67 { |
|
68 CSIPPluginDirector* self = new(ELeave)CSIPPluginDirector(aObserver); |
|
69 CleanupStack::PushL(self); |
|
70 self->ConstructL(); |
|
71 return self; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CSIPPluginDirector::NewL |
|
76 // Two-phased constructor. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CSIPPluginDirector* CSIPPluginDirector::NewL( |
|
80 MSIPProfileAgentObserver& aObserver) |
|
81 { |
|
82 CSIPPluginDirector* self = CSIPPluginDirector::NewLC(aObserver); |
|
83 CleanupStack::Pop(self); |
|
84 return self; |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CSIPPluginDirector::~CSIPPluginDirector |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CSIPPluginDirector::~CSIPPluginDirector() |
|
92 { |
|
93 iSIPProfileAgents.ResetAndDestroy(); |
|
94 delete iDeltaTimer; |
|
95 delete iConfigExtension; |
|
96 REComSession::FinalClose(); |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CSIPPluginDirector::FindImplementation |
|
101 // (other items were commented in a header). |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 CSIPProfileAgent* CSIPPluginDirector::FindImplementation( |
|
105 const TSIPProfileTypeInfo& aType) |
|
106 { |
|
107 PROFILE_DEBUG6("CSIPPluginDirector::FindImplementation", |
|
108 aType.iSIPProfileName) |
|
109 for (TInt i=0; i < iSIPProfileAgents.Count(); i++) |
|
110 { |
|
111 if (iSIPProfileAgents[i]->Type().iSIPProfileName == |
|
112 aType.iSIPProfileName && |
|
113 iSIPProfileAgents[i]->Type().iSIPProfileClass == |
|
114 aType.iSIPProfileClass) |
|
115 { |
|
116 return iSIPProfileAgents[i]; |
|
117 } |
|
118 |
|
119 } |
|
120 PROFILE_DEBUG2("CSIPPluginDirector::FindImplementation", "Not found!") |
|
121 return NULL; |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CSIPPluginDirector::CreateImplementationL |
|
126 // (other items were commented in a header). |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 CSIPProfileAgent& CSIPPluginDirector::CreateImplementationL( |
|
130 const TSIPProfileTypeInfo& aType) |
|
131 { |
|
132 PROFILE_DEBUG6("CSIPPluginDirector::CreateImplementationL", |
|
133 aType.iSIPProfileName) |
|
134 TSIPProfileAgentInitParams initParams(*iDeltaTimer, |
|
135 iProfileAgentObserver); |
|
136 TBuf8<30> plugin; |
|
137 plugin.Format(_L8("%u_"), aType.iSIPProfileClass); |
|
138 plugin.Append(aType.iSIPProfileName); |
|
139 |
|
140 CSIPProfileAgent* sipProfileAgent = |
|
141 CSIPProfileAgent::NewL(plugin,initParams); |
|
142 CleanupStack::PushL( sipProfileAgent); |
|
143 sipProfileAgent->Extension(KSipProfileAgentConfigExtension, |
|
144 iConfigExtension); |
|
145 User::LeaveIfError(iSIPProfileAgents.Append(sipProfileAgent)); |
|
146 CleanupStack::Pop(sipProfileAgent); |
|
147 return *sipProfileAgent; |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CSIPPluginDirector::ProvideImplementationL |
|
152 // provides correct implementation |
|
153 // (other items were commented in a header). |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 CSIPProfileAgent& CSIPPluginDirector::ProvideImplementationL( |
|
157 const TSIPProfileTypeInfo& aType) |
|
158 { |
|
159 PROFILE_DEBUG6("CSIPPluginDirector::ProvideImplementationL", aType.iSIPProfileName) |
|
160 |
|
161 CSIPProfileAgent* implementation = FindImplementation(aType); |
|
162 if (implementation) |
|
163 return *implementation; |
|
164 else |
|
165 return CreateImplementationL(aType); |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CSIPPluginDirector::DeltaTimer |
|
170 // returns iDeltaTimer as reference |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 CDeltaTimer& CSIPPluginDirector::DeltaTimer() |
|
174 { |
|
175 return *iDeltaTimer; |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CSIPPluginDirector::RegisterL |
|
180 // registers profile |
|
181 // (other items were commented in a header). |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 void CSIPPluginDirector::RegisterL( |
|
185 CSIPConcreteProfile& aSIPProfile) |
|
186 { |
|
187 PROFILE_DEBUG3("CSIPPluginDirector::RegisterL", aSIPProfile.Id()) |
|
188 ProvideImplementationL(aSIPProfile.ProfileType()).RegisterL(aSIPProfile); |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CSIPPluginDirector::DeregisterL |
|
193 // deregisters profile |
|
194 // (other items were commented in a header). |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void CSIPPluginDirector::DeregisterL( |
|
198 CSIPConcreteProfile& aSIPProfile) |
|
199 { |
|
200 PROFILE_DEBUG3("CSIPPluginDirector::DeregisterL", aSIPProfile.Id()) |
|
201 CSIPProfileAgent* profileagent = FindImplementation(aSIPProfile.ProfileType()); |
|
202 |
|
203 __ASSERT_ALWAYS (profileagent, User::Leave(KErrArgument)); |
|
204 profileagent->DeregisterL(aSIPProfile); |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CSIPPluginDirector::UpdateRegistrationL |
|
209 // deregisters profile |
|
210 // (other items were commented in a header). |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 void CSIPPluginDirector::UpdateRegistrationL( |
|
214 CSIPConcreteProfile& aNewProfile, |
|
215 CSIPConcreteProfile& aOldProfile) |
|
216 { |
|
217 PROFILE_DEBUG3("CSIPPluginDirector::UpdateRegistrationL", aNewProfile.Id()) |
|
218 __ASSERT_ALWAYS(aNewProfile.Id() == aOldProfile.Id(), |
|
219 User::Leave(KErrArgument)); |
|
220 CSIPProfileAgent* profileagent = FindImplementation(aOldProfile.ProfileType()); |
|
221 __ASSERT_ALWAYS(profileagent, User::Leave(KErrArgument)); |
|
222 profileagent->UpdateL(aNewProfile, aOldProfile); |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CSIPPluginDirector::ListImplementationsL |
|
227 // Lists all implementations |
|
228 // (other items were commented in a header). |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 void CSIPPluginDirector::ListImplementationsL( |
|
232 RImplInfoPtrArray& aImplementations) |
|
233 { |
|
234 PROFILE_DEBUG1("CSIPPluginDirector::ListImplementationsL") |
|
235 CSIPProfileAgent::ListAllImplementationsL(aImplementations); |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CSIPPluginDirector::IsRegisterPending |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 TBool CSIPPluginDirector::IsRegisterPending(CSIPConcreteProfile& aSIPProfile) |
|
243 { |
|
244 PROFILE_DEBUG3("CSIPPluginDirector::IsRegisterPending", aSIPProfile.Id()) |
|
245 CSIPProfileAgent* implementation = |
|
246 FindImplementation(aSIPProfile.ProfileType()); |
|
247 if (implementation) |
|
248 { |
|
249 return implementation->RegisterPending(aSIPProfile); |
|
250 } |
|
251 return EFalse; |
|
252 } |
|
253 |
|
254 // ----------------------------------------------------------------------------- |
|
255 // CSIPPluginDirector::State |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 TInt CSIPPluginDirector::State(CSIPConcreteProfile::TStatus& aStatus, |
|
259 CSIPConcreteProfile& aSIPProfile) |
|
260 { |
|
261 TInt err(KErrNotFound); |
|
262 aStatus = CSIPConcreteProfile::EUnregistered; |
|
263 CSIPProfileAgent* implementation = |
|
264 FindImplementation(aSIPProfile.ProfileType()); |
|
265 if (implementation) |
|
266 { |
|
267 err = implementation->GetProfileState(aStatus, aSIPProfile); |
|
268 } |
|
269 return err; |
|
270 } |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CSIPPluginDirector::TerminateHandling |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 TInt CSIPPluginDirector::TerminateHandling(CSIPConcreteProfile& aSIPProfile) |
|
277 { |
|
278 CSIPProfileAgent* implementation = |
|
279 FindImplementation(aSIPProfile.ProfileType()); |
|
280 if (implementation) |
|
281 { |
|
282 return implementation->TerminateHandling(aSIPProfile); |
|
283 } |
|
284 return KErrNotFound; |
|
285 } |
|
286 |
|
287 // ----------------------------------------------------------------------------- |
|
288 // CSIPPluginDirector::Cleanup |
|
289 // initiate cleanup; idle agent will be deleted |
|
290 // (other items were commented in a header). |
|
291 // ----------------------------------------------------------------------------- |
|
292 // |
|
293 void CSIPPluginDirector::Cleanup() |
|
294 { |
|
295 CSIPProfileAgent* agent; |
|
296 |
|
297 for (TInt i=iSIPProfileAgents.Count()-1; i >= 0; i-- ) |
|
298 { |
|
299 agent = iSIPProfileAgents[i]; |
|
300 if ( agent->IsIdle() ) |
|
301 { |
|
302 iSIPProfileAgents.Remove(i); |
|
303 delete agent; |
|
304 agent = 0; |
|
305 }//if |
|
306 |
|
307 }//for |
|
308 } |
|
309 |
|
310 // ----------------------------------------------------------------------------- |
|
311 // CSIPPluginDirector::StartTimerForCleanup |
|
312 // ----------------------------------------------------------------------------- |
|
313 // |
|
314 void CSIPPluginDirector::StartTimerForCleanup () |
|
315 { |
|
316 PROFILE_DEBUG1("CSIPPluginDirector::StartTimerForCleanup") |
|
317 iDeltaTimer->Remove(iDeltaTimerEntry); |
|
318 TTimeIntervalMicroSeconds32 interval(KPluginMicroSecInSec); |
|
319 iDeltaTimer->Queue(interval, iDeltaTimerEntry); |
|
320 } |
|
321 |
|
322 // ----------------------------------------------------------------------------- |
|
323 // CSIPPluginDirector::CleanupTimerExpired |
|
324 // ----------------------------------------------------------------------------- |
|
325 // |
|
326 TInt CSIPPluginDirector::CleanupTimerExpired(TAny* aPtr) |
|
327 { |
|
328 PROFILE_DEBUG1("CSIPPluginDirector::CleanupTimerExpired") |
|
329 CSIPPluginDirector* self = reinterpret_cast<CSIPPluginDirector*>(aPtr); |
|
330 self->Cleanup(); |
|
331 return ETrue; |
|
332 } |
|
333 |
|
334 // ----------------------------------------------------------------------------- |
|
335 // CSIPPluginDirector::CreateProfileL |
|
336 // ----------------------------------------------------------------------------- |
|
337 // |
|
338 CSIPConcreteProfile* CSIPPluginDirector::CreateProfileL ( |
|
339 const TSIPProfileTypeInfo& aType) |
|
340 { |
|
341 PROFILE_DEBUG1("CSIPPluginDirector::CreateProfileL") |
|
342 return ProvideImplementationL(aType).CreateL(); |
|
343 } |