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: Socket writer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CSOCKETWRITER_H |
|
21 #define CSOCKETWRITER_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 |
|
26 // CONSTANTS |
|
27 const TInt KWriteBufferSize = 128; |
|
28 |
|
29 // FORWARD DECLARATIONS |
|
30 class MSocketWriterObserver; |
|
31 class RSocket; |
|
32 class CDesC8Array; |
|
33 |
|
34 // CLASS DECLARATION |
|
35 |
|
36 /** |
|
37 * Socket writer. Asynchronously writes data to opened socket. |
|
38 */ |
|
39 NONSHARABLE_CLASS( CSocketWriter ) : public CActive |
|
40 { |
|
41 public: // Constructors and destructor |
|
42 |
|
43 /** |
|
44 * Factory function. |
|
45 * @param aSocket RSocket instance which is used to write data. |
|
46 * @param aUDPRemotePort Remote UDB port. |
|
47 * @return New CSocketWriter instance. |
|
48 */ |
|
49 static CSocketWriter* NewL( RSocket& aSocket, |
|
50 TInt aUDPRemotePort = -1 ); |
|
51 |
|
52 /** |
|
53 * Factory function. |
|
54 * @param aSocket RSocket instance which is used to write data. |
|
55 * @param aUDPRemotePort Remote UDB port. |
|
56 * @return New CSocketWriter instance. |
|
57 */ |
|
58 static CSocketWriter* NewLC( RSocket& aSocket, |
|
59 TInt aUDPRemotePort = -1 ); |
|
60 |
|
61 /** |
|
62 * Destructor. |
|
63 */ |
|
64 ~CSocketWriter(); |
|
65 |
|
66 public: // New functions |
|
67 |
|
68 /** |
|
69 * Sets observer. |
|
70 * @param aObserver Pointer to observer. |
|
71 */ |
|
72 void SetObserver( MSocketWriterObserver* aObserver ); |
|
73 |
|
74 /** |
|
75 * Issues writing data to socket. If the request is already |
|
76 * pending the data will be written to queue and it will be |
|
77 * handled afterwards. |
|
78 * @param aData Data to be written. |
|
79 */ |
|
80 void IssueWriteL( const TDesC8& aData ); |
|
81 |
|
82 /** |
|
83 * Resets transfer buffer. |
|
84 */ |
|
85 void ResetTransferBuffer(); |
|
86 |
|
87 /** |
|
88 * Continues writing if there is something in the buffer left. |
|
89 */ |
|
90 void ContinueAfterError(); |
|
91 |
|
92 private: |
|
93 /** |
|
94 * Writes one descriptor from queue. |
|
95 */ |
|
96 void IssueWrite(); |
|
97 |
|
98 protected: // Functions from base classes |
|
99 |
|
100 /** |
|
101 * From CActive. Pending request has been completed. |
|
102 */ |
|
103 void RunL(); |
|
104 |
|
105 /** |
|
106 * From CActive. Pending request has been cancelled. |
|
107 */ |
|
108 void DoCancel(); |
|
109 |
|
110 /** |
|
111 * From CActive. RunL has leaved. |
|
112 */ |
|
113 TInt RunError( TInt aError ); |
|
114 |
|
115 |
|
116 private: |
|
117 |
|
118 /** |
|
119 * Default constructor. |
|
120 */ |
|
121 CSocketWriter( RSocket& aSocket, TInt aUDPRemotePort = -1 ); |
|
122 |
|
123 /** |
|
124 * 2nd phase constructor. |
|
125 */ |
|
126 void ConstructL(); |
|
127 |
|
128 private: // Data |
|
129 CDesC8Array* iTransferBufferArray; |
|
130 MSocketWriterObserver* iObserver; |
|
131 RSocket& iSocket; |
|
132 TBuf8<KWriteBufferSize> iWriteBuffer; |
|
133 RTimer iTimer; |
|
134 TBool iWaiting; |
|
135 const TInt iUDPRemotePort; |
|
136 }; |
|
137 |
|
138 #endif // CSOCKETWRITER_H |
|
139 |
|
140 // End of File |
|