|
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: Definition of CCommAdapter that uses media plugins to read |
|
15 * HTI messages and send new ones back. Because comm plug-in |
|
16 * interface define async functions, this class is AO. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #ifndef MCOMMADAPTER_H__ |
|
22 #define MCOMMADAPTER_H__ |
|
23 |
|
24 #include <e32base.h> |
|
25 |
|
26 //forward declaration |
|
27 class CHtiDispatcher; |
|
28 class CHTICommPluginInterface; |
|
29 class CHtiMessage; |
|
30 |
|
31 class CHtiCommAdapter: public CActive |
|
32 { |
|
33 private: |
|
34 /** |
|
35 * Enum of different states depending on the current operation |
|
36 */ |
|
37 enum TCommState |
|
38 { |
|
39 EIdle, |
|
40 EReceiving, |
|
41 EReceivingCont, |
|
42 ESending |
|
43 }; |
|
44 |
|
45 public: |
|
46 /** |
|
47 * Construct the object and adds it to CActiveScheduler. |
|
48 * |
|
49 * @param aCommPlugin communication plug-in |
|
50 * @param aDispatcher message dispatcher |
|
51 * @param aMaxMsgSize max size of an incoming message that will be |
|
52 * accepted |
|
53 */ |
|
54 static CHtiCommAdapter* NewL(CHTICommPluginInterface* aCommPlugin, |
|
55 CHtiDispatcher* aDispatcher, |
|
56 TInt aMaxMsgSize); |
|
57 |
|
58 /** |
|
59 * Construct the object and adds it to CActiveScheduler |
|
60 * |
|
61 * @param aCommPlugin communication plug-in |
|
62 * @param aDispatcher message dispatcher |
|
63 * @param aMaxMsgSize max size of an incoming message that will be |
|
64 * accepted |
|
65 */ |
|
66 static CHtiCommAdapter* NewLC(CHTICommPluginInterface* aCommPlugin, |
|
67 CHtiDispatcher* aDispatcher, |
|
68 TInt aMaxMsgSize); |
|
69 |
|
70 /** |
|
71 * Destructor |
|
72 */ |
|
73 ~CHtiCommAdapter(); |
|
74 |
|
75 /** |
|
76 * Issue an async request to receive whole HTI message and |
|
77 * pass it to the framework on complition. |
|
78 */ |
|
79 void ReceiveMessage(); |
|
80 |
|
81 /** |
|
82 * Send a HTI message via comm plug-in. |
|
83 * Ownership of aMessage is tranfered to CCommAdapter. |
|
84 * When message is sent, aMessage will be deleted. |
|
85 * |
|
86 * @param aMessage a HTI message to send |
|
87 */ |
|
88 void SendMessage(CHtiMessage* aMessage); |
|
89 |
|
90 /** |
|
91 * Stop all ongoing operations and clean all internal buffers. |
|
92 */ |
|
93 void Reset(); |
|
94 |
|
95 protected: |
|
96 |
|
97 CHtiCommAdapter(CHtiDispatcher* aDispatcher, |
|
98 CHTICommPluginInterface* aCommPlugin, |
|
99 TInt aMaxMsgSize); |
|
100 |
|
101 void ConstructL(); |
|
102 |
|
103 |
|
104 /** |
|
105 * Issue request to receive the next packet. |
|
106 * If aContinue = ETrue than iState is set to EReceivingCont |
|
107 * Otherwise it set to EReceiving. |
|
108 * iState set to EReceivingCont after message beginning was received |
|
109 * and its continuation is expected |
|
110 * |
|
111 * @param aContinue continuation flag |
|
112 */ |
|
113 void ReceiveMessage(TBool aContinue); |
|
114 |
|
115 /** |
|
116 * Handle received data from buffer and reissue request |
|
117 */ |
|
118 void HandleReceiveL(); |
|
119 void HandleReceiveContL(); |
|
120 |
|
121 /** |
|
122 * Reissue request to send message |
|
123 */ |
|
124 void HandleSend(); |
|
125 |
|
126 |
|
127 protected: //from CActive |
|
128 void RunL(); |
|
129 void DoCancel(); |
|
130 TInt RunError(TInt aError); |
|
131 |
|
132 private: //data members |
|
133 |
|
134 /** |
|
135 * Current communication state |
|
136 */ |
|
137 TCommState iState; |
|
138 |
|
139 /** |
|
140 * Pointer to message dispatcher. |
|
141 */ |
|
142 CHtiDispatcher* iDispatcher; |
|
143 |
|
144 /** |
|
145 * Communication ECom plug-in |
|
146 */ |
|
147 CHTICommPluginInterface* iCommPlugin; |
|
148 |
|
149 /** |
|
150 * Buffer for receiving data. It'is allocated once and used for |
|
151 * all subsequent receiving operation. Data from this buffer copied |
|
152 * to iMsgToReceive buffer that than passed to the framework for |
|
153 * processing |
|
154 */ |
|
155 HBufC8* iBuffer; |
|
156 |
|
157 /** |
|
158 * Pointer to the buffer for receiveing data |
|
159 */ |
|
160 TPtr8 iBufferPtr; |
|
161 |
|
162 /** |
|
163 * HTI incoming message. It's passed to the framework |
|
164 * when whole message is received |
|
165 */ |
|
166 CHtiMessage* iMsgToReceive; |
|
167 |
|
168 /** |
|
169 * Small buffer used when there is some data left in iBuffer that |
|
170 * cannot be processed (less than min header size) |
|
171 */ |
|
172 HBufC8* iLeftovers; |
|
173 |
|
174 /** |
|
175 * Keep message passed in SendMessage() between calls to comm. plugin |
|
176 * and deleted when sending is complete |
|
177 */ |
|
178 CHtiMessage* iMsgToSend; |
|
179 |
|
180 /** |
|
181 * Pointer to the part of iMsgToSend started from iMsgToSendOffset |
|
182 * that is being sent via current comm. plug-in |
|
183 */ |
|
184 TPtrC8 iMsgToSendPtr; //ptr to msg part passed to plug-ins |
|
185 |
|
186 /** |
|
187 * Offset in iMsgToSend of a part that is being sent |
|
188 */ |
|
189 TInt iMsgToSendOffset; |
|
190 |
|
191 /** |
|
192 * Amount of receving bytes to skip. |
|
193 * It's ussed when there is no memory for incoming message or |
|
194 * its size too big. |
|
195 */ |
|
196 TInt iSkipLength; |
|
197 |
|
198 /** |
|
199 * Max message size to accept |
|
200 */ |
|
201 const TInt iMaxMessageSize; |
|
202 }; |
|
203 |
|
204 #endif |