00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <bautils.h>
00031 #include <mtp/mmtpconnection.h>
00032 #include <mtp/mtpprotocolconstants.h>
00033 #include <mtp/mmtpdataproviderframework.h>
00034 #include <mtp/mmtpstoragemgr.h>
00035 #include <mtp/cmtpobjectmetadata.h>
00036 #include <mtp/mmtpobjectmgr.h>
00037
00038 #include "mtpdataproviderpluginexample.h"
00039
00040 #include "mtpexamplerequestprocessor.h"
00041 #include "cmtpexampledprequestprocessor.h"
00042
00043 #include "cmtpexampledpconst.h"
00044
00045
00046
00048 static const TInt KMTPExampleDpSessionGranualrity = 3;
00049
00050
00055 TAny* CMTPExampleDataProvider::NewL(TAny* aParams)
00056 {
00057 CMTPExampleDataProvider* self = new (ELeave) CMTPExampleDataProvider(aParams);
00058 CleanupStack::PushL(self);
00059 self->ConstructL();
00060 CleanupStack::Pop(self);
00061 return self;
00062 }
00063
00068 CMTPExampleDataProvider::CMTPExampleDataProvider(TAny* aParams)
00069 :CMTPDataProviderPlugin(aParams),
00070 iActiveProcessors(KMTPExampleDpSessionGranualrity),
00071 iActiveProcessor(-1)
00072 {
00073
00074 }
00075
00079 CMTPExampleDataProvider::~CMTPExampleDataProvider()
00080 {
00081 TUint count(iActiveProcessors.Count());
00082 while (count--)
00083 {
00084 iActiveProcessors[count]->Release();
00085 }
00086 iActiveProcessors.Close();
00087 }
00088
00089
00090 void CMTPExampleDataProvider::Cancel()
00091 {
00092 }
00093
00099 void CMTPExampleDataProvider::Supported(TMTPSupportCategory aCategory, RArray<TUint>& aArray) const
00100 {
00101 switch (aCategory)
00102 {
00103 case EEvents:
00104 break;
00105 case EObjectPlaybackFormats:
00106 case EObjectCaptureFormats:
00107 break;
00108 case EObjectProperties:
00109 break;
00110
00111 case EOperations:
00112 {
00113 TInt count(sizeof(KMTPExampleDpSupportedOperations) / sizeof(KMTPExampleDpSupportedOperations[0]));
00114 for (TInt i(0); (i < count); i++)
00115 {
00116 aArray.Append(KMTPExampleDpSupportedOperations[i]);
00117 }
00118 }
00119 break;
00120
00121 default:
00122 break;
00123 }
00124 }
00131 void CMTPExampleDataProvider::SupportedL(TMTPSupportCategory aCategory, CDesCArray& ) const
00132 {
00133 switch (aCategory)
00134 {
00135 case EFolderExclusionSets:
00136 break;
00137 case EFormatExtensionSets:
00138 break;
00139 default:
00140 break;
00141 }
00142 }
00143
00147 void CMTPExampleDataProvider::StartObjectEnumerationL(TUint32 aStorageId)
00148 {
00149 Framework().ObjectEnumerationCompleteL(aStorageId);
00150
00151 }
00152
00156 void CMTPExampleDataProvider::StartStorageEnumerationL()
00157 {
00158 Framework().StorageEnumerationCompleteL();
00159 }
00160
00166 void CMTPExampleDataProvider::ProcessEventL(const TMTPTypeEvent& aEvent, MMTPConnection& aConnection)
00167 {
00168 TInt idx = LocateRequestProcessorL(aEvent, aConnection);
00169
00170 if (idx != KErrNotFound)
00171 {
00172 iActiveProcessors[idx]->HandleEventL(aEvent);
00173 }
00174 }
00175
00181 void CMTPExampleDataProvider::ProcessNotificationL(TMTPNotification aNotification, const TAny* aParams)
00182 {
00183 switch (aNotification)
00184 {
00185 case EMTPSessionClosed:
00186 SessionClosedL(*reinterpret_cast<const TMTPNotificationParamsSessionChange*>(aParams));
00187 break;
00188
00189 case EMTPSessionOpened:
00190 SessionOpenedL(*reinterpret_cast<const TMTPNotificationParamsSessionChange*>(aParams));
00191 break;
00192
00193 default:
00194
00195 break;
00196 }
00197 }
00198
00205 void CMTPExampleDataProvider::ProcessRequestPhaseL(TMTPTransactionPhase aPhase, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection)
00206 {
00207
00208 TInt idx(LocateRequestProcessorL(aRequest, aConnection));
00209 MMTPExampleDpRequestProcessor* processor(iActiveProcessors[idx]);
00210
00211 TBool result(processor->HandleRequestL(aRequest, aPhase));
00212 if (result)
00213 {
00214 processor->Release();
00215 iActiveProcessors.Remove(idx);
00216 }
00217 }
00218
00224 void CMTPExampleDataProvider::SessionClosedL(const TMTPNotificationParamsSessionChange& aSession)
00225 {
00226 TInt count = iActiveProcessors.Count();
00227 while(count--)
00228 {
00229 MMTPExampleDpRequestProcessor* processor = iActiveProcessors[count];
00230 TUint32 sessionId = processor->SessionId();
00231 if((sessionId == aSession.iMTPId) && (processor->Connection().ConnectionId() == aSession.iConnection.ConnectionId()))
00232 {
00233 iActiveProcessors.Remove(count);
00234 if (count == iActiveProcessor)
00235 {
00236 iActiveProcessorRemoved = ETrue;
00237 }
00238 else
00239 {
00240 processor->Release();
00241 }
00242 }
00243 }
00244 }
00245
00251 void CMTPExampleDataProvider::SessionOpenedL(const TMTPNotificationParamsSessionChange& )
00252 {
00253 }
00254
00260 TAny* CMTPExampleDataProvider::GetExtendedInterface(TUid )
00261 {
00262 return NULL;
00263 }
00264
00268 void CMTPExampleDataProvider::ConstructL()
00269 {
00270
00271
00272 }
00273
00281 TInt CMTPExampleDataProvider::LocateRequestProcessorL(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection)
00282 {
00283 TInt idx(KErrNotFound);
00284
00285 TInt count(iActiveProcessors.Count());
00286
00287 if (idx == KErrNotFound)
00288 {
00289 MMTPExampleDpRequestProcessor* processor = MTPExampleDpProcessor::CreateL
00290 (Framework(), aRequest, aConnection);
00291 CleanupReleasePushL(*processor);
00292 iActiveProcessors.AppendL(processor);
00293 CleanupStack::Pop(processor);
00294 idx = count;
00295 }
00296 return idx;
00297 }
00298
00307 TInt CMTPExampleDataProvider::LocateRequestProcessorL(const TMTPTypeEvent& aEvent, MMTPConnection& aConnection)
00308 {
00309 TInt idx(KErrNotFound);
00310 TInt count(iActiveProcessors.Count());
00311 for (TInt i(0); (i < count); i++)
00312 {
00313 if (iActiveProcessors[i]->Match(aEvent, aConnection))
00314 {
00315 idx = i;
00316 break;
00317 }
00318 }
00319 return idx;
00320 }
00321
00322
00323