1 /* |
|
2 * Copyright (c) 2006 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: Launches file manager scheduled backup task |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32base.h> |
|
22 #include <f32file.h> |
|
23 #include <s32file.h> |
|
24 #include <schtask.h> |
|
25 #include "FileManagerDebug.h" |
|
26 #include "filemanagerschbackuptask.h" |
|
27 |
|
28 |
|
29 // CONSTANTS |
|
30 _LIT_SECURE_ID( KTaskSchedulerSID, 0x10005399 ); |
|
31 |
|
32 |
|
33 // ======== LOCAL FUNCTIONS ======== |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // StartSchTaskL |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 LOCAL_C void StartSchTaskL( RFile& aTaskFile ) |
|
40 { |
|
41 INFO_LOG( "StartSchTaskL()-Started" ) |
|
42 |
|
43 // Create and install the active scheduler we need |
|
44 CActiveScheduler* scheduler = new ( ELeave ) CActiveScheduler(); |
|
45 CleanupStack::PushL( scheduler ); |
|
46 CActiveScheduler::Install( scheduler ); |
|
47 |
|
48 // Get scheduled task parameters |
|
49 CFileStore* store = CDirectFileStore::FromLC( aTaskFile ); |
|
50 RStoreReadStream instream; |
|
51 instream.OpenLC( *store, store->Root() ); |
|
52 |
|
53 TInt count( instream.ReadInt32L() ); |
|
54 if ( !count ) |
|
55 { |
|
56 User::Leave( KErrNotFound ); |
|
57 } |
|
58 |
|
59 // Create the task to be started |
|
60 CScheduledTask* task = CScheduledTask::NewLC( instream ); |
|
61 CFileManagerSchBackupTask* fmTask = |
|
62 CFileManagerSchBackupTask::NewL( *task ); |
|
63 CleanupStack::PopAndDestroy( task ); |
|
64 CleanupStack::PopAndDestroy( &instream ); |
|
65 CleanupStack::PopAndDestroy( store ); |
|
66 |
|
67 // Start scheduler to handle the backup launch. |
|
68 // This call exists after backup launch has finished. |
|
69 CActiveScheduler::Start(); |
|
70 |
|
71 // Cleanup the task and scheduler |
|
72 delete fmTask; |
|
73 CleanupStack::PopAndDestroy( scheduler ); |
|
74 |
|
75 INFO_LOG( "StartSchTaskL()-Finished" ) |
|
76 } |
|
77 |
|
78 |
|
79 // ======== GLOBAL FUNCTIONS ======== |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // E32Main |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 GLDEF_C TInt E32Main() |
|
86 { |
|
87 __UHEAP_MARK; |
|
88 |
|
89 INFO_LOG( "FileManagerSchBackup-E32Main()-Started" ) |
|
90 |
|
91 TInt err( KErrPermissionDenied ); |
|
92 |
|
93 // Check process creator and start scheduled task |
|
94 if( User::CreatorSecureId() == KTaskSchedulerSID ) |
|
95 { |
|
96 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
97 if ( cleanupStack ) |
|
98 { |
|
99 INFO_LOG( "FileManagerSchBkup-E32Main()-Adopt task file" ) |
|
100 |
|
101 RFile file; |
|
102 err = file.AdoptFromCreator( |
|
103 TScheduledTaskFile::FsHandleIndex(), |
|
104 TScheduledTaskFile::FileHandleIndex() ); |
|
105 if ( err == KErrNone ) |
|
106 { |
|
107 TRAP( err, StartSchTaskL( file ) ); |
|
108 file.Close(); |
|
109 } |
|
110 delete cleanupStack; |
|
111 } |
|
112 else |
|
113 { |
|
114 err = KErrNoMemory; |
|
115 } |
|
116 } |
|
117 |
|
118 LOG_IF_ERROR1( err, "FileManagerSchBackup-E32Main()-Error=%d", err ) |
|
119 |
|
120 INFO_LOG( "FileManagerSchBackup-E32Main()-Finished" ) |
|
121 |
|
122 __UHEAP_MARKEND; |
|
123 |
|
124 return err; |
|
125 } |
|
126 |
|
127 // End of file |
|