|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef __CSOCKETWRITER_H__ |
|
17 #define __CSOCKETWRITER_H__ |
|
18 |
|
19 #include <e32base.h> |
|
20 |
|
21 #include "moutputstream.h" |
|
22 #include "cimapobservabletimer.h" |
|
23 |
|
24 // Forward declarations |
|
25 class CSocket; |
|
26 class MOutputSocketObserver; |
|
27 class MSocketController; |
|
28 |
|
29 /** |
|
30 The CSocketWriter class encapsulates the writing functionality and behaviour |
|
31 for a connected socket. It implements the MOutputStream API. |
|
32 |
|
33 @see MOutputStream |
|
34 @internalTechnology |
|
35 @prototype |
|
36 */ |
|
37 class CSocketWriter : public CActive, public MOutputStream, public MImapTimerObserver |
|
38 { |
|
39 public: |
|
40 static CSocketWriter* NewL(CSocket& aSocket, MSocketController& aController); |
|
41 virtual ~CSocketWriter(); |
|
42 |
|
43 void SocketClosed(TInt aError); |
|
44 virtual void SecureClientReq(const TDesC8& aSSLDomainName); |
|
45 |
|
46 private: |
|
47 CSocketWriter(CSocket& aSocket, MSocketController& aController); |
|
48 void ConstructL(); |
|
49 void CompleteSelf(); |
|
50 |
|
51 // from MOutputStream |
|
52 virtual void Bind(MOutputStreamObserver& aObserver, TInt aLogId); |
|
53 virtual void BindSecure(MOutputStreamSecureObserver& aObserver); |
|
54 virtual void SendDataReq(const TDesC8& aBuffer, TInt aIdleTime = 0); |
|
55 virtual void Close(); |
|
56 |
|
57 // from CActive |
|
58 virtual void RunL(); |
|
59 virtual void DoCancel(); |
|
60 virtual TInt RunError(TInt aError); |
|
61 void CloseStreams(TInt aError); |
|
62 // from MImapTimerObserver |
|
63 void OnTimerL(const CImapObservableTimer& aSourceTimer); |
|
64 |
|
65 private: |
|
66 /** The state machine for the output stream. */ |
|
67 enum TOutputState |
|
68 { |
|
69 /** The output stream is waiting for an observer to bind itself to it. */ |
|
70 EIdle = 0, |
|
71 /** The output stream is ready to send data to the socket. It is waiting for the observer to request a data send. */ |
|
72 EPendingSend, |
|
73 /** Data has been sent to the socket. The output stream is waiting for the socket to notify it that the write was successful. */ |
|
74 ESentData, |
|
75 /** Start the secure handshake procedure. */ |
|
76 EStartSecureHandshake, |
|
77 /** Secure handshake has completed. */ |
|
78 ESecureHandshakeComplete, |
|
79 /** The observer has asked the output stream to close the socket. */ |
|
80 EClosing, |
|
81 /** The socket has been closed - data can no longer be sent to it. */ |
|
82 EClosed |
|
83 }; |
|
84 |
|
85 private: |
|
86 /** The connected socket.*/ |
|
87 CSocket& iSocket; |
|
88 /** The socket controller that owns the socket.*/ |
|
89 MSocketController& iController; |
|
90 /** The state of the output stream. */ |
|
91 TOutputState iState; |
|
92 /** The observer for the output stream. */ |
|
93 MOutputStreamObserver* iObserver; |
|
94 /** The observer for the output stream for secure socket notifications. */ |
|
95 MOutputStreamSecureObserver* iSecureObserver; |
|
96 /** SSL domain name to use for certificate validation. */ |
|
97 TPtrC8 iSSLDomainName; |
|
98 /** Log file identifier */ |
|
99 TInt iLogId; |
|
100 CImapObservableTimer* iTimer; |
|
101 }; |
|
102 |
|
103 #endif // __CSOCKETWRITER_H__ |