|
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: HtiDeviceReboot implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <hal.h> |
|
22 #include <starterclient.h> |
|
23 #include <syslangutil.h> |
|
24 |
|
25 // CONSTANTS |
|
26 _LIT( KHtiDeviceRebootName, "HtiDeviceReboot" ); |
|
27 _LIT( KParamNormalRfs, "rfsnormal" ); |
|
28 _LIT( KParamDeepRfs, "rfsdeep" ); |
|
29 |
|
30 // MACROS |
|
31 |
|
32 // LOCAL CONSTANTS AND MACROS |
|
33 |
|
34 // MODULE DATA STRUCTURES |
|
35 |
|
36 // LOCAL FUNCTION PROTOTYPES |
|
37 LOCAL_C TInt StartL(); |
|
38 LOCAL_C TInt Reboot(RStarterSession::TResetReason aReason); |
|
39 LOCAL_C TInt RestoreFactorySettings( TBool aIsDeepRfs ); |
|
40 |
|
41 |
|
42 // FORWARD DECLARATIONS |
|
43 |
|
44 // ============================ LOCAL FUNCTIONS =============================== |
|
45 |
|
46 LOCAL_C TInt StartL() |
|
47 { |
|
48 TInt error = KErrNone; |
|
49 |
|
50 TInt cmdLen = User::CommandLineLength(); |
|
51 HBufC* cmdLine = HBufC::NewLC( cmdLen ); |
|
52 TPtr ptCmdLine = cmdLine->Des(); |
|
53 User::CommandLine( ptCmdLine ); |
|
54 |
|
55 if ( cmdLen == 0 ) |
|
56 { |
|
57 error = Reboot(RStarterSession::EUnknownReset); |
|
58 } |
|
59 |
|
60 else |
|
61 { |
|
62 TLex parser( *cmdLine ); |
|
63 TInt input; |
|
64 TInt ret = parser.Val(input); |
|
65 |
|
66 parser.SkipCharacters(); |
|
67 if ( parser.MarkedToken().CompareF( KParamNormalRfs ) == 0 ) |
|
68 { |
|
69 error = RestoreFactorySettings( EFalse ); |
|
70 } |
|
71 else if ( parser.MarkedToken().CompareF( KParamDeepRfs ) == 0 ) |
|
72 { |
|
73 error = RestoreFactorySettings( ETrue ); |
|
74 } |
|
75 else |
|
76 { |
|
77 if(ret != KErrNone ) |
|
78 { |
|
79 error = KErrArgument; // Unknown argument |
|
80 } |
|
81 else |
|
82 { |
|
83 error = Reboot(static_cast<RStarterSession::TResetReason>(input)); |
|
84 } |
|
85 } |
|
86 } |
|
87 |
|
88 CleanupStack::PopAndDestroy(); // cmdLine |
|
89 return error; |
|
90 } |
|
91 |
|
92 LOCAL_C TInt Reboot(RStarterSession::TResetReason aReason) |
|
93 { |
|
94 RStarterSession session; |
|
95 TInt error = session.Connect(); |
|
96 if ( error == KErrNone ) |
|
97 { |
|
98 session.Reset( aReason ); |
|
99 session.Close(); |
|
100 } |
|
101 return error; |
|
102 } |
|
103 |
|
104 LOCAL_C TInt RestoreFactorySettings( TBool aIsDeepRfs ) |
|
105 { |
|
106 // In case of deep rfs, set language to default |
|
107 if ( aIsDeepRfs ) |
|
108 { |
|
109 TInt lang = 0; |
|
110 if ( SysLangUtil::GetDefaultLanguage( lang ) == KErrNone ) |
|
111 { |
|
112 HAL::Set( HALData::ELanguageIndex, lang ); |
|
113 } |
|
114 } |
|
115 |
|
116 // Do reboot with appropriate rfs reason code |
|
117 RStarterSession session; |
|
118 TInt error = session.Connect(); |
|
119 if ( error == KErrNone ) |
|
120 { |
|
121 session.Reset( aIsDeepRfs ? RStarterSession::EDeepRFSReset : |
|
122 RStarterSession::ENormalRFSReset ); |
|
123 session.Close(); |
|
124 } |
|
125 return error; |
|
126 } |
|
127 |
|
128 GLDEF_C TInt E32Main() |
|
129 { |
|
130 __UHEAP_MARK; |
|
131 |
|
132 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
133 CActiveScheduler *scheduler = new(ELeave) CActiveScheduler; |
|
134 CActiveScheduler::Install( scheduler ); |
|
135 |
|
136 User::RenameThread( KHtiDeviceRebootName ); |
|
137 |
|
138 TRAPD( err, StartL() ); |
|
139 |
|
140 delete scheduler; |
|
141 delete cleanup; |
|
142 |
|
143 __UHEAP_MARKEND; |
|
144 |
|
145 return err; |
|
146 } |
|
147 |
|
148 // End of File |