|
1 /* |
|
2 * Copyright (c) 2002 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 the License "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: |
|
15 * Declaration of class CConnection. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #ifndef CONNECTION_H |
|
22 #define CONNECTION_H |
|
23 |
|
24 // INCLUDES |
|
25 |
|
26 #include <e32base.h> |
|
27 #include <es_sock.h> |
|
28 #include <CommDbConnPref.h> |
|
29 |
|
30 // CLASS DECLARATION |
|
31 |
|
32 /** |
|
33 * Connection Active Object. |
|
34 */ |
|
35 NONSHARABLE_CLASS( CConnection ) : public CActive |
|
36 { |
|
37 public: // Constructors and destructor. |
|
38 |
|
39 /** |
|
40 * Two phased constructor. Leaves on failure. |
|
41 * @return The created connection factory. |
|
42 */ |
|
43 static CConnection* NewL(); |
|
44 |
|
45 /** |
|
46 * Destructor. |
|
47 */ |
|
48 ~CConnection(); |
|
49 |
|
50 public: // new methods |
|
51 |
|
52 /** |
|
53 * Connect to network, create new connection if required. |
|
54 * @param aIap IAP. |
|
55 * @param aStatus Completes when done. |
|
56 */ |
|
57 void ConnectL( TUint32 aIap, TRequestStatus* aStatus ); |
|
58 |
|
59 /** |
|
60 * Connect to network, attach-only. |
|
61 * @param aIap IAP. |
|
62 */ |
|
63 void AttachL( TUint32 aIap ); |
|
64 |
|
65 /** |
|
66 * Close connection. If a request is outstanding, it is cancelled. |
|
67 */ |
|
68 void Close(); |
|
69 |
|
70 /** |
|
71 * Check if connected. |
|
72 * @param aIap IAP of active connection returned here. |
|
73 * @return ETrue if connected, EFalse otherwise. |
|
74 */ |
|
75 TBool IsConnected( TUint32& aIap ); |
|
76 |
|
77 /** |
|
78 * Get socket server handle. |
|
79 * @return Socket server handle. |
|
80 */ |
|
81 inline RSocketServ& SockServ(); |
|
82 |
|
83 /** |
|
84 * Get connection handle. |
|
85 * @return Connection handle. |
|
86 */ |
|
87 inline RConnection& Conn(); |
|
88 |
|
89 private: // types |
|
90 |
|
91 enum TState ///< State. |
|
92 { |
|
93 EInit, ///< Initial state (idle). |
|
94 EConnecting, ///< Connecting in progress. |
|
95 EConnected ///< Connected. |
|
96 }; |
|
97 |
|
98 private: // Constructors and destructor. |
|
99 |
|
100 /** |
|
101 * Constructor. |
|
102 */ |
|
103 CConnection(); |
|
104 |
|
105 /** |
|
106 * Second phase constructor. Leaves on failure. |
|
107 */ |
|
108 void ConstructL(); |
|
109 |
|
110 private: // from CActive |
|
111 |
|
112 /** |
|
113 * Cancel protocol implementation. |
|
114 */ |
|
115 virtual void DoCancel(); |
|
116 |
|
117 /** |
|
118 * Outstanding request completed. |
|
119 */ |
|
120 virtual void RunL(); |
|
121 |
|
122 /** |
|
123 * Handle error. |
|
124 * @param aError Error code. |
|
125 * @return KErrNone. |
|
126 */ |
|
127 virtual TInt RunError( TInt aError ); |
|
128 |
|
129 private: // new methods |
|
130 |
|
131 /** |
|
132 * Implementation of close. |
|
133 */ |
|
134 void DoClose(); |
|
135 |
|
136 /** |
|
137 * Done. |
|
138 */ |
|
139 void Done(); |
|
140 |
|
141 private: // data |
|
142 |
|
143 RSocketServ iSockServ; ///< Socket Server session handle. |
|
144 RConnection iConn; ///< Connection handle. |
|
145 TState iState; ///< State. |
|
146 TRequestStatus* iParentStatus; ///< Parent status. |
|
147 TCommDbConnPref iConnPref; ///< Connection preferences. |
|
148 |
|
149 }; |
|
150 |
|
151 #include "Connection.inl" |
|
152 |
|
153 #endif /* def CONNECTION_H */ |