|
1 // btserialclient.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 // Transient server example - client interface implementation |
|
14 |
|
15 #include <fshell/btserialclient.h> |
|
16 #include "btserialclientserver.h" |
|
17 #include "..\connection\btdebug.h" |
|
18 |
|
19 _LIT(KSubThreadName, "btconsolethread"); |
|
20 static const TInt KMaxHeapSize = 0x100000; // 1M |
|
21 |
|
22 TInt RBtSerialSession::StartServer() |
|
23 // |
|
24 // Start the server process. Simultaneous launching |
|
25 // of two such processes should be detected when the second one attempts to |
|
26 // create the server object, failing with KErrAlreadyExists. |
|
27 // |
|
28 { |
|
29 TInt err = iSubThread.Create(KSubThreadName, &ServerThread, KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &iServer); |
|
30 |
|
31 if (err != KErrNone) |
|
32 { |
|
33 return err; |
|
34 } |
|
35 |
|
36 TRequestStatus rendezvous; |
|
37 iSubThread.Rendezvous(rendezvous); |
|
38 |
|
39 iSubThread.Resume(); |
|
40 User::WaitForRequest(rendezvous); |
|
41 |
|
42 return rendezvous.Int(); |
|
43 } |
|
44 |
|
45 //______________________________________________________________________________ |
|
46 // RBtSerialSession |
|
47 EXPORT_C TInt RBtSerialSession::Connect() |
|
48 { |
|
49 TInt err = StartServer(); |
|
50 if (err == KErrNone) |
|
51 { |
|
52 TVersion ver; |
|
53 err = CreateSession(iServer, ver); |
|
54 } |
|
55 return err; |
|
56 } |
|
57 |
|
58 EXPORT_C void RBtSerialSession::Close() |
|
59 { |
|
60 TRACE1("RBtSerialSession::Close closing IPC session"); |
|
61 RSessionBase::Close(); |
|
62 // when we close the session (above) the server thread will exit. |
|
63 // logon and wait for it |
|
64 TRequestStatus stat; |
|
65 iSubThread.Logon(stat); |
|
66 TRACE1("RBtSerialSession::Close waiting for thread to exit"); |
|
67 User::WaitForRequest(stat); |
|
68 iSubThread.Close(); |
|
69 TRACE2("RBtSerialSession::Close done (%d)", stat.Int()); |
|
70 } |
|
71 |
|
72 EXPORT_C void RBtSerialSession::WaitForConnection(TRequestStatus& aStatus) |
|
73 { |
|
74 SendReceive(EBtSerialWaitForConnection, aStatus); |
|
75 } |
|
76 |
|
77 EXPORT_C void RBtSerialSession::CancelWaitForConnection() |
|
78 { |
|
79 SendReceive(EBtSerialCancelWaitForConnection); |
|
80 } |
|
81 |
|
82 EXPORT_C TInt RBtSerialSession::IsConnected() const |
|
83 { |
|
84 return SendReceive(EBtSerialIsConnected); |
|
85 } |
|
86 |
|
87 EXPORT_C void RBtSerialSession::Write(const TDesC8& aData, TRequestStatus& aStatus) |
|
88 { |
|
89 SendReceive(EBtSerialWrite, TIpcArgs(&aData), aStatus); |
|
90 } |
|
91 |
|
92 EXPORT_C void RBtSerialSession::CancelWrite() |
|
93 { |
|
94 SendReceive(EBtSerialCancelWrite); |
|
95 } |
|
96 |
|
97 EXPORT_C void RBtSerialSession::Read(TDes8& aData, TRequestStatus& aStatus) const |
|
98 { |
|
99 SendReceive(EBtSerialRead, TIpcArgs(&aData), aStatus); |
|
100 } |
|
101 |
|
102 EXPORT_C void RBtSerialSession::CancelRead() const |
|
103 { |
|
104 SendReceive(EBtSerialCancelRead); |
|
105 } |
|
106 |
|
107 EXPORT_C TInt RBtSerialSession::GetConnectedDeviceName(TDes& aName) |
|
108 { |
|
109 return SendReceive(EBtSerialGetConnectedDeviceName, TIpcArgs(&aName)); |
|
110 } |
|
111 |
|
112 EXPORT_C TInt RBtSerialSession::GetConnectedDeviceAddr(TBTDevAddr& aAddr) |
|
113 { |
|
114 TPckg<TBTDevAddr> pckg(aAddr); |
|
115 return SendReceive(EBtSerialGetConnectedDeviceAddr, TIpcArgs(&pckg)); |
|
116 } |