|
1 // vtc_bt.cpp |
|
2 // |
|
3 // Copyright (c) 2008 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "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 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include <e32std.h> |
|
14 #include <fshell/consoleextensions.h> |
|
15 #include "vtc_bt.h" |
|
16 |
|
17 |
|
18 EXPORT_C TAny* NewConsole() |
|
19 { |
|
20 return new CBtConsole; |
|
21 } |
|
22 |
|
23 //______________________________________________________________________________ |
|
24 // CBtConsole |
|
25 CBtConsole::CBtConsole() |
|
26 { |
|
27 } |
|
28 |
|
29 CBtConsole::~CBtConsole() |
|
30 { |
|
31 iBtConnection.Close(); |
|
32 } |
|
33 |
|
34 _LIT(KWaitingForBt, "Waiting for Bluetooth connection"); |
|
35 _LIT(KConnectionErrorFmt, "Bluetooth connection error - %d"); |
|
36 _LIT(KConnectedNameAddrFmt, "BT device '%S' (%02x:%02x:%02x:%02x:%02x:%02x) connected"); |
|
37 _LIT(KConnectedAddrFmt, "BT device %02x:%02x:%02x:%02x:%02x:%02x connected"); |
|
38 |
|
39 void CBtConsole::ConstructL(const TDesC& aTitle) |
|
40 { |
|
41 // Run the preamble script, if we have one. Because iosrv is multithreaded this shouldn't cause a deadlock so long as we use a different console (in this case, nullcons) |
|
42 _LIT(KPreamble, "--console nullcons vt100btcons_preamble"); |
|
43 RProcess preamble; |
|
44 TRequestStatus stat; |
|
45 TInt err = preamble.Create(_L("fshell.exe"), KPreamble); |
|
46 if (err == KErrNone) |
|
47 { |
|
48 preamble.Logon(stat); |
|
49 if (stat == KRequestPending) |
|
50 { |
|
51 preamble.Resume(); |
|
52 User::WaitForRequest(stat); |
|
53 } |
|
54 err = stat.Int(); |
|
55 preamble.Close(); |
|
56 } |
|
57 |
|
58 if (err == KErrNone) |
|
59 { |
|
60 Message(EInformation, _L("Preamble script ran ok")); |
|
61 } |
|
62 else if (err != KErrNotFound) |
|
63 { |
|
64 Message(EInformation, _L("Preamble script failed with %d"), err); |
|
65 } |
|
66 |
|
67 |
|
68 User::LeaveIfError(iBtConnection.Connect()); |
|
69 iBtConnection.WaitForConnection(stat); |
|
70 Message(EInformation, KWaitingForBt); |
|
71 User::WaitForRequest(stat); |
|
72 if (stat.Int() != KErrNone) |
|
73 { |
|
74 Message(EError, KConnectionErrorFmt, stat.Int()); |
|
75 User::Leave(stat.Int()); |
|
76 } |
|
77 |
|
78 TBTDevAddr addr; |
|
79 User::LeaveIfError(iBtConnection.GetConnectedDeviceAddr(addr)); |
|
80 TName name; |
|
81 |
|
82 TInt nerr = iBtConnection.GetConnectedDeviceName(name); |
|
83 if (nerr == KErrOverflow) nerr = KErrNone; |
|
84 |
|
85 if (nerr == KErrNone) |
|
86 { |
|
87 Message(EInformation, KConnectedNameAddrFmt, &name, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); |
|
88 } |
|
89 else |
|
90 { |
|
91 Message(EInformation, KConnectedAddrFmt, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); |
|
92 } |
|
93 |
|
94 CVtcConsoleBase::ConstructL(aTitle); |
|
95 } |
|
96 |
|
97 TInt CBtConsole::Output(const TDesC8& aDes) |
|
98 { |
|
99 TRequestStatus stat; |
|
100 iBtConnection.Write(aDes, stat); |
|
101 User::WaitForRequest(stat); |
|
102 return stat.Int(); |
|
103 } |
|
104 |
|
105 void CBtConsole::Input(TDes8& aDes, TRequestStatus& aStatus) |
|
106 { |
|
107 iBtConnection.Read(aDes, aStatus); |
|
108 } |
|
109 |
|
110 void CBtConsole::CancelInput(TRequestStatus&) |
|
111 { |
|
112 iBtConnection.CancelRead(); |
|
113 } |