upnp/upnpstack/serviceframework/src/upnpsettings.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /** @file
       
     2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies  this distribution, and is available 
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CUpnpSettings
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "upnpsettings.h"
       
    21 #include <centralrepository.h>
       
    22 #include "upnpstring.h"
       
    23 #include "upnpcompvariant.hrh"
       
    24 #include <f32file.h> 
       
    25 
       
    26 const TInt KBufferGranularity = 256;
       
    27 // =========================== MEMBER FUNCTIONS ===============================
       
    28 // ----------------------------------------------------------------------------
       
    29 // CUpnpSettings::ConstructL
       
    30 // Symbian 2nd phase constructor can leave.
       
    31 // ----------------------------------------------------------------------------
       
    32 //
       
    33 void CUpnpSettings::ConstructL(TUid aRepositoryUid)
       
    34 {
       
    35     iRepository = CRepository::NewL(aRepositoryUid);       
       
    36 }
       
    37 
       
    38 // ----------------------------------------------------------------------------
       
    39 // CUpnpSettings::NewL
       
    40 // Two-phased constructor.
       
    41 // ----------------------------------------------------------------------------
       
    42 //
       
    43 EXPORT_C CUpnpSettings* CUpnpSettings::NewL(TUid aRepositoryUid)
       
    44 {
       
    45     CUpnpSettings* self = new (ELeave) CUpnpSettings();
       
    46     CleanupStack::PushL(self);
       
    47     self->ConstructL(aRepositoryUid);
       
    48     CleanupStack::Pop();
       
    49     return self;
       
    50 }
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // CUpnpSettings::CUpnpSettings
       
    54 // Destructor
       
    55 // ----------------------------------------------------------------------------
       
    56 //
       
    57 CUpnpSettings::~CUpnpSettings()
       
    58 {
       
    59     delete iRepository;
       
    60 }
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // CUpnpSettings::Set
       
    64 // See upnpsettings.h
       
    65 // ----------------------------------------------------------------------------
       
    66 //
       
    67 EXPORT_C TInt CUpnpSettings::Set(TUint aId, TInt& aValue)
       
    68 {  
       
    69     if ((aId == KUPnPStackFileBufferSize)&&(aValue<0))
       
    70         return KErrArgument;
       
    71     else  
       
    72         return iRepository->Set(aId, aValue);       
       
    73 }
       
    74 
       
    75 
       
    76 // ----------------------------------------------------------------------------
       
    77 // CUpnpSettings::Get
       
    78 // See upnpsettings.h
       
    79 // ----------------------------------------------------------------------------
       
    80 //
       
    81 EXPORT_C TInt CUpnpSettings::Get(TUint aId, TInt& aValue)
       
    82 {
       
    83     return iRepository->Get(aId, aValue);
       
    84 }
       
    85     
       
    86 
       
    87 
       
    88 // ----------------------------------------------------------------------------
       
    89 // CUpnpSettings::Set
       
    90 // See upnpsettings.h
       
    91 // ----------------------------------------------------------------------------
       
    92 //
       
    93 EXPORT_C TInt CUpnpSettings::SetL(TUint aId, const TDesC8& aValue)
       
    94 {
       
    95     HBufC* data = UpnpString::ToUnicodeL(aValue);
       
    96     TPtr dataPtr(data->Des());
       
    97     TInt err = iRepository->Set(aId, dataPtr);
       
    98     delete data;
       
    99     return err;
       
   100 }    
       
   101 
       
   102 // ----------------------------------------------------------------------------
       
   103 // CUpnpSettings::Set
       
   104 // See upnpsettings.h
       
   105 // ----------------------------------------------------------------------------
       
   106 //
       
   107 EXPORT_C TInt CUpnpSettings::Set(TUint aId, const TDesC& aValue)
       
   108 {
       
   109     return iRepository->Set(aId, aValue);
       
   110 }
       
   111 
       
   112 // ----------------------------------------------------------------------------
       
   113 // CUpnpSettings::Get
       
   114 // See upnpsettings.h
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 EXPORT_C TInt CUpnpSettings::Get(TUint aId, TDes& aValue)
       
   118 {
       
   119     return iRepository->Get(aId, aValue);
       
   120 }    
       
   121 // ----------------------------------------------------------------------------
       
   122 // CUpnpSettings::Get
       
   123 // See upnpsettings.h
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 EXPORT_C HBufC8* CUpnpSettings::GetL(TUint aId)
       
   127     {
       
   128     TInt len(0);
       
   129     HBufC* buf(0);
       
   130     TInt err(KErrNotFound);
       
   131             
       
   132     do //until the buffer is large enough
       
   133         {
       
   134         len += KBufferGranularity;
       
   135         delete buf; // first time it is Null
       
   136         buf = HBufC::NewL(len);
       
   137         TPtr bufPtr(buf->Des());
       
   138         err = iRepository->Get(aId, bufPtr);
       
   139         } while(err == KErrOverflow );
       
   140         
       
   141     // handle error
       
   142     if(err)
       
   143         {
       
   144         delete buf;
       
   145         User::Leave(err);
       
   146         }
       
   147         
       
   148     // convert to UTF-8
       
   149     CleanupStack::PushL(buf);       
       
   150     HBufC8* buf8 = UpnpString::FromUnicodeL(*buf);
       
   151     CleanupStack::PopAndDestroy(buf);
       
   152     return buf8;
       
   153     }
       
   154 
       
   155 // ----------------------------------------------------------------------------
       
   156 // CUpnpSettings::GetUserAgentL
       
   157 // See upnpsettings.h
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 EXPORT_C HBufC8* CUpnpSettings::GetUserAgentL()
       
   161     {       
       
   162     #if defined(__HN_31__) || defined(__HN_32__)
       
   163     CUpnpSettings* usc = CUpnpSettings::NewL( KHnCRUidUPnPStack );
       
   164     #else
       
   165     CUpnpSettings* usc = CUpnpSettings::NewL( KCRUidUPnPStack );
       
   166     #endif
       
   167     CleanupStack::PushL(usc);
       
   168     HBufC8* tmp = usc->GetL(CUpnpSettings::KUPnPStackCustomizedUserAgent);  
       
   169     CleanupStack::PopAndDestroy(usc);  
       
   170     return tmp;
       
   171     }
       
   172 
       
   173 
       
   174 
       
   175 // ----------------------------------------------------------------------------
       
   176 // CUpnpSettings::Get
       
   177 // See upnpsettings.h
       
   178 // ----------------------------------------------------------------------------
       
   179 //
       
   180 EXPORT_C TInt CUpnpSettings::GetIapL()
       
   181 {
       
   182     TInt noIap = 0;     
       
   183     #if defined(__HN_31__) || defined(__HN_32__)
       
   184     CUpnpSettings* usc = CUpnpSettings::NewL( KHnCRUidUPnPStack );
       
   185     #else
       
   186     CUpnpSettings* usc = CUpnpSettings::NewL( KCRUidUPnPStack );
       
   187     #endif
       
   188     CleanupStack::PushL(usc);
       
   189     usc->Get(CUpnpSettings::KUPnPStackIapId, noIap);  
       
   190     CleanupStack::PopAndDestroy(usc);  
       
   191     return noIap;
       
   192 }
       
   193 
       
   194 // ----------------------------------------------------------------------------
       
   195 // CUpnpSettings::GetFileBufferSizeL
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 EXPORT_C TInt CUpnpSettings::GetFileBufferSizeL()
       
   199     {
       
   200     TInt size = 0;  
       
   201     #if defined(__HN_31__) || defined(__HN_32__)
       
   202     CUpnpSettings* usc = CUpnpSettings::NewL( KHnCRUidUPnPStack );
       
   203     #else
       
   204     CUpnpSettings* usc = CUpnpSettings::NewL( KCRUidUPnPStack );
       
   205     #endif
       
   206     CleanupStack::PushL(usc);
       
   207     User::LeaveIfError(usc->Get(CUpnpSettings::KUPnPStackFileBufferSize, size));  
       
   208     CleanupStack::PopAndDestroy(usc);  
       
   209     return size;
       
   210     }
       
   211 
       
   212 // ----------------------------------------------------------------------------
       
   213 // CUpnpSettings::GetServerHeaderL
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 EXPORT_C HBufC8* CUpnpSettings::GetServerHeaderL()
       
   217 {
       
   218     #if defined(__HN_31__) || defined(__HN_32__)
       
   219     CUpnpSettings* usc = CUpnpSettings::NewL( KHnCRUidUPnPStack );
       
   220     #else
       
   221     CUpnpSettings* usc = CUpnpSettings::NewL( KCRUidUPnPStack );
       
   222     #endif
       
   223     CleanupStack::PushL(usc);
       
   224     HBufC8* tmp = usc->GetL(CUpnpSettings::KUPnPStackCustomizedServerHeader);  
       
   225     CleanupStack::PopAndDestroy(usc);  
       
   226     return tmp;
       
   227 }
       
   228 
       
   229 // ----------------------------------------------------------------------------
       
   230 // CUpnpSettings::GetServerHeaderL
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 HBufC8* CUpnpSettings::GetMSearchConfigurationL()
       
   234 {
       
   235     #if defined(__HN_31__) || defined(__HN_32__)
       
   236     CUpnpSettings* usc = CUpnpSettings::NewL( KHnCRUidUPnPStack );
       
   237     #else
       
   238     CUpnpSettings* usc = CUpnpSettings::NewL( KCRUidUPnPStack );
       
   239     #endif
       
   240     CleanupStack::PushL(usc);
       
   241     HBufC8* tmp = usc->GetL(CUpnpSettings::KUPnPStackMSearchConfig);  
       
   242     CleanupStack::PopAndDestroy(usc);  
       
   243     return tmp;
       
   244 }
       
   245 
       
   246 // End of File