1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Server side session in HtiBtCommServer. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CHTIBTCOMMSERVERSESSION_H |
|
20 #define CHTIBTCOMMSERVERSESSION_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32std.h> |
|
24 #include <e32base.h> |
|
25 |
|
26 #include "BtSerialClient.h" // MBtSerialClientObserver |
|
27 |
|
28 // FORWARD DECLARATIONS |
|
29 |
|
30 class CHtiBtCommServer; |
|
31 |
|
32 // CLASS DECLARATION |
|
33 |
|
34 /** |
|
35 * This class represents a client session in the server. |
|
36 * |
|
37 * Server owns one instance of session (meaning only one client session |
|
38 * is allowed for this server). |
|
39 * Session allows only one outstanding read request and write request at a time. |
|
40 * Read request and write request may be outstanding simultaneously. |
|
41 */ |
|
42 class CHtiBtCommServerSession : |
|
43 public CSession2, |
|
44 public MBtSerialClientObserver |
|
45 { |
|
46 public: |
|
47 |
|
48 /** |
|
49 * Two phase constructor. |
|
50 * |
|
51 * @param aServer Pointer to the server instance |
|
52 */ |
|
53 static CHtiBtCommServerSession* NewL( CHtiBtCommServer* aServer ); |
|
54 |
|
55 private: // Construction |
|
56 |
|
57 /** |
|
58 * C++ default constructor. |
|
59 * |
|
60 * @param aClient |
|
61 * @param aServer |
|
62 */ |
|
63 CHtiBtCommServerSession( CHtiBtCommServer* aServer ); |
|
64 |
|
65 /** |
|
66 * Second phase construction. |
|
67 */ |
|
68 void ConstructL(); |
|
69 |
|
70 /** |
|
71 * Destructor. |
|
72 */ |
|
73 ~CHtiBtCommServerSession(); |
|
74 |
|
75 private: // From MBtSerialClientObserver |
|
76 |
|
77 void ConnectedToServer(TInt aError); |
|
78 void DisconnectedFromServer(); |
|
79 void DataFromServer(const TDesC8& aData); |
|
80 void AllBufferedDataSent(); |
|
81 |
|
82 private: |
|
83 |
|
84 /** |
|
85 * Handle client request. This is invoced by client server framework. |
|
86 * @param aMessage Message object describing client request |
|
87 */ |
|
88 virtual void ServiceL(const RMessage2 &aMessage); |
|
89 |
|
90 /** |
|
91 * Determine client request type and delegate handling accordingly. |
|
92 * @param aMessage Message object describing client request |
|
93 */ |
|
94 void DispatchMessageL(const RMessage2 &aMessage); |
|
95 |
|
96 void HandleConnectRequestL(const RMessage2& aMessage); |
|
97 |
|
98 /** |
|
99 * Handle client's send request. |
|
100 * Copies data from client address space to internal send buffer and starts |
|
101 * sending it. |
|
102 * @param aMessage Message object describing client request |
|
103 */ |
|
104 void HandleSendRequestL(const RMessage2& aMessage); |
|
105 |
|
106 /** |
|
107 * Handle client's read request. |
|
108 * Wait for incoming data. Once received, copy its data to client's |
|
109 * address space and complete client's request. |
|
110 * @param aMessage Message object describing client request |
|
111 */ |
|
112 void HandleReadRequestL(const RMessage2& aMessage); |
|
113 |
|
114 /** |
|
115 * Handle client's cancel requests. |
|
116 * Cancel either read or write operation depending on client request. |
|
117 * @param aMessage Message object describing client request |
|
118 */ |
|
119 void HandleCancelRequestL(const RMessage2& aMessage); |
|
120 |
|
121 /** |
|
122 * Handle port number request |
|
123 * Write the port number of the currently connected service. If not |
|
124 * connected writes KErrDisconnected. |
|
125 */ |
|
126 void HandlePortNumberRequestL(const RMessage2& aMessage); |
|
127 |
|
128 private: // Helpers |
|
129 |
|
130 void PanicClient(TInt aPanic) const; |
|
131 void ResetAll(TInt aCompletionCode); |
|
132 void TryCompleteReadRequest(); |
|
133 |
|
134 private: // Data |
|
135 |
|
136 CHtiBtCommServer *iBtCommServer; // referenced |
|
137 |
|
138 RMessage2 iReadRequest; |
|
139 RMessage2 iWriteRequest; |
|
140 RMessage2 iConnectRequest; |
|
141 TBool iWriteRequestComplete; // ETrue: no previous pending write request |
|
142 TBool iReadRequestComplete; // ETrue: no previous pending read request |
|
143 TBool iConnectRequestComplete; |
|
144 |
|
145 CBtSerialClient* iBtClient; |
|
146 |
|
147 HBufC8* iIncomingDataBuf; // Coming from remote host |
|
148 HBufC8* iSendBuffer; // Sent to remote host |
|
149 |
|
150 }; |
|
151 |
|
152 #endif // CHTIBTCOMMSERVERSESSION_H |
|
153 |
|
154 // End of File |
|