|
1 // Copyright (c) 2005-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 <e32base.h> |
|
17 #include <f32file.h> |
|
18 #include <s32file.h> |
|
19 #include <s32stor.h> |
|
20 #include <e32cons.h> |
|
21 #include <e32std.h> |
|
22 |
|
23 _LIT(KConsoleName, "Ecom Server Ini File Writer"); |
|
24 _LIT(KFailedMessage, "failed: leave code=%d \n[press any key]"); |
|
25 _LIT(KOkMessage, "ok \n[press any key]"); |
|
26 |
|
27 // ini file |
|
28 _LIT(KIniFileName, "_:\\EComSrvr.ini"); |
|
29 static TBuf<15> IniFileName(KIniFileName); |
|
30 |
|
31 static TInt32 KEComUid = 0x10009D8F; |
|
32 static TInt32 KSsaUid = 0x00000001; |
|
33 static TInt8 KSsaEnabled = 0x01; |
|
34 static TInt8 KSsaDisabled = 0x00; |
|
35 |
|
36 /** |
|
37 @fn void WriteIniFileL() |
|
38 Open the ini file and store the values |
|
39 */ |
|
40 LOCAL_C void WriteIniFileL() |
|
41 { |
|
42 RFs fileSession; |
|
43 User::LeaveIfError(fileSession.Connect()); |
|
44 CleanupClosePushL(fileSession); |
|
45 |
|
46 // create folder path |
|
47 fileSession.MkDirAll(IniFileName); |
|
48 |
|
49 RFileWriteStream fileWriteStream; |
|
50 User::LeaveIfError(fileWriteStream.Create(fileSession, IniFileName ,EFileWrite)); |
|
51 CleanupClosePushL(fileWriteStream); |
|
52 |
|
53 //write the KEComUid to the stream |
|
54 fileWriteStream.WriteInt32L(KEComUid); |
|
55 |
|
56 //write the KSsaUid to the stream |
|
57 fileWriteStream.WriteInt32L(KSsaUid); |
|
58 |
|
59 //write the SSA value to the stream |
|
60 fileWriteStream.WriteInt8L(KSsaDisabled); |
|
61 |
|
62 //commit changes to the stream |
|
63 fileWriteStream.CommitL(); |
|
64 |
|
65 // close: fileSession, fileWriteStream |
|
66 CleanupStack::PopAndDestroy(2); |
|
67 } |
|
68 |
|
69 /** |
|
70 @fn void ReadIniFileL() |
|
71 Open the ini file and read the contents. Intended for manually testing the |
|
72 write code. |
|
73 */ |
|
74 LOCAL_C void ReadIniFileL() |
|
75 { |
|
76 RFs fileSession; |
|
77 User::LeaveIfError(fileSession.Connect()); |
|
78 CleanupClosePushL(fileSession); |
|
79 |
|
80 RFileReadStream fileReadStream; |
|
81 User::LeaveIfError(fileReadStream.Open(fileSession, IniFileName, EFileRead)); |
|
82 CleanupClosePushL(fileReadStream); |
|
83 |
|
84 TInt32 value1 = 0; |
|
85 TInt8 value2 = 0; |
|
86 |
|
87 //read the KEComUid and KSsaUid |
|
88 value1 = fileReadStream.ReadInt32L(); |
|
89 value1 = fileReadStream.ReadInt32L(); |
|
90 value2 = fileReadStream.ReadInt8L(); |
|
91 |
|
92 // close: fileSession, fileReadStream |
|
93 CleanupStack::PopAndDestroy(2); |
|
94 } |
|
95 |
|
96 /** |
|
97 @fn void StartConsoleL() |
|
98 Start the console and create the ini file, then call the read method |
|
99 to manually test the contents. |
|
100 */ |
|
101 LOCAL_C void StartConsoleL() |
|
102 { |
|
103 // set INI file drive |
|
104 IniFileName[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive()); |
|
105 |
|
106 // Create the console and put it on the cleanup stack |
|
107 CConsoleBase* console = |
|
108 Console::NewL(KConsoleName, TSize(KConsFullScreen, KConsFullScreen)); |
|
109 CleanupStack::PushL(console); |
|
110 |
|
111 // Call the main function and trap the result |
|
112 TRAPD(error, WriteIniFileL()); // create the ini file |
|
113 if(!error) |
|
114 { |
|
115 TRAPD(error2, ReadIniFileL()); // perform test |
|
116 error = error2; |
|
117 } |
|
118 if (error) |
|
119 console->Printf(KFailedMessage, error); |
|
120 else |
|
121 console->Printf(KOkMessage); |
|
122 |
|
123 CleanupStack::PopAndDestroy(console); // close console |
|
124 } |
|
125 |
|
126 /** |
|
127 @fn TInt E32Main() |
|
128 Main entry point to the console app called by E32 |
|
129 */ |
|
130 GLDEF_C TInt E32Main() |
|
131 { |
|
132 __UHEAP_MARK; |
|
133 |
|
134 CTrapCleanup* cleanupStack = CTrapCleanup::New();// create clean-up stack |
|
135 TRAP_IGNORE(StartConsoleL()); // start program |
|
136 delete cleanupStack; // destroy clean-up stack |
|
137 |
|
138 __UHEAP_MARKEND; |
|
139 |
|
140 return KErrNone; // and return No Error |
|
141 } |
|
142 |