examples/RemoteConn/MtpDataProviderExample/src/mtpdataproviderpluginexample.cpp

00001 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 //
00015 
00016 #include <bautils.h>
00017 #include <mtp/mmtpconnection.h>
00018 #include <mtp/mtpprotocolconstants.h>
00019 #include <mtp/mmtpdataproviderframework.h>
00020 #include <mtp/mmtpstoragemgr.h>
00021 #include <mtp/cmtpobjectmetadata.h>
00022 #include <mtp/mmtpobjectmgr.h>
00023 
00024 #include "mtpdataproviderpluginexample.h"
00025 
00026 #include "mtpexamplerequestprocessor.h"
00027 #include "cmtpexampledprequestprocessor.h"
00028 
00029 #include "cmtpexampledpconst.h"
00030 
00031 
00032 // Class constants.
00034 static const TInt KMTPExampleDpSessionGranualrity = 3;
00035 
00036 
00041 TAny* CMTPExampleDataProvider::NewL(TAny* aParams)
00042         {
00043         CMTPExampleDataProvider* self = new (ELeave) CMTPExampleDataProvider(aParams);
00044         CleanupStack::PushL(self);
00045         self->ConstructL();
00046         CleanupStack::Pop(self);
00047         return self;
00048         }
00049         
00054 CMTPExampleDataProvider::CMTPExampleDataProvider(TAny* aParams)
00055         :CMTPDataProviderPlugin(aParams),
00056         iActiveProcessors(KMTPExampleDpSessionGranualrity),
00057     iActiveProcessor(-1)
00058         {
00059         
00060         }
00061 
00065 CMTPExampleDataProvider::~CMTPExampleDataProvider()
00066         {
00067     TUint count(iActiveProcessors.Count());
00068     while (count--)
00069         {
00070         iActiveProcessors[count]->Release();
00071         }
00072     iActiveProcessors.Close();
00073         }
00074         
00075 
00076 void CMTPExampleDataProvider::Cancel()
00077         {
00078         }
00079 
00085 void CMTPExampleDataProvider::Supported(TMTPSupportCategory aCategory, RArray<TUint>& aArray) const
00086     {
00087     switch (aCategory) 
00088         {        
00089         case EEvents:
00090             break;
00091         case EObjectPlaybackFormats:
00092         case EObjectCaptureFormats:
00093             break;
00094         case EObjectProperties:
00095             break; 
00096     
00097         case EOperations:
00098             {
00099             TInt count(sizeof(KMTPExampleDpSupportedOperations) / sizeof(KMTPExampleDpSupportedOperations[0]));
00100             for (TInt i(0); (i < count); i++)
00101                 {
00102                 aArray.Append(KMTPExampleDpSupportedOperations[i]);
00103                 }   
00104             }
00105             break;  
00106    
00107         default:   
00108             break;
00109         }
00110     }
00117 void CMTPExampleDataProvider::SupportedL(TMTPSupportCategory aCategory, CDesCArray& /*aStrings*/) const
00118         {
00119         switch (aCategory) 
00120         {
00121         case EFolderExclusionSets:
00122             break;
00123         case EFormatExtensionSets:
00124             break;
00125         default:
00126             break;
00127         }
00128         }
00129 
00133 void CMTPExampleDataProvider::StartObjectEnumerationL(TUint32 aStorageId)
00134     {
00135     Framework().ObjectEnumerationCompleteL(aStorageId);
00136 
00137     }
00138     
00142 void CMTPExampleDataProvider::StartStorageEnumerationL()
00143     {
00144     Framework().StorageEnumerationCompleteL();
00145     }
00146 
00152 void CMTPExampleDataProvider::ProcessEventL(const TMTPTypeEvent& aEvent, MMTPConnection& aConnection)   
00153         {
00154     TInt idx = LocateRequestProcessorL(aEvent, aConnection);
00155 
00156     if (idx != KErrNotFound)
00157         {
00158         iActiveProcessors[idx]->HandleEventL(aEvent);
00159         }
00160         }
00161 
00167 void CMTPExampleDataProvider::ProcessNotificationL(TMTPNotification aNotification, const TAny* aParams)
00168     {
00169     switch (aNotification)
00170         {
00171     case EMTPSessionClosed:
00172         SessionClosedL(*reinterpret_cast<const TMTPNotificationParamsSessionChange*>(aParams));
00173         break;
00174         
00175     case EMTPSessionOpened:
00176         SessionOpenedL(*reinterpret_cast<const TMTPNotificationParamsSessionChange*>(aParams));
00177         break;
00178         
00179     default:
00180         // Ignore all other notifications.
00181         break;
00182         }
00183     }
00184     
00191 void CMTPExampleDataProvider::ProcessRequestPhaseL(TMTPTransactionPhase aPhase, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection)
00192         {
00193     //Check if the request is handled.
00194     TInt idx(LocateRequestProcessorL(aRequest, aConnection));
00195     MMTPExampleDpRequestProcessor* processor(iActiveProcessors[idx]);
00196     //Handle the request
00197     TBool result(processor->HandleRequestL(aRequest, aPhase));
00198     if (result)    //destroy the processor
00199         {
00200         processor->Release();
00201         iActiveProcessors.Remove(idx);
00202         }
00203         }
00204 
00210 void CMTPExampleDataProvider::SessionClosedL(const TMTPNotificationParamsSessionChange& aSession)       
00211         {
00212     TInt count = iActiveProcessors.Count();
00213     while(count--)
00214         {
00215         MMTPExampleDpRequestProcessor* processor = iActiveProcessors[count];
00216         TUint32 sessionId = processor->SessionId();
00217         if((sessionId == aSession.iMTPId) && (processor->Connection().ConnectionId() == aSession.iConnection.ConnectionId()))
00218             {
00219             iActiveProcessors.Remove(count);
00220             if (count == iActiveProcessor)
00221                 {
00222                 iActiveProcessorRemoved = ETrue;
00223                 }
00224             else
00225                 {
00226                 processor->Release();
00227                 }
00228             }
00229         } 
00230         }
00231 
00237 void CMTPExampleDataProvider::SessionOpenedL(const TMTPNotificationParamsSessionChange& /*aSession*/)   
00238         {
00239         }
00240         
00246 TAny* CMTPExampleDataProvider::GetExtendedInterface(TUid /*aInterfaceUid*/)     
00247         {
00248         return NULL;
00249         }
00250 
00254 void CMTPExampleDataProvider::ConstructL()      
00255         {
00256 
00257       
00258         }
00259 
00267 TInt CMTPExampleDataProvider::LocateRequestProcessorL(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection)
00268         {
00269     TInt idx(KErrNotFound);
00270     //Get the Count of the request supported.
00271     TInt count(iActiveProcessors.Count());
00272     //Not found create and then append to the array.
00273     if (idx == KErrNotFound)
00274         {
00275         MMTPExampleDpRequestProcessor* processor = MTPExampleDpProcessor::CreateL
00276                                                  (Framework(), aRequest, aConnection);
00277         CleanupReleasePushL(*processor);
00278         iActiveProcessors.AppendL(processor);
00279         CleanupStack::Pop(processor);
00280         idx = count;
00281         }
00282     return idx;
00283         }
00284 
00293 TInt CMTPExampleDataProvider::LocateRequestProcessorL(const TMTPTypeEvent& aEvent, MMTPConnection& aConnection)
00294         {
00295     TInt idx(KErrNotFound);
00296     TInt count(iActiveProcessors.Count());
00297     for (TInt i(0); (i < count); i++)
00298         {
00299         if (iActiveProcessors[i]->Match(aEvent, aConnection))
00300             {
00301             idx = i;
00302             break;
00303             }
00304         }    
00305     return idx;   
00306         }
00307         
00308         
00309 

Generated by  doxygen 1.6.2