|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 #include <mtp/tmtptypeflatbase.h> |
|
18 #include <mtp/cmtptypestorageinfo.h> |
|
19 #include <mtp/cmtptypestring.h> |
|
20 |
|
21 // Dataset constants |
|
22 const TUint CMTPTypeStorageInfo::KFlatChunkSize(26); |
|
23 |
|
24 // Dataset element metadata. |
|
25 const CMTPTypeCompoundBase::TElementInfo CMTPTypeStorageInfo::iElementMetaData[CMTPTypeStorageInfo::ENumElements] = |
|
26 { |
|
27 {EIdFlatChunk, EMTPTypeFlat, {EMTPTypeUINT16, 0, KMTPTypeUINT16Size}}, // EStorageType |
|
28 {EIdFlatChunk, EMTPTypeFlat, {EMTPTypeUINT16, 2, KMTPTypeUINT16Size}}, // EFileSystemType |
|
29 {EIdFlatChunk, EMTPTypeFlat, {EMTPTypeUINT16, 4, KMTPTypeUINT16Size}}, // EAccessCapability |
|
30 {EIdFlatChunk, EMTPTypeFlat, {EMTPTypeUINT64, 6, KMTPTypeUINT64Size}}, // EMaxCapacity |
|
31 {EIdFlatChunk, EMTPTypeFlat, {EMTPTypeUINT64, 14, KMTPTypeUINT64Size}}, // EFreeSpaceInBytes |
|
32 {EIdFlatChunk, EMTPTypeFlat, {EMTPTypeUINT32, 22, KMTPTypeUINT32Size}}, // EFreeSpaceInObjects |
|
33 {EIdStorageDescriptionChunk, EMTPTypeString, {EMTPTypeString, KMTPNotApplicable, KMTPNotApplicable}}, // EStorageDescription |
|
34 {EIdVolumeIdentifierChunk, EMTPTypeString, {EMTPTypeString, KMTPNotApplicable, KMTPNotApplicable}}, // EVolumeIdentifier |
|
35 }; |
|
36 |
|
37 /** |
|
38 MTP StorageInfo dataset factory method. This method is used to create an empty |
|
39 MTP StorageInfo dataset type. A pointer to the MTP array data type is placed on |
|
40 the cleanup stack. |
|
41 @return A pointer to an empty MTP StorageInfo dataset type. Ownership IS |
|
42 transfered. |
|
43 @leave One of the system wide error codes, if unsuccessful. |
|
44 */ |
|
45 EXPORT_C CMTPTypeStorageInfo* CMTPTypeStorageInfo::NewL() |
|
46 { |
|
47 CMTPTypeStorageInfo* self=CMTPTypeStorageInfo::NewLC(); |
|
48 CleanupStack::Pop(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 |
|
53 /** |
|
54 MTP StorageInfo dataset factory method. This method is used to create an empty |
|
55 MTP StorageInfo dataset type. |
|
56 @return A pointer to an empty MTP StorageInfo dataset type. Ownership IS |
|
57 transfered. |
|
58 @leave One of the system wide error codes, if unsuccessful. |
|
59 */ |
|
60 EXPORT_C CMTPTypeStorageInfo* CMTPTypeStorageInfo::NewLC() |
|
61 { |
|
62 CMTPTypeStorageInfo* self=new (ELeave) CMTPTypeStorageInfo(); |
|
63 CleanupStack::PushL(self); |
|
64 self->ConstructL(); |
|
65 return self; |
|
66 } |
|
67 |
|
68 /** |
|
69 Destructor. |
|
70 */ |
|
71 EXPORT_C CMTPTypeStorageInfo::~CMTPTypeStorageInfo() |
|
72 { |
|
73 iChunkFlat.Close(); |
|
74 iStringChunks.ResetAndDestroy(); |
|
75 } |
|
76 |
|
77 EXPORT_C TUint CMTPTypeStorageInfo::Type() const |
|
78 { |
|
79 return EMTPTypeStorageInfoDataset; |
|
80 } |
|
81 |
|
82 const CMTPTypeCompoundBase::TElementInfo& CMTPTypeStorageInfo::ElementInfo(TInt aElementId) const |
|
83 { |
|
84 return iElementInfo[aElementId]; |
|
85 } |
|
86 |
|
87 CMTPTypeStorageInfo::CMTPTypeStorageInfo() : |
|
88 CMTPTypeCompoundBase((!KJustInTimeConstruction), EIdNumChunks), |
|
89 iElementInfo(iElementMetaData, ENumElements), |
|
90 iChunkFlat(KFlatChunkSize, *this) |
|
91 { |
|
92 |
|
93 } |
|
94 |
|
95 void CMTPTypeStorageInfo::ConstructL() |
|
96 { |
|
97 for (TUint i(0); (i < ENumElements); i++) |
|
98 { |
|
99 const TElementInfo& info(iElementInfo[i]); |
|
100 if (ChunkCount() <= info.iChunkId) |
|
101 { |
|
102 MMTPType* chunk(NULL); |
|
103 |
|
104 switch (info.iType) |
|
105 { |
|
106 case EMTPTypeFlat: |
|
107 chunk = NewFlatChunkL(info); |
|
108 break; |
|
109 |
|
110 case EMTPTypeString: |
|
111 chunk = NewStringChunkL(info); |
|
112 break; |
|
113 |
|
114 default: |
|
115 break; |
|
116 } |
|
117 __ASSERT_DEBUG(chunk, User::Invariant()); |
|
118 ChunkAppendL(*chunk); |
|
119 } |
|
120 } |
|
121 } |
|
122 |
|
123 MMTPType* CMTPTypeStorageInfo::NewFlatChunkL(const TElementInfo& aElementInfo) |
|
124 { |
|
125 MMTPType* chunk(NULL); |
|
126 switch (aElementInfo.iChunkId) |
|
127 { |
|
128 case 0: |
|
129 iChunkFlat.OpenL(); |
|
130 chunk = &iChunkFlat; |
|
131 break; |
|
132 |
|
133 default: |
|
134 break; |
|
135 } |
|
136 __ASSERT_DEBUG(chunk, User::Invariant()); |
|
137 return chunk; |
|
138 } |
|
139 |
|
140 MMTPType* CMTPTypeStorageInfo::NewStringChunkL(const TElementInfo& /*aElementInfo*/) |
|
141 { |
|
142 CMTPTypeString* chunk(CMTPTypeString::NewLC()); |
|
143 iStringChunks.AppendL(chunk); |
|
144 CleanupStack::Pop(chunk); |
|
145 return chunk; |
|
146 } |
|
147 |