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