|
1 /* |
|
2 * Copyright (c) 2007,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: Control class of Orientation SSY |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ssycallback.h> |
|
20 #include "SsyControlOrientation.h" |
|
21 #include "SsyProperty.h" |
|
22 #include "SsyConfiguration.h" |
|
23 #include "SsyTrace.h" |
|
24 |
|
25 |
|
26 |
|
27 // ---------------------------------------------------------------------------------- |
|
28 // CSSYControlOrientationOrientation::CSSYControlOrientation() |
|
29 // ---------------------------------------------------------------------------------- |
|
30 // |
|
31 CSSYControlOrientation* CSSYControlOrientation::NewL( MSsyCallback* aSsyCallback ) |
|
32 { |
|
33 SSY_TRACE_IN(); |
|
34 |
|
35 ASSERT_DEBUG_SSY( aSsyCallback ); |
|
36 |
|
37 CSSYControlOrientation* self = new( ELeave ) CSSYControlOrientation( aSsyCallback ); |
|
38 CleanupStack::PushL( self ); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop( self ); |
|
41 |
|
42 SSY_TRACE_OUT(); |
|
43 |
|
44 return self; |
|
45 } |
|
46 |
|
47 // ---------------------------------------------------------------------------------- |
|
48 // CSSYControlOrientation::ConstructL() |
|
49 // ---------------------------------------------------------------------------------- |
|
50 // |
|
51 void CSSYControlOrientation::ConstructL() |
|
52 { |
|
53 SSY_TRACE_IN(); |
|
54 |
|
55 // Create sensor properties |
|
56 iSensorProperties = new (ELeave) CSSYProperty( |
|
57 0, KSSySensorProperties, ARRAY_LENGTH( KSSySensorProperties ) ); |
|
58 |
|
59 // Create and register all the needed channels |
|
60 CreateAndRegisterChannelsL( KSSsyChannelInfo, ARRAY_LENGTH( KSSsyChannelInfo ) ); |
|
61 |
|
62 SSY_TRACE_OUT(); |
|
63 } |
|
64 |
|
65 // ---------------------------------------------------------------------------------- |
|
66 // CSSYControlOrientation::CSSYControlOrientation() |
|
67 // ---------------------------------------------------------------------------------- |
|
68 // |
|
69 CSSYControlOrientation::CSSYControlOrientation( MSsyCallback* aSsyCallback ) : |
|
70 iSensorProperties( NULL ), |
|
71 iCallback( aSsyCallback ) |
|
72 { |
|
73 SSY_TRACE_IN(); |
|
74 |
|
75 SSY_TRACE_OUT(); |
|
76 } |
|
77 |
|
78 // ---------------------------------------------------------------------------------- |
|
79 // CSSYControlOrientation::~CSSYControlOrientation() |
|
80 // ---------------------------------------------------------------------------------- |
|
81 // |
|
82 CSSYControlOrientation::~CSSYControlOrientation() |
|
83 { |
|
84 SSY_TRACE_IN(); |
|
85 |
|
86 delete iSensorProperties; |
|
87 iSensorProperties = NULL; |
|
88 |
|
89 iChannelArray.ResetAndDestroy(); |
|
90 |
|
91 SSY_TRACE_OUT(); |
|
92 } |
|
93 |
|
94 // ---------------------------------------------------------------------------------- |
|
95 // CSSYControlOrientation::IsChannelSupported() |
|
96 // ---------------------------------------------------------------------------------- |
|
97 // |
|
98 TBool CSSYControlOrientation::IsChannelSupported( |
|
99 const TSensrvChannelId aChannelID, |
|
100 TInt& aIndex ) |
|
101 { |
|
102 SSY_TRACE_IN(); |
|
103 |
|
104 TBool found( EFalse ); |
|
105 |
|
106 for ( TInt index = 0; index < iChannelArray.Count(); index++ ) |
|
107 { |
|
108 if ( ( *iChannelArray[index] ).ChannelId() == aChannelID ) |
|
109 { |
|
110 found = ETrue; |
|
111 aIndex = index; |
|
112 break; |
|
113 } |
|
114 } |
|
115 |
|
116 SSY_TRACE_OUT(); |
|
117 |
|
118 return found; |
|
119 } |
|
120 |
|
121 // ---------------------------------------------------------------------------------- |
|
122 // CSSYControlOrientation::OpenChannelL() |
|
123 // ---------------------------------------------------------------------------------- |
|
124 // |
|
125 void CSSYControlOrientation::OpenChannelL( TSensrvChannelId aChannelID ) |
|
126 { |
|
127 SSY_TRACE_IN(); |
|
128 |
|
129 TInt err( KErrNone ); |
|
130 TInt channelIndex( 0 ); |
|
131 |
|
132 if ( IsChannelSupported( aChannelID, channelIndex ) ) |
|
133 { |
|
134 err = ( *iChannelArray[ channelIndex ] ).OpenChannel(); |
|
135 } |
|
136 else |
|
137 { |
|
138 err = KErrGeneral; |
|
139 } |
|
140 |
|
141 if ( err != KErrNone ) |
|
142 { |
|
143 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Opening channel failed: %d", err ); |
|
144 User::Leave( err ); |
|
145 } |
|
146 |
|
147 SSY_TRACE_OUT(); |
|
148 } |
|
149 |
|
150 // ---------------------------------------------------------------------------------- |
|
151 // CSSYControlOrientation::CloseChannelL() |
|
152 // ---------------------------------------------------------------------------------- |
|
153 // |
|
154 void CSSYControlOrientation::CloseChannelL( TSensrvChannelId aChannelID ) |
|
155 { |
|
156 SSY_TRACE_IN(); |
|
157 |
|
158 TInt err( KErrNone ); |
|
159 TInt channelIndex( 0 ); |
|
160 |
|
161 if ( IsChannelSupported( aChannelID, channelIndex ) ) |
|
162 { |
|
163 if( channelIndex <= iChannelArray.Count() ) |
|
164 { |
|
165 err = ( *iChannelArray[channelIndex] ).CloseChannel(); |
|
166 } |
|
167 } |
|
168 else |
|
169 { |
|
170 err = KErrGeneral; |
|
171 } |
|
172 |
|
173 if ( err != KErrNone ) |
|
174 { |
|
175 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Closing channel failed: %d", err ); |
|
176 User::Leave( err ); |
|
177 } |
|
178 |
|
179 SSY_TRACE_OUT(); |
|
180 } |
|
181 |
|
182 // ---------------------------------------------------------------------------------- |
|
183 // CSSYControlOrientation::CreateAndRegisterChannelsL() |
|
184 // ---------------------------------------------------------------------------------- |
|
185 // |
|
186 void CSSYControlOrientation::CreateAndRegisterChannelsL( |
|
187 const TSSsyChannelInfo* aChannelConfigurations, |
|
188 const TUint aNumberofConfigurations ) |
|
189 { |
|
190 SSY_TRACE_IN(); |
|
191 |
|
192 ASSERT_ALWAYS_SSY( aChannelConfigurations ); |
|
193 ASSERT_ALWAYS_SSY( aNumberofConfigurations ); |
|
194 |
|
195 RSensrvChannelInfoList channelInfoList; |
|
196 |
|
197 for ( TInt index = 0; index < aNumberofConfigurations; index++ ) |
|
198 { |
|
199 CSSYChannel* channel( NULL ); |
|
200 |
|
201 TSensrvChannelInfo channelInfo |
|
202 ( |
|
203 aChannelConfigurations[index].iChannelId, |
|
204 aChannelConfigurations[index].iContextType, |
|
205 aChannelConfigurations[index].iQuantity, |
|
206 aChannelConfigurations[index].iChannelType, |
|
207 aChannelConfigurations[index].iLocation, |
|
208 aChannelConfigurations[index].iVendorId, |
|
209 aChannelConfigurations[index].iDataItemSize, |
|
210 aChannelConfigurations[index].iDataTypeId |
|
211 ); |
|
212 |
|
213 switch ( channelInfo.iChannelType ) |
|
214 { |
|
215 case KSensrvChannelTypeIdOrientationData: |
|
216 // Intentional flowthrough |
|
217 case KSensrvChannelTypeIdRotationData: |
|
218 channel = CSSYChannel::NewL( iSensorProperties, iCallback, channelInfo ); |
|
219 break; |
|
220 default: |
|
221 ASSERT_ALWAYS_SSY( 0 ); |
|
222 break; |
|
223 } |
|
224 |
|
225 if ( channel ) |
|
226 { |
|
227 iChannelArray.Append( channel ); |
|
228 channelInfoList.Append( channelInfo ); |
|
229 } |
|
230 } |
|
231 |
|
232 // Register channels to the client |
|
233 SSY_TRACE_TRAP( err, iCallback->RegisterChannelsL( channelInfoList ) ); |
|
234 |
|
235 // Update ChannelId |
|
236 for ( TInt i = 0; i < iChannelArray.Count(); i++ ) |
|
237 { |
|
238 (*iChannelArray[i]).SetChannelId( channelInfoList[i].iChannelId ); |
|
239 } |
|
240 |
|
241 channelInfoList.Reset(); |
|
242 channelInfoList.Close(); |
|
243 |
|
244 SSY_TRACE_OUT(); |
|
245 } |
|
246 |
|
247 // End of File |