|
1 /* |
|
2 * Copyright (c) 2002 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: Used for testing BT API |
|
15 * Revision : $Revision: $ |
|
16 * Date : $Date: $ |
|
17 * |
|
18 */ |
|
19 |
|
20 #include <e32std.h> |
|
21 #include <e32base.h> |
|
22 #include <e32cmn.h> |
|
23 #include <btengsettings.h> |
|
24 |
|
25 #include "btapisettings.h" |
|
26 #include "bttestlogger.h" |
|
27 |
|
28 // Log string for Power on |
|
29 _LIT( KSetBTPowerOn, "on " ); |
|
30 // Log string for Power off |
|
31 _LIT( KSetBTPowerOff, "off" ); |
|
32 |
|
33 // Constructor |
|
34 CBTApiSettings::CBTApiSettings( MBTTestObserver& aObserver ) |
|
35 : iObserver( aObserver ) |
|
36 { |
|
37 } |
|
38 |
|
39 // Destructor |
|
40 CBTApiSettings::~CBTApiSettings( ) |
|
41 { |
|
42 delete iBTEngSettings; |
|
43 } |
|
44 |
|
45 |
|
46 // NewL |
|
47 CBTApiSettings* CBTApiSettings::NewL (MBTTestObserver& aObserver) |
|
48 { |
|
49 CBTApiSettings* self = new (ELeave) CBTApiSettings(aObserver); |
|
50 |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(); |
|
53 CleanupStack::Pop(self); |
|
54 |
|
55 return self; |
|
56 } |
|
57 |
|
58 |
|
59 // Symbian 2nd phase constructor. |
|
60 void CBTApiSettings::ConstructL() |
|
61 { |
|
62 iBTEngSettings = CBTEngSettings::NewL( this ); |
|
63 iExpectedPowerState = EBTPowerOff; |
|
64 iExpectedVisibility = EBTVisibilityModeGeneral; |
|
65 iError = KErrNone; |
|
66 iExpectedLocalName.Zero(); |
|
67 } |
|
68 |
|
69 void CBTApiSettings::PowerStateChanged( TBTPowerStateValue aState ) |
|
70 { |
|
71 iError = KErrNone; |
|
72 iObserver.Logger().Log( CBtTestLogger::ETLDebug, _L( "CBTApiSettings::PowerStateChanged: %d" ), aState); |
|
73 |
|
74 if ( iExpectedPowerState != aState ) |
|
75 { |
|
76 iError = KErrArgument; |
|
77 } |
|
78 if ( iWaiter.IsStarted() ) |
|
79 { |
|
80 iWaiter.AsyncStop(); |
|
81 } |
|
82 } |
|
83 |
|
84 void CBTApiSettings::VisibilityModeChanged( TBTVisibilityMode aState ) |
|
85 { |
|
86 iError = KErrNone; |
|
87 iObserver.Logger().Log( CBtTestLogger::ETLDebug, _L( "CBTApiSettings::VisibilityModeChanged: %d" ), aState); |
|
88 |
|
89 if ( iExpectedVisibility != aState ) |
|
90 { |
|
91 iError = KErrArgument; |
|
92 } |
|
93 if ( iWaiter.IsStarted() ) |
|
94 { |
|
95 iWaiter.AsyncStop(); |
|
96 } |
|
97 } |
|
98 |
|
99 TInt CBTApiSettings::TurnBtOn() |
|
100 { |
|
101 TBTPowerStateValue state; |
|
102 TInt err = KErrNone; |
|
103 |
|
104 err = iBTEngSettings->GetPowerState( state ); |
|
105 if ( err ) |
|
106 { |
|
107 return err; |
|
108 } |
|
109 |
|
110 if( state == EBTPowerOff ) |
|
111 { |
|
112 state = EBTPowerOn; |
|
113 } |
|
114 else |
|
115 { |
|
116 return KErrNone; |
|
117 } |
|
118 |
|
119 err = iBTEngSettings->SetPowerState( state ); |
|
120 if ( err ) |
|
121 { |
|
122 return err; |
|
123 } |
|
124 |
|
125 iExpectedPowerState = state; |
|
126 iWaiter.Start(); |
|
127 return iError; |
|
128 } |
|
129 |
|
130 TInt CBTApiSettings::SwitchPowerState() |
|
131 { |
|
132 TBTPowerStateValue state; |
|
133 TInt err = KErrNone; |
|
134 |
|
135 err = iBTEngSettings->GetPowerState( state ); |
|
136 if ( err ) |
|
137 { |
|
138 return err; |
|
139 } |
|
140 |
|
141 if( state == EBTPowerOff ) |
|
142 { |
|
143 state = EBTPowerOn; |
|
144 } |
|
145 else |
|
146 { |
|
147 state = EBTPowerOff; |
|
148 } |
|
149 |
|
150 err = iBTEngSettings->SetPowerState( state ); |
|
151 |
|
152 if ( err ) |
|
153 { |
|
154 return err; |
|
155 } |
|
156 iExpectedPowerState = state; |
|
157 iObserver.Logger().Log( CBtTestLogger::ETLDebug, _L( "Switching BT power: %d" ), state); |
|
158 iWaiter.Start(); |
|
159 return iError; |
|
160 } |
|
161 |
|
162 TInt CBTApiSettings::GetPowerState() |
|
163 { |
|
164 TInt err = KErrNone; |
|
165 TBTPowerStateValue state; |
|
166 |
|
167 err = iBTEngSettings->GetPowerState( state ); |
|
168 |
|
169 if ( err ) |
|
170 { |
|
171 return err; |
|
172 } |
|
173 |
|
174 if ( iExpectedPowerState != state ) |
|
175 { |
|
176 return KErrArgument; |
|
177 } |
|
178 return err; |
|
179 } |
|
180 |
|
181 TInt CBTApiSettings::SetVisibilityMode( TBTVisibilityMode visibilityState, TInt aTimer ) |
|
182 { |
|
183 TInt err = KErrNone; |
|
184 err = iBTEngSettings->SetVisibilityMode( visibilityState ); |
|
185 |
|
186 if ( err ) |
|
187 { |
|
188 return err; |
|
189 } |
|
190 iExpectedVisibility = visibilityState; |
|
191 iObserver.Logger().Log( CBtTestLogger::ETLDebug, _L( "Switching BT visibility: %d" ), visibilityState); |
|
192 iWaiter.Start(); |
|
193 return iError; |
|
194 } |
|
195 |
|
196 TInt CBTApiSettings::GetVisibilityMode() |
|
197 { |
|
198 TInt err = KErrNone; |
|
199 TBTVisibilityMode mode; |
|
200 |
|
201 err = iBTEngSettings->GetVisibilityMode( mode ); |
|
202 |
|
203 if ( err ) |
|
204 { |
|
205 return err; |
|
206 } |
|
207 |
|
208 if ( iExpectedVisibility!= mode ) |
|
209 { |
|
210 return KErrArgument; |
|
211 } |
|
212 |
|
213 return iError; |
|
214 } |
|
215 |
|
216 TInt CBTApiSettings::SetLocalName( TDesC& aName ) |
|
217 { |
|
218 TInt err = KErrNone; |
|
219 iExpectedLocalName = aName; |
|
220 iObserver.Logger().Log( CBtTestLogger::ETLDebug, _L( "Setting BT localname to: %S" ), &aName); |
|
221 err = iBTEngSettings->SetLocalName( iExpectedLocalName ); |
|
222 if ( err ) |
|
223 { |
|
224 iExpectedLocalName.Zero(); |
|
225 } |
|
226 return err; |
|
227 } |
|
228 |
|
229 TInt CBTApiSettings::GetLocalName() |
|
230 { |
|
231 TInt err = KErrNone; |
|
232 TBuf<100> name; |
|
233 err = iBTEngSettings->GetLocalName( name ); |
|
234 |
|
235 if ( iExpectedLocalName.Length() ) |
|
236 { |
|
237 if ( name.Compare( iExpectedLocalName ) ) |
|
238 { |
|
239 err = KErrArgument; |
|
240 } |
|
241 } |
|
242 return err; |
|
243 } |
|
244 |