|
1 /** |
|
2 * Copyright (c) 1998-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: |
|
15 * FTP protocol engine |
|
16 * Author: Philippe Gabriel |
|
17 * Implements objet controling the PI channel of the FTP protocol |
|
18 * Model the PI Channel as an FSM |
|
19 * Implements objet controling the PI channel of the FTP protocol |
|
20 * Model the PI Channel as an FSM |
|
21 * The FSM has 7 states: |
|
22 * Idle, Connecting, Disconnecting, Connected, Sending, Parsing |
|
23 * ParsingSending |
|
24 * Transitions between states are triggered by PI methods and events |
|
25 * coming from ESOCK |
|
26 * |
|
27 * |
|
28 */ |
|
29 |
|
30 |
|
31 |
|
32 /** |
|
33 @file PICHNL.CPP |
|
34 @internalComponent |
|
35 */ |
|
36 |
|
37 #if !defined(__PICHNL_H__) |
|
38 #define __PICHNL_H__ |
|
39 #include "DEBUG.H" |
|
40 #include "FTPDEF.H" |
|
41 #include <e32base.h> |
|
42 #include <in_sock.h> |
|
43 |
|
44 ////////////////////////////////////////////////////////////// |
|
45 // Definitions |
|
46 ////////////////////////////////////////////////////////////// |
|
47 class CFtpProtocol; |
|
48 class MPIChannelNotifier |
|
49 /** |
|
50 @internalComponent |
|
51 */ |
|
52 { |
|
53 public: |
|
54 /** |
|
55 Operation completion return codes. |
|
56 */ |
|
57 enum TPiOperationCompletion |
|
58 { |
|
59 EPiConnectComplete=0, |
|
60 EPiDisconnectComplete, |
|
61 EPiSendComplete, |
|
62 EPiOpCancelComplete |
|
63 }; |
|
64 /** |
|
65 Error status |
|
66 */ |
|
67 enum TPiOperationError |
|
68 { |
|
69 EPiConnectFailed=0, |
|
70 EPiConnectionReset, |
|
71 EPiDisconnectFailed, |
|
72 EPiSendFailed, |
|
73 EPiCancelFailed |
|
74 }; |
|
75 public: |
|
76 /** Notify of normal completion of an operation */ |
|
77 virtual void PIChannelOperationCompletion(const TPiOperationCompletion)=0; |
|
78 /** Notify of error performing an operation */ |
|
79 virtual void PIChannelOperationError(const TPiOperationError)=0; |
|
80 /** Notify of reception */ |
|
81 virtual void PIChannelRcvNotification(void)=0; |
|
82 }; |
|
83 |
|
84 class CPIChannel; |
|
85 |
|
86 NONSHARABLE_CLASS(CPISocketRead) : public CActive |
|
87 /** |
|
88 Active object waiting for incoming data |
|
89 @internalComponent |
|
90 */ |
|
91 { |
|
92 public: |
|
93 static CPISocketRead* NewL(MPIChannelNotifier* aNotifier, |
|
94 CPIChannel* aPIChannel); |
|
95 void ConstructL(); |
|
96 /** CActive */ |
|
97 void DoCancel(); |
|
98 /** CActive */ |
|
99 void RunL(); |
|
100 void IssueRead(TDes8& aBuffer); |
|
101 void SetSocket(RSocket* aSocket){iSocket = aSocket;} |
|
102 |
|
103 protected: |
|
104 CPISocketRead(MPIChannelNotifier*,CPIChannel*); |
|
105 |
|
106 private: |
|
107 RSocket* iSocket; |
|
108 MPIChannelNotifier* iNotifier; |
|
109 TSockXfrLength iRcvLen; |
|
110 CPIChannel* iPIChannel; |
|
111 }; |
|
112 |
|
113 |
|
114 NONSHARABLE_CLASS(CPIChannel) : public CActive |
|
115 /** |
|
116 PI Channel |
|
117 @internalComponent |
|
118 */ |
|
119 { |
|
120 friend class CPISocketRead; |
|
121 public: |
|
122 |
|
123 CPIChannel(MPIChannelNotifier*); |
|
124 ~CPIChannel(); |
|
125 static CPIChannel* NewL(MPIChannelNotifier*,RSocketServ&); |
|
126 /** Command interface */ |
|
127 /** Connect PI socket */ |
|
128 TBool Connect(TSockAddr& aNetAddr); |
|
129 void GetLocalAddress(TInetAddr& aLocalAddr); |
|
130 /** Disconnect PI socket */ |
|
131 void Disconnect(void); |
|
132 /** Returns state of DTP Channel */ |
|
133 TBool Busy(void); |
|
134 /** Send a command on the PI Channel */ |
|
135 void SendCommand(TDes8& aCommand,TUint aSomeFlags=0,TBool aSendCRLF=TRUE); |
|
136 /** Fetch the reply sent by the server */ |
|
137 void GetNextAnswer(TDes8& aBuffer); |
|
138 protected: |
|
139 void RunL(); |
|
140 void DoCancel(void); |
|
141 private: |
|
142 enum TState |
|
143 { |
|
144 EPIChannelIdle,EPIChannelConnecting,EPIChannelDisconnecting, |
|
145 EPIChannelConnected,EPIChannelSending |
|
146 }; |
|
147 enum TPanic |
|
148 { |
|
149 EPIPanicChannelConnected = -1, |
|
150 EPIPanicOutOfState = -2, |
|
151 EPIPanicChannelNotConnected = -3 |
|
152 }; |
|
153 void ConstructL(RSocketServ& aSockServ); |
|
154 /** The state of the FSM */ |
|
155 TState iPIChannelState; |
|
156 /** A socket server to be used for all socket operations */ |
|
157 RSocketServ iSockServ; |
|
158 RSocket iPiSocket; |
|
159 /** Last code sent by the FTP server */ |
|
160 TUint32 iPIServerCode; |
|
161 /** Active object receiving data */ |
|
162 CPISocketRead *iReceiver; |
|
163 MPIChannelNotifier* iNotifier; |
|
164 }; |
|
165 #endif // __PICHNL_H__ |