|
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: CTCSsyControl class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ssycallback.h> |
|
20 |
|
21 #include "tcssycontrol.h" |
|
22 #include "tcchanneltilt.h" |
|
23 #include "trace.h" |
|
24 |
|
25 CTCSsyControl* CTCSsyControl::NewL( MSsyCallback* aSsyCallback ) |
|
26 { |
|
27 FUNC_LOG; |
|
28 |
|
29 CTCSsyControl* self = new( ELeave ) CTCSsyControl; |
|
30 |
|
31 CleanupStack::PushL( self ); |
|
32 self->ConstructL( aSsyCallback ); |
|
33 CleanupStack::Pop( self ); |
|
34 |
|
35 return self; |
|
36 } |
|
37 |
|
38 CTCSsyControl::~CTCSsyControl() |
|
39 { |
|
40 FUNC_LOG; |
|
41 |
|
42 iChannels.ResetAndDestroy(); |
|
43 } |
|
44 |
|
45 CTCSsyControl::CTCSsyControl() |
|
46 { |
|
47 FUNC_LOG; |
|
48 } |
|
49 |
|
50 void CTCSsyControl::ConstructL( MSsyCallback* aSsyCallback ) |
|
51 { |
|
52 FUNC_LOG; |
|
53 |
|
54 // Create tilt channel. Tilt channel provides compensated tilt data |
|
55 // from magnetometer and accelerometer vectors |
|
56 CTCChannel* channel = CTCChannelTilt::NewL( *aSsyCallback ); |
|
57 CleanupStack::PushL( channel ); |
|
58 iChannels.AppendL( channel ); |
|
59 CleanupStack::Pop( channel ); |
|
60 |
|
61 // Register channels |
|
62 RSensrvChannelInfoList channelList; |
|
63 CleanupClosePushL( channelList ); |
|
64 TInt channelCount = iChannels.Count(); |
|
65 for( TInt i = 0; i < channelCount; i++ ) |
|
66 { |
|
67 iChannels[ i ]->RegisterChannelL( channelList ); |
|
68 } |
|
69 aSsyCallback->RegisterChannelsL( channelList ); |
|
70 |
|
71 _LIT( KThreadName, "TiltThread" ); |
|
72 RThread thread; |
|
73 thread.RenameMe( KThreadName ); |
|
74 |
|
75 // Update channel IDs |
|
76 TInt channelInfoCount = channelList.Count(); |
|
77 channelCount = iChannels.Count(); |
|
78 for( TInt i = 0; i < channelInfoCount; i++ ) |
|
79 { |
|
80 channel = NULL; |
|
81 for( TInt j = 0; j < channelCount; j++ ) |
|
82 { |
|
83 channel = iChannels[ j ]; |
|
84 const TSensrvChannelInfo& info = channelList[ i ]; |
|
85 if( channel->ChannelSupported( info ) ) |
|
86 { |
|
87 channel->SetChannelId( info.iChannelId ); |
|
88 } |
|
89 } |
|
90 } |
|
91 CleanupStack::PopAndDestroy( &channelList ); |
|
92 } |
|
93 |
|
94 // ---------------------------------------------------------------------------------- |
|
95 // CTCSsyControl::OpenChannelL |
|
96 // ---------------------------------------------------------------------------------- |
|
97 // |
|
98 void CTCSsyControl::OpenChannelL( TSensrvChannelId aChannelId ) |
|
99 { |
|
100 FUNC_LOG; |
|
101 |
|
102 CTCChannel* channel = ChannelSupported( aChannelId ); |
|
103 if( channel ) |
|
104 { |
|
105 INFO_1( "Found channel [%d]. Opening channel", aChannelId ); |
|
106 channel->OpenChannelL(); |
|
107 INFO_1( "Channel [%d] opened", aChannelId ); |
|
108 } |
|
109 else |
|
110 { |
|
111 ERROR_GEN_1( "Channel [%d] not supported", aChannelId ); |
|
112 User::Leave( KErrNotSupported ); |
|
113 } |
|
114 } |
|
115 |
|
116 // ---------------------------------------------------------------------------------- |
|
117 // CTCSsyControl::CloseChannelL |
|
118 // ---------------------------------------------------------------------------------- |
|
119 // |
|
120 void CTCSsyControl::CloseChannelL( TSensrvChannelId aChannelId ) |
|
121 { |
|
122 FUNC_LOG; |
|
123 |
|
124 CTCChannel* channel = ChannelSupported( aChannelId ); |
|
125 if( channel ) |
|
126 { |
|
127 INFO_1( "Found channel [%d]. Opening channel", aChannelId ); |
|
128 channel->CloseChannelL(); |
|
129 INFO_1( "Channel [%d] opened", aChannelId ); |
|
130 } |
|
131 else |
|
132 { |
|
133 ERROR_GEN_1( "Channel [%d] not supported", aChannelId ); |
|
134 User::Leave( KErrNotSupported ); |
|
135 } |
|
136 } |
|
137 |
|
138 // ---------------------------------------------------------------------------------- |
|
139 // CTCSsyControl::ChannelSupported |
|
140 // ---------------------------------------------------------------------------------- |
|
141 // |
|
142 CTCChannel* CTCSsyControl::ChannelSupported( TSensrvChannelId aChannelId ) const |
|
143 { |
|
144 FUNC_LOG; |
|
145 |
|
146 CTCChannel* channel = NULL; |
|
147 TInt count( iChannels.Count() ); |
|
148 for( TInt i = 0; i < count; i++ ) |
|
149 { |
|
150 channel = iChannels[ i ]; |
|
151 TSensrvChannelId id = channel->ChannelId(); |
|
152 if( id == aChannelId ) |
|
153 { |
|
154 // Channel found, break |
|
155 break; |
|
156 } |
|
157 } |
|
158 |
|
159 return channel; |
|
160 } |
|
161 |
|
162 // End of File |