|
1 /* |
|
2 * Copyright (c) 2006-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: Utility class to keep a list of mediaid's |
|
15 */ |
|
16 |
|
17 #include "harvestermediaidutil.h" |
|
18 #include "mdsutils.h" |
|
19 |
|
20 |
|
21 CHarvesterMediaIdUtil* CHarvesterMediaIdUtil::NewL() |
|
22 { |
|
23 CHarvesterMediaIdUtil* self = new (ELeave) CHarvesterMediaIdUtil; |
|
24 CleanupStack::PushL( self ); |
|
25 self->ConstructL(); |
|
26 CleanupStack::Pop( self ); |
|
27 return self; |
|
28 } |
|
29 |
|
30 |
|
31 CHarvesterMediaIdUtil::CHarvesterMediaIdUtil() |
|
32 { |
|
33 // no implementation needed |
|
34 } |
|
35 |
|
36 CHarvesterMediaIdUtil::~CHarvesterMediaIdUtil() |
|
37 { |
|
38 iFs.Close(); |
|
39 } |
|
40 |
|
41 void CHarvesterMediaIdUtil::ConstructL() |
|
42 { |
|
43 for ( TInt i = 0; i < KMaxDrives; i++ ) |
|
44 { |
|
45 iMediaId[i] = 0; |
|
46 } |
|
47 User::LeaveIfError( iFs.Connect() ); |
|
48 } |
|
49 |
|
50 EXPORT_C TInt CHarvesterMediaIdUtil::GetMediaId( const TDesC& aUri, TUint32& aMediaId ) |
|
51 { |
|
52 TChar ch = aUri[0]; |
|
53 TInt drive( 0 ); |
|
54 TInt err = RFs::CharToDrive( ch, drive ); |
|
55 if ( err == KErrNone ) |
|
56 { |
|
57 // return mediaid if already in array |
|
58 if( iMediaId[drive] > 0 ) |
|
59 { |
|
60 aMediaId = iMediaId[drive]; |
|
61 return KErrNone; |
|
62 } |
|
63 |
|
64 // resolve mediaid and save into array |
|
65 err = MdsUtils::GetVolumeInfo( iFs, aUri, iVolumeInfo ); |
|
66 if ( err == KErrNone ) |
|
67 { |
|
68 iMediaId[drive] = iVolumeInfo.iUniqueID; |
|
69 aMediaId = iVolumeInfo.iUniqueID; |
|
70 return KErrNone; |
|
71 } |
|
72 } |
|
73 return err; |
|
74 } |
|
75 |
|
76 EXPORT_C TInt CHarvesterMediaIdUtil::GetDriveLetter( TUint32 aMediaId, TChar& aChar ) |
|
77 { |
|
78 for ( TInt i = 0; i < KMaxDrives; i++ ) |
|
79 { |
|
80 if ( iMediaId[i] == aMediaId ) |
|
81 { |
|
82 TInt err = RFs::DriveToChar( i, aChar ); |
|
83 return err; |
|
84 } |
|
85 } |
|
86 return KErrNotFound; |
|
87 } |
|
88 |
|
89 EXPORT_C void CHarvesterMediaIdUtil::RemoveMediaId( TUint32 aMediaId ) |
|
90 { |
|
91 for ( TInt i = 0; i < KMaxDrives; i++ ) |
|
92 { |
|
93 if ( iMediaId[i] == aMediaId ) |
|
94 { |
|
95 iMediaId[i] = 0; |
|
96 break; |
|
97 } |
|
98 } |
|
99 } |
|
100 |
|
101 EXPORT_C CHarvesterMediaIdUtil& RMediaIdUtil::GetInstanceL() |
|
102 { |
|
103 TMediaIdUtilInfo* data = |
|
104 static_cast<TMediaIdUtilInfo*>( |
|
105 UserSvr::DllTls( KHarvesterMediaIdTLSKey ) ); |
|
106 |
|
107 CHarvesterMediaIdUtil* instance = NULL; |
|
108 |
|
109 if ( data ) |
|
110 { |
|
111 instance = data->iMediaIdUtil; |
|
112 data->iRefCount++; |
|
113 } |
|
114 else |
|
115 { |
|
116 instance = CHarvesterMediaIdUtil::NewL(); |
|
117 CleanupStack::PushL(instance); |
|
118 TMediaIdUtilInfo* tmp = new (ELeave) TMediaIdUtilInfo; |
|
119 tmp->iMediaIdUtil = instance; |
|
120 tmp->iRefCount = 1; |
|
121 UserSvr::DllSetTls( KHarvesterMediaIdTLSKey, tmp ); |
|
122 |
|
123 CleanupStack::Pop(instance); |
|
124 } |
|
125 |
|
126 return *instance; |
|
127 } |
|
128 |
|
129 EXPORT_C void RMediaIdUtil::ReleaseInstance() |
|
130 { |
|
131 TMediaIdUtilInfo* data = static_cast<TMediaIdUtilInfo*> (UserSvr::DllTls( |
|
132 KHarvesterMediaIdTLSKey)); |
|
133 if (data) |
|
134 { |
|
135 data->iRefCount--; |
|
136 if (data->iRefCount <= 0) |
|
137 { |
|
138 delete data->iMediaIdUtil; |
|
139 |
|
140 delete data; |
|
141 UserSvr::DllFreeTls(KHarvesterMediaIdTLSKey); |
|
142 } |
|
143 } |
|
144 } |