|
1 /* |
|
2 * Copyright (c) 2007 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "sipsystemstatemonitorimpl.h" |
|
21 #include "CSystemStateConnUsagePermissionMonitor.h" |
|
22 #include "sipdevicestateaware.h" |
|
23 #include "siprfsmonitorao.h" |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CSipSystemStateMonitorImpl::NewL |
|
27 // ----------------------------------------------------------------------------- |
|
28 // |
|
29 CSipSystemStateMonitorImpl* CSipSystemStateMonitorImpl::NewL() |
|
30 { |
|
31 CSipSystemStateMonitorImpl* self = |
|
32 new( ELeave )CSipSystemStateMonitorImpl(); |
|
33 CleanupStack::PushL( self ); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop( self ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CSipSystemStateMonitorImpl::ConstructL |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 void CSipSystemStateMonitorImpl::ConstructL() |
|
44 { |
|
45 iMonitorAo = CSipSystemStateMonitorAo::NewL(); |
|
46 iUsagePermissionMonitor = |
|
47 CSystemStateConnUsagePermissionMonitor::NewL(); |
|
48 iSipDeviceAwareObject = CSipDeviceStateAware::NewL(); |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CSipSystemStateMonitorImpl::CSipSystemStateMonitorImpl |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CSipSystemStateMonitorImpl::CSipSystemStateMonitorImpl() |
|
56 { |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CSipSystemStateMonitorImpl::~CSipSystemStateMonitorImpl |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CSipSystemStateMonitorImpl::~CSipSystemStateMonitorImpl() |
|
64 { |
|
65 delete iMonitorAo; |
|
66 iSnapMonitors.ResetAndDestroy(); |
|
67 delete iUsagePermissionMonitor; |
|
68 delete iRfsMonitor; |
|
69 delete iSipDeviceAwareObject; |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CSipSystemStateMonitorImpl::State |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 CSipSystemStateMonitor::TSystemState CSipSystemStateMonitorImpl::State() const |
|
77 { |
|
78 return iMonitorAo->State(); |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CSipSystemStateMonitorImpl::StartMonitoringL |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 void CSipSystemStateMonitorImpl::StartMonitoringL( |
|
86 TSystemVariable aVariable, |
|
87 TInt aObjectId, |
|
88 MSipSystemStateObserver& aObserver ) |
|
89 { |
|
90 if ( aVariable == ESystemState ) |
|
91 { |
|
92 iMonitorAo->AddObserverL( aObserver ); |
|
93 iSipDeviceAwareObject->AddObserverL( aObserver ); |
|
94 } |
|
95 else if ( aVariable == ESnapAvailability ) |
|
96 { |
|
97 CSipSnapAvailabilityMonitor* monitor = FindSnapMonitorById( aObjectId ); |
|
98 if ( !monitor ) |
|
99 { |
|
100 TInt permissionToUseNetwork = |
|
101 iUsagePermissionMonitor->CurrentUsagePermission(); |
|
102 User::LeaveIfError( permissionToUseNetwork ); |
|
103 monitor = CSipSnapAvailabilityMonitor::NewLC( |
|
104 aObjectId, permissionToUseNetwork, aObserver ); |
|
105 iUsagePermissionMonitor->AddObserverL( *monitor ); |
|
106 iSnapMonitors.AppendL( monitor ); |
|
107 CleanupStack::Pop( monitor ); |
|
108 } |
|
109 else |
|
110 { |
|
111 monitor->AddObserverL( aObserver ); |
|
112 } |
|
113 } |
|
114 else if ( aVariable == ERfsState ) |
|
115 { |
|
116 iRfsMonitor = iRfsMonitor?iRfsMonitor:CSipRfsMonitorAo::NewL(); |
|
117 iRfsMonitor->AddObserverL( aObserver ); |
|
118 } |
|
119 else |
|
120 { |
|
121 User::Leave( KErrNotSupported ); |
|
122 } |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CSipSystemStateMonitorImpl::StopMonitoring |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 void CSipSystemStateMonitorImpl::StopMonitoring( |
|
130 TSystemVariable aVariable, |
|
131 TInt aObjectId, |
|
132 MSipSystemStateObserver& aObserver ) |
|
133 { |
|
134 if ( aVariable == ESystemState ) |
|
135 { |
|
136 iMonitorAo->RemoveObserver( aObserver ); |
|
137 iSipDeviceAwareObject->RemoveObserver ( aObserver ); |
|
138 } |
|
139 else if ( aVariable == ESnapAvailability ) |
|
140 { |
|
141 CSipSnapAvailabilityMonitor* monitor = FindSnapMonitorById( aObjectId ); |
|
142 if ( monitor ) |
|
143 { |
|
144 iUsagePermissionMonitor->RemoveObserver( *monitor ); |
|
145 monitor->RemoveObserver( aObserver ); |
|
146 if ( !monitor->HasObservers() ) |
|
147 { |
|
148 iSnapMonitors.Remove( iSnapMonitors.Find( monitor ) ); |
|
149 delete monitor; |
|
150 } |
|
151 } |
|
152 } |
|
153 else if ( aVariable == ERfsState ) |
|
154 { |
|
155 if(iRfsMonitor) |
|
156 iRfsMonitor->RemoveObserver( aObserver ); |
|
157 } |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CSipSystemStateMonitorImpl::CurrentValue |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 TInt CSipSystemStateMonitorImpl::CurrentValue( |
|
165 TSystemVariable aVariable, |
|
166 TInt aObjectId ) const |
|
167 { |
|
168 if ( aVariable == ESystemState ) |
|
169 { |
|
170 return iMonitorAo->State(); |
|
171 } |
|
172 else if ( aVariable == ESnapAvailability ) |
|
173 { |
|
174 CSipSnapAvailabilityMonitor* monitor = FindSnapMonitorById( aObjectId ); |
|
175 if ( monitor ) |
|
176 { |
|
177 TInt permissionToUseNetwork = |
|
178 iUsagePermissionMonitor->CurrentUsagePermission(); |
|
179 if ( permissionToUseNetwork < 0 ) |
|
180 { |
|
181 return permissionToUseNetwork; |
|
182 } |
|
183 return permissionToUseNetwork && monitor->SnapAvailability(); |
|
184 } |
|
185 } |
|
186 else if ( aVariable == ERfsState ) |
|
187 { |
|
188 if(iRfsMonitor) |
|
189 iRfsMonitor->State(); |
|
190 } |
|
191 return KErrNotFound; |
|
192 } |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // CSipSystemStateMonitorImpl::EventProcessingCompleted |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 void CSipSystemStateMonitorImpl::EventProcessingCompleted( |
|
199 TSystemVariable aVariable, |
|
200 TInt /*aObjectId*/, |
|
201 MSipSystemStateObserver& aObserver) |
|
202 { |
|
203 if ( iRfsMonitor && aVariable == ERfsState ) |
|
204 { |
|
205 iRfsMonitor->EventProcessingCompleted(aObserver); |
|
206 } |
|
207 else if ( iSipDeviceAwareObject && aVariable == ESystemState ) |
|
208 { |
|
209 iSipDeviceAwareObject->EventProcessingCompleted(aObserver); |
|
210 } |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // CSipSystemStateMonitorImpl::FindSnapMonitorById |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 CSipSnapAvailabilityMonitor* CSipSystemStateMonitorImpl::FindSnapMonitorById( |
|
218 TInt aSnapId ) const |
|
219 { |
|
220 CSipSnapAvailabilityMonitor* monitor = NULL; |
|
221 for ( TInt i=0; i < iSnapMonitors.Count() && !monitor; i++ ) |
|
222 { |
|
223 CSipSnapAvailabilityMonitor* tmp = iSnapMonitors[i]; |
|
224 if ( tmp->SnapId() == aSnapId ) |
|
225 { |
|
226 monitor = tmp; |
|
227 } |
|
228 } |
|
229 return monitor; |
|
230 } |