mtpfws/mtpfw/src/cmtpdataproviderconfig.cpp
changeset 0 d0791faffa3f
child 4 60a94a45d437
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     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 <barsread.h>
       
    17 #include "cmtpdataproviderconfig.h"
       
    18 
       
    19 /**
       
    20 CMTPDataProviderConfig factory method.
       
    21 @param aReader The data provider configuration resource file reader.
       
    22 @param aFileName The data provider configuration resource file name.
       
    23 @return A pointer to a new CMTPDataProviderConfig instance. Ownership IS 
       
    24 transfered.
       
    25 @leave One of the system wide error codes if a processing failure occurs.
       
    26 */
       
    27 CMTPDataProviderConfig* CMTPDataProviderConfig::NewL(TResourceReader& aReader, const TDesC& aFileName)
       
    28     {
       
    29     CMTPDataProviderConfig* self = new (ELeave) CMTPDataProviderConfig();
       
    30     CleanupStack::PushL(self);
       
    31     self->ConstructL(aReader, aFileName);
       
    32     CleanupStack::Pop(self);
       
    33     return self;
       
    34     }
       
    35 
       
    36 /**
       
    37 Destructor.
       
    38 */
       
    39 CMTPDataProviderConfig::~CMTPDataProviderConfig()
       
    40     {
       
    41     delete iServerName;
       
    42     delete iServerImageName;
       
    43     delete iResourceFileName;
       
    44     }
       
    45 
       
    46 /**
       
    47 Indicates if the data provider supporte the specified operational mode.
       
    48 @param aMode The operational mode.
       
    49 @return ETrue if the mode is supported, otherwise EFalse.
       
    50 */
       
    51 TBool CMTPDataProviderConfig::ModeSupported(TMTPOperationalMode aMode) const
       
    52     {
       
    53     return (iSupportedModes & aMode);
       
    54     }
       
    55     
       
    56 TUint CMTPDataProviderConfig::UintValue(MMTPDataProviderConfig::TParameter aParam) const
       
    57     {
       
    58     TUint value(0);
       
    59     switch (aParam)
       
    60         {
       
    61     case EDataProviderType:
       
    62         value = iType;
       
    63         break;
       
    64 
       
    65     case EMajorProtocolRevision:
       
    66         value = iVersion;
       
    67         break;
       
    68 
       
    69     case EOpaqueResource:
       
    70         value = iOpaqueResource;
       
    71         break;
       
    72 
       
    73     case EEnumerationPhase:
       
    74         value = iEnumerationPhase;
       
    75         break;
       
    76 
       
    77     default:
       
    78         User::Invariant();
       
    79         break;
       
    80         }
       
    81     return value;
       
    82     }
       
    83     
       
    84 TBool CMTPDataProviderConfig::BoolValue(MMTPDataProviderConfig::TParameter aParam) const
       
    85     {
       
    86     TBool value(EFalse);
       
    87     switch (aParam)
       
    88         {
       
    89     case EObjectEnumerationPersistent:
       
    90         value = iObjectEnumerationPersistent;
       
    91         break;
       
    92 
       
    93     default:
       
    94         User::Invariant();
       
    95         }
       
    96     return value;
       
    97     }
       
    98     
       
    99 const TDesC& CMTPDataProviderConfig::DesCValue(MMTPDataProviderConfig::TParameter aParam) const
       
   100     {
       
   101     const TDesC* value(&KNullDesC);
       
   102     switch (aParam)
       
   103         {
       
   104     case EServerName:
       
   105         value = iServerName;
       
   106         break;
       
   107 
       
   108     case EServerImageName:
       
   109         value = iServerImageName;
       
   110         break;
       
   111 
       
   112     case EResourceFileName:
       
   113         value = iResourceFileName;
       
   114         break;
       
   115 
       
   116     default:
       
   117         User::Invariant();
       
   118         break;
       
   119         }
       
   120     return *value;
       
   121     }
       
   122     
       
   123 const TDesC8& CMTPDataProviderConfig::DesC8Value(MMTPDataProviderConfig::TParameter /*aParam*/) const
       
   124     {
       
   125     User::Invariant();
       
   126     return KNullDesC8;
       
   127     }
       
   128     
       
   129 void CMTPDataProviderConfig::GetArrayValue(MMTPDataProviderConfig::TParameter aParam, RArray<TUint>& aArray) const
       
   130     {
       
   131     switch (aParam)
       
   132         {
       
   133     case ESupportedModes:
       
   134         {
       
   135         if (iSupportedModes & EModePTP)
       
   136             {
       
   137             aArray.Append(EModePTP);
       
   138             }
       
   139         if (iSupportedModes & EModeMTP)
       
   140             {
       
   141             aArray.Append(EModeMTP);
       
   142             }
       
   143         if (iSupportedModes & EModePictBridge)
       
   144             {
       
   145             aArray.Append(EModePictBridge);
       
   146             }
       
   147 
       
   148         break;
       
   149         }
       
   150 
       
   151     default:
       
   152         User::Invariant();
       
   153         break;
       
   154         }
       
   155     }
       
   156 
       
   157 /**
       
   158 Constructor
       
   159 */
       
   160 CMTPDataProviderConfig::CMTPDataProviderConfig()
       
   161     {
       
   162 
       
   163     }
       
   164 
       
   165 /**
       
   166 Second phase construction. Reads the data from the reader and configures the instance.
       
   167 See mtpdpinfo.rh for the definition of the MTP_DATA_PROVIDER resource structure.
       
   168 @param aReader    Resource reader opened on the corresponding RSC file.
       
   169 */
       
   170 void CMTPDataProviderConfig::ConstructL(TResourceReader& aReader, const TDesC& aFileName)
       
   171     {
       
   172     iResourceFileName = aFileName.AllocL();
       
   173     
       
   174     // WORD type
       
   175     iType = static_cast<TMTPDataProviderTypes>(aReader.ReadUint16());
       
   176     if(KMTPDataProviderTypeECOM != iType)
       
   177         {
       
   178         User::Leave(KErrCorrupt);
       
   179         }
       
   180 
       
   181     // BYTE major_version
       
   182     iVersion = aReader.ReadInt8();
       
   183 
       
   184     // BYTE object_enumeration_persistent
       
   185     iObjectEnumerationPersistent = (aReader.ReadInt8() != 0);
       
   186 
       
   187     // WORD supported_modes
       
   188     iSupportedModes = aReader.ReadUint16();
       
   189 
       
   190     // LTEXT server_name
       
   191     iServerName = aReader.ReadHBufCL();
       
   192 
       
   193     // LTEXT server_image_name
       
   194     iServerImageName = aReader.ReadHBufCL();
       
   195 
       
   196     // LLINK opaque_resource
       
   197     iOpaqueResource = aReader.ReadUint32();
       
   198 
       
   199     // BYTE enumeration_phase
       
   200     iEnumerationPhase = aReader.ReadUint8();
       
   201     if (iEnumerationPhase == 0)
       
   202       {
       
   203       // The default value 0 is treated as 255
       
   204       iEnumerationPhase = 255;
       
   205       }
       
   206     
       
   207     }
       
   208