|
1 // Copyright (c) 2001-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 // Started by AY, May 1997 |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32base.h> |
|
19 #include <es_sock.h> |
|
20 #include <in_sock.h> |
|
21 #include <e32test.h> |
|
22 #include <f32file.h> |
|
23 |
|
24 enum TOpCode |
|
25 { |
|
26 ERRQ=1,EWRQ,EDATA,EACK,EERR |
|
27 }; |
|
28 |
|
29 enum TOpComp |
|
30 { |
|
31 ETimedOut=1,ESendFail,ERecvFail,EOpComplete,EFileOpenFailure,EError |
|
32 }; |
|
33 |
|
34 class TTftpPacket : public TPtr8 |
|
35 { |
|
36 public: |
|
37 TTftpPacket(); |
|
38 TBool CheckBlock(); |
|
39 TInt OpCode(); |
|
40 void MakeRqst(const TOpCode aOpc, const TDesC& aName, const TDesC& aMode); |
|
41 void MakeAckn(); |
|
42 TInt MakeData(const TDesC8& aData); |
|
43 void MakeError();//will need error code (will then lookup msg? |
|
44 private: |
|
45 TUint8 iBuffer[516]; |
|
46 TUint16 iBlockNum; |
|
47 }; |
|
48 |
|
49 class CTftpEngine; |
|
50 |
|
51 class CTftpTimer: public CTimer |
|
52 { |
|
53 public: |
|
54 ~CTftpTimer(); |
|
55 static CTftpTimer* NewL(const TInt aPriority, CTftpEngine& aEngine); |
|
56 protected: |
|
57 CTftpTimer(const TInt aPriority, CTftpEngine& aEngine); |
|
58 void ConstructL(); |
|
59 virtual void RunL(); |
|
60 private: |
|
61 CTftpEngine& iEngine; |
|
62 }; |
|
63 |
|
64 class MTftpNotifier |
|
65 { |
|
66 public: |
|
67 virtual void OpComplete(TOpComp aResult, TInt aOp)=0; |
|
68 virtual void ProgressNotification()=0; |
|
69 }; |
|
70 |
|
71 class CTftpEngine: public CActive |
|
72 { |
|
73 private: |
|
74 enum TState |
|
75 { |
|
76 ESending, EReceiving, EComplete, ESendingLastData, |
|
77 ESendingLastAckn, EReceivingLast |
|
78 }; |
|
79 public: |
|
80 IMPORT_C ~CTftpEngine(); |
|
81 IMPORT_C void Get(const TDesC& aNetAddr, const TDesC& aName, const TDesC& aMode = _L("Octet")); |
|
82 IMPORT_C void Put(const TDesC& aNetAddr, const TDesC& aName, const TDesC& aMode = _L("Octet")); |
|
83 IMPORT_C void TimerExpired(); |
|
84 IMPORT_C void SetTimeOut(const TInt aTimeOut); |
|
85 IMPORT_C static CTftpEngine *NewL(const TInt aPriority, MTftpNotifier& aNotifier); |
|
86 |
|
87 protected: |
|
88 virtual void RunL(); |
|
89 virtual void DoCancel(); |
|
90 private: |
|
91 CTftpEngine(const TInt aPriority, MTftpNotifier& aNotifier); |
|
92 void ConstructL(); |
|
93 |
|
94 private: |
|
95 RSocketServ iSockServ; |
|
96 RSocket iSocket; |
|
97 RFs iFs; |
|
98 RFile iFile; |
|
99 CTftpTimer* iTimer; |
|
100 TTftpPacket iPacket; |
|
101 TInt iTimeOut; |
|
102 TInetAddr iAddress; |
|
103 TState iState; |
|
104 MTftpNotifier& iNotifier; |
|
105 }; |