|
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 // |
|
15 |
|
16 #include <in_sock.h> |
|
17 #include <c32comm.h> |
|
18 #include <e32base.h> |
|
19 #include <es_sock.h> |
|
20 #include <tftpeng.h> |
|
21 #include <nifman.h> |
|
22 |
|
23 // Device driver names |
|
24 #ifndef __EPOC32__ |
|
25 #define PDD_NAME _L("ECDRV") |
|
26 #define LDD_NAME _L("ECOMM") |
|
27 #else |
|
28 #define PDD_NAME _L("EUART1") |
|
29 #define LDD_NAME _L("ECOMM") |
|
30 #endif |
|
31 |
|
32 LOCAL_C void InitCommsL(); |
|
33 LOCAL_C void ProgramL(); |
|
34 |
|
35 //temporary const for TFTP server on own machine |
|
36 _LIT(KInetTempAddr, "10.159.24.32"); |
|
37 //const for file to be moved |
|
38 _LIT(KFileToMove, "test.cpp"); |
|
39 |
|
40 class CCommandParser: public CAsyncOneShot, public MTftpNotifier |
|
41 { |
|
42 |
|
43 public: |
|
44 ~CCommandParser(); |
|
45 static CCommandParser* NewL(CConsoleBase& aConsole); |
|
46 |
|
47 protected: |
|
48 CCommandParser(CConsoleBase& aConsole); |
|
49 void ConstructL(); |
|
50 virtual void RunL(); |
|
51 virtual void OpComplete(TOpComp aResult, TInt aOp); |
|
52 virtual void ProgressNotification(); |
|
53 private: |
|
54 CConsoleBase& iConsole; |
|
55 CTftpEngine* iEngine; |
|
56 }; |
|
57 |
|
58 GLDEF_C TInt E32Main() |
|
59 { |
|
60 __UHEAP_MARK; |
|
61 CTrapCleanup* trap = CTrapCleanup::New(); |
|
62 if(trap==NULL) |
|
63 return KErrNoMemory; |
|
64 |
|
65 TInt err = KErrNone; |
|
66 |
|
67 TRAP(err, ProgramL()); |
|
68 |
|
69 delete trap; |
|
70 __UHEAP_MARKEND; |
|
71 return err; |
|
72 } |
|
73 |
|
74 // |
|
75 // Set up Epoc environment. Put in separate function so we can |
|
76 // let heap allocations fail and leave, trapping them all in |
|
77 // one place above. |
|
78 // |
|
79 LOCAL_C void ProgramL() |
|
80 { |
|
81 CActiveScheduler* pS = new(ELeave) CActiveScheduler; |
|
82 CleanupStack::PushL(pS); |
|
83 |
|
84 //initialization for COMM port (TFTP server on comm2) |
|
85 InitCommsL(); |
|
86 |
|
87 CActiveScheduler::Install(pS); |
|
88 //create console for output |
|
89 CConsoleBase* console = Console::NewL(_L("TFTP"),TSize(KConsFullScreen,KConsFullScreen)); |
|
90 CleanupStack::PushL(console); |
|
91 CCommandParser* compars= CCommandParser::NewL(*console); |
|
92 compars->Call(); |
|
93 |
|
94 CActiveScheduler::Start(); |
|
95 |
|
96 delete compars; |
|
97 CleanupStack::PopAndDestroy(console); |
|
98 CleanupStack::PopAndDestroy(pS); |
|
99 } |
|
100 |
|
101 LOCAL_C void InitCommsL() |
|
102 // |
|
103 // Initialisation code - loads the serial LDD and PDD |
|
104 // starts the comm subsystem (for EPOC32 builds) |
|
105 // On a full EPOC implementation, this code would not |
|
106 // be required because higher level components (EIKON) |
|
107 // automatically start the services. |
|
108 // |
|
109 { |
|
110 // Load the physical device driver |
|
111 // The OS will automatically append .PDD and |
|
112 // search /System/Libs on all drives. |
|
113 TInt r=User::LoadPhysicalDevice(PDD_NAME); |
|
114 if (r != KErrNone && r!= KErrAlreadyExists) |
|
115 User::Leave(r); |
|
116 //test(r==KErrNone || r==KErrAlreadyExists); |
|
117 |
|
118 // Similarly for the Logical device driver |
|
119 r=User::LoadLogicalDevice(LDD_NAME); |
|
120 if (r != KErrNone && r != KErrAlreadyExists) |
|
121 User::Leave(r); |
|
122 //test(r==KErrNone|| r==KErrAlreadyExists); |
|
123 |
|
124 // User::LeaveIfError(Nifman::CheckIniConfig()); |
|
125 } |
|
126 |
|
127 CCommandParser::~CCommandParser() |
|
128 // |
|
129 // C++ D'tor |
|
130 // |
|
131 { |
|
132 delete iEngine; |
|
133 } |
|
134 |
|
135 CCommandParser::CCommandParser(CConsoleBase& aConsole) |
|
136 : CAsyncOneShot(0), iConsole(aConsole) |
|
137 // |
|
138 // C++ C'tor |
|
139 // |
|
140 { |
|
141 } |
|
142 |
|
143 void CCommandParser::ConstructL() |
|
144 // |
|
145 // E32 C'tor |
|
146 // |
|
147 { |
|
148 iEngine = CTftpEngine::NewL(0, *this); |
|
149 } |
|
150 |
|
151 void CCommandParser::RunL() |
|
152 // |
|
153 // Run method |
|
154 // |
|
155 { |
|
156 iConsole.Printf(_L("TFTP>")); |
|
157 TBuf<0x100> command; |
|
158 TKeyCode key; |
|
159 while((key=iConsole.Getch())!=EKeyEnter) |
|
160 { |
|
161 if(command.Length()>=0x100) |
|
162 User::Beep(440, 500000); |
|
163 else if(key == EKeyBackspace) |
|
164 { |
|
165 if(command.Length()) |
|
166 { |
|
167 iConsole.Printf(_L("%c"), key); |
|
168 command.SetLength(command.Length()-1); |
|
169 } |
|
170 } |
|
171 else |
|
172 { |
|
173 iConsole.Printf(_L("%c"), key); |
|
174 command.Append(TChar(key)); |
|
175 } |
|
176 } |
|
177 |
|
178 iConsole.Printf(_L("\n Command %S\n"), &command); |
|
179 if(!command.CompareF(_L("quit"))) |
|
180 CActiveScheduler::Stop(); |
|
181 else if(!command.CompareF(_L("get"))) |
|
182 |
|
183 iEngine->Get(KInetTempAddr,KFileToMove); |
|
184 else if(!command.CompareF(_L("put"))) |
|
185 iEngine->Put(KInetTempAddr,KFileToMove); |
|
186 else |
|
187 { |
|
188 iConsole.Printf(_L("Unknown Function\n")); |
|
189 Call(); |
|
190 } |
|
191 } |
|
192 |
|
193 void CCommandParser::OpComplete(TOpComp aResult, TInt aOp) |
|
194 // |
|
195 // Operation completed |
|
196 // |
|
197 { |
|
198 iConsole.Printf(_L("\nOperation %d completed %d\n"), aOp, aResult); |
|
199 Call(); |
|
200 } |
|
201 |
|
202 void CCommandParser::ProgressNotification() |
|
203 // |
|
204 // Progress indication |
|
205 // |
|
206 { |
|
207 iConsole.Printf(_L(".")); |
|
208 } |
|
209 |
|
210 CCommandParser* CCommandParser::NewL(CConsoleBase& aConsl) |
|
211 // |
|
212 // Create and connect client with leaving |
|
213 // |
|
214 { |
|
215 CCommandParser* p = new (ELeave) CCommandParser(aConsl); |
|
216 CleanupStack::PushL(p); |
|
217 p->ConstructL(); |
|
218 CleanupStack::Pop(p); |
|
219 return p; |
|
220 } |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |