mtpdataproviders/mtppictbridgedp/src/mtppictbridgerequestprocessor.cpp
changeset 0 d0791faffa3f
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 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  @file
       
    18  @internalTechnology
       
    19  */
       
    20 
       
    21 #include <mtp/tmtptyperequest.h>
       
    22 #include "mtppictbridgedpconst.h"
       
    23 #include "mtppictbridgedpprocessor.h"
       
    24 #include "cmtppictbridgedpgetobject.h"
       
    25 #include "cmtppictbridgedpgetobjectinfo.h"
       
    26 #include "cmtppictbridgedpsendobjectinfo.h"
       
    27 #include "cmtprequestunknown.h"
       
    28 #include "cmtpcommonrequestprocessor.h"
       
    29 
       
    30 /** 
       
    31 Defines a processor factory function pointer
       
    32 
       
    33 @internalTechnology
       
    34 */
       
    35 typedef MMTPRequestProcessor* (*TMTPPictBridgeRequestProcessorCreateFunc)(
       
    36                                                                 MMTPDataProviderFramework& aFramework, 
       
    37                                                                 MMTPConnection& aConnection,
       
    38                                                                 CMTPPictBridgeDataProvider& aDataProvider);
       
    39 
       
    40 
       
    41 /** 
       
    42 Defines an entry which maps from operation code to the request processor
       
    43 
       
    44 @internalTechnology
       
    45 */
       
    46 typedef struct 
       
    47     {
       
    48     TUint16                                  iOperationCode;
       
    49     TMTPPictBridgeRequestProcessorCreateFunc iCreateFunc;
       
    50     }TMTPPictBridgeRequestProcessorEntry;
       
    51 
       
    52 template<TMTPResponseCode RESPCODE, TBool HASITORDATA>
       
    53 static MMTPRequestProcessor* CommonProcessorCreator(MMTPDataProviderFramework& aFramework, 
       
    54                                                     MMTPConnection& aConnection,
       
    55                                                     CMTPPictBridgeDataProvider& )
       
    56     {
       
    57     return CMTPCommonRequestProcessor::NewL<RESPCODE, HASITORDATA>(aFramework, aConnection);
       
    58     }
       
    59     
       
    60 
       
    61 // --------------------------------------------------------------------------
       
    62 // A mapping table from the operation code to the request processor factory method
       
    63 // --------------------------------------------------------------------------
       
    64 //
       
    65 static const TMTPPictBridgeRequestProcessorEntry KMTPPictBridgeDpRequestProcessorTable[]=
       
    66     {
       
    67     {EMTPOpCodeGetObjectInfo,           CMTPPictBridgeDpGetObjectInfo::NewL},
       
    68     {EMTPOpCodeGetObject,               CMTPPictBridgeDpGetObject::NewL},
       
    69     {EMTPOpCodeSendObjectInfo,          CMTPPictBridgeDpSendObjectInfo::NewL},
       
    70     {EMTPOpCodeSendObject,              CMTPPictBridgeDpSendObjectInfo::NewL}  
       
    71     };
       
    72 
       
    73 // --------------------------------------------------------------------------
       
    74 // Create a request processor that matches the request
       
    75 // @param aPlugin   The reference to the data provider plugin 
       
    76 // @param aFramework The reference to the data provider framework
       
    77 // @param aRequest  The request to be processed
       
    78 // @param aConnection The connection from which the request comes from
       
    79 // @return a pointer to the request processor
       
    80 // --------------------------------------------------------------------------
       
    81 //
       
    82 MMTPRequestProcessor* MTPPictBridgeDpProcessor::CreateL(
       
    83                                                     MMTPDataProviderFramework& aFramework,
       
    84                                                     const TMTPTypeRequest& aRequest, 
       
    85                                                     MMTPConnection& aConnection,
       
    86                                                     CMTPPictBridgeDataProvider& aDataProvider)
       
    87     {
       
    88     
       
    89 
       
    90     TMTPPictBridgeRequestProcessorCreateFunc createFunc = NULL; 
       
    91     TUint16 operationCode = aRequest.Uint16(TMTPTypeRequest::ERequestOperationCode);
       
    92     TInt count = sizeof(KMTPPictBridgeDpRequestProcessorTable) / sizeof(TMTPRequestProcessorEntry);
       
    93 
       
    94     for(TInt i = 0; i < count; i++)
       
    95         {
       
    96         if(KMTPPictBridgeDpRequestProcessorTable[i].iOperationCode == operationCode)
       
    97             {
       
    98             createFunc = KMTPPictBridgeDpRequestProcessorTable[i].iCreateFunc;
       
    99             break;
       
   100             }
       
   101         }
       
   102 
       
   103     if(!createFunc) 
       
   104         {
       
   105         return CMTPRequestUnknown::NewL(aFramework, aConnection);
       
   106         }
       
   107 
       
   108     return (*createFunc)(aFramework, aConnection, aDataProvider);
       
   109     }
       
   110