|
1 /* |
|
2 * Component Name: Headset Simulator |
|
3 * Author: Comarch S.A. |
|
4 * Version: 1.0 |
|
5 * Copyright (c) 2010 Comarch S.A. |
|
6 * |
|
7 * This Software is submitted by Comarch S.A. to Symbian Foundation Limited on |
|
8 * the basis of the Member Contribution Agreement entered between Comarch S.A. |
|
9 * and Symbian Foundation Limited on 5th June 2009 (“Agreement”) and may be |
|
10 * used only in accordance with the terms and conditions of the Agreement. |
|
11 * Any other usage, duplication or redistribution of this Software is not |
|
12 * allowed without written permission of Comarch S.A. |
|
13 * |
|
14 */ |
|
15 |
|
16 #ifndef HSSERVER_H |
|
17 #define HSSERVER_H |
|
18 |
|
19 #include <bt_sock.h> |
|
20 #include <bttypes.h> |
|
21 |
|
22 class CBluetoothSocket; |
|
23 class RSocketServ; |
|
24 class MHsAcceptNewClientObserver; |
|
25 |
|
26 /** The number of connections allowed in the queue */ |
|
27 const TUint KListenQueueSize = 10; |
|
28 |
|
29 /** Buffer size */ |
|
30 const TInt KMaxTHSConnectionBufferSize = 1024; |
|
31 |
|
32 /** |
|
33 * @brief Server that listens and handles physical link connection with AG device. |
|
34 */ |
|
35 class CHsServer : public CBase, public MBluetoothSocketNotifier |
|
36 { |
|
37 public: |
|
38 |
|
39 /** |
|
40 * Two-phased constructor. |
|
41 * @param aSocketServ session of socket server |
|
42 * @return instance of class |
|
43 */ |
|
44 static CHsServer* NewL( RSocketServ &aSocketServ ); |
|
45 |
|
46 /** |
|
47 * Two-phased constructor. |
|
48 * @param aSocketServ session of socket server |
|
49 * @return instance of class |
|
50 */ |
|
51 static CHsServer* NewLC( RSocketServ &aSocketServ ); |
|
52 |
|
53 /** |
|
54 * Destructor |
|
55 */ |
|
56 ~CHsServer(); |
|
57 |
|
58 public: |
|
59 |
|
60 /** |
|
61 * Turns on server. Method listens (RFCOMM protocol) and accepts ongoing |
|
62 * connections. Server gets the first free port number in system. |
|
63 * |
|
64 * @return KErrNone if successful, |
|
65 * KErrAlreadyExists if server is already running, |
|
66 * otherwise one of the system-wide error codes |
|
67 */ |
|
68 TInt Listen(); |
|
69 |
|
70 /** |
|
71 * Returns server listening status. |
|
72 * |
|
73 * @return ETrue if server listens, otherwise EFalse |
|
74 */ |
|
75 TBool IsReady(); |
|
76 |
|
77 /** |
|
78 * Shutdowns server. Cancels receiving and sending data, disconnects |
|
79 * clients and destroys all bluetooth sockets. |
|
80 */ |
|
81 void Shutdown(); |
|
82 |
|
83 /** |
|
84 * Sets new client observer. |
|
85 * |
|
86 * @param aNewClientObserv reference to observer |
|
87 */ |
|
88 void SetNewClientObserver( MHsAcceptNewClientObserver &aNewClientObserv ); |
|
89 |
|
90 /** |
|
91 * Returns listening server port. |
|
92 * |
|
93 * @return port number |
|
94 */ |
|
95 TInt GetPort(); |
|
96 |
|
97 /** |
|
98 * Connects to AG client's socket. |
|
99 * |
|
100 * @param aAddr socket address |
|
101 * |
|
102 * @leave KErrInUse if the device is already being used |
|
103 */ |
|
104 void GetSocketAndTryToConnectL( const TBTSockAddr &aAddr ); |
|
105 |
|
106 protected: |
|
107 |
|
108 private: |
|
109 /** |
|
110 * Constructor for performing 1st stage construction |
|
111 * |
|
112 * @param aSocketServ session of socket server |
|
113 */ |
|
114 CHsServer( RSocketServ &aSocketServ ); |
|
115 |
|
116 /** |
|
117 * Constructor for performing 2nd stage construction |
|
118 */ |
|
119 void ConstructL(); |
|
120 |
|
121 private: |
|
122 //Methods inhertited from MBluetoothSocketNotifier |
|
123 void HandleConnectCompleteL( TInt aErr ); |
|
124 |
|
125 void HandleAcceptCompleteL( TInt aErr ); |
|
126 |
|
127 void HandleShutdownCompleteL( TInt aErr ); |
|
128 |
|
129 void HandleSendCompleteL( TInt aErr ); |
|
130 |
|
131 void HandleReceiveCompleteL( TInt aErr ); |
|
132 |
|
133 void HandleIoctlCompleteL( TInt aErr ); |
|
134 |
|
135 void HandleActivateBasebandEventNotifierCompleteL( TInt aErr, |
|
136 TBTBasebandEventNotification& aEventNotification ); |
|
137 private: |
|
138 |
|
139 /** Listening status */ |
|
140 TBool iListen; |
|
141 |
|
142 /** Server port */ |
|
143 TInt iPort; |
|
144 |
|
145 /** Service security */ |
|
146 TBTServiceSecurity iServerSecurity; |
|
147 |
|
148 /** Session of socket server */ |
|
149 RSocketServ &iSServ; |
|
150 |
|
151 /** Socket for listening for new connections */ |
|
152 CBluetoothSocket *iSocketServer; |
|
153 |
|
154 /** Client socket */ |
|
155 CBluetoothSocket *iBlankSocket; |
|
156 |
|
157 /** Second client socket */ |
|
158 CBluetoothSocket *iBlankSocket2; |
|
159 |
|
160 /** Pointer to observer */ |
|
161 MHsAcceptNewClientObserver *iNewClientObserver; |
|
162 }; |
|
163 |
|
164 #endif // HSSERVER_H |