1 /* |
|
2 * Copyright (c) 2005 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: TMMCScBkupDriveFilter implementation |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "TMMCScBkupDriveFilter.h" |
|
20 |
|
21 // Constants |
|
22 const TInt KMMCScBkupInitialDriveIndex = -1; |
|
23 |
|
24 |
|
25 |
|
26 // ========================= MEMBER FUNCTIONS ================================ |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // TMMCScBkupDriveFilter::Reset() |
|
30 // |
|
31 // |
|
32 // --------------------------------------------------------------------------- |
|
33 void TMMCScBkupDriveFilter::Reset() |
|
34 { |
|
35 iCurrentDrive = KMMCScBkupInitialDriveIndex; |
|
36 } |
|
37 |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // TMMCScBkupDriveFilter::SetPrimaryDriveFilter() |
|
41 // |
|
42 // |
|
43 // --------------------------------------------------------------------------- |
|
44 void TMMCScBkupDriveFilter::SetPrimaryDriveFilter( const TDriveList& aDriveList ) |
|
45 { |
|
46 iPrimaryDriveList = aDriveList; |
|
47 } |
|
48 |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // TMMCScBkupDriveFilter::SetSecondaryDriveFilter() |
|
52 // |
|
53 // |
|
54 // --------------------------------------------------------------------------- |
|
55 void TMMCScBkupDriveFilter::SetSecondaryDriveFilter( const TDriveList& aDriveList ) |
|
56 { |
|
57 iSecondaryDriveList = aDriveList; |
|
58 iHaveSecondaryList = ETrue; |
|
59 } |
|
60 |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // TMMCScBkupDriveFilter::NextValidDrive() |
|
64 // |
|
65 // |
|
66 // --------------------------------------------------------------------------- |
|
67 TBool TMMCScBkupDriveFilter::NextValidDrive( TDriveNumber& aDrive ) |
|
68 { |
|
69 // Always move to the next drive before checking its availability. |
|
70 // FindValidDrive takes care of ensuring the value falls within A-Z |
|
71 // range. |
|
72 ++iCurrentDrive; |
|
73 |
|
74 // Do we have an available primary drive? |
|
75 TBool driveAvailable = EFalse; |
|
76 while( iCurrentDrive >= EDriveA && iCurrentDrive <= EDriveZ ) |
|
77 { |
|
78 TDriveNumber drive; |
|
79 driveAvailable = FindValidDrive( iPrimaryDriveList, drive ); |
|
80 if ( driveAvailable && iHaveSecondaryList ) |
|
81 { |
|
82 // Verify against secondary drive list also... |
|
83 const TBool makeOnlyOneDirectAttempt = ETrue; |
|
84 driveAvailable = FindValidDrive( iSecondaryDriveList, drive, makeOnlyOneDirectAttempt ); |
|
85 } |
|
86 else if (!driveAvailable) |
|
87 { |
|
88 // No more primary drives left, so we're done here. |
|
89 break; |
|
90 } |
|
91 |
|
92 // Did we find a match on (just) the primary drive, or then |
|
93 // the primary and secondary drive lists combined? |
|
94 if (driveAvailable) |
|
95 { |
|
96 // Yes, match found - we're finished here. |
|
97 aDrive = drive; |
|
98 break; |
|
99 } |
|
100 else |
|
101 { |
|
102 // Try to search for the next drive that matches both the |
|
103 // primary and secondary lists (if supported) |
|
104 ++iCurrentDrive; |
|
105 } |
|
106 } |
|
107 // |
|
108 return driveAvailable; |
|
109 } |
|
110 |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // TMMCScBkupDriveFilter::CurrentDrive() |
|
114 // |
|
115 // |
|
116 // --------------------------------------------------------------------------- |
|
117 TDriveNumber TMMCScBkupDriveFilter::CurrentDrive() const |
|
118 { |
|
119 return static_cast< TDriveNumber >( iCurrentDrive ); |
|
120 } |
|
121 |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // TMMCScBkupDriveFilter::FindValidDrive() |
|
125 // |
|
126 // |
|
127 // --------------------------------------------------------------------------- |
|
128 TBool TMMCScBkupDriveFilter::FindValidDrive( const TDriveList& aList, TDriveNumber& aDrive, TBool aOneAttemptOnly ) |
|
129 { |
|
130 // If we've already reached Z then there isn't any sense in continuing |
|
131 // as all drives have been processed. |
|
132 TBool driveAvailable = EFalse; |
|
133 |
|
134 // Keep checking drives until we go past Z |
|
135 while( iCurrentDrive >= EDriveA && iCurrentDrive <= EDriveZ ) |
|
136 { |
|
137 if ( aList[ iCurrentDrive ] != 0 ) |
|
138 { |
|
139 // Found an available drive |
|
140 aDrive = static_cast< TDriveNumber >( iCurrentDrive ); |
|
141 driveAvailable = ETrue; |
|
142 break; |
|
143 } |
|
144 else if ( aOneAttemptOnly ) |
|
145 { |
|
146 break; |
|
147 } |
|
148 |
|
149 // Try next drive |
|
150 ++iCurrentDrive; |
|
151 } |
|
152 // |
|
153 return driveAvailable; |
|
154 } |
|
155 |
|
156 |
|
157 |
|
158 |
|