|
1 /* |
|
2 * Copyright (c) 2006-2008 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: CSensrvChannelFinderImpl implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "sensrvchannelfinderimpl.h" |
|
20 #include "sensrvchannelchangehandler.h" |
|
21 #include "sensrvtrace.h" |
|
22 |
|
23 const TInt KDefaultChannelCount = 10; |
|
24 |
|
25 |
|
26 // ======== MEMBER FUNCTIONS ======== |
|
27 |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // C++ constructor |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CSensrvChannelFinderImpl::CSensrvChannelFinderImpl() |
|
34 { |
|
35 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelFinderImpl::CSensrvChannelFinderImpl()" ) ) ); |
|
36 } |
|
37 |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // 2nd phase of construction |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 void CSensrvChannelFinderImpl::ConstructL() |
|
44 { |
|
45 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelFinderImpl::ConstructL() - Start" ) ) ); |
|
46 |
|
47 User::LeaveIfError( iSensrvClient.Connect() ); |
|
48 |
|
49 iChannelChangeHandler = CSensrvChannelChangeHandler::NewL( iSensrvClient ); |
|
50 |
|
51 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelFinderImpl::ConstructL() - Return" ) ) ); |
|
52 } |
|
53 |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // Destructor |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 CSensrvChannelFinderImpl::~CSensrvChannelFinderImpl() |
|
60 { |
|
61 delete iChannelChangeHandler; |
|
62 iSensrvClient.Close(); |
|
63 } |
|
64 |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // CSensrvChannelFinderImpl::FindChannelsL |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 void CSensrvChannelFinderImpl::FindChannelsL( |
|
71 RSensrvChannelInfoList& aChannelList, |
|
72 const TSensrvChannelInfo& aSearchConditions ) |
|
73 { |
|
74 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelFinderImpl::FindChannelsL() - Start" ) ) ); |
|
75 |
|
76 // Create condition buffer |
|
77 TSensrvChannelInfoPckgBuf searchConditionsBuf( aSearchConditions ); |
|
78 |
|
79 // Create channel info array |
|
80 RSensrvChannelInfoList channelInfoList(KDefaultChannelCount); |
|
81 CleanupClosePushL( channelInfoList ); |
|
82 |
|
83 for( TInt i = 0; i < KDefaultChannelCount; i++ ) |
|
84 { |
|
85 channelInfoList.AppendL( TSensrvChannelInfo() ); |
|
86 } |
|
87 |
|
88 TInt arraySize = ( sizeof(TSensrvChannelInfo) ) * KDefaultChannelCount; |
|
89 TPtr8 arrayPtr( (TUint8*)&channelInfoList[0], arraySize, arraySize ); |
|
90 |
|
91 TInt channelInfoCount(0); |
|
92 TSensrvTIntPckgBuf intBuf( channelInfoCount ); |
|
93 |
|
94 |
|
95 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelFinderImpl::FindChannels() - SendReceive..." ) ) ); |
|
96 TInt err = iSensrvClient.SendReceiveSync( ESensrvSrvReqQueryChannels, TIpcArgs( &searchConditionsBuf, |
|
97 &arrayPtr, &intBuf ) ); |
|
98 |
|
99 channelInfoCount = intBuf(); |
|
100 |
|
101 if( err == KErrNone ) // Copy channels info to aChannelList |
|
102 { |
|
103 for( TInt i = 0; i < channelInfoCount; ++i ) |
|
104 { |
|
105 aChannelList.AppendL( channelInfoList[i] ); |
|
106 } |
|
107 } |
|
108 |
|
109 else if( err == KErrOverflow ) // buffer overflow. Allocate new buffer |
|
110 { |
|
111 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelFinderImpl::FindChannels() - KErrOverflow" ) ) ); |
|
112 |
|
113 for( TInt i = KDefaultChannelCount; i < channelInfoCount; i++ ) |
|
114 { |
|
115 channelInfoList.AppendL( TSensrvChannelInfo() ); |
|
116 } |
|
117 |
|
118 TInt newArraySize = ( sizeof(TSensrvChannelInfo) ) * channelInfoCount; |
|
119 TPtr8 newArrayPtr( (TUint8*)&channelInfoList[0], newArraySize, newArraySize ); |
|
120 |
|
121 // Send new request |
|
122 User::LeaveIfError( iSensrvClient.SendReceiveSync( ESensrvSrvReqQueryChannels, |
|
123 TIpcArgs( &searchConditionsBuf, &newArrayPtr, &intBuf ) ) ); |
|
124 |
|
125 channelInfoCount = intBuf(); |
|
126 |
|
127 for( TInt i = 0; i < channelInfoCount; ++i ) |
|
128 { |
|
129 aChannelList.AppendL( channelInfoList[i] ); |
|
130 } |
|
131 |
|
132 } |
|
133 else |
|
134 { |
|
135 User::Leave( err ); |
|
136 } |
|
137 |
|
138 CleanupStack::PopAndDestroy( &channelInfoList ); |
|
139 |
|
140 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelFinderImpl::FindChannels() - return" ) ) ); |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // CSensrvChannelFinderImpl::SetChannelListenerL |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 void CSensrvChannelFinderImpl::SetChannelListenerL( MSensrvChannelListener* aChannelListener, |
|
148 const TSensrvChannelInfo& aSearchParameters ) |
|
149 { |
|
150 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelFinderImpl::SetChannelListenerL() - Start" ) ) ); |
|
151 |
|
152 if( iChannelChangeListener && aChannelListener ) |
|
153 { |
|
154 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelFinderImpl::SetChannelListenerL() - ERROR: Already listening: return KErrAlreadyExists" ) ) ); |
|
155 User::Leave( KErrAlreadyExists ); |
|
156 } |
|
157 |
|
158 iChannelChangeListener = aChannelListener; |
|
159 |
|
160 if( iChannelChangeListener ) |
|
161 { |
|
162 iChannelChangeHandler->StartListening( this, aSearchParameters ); |
|
163 } |
|
164 else |
|
165 { |
|
166 if( iChannelChangeHandler->IsActive() ) |
|
167 { |
|
168 iChannelChangeHandler->Cancel(); |
|
169 } |
|
170 else |
|
171 { |
|
172 TInt ignore = iSensrvClient.SendReceiveSync( ESensrvSrvReqStopChannelChangeListening, |
|
173 TIpcArgs() ); |
|
174 } |
|
175 } |
|
176 |
|
177 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelFinderImpl::SetChannelListenerL() - Return" ) ) ); |
|
178 } |
|
179 |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // CSensrvChannelFinderImpl::ChannelChangeDetected |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 void CSensrvChannelFinderImpl::ChannelChangeDetected( const TSensrvChannelInfo& aDetectedChannel, |
|
186 TSensrvChannelChangeType aChangeType ) |
|
187 { |
|
188 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelFinderImpl::ChannelChangeDetected()" ) ) ); |
|
189 |
|
190 if( iChannelChangeListener ) |
|
191 { |
|
192 iChannelChangeListener->ChannelChangeDetected( aDetectedChannel, aChangeType ); |
|
193 } |
|
194 |
|
195 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelFinderImpl::ChannelChangeDetected - return" ) ) ); |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 // CSensrvChannelFinderImpl::ChannelDetectionError |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 void CSensrvChannelFinderImpl::ChannelDetectionError( TSensrvErrorSeverity aError ) |
|
203 { |
|
204 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelFinderImpl::ChannelDetectionError()" ) ) ); |
|
205 |
|
206 if( aError == ESensrvErrorSeverityFatal ) |
|
207 { |
|
208 iSensrvClient.Close(); |
|
209 } |
|
210 |
|
211 if( iChannelChangeListener ) |
|
212 { |
|
213 iChannelChangeListener->ChannelDetectionError( *this, aError ); |
|
214 } |
|
215 |
|
216 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelFinderImpl::ChannelDetectionError - return" ) ) ); |
|
217 } |
|
218 |