|
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: Listens TCP port |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CTCPPORTLISTENER_H |
|
21 #define CTCPPORTLISTENER_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <es_sock.h> |
|
26 |
|
27 |
|
28 // FORWARD DECLARATIONS |
|
29 class MTCPPortListenerObserver; |
|
30 |
|
31 // CLASS DECLARATION |
|
32 |
|
33 /** |
|
34 * ActiveObject which listens a TCP port. |
|
35 */ |
|
36 NONSHARABLE_CLASS( CTCPPortListener ) : public CActive |
|
37 { |
|
38 public: // Constructors and destructor |
|
39 |
|
40 /** |
|
41 * Factory function. |
|
42 * @param aPort TCP port to listen. |
|
43 * @param aObserver Pointer to observer. |
|
44 */ |
|
45 static CTCPPortListener* NewL( TInt aPort, |
|
46 MTCPPortListenerObserver* aObserver ); |
|
47 |
|
48 /** |
|
49 * Factory function. |
|
50 * @param aPort TCP port to listen. |
|
51 * @param aObserver Pointer to observer. |
|
52 */ |
|
53 static CTCPPortListener* NewLC( TInt aPort, |
|
54 MTCPPortListenerObserver* aObserver ); |
|
55 |
|
56 /** |
|
57 * Destructor. |
|
58 */ |
|
59 ~CTCPPortListener(); |
|
60 |
|
61 public: // New functions |
|
62 |
|
63 /** |
|
64 * Starts listening the port. |
|
65 */ |
|
66 void IssueListen(); |
|
67 |
|
68 /** |
|
69 * Retrieve current port number for this listener |
|
70 * @return Port number for this listening socket |
|
71 */ |
|
72 TInt Port() const; |
|
73 |
|
74 public: // Functions from base classes |
|
75 |
|
76 /** |
|
77 * From CActive. Pending request has been completed. |
|
78 */ |
|
79 void RunL(); |
|
80 |
|
81 /** |
|
82 * From CActive. Pending request has been cancelled. |
|
83 */ |
|
84 void DoCancel(); |
|
85 |
|
86 /** |
|
87 * From CActive. RunL has leaved. |
|
88 */ |
|
89 TInt RunError( TInt aError ); |
|
90 |
|
91 private: |
|
92 |
|
93 /** |
|
94 * Default constructor. |
|
95 * @param aPort TCP port to listen. |
|
96 * @param aObserver Pointer to observer. |
|
97 */ |
|
98 CTCPPortListener( TInt aPort, |
|
99 MTCPPortListenerObserver* aObserver ); |
|
100 |
|
101 /** |
|
102 * 2nd phase constructor. |
|
103 */ |
|
104 void ConstructL(); |
|
105 |
|
106 private: // Data |
|
107 MTCPPortListenerObserver* iObserver; |
|
108 TInt iPort; |
|
109 RSocketServ iSocketServer; |
|
110 RSocket iListeningSocket; |
|
111 RSocket* iAcceptedSocket; |
|
112 }; |
|
113 |
|
114 #endif // CTCPPORTLISTENER_H |
|
115 |
|
116 // End of File |