upnpsettings/upnpsettingsengine/src/upnpsettingsengine.cpp
changeset 0 7f85d04be362
child 12 9925bac961f9
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 2005-2008 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:      UPnP settings engine class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 //  Include Files
       
    25 
       
    26 #include <centralrepository.h>
       
    27 #include <s32file.h>
       
    28 #include <upnpstring.h>
       
    29 #include <pathinfo.h> //PathInfo
       
    30 #include <upnpmediaserversettings.h>
       
    31 
       
    32 #include <cmsettingsui.h> // CCmSettingsUi
       
    33 #include <cmmanager.h>   // RCmManager
       
    34 #include <cmconnectionmethoddef.h>
       
    35 #include <commdb.h> // CCommsDatabase
       
    36 #include <cdbcols.h>
       
    37 #include <WlanCdbCols.h>  // WLAN_SERVICE
       
    38 #include <wlanmgmtcommon.h>
       
    39 
       
    40 #include "upnpsettingsengine.h"
       
    41 #include "upnpsettingsengine.hrh"
       
    42 #include "upnpapplicationcrkeys.h"
       
    43 
       
    44 #include "upnpsettings.h"
       
    45 
       
    46 _LIT( KComponentLogfile, "upnpsettingsengine.txt");
       
    47 #include "upnplog.h"
       
    48 
       
    49 // CONSTANTS
       
    50 _LIT8( KManufacturerName, "Nokia");
       
    51 _LIT( KDummyIAP, "DummyIAP");
       
    52 
       
    53 // upload directory
       
    54 _LIT( KUploadDirectoryCDrive, "\\data\\Download\\Media\\" );
       
    55 _LIT( KUploadDirectory, "\\Download\\Media\\" );
       
    56 _LIT( KModelFile, "\\resource\\versions\\model.txt" );
       
    57 _LIT8( KModel, "Nokia X" );
       
    58 _LIT8( KManufacturerUrl, "http://www.nokia.com");
       
    59 _LIT8( KModelUrl, "http://www.nseries.com");
       
    60 const TInt KMaxNameLength = 128;
       
    61 const TUint KUidWlanBearerType = 0x10281BB1;
       
    62 
       
    63 // ============================ MEMBER FUNCTIONS ============================
       
    64 
       
    65 // --------------------------------------------------------------------------
       
    66 // CUPnPSettingsEngine::CUPnPSettingsEngine
       
    67 // C++ default constructor can NOT contain any code, that
       
    68 // might leave.
       
    69 // --------------------------------------------------------------------------
       
    70 //
       
    71 CUPnPSettingsEngine::CUPnPSettingsEngine()
       
    72     {
       
    73     __LOG("CUPnPSettingsEngine::CUPnPSettingsEngine()");
       
    74     }
       
    75 
       
    76 
       
    77 // --------------------------------------------------------------------------
       
    78 // CUPnPSettingsEngine::NewLC
       
    79 // Two-phased constructor.
       
    80 // --------------------------------------------------------------------------
       
    81 //
       
    82 EXPORT_C CUPnPSettingsEngine* CUPnPSettingsEngine::NewLC()
       
    83     {
       
    84     __LOG("CUPnPSettingsEngine::NewLC()");
       
    85 
       
    86     CUPnPSettingsEngine* self = new (ELeave) CUPnPSettingsEngine;
       
    87     CleanupStack::PushL( self );
       
    88     self->ConstructL();
       
    89     return self;
       
    90     }
       
    91 
       
    92 // --------------------------------------------------------------------------
       
    93 // CUPnPSettingsEngine::NewL
       
    94 // Two-phased constructor.
       
    95 // --------------------------------------------------------------------------
       
    96 //
       
    97 EXPORT_C CUPnPSettingsEngine* CUPnPSettingsEngine::NewL()
       
    98     {
       
    99     __LOG("CUPnPSettingsEngine::NewL()");
       
   100 
       
   101     CUPnPSettingsEngine* self = CUPnPSettingsEngine::NewLC();
       
   102     CleanupStack::Pop( self );
       
   103     return self;
       
   104     }
       
   105 
       
   106 // --------------------------------------------------------------------------
       
   107 // CUPnPSettingsEngine::ConstructL
       
   108 // Symbian 2nd phase constructor can leave.
       
   109 // --------------------------------------------------------------------------
       
   110 //
       
   111 void CUPnPSettingsEngine::ConstructL()
       
   112     {
       
   113     iRepository = CRepository::NewL( KCRUidUPnPApplication );
       
   114     iUpnpRepository = CUpnpSettings::NewL(KCRUidUPnPStack);
       
   115 
       
   116     //set model, ManufacturerUrl, and ModelUrl into UpnpMediaServerSettings
       
   117     SetManufacturerParamsL();
       
   118     }
       
   119 
       
   120 
       
   121 // Destructor
       
   122 EXPORT_C CUPnPSettingsEngine::~CUPnPSettingsEngine()
       
   123     {
       
   124     __LOG("CUPnPSettingsEngine::~CUPnPSettingsEngine()");
       
   125 
       
   126     delete iRepository;
       
   127     iRepository = NULL;
       
   128     delete iUpnpRepository;
       
   129     iUpnpRepository = NULL;
       
   130     }
       
   131 
       
   132 // --------------------------------------------------------------------------
       
   133 // CUPnPSettingsEngine::SetLocalFriendlyName
       
   134 // Sets friendly name to Central Repository
       
   135 // --------------------------------------------------------------------------
       
   136 //
       
   137 EXPORT_C TInt CUPnPSettingsEngine::SetLocalFriendlyName(
       
   138     const TDesC8& aFriendlyName ) const
       
   139     {
       
   140     __LOG("CUPnPSettingsEngine::SetLocalFriendlyName()");
       
   141 
       
   142     TBuf8<KMaxNameLength> name;
       
   143     name.Copy(aFriendlyName);
       
   144     TInt err( KErrNone );
       
   145     TRAP_IGNORE(
       
   146         CUpnpMediaServerSettings* settings = CUpnpMediaServerSettings::NewL();
       
   147         CleanupStack::PushL(settings);
       
   148         err = settings->SetL( UpnpMediaServerSettings::EFriendlyName, name);
       
   149         CleanupStack::PopAndDestroy(settings);
       
   150         );
       
   151     return err;
       
   152     }
       
   153 
       
   154 // --------------------------------------------------------------------------
       
   155 // CUPnPSettingsEngine::GetLocalFriendlyName
       
   156 // Gets friendly name from Central Repository.
       
   157 // --------------------------------------------------------------------------
       
   158 //
       
   159 EXPORT_C TInt CUPnPSettingsEngine::GetLocalFriendlyName(
       
   160     TDes8& aFriendlyName ) const
       
   161     {
       
   162     __LOG("CUPnPSettingsEngine::GetLocalFriendlyName()");
       
   163     TInt err( KErrNone );
       
   164     TRAP(err, err = GetLocalFriendlyNameL( aFriendlyName ) );
       
   165     return err;
       
   166     }
       
   167 
       
   168 // --------------------------------------------------------------------------
       
   169 // CUPnPSettingsEngine::GetLocalFriendlyNameL
       
   170 // Gets friendly name from Central Repository.
       
   171 // --------------------------------------------------------------------------
       
   172 //
       
   173 TInt CUPnPSettingsEngine::GetLocalFriendlyNameL(
       
   174     TDes8& aFriendlyName ) const
       
   175     {
       
   176     __LOG("CUPnPSettingsEngine::GetLocalFriendlyNameL()");
       
   177     
       
   178     CUpnpMediaServerSettings* settings = CUpnpMediaServerSettings::NewL();
       
   179     CleanupStack::PushL( settings );
       
   180     HBufC8 *tmp = settings->GetL( UpnpMediaServerSettings::EFriendlyName );
       
   181     
       
   182     //check if there is any name for the device
       
   183     if ( !tmp->Length() )
       
   184         {
       
   185         //no name available, try to get the device model name as the 
       
   186         //device name
       
   187         
       
   188         // Read device model
       
   189         delete tmp; tmp = NULL;
       
   190         
       
   191         //string ownership transferred
       
   192         tmp = settings->GetL( UpnpMediaServerSettings::
       
   193                               EModelName );
       
   194                               
       
   195         if ( tmp->Length() )
       
   196             {
       
   197             //if device model name is available
       
   198             aFriendlyName.Copy( *tmp );
       
   199             }
       
   200         else
       
   201             {
       
   202             // final try if reading model name fails, use manufacturer name
       
   203             // as device name
       
   204             aFriendlyName.Copy( KManufacturerName );
       
   205             }
       
   206         }
       
   207     else
       
   208         {
       
   209         aFriendlyName.Copy( *tmp );
       
   210         }
       
   211     delete tmp; tmp = NULL;
       
   212     CleanupStack::PopAndDestroy( settings );
       
   213     return KErrNone;
       
   214     }
       
   215 
       
   216 
       
   217 // --------------------------------------------------------------------------
       
   218 // CUPnPSettingsEngine::SetAccessPoint
       
   219 // Sets IAP to Central Repository
       
   220 // --------------------------------------------------------------------------
       
   221 //
       
   222 EXPORT_C TInt CUPnPSettingsEngine::SetAccessPoint( const TInt aIAP )
       
   223     {
       
   224     TInt value = aIAP; // remove constness
       
   225     return iUpnpRepository->Set(CUpnpSettings::KUPnPStackIapId, value );
       
   226     }
       
   227 
       
   228 // --------------------------------------------------------------------------
       
   229 // CUPnPSettingsEngine::GetAccessPoint
       
   230 // Gets IAP from Central Repository.
       
   231 // --------------------------------------------------------------------------
       
   232 //
       
   233 EXPORT_C TInt CUPnPSettingsEngine::GetAccessPoint( TInt& aIAP )
       
   234     {
       
   235     return iUpnpRepository->Get(CUpnpSettings::KUPnPStackIapId, aIAP );
       
   236     }
       
   237 
       
   238 
       
   239 // --------------------------------------------------------------------------
       
   240 // CUPnPSettingsEngine::SetAccessPointSetting
       
   241 // Sets IAP setting to Central Repository
       
   242 // --------------------------------------------------------------------------
       
   243 //
       
   244 EXPORT_C TInt CUPnPSettingsEngine::SetAccessPointSetting(
       
   245     const TInt aIAPSetting )
       
   246     {
       
   247     return iRepository->Set( KUPnPAppAccessPointSetting, aIAPSetting );
       
   248     }
       
   249 
       
   250 // --------------------------------------------------------------------------
       
   251 // CUPnPSettingsEngine::GetAccessPointSetting
       
   252 // Gets IAP setting from Central Repository.
       
   253 // --------------------------------------------------------------------------
       
   254 //
       
   255 EXPORT_C TInt CUPnPSettingsEngine::GetAccessPointSetting( TInt& aIAPSetting )
       
   256     {
       
   257     return iRepository->Get( KUPnPAppAccessPointSetting, aIAPSetting );
       
   258     }
       
   259 
       
   260 // --------------------------------------------------------------------------
       
   261 // CUPnPSettingsEngine::SetWapId
       
   262 // Sets iap wap id to Central Repository
       
   263 // --------------------------------------------------------------------------
       
   264 //
       
   265 EXPORT_C TInt CUPnPSettingsEngine::SetWapId( const TInt aWapId )
       
   266     {
       
   267     return iRepository->Set( KUPnPAppWapId, aWapId );
       
   268     }
       
   269 
       
   270 // --------------------------------------------------------------------------
       
   271 // CUPnPSettingsEngine::GetWapId
       
   272 // Gets iap wap id from Central Repository
       
   273 // --------------------------------------------------------------------------
       
   274 //
       
   275 EXPORT_C TInt CUPnPSettingsEngine::GetWapId( TInt& aWapId )
       
   276     {
       
   277     return iRepository->Get( KUPnPAppWapId, aWapId );
       
   278     }
       
   279 
       
   280 // --------------------------------------------------------------------------
       
   281 // CUPnPSettingsEngine::GetFirstStart
       
   282 // Gets information if this is the first start of home network
       
   283 // --------------------------------------------------------------------------
       
   284 //
       
   285 EXPORT_C TInt CUPnPSettingsEngine::GetFirstStart( TInt& aFirstStart )
       
   286     {
       
   287     TInt err ( iRepository->Get( KUPnPAppFirstStart, aFirstStart ));
       
   288     if ( aFirstStart )
       
   289         {
       
   290         TRAP_IGNORE(
       
   291         RFs fs;
       
   292         err = fs.Connect();
       
   293         CleanupClosePushL( fs );
       
   294         TVolumeInfo volumeInfo;
       
   295         TDriveUnit driveUnit;
       
   296         TInt err = fs.Volume(volumeInfo, EDriveE);
       
   297         if( err == KErrNone && volumeInfo.iFree > 0)
       
   298             {
       
   299             driveUnit = TDriveUnit( PathInfo::MemoryCardRootPath() );
       
   300             }
       
   301         else
       
   302             {
       
   303             driveUnit = TDriveUnit( PathInfo::PhoneMemoryRootPath() );
       
   304             }
       
   305 
       
   306         CleanupStack::PopAndDestroy( &fs );
       
   307         SetCopyLocationL( (TDriveNumber)((TInt)driveUnit) ));
       
   308         }
       
   309     return err;
       
   310     }
       
   311 
       
   312 // --------------------------------------------------------------------------
       
   313 // CUPnPSettingsEngine::SetFirstStart
       
   314 // Sets information if this is the first start of home network
       
   315 // --------------------------------------------------------------------------
       
   316 //
       
   317 EXPORT_C TInt CUPnPSettingsEngine::SetFirstStart( const TInt aFirstStart )
       
   318     {
       
   319     return iRepository->Set( KUPnPAppFirstStart, aFirstStart );
       
   320     }
       
   321 
       
   322 // --------------------------------------------------------------------------
       
   323 // CUPnPSettingsEngine::SetManufacturerParamsL
       
   324 // Sets the mandatory manufacturer settings
       
   325 // --------------------------------------------------------------------------
       
   326 //
       
   327 EXPORT_C TInt CUPnPSettingsEngine::SetManufacturerParamsL() const
       
   328     {
       
   329     __LOG("CUPnPSettingsEngine::SetManufacturerParamsL()");
       
   330     CUpnpMediaServerSettings* settings = CUpnpMediaServerSettings::NewL();
       
   331     CleanupStack::PushL( settings );
       
   332 
       
   333     // Manufacturer
       
   334     InitializePropertyL( *settings, 
       
   335                          UpnpMediaServerSettings::EManufacturer, 
       
   336                          KManufacturerName );
       
   337 
       
   338     // Model name
       
   339     HBufC8* model = HBufC8::NewLC( KMaxFileName );
       
   340     TPtr8 modelPtr( model->Des() );
       
   341     TInt err = ReadDeviceModelL( modelPtr );
       
   342     if( err )
       
   343         {
       
   344         model->Des().Copy( KModel );
       
   345         }
       
   346     InitializePropertyL( *settings, 
       
   347                          UpnpMediaServerSettings::EModelName, 
       
   348                          *model );
       
   349     // Friendly name
       
   350     InitializePropertyL( *settings, 
       
   351                          UpnpMediaServerSettings::EFriendlyName, 
       
   352                          *model );
       
   353     CleanupStack::PopAndDestroy( model );
       
   354 
       
   355     // Manufacturer url
       
   356     InitializePropertyL( *settings, 
       
   357                          UpnpMediaServerSettings::EManufacturerUrl, 
       
   358                          KManufacturerUrl );
       
   359 
       
   360     // Model url
       
   361     InitializePropertyL( *settings, 
       
   362                          UpnpMediaServerSettings::EModelUrl, 
       
   363                          KModelUrl );
       
   364 
       
   365     CleanupStack::PopAndDestroy( settings );
       
   366     return KErrNone;
       
   367     }
       
   368 
       
   369 // --------------------------------------------------------------------------
       
   370 // CUPnPSettingsEngine::ReadDeviceModelL
       
   371 // Get device model
       
   372 // --------------------------------------------------------------------------
       
   373 //
       
   374 TInt CUPnPSettingsEngine::ReadDeviceModelL( TDes8& aModel ) const
       
   375     {
       
   376     __LOG("CUPnPSettingsEngine::ReadDeviceModel()");
       
   377     RFs fs;
       
   378     RFile file;
       
   379     User::LeaveIfError( fs.Connect() );
       
   380     CleanupClosePushL( fs );
       
   381     
       
   382     HBufC*path = HBufC::NewLC( KMaxFileName );
       
   383     TParse parse;
       
   384     parse.Set( PathInfo::RomRootPath(), NULL, NULL );
       
   385     TPtrC romDrive = parse.Drive();
       
   386     
       
   387     path->Des().Append( romDrive );
       
   388     path->Des().Append( KModelFile() );
       
   389     
       
   390     TInt error ( file.Open(fs, *path, EFileRead ));
       
   391     if ( !error )
       
   392         {
       
   393         CleanupClosePushL( file );
       
   394 
       
   395         TFileText txtFile;
       
   396         txtFile.Set( file );
       
   397         HBufC* readBuf = HBufC::NewLC( KMaxFileName );
       
   398         txtFile.Seek( ESeekStart );
       
   399         TPtr bufPtr( readBuf->Des() );
       
   400         error = txtFile.Read( bufPtr ); // read one line
       
   401         if ( !error )
       
   402             {
       
   403             HBufC8* bufbuf = UpnpString::FromUnicodeL( *readBuf );
       
   404             CleanupStack::PushL( bufbuf );
       
   405 
       
   406             aModel = *bufbuf;
       
   407             CleanupStack::PopAndDestroy( bufbuf );
       
   408             }
       
   409         CleanupStack::PopAndDestroy( readBuf );
       
   410         CleanupStack::PopAndDestroy( &file ); // Close file
       
   411         }
       
   412     CleanupStack::PopAndDestroy( path );    
       
   413     CleanupStack::PopAndDestroy( &fs );
       
   414 
       
   415     return error;
       
   416     }
       
   417 
       
   418 // --------------------------------------------------------------------------
       
   419 // CUPnPSettingsEngine::GetCopyLocationDriveL
       
   420 // Gets the drive of the location for copied files
       
   421 // --------------------------------------------------------------------------
       
   422 //
       
   423 EXPORT_C void CUPnPSettingsEngine::GetCopyLocationDriveL( 
       
   424     TDriveNumber& aDrive )
       
   425     const
       
   426     {
       
   427     __LOG("CUPnPSettingsEngine::GetCopyLocationDriveL()");
       
   428 
       
   429     HBufC* location = HBufC::NewL(KMaxFileName);
       
   430     CleanupStack::PushL( location );
       
   431     TBool isPhoneMem( EFalse );
       
   432     TPtr locationPtr( location->Des() );
       
   433     GetCopyLocationL( locationPtr, isPhoneMem );
       
   434 
       
   435     TDriveUnit driveUnit = TDriveUnit( locationPtr );
       
   436 
       
   437     aDrive = (TDriveNumber)((TInt)driveUnit);
       
   438 
       
   439     CleanupStack::PopAndDestroy( location );
       
   440     }
       
   441 
       
   442 // --------------------------------------------------------------------------
       
   443 // CUPnPSettingsEngine::GetCopyLocationL
       
   444 // Gets the location for copied files
       
   445 // --------------------------------------------------------------------------
       
   446 //
       
   447 EXPORT_C void CUPnPSettingsEngine::GetCopyLocationL( TDes& aLocation,
       
   448                                                     TBool& aIsPhoneMemory )
       
   449     const
       
   450     {
       
   451     __LOG("CUPnPSettingsEngine::GetCopyLocationL()");
       
   452 
       
   453     // Get instance of Server Settings object
       
   454     CUpnpMediaServerSettings* settings = CUpnpMediaServerSettings::NewL();
       
   455     CleanupStack::PushL( settings );
       
   456 
       
   457     // Get the location setting from ServerSettings
       
   458     settings->Get( UpnpMediaServerSettings::EUploadDirectory, aLocation );
       
   459 
       
   460     // Check to see if drive is ready.
       
   461     TVolumeInfo volInfo;
       
   462     TDriveUnit driveUnit = TDriveUnit( aLocation );
       
   463     RFs fileServer;
       
   464 
       
   465     User::LeaveIfError( fileServer.Connect() );
       
   466     CleanupClosePushL( fileServer );
       
   467     TInt error = fileServer.Volume( volInfo, driveUnit );
       
   468     CleanupStack::PopAndDestroy( &fileServer );
       
   469 
       
   470     // check if memory is present
       
   471     // Revert to phone memory if location is not available
       
   472     // If the location is full no need to change the location. User will be
       
   473     // informed that memory is full and the location should be changed
       
   474     if( error == KErrNone )
       
   475         {
       
   476         TDriveUnit driveUnit = TDriveUnit( aLocation );    
       
   477         if( driveUnit == EDriveC )
       
   478             {
       
   479             aIsPhoneMemory = ETrue;
       
   480             }
       
   481         else
       
   482             {
       
   483             aIsPhoneMemory = EFalse;
       
   484             }
       
   485         }
       
   486     else
       
   487         {
       
   488         SetCopyLocationL( EDriveC );
       
   489         aIsPhoneMemory = ETrue;
       
   490         }
       
   491 
       
   492     CleanupStack::PopAndDestroy( settings );
       
   493     }
       
   494 
       
   495 // --------------------------------------------------------------------------
       
   496 // CUPnPSettingsEngine::SetCopyLocationL
       
   497 // Sets the location for copied files
       
   498 // --------------------------------------------------------------------------
       
   499 //
       
   500 EXPORT_C TInt CUPnPSettingsEngine::SetCopyLocationL( 
       
   501     const TDriveNumber aDrive )
       
   502     const
       
   503     {
       
   504     __LOG("CUPnPSettingsEngine::SetCopyLocationL()");
       
   505     TInt err( KErrNone );
       
   506 
       
   507     HBufC* path = HBufC::NewL( KMaxFileName );
       
   508     CleanupStack::PushL( path );
       
   509 
       
   510     CUpnpMediaServerSettings* settings =
       
   511         CUpnpMediaServerSettings::NewL();
       
   512     CleanupStack::PushL( settings );
       
   513 
       
   514     TDriveUnit driveUnit = TDriveUnit( aDrive );
       
   515     path->Des().Append( driveUnit.Name() );
       
   516     if( aDrive == EDriveC )
       
   517         {
       
   518         path->Des().Append( KUploadDirectoryCDrive );
       
   519         }
       
   520     else
       
   521         {
       
   522         path->Des().Append( KUploadDirectory );
       
   523         }
       
   524 
       
   525     err = settings->Set( UpnpMediaServerSettings::EUploadDirectory, *path );
       
   526 
       
   527     CleanupStack::PopAndDestroy( settings );
       
   528     CleanupStack::PopAndDestroy( path );
       
   529 
       
   530     return err;
       
   531     }
       
   532 
       
   533 // --------------------------------------------------------------------------
       
   534 // CUPnPSettingsEngine::GetCurrentIapNameL
       
   535 // Get iap name
       
   536 // --------------------------------------------------------------------------
       
   537 //
       
   538 EXPORT_C HBufC* CUPnPSettingsEngine::GetCurrentIapNameL( TInt aIapId )
       
   539     {
       
   540     __LOG("CUPnPSettingsEngine::GetCurrentIapNameL() begin");
       
   541     __LOG("read iap");
       
   542     
       
   543     HBufC* name = NULL;
       
   544     if( aIapId > EUPnPSettingsEngineIAPIdAlwaysAsk )
       
   545         {
       
   546         name = HBufC::NewLC( KMaxFileName );
       
   547         TPtr namePtr( name->Des() );
       
   548         CCommsDatabase* db = CCommsDatabase::NewL();
       
   549         CleanupStack::PushL( db );
       
   550         CCommsDbTableView* iapView = db->OpenViewMatchingUintLC(
       
   551             TPtrC(IAP),
       
   552             TPtrC(COMMDB_ID),
       
   553             aIapId );
       
   554         if( iapView )
       
   555             {
       
   556             TInt err = KErrNotFound;
       
   557             err = iapView->GotoFirstRecord();
       
   558             if ( !err )
       
   559                 {
       
   560                 iapView->ReadTextL(TPtrC(COMMDB_NAME), namePtr );
       
   561                 }
       
   562             CleanupStack::PopAndDestroy( iapView );
       
   563             }
       
   564         CleanupStack::PopAndDestroy( db );
       
   565         CleanupStack::Pop( name );
       
   566         }
       
   567     
       
   568     if( !name )
       
   569         {
       
   570         User::LeaveIfError( KErrNotFound );
       
   571         }
       
   572     
       
   573     __LOG("CUPnPSettingsEngine::GetCurrentIapNameL() end");
       
   574     return name;
       
   575     }
       
   576 
       
   577 //---------------------------------------------------------------------------
       
   578 // CUPnPSettingsEngine::IsAccessPointValidL
       
   579 // Checks if the given access point is valid.
       
   580 //---------------------------------------------------------------------------
       
   581 //
       
   582 EXPORT_C TBool CUPnPSettingsEngine::IsAccessPointValidL( TInt aIapId )
       
   583     {
       
   584     if ( aIapId == EUPnPSettingsEngineIAPIdAlwaysAsk )
       
   585         {
       
   586         // IAP is always ask. Returns true automatically.
       
   587         return ETrue;
       
   588         }
       
   589     else if ( aIapId > EUPnPSettingsEngineIAPIdAlwaysAsk )
       
   590         {
       
   591         // Verifies that IAP exists in the comms db and it is valid.
       
   592         return IsWLANAccessPointValidL( aIapId );
       
   593         }
       
   594     else
       
   595         {
       
   596         // IAP is NONE or some bogus value. Not valid.
       
   597         return EFalse;
       
   598         }
       
   599     }
       
   600 
       
   601 // -------------------------------------------------------------
       
   602 // CUPnPSettingsEngine::GetWLANAccessPointsL
       
   603 // Get wlan access points from commsdb
       
   604 // -------------------------------------------------------------
       
   605 //
       
   606 EXPORT_C void CUPnPSettingsEngine::GetWLANAccessPointsL(
       
   607                                     CDesCArray* aNameArray,
       
   608                                     RArray<TInt64>& aIapIdArr )
       
   609     {
       
   610     __LOG("CUPnPSettingsEngine::GetWLANAccessPointsL() begin");
       
   611 #ifdef __arm
       
   612     TUint32 bearerType;
       
   613 #endif
       
   614 
       
   615     RCmManager cmm;
       
   616     cmm.OpenL();
       
   617     CleanupClosePushL ( cmm );
       
   618 
       
   619     RArray<TUint32> iapIdArr;    
       
   620     CleanupClosePushL ( iapIdArr );
       
   621 
       
   622     //get all the connections, exclude easy wlan
       
   623     cmm.ConnectionMethodL( iapIdArr, EFalse, EFalse, EFalse );
       
   624 
       
   625     __LOG1(" total %d", iapIdArr.Count() );
       
   626 
       
   627     //Get the iap names
       
   628     for(TInt i = 0; i < iapIdArr.Count(); i++ )
       
   629         {
       
   630 #ifdef __arm
       
   631 
       
   632         bearerType = cmm.GetConnectionMethodInfoIntL(
       
   633                                iapIdArr[i], CMManager::ECmBearerType );
       
   634 
       
   635         __LOG1(" bearerType %d", bearerType);
       
   636 
       
   637         if( bearerType == KUidWlanBearerType )
       
   638             {
       
   639 #endif
       
   640             __LOG1(" i: %d", i);
       
   641             aIapIdArr.AppendL( iapIdArr[i] );
       
   642 
       
   643             if( aNameArray )
       
   644                 {
       
   645                 HBufC* name = NULL;
       
   646                 __LOG(" name ");
       
   647 
       
   648                 // This can leave in WINSCW env, so catch and handle the
       
   649                 // exception
       
   650                 TRAPD( getConnectionMethodErr,
       
   651                        name = cmm.GetConnectionMethodInfoStringL(
       
   652                                    iapIdArr[i], CMManager::ECmName );
       
   653                 );
       
   654 
       
   655                 if( getConnectionMethodErr == KErrNone )
       
   656                     {
       
   657                     __LOG16( *name );
       
   658                     CleanupStack::PushL( name );
       
   659                     __LOG(" append name ");
       
   660                     aNameArray->AppendL( *name ); //ownership not transferred
       
   661                     CleanupStack::PopAndDestroy( name );
       
   662                     }
       
   663                 else
       
   664                     {
       
   665                     // If failed to get the connection method info string,
       
   666                     // use a dummy IAP name
       
   667                     __LOG( " Failed to get IAP name! Using a dummy name. ");
       
   668                     aNameArray->AppendL( KDummyIAP );
       
   669                     }
       
   670                 }
       
   671 #ifdef __arm
       
   672             }
       
   673 #endif
       
   674 
       
   675         }
       
   676 
       
   677     CleanupStack::PopAndDestroy( &iapIdArr );
       
   678     CleanupStack::PopAndDestroy( &cmm );
       
   679 
       
   680     __LOG1(" aIapIdArr count %d", aIapIdArr.Count() );  
       
   681     __LOG("CUPnPSettingsEngine::GetWLANAccessPointsL() end");
       
   682 
       
   683     }
       
   684 
       
   685 
       
   686 // --------------------------------------------------------------------------
       
   687 // CUPnPSettingsEngine::CreateAccessPointL
       
   688 // Create AP modifying window
       
   689 // --------------------------------------------------------------------------
       
   690 //
       
   691 EXPORT_C void CUPnPSettingsEngine::CreateAccessPointL()
       
   692     {
       
   693     CCmSettingsUi* settings = CCmSettingsUi::NewL();    
       
   694     CleanupStack::PushL( settings );
       
   695     settings->RunSettingsL();
       
   696     CleanupStack::PopAndDestroy( settings );
       
   697     }
       
   698     
       
   699 //---------------------------------------------------------------------------
       
   700 // CUPnPSettingsEngine::IsWLANAccessPointValidL
       
   701 // Checks if the given access point is valid.
       
   702 //---------------------------------------------------------------------------
       
   703 //
       
   704 TBool CUPnPSettingsEngine::IsWLANAccessPointValidL( TUint32 aIapId )
       
   705     {
       
   706     
       
   707     TBool ret = EFalse;
       
   708     
       
   709     RArray<TInt64> newArray;
       
   710     CleanupClosePushL( newArray );
       
   711     
       
   712     GetWLANAccessPointsL( NULL, newArray );
       
   713     
       
   714     for(TInt i = 0; i < newArray.Count(); i++ )
       
   715         {
       
   716         if( aIapId == newArray[i] )
       
   717             {
       
   718             ret = ETrue;
       
   719             i = newArray.Count(); //quit the loop
       
   720             }
       
   721         }
       
   722     CleanupStack::PopAndDestroy( &newArray ); 
       
   723     
       
   724     return ret;
       
   725     }
       
   726 
       
   727 // --------------------------------------------------------------------------
       
   728 // CUPnPSettingsEngine::InitializePropertyL
       
   729 // Initializes a property if property has not yet been set
       
   730 // --------------------------------------------------------------------------
       
   731 //
       
   732 void CUPnPSettingsEngine::InitializePropertyL( 
       
   733     CUpnpMediaServerSettings& aSettings, 
       
   734     TInt aKey, 
       
   735     const TDesC8& aValue ) const
       
   736     {
       
   737     HBufC8* currentValue( NULL );
       
   738     TRAPD( err, currentValue = aSettings.GetL( aKey ) );
       
   739     if( !err )
       
   740         {
       
   741         TInt currentLength = currentValue->Length();
       
   742         delete currentValue;
       
   743         currentValue = NULL;
       
   744         if( !currentLength )
       
   745             {
       
   746             User::LeaveIfError( aSettings.SetL( aKey, aValue ) );
       
   747             }
       
   748         }
       
   749     else if( err == KErrNotFound )
       
   750         {
       
   751         User::LeaveIfError( aSettings.SetL( aKey, aValue ) );
       
   752         }
       
   753     else
       
   754         {
       
   755         User::Leave( err );
       
   756         }
       
   757     }
       
   758     
       
   759 // End of file