author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 18 Jan 2010 21:02:57 +0200 | |
changeset 27 | 02682e02e51f |
parent 26 | 5d0ec8b709be |
permissions | -rw-r--r-- |
5 | 1 |
/* |
2 |
* Copyright (c) 2006-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 the License "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: This file contains implementation for the core class of sensor service API |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include "sensorservice.h" |
|
20 |
#include "sensorservice.hrh" |
|
21 |
||
22 |
||
23 |
/* |
|
24 |
----------------------------------------------------------------------------- |
|
25 |
CSensorService::CSensorService() |
|
26 |
Description : Symbian default Constructor can NOT contain |
|
27 |
any code that might leave. |
|
28 |
Return values : N/A |
|
29 |
----------------------------------------------------------------------------- |
|
30 |
*/ |
|
31 |
CSensorService::CSensorService() |
|
32 |
{ |
|
33 |
} |
|
34 |
||
35 |
/* |
|
36 |
----------------------------------------------------------------------------- |
|
37 |
void CSensorService::ConstructL() |
|
38 |
Description : Symbian 2nd phase constructor can leave. |
|
39 |
Return values : N/A |
|
40 |
----------------------------------------------------------------------------- |
|
41 |
*/ |
|
42 |
||
43 |
void CSensorService::ConstructL() |
|
44 |
{ |
|
45 |
} |
|
46 |
||
47 |
||
48 |
||
49 |
/* |
|
50 |
----------------------------------------------------------------------------- |
|
51 |
CSensorService* CSensorService::NewL() |
|
52 |
Description : Two-phased constructor. |
|
53 |
Return values : CSensorChannelService* object pointer |
|
54 |
----------------------------------------------------------------------------- |
|
55 |
*/ |
|
56 |
||
57 |
EXPORT_C CSensorService* CSensorService :: NewL() |
|
58 |
{ |
|
59 |
CSensorService* self = new(ELeave) CSensorService(); |
|
60 |
CleanupStack::PushL(self); |
|
61 |
self->ConstructL(); |
|
62 |
CleanupStack::Pop(self); |
|
63 |
return self; |
|
64 |
} |
|
65 |
||
66 |
||
67 |
/* |
|
68 |
----------------------------------------------------------------------------- |
|
69 |
CSensorService::~CSensorService() |
|
70 |
Description : Destructor, free allocated resources |
|
71 |
Return values : N/A |
|
72 |
----------------------------------------------------------------------------- |
|
73 |
*/ |
|
74 |
||
75 |
CSensorService::~CSensorService() |
|
76 |
{ |
|
77 |
TInt count = iChannelList.Count(); |
|
78 |
for (TInt i=0;i<count;i++) |
|
79 |
{ |
|
80 |
iChannelList[i]->CloseChannel(); |
|
81 |
||
82 |
} |
|
83 |
iChannelList.ResetAndDestroy(); |
|
84 |
||
85 |
if ( iChannelFinder ) |
|
86 |
delete iChannelFinder; |
|
87 |
} |
|
88 |
||
89 |
/* |
|
90 |
----------------------------------------------------------------------------- |
|
91 |
CSensorService::FindSensorChannelsL() |
|
92 |
Description : Finds channel which matches the search criterion |
|
93 |
Return values : NA |
|
94 |
----------------------------------------------------------------------------- |
|
95 |
*/ |
|
96 |
EXPORT_C void CSensorService:: FindSensorChannelsL(const TInt aSearchCriterion |
|
97 |
,RSensrvChannelInfoList& aChannelInfoList) |
|
98 |
{ |
|
99 |
if ( !iChannelFinder ) |
|
100 |
{ |
|
101 |
//Construct a channel finder. |
|
102 |
iChannelFinder = CSensrvChannelFinder::NewL(); |
|
103 |
||
104 |
} |
|
105 |
||
106 |
//Create and fill channel search criteria. |
|
107 |
TSensrvChannelInfo channelInfo; |
|
108 |
channelInfo.iChannelType = aSearchCriterion; |
|
109 |
||
110 |
//Find channel |
|
111 |
iChannelFinder->FindChannelsL( aChannelInfoList , channelInfo ); |
|
112 |
} |
|
113 |
/* |
|
114 |
----------------------------------------------------------------------------- |
|
115 |
CSensorService::StartGettingDataNotification() |
|
116 |
Description : Register to start receiving channel data |
|
117 |
Return values : NA |
|
118 |
----------------------------------------------------------------------------- |
|
119 |
*/ |
|
120 |
||
121 |
EXPORT_C void CSensorService::GetDataNotificationL(const TSensrvChannelInfo& aChannelInfo |
|
122 |
,MSensrvDataListener* aDataListener) |
|
123 |
{ |
|
124 |
TInt index; |
|
125 |
//Channel Id of the specified channel in the input parameter |
|
126 |
TUint32 channelId = aChannelInfo.iChannelId; |
|
127 |
//Find if specified channel is already opened |
|
128 |
if ( ( IsChannelOpen( channelId,index ) ) ) |
|
129 |
{ |
|
130 |
iChannelList[index]->StartDataListeningL( aDataListener, |
|
131 |
KDesiredCount, |
|
132 |
KMaxCount, |
|
133 |
KBufferingPeriod ); |
|
134 |
} |
|
135 |
//else open new channel and set data listener for it |
|
136 |
else |
|
137 |
{ |
|
138 |
CSensrvChannel* sensorChannel = CSensrvChannel::NewL( aChannelInfo ); |
|
139 |
CleanupStack::PushL( sensorChannel ); |
|
140 |
||
141 |
||
142 |
//open requested channel |
|
143 |
sensorChannel->OpenChannelL(); |
|
144 |
||
145 |
iChannelList.Append(sensorChannel); |
|
146 |
sensorChannel->StartDataListeningL( aDataListener, |
|
147 |
KDesiredCount, |
|
148 |
KMaxCount, |
|
149 |
KBufferingPeriod ); |
|
150 |
CleanupStack::Pop( sensorChannel ); |
|
151 |
} |
|
152 |
} |
|
153 |
||
154 |
||
155 |
/* |
|
156 |
--------------------------------------------------------------------------------------- |
|
157 |
CSensorService::StopNotificationL() |
|
158 |
Description : Stop getting any previously registered notification from a channel |
|
159 |
Return values : NA |
|
160 |
--------------------------------------------------------------------------------------- |
|
161 |
*/ |
|
162 |
||
163 |
EXPORT_C void CSensorService::StopNotificationL(TInt aNotificationType,TUint32 aChannelId ) |
|
164 |
{ |
|
165 |
TInt index ; |
|
166 |
||
167 |
if ( aChannelId == 0 ) |
|
168 |
{ |
|
169 |
if ( !iChannelFinder ) |
|
170 |
User::Leave(KErrArgument); |
|
171 |
} |
|
172 |
else if( ( IsChannelOpen( aChannelId,index ) ) ) |
|
173 |
{ |
|
174 |
switch( aNotificationType ) |
|
175 |
{ |
|
176 |
case EStopData: |
|
177 |
iChannelList[index]->StopDataListening(); |
|
178 |
break; |
|
179 |
} |
|
180 |
} |
|
181 |
else |
|
182 |
User::Leave( KErrArgument ); |
|
183 |
} |
|
184 |
||
185 |
/* |
|
186 |
----------------------------------------------------------------------------- |
|
187 |
CSensorService::IsChannelOpen() |
|
188 |
Description : Check if a channel is open |
|
189 |
Return values : True if specified channel is open ;False otherwise |
|
190 |
----------------------------------------------------------------------------- |
|
191 |
*/ |
|
192 |
||
193 |
TBool CSensorService::IsChannelOpen(TUint32 aChannelId,TInt& aIndex) |
|
194 |
{ |
|
195 |
//Find Number of channel already opened |
|
196 |
TInt chnlCount = iChannelList.Count(); |
|
197 |
||
198 |
//Check if aChannelId matches with any one of the opened channel |
|
199 |
for(TInt i=0;i<chnlCount;i++) |
|
200 |
{ |
|
201 |
const TSensrvChannelInfo& channelInfo = iChannelList[i]->GetChannelInfo(); |
|
202 |
if ( channelInfo.iChannelId == aChannelId ) |
|
203 |
{ |
|
204 |
aIndex = i; |
|
205 |
return TRUE; |
|
206 |
} |
|
207 |
} |
|
208 |
return FALSE; |
|
209 |
} |
|
210 |
||
211 |
||
212 |
/* |
|
213 |
----------------------------------------------------------------------------- |
|
214 |
CSensorService::GetChannelProperty() |
|
215 |
Description : Get property of specified channel |
|
216 |
Return values : NA |
|
217 |
----------------------------------------------------------------------------- |
|
218 |
*/ |
|
219 |
EXPORT_C void CSensorService::GetChannelPropertyL( const TSensrvChannelInfo& aChannelInfo, |
|
220 |
RSensrvPropertyList& aChannelPropertyList ) |
|
221 |
{ |
|
222 |
TInt index; |
|
223 |
//Channel Id of the specified channel in the inpiut parameter |
|
224 |
TUint32 channelId = aChannelInfo.iChannelId; |
|
225 |
//Find if specified channel is already opened |
|
226 |
if ( ( IsChannelOpen( channelId,index ) ) ) |
|
227 |
{ |
|
228 |
iChannelList[index]->GetAllPropertiesL( aChannelPropertyList ); |
|
229 |
} |
|
230 |
//else open new channel and get property change listener for it |
|
231 |
else |
|
232 |
{ |
|
233 |
CSensrvChannel* sensorChannel = CSensrvChannel::NewL( aChannelInfo ); |
|
234 |
CleanupStack::PushL( sensorChannel ); |
|
235 |
//open requested channel |
|
236 |
sensorChannel->OpenChannelL(); |
|
237 |
sensorChannel->GetAllPropertiesL( aChannelPropertyList ); |
|
238 |
sensorChannel->CloseChannel(); |
|
239 |
CleanupStack::PopAndDestroy( sensorChannel ); |
|
240 |
} |
|
241 |
||
242 |
} |
|
26
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
243 |