|
1 // ssyreferencecontrol.cpp |
|
2 |
|
3 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 // All rights reserved. |
|
5 // This component and the accompanying materials are made available |
|
6 // under the terms of "Eclipse Public License v1.0" |
|
7 // which accompanies this distribution, and is available |
|
8 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 // |
|
10 // Initial Contributors: |
|
11 // Nokia Corporation - initial contribution. |
|
12 // |
|
13 // Contributors: |
|
14 // |
|
15 // Description: |
|
16 // |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <sensors/spi/ssycallback.h> // MSsyCallback |
|
22 #include "ssyreferencecontrol.h" |
|
23 #include "ssyreferencetrace.h" |
|
24 #include "ssyreferencechannel.h" |
|
25 #include "ssyreferencecmdhandler.h" |
|
26 |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // CSsyReferenceControl C++ constructor |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CSsyReferenceControl::CSsyReferenceControl( MSsyCallback& aSsyCallback ) : |
|
35 iSsyCallback( aSsyCallback ) |
|
36 { |
|
37 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::CSsyReferenceControl()" ) ) ); |
|
38 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::CSsyReferenceControl() - return" ) ) ); |
|
39 } |
|
40 |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // Symbian 2nd phase constructor |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 void CSsyReferenceControl::ConstructL() |
|
47 { |
|
48 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::ConstructL()" ) ) ); |
|
49 |
|
50 // Create configurator and start config file parsing |
|
51 iConfigFile = CSsyReferenceConfig::NewL(); |
|
52 TRAPD( err, iConfigFile->InitConfigL() ); // This will block until config is ready |
|
53 |
|
54 if ( KErrNone != err ) |
|
55 { |
|
56 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::ConstructL() - Init config failed: %i" ), err ) ); |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------- |
|
60 |
|
61 // Store channel count for later use |
|
62 const TInt channelCount( iConfigFile->ChannelCount() ); |
|
63 |
|
64 // Instantiate channel info list |
|
65 RSensrvChannelInfoList channelInfoList( channelCount ); |
|
66 CleanupClosePushL( channelInfoList ); |
|
67 |
|
68 // Fills channel info list with generated channel info objects |
|
69 iConfigFile->GenerateChannels( channelInfoList ); |
|
70 |
|
71 // Register channels. Sensor Server generates unique ID for each channel |
|
72 iSsyCallback.RegisterChannelsL( channelInfoList ); |
|
73 |
|
74 // Update channel IDs to ConfigFile |
|
75 iConfigFile->UpdateChannelIds( channelInfoList ); |
|
76 |
|
77 // Create channels |
|
78 iChannelArray = new ( ELeave ) CArrayPtrFlat<CSsyReferenceChannel>( channelCount ); |
|
79 for ( TInt i = 0; i < channelCount; i++ ) |
|
80 { |
|
81 CSsyReferenceChannel* channel = CSsyReferenceChannel::NewL( *this, channelInfoList[i] ); |
|
82 iChannelArray->AppendL( channel ); |
|
83 } |
|
84 |
|
85 // Clean up |
|
86 CleanupStack::PopAndDestroy( &channelInfoList ); |
|
87 |
|
88 // Get properties of this SSY. Leaves with KErrNotFound if not found. These properties are |
|
89 // not mandatory, so we can ignore that leave |
|
90 TRAP_IGNORE( iConfigFile->GetSensorPropertiesL( iProperties ) ); |
|
91 |
|
92 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::ConstructL() - return" ) ) ); |
|
93 } |
|
94 |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // CSsyReferenceControl::NewL |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 CSsyReferenceControl* CSsyReferenceControl::NewL( MSsyCallback& aSsyCallback ) |
|
101 { |
|
102 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::NewL()" ) ) ); |
|
103 CSsyReferenceControl* self = new ( ELeave ) CSsyReferenceControl( aSsyCallback ); |
|
104 CleanupStack::PushL( self ); |
|
105 self->ConstructL(); |
|
106 CleanupStack::Pop( self ); |
|
107 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::NewL() - return" ) ) ); |
|
108 return self; |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // Destructor |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 CSsyReferenceControl::~CSsyReferenceControl() |
|
116 { |
|
117 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::~CSsyReferenceControl()" ) ) ); |
|
118 |
|
119 if ( iChannelArray ) |
|
120 { |
|
121 if ( iChannelArray->Count() ) |
|
122 { |
|
123 iChannelArray->ResetAndDestroy(); |
|
124 } |
|
125 |
|
126 delete iChannelArray; |
|
127 } |
|
128 |
|
129 if ( iConfigFile ) |
|
130 { |
|
131 delete iConfigFile; |
|
132 iConfigFile = NULL; |
|
133 } |
|
134 |
|
135 iProperties.Reset(); |
|
136 |
|
137 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::~CSsyReferenceControl() - return" ) ) ); |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // CSsyReferenceControl::SsyCallback |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 MSsyCallback& CSsyReferenceControl::SsyCallback() const |
|
145 { |
|
146 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::SsyCallback()" ) ) ); |
|
147 return iSsyCallback; |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // CSsyReferenceControl::SsyConfig |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 CSsyReferenceConfig& CSsyReferenceControl::SsyConfig() const |
|
155 { |
|
156 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::SsyConfig()" ) ) ); |
|
157 return *iConfigFile; |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // CSsyReferenceControl::FindPropertyL |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 void CSsyReferenceControl::FindPropertyL( |
|
165 const TSensrvPropertyId aPropertyId, |
|
166 const TInt aArrayIndex, |
|
167 TSensrvProperty& aProperty ) |
|
168 { |
|
169 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::FindPropertyL()" ) ) ); |
|
170 TSensrvProperty* property = NULL; |
|
171 TBool propertyFound( EFalse ); |
|
172 |
|
173 // Search property |
|
174 for ( TInt i = 0; i < iProperties.Count() && !propertyFound; i++ ) |
|
175 { |
|
176 property = static_cast<TSensrvProperty*>( &iProperties[i] ); |
|
177 |
|
178 // Compare property IDs |
|
179 if ( property->GetPropertyId() == aPropertyId ) |
|
180 { |
|
181 // Correct property ID is found, now check is it array type of property. |
|
182 // Either array indexes must match or propertys array index has to be array info |
|
183 if ( ( property->GetArrayIndex() == aArrayIndex ) || |
|
184 ( ( property->GetArrayIndex() == ESensrvArrayPropertyInfo ) && |
|
185 ( ESensrvSingleProperty == aArrayIndex ) ) ) |
|
186 { |
|
187 // Correct array index found |
|
188 propertyFound = ETrue; |
|
189 } |
|
190 } |
|
191 } |
|
192 |
|
193 // Leave if not found |
|
194 if ( !propertyFound ) |
|
195 { |
|
196 User::Leave( KErrNotFound ); |
|
197 } |
|
198 |
|
199 aProperty = *property; |
|
200 |
|
201 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::FindPropertyL() - return" ) ) ); |
|
202 } |
|
203 |
|
204 |
|
205 // --------------------------------------------------------------------------- |
|
206 // CSsyReferenceControl::FindChannel |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 CSsyReferenceChannel* CSsyReferenceControl::FindChannelL( TSensrvChannelId aChannelID ) |
|
210 { |
|
211 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::FindChannel()" ) ) ); |
|
212 |
|
213 if ( !iChannelArray ) |
|
214 { |
|
215 User::Leave( KErrNotFound ); |
|
216 } |
|
217 |
|
218 const TInt channelCount( iChannelArray->Count() ); |
|
219 CSsyReferenceChannel* channel = NULL; |
|
220 |
|
221 // Check that there are channels |
|
222 if ( channelCount ) |
|
223 { |
|
224 // Loop channels until correct channel is found |
|
225 for ( TInt i = 0; i < channelCount; i++ ) |
|
226 { |
|
227 channel = iChannelArray->At( i ); |
|
228 |
|
229 // Compare channel id |
|
230 if ( channel->ChannelId() == aChannelID ) |
|
231 { |
|
232 // Channel found, no need to loop rest |
|
233 i = channelCount; |
|
234 } |
|
235 } |
|
236 } |
|
237 |
|
238 // Leave if channel is not found |
|
239 if ( !channel ) |
|
240 { |
|
241 User::Leave( KErrNotFound ); |
|
242 } |
|
243 |
|
244 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::FindChannel() - return" ) ) ); |
|
245 return channel; |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // CSsyReferenceControl::OpenChannelL |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 void CSsyReferenceControl::OpenChannelL( TSensrvChannelId aChannelID ) |
|
253 { |
|
254 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::OpenChannelL()" ) ) ); |
|
255 // Find and open channel |
|
256 User::LeaveIfError( FindChannelL( aChannelID )->OpenChannel() ); |
|
257 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::OpenChannelL() - return" ) ) ); |
|
258 } |
|
259 |
|
260 // --------------------------------------------------------------------------- |
|
261 // CSsyReferenceControl::CloseChannelL |
|
262 // --------------------------------------------------------------------------- |
|
263 // |
|
264 void CSsyReferenceControl::CloseChannelL( TSensrvChannelId aChannelID ) |
|
265 { |
|
266 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::CloseChannelL()" ) ) ); |
|
267 // Find and close channel |
|
268 User::LeaveIfError( FindChannelL( aChannelID )->CloseChannel() ); |
|
269 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::CloseChannelL() - return" ) ) ); |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // CSsyReferenceControl::ProcessResponse |
|
274 // --------------------------------------------------------------------------- |
|
275 // |
|
276 void CSsyReferenceControl::ProcessResponse( TSsyReferenceMsg* /*aMessage*/ ) |
|
277 { |
|
278 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::ProcessResponse()" ) ) ); |
|
279 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceControl::ProcessResponse() - return" ) ) ); |
|
280 } |
|
281 |