|
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 : sipalrmonitor.cpp |
|
15 // Part of : SIP / SIP ALR Monitor |
|
16 // Version : SIP/6.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "sipalrobserver.h" |
|
22 #include "sipalrmonitor.h" |
|
23 #include "../../Profile/Inc/SipProfileLog.h" |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CSipAlrMonitor::NewL |
|
27 // ----------------------------------------------------------------------------- |
|
28 // |
|
29 CSipAlrMonitor* CSipAlrMonitor::NewL( |
|
30 CSipSystemStateMonitor& aSystemStateMonitor) |
|
31 { |
|
32 CSipAlrMonitor* self = new(ELeave)CSipAlrMonitor(aSystemStateMonitor); |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CSipAlrMonitor::CSipAlrMonitor |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CSipAlrMonitor::CSipAlrMonitor(CSipSystemStateMonitor& aSystemStateMonitor) : |
|
44 iSystemStateMonitor(aSystemStateMonitor) |
|
45 { |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CSipAlrMonitor::ConstructL |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 void CSipAlrMonitor::ConstructL() |
|
53 { |
|
54 User::LeaveIfError ( iSocketServer.Connect() ); |
|
55 PROFILE_DEBUG1("CSipAlrMonitor::ConstructL") |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CSipAlrMonitor::~CSipAlrMonitor |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CSipAlrMonitor::~CSipAlrMonitor() |
|
63 { |
|
64 iSocketServer.Close(); |
|
65 iSnapMonitors.ResetAndDestroy(); |
|
66 |
|
67 PROFILE_DEBUG1("CSipAlrMonitor::~CSipAlrMonitor") |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CSipAlrMonitor::RefreshIapAvailabilityL |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 void CSipAlrMonitor::RefreshIapAvailabilityL ( TUint32 aSnapId ) |
|
75 { |
|
76 PROFILE_DEBUG3( "CSipAlrMonitorImplementation::RefreshIapAvailabilityL", |
|
77 aSnapId ) |
|
78 |
|
79 CSipAlrSnapMonitor* monitor = FindSnapMonitor( aSnapId ); |
|
80 if ( monitor ) |
|
81 { |
|
82 monitor->RefreshL(); |
|
83 } |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CSipAlrMonitor::AllowMigration |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 TInt CSipAlrMonitor::AllowMigration( TUint32 aSnapId ) |
|
91 { |
|
92 PROFILE_DEBUG3("CSipAlrMonitor::AllowMigration, SnapId",aSnapId) |
|
93 |
|
94 CSipAlrSnapMonitor* monitor = FindSnapMonitor( aSnapId ); |
|
95 if ( monitor ) |
|
96 { |
|
97 monitor->AllowMigration(); |
|
98 return KErrNone; |
|
99 } |
|
100 return KErrNotFound; |
|
101 } |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CSipAlrMonitor::DisallowMigration |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 TInt CSipAlrMonitor::DisallowMigration( TUint32 aSnapId ) |
|
107 { |
|
108 PROFILE_DEBUG3("CSipAlrMonitor::DisallowMigration, SnapId",aSnapId) |
|
109 |
|
110 CSipAlrSnapMonitor* monitor = FindSnapMonitor( aSnapId ); |
|
111 if ( monitor ) |
|
112 { |
|
113 monitor->DisallowMigration(); |
|
114 return KErrNone; |
|
115 } |
|
116 return KErrNotFound; |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CSipAlrMonitor::NewIapAccepted |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 TInt CSipAlrMonitor::NewIapAccepted( TUint32 aSnapId ) |
|
124 { |
|
125 PROFILE_DEBUG3("CSipAlrMonitor::NewIapAccepted, SnapId",aSnapId) |
|
126 |
|
127 CSipAlrSnapMonitor* monitor = FindSnapMonitor( aSnapId ); |
|
128 if ( monitor ) |
|
129 { |
|
130 monitor->NewIapAccepted(); |
|
131 return KErrNone; |
|
132 } |
|
133 return KErrNotFound; |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CSipAlrMonitor::NewIapRejected |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 TInt CSipAlrMonitor::NewIapRejected( TUint32 aSnapId ) |
|
141 { |
|
142 PROFILE_DEBUG3( "CSipAlrMonitor::NewIapRejected, SnapId",aSnapId ) |
|
143 |
|
144 CSipAlrSnapMonitor* monitor = FindSnapMonitor( aSnapId ); |
|
145 if ( monitor ) |
|
146 { |
|
147 monitor->NewIapRejected(); |
|
148 return KErrNone; |
|
149 } |
|
150 return KErrNotFound; |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CSipAlrMonitor::MonitorSnapL |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 void CSipAlrMonitor::MonitorSnapL( |
|
158 TUint32 aSnapId, |
|
159 MSipAlrObserver& aObserver ) |
|
160 { |
|
161 PROFILE_DEBUG4( "CSipAlrMonitor::MonitorSnapL", |
|
162 aSnapId, reinterpret_cast< TUint >( &aObserver ) ) |
|
163 |
|
164 CSipAlrSnapMonitor* monitor = FindSnapMonitor( aSnapId ); |
|
165 if ( monitor ) |
|
166 { |
|
167 // Monitor exists, add observer and get current IAP availability |
|
168 monitor->AddObserverL(aObserver); |
|
169 monitor->RefreshL(); |
|
170 |
|
171 PROFILE_DEBUG1("CSipAlrMonitor::MonitorSnapL: observer added" ) |
|
172 } |
|
173 else |
|
174 { |
|
175 monitor = CSipAlrSnapMonitor::NewLC( |
|
176 aSnapId, aObserver, iSocketServer, iSystemStateMonitor ); |
|
177 iSnapMonitors.AppendL( monitor ); |
|
178 CleanupStack::Pop( monitor ); |
|
179 |
|
180 PROFILE_DEBUG1("CSipAlrMonitor::MonitorSnapL: new monitor created" ) |
|
181 } |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CSipAlrMonitor::FreeResources |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 void CSipAlrMonitor::FreeResources ( MSipAlrObserver& aObserver ) |
|
189 { |
|
190 for ( TInt i = iSnapMonitors.Count()-1; i >= 0; i-- ) |
|
191 { |
|
192 TBool last = iSnapMonitors[i]->DetachObserver ( aObserver ); |
|
193 if ( last ) |
|
194 { |
|
195 delete iSnapMonitors[i]; |
|
196 iSnapMonitors.Remove ( i ); |
|
197 PROFILE_DEBUG1( "CSipAlrMonitor::FreeResources monitor deleted" ) |
|
198 } |
|
199 } |
|
200 } |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CSipAlrMonitor::FindSnapMonitor |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 CSipAlrSnapMonitor* CSipAlrMonitor::FindSnapMonitor( TUint32 aSnapId ) |
|
207 { |
|
208 CSipAlrSnapMonitor* monitor = NULL; |
|
209 for ( TInt i = 0; i < iSnapMonitors.Count() && !monitor; i++ ) |
|
210 { |
|
211 if ( iSnapMonitors[i]->SnapId() == aSnapId ) |
|
212 { |
|
213 monitor = iSnapMonitors[i]; |
|
214 } |
|
215 } |
|
216 return monitor; |
|
217 } |