|
1 /* |
|
2 * Copyright (c) 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: HtiNpdHlp implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <NpdApi.h> |
|
22 #include <eikenv.h> |
|
23 |
|
24 |
|
25 #ifdef __ENABLE_LOGGING__ |
|
26 |
|
27 #include <flogger.h> |
|
28 _LIT( KLogFolder, "hti" ); |
|
29 _LIT( KLogFile, "HtiNpdHlp.txt" ); |
|
30 |
|
31 #define HTI_LOG_TEXT(a1) {_LIT(temp, a1); RFileLogger::Write(KLogFolder, KLogFile, EFileLoggingModeAppend, temp);} |
|
32 #define HTI_LOG_DES(a1) {RFileLogger::Write(KLogFolder, KLogFile, EFileLoggingModeAppend, a1);} |
|
33 #define HTI_LOG_FORMAT(a1,a2) {_LIT(temp, a1); RFileLogger::WriteFormat(KLogFolder, KLogFile, EFileLoggingModeAppend, temp, (a2));} |
|
34 |
|
35 _LIT8(KFuncIn, "-=> %S"); |
|
36 _LIT8(KFuncOut, "<=- %S"); |
|
37 |
|
38 #define HTI_LOG_FUNC_IN(a1) {_LIT8(temp, a1); RFileLogger::WriteFormat(KLogFolder, KLogFile, EFileLoggingModeAppend, KFuncIn, &temp);} |
|
39 #define HTI_LOG_FUNC_OUT(a1) {_LIT8(temp, a1); RFileLogger::WriteFormat(KLogFolder, KLogFile, EFileLoggingModeAppend, KFuncOut, &temp);} |
|
40 |
|
41 #else // !__ENABLE_LOGGING__ |
|
42 |
|
43 #define HTI_LOG_TEXT(a1) |
|
44 #define HTI_LOG_DES(a1) |
|
45 #define HTI_LOG_FORMAT(a1,a2) |
|
46 #define HTI_LOG_FUNC_IN(a1) |
|
47 #define HTI_LOG_FUNC_OUT(a1) |
|
48 |
|
49 #endif // __ENABLE_LOGGING__ |
|
50 |
|
51 // CONSTANTS |
|
52 _LIT( KHtiNpdHlp, "HtiNpdHlp" ); |
|
53 |
|
54 _LIT( KCmdAddMemo, "AddMemo" ); |
|
55 _LIT( KCmdAddMemoFromFile, "AddMemoFromFile" ); |
|
56 _LIT( KCmdDeleteAll, "DeleteAll" ); |
|
57 |
|
58 _LIT( KNotepadDatabaseFile, "c:\\Private\\100012a5\\DBS_101F8878_Notepad.dat" ); |
|
59 |
|
60 // MACROS |
|
61 |
|
62 // LOCAL CONSTANTS AND MACROS |
|
63 |
|
64 // MODULE DATA STRUCTURES |
|
65 |
|
66 // LOCAL FUNCTION PROTOTYPES |
|
67 |
|
68 // FORWARD DECLARATIONS |
|
69 |
|
70 // ============================ LOCAL FUNCTIONS =============================== |
|
71 void HandleAddMemoL( TLex& aParser ) |
|
72 { |
|
73 HTI_LOG_FUNC_IN( "HandleAddMemoL" ); |
|
74 |
|
75 aParser.SkipSpace(); |
|
76 TPtrC text = aParser.Remainder(); |
|
77 |
|
78 if ( text.Length() == 0 ) |
|
79 { |
|
80 HTI_LOG_TEXT( "missing text arg" ); |
|
81 User::Leave(KErrArgument); |
|
82 } |
|
83 |
|
84 // NOTE: We need to create CCoeEnv to make CNotepadApi work. |
|
85 // This also creates a new cleaupstack so we need to destory |
|
86 // CCoeEnv's cleanupstack before leaving to make our cleanupstack |
|
87 // the topmost stack |
|
88 |
|
89 CCoeEnv* env = new CCoeEnv; |
|
90 TRAPD( err, env->ConstructL() ); |
|
91 if ( err ) |
|
92 { |
|
93 HTI_LOG_FORMAT( "CEikonEnv::ConstructL err %d", err ); |
|
94 User::Leave( err ); |
|
95 } |
|
96 |
|
97 TRAP( err, CNotepadApi::AddContentL( text ) ); |
|
98 if ( err ) |
|
99 { |
|
100 HTI_LOG_FORMAT( "CNotepadApi::AddContentL err %d", err ); |
|
101 env->DestroyEnvironment(); |
|
102 User::Leave( err ); |
|
103 } |
|
104 |
|
105 env->DestroyEnvironment(); |
|
106 |
|
107 HTI_LOG_FUNC_OUT( "HandleAddMemoL" ); |
|
108 } |
|
109 |
|
110 |
|
111 void HandleAddMemoFromFileL( TLex& aParser ) |
|
112 { |
|
113 HTI_LOG_FUNC_IN( "HandleAddMemoFromFileL" ); |
|
114 |
|
115 aParser.SkipSpaceAndMark(); |
|
116 aParser.SkipCharacters(); |
|
117 if ( aParser.TokenLength() <= 0 ) |
|
118 { |
|
119 User::Leave(KErrArgument); |
|
120 } |
|
121 |
|
122 TPtrC filename = aParser.MarkedToken(); |
|
123 |
|
124 /* |
|
125 NOTE: Maybe will add this later |
|
126 |
|
127 aParser.SkipSpaceAndMark(); |
|
128 aParser.SkipCharacters(); |
|
129 |
|
130 TPtrC encoding = KNullDesC; |
|
131 if ( aParser.TokenLength() > 0 ) |
|
132 { |
|
133 encoding.Set( aParser.MarkedToken() ); |
|
134 } |
|
135 */ |
|
136 |
|
137 CCoeEnv* env = new CCoeEnv; |
|
138 TRAPD( err, env->ConstructL() ); |
|
139 if ( err ) |
|
140 { |
|
141 HTI_LOG_FORMAT( "CEikonEnv::ConstructL err %d", err ); |
|
142 User::Leave( err ); |
|
143 } |
|
144 |
|
145 TRAP( err, CNotepadApi::SaveFileAsMemoL( filename ) ); |
|
146 if ( err ) |
|
147 { |
|
148 HTI_LOG_FORMAT( "CNotepadApi::SaveFileAsMemoL err %d", err ); |
|
149 env->DestroyEnvironment(); |
|
150 User::Leave( err ); |
|
151 } |
|
152 |
|
153 env->DestroyEnvironment(); |
|
154 |
|
155 HTI_LOG_FUNC_OUT( "HandleAddMemoFromFileL" ); |
|
156 } |
|
157 |
|
158 void HandleDeleteAllL() |
|
159 { |
|
160 HTI_LOG_FUNC_IN( "HandleDeleteAllL" ); |
|
161 TInt err = KErrNone; |
|
162 RFs fs; |
|
163 err = fs.Connect(); |
|
164 if ( err == KErrNone ) |
|
165 { |
|
166 err = fs.Delete( KNotepadDatabaseFile ); |
|
167 fs.Close(); |
|
168 } |
|
169 if ( err != KErrNone && err != KErrNotFound ) |
|
170 { |
|
171 HTI_LOG_FORMAT( "Notepad database delete failed %d", err ); |
|
172 User::Leave( err ); |
|
173 } |
|
174 HTI_LOG_FUNC_OUT( "HandleDeleteAllL" ); |
|
175 } |
|
176 |
|
177 |
|
178 LOCAL_C TInt StartL() |
|
179 { |
|
180 HTI_LOG_FUNC_IN( "StartL" ); |
|
181 TInt cmdLen = User::CommandLineLength(); |
|
182 HBufC* cmdLine = HBufC::NewLC( cmdLen ); |
|
183 TPtr ptCmdLine = cmdLine->Des(); |
|
184 User::CommandLine( ptCmdLine ); |
|
185 |
|
186 HTI_LOG_DES( *cmdLine ); |
|
187 |
|
188 //parse command line |
|
189 TLex parser( *cmdLine ); |
|
190 parser.SkipCharacters(); |
|
191 |
|
192 if ( parser.TokenLength() <= 0 ) |
|
193 { |
|
194 HTI_LOG_TEXT( "missing arguments" ); |
|
195 User::Leave( KErrArgument ); |
|
196 } |
|
197 |
|
198 |
|
199 TPtrC cmd = parser.MarkedToken(); |
|
200 |
|
201 if ( cmd == KCmdAddMemo ) |
|
202 { |
|
203 HandleAddMemoL( parser ); |
|
204 } |
|
205 else if ( cmd == KCmdAddMemoFromFile ) |
|
206 { |
|
207 HandleAddMemoFromFileL( parser ); |
|
208 } |
|
209 else if ( cmd == KCmdDeleteAll ) |
|
210 { |
|
211 HandleDeleteAllL(); |
|
212 } |
|
213 else |
|
214 { |
|
215 HTI_LOG_TEXT( "Unknown argument" ); |
|
216 User::Leave( KErrArgument ); |
|
217 } |
|
218 |
|
219 CleanupStack::PopAndDestroy(); // cmdLine |
|
220 HTI_LOG_FUNC_OUT( "StartL" ); |
|
221 return KErrNone; |
|
222 } |
|
223 |
|
224 |
|
225 GLDEF_C TInt E32Main() |
|
226 { |
|
227 __UHEAP_MARK; |
|
228 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
229 User::RenameThread( KHtiNpdHlp ); |
|
230 TRAPD( err, StartL() ); |
|
231 delete cleanup; |
|
232 __UHEAP_MARKEND; |
|
233 return err; |
|
234 } |
|
235 |
|
236 |
|
237 // End of File |