60
|
1 |
/*
|
|
2 |
* Copyright (c) 2008-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: MMC Notifier
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <glxtracer.h>
|
|
20 |
#include <glxlog.h>
|
|
21 |
#include <driveinfo.h>
|
|
22 |
#include "glxmmcnotifier.h"
|
|
23 |
|
|
24 |
// ---------------------------------------------------------
|
|
25 |
// CGlxMMCNotifier::NewL
|
|
26 |
// ---------------------------------------------------------
|
|
27 |
//
|
|
28 |
EXPORT_C CGlxMMCNotifier* CGlxMMCNotifier::NewL(MStorageNotifierObserver& aNotify)
|
|
29 |
{
|
|
30 |
TRACER("CGlxMMCNotifier::NewL()");
|
|
31 |
CGlxMMCNotifier* self = CGlxMMCNotifier::NewLC(aNotify);
|
|
32 |
CleanupStack::Pop(self);
|
|
33 |
return self;
|
|
34 |
}
|
|
35 |
|
|
36 |
// ---------------------------------------------------------
|
|
37 |
// CGlxMMCNotifier::NewLC
|
|
38 |
// ---------------------------------------------------------
|
|
39 |
//
|
|
40 |
CGlxMMCNotifier* CGlxMMCNotifier::NewLC(MStorageNotifierObserver& aNotify)
|
|
41 |
{
|
|
42 |
TRACER("CGlxMMCNotifier::NewLC()");
|
|
43 |
CGlxMMCNotifier* self = new (ELeave) CGlxMMCNotifier(aNotify);
|
|
44 |
CleanupStack::PushL(self);
|
|
45 |
self->ConstructL();
|
|
46 |
return self;
|
|
47 |
}
|
|
48 |
|
|
49 |
// ---------------------------------------------------------
|
|
50 |
// CGlxMMCNotifier::CGlxMMCNotifier
|
|
51 |
// ---------------------------------------------------------
|
|
52 |
//
|
|
53 |
CGlxMMCNotifier::CGlxMMCNotifier(MStorageNotifierObserver& aNotify)
|
|
54 |
: CActive( CActive::EPriorityStandard ),iNotify(aNotify)
|
|
55 |
{
|
|
56 |
TRACER("CGlxMMCNotifier::CGlxMMCNotifier()");
|
|
57 |
CActiveScheduler::Add( this );
|
|
58 |
}
|
|
59 |
|
|
60 |
// ---------------------------------------------------------
|
|
61 |
// CGlxMMCNotifier::~CGlxMMCNotifier()
|
|
62 |
// ---------------------------------------------------------
|
|
63 |
//
|
|
64 |
CGlxMMCNotifier::~CGlxMMCNotifier()
|
|
65 |
{
|
|
66 |
TRACER("CGlxMMCNotifier::~CGlxMMCNotifier()");
|
|
67 |
Cancel();
|
|
68 |
iFs.Close();
|
|
69 |
}
|
|
70 |
|
|
71 |
// ---------------------------------------------------------
|
|
72 |
// CGlxMMCNotifier::IssueRequest()
|
|
73 |
// ---------------------------------------------------------
|
|
74 |
//
|
|
75 |
void CGlxMMCNotifier::IssueRequest()
|
|
76 |
{
|
|
77 |
TRACER("CGlxMMCNotifier::IssueRequest()");
|
|
78 |
if ( !IsActive() )
|
|
79 |
{
|
|
80 |
// Request to get notified of MMC insertion/removal events
|
|
81 |
iFs.NotifyChange( ENotifyDisk, iStatus );
|
|
82 |
SetActive();
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
// ---------------------------------------------------------
|
|
87 |
// CGlxMMCNotifier::ConstructL()
|
|
88 |
// ---------------------------------------------------------
|
|
89 |
//
|
|
90 |
void CGlxMMCNotifier::ConstructL()
|
|
91 |
{
|
|
92 |
TRACER("CGlxMMCNotifier::ConstructL()");
|
|
93 |
TInt err = iFs.Connect();
|
|
94 |
GLX_LOG_INFO1("CGlxMMCNotifier::ConstructL iFs.Connect err %d",err );
|
|
95 |
|
|
96 |
User::LeaveIfError(DriveInfo::GetDefaultDrive(
|
|
97 |
DriveInfo::EDefaultRemovableMassStorage, iDefaultMemoryCardDrive));
|
|
98 |
GLX_LOG_INFO1("CGlxMMCNotifier::ConstructL iFs.Connect iDrive %d",
|
|
99 |
iDefaultMemoryCardDrive );
|
|
100 |
IssueRequest();
|
|
101 |
}
|
|
102 |
|
|
103 |
// ---------------------------------------------------------
|
|
104 |
// CGlxMMCNotifier::DoCancel()
|
|
105 |
// ---------------------------------------------------------
|
|
106 |
//
|
|
107 |
void CGlxMMCNotifier::DoCancel()
|
|
108 |
{
|
|
109 |
TRACER("CGlxMMCNotifier::DoCancel()");
|
|
110 |
iFs.NotifyChangeCancel();
|
|
111 |
}
|
|
112 |
|
|
113 |
// ---------------------------------------------------------
|
|
114 |
// CGlxMMCNotifier::RunL
|
|
115 |
// ---------------------------------------------------------
|
|
116 |
//
|
|
117 |
void CGlxMMCNotifier::RunL()
|
|
118 |
{
|
|
119 |
TRACER("CGlxMMCNotifier::RunL()");
|
|
120 |
TDriveInfo driveInfo;
|
|
121 |
// Get the drive info for memory card
|
|
122 |
TInt err = iFs.Drive(driveInfo, iDefaultMemoryCardDrive);
|
|
123 |
GLX_LOG_INFO1("CGlxMMCNotifier::RunL driveInfo err=%d", err);
|
|
124 |
if (err == KErrNone && (driveInfo.iDriveAtt & KDriveAttRemovable))
|
|
125 |
{
|
|
126 |
GLX_LOG_INFO1("CGlxMMCNotifier::RunL driveInfo.iDriveAtt=%d",
|
|
127 |
driveInfo.iDriveAtt);
|
|
128 |
switch (driveInfo.iType)
|
|
129 |
{
|
|
130 |
case EMediaNotPresent:
|
|
131 |
{
|
|
132 |
//MMC removed don't do anything
|
|
133 |
iNotify.HandleMMCRemovalL();
|
|
134 |
break;
|
|
135 |
}
|
|
136 |
default:
|
|
137 |
{
|
|
138 |
iNotify.HandleMMCInsertionL();
|
|
139 |
//MMC inserted
|
|
140 |
break;
|
|
141 |
}
|
|
142 |
}
|
|
143 |
}
|
|
144 |
// Issue request for next event notification
|
|
145 |
IssueRequest();
|
|
146 |
}
|
|
147 |
|
|
148 |
|