examples/RemoteConn/MtpDataProviderExample/src/mtpdataproviderpluginexample.cpp

00001 /*
00002 Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description: 
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 // Class constants.
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& /*aStrings*/) 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         // Ignore all other notifications.
00195         break;
00196         }
00197     }
00198     
00205 void CMTPExampleDataProvider::ProcessRequestPhaseL(TMTPTransactionPhase aPhase, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection)
00206         {
00207     //Check if the request is handled.
00208     TInt idx(LocateRequestProcessorL(aRequest, aConnection));
00209     MMTPExampleDpRequestProcessor* processor(iActiveProcessors[idx]);
00210     //Handle the request
00211     TBool result(processor->HandleRequestL(aRequest, aPhase));
00212     if (result)    //destroy the processor
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& /*aSession*/)   
00252         {
00253         }
00254         
00260 TAny* CMTPExampleDataProvider::GetExtendedInterface(TUid /*aInterfaceUid*/)     
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     //Get the Count of the request supported.
00285     TInt count(iActiveProcessors.Count());
00286     //Not found create and then append to the array.
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 

Generated by  doxygen 1.6.2