|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <e32base.h> |
|
17 #include <e32std.h> |
|
18 #include <e32test.h> |
|
19 #include <bt_subscribe.h> |
|
20 #include <bt_sock.h> |
|
21 #include "BTProperties.h" |
|
22 |
|
23 _LIT(KNumLinks, "Number of links:"); |
|
24 _LIT(KConnecting, "Connecting..."); |
|
25 _LIT(KRegistry, "Registry changed."); |
|
26 _LIT(KLimited, "Limited discoverable:"); |
|
27 _LIT(KScanning, "Scans:"); // could resolve this into discoverable/connectable |
|
28 _LIT(KDeviceClass, "DeviceClass:"); |
|
29 _LIT(KDeviceName, "DeviceName:"); |
|
30 _LIT(KCorruptRegistry, "Registry reset at this point:"); |
|
31 _LIT(KDiscovering, "Discovering..."); |
|
32 |
|
33 GLDEF_D RTest test(_L("Bluetooth P&S Subscription Tests")); |
|
34 |
|
35 void ShowAddress() |
|
36 /** |
|
37 Shows the example of using a synchronous Get to retrieve local BTAddr |
|
38 |
|
39 */ |
|
40 { |
|
41 RProperty property; |
|
42 TBuf8<6> addr; |
|
43 |
|
44 TInt err = property.Get(KPropertyUidBluetoothCategory, |
|
45 KPropertyKeyBluetoothGetLocalDeviceAddress, addr); |
|
46 |
|
47 if (err) |
|
48 test.Printf(_L("P&S: ERROR retrieving local address\n")); |
|
49 else |
|
50 { |
|
51 TBTDevAddr localAddress(addr); |
|
52 TBuf<20> dispBuf; |
|
53 localAddress.GetReadable(dispBuf); |
|
54 test.Printf(_L("Local address = 0x%S\n"),&dispBuf); |
|
55 } |
|
56 } |
|
57 |
|
58 void TestL() |
|
59 { |
|
60 // first do a sync test |
|
61 ShowAddress(); |
|
62 |
|
63 RPointerArray<CSubscriber> subscribers; |
|
64 |
|
65 //ignoring errors! |
|
66 subscribers.Append(CSubscriber::NewL(test, KPropertyKeyBluetoothGetPHYCount, KNumLinks)); |
|
67 subscribers.Append(CSubscriber::NewL(test, KPropertyKeyBluetoothGetRegistryTableChange, KRegistry)); |
|
68 subscribers.Append(CSubscriber::NewL(test, KPropertyKeyBluetoothGetConnectingStatus, KConnecting)); |
|
69 subscribers.Append(CSubscriber::NewL(test, KPropertyKeyBluetoothGetScanningStatus, KScanning)); |
|
70 subscribers.Append(CSubscriber::NewL(test, KPropertyKeyBluetoothGetLimitedDiscoverableStatus, KLimited)); |
|
71 subscribers.Append(CSubscriber::NewL(test, KPropertyKeyBluetoothGetDeviceClass, KDeviceClass)); |
|
72 subscribers.Append(CSubscriber::NewL(test, KPropertyKeyBluetoothGetCorruptRegistryResetIndication, KCorruptRegistry)); |
|
73 subscribers.Append(CDeviceNameSubscriber::NewL(test, KPropertyKeyBluetoothGetDeviceName, KDeviceName)); |
|
74 subscribers.Append(CSubscriber::NewL(test, KPropertyKeyBluetoothHostResolverActive, KDiscovering)); |
|
75 |
|
76 test.Printf(_L("%d Subscribers\n"), subscribers.Count()); |
|
77 |
|
78 for (TInt i=0; i<subscribers.Count(); i++) |
|
79 subscribers[i]->Start(); |
|
80 |
|
81 CActiveScheduler::Start(); |
|
82 subscribers.ResetAndDestroy(); |
|
83 } |
|
84 |
|
85 |
|
86 CSubscriber* CSubscriber::NewL(RTest& aTest, TUint aKey, const TDesC& aString) |
|
87 { |
|
88 CSubscriber* s = new(ELeave) CSubscriber(aTest, aString); |
|
89 CleanupStack::PushL(s); |
|
90 s->ConstructL(aKey); |
|
91 CleanupStack::Pop(s); |
|
92 return s; |
|
93 } |
|
94 |
|
95 CSubscriber::CSubscriber(RTest& aTest, const TDesC& aString) |
|
96 : CActive(EPriorityStandard), iTest(aTest), iString(aString) |
|
97 { |
|
98 CActiveScheduler::Add(this); |
|
99 } |
|
100 |
|
101 CSubscriber::~CSubscriber() |
|
102 { |
|
103 Cancel(); |
|
104 } |
|
105 |
|
106 void CSubscriber::ConstructL(TUint aKey) |
|
107 { |
|
108 User::LeaveIfError(iProperty.Attach(KPropertyUidBluetoothCategory, aKey)); |
|
109 } |
|
110 |
|
111 void CSubscriber::Start() |
|
112 { |
|
113 iProperty.Subscribe(iStatus); |
|
114 SetActive(); |
|
115 } |
|
116 |
|
117 void CSubscriber::RunL() |
|
118 { |
|
119 Start(); |
|
120 TInt val; |
|
121 iProperty.Get(val); |
|
122 |
|
123 iTest.Printf(_L("%S = %d\n"), &iString, val); |
|
124 } |
|
125 |
|
126 void CSubscriber::DoCancel() |
|
127 { |
|
128 iProperty.Cancel(); |
|
129 } |
|
130 |
|
131 /*************************************************************************/ |
|
132 // |
|
133 // CDeviceNameSubscriber Implementation |
|
134 // |
|
135 CDeviceNameSubscriber* CDeviceNameSubscriber::NewL(RTest& aTest, TUint aKey, const TDesC& aString) |
|
136 { |
|
137 CDeviceNameSubscriber* s = new(ELeave) CDeviceNameSubscriber(aTest, aString); |
|
138 CleanupStack::PushL(s); |
|
139 s->ConstructL(aKey); |
|
140 CleanupStack::Pop(s); |
|
141 return s; |
|
142 } |
|
143 |
|
144 CDeviceNameSubscriber::CDeviceNameSubscriber(RTest& aTest, const TDesC& aString) |
|
145 : CSubscriber(aTest,aString) |
|
146 { |
|
147 } |
|
148 |
|
149 CDeviceNameSubscriber::~CDeviceNameSubscriber() |
|
150 { |
|
151 // No need to cancel since it's done in the base class |
|
152 } |
|
153 |
|
154 void CDeviceNameSubscriber::RunL() |
|
155 { |
|
156 Start(); |
|
157 |
|
158 TBuf16<KHCILocalDeviceNameMaxLength> val; |
|
159 iProperty.Get(val); |
|
160 |
|
161 iTest.Printf(_L("%S = %S\n"), &iString, &val); |
|
162 } |
|
163 |
|
164 |
|
165 TInt E32Main() |
|
166 { |
|
167 CTrapCleanup* cleanupStack=CTrapCleanup::New(); |
|
168 CActiveScheduler::Install(new CActiveScheduler); |
|
169 |
|
170 TRAPD(err,TestL()); // Ignore err |
|
171 |
|
172 if (err != KErrNone) |
|
173 { |
|
174 test.Printf(_L("Error %d"), err); |
|
175 test.Getch(); |
|
176 } |
|
177 |
|
178 delete cleanupStack; |
|
179 return err; |
|
180 } |