mtpfws/mtpfw/src/cmtpframeworkconfig.cpp
changeset 0 d0791faffa3f
child 15 f85613f12947
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 <centralrepository.h>
       
    17 
       
    18 #include "cmtpframeworkconfig.h"
       
    19 
       
    20 /**
       
    21 CMTPFrameworkConfig factory method. 
       
    22 @return A pointer to a new CMTPFrameworkConfig instance. Ownership IS transfered.
       
    23 @leave One of the system wide error codes if a processing failure occurs.
       
    24 */
       
    25 CMTPFrameworkConfig* CMTPFrameworkConfig::NewL()
       
    26     {
       
    27     CMTPFrameworkConfig* self = new (ELeave) CMTPFrameworkConfig();
       
    28     CleanupStack::PushL(self);
       
    29     self->ConstructL();
       
    30     CleanupStack::Pop(self);
       
    31     return self;
       
    32     }
       
    33 
       
    34 /**
       
    35 Destructor.
       
    36 */
       
    37 CMTPFrameworkConfig::~CMTPFrameworkConfig()
       
    38     {
       
    39     //Save the AbnormalDown state to EFalse
       
    40     const TInt KNormalShutDownValue = 0;
       
    41     iRepository->Set(EAbnormalDown, KNormalShutDownValue);
       
    42     
       
    43     delete iRepository;
       
    44     }
       
    45 
       
    46 EXPORT_C void CMTPFrameworkConfig::GetValueL(TParameter aParam, TDes& aValue) const
       
    47     {
       
    48     TInt err(iRepository->Get(aParam, aValue));
       
    49     if (KErrNotFound == err)
       
    50         {
       
    51         aValue = KNullDesC;
       
    52         }
       
    53     else if (KErrNone != err)
       
    54         {
       
    55         User::Leave(err);
       
    56         }
       
    57     }
       
    58 
       
    59 EXPORT_C HBufC* CMTPFrameworkConfig::ValueL(TParameter aParam) const
       
    60     {
       
    61     TInt length;
       
    62     HBufC* buf = HBufC::NewLC(0);
       
    63     TPtr ptr(buf->Des());
       
    64     TInt err = iRepository->Get(aParam, ptr, length);    
       
    65 
       
    66     // We want to get the length here so ignore the error if KErrOverflow
       
    67     // Sometimes, the return value is KErrNone
       
    68     if (KErrOverflow == err  || KErrNone == err)
       
    69         {
       
    70         // Now reallocate the buffer to length
       
    71         if((length > 0)&&(length <255))
       
    72             {
       
    73         buf = buf->ReAllocL(length);
       
    74         CleanupStack::Pop();
       
    75         CleanupStack::PushL(buf);
       
    76         
       
    77         // Get the value
       
    78         ptr.Set(buf->Des());
       
    79         User::LeaveIfError(iRepository->Get(aParam, ptr));
       
    80             }
       
    81         }
       
    82     else if (KErrNotFound != err)
       
    83         {
       
    84         User::Leave(err);
       
    85         }
       
    86     CleanupStack::Pop(buf);
       
    87     return buf;
       
    88     }
       
    89 
       
    90 EXPORT_C void CMTPFrameworkConfig::GetValueL(TParameter aParam, TUint& aValue) const
       
    91     {    
       
    92     // Use a temporary to avoid the compiler warning
       
    93     TInt value(0);
       
    94     TInt err(iRepository->Get(aParam, value));
       
    95     if ((KErrNone != err ) &&
       
    96         (KErrNotFound != err))
       
    97         {
       
    98         User::Leave(err);
       
    99         }
       
   100     aValue = static_cast<TUint>(value);
       
   101     }
       
   102 
       
   103 EXPORT_C void CMTPFrameworkConfig::GetValueL(TParameter aParam, TBool& aValue) const
       
   104     {
       
   105     TInt value(0);
       
   106     if(EAbnormalDown == aParam)
       
   107     	{
       
   108     	value = iAbnormalDownValue;
       
   109     	}
       
   110     else
       
   111     	{
       
   112         TInt err(iRepository->Get(aParam, value));
       
   113         if ((KErrNone != err ) &&
       
   114             (KErrNotFound != err))
       
   115             {
       
   116             User::Leave(err);
       
   117             };
       
   118     	}
       
   119     aValue = (value != 0);
       
   120     }
       
   121    
       
   122 EXPORT_C void CMTPFrameworkConfig::GetValueL(TParameter aParam, RArray<TUint>& aArray) const
       
   123     {
       
   124     aArray.Reset();
       
   125     if (CMTPFrameworkConfig::EExcludedStorageDrives != aParam)
       
   126         {
       
   127         User::Leave(KErrArgument);
       
   128         }
       
   129         
       
   130     // Array settings key mask. All array settings keys must be unique that are
       
   131     // unique in the most significant 2 bytes of the mask
       
   132     static const TUint32 KMTPRepositoryArrayMask = 0xFFFF0000;
       
   133     RArray<TUint32> keys;
       
   134     CleanupClosePushL(keys);
       
   135     
       
   136     aArray.Reset();            
       
   137     // Retrieve the keys for all array elements
       
   138     TInt err(iRepository->FindL(aParam, KMTPRepositoryArrayMask, keys));
       
   139     if (KErrNone == err)
       
   140         {
       
   141         // Iterate the keys, retrieve the values and append them to the destination array
       
   142         TInt count = keys.Count();
       
   143         for (TInt index = 0; index < count; index++)
       
   144             {        
       
   145             TInt value;
       
   146             User::LeaveIfError(iRepository->Get(keys[index], value));    
       
   147             aArray.AppendL(static_cast<TUint>(value));
       
   148             }                 
       
   149         }
       
   150     else if (KErrNotFound != err)
       
   151         {
       
   152         User::Leave(err);    
       
   153         }
       
   154     
       
   155     CleanupStack::PopAndDestroy(&keys);    
       
   156     }
       
   157     
       
   158 /**
       
   159 Constructor
       
   160 */
       
   161 CMTPFrameworkConfig::CMTPFrameworkConfig()
       
   162     {
       
   163     }
       
   164 
       
   165 /**
       
   166 Second phase constructor.
       
   167 */
       
   168 void CMTPFrameworkConfig::ConstructL()
       
   169     {
       
   170     const TUint32 KUidMTPRepositoryValue(0x10282FCC);
       
   171     const TUid KUidMTPRepository = {KUidMTPRepositoryValue};
       
   172     iRepository = CRepository::NewL(KUidMTPRepository);
       
   173     
       
   174     const TInt KStartupInitValue = 1;
       
   175     iAbnormalDownValue = 0;
       
   176     TInt err(iRepository->Get(EAbnormalDown, iAbnormalDownValue));
       
   177     if ((KErrNone != err ) && (KErrNotFound != err))
       
   178 		{
       
   179 		User::Leave(err);
       
   180 		}
       
   181     
       
   182     //Save the AbnormalDown state to ETrue
       
   183     User::LeaveIfError(iRepository->Set(EAbnormalDown, KStartupInitValue ));
       
   184 
       
   185     }
       
   186