upnpmediaserver/mediaserverclient/src/upnpmediaserversettings.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     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:  Media Server Settings
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32math.h>
       
    21 #include <centralrepository.h>
       
    22 #include "upnpstring.h"
       
    23 #include <platform_paths.hrh>
       
    24 #include <bldvariant.hrh>
       
    25 
       
    26 #include "upnpmediaserversettings.h"
       
    27 
       
    28 #ifdef _DEBUG
       
    29 #define KLogFile _L("UPnPMediaServer.txt")
       
    30 #endif
       
    31 #include "upnpcustomlog.h"
       
    32 
       
    33 const TInt KBufferGranularity = 256;
       
    34 
       
    35 // =========================== MEMBER FUNCTIONS ===============================
       
    36 // ----------------------------------------------------------------------------
       
    37 // CUpnpMediaServerSettings::ConstructL
       
    38 // Symbian 2nd phase constructor can leave.
       
    39 // ----------------------------------------------------------------------------
       
    40 //
       
    41 void CUpnpMediaServerSettings::ConstructL(TUid aRepositoryUid)
       
    42     {
       
    43     iRepository = CRepository::NewL(aRepositoryUid);
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CUpnpMediaServerSettings::CUpnpMediaServerSettings
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CUpnpMediaServerSettings::CUpnpMediaServerSettings() :CActive(EPriorityStandard)
       
    51     {
       
    52     CActiveScheduler::Add(this);
       
    53     }
       
    54 	
       
    55 // ----------------------------------------------------------------------------
       
    56 // CUpnpMediaServerSettings::NewL
       
    57 // Two-phased constructor.
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 EXPORT_C CUpnpMediaServerSettings* CUpnpMediaServerSettings::NewL()
       
    61     {
       
    62     CUpnpMediaServerSettings* self = new ( ELeave ) CUpnpMediaServerSettings();
       
    63     CleanupStack::PushL( self );
       
    64     self->ConstructL( KCRUidMediaServer );
       
    65     CleanupStack::Pop();
       
    66     return self;
       
    67     }
       
    68 
       
    69 // Destructor
       
    70 CUpnpMediaServerSettings::~CUpnpMediaServerSettings()
       
    71     {
       
    72     Cancel();
       
    73     delete iRepository;
       
    74     }
       
    75     
       
    76 // ----------------------------------------------------------------------------
       
    77 // CUpnpMediaServerSettings::Set
       
    78 // ----------------------------------------------------------------------------
       
    79 //
       
    80 EXPORT_C TInt CUpnpMediaServerSettings::SetL(TUint aId, const TDesC8& aValue)
       
    81     {
       
    82     HBufC* data = UpnpString::ToUnicodeL(aValue);
       
    83     TPtr dataPtr(data->Des());
       
    84     TInt err = iRepository->Set(aId, dataPtr);
       
    85     delete data;
       
    86     return err;
       
    87     }    
       
    88 
       
    89 // ----------------------------------------------------------------------------
       
    90 // CUpnpMediaServerSettings::Set
       
    91 // ----------------------------------------------------------------------------
       
    92 //
       
    93 EXPORT_C TInt CUpnpMediaServerSettings::Set(TUint aId, const TDesC& aValue)
       
    94     {
       
    95     return iRepository->Set(aId, aValue);
       
    96     }
       
    97 
       
    98 // ----------------------------------------------------------------------------
       
    99 // CUpnpMediaServerSettings::Set
       
   100 // ----------------------------------------------------------------------------
       
   101 //
       
   102 EXPORT_C TInt CUpnpMediaServerSettings::Set(TUint aId, const TInt& aValue)
       
   103     {
       
   104     return iRepository->Set(aId, aValue);
       
   105     }
       
   106 // ----------------------------------------------------------------------------
       
   107 // CUpnpMediaServerSettings::Get
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 EXPORT_C TInt CUpnpMediaServerSettings::Get(TUint aId, TInt& aValue)
       
   111     {
       
   112     return iRepository->Get(aId, aValue);
       
   113     }    
       
   114 // ----------------------------------------------------------------------------
       
   115 // CUpnpMediaServerSettings::Get
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 EXPORT_C TInt CUpnpMediaServerSettings::Get(TUint aId, TDes& aValue)
       
   119     {
       
   120     return iRepository->Get(aId, aValue);
       
   121     }    
       
   122 // ----------------------------------------------------------------------------
       
   123 // CUpnpMediaServerSettings::Get
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 EXPORT_C HBufC8* CUpnpMediaServerSettings::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         }
       
   140     while(err == KErrOverflow );
       
   141 	
       
   142     // handle error
       
   143     if(err)
       
   144         {
       
   145         delete buf;
       
   146         User::Leave(err);
       
   147         }
       
   148 
       
   149     // convert to UTF-8
       
   150     CleanupStack::PushL(buf);	
       
   151     HBufC8* buf8 = UpnpString::FromUnicodeL(*buf);
       
   152     CleanupStack::PopAndDestroy(buf);
       
   153     return buf8;
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CUpnpMediaServerSettings::DoCancel
       
   158 // ---------------------------------------------------------------------------
       
   159 //	
       
   160 void CUpnpMediaServerSettings::DoCancel()
       
   161     {
       
   162     iRepository->NotifyCancelAll();
       
   163     }
       
   164 	
       
   165 // ---------------------------------------------------------------------------
       
   166 // CUpnpMediaServerSettings::Subscribe
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 EXPORT_C TInt CUpnpMediaServerSettings::Subscribe(TUint aId, MUpnpSettingObserver* aObserver)
       
   170     {
       
   171     iObserver = aObserver;
       
   172 
       
   173     Cancel();
       
   174 
       
   175     TInt err = iRepository->NotifyRequest(aId, iStatus);
       
   176     if( !err )
       
   177         {
       
   178         SetActive();    
       
   179         }
       
   180     return err;
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------------------------
       
   184 // CUpnpMediaServerSettings::RunL
       
   185 // ---------------------------------------------------------------------------
       
   186 //	
       
   187 void CUpnpMediaServerSettings::RunL()
       
   188     {
       
   189     iObserver->SettingChangedL();
       
   190     }	
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // CUpnpMediaServerSettings::RunError
       
   194 // ---------------------------------------------------------------------------
       
   195 //  
       
   196 TInt CUpnpMediaServerSettings::RunError( TInt aErr )
       
   197     {
       
   198     LOGS1("CUpnpMediaServerSettings::RunError(%d)", aErr);
       
   199     return KErrNone;
       
   200     }
       
   201 
       
   202 // End of File