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: General purpose socket implementetion |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CSOCKET_H |
|
21 #define CSOCKET_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include "MSocketWriterObserver.h" |
|
26 #include "MSocketReaderObserver.h" |
|
27 #include "MSocket.h" |
|
28 |
|
29 // FORWARD DECLARATIONS |
|
30 class CSocketWriter; |
|
31 class CSocketReader; |
|
32 |
|
33 // CLASS DECLARATION |
|
34 |
|
35 /** |
|
36 * General purpose socket implementetion. |
|
37 * With this class the client can write and receive data |
|
38 * to and from the opened RSocket object. |
|
39 */ |
|
40 NONSHARABLE_CLASS( CSocket ) : public CBase, |
|
41 public MSocketWriterObserver, |
|
42 public MSocketReaderObserver, |
|
43 public MSocket |
|
44 { |
|
45 public: // Constructors and destructor |
|
46 |
|
47 /** |
|
48 * Factory function. |
|
49 * @param aSocket Opened RSocket instance that is used to read and write |
|
50 * data. |
|
51 * @param aUDPRemotePort Remote UDB port. |
|
52 |
|
53 */ |
|
54 static CSocket* NewL( RSocket* aSocket, TInt aUDPRemotePort = -1 ); |
|
55 |
|
56 /** |
|
57 * Factory function. |
|
58 * @param aSocket Opened RSocket instance that is used to read and write |
|
59 * data. |
|
60 * @param aUDPRemotePort Remote UDB port. |
|
61 */ |
|
62 static CSocket* NewLC( RSocket* aSocket, TInt aUDPRemotePort = -1 ); |
|
63 |
|
64 /** |
|
65 * Destructor. |
|
66 */ |
|
67 virtual ~CSocket(); |
|
68 |
|
69 public: // New functions |
|
70 |
|
71 /** |
|
72 * @return RSocket object |
|
73 */ |
|
74 RSocket* GetRSocket(); |
|
75 |
|
76 /** |
|
77 * @return Local TCP port. |
|
78 */ |
|
79 TUint LocalPort() const; |
|
80 |
|
81 /** |
|
82 * @return Remote TCP port. |
|
83 */ |
|
84 TUint RemotePort() const; |
|
85 |
|
86 /** |
|
87 * Sets observer. |
|
88 * @param aObserver Pointer to observer. |
|
89 */ |
|
90 void SetObserver( MSocketObserver* aObserver ); |
|
91 |
|
92 /** |
|
93 * Sets the ownership mode of RSocket object. If set ETrue |
|
94 * the socket will be closed and RSocket object will be deleted |
|
95 * in the destruction. |
|
96 * @param aHasOwnership Ownership mode. |
|
97 */ |
|
98 void SetSocketOwnershipMode( TBool aHasOwnership ); |
|
99 |
|
100 /** |
|
101 * Starts receiving data. |
|
102 */ |
|
103 void IssueRead(); |
|
104 |
|
105 /** |
|
106 * Cancels all pending requests. |
|
107 */ |
|
108 void Cancel(); |
|
109 |
|
110 /* |
|
111 * Returns the protocol information of the socket |
|
112 */ |
|
113 void SocketInfo( TProtocolDesc& aDesc) const; |
|
114 |
|
115 /* |
|
116 * Is this a UDP socket |
|
117 */ |
|
118 TBool IsUDP() const; |
|
119 |
|
120 public: // From MSocketWriter |
|
121 /** |
|
122 * Issues writing data to socket. |
|
123 * @param aData Data to be written. |
|
124 */ |
|
125 void WriteL( const TDesC8& aData ); |
|
126 |
|
127 protected: // From MSocketReaderObserver |
|
128 /** |
|
129 * From MSocketReaderObserver. |
|
130 * Data has been received. |
|
131 * @param aData Received data. |
|
132 */ |
|
133 void DataReceivedL( const TDesC8& aData ); |
|
134 |
|
135 /** |
|
136 * From MSocketReaderObserver. |
|
137 * Notifies that error has occurred. |
|
138 * @param aErrorCode Error code. |
|
139 */ |
|
140 void ReaderErrorL( TInt aErrorCode ); |
|
141 |
|
142 /** |
|
143 * From MSocketWriterObserver. |
|
144 * Notifies that error has occurred. |
|
145 * @param aErrorCode Error code. |
|
146 */ |
|
147 void WriterErrorL( TInt aErrorCode ); |
|
148 |
|
149 /** |
|
150 * From MSocketWriterObserver. |
|
151 * Notifies that all data has succesfully been written. |
|
152 */ |
|
153 void BufferUnderrunL(); |
|
154 |
|
155 /** |
|
156 * From MSocketReaderObserver and MSocketWriterObserver. |
|
157 * Notifies that the observer has leaved while executing the callback |
|
158 * function. |
|
159 * @param aLeaveCode Leave code. |
|
160 */ |
|
161 void ObserverLeaved( TInt aLeaveCode ); |
|
162 |
|
163 |
|
164 private: |
|
165 |
|
166 /** |
|
167 * Default constructor. |
|
168 */ |
|
169 CSocket( RSocket* aSocket, TInt aUDPRemotePort = -1 ); |
|
170 |
|
171 /** |
|
172 * 2nd phase constructor. |
|
173 */ |
|
174 void ConstructL(); |
|
175 |
|
176 private: // Data |
|
177 RSocket* iSocket; |
|
178 CSocketWriter* iSocketWriter; |
|
179 CSocketReader* iSocketReader; |
|
180 MSocketObserver* iObserver; |
|
181 TBool iHasOwnership; |
|
182 const TInt iUDPRemotePort; |
|
183 }; |
|
184 |
|
185 #endif // CSOCKET_H |
|
186 |
|
187 // End of File |
|