|
1 // BtSerialTest.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 <fshell/ioutils.h> |
|
14 #include <fshell/btserialclient.h> |
|
15 |
|
16 using namespace IoUtils; |
|
17 |
|
18 class CCmdBtSerialTest : public CCommandBase |
|
19 { |
|
20 public: |
|
21 static CCommandBase* NewLC(); |
|
22 ~CCmdBtSerialTest(); |
|
23 private: |
|
24 CCmdBtSerialTest(); |
|
25 private: // From CCommandBase. |
|
26 virtual const TDesC& Name() const; |
|
27 virtual const TDesC& Description() const; |
|
28 virtual void DoRunL(); |
|
29 virtual void ArgumentsL(RCommandArgumentList& aArguments); |
|
30 virtual void OptionsL(RCommandOptionList& aOptions); |
|
31 private: |
|
32 RBtSerialSession iSession; |
|
33 }; |
|
34 |
|
35 |
|
36 CCommandBase* CCmdBtSerialTest::NewLC() |
|
37 { |
|
38 CCmdBtSerialTest* self = new(ELeave) CCmdBtSerialTest(); |
|
39 CleanupStack::PushL(self); |
|
40 self->BaseConstructL(); |
|
41 return self; |
|
42 } |
|
43 |
|
44 CCmdBtSerialTest::~CCmdBtSerialTest() |
|
45 { |
|
46 } |
|
47 |
|
48 CCmdBtSerialTest::CCmdBtSerialTest() |
|
49 { |
|
50 } |
|
51 |
|
52 const TDesC& CCmdBtSerialTest::Name() const |
|
53 { |
|
54 _LIT(KName, "BtSerialTest"); |
|
55 |
|
56 return KName; |
|
57 } |
|
58 |
|
59 const TDesC& CCmdBtSerialTest::Description() const |
|
60 { |
|
61 _LIT(KDescription, "Test for BT serial incoming connection"); |
|
62 return KDescription; |
|
63 } |
|
64 |
|
65 void CCmdBtSerialTest::DoRunL() |
|
66 { |
|
67 TInt err = iSession.Connect(); |
|
68 if (err!=KErrNone) |
|
69 { |
|
70 Printf(_L("Failed to connect %d\n"), err); |
|
71 iSession.Close(); |
|
72 return; |
|
73 } |
|
74 TRequestStatus req; |
|
75 iSession.WaitForConnection(req); |
|
76 Printf(_L("Waiting for connection...\n")); |
|
77 User::WaitForRequest(req); |
|
78 Printf(_L("Connected %d\n"), req.Int()); |
|
79 |
|
80 TBuf8<0x100> buf; |
|
81 iSession.Read(buf, req); |
|
82 Printf(_L("Waiting for data...\n")); |
|
83 User::WaitForRequest(req); |
|
84 if (req != KErrNone) |
|
85 { |
|
86 Printf(_L("Read error %d\n"), req.Int()); |
|
87 } |
|
88 else |
|
89 { |
|
90 iSession.Write(buf, req); |
|
91 Printf(_L("Echoing data...\n")); |
|
92 User::WaitForRequest(req); |
|
93 Printf(_L("Write returns %d"), req.Int()); |
|
94 } |
|
95 |
|
96 iSession.Close(); |
|
97 } |
|
98 |
|
99 void CCmdBtSerialTest::ArgumentsL(RCommandArgumentList& /*aArguments*/) |
|
100 { |
|
101 } |
|
102 |
|
103 void CCmdBtSerialTest::OptionsL(RCommandOptionList& /*aOptions*/) |
|
104 { |
|
105 } |
|
106 |
|
107 |
|
108 EXE_BOILER_PLATE(CCmdBtSerialTest) |
|
109 |