|
1 // Copyright (c) 2006-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 "restartsys.h" |
|
17 #include <e32svr.h> |
|
18 #include <hal.h> |
|
19 #include <hal_data.h> |
|
20 #include <e32modes.h> |
|
21 |
|
22 #include "shmadebug.h" |
|
23 #include "shmapanic.h" |
|
24 |
|
25 /** Safely restarts the system in a given startup mode. |
|
26 @post This function will return after posting an event in system event queue. The processing of this event might |
|
27 take some time and even might be cancelled if the system cannot be restarted safely. The execution of the calling |
|
28 thread will continue for an indefinte period of time after this call, but it has no guarantees to finish execution. |
|
29 It is strongly advised to delay for a sufficient period of time to let the shutdown request be processed. |
|
30 @code |
|
31 // Usage example to restart the system in licensee-defined mode 3 |
|
32 RestartSys::RestartSystem(3); |
|
33 User::After(5000000); |
|
34 @endcode |
|
35 @param aStartupMode The startup mode the device will start in after reboot |
|
36 @panic ERestartNotSupportedOnEmulator if this function is called on emulator |
|
37 @capability PowerMgmt |
|
38 @capability WriteDeviceData |
|
39 @capability SwEvent |
|
40 @return KErrNone, if successful; KErrArgument if aStartupMode is out of the valid range; KErrPermissionDenied, if the caller has insufficient capability; otherwise, one of the other system-wide error codes. |
|
41 */ |
|
42 EXPORT_C TInt RestartSys::RestartSystem(TInt aStartupMode) |
|
43 { |
|
44 (void) aStartupMode; |
|
45 DEBUGPRINT2(_L("RestartSys::RestartSystem called with aStartupMode=%d"), aStartupMode); |
|
46 |
|
47 #ifdef __WINS__ // Restart using event is not supported on emulator because Base change is needed |
|
48 PanicNow(KPanicRestartSys, ERestartNotSupportedOnEmulator); |
|
49 return KErrNotSupported; |
|
50 #else |
|
51 TInt err = HAL::Set(HALData::EPersistStartupModeKernel, aStartupMode); |
|
52 if (err!=KErrNone) |
|
53 { |
|
54 DEBUGPRINT2(_L("RestartSys::HAL::Set return err=%d"), err); |
|
55 return err; |
|
56 } |
|
57 |
|
58 TRawEvent event; |
|
59 event.Set(TRawEvent::ERestartSystem); |
|
60 return UserSvr::AddEvent(event); |
|
61 #endif |
|
62 } |
|
63 |
|
64 |
|
65 /** Safely restarts the system in the default startup mode (EStartupModeUndefined). |
|
66 @capability PowerMgmt |
|
67 @capability SwEvent |
|
68 @see RestartSys::RestartSystem(TInt aStartupMode) |
|
69 */ |
|
70 EXPORT_C TInt RestartSys::RestartSystem() |
|
71 { |
|
72 return RestartSystem(EStartupModeUndefined); |
|
73 } |
|
74 |