|
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 #include "cmtpobjectbrowser.h" |
|
17 #include <mtp/mtpprotocolconstants.h> |
|
18 #include <mtp/tmtptyperequest.h> |
|
19 #include <mtp/cmtptypearray.h> |
|
20 #include <mtp/mtpobjectmgrquerytypes.h> |
|
21 #include <mtp/mmtpobjectmgr.h> |
|
22 #include <mtp/cmtpobjectmetadata.h> |
|
23 |
|
24 #include "cmtprequestchecker.h" |
|
25 #include "mtpdppanic.h" |
|
26 |
|
27 __FLOG_STMT(_LIT8(KComponent,"ObjectBrowser");) |
|
28 |
|
29 |
|
30 CMTPObjectBrowser* CMTPObjectBrowser::NewL( MMTPDataProviderFramework& aDpFw ) |
|
31 { |
|
32 CMTPObjectBrowser* self = new( ELeave ) CMTPObjectBrowser( aDpFw ); |
|
33 CleanupStack::PushL( self ); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop( self ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 TBool CMTPObjectBrowser::IsFolderFormat( TUint aFmtCode, TUint aFmtSubCode ) |
|
40 { |
|
41 return ( ( EMTPFormatCodeAssociation == aFmtCode ) && ( EMTPAssociationTypeGenericFolder == aFmtSubCode ) ); |
|
42 } |
|
43 |
|
44 CMTPObjectBrowser::~CMTPObjectBrowser() |
|
45 { |
|
46 delete iObjMetaCache; |
|
47 __FLOG( _L8("+/-Dtor") ); |
|
48 __FLOG_CLOSE; |
|
49 } |
|
50 |
|
51 void CMTPObjectBrowser::GoL( TUint32 aFormatCode, TUint32 aHandle, TUint32 aDepth, const TBrowseCallback& aBrowseCallback ) const |
|
52 { |
|
53 __FLOG_VA( ( _L8("+GoL( 0x%08X, 0x%08X, %d )"), aFormatCode, aHandle, aDepth ) ); |
|
54 |
|
55 switch ( aHandle ) |
|
56 { |
|
57 case KMTPHandleAll: |
|
58 GetObjectHandlesL( 0, KMTPStorageAll, aFormatCode, KMaxTUint, KMTPHandleNoParent, aBrowseCallback ); |
|
59 break; |
|
60 case KMTPHandleNone: |
|
61 GetRootObjectHandlesL( 0, aFormatCode, aDepth, aBrowseCallback ); |
|
62 break; |
|
63 default: |
|
64 GetObjectHandlesTreeL( 0, aFormatCode, aDepth, aHandle, aBrowseCallback ); |
|
65 break; |
|
66 } |
|
67 |
|
68 __FLOG( _L8("-GoL") ); |
|
69 } |
|
70 |
|
71 CMTPObjectBrowser::CMTPObjectBrowser( MMTPDataProviderFramework& aDpFw ): |
|
72 iDpFw( aDpFw ) |
|
73 { |
|
74 __FLOG_OPEN( KMTPSubsystem, KComponent ); |
|
75 __FLOG( _L8("+/-Ctor") ); |
|
76 } |
|
77 |
|
78 void CMTPObjectBrowser::ConstructL() |
|
79 { |
|
80 __FLOG( _L8("+ConstructL") ); |
|
81 iObjMetaCache = CMTPObjectMetaData::NewL(); |
|
82 __FLOG( _L8("-ConstructL") ); |
|
83 } |
|
84 |
|
85 void CMTPObjectBrowser::GetObjectHandlesL( TUint32 aCurDepth, TUint32 aStorageId, TUint32 aFormatCode, TUint32 aDepth, TUint32 aParentHandle, const TBrowseCallback& aBrowseCallback ) const |
|
86 { |
|
87 __FLOG_VA( ( _L8("+GetObjectHandlesL( %d, 0x%08X, 0x%08X, %d, 0x%08X )"), aCurDepth, aStorageId, aFormatCode, aDepth, aParentHandle ) ); |
|
88 |
|
89 RMTPObjectMgrQueryContext context; |
|
90 RArray< TUint > handles; |
|
91 TMTPObjectMgrQueryParams params( aStorageId, aFormatCode, aParentHandle ); |
|
92 CleanupClosePushL( context ); |
|
93 CleanupClosePushL( handles ); |
|
94 |
|
95 do |
|
96 { |
|
97 iDpFw.ObjectMgr().GetObjectHandlesL( params, context, handles ); |
|
98 TUint handleCount = handles.Count(); |
|
99 if ( aDepth > 0 ) |
|
100 { |
|
101 for ( TUint i = 0; i < handleCount; i++ ) |
|
102 { |
|
103 GetObjectHandlesTreeL( aCurDepth, aFormatCode, aDepth, handles[i], aBrowseCallback ); |
|
104 } |
|
105 } |
|
106 else |
|
107 { |
|
108 for ( TUint i = 0; i < handleCount; i++ ) |
|
109 { |
|
110 aBrowseCallback.iCallback( aBrowseCallback.iContext, handles[i], aCurDepth ); |
|
111 } |
|
112 } |
|
113 } |
|
114 while ( !context.QueryComplete() ); |
|
115 |
|
116 CleanupStack::PopAndDestroy( &handles ); |
|
117 CleanupStack::PopAndDestroy( &context ); |
|
118 |
|
119 __FLOG( _L8("-GetObjectHandlesL") ); |
|
120 } |
|
121 |
|
122 void CMTPObjectBrowser::GetFolderObjectHandlesL( TUint32 aCurDepth, TUint32 aFormatCode, TUint32 aDepth, TUint32 aParentHandle, const TBrowseCallback& aBrowseCallback ) const |
|
123 { |
|
124 __FLOG_VA( ( _L8("+GetFolderObjectHandlesL( %d, 0x%08X, %d, 0x%08X )"), aCurDepth, aFormatCode, aDepth, aParentHandle ) ); |
|
125 |
|
126 if ( 0 == aDepth ) |
|
127 { |
|
128 aBrowseCallback.iCallback( aBrowseCallback.iContext, aParentHandle, aCurDepth ); |
|
129 } |
|
130 else |
|
131 { |
|
132 GetObjectHandlesL( aCurDepth + 1, KMTPStorageAll, aFormatCode, aDepth - 1, aParentHandle, aBrowseCallback ); |
|
133 aBrowseCallback.iCallback( aBrowseCallback.iContext, aParentHandle, aCurDepth ); |
|
134 } |
|
135 |
|
136 __FLOG( _L8("-GetFolderObjectHandlesL") ); |
|
137 } |
|
138 |
|
139 void CMTPObjectBrowser::GetRootObjectHandlesL( TUint32 aCurDepth, TUint32 aFormatCode, TUint32 aDepth, const TBrowseCallback& aBrowseCallback ) const |
|
140 { |
|
141 __FLOG_VA( ( _L8("+GetRootObjectHandlesL( %d, 0x%08X, %d )"), aCurDepth, aFormatCode, aDepth ) ); |
|
142 |
|
143 switch ( aDepth ) |
|
144 { |
|
145 case KMaxTUint: |
|
146 GetObjectHandlesL( aCurDepth, KMTPStorageAll, aFormatCode, aDepth, KMTPHandleNoParent, aBrowseCallback ); |
|
147 break; |
|
148 case 0: |
|
149 // do nothing |
|
150 break; |
|
151 default: |
|
152 GetObjectHandlesL( aCurDepth, KMTPStorageAll, aFormatCode, aDepth, KMTPHandleNoParent, aBrowseCallback ); |
|
153 break; |
|
154 } |
|
155 |
|
156 __FLOG( _L8("-GetRootObjectHandlesL") ); |
|
157 } |
|
158 |
|
159 void CMTPObjectBrowser::GetObjectHandlesTreeL( TUint32 aCurDepth, TUint32 aFormatCode, TUint32 aDepth, TUint32 aParentHandle, const TBrowseCallback& aBrowseCallback ) const |
|
160 { |
|
161 __FLOG_VA( ( _L8("+GetObjectHandlesTreeL( %d, 0x%08X, %d, 0x%08X )"), aCurDepth, aFormatCode, aDepth, aParentHandle ) ); |
|
162 |
|
163 iDpFw.ObjectMgr().ObjectL( aParentHandle, *iObjMetaCache ); |
|
164 #ifdef __FLOG_ACTIVE |
|
165 RBuf suid; |
|
166 suid.Create( iObjMetaCache->DesC( CMTPObjectMetaData::ESuid ) ); |
|
167 #endif |
|
168 if ( IsFolderFormat( iObjMetaCache->Uint( CMTPObjectMetaData::EFormatCode ), iObjMetaCache->Uint( CMTPObjectMetaData::EFormatSubCode ) ) ) |
|
169 { |
|
170 GetFolderObjectHandlesL( aCurDepth, aFormatCode, aDepth, aParentHandle, aBrowseCallback ); |
|
171 } |
|
172 else |
|
173 { |
|
174 aBrowseCallback.iCallback( aBrowseCallback.iContext, aParentHandle, aCurDepth ); |
|
175 } |
|
176 #ifdef __FLOG_ACTIVE |
|
177 __FLOG_1( _L8("recursion_depth: %d"), aCurDepth ); |
|
178 __FLOG_1( _L("recursion_suid: %S"), &suid ); |
|
179 suid.Close(); |
|
180 #endif |
|
181 __FLOG( _L8("-GetObjectHandlesTreeL") ); |
|
182 } |
|
183 |
|
184 |