17 |
17 |
18 |
18 |
19 #include "drivewatcher.h" |
19 #include "drivewatcher.h" |
20 #include "SWInstDebug.h" |
20 #include "SWInstDebug.h" |
21 |
21 |
22 using namespace Swi; |
22 namespace Swi |
23 |
23 { |
24 // CDriveWatcher |
24 // CDriveWatcher |
25 _LIT(KNotificationDirectory,"mediachange\\"); |
25 _LIT(KNotificationDirectory,"mediachange\\"); |
26 |
26 |
27 |
27 /*static*/ CDriveWatcher* CDriveWatcher::NewL(RFs& aFs, TInt aDrive, |
28 // ----------------------------------------------------------------------- |
28 MDriveObserver& aObserver, |
29 // CDriveWatcher::NewL |
29 TInt aPriority) |
30 // ----------------------------------------------------------------------- |
|
31 // |
|
32 /*static*/ |
|
33 CDriveWatcher* CDriveWatcher::NewL( RFs& aFs, |
|
34 TInt aDrive, |
|
35 MDriveObserver& aObserver, |
|
36 TInt aPriority ) |
|
37 { |
30 { |
38 CDriveWatcher* self = NewLC( aFs, aDrive, aObserver, aPriority ); |
31 CDriveWatcher* self=NewLC(aFs, aDrive, aObserver, aPriority); |
39 CleanupStack::Pop(self); |
32 CleanupStack::Pop(self); |
40 return self; |
33 return self; |
41 } |
34 } |
42 |
35 |
43 // ----------------------------------------------------------------------- |
36 /*static*/ CDriveWatcher* CDriveWatcher::NewLC(RFs& aFs, TInt aDrive, |
44 // |
37 MDriveObserver& aObserver, |
45 // ----------------------------------------------------------------------- |
38 TInt aPriority) |
46 // |
|
47 /*static*/ |
|
48 CDriveWatcher* CDriveWatcher::NewLC( RFs& aFs, |
|
49 TInt aDrive, |
|
50 MDriveObserver& aObserver, |
|
51 TInt aPriority ) |
|
52 { |
39 { |
53 CDriveWatcher* self = new(ELeave) CDriveWatcher( aFs, |
40 CDriveWatcher* self=new(ELeave) CDriveWatcher(aFs, aDrive, aObserver, aPriority); |
54 aDrive, |
41 CleanupStack::PushL(self); |
55 aObserver, |
|
56 aPriority ); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
42 self->ConstructL(); |
59 return self; |
43 return self; |
60 } |
44 } |
61 |
45 |
62 // ----------------------------------------------------------------------- |
|
63 // |
|
64 // ----------------------------------------------------------------------- |
|
65 // |
|
66 CDriveWatcher::~CDriveWatcher() |
46 CDriveWatcher::~CDriveWatcher() |
67 { |
47 { |
68 Cancel(); |
48 Cancel(); |
69 } |
49 } |
70 |
50 |
71 // ----------------------------------------------------------------------- |
51 CDriveWatcher::CDriveWatcher(RFs& aFs, TInt aDrive, MDriveObserver& aObserver, |
72 // |
52 TInt aPriority) |
73 // ----------------------------------------------------------------------- |
53 : CActive(aPriority), iFs(aFs), iDrive(aDrive), iObserver(aObserver) |
74 // |
|
75 CDriveWatcher::CDriveWatcher( RFs& aFs, |
|
76 TInt aDrive, |
|
77 MDriveObserver& aObserver, |
|
78 TInt aPriority ) |
|
79 : CActive(aPriority), |
|
80 iFs(aFs), |
|
81 iDrive(aDrive), |
|
82 iObserver(aObserver) |
|
83 { |
54 { |
84 CActiveScheduler::Add(this); |
55 CActiveScheduler::Add(this); |
85 } |
56 } |
86 |
57 |
87 // ----------------------------------------------------------------------- |
|
88 // |
|
89 // ----------------------------------------------------------------------- |
|
90 // |
|
91 void CDriveWatcher::ConstructL() |
58 void CDriveWatcher::ConstructL() |
92 { |
59 { |
93 // Notify observer of media change since we're beginning |
60 // Notify observer of media change since we're beginning from an unknown state |
94 // from an unknown state |
|
95 NotifyMediaChange(); |
61 NotifyMediaChange(); |
96 |
62 |
97 // Start watching for changes |
63 // Start watching for changes |
98 WaitForChangeL(); |
64 WaitForChangeL(); |
99 } |
65 } |
100 |
66 |
101 // ----------------------------------------------------------------------- |
|
102 // |
|
103 // ----------------------------------------------------------------------- |
|
104 // |
|
105 void CDriveWatcher::DoCancel() |
67 void CDriveWatcher::DoCancel() |
106 { |
68 { |
107 iFs.NotifyChangeCancel(iStatus); |
69 iFs.NotifyChangeCancel(iStatus); |
108 } |
70 } |
109 |
71 |
110 // ----------------------------------------------------------------------- |
|
111 // |
|
112 // ----------------------------------------------------------------------- |
|
113 // |
|
114 TBool CDriveWatcher::IsMediaPresentL() |
72 TBool CDriveWatcher::IsMediaPresentL() |
115 { |
73 { |
116 FLOG_1( _L("Daemon: Checking media presence for drive %d"), iDrive ); |
74 FLOG_1( _L("Daemon: Checking media presence for drive %d"), iDrive ); |
117 |
75 |
118 TVolumeInfo volumeInfo; |
76 TVolumeInfo volumeInfo; |
119 TInt err = iFs.Volume( volumeInfo, iDrive ); |
77 TInt err=iFs.Volume(volumeInfo, iDrive); |
120 |
78 |
121 switch ( err ) |
79 switch (err) |
122 { |
80 { |
123 case KErrNotReady: // No Media present |
81 case KErrNotReady: // No Media present |
124 { |
82 { |
125 return EFalse; |
83 return EFalse; |
126 } |
84 } |
129 { |
87 { |
130 return ETrue; |
88 return ETrue; |
131 } |
89 } |
132 } |
90 } |
133 |
91 |
134 User::Leave( err ); |
92 User::Leave(err); |
135 return ETrue; // Will never get here. |
93 return ETrue; // Will never get here. |
136 } |
94 } |
137 |
95 |
138 // ----------------------------------------------------------------------- |
|
139 // |
|
140 // ----------------------------------------------------------------------- |
|
141 // |
|
142 void CDriveWatcher::NotifyMediaChange() |
96 void CDriveWatcher::NotifyMediaChange() |
143 { |
97 { |
144 FLOG( _L("Daemon: NotifyMediaChange") ); |
98 FLOG( _L("Daemon: NotifyMediaChange") ); |
145 // Unsuccessful media change is not fatal, so handle here |
99 // Unsuccessful media change is not fatal, so handle here |
146 TRAPD( err, iObserver.MediaChangeL( iDrive, |
100 TRAPD(err,iObserver.MediaChangeL(iDrive, IsMediaPresentL() ? MDriveObserver::EMediaInserted : MDriveObserver::EMediaRemoved)); |
147 IsMediaPresentL() |
|
148 ? MDriveObserver::EMediaInserted : |
|
149 MDriveObserver::EMediaRemoved)); |
|
150 |
101 |
151 if (err != KErrNone) |
102 if (err != KErrNone) |
152 { |
103 { |
153 FLOG_1(_L("Daemon: MediaChangeL TRAP err = %d"), err ); |
104 FLOG_1(_L("Daemon: MDriveObserver::MediaChangeL left while processing media notification %d"),err); |
154 } |
105 } |
155 } |
106 } |
156 |
107 |
157 // ----------------------------------------------------------------------- |
|
158 // |
|
159 // ----------------------------------------------------------------------- |
|
160 // |
|
161 void CDriveWatcher::RunL() |
108 void CDriveWatcher::RunL() |
162 { |
109 { |
163 NotifyMediaChange(); |
110 NotifyMediaChange(); |
164 |
111 |
165 WaitForChangeL(); |
112 WaitForChangeL(); |
166 } |
113 } |
167 |
114 |
168 // ----------------------------------------------------------------------- |
|
169 // |
|
170 // ----------------------------------------------------------------------- |
|
171 // |
|
172 void CDriveWatcher::WaitForChangeL() |
115 void CDriveWatcher::WaitForChangeL() |
173 { |
116 { |
174 TChar drive; |
117 TChar drive; |
175 User::LeaveIfError( iFs.DriveToChar( iDrive, drive ) ); |
118 User::LeaveIfError(iFs.DriveToChar(iDrive, drive)); |
176 TUint driveChar(drive); // Can't pass TChar to Format(). |
119 TUint driveChar(drive); // Can't pass TChar to Format(). |
177 |
120 |
178 TPath notificationPath; |
121 TPath notificationPath; |
179 TPath privatePath; |
122 TPath privatePath; |
180 _LIT(KNotificationPathFormat,"%c:%S%S"); |
123 _LIT(KNotificationPathFormat,"%c:%S%S"); |
181 User::LeaveIfError( iFs.PrivatePath( privatePath ) ); |
124 User::LeaveIfError(iFs.PrivatePath(privatePath)); |
182 |
125 |
183 notificationPath.Format( KNotificationPathFormat, |
126 notificationPath.Format(KNotificationPathFormat, driveChar, &privatePath, &KNotificationDirectory); |
184 driveChar, |
|
185 &privatePath, |
|
186 &KNotificationDirectory ); |
|
187 |
127 |
188 iFs.NotifyChange( ENotifyEntry, iStatus, notificationPath ); |
128 iFs.NotifyChange(ENotifyEntry, iStatus, notificationPath); |
189 |
129 |
190 SetActive(); |
130 SetActive(); |
191 } |
131 } |
192 |
132 |
193 //EOF |
133 } |